所以,我知道你通过相关列关联DataTables ......虽然我有一个小问题。
示例:
父表 - 客户 - > {customerName,customerCode(PK),telphoneCell,... etc}
子表 - 订单 - > {customerCode,orderCode(PK)dateStart,dateEnd,... etc}
现在...
孙子表 - 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 :(得分: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