所以,我知道您通过相关列关联数据表......虽然我有一个小问题。
例子:
父表 -客户-> {customerName, customerCode(PK), telphoneCell, ... etc}
子表 -订单-> { customerCode, orderCode(PK) dateStart, dateEnd, ... 等}
现在...
孙子表 - ManufacturingSheet -> {panelNumber, panelWidth, panelHeight, ... etc}
还有一些文本框显示了我根据用户输入计算出的零件数量,例如螺栓和螺母。
那么如何将整个表格保存到单个客户的订单中呢?客户名称、代码和日期详细信息等也出现在此表格上。
即使我可以将 texbox 链接到Orders表,我将如何链接到表单的其余部分?
这是显示我想存储在数据库中的所有网格和文本框的代码:
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);
}
}
}
}