2013-03-06 60 views
0

所以,我知道你通過相關的列關聯DataTable ...雖然我有一個小問題。無法將DataTable與另一個C#相關聯

實施例:

父表 - 客戶 - > {客戶名稱,customerCode(PK),telphoneCell,...等}

子表 - 訂單 - > {customerCode,orderCode( PK)dateStart,dateEnd,...等}

現在......

孫表(S) - ManufacturingSheet - > {panelNumber,panelWidth,panelHeight,... etc}

還有一些文本框顯示零件的數量,如螺栓&堅果,我從用戶輸入計算。

那麼,如何將整個表單保存爲單個客戶訂單呢?客戶名稱,代碼和日期詳細信息等也出現在此表單上。

即使我可以鏈接一個texbox到訂單表,我將如何鏈接到表單的其餘部分?

這裏是代碼顯示所有網格&文本框,我想被存儲在數據庫:

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Windows.Forms; 

namespace PalisadeWorld 
{ 
public partial class ManufacturingSheet : Form 
{ 
    public ManufacturingSheet() 
    { 
     InitializeComponent(); 
    } 

    //all the calculated sizes, and parts 
    public string[] dis_Width { get; set; } 
    public string[] dis_Height { get; set; } 
    public string[] dis_Comments { get; set; } 
    public int[] dis_PaleQty { get; set; } 
    public int[] dis_Blocks { get; set; } 
    public int dis_num { get; set; } 

    //Method to Convert a string array to int array 
    private int[] ConvertArray(string[] s, int rows) 
    { 
     int[] intArray = new int[rows]; 

     for (int x = 0; x < rows; x++) 
     { 
      intArray[x] = Convert.ToInt32(s[x]); 
     } 
     return intArray; 
    } 

    //Methods returning other parts calculated with sizes above 
    private int GetTotalBearers(string[] bearers, int rows) 
    { 
     int i; 
     int totalBearers = 0; 
     int[] temp = ConvertArray(bearers, rows); 
     for (i = 0; i < rows; i++) 
     { 
      if (temp[i] >= 2200) 
      { 
       totalBearers += 6; 
      } 
      else totalBearers += 4; 
     } 
     return totalBearers; 
    } 
    private int GetTotalPales(int[] pales, int rows) 
    { 
     int i; 
     int totalPales = 0; 
     for (i = 0; i < rows; i++) 
     { 
      totalPales += pales[i]; 
     } 
     return totalPales; 
    } 
    private int GetTotalBoltsNutsBrackest(int[] pales, int rows) 
    { 
     int totalBolts = GetTotalPales(pales, rows) + (rows * 4); 
     return totalBolts; 
    } 

    private void ManufacturingSheet_Load(object sender, EventArgs e) 
    { 
     //displaying number of respective parts 
     numBearers.Text = string.Format("{0}", GetTotalBearers(dis_Height, dis_num)); 
     numPales.Text = string.Format("{0}", GetTotalPales(dis_PaleQty, dis_num)); 
     numBrackets.Text = numBearers.Text; 
     numBoltsNutsWashers.Text = string.Format("{0}", GetTotalBoltsNutsBrackest(dis_PaleQty, dis_num)); 

     int i; 
     int no = 0; 

     //displaying sizes etc in DataGrid 
     for(i = 0; i < dis_num; i++) 
     { 
      // Create a new row. 
      PalisadeWorldDatabaseDataSet.ManufacturingSheetRow newOutputRow; 

      newOutputRow = palisadeWorldDatabaseDataSet1.ManufacturingSheet.NewManufacturingSheetRow(); 

      newOutputRow.no = ++no ; 
      newOutputRow.cutSize = string.Format("{0}", dis_Width[i]); 
      newOutputRow.block = string.Format("{0}", dis_Blocks[i]); 
      newOutputRow.height = string.Format("{0}", dis_Height[i]); 
      newOutputRow.palesQty = string.Format("{0}", dis_PaleQty[i]); 
      newOutputRow.comments = string.Format("{0}", dis_Comments[i]); 

      // Add the row to the Region table 
      this.palisadeWorldDatabaseDataSet1.ManufacturingSheet.Rows.Add(newOutputRow); 

      // Save the new row to the database 
      this.manufacturingSheetTableAdapter.Update(this.palisadeWorldDatabaseDataSet1.ManufacturingSheet); 

      this.manufacturingSheetTableAdapter.Fill(this.palisadeWorldDatabaseDataSet1.ManufacturingSheet); 
     }   
    } 
} 

}

+0

也許** ManufacturingSheet **更多是報告而不是數據集,但仍需要根據客戶詳細信息保存 – 2013-03-06 12:19:41

回答

0

DataAdapter的允許您定義多個表和它們之間的關係,以及定義插入並更新每個表的命令(以及選擇命令和刪除命令)。

http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldataadapter.aspx

對於GUI的問題,通常你會的OrderItems表(通常命名的OrderDetail),你會用一個DataGrid捕獲訂單上的一個或多個項目:

 OrderItems 
     OrderID 
     ItemID typically references a Parts table 
     Quantity 
     UnitPrice 
+0

非常感謝Kind先生Tim – 2013-03-06 11:16:06

+0

通常是。但是這些面板都是相同的產品,只是尺寸不同而且通常尺寸相同。因爲它只有一個計數器,所以在使用panelNumber作爲參考時沒有用處 – 2013-03-06 11:42:54

相關問題