DataSet tempds = new DataSet();
Bool SuccessFlag=false;
private void BJInNew_Click(object sender,EventArgs e) //新建入库单---主要是创建入库单号及入库单的表结构
{ CreateTempTable(); //创建入库单表结构
int countNewBJ = 0;
countNewBJ = tempds.Tables["BJ_InBound_Info"].Rows.Count; //插入入库单的数据行数
if (countNewBJ == 0)
{
clearAll(); //清除输入框
Create_Inbound_no(); //创建入库单号
}
else if (MessageBox.Show("您刚才创建的入库单尚未保存,保存刚才创建的入库单吗?", "请选择", MessageBoxButtons.YesNo, MessageBoxIcon.Question,MessageBoxDefaultButton.Button2) == DialogResult.Yes)
{
SaveData();
clearAll(); //清除输入框
Create_Inbound_no(); //创建入库单号
}
else
{
clearAll(); //清除输入框
Create_Inbound_no(); //创建入库单号
}
}
private void CreateTempTable() //创建入库单表结构
{
tempds = new DataSet();
DataTable tempdt = tempds.Tables.Add("BJ_InBound_Info");
DataColumn InBound_no = tempdt.Columns.Add("InBound_no",typeof(string));
InBound_no.AllowDBNull = false;
InBound_no.MaxLength = 10;
InBound_no.Unique = false;
DataColumn Spareparts_no = tempdt.Columns.Add("Spareparts_no",typeof(string));
Spareparts_no.AllowDBNull = false;
Spareparts_no.MaxLength = 15;
Spareparts_no.Unique = false;
}
private void BJInAdd_Click(object sender,EventArgs e)
{
string strMessage = "确定添加该条记录吗?";
DialogResult responseDialogResult = MessageBox.Show(strMessage, "添加信息提示",MessageBoxButtons.YesNo, MessageBoxIcon.Question,MessageBoxDefaultButton.Button2);
if (responseDialogResult == DialogResult.Yes)
{
countBJIn = tempds.Tables["BJ_InBound_Info"].Rows.Count;
InsertData();
}
}
private void InsertData() //向入库单中插入数据行
{
DataRow dr= tempds.Tables["BJ_InBound_Info"].NewRow();
try
{
row["InBound_no"] = InBound_no.Text;
row["Spareparts_no"] = Spareparts_no.Text;
tempds.Tables["BJ_InBound_Info"].Rows.Add(row);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
this.bindingSource1.DataSource = indatads.Tables["BJ_InBound_Info"];
this.bindingNavigator1.BindingSource = bindingSource1;
this.dataGridView1.DataSource = bindingSource1;
}
private void BJInSave_Click(object sender, EventArgs e)
{
int countNewBJ =0; //一个入库单中添加备件的记录数
countNewBJ = tempds.Tables["BJ_InBound_Info"].Rows.Count;
if (countNewBJ ==0)
{
MessageBox.Show("您没有添加新的备件信息!");
}
else
{
string strMessage = "确定保存吗?";
DialogResult responseDialogResult=MessageBox.Show(strMessage,"添加信息提示",MessageBoxButtons.YesNo, MessageBoxIcon.Question,MessageBoxDefaultButton.Button2);
if(responseDialogResult == DialogResult.Yes)
{
SaveData();
}
clearAll();
Create_Inbound_no();
tempds.Dispose();
}
}
private void SaveData() //保存入库
{
string strSQL ="";
OracleConnection conn = newOracleConnection(ConnectionString);
stringtempInBound_no = "";
string tempSpareparts_no= "";
countBJIn = tempds.Tables["BJ_InBound_Info"].Rows.Count;
for (int i = 0; i< countBJIn; i++) //把记录各个字段数据放到临时表各个对应的变量中然后再添加到数据库中
{
tempInBound_no= indatads.Tables[0].Rows[i]["InBound_no"].ToString();
tempSpareparts_no= indatads.Tables[0].Rows[i]["Spareparts_no"].ToString();
strSQL="INSERT INTO T_BJ_InBound(InBound_No,Spareparts_no)VALUES(‘”+tempInBound_no+”’,‘”+ tempSpareparts_no+”’)
OracleCommand cmd = newOracleCommand();
try
{
cmd.Connection = conn;
cmd.CommandText = strSQL;
conn.Open();
cmd.ExecuteNonQuery();
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
SuccessFlag = false;
}
finally
{
conn.Close();
conn.Dispose();
cmd.Dispose();
}
}