📄 form3.cs
字号:
this.label4.TabIndex = 2;
this.label4.Text = "单价";
this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// label3
//
this.label3.Location = new System.Drawing.Point(8, 64);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(72, 23);
this.label3.TabIndex = 1;
this.label3.Text = "名称";
this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// label2
//
this.label2.Location = new System.Drawing.Point(8, 24);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(72, 23);
this.label2.TabIndex = 0;
this.label2.Text = "编号";
this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// btnupdata
//
this.btnupdata.Location = new System.Drawing.Point(224, 312);
this.btnupdata.Name = "btnupdata";
this.btnupdata.TabIndex = 13;
this.btnupdata.Text = "保存";
this.btnupdata.Click += new System.EventHandler(this.btnupdata_Click);
//
// sqlDataAdapter1
//
this.sqlDataAdapter1.DeleteCommand = this.sqlDeleteCommand1;
this.sqlDataAdapter1.InsertCommand = this.sqlInsertCommand1;
this.sqlDataAdapter1.SelectCommand = this.sqlSelectCommand1;
this.sqlDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table", "good", new System.Data.Common.DataColumnMapping[] {
new System.Data.Common.DataColumnMapping("goodid", "goodid"),
new System.Data.Common.DataColumnMapping("goodnm", "goodnm"),
new System.Data.Common.DataColumnMapping("goodprice", "goodprice"),
new System.Data.Common.DataColumnMapping("goodnum", "goodnum")})});
this.sqlDataAdapter1.UpdateCommand = this.sqlUpdateCommand1;
//
// sqlDeleteCommand1
//
this.sqlDeleteCommand1.CommandText = @"DELETE FROM good WHERE (goodid = @Original_goodid) AND (goodnm = @Original_goodnm OR @Original_goodnm IS NULL AND goodnm IS NULL) AND (goodnum = @Original_goodnum OR @Original_goodnum IS NULL AND goodnum IS NULL) AND (goodprice = @Original_goodprice OR @Original_goodprice IS NULL AND goodprice IS NULL)";
this.sqlDeleteCommand1.Connection = this.sqlConnection1;
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_goodid", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "goodid", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_goodnm", System.Data.SqlDbType.VarChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "goodnm", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_goodnum", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "goodnum", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_goodprice", System.Data.SqlDbType.Money, 8, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "goodprice", System.Data.DataRowVersion.Original, null));
//
// sqlConnection1
//
this.sqlConnection1.ConnectionString = "workstation id=HOUHAIPO1;packet size=4096;integrated security=SSPI;data source=\"." +
"\";persist security info=False;initial catalog=sqlgoods";
//
// sqlInsertCommand1
//
this.sqlInsertCommand1.CommandText = "INSERT INTO good(goodid, goodnm, goodprice, goodnum) VALUES (@goodid, @goodnm, @g" +
"oodprice, @goodnum); SELECT goodid, goodnm, goodprice, goodnum FROM good WHERE (" +
"goodid = @goodid)";
this.sqlInsertCommand1.Connection = this.sqlConnection1;
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@goodid", System.Data.SqlDbType.Int, 4, "goodid"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@goodnm", System.Data.SqlDbType.VarChar, 50, "goodnm"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@goodprice", System.Data.SqlDbType.Money, 8, "goodprice"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@goodnum", System.Data.SqlDbType.Int, 4, "goodnum"));
//
// sqlSelectCommand1
//
this.sqlSelectCommand1.CommandText = "SELECT goodid, goodnm, goodprice, goodnum FROM good";
this.sqlSelectCommand1.Connection = this.sqlConnection1;
//
// sqlUpdateCommand1
//
this.sqlUpdateCommand1.CommandText = @"UPDATE good SET goodid = @goodid, goodnm = @goodnm, goodprice = @goodprice, goodnum = @goodnum WHERE (goodid = @Original_goodid) AND (goodnm = @Original_goodnm OR @Original_goodnm IS NULL AND goodnm IS NULL) AND (goodnum = @Original_goodnum OR @Original_goodnum IS NULL AND goodnum IS NULL) AND (goodprice = @Original_goodprice OR @Original_goodprice IS NULL AND goodprice IS NULL); SELECT goodid, goodnm, goodprice, goodnum FROM good WHERE (goodid = @goodid)";
this.sqlUpdateCommand1.Connection = this.sqlConnection1;
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@goodid", System.Data.SqlDbType.Int, 4, "goodid"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@goodnm", System.Data.SqlDbType.VarChar, 50, "goodnm"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@goodprice", System.Data.SqlDbType.Money, 8, "goodprice"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@goodnum", System.Data.SqlDbType.Int, 4, "goodnum"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_goodid", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "goodid", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_goodnm", System.Data.SqlDbType.VarChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "goodnm", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_goodnum", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "goodnum", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_goodprice", System.Data.SqlDbType.Money, 8, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "goodprice", System.Data.DataRowVersion.Original, null));
//
// btnprev
//
this.btnprev.Location = new System.Drawing.Point(8, 312);
this.btnprev.Name = "btnprev";
this.btnprev.TabIndex = 14;
this.btnprev.Text = "向上";
this.btnprev.Click += new System.EventHandler(this.btnprev_Click);
//
// btnnext
//
this.btnnext.Location = new System.Drawing.Point(120, 312);
this.btnnext.Name = "btnnext";
this.btnnext.TabIndex = 15;
this.btnnext.Text = "向下";
this.btnnext.Click += new System.EventHandler(this.btnnext_Click);
//
// Form3
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(736, 354);
this.Controls.Add(this.btnnext);
this.Controls.Add(this.btnprev);
this.Controls.Add(this.btnupdata);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.label1);
this.Controls.Add(this.button5);
this.Controls.Add(this.dataGrid1);
this.Name = "Form3";
this.Text = "Form3";
this.Load += new System.EventHandler(this.Form3_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.dataSet11)).EndInit();
this.groupBox1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private void Form3_Load(object sender, System.EventArgs e)
{
try
{
this.sqlDataAdapter1.Fill(dataSet11,"good");
}
catch (Exception err)
{
MessageBox.Show(err.Message);
}
}
private void dataGrid1_Navigate(object sender, System.Windows.Forms.NavigateEventArgs ne)
{
}
private void btnin_Click(object sender, System.EventArgs e)
{
int flaggg=0;
try
{
int i,number,flag = 0;
for (i=0; i < this.dataSet11.good.Rows.Count; i++)
{
if(txtid2.Text == this.dataSet11.good.Rows[i]["goodid"].ToString()||txtnm2.Text==this.dataSet11.good.Rows[i]["goodnm"].ToString())
{
number = Convert.ToInt32(this.txtnum2.Text);
this.dataSet11.good.Rows[i]["goodnum"] = Convert.ToInt32(this.dataSet11.good.Rows[i]["goodnum"]) + number;
this.sqlDataAdapter1.Update(dataSet11,"good");
txtid2.Text=this.dataSet11.good.Rows[i]["goodid"].ToString();
if(txtprice2.Text=="")
{
txtprice2.Text=Convert.ToString(Convert.ToInt32(this.dataSet11.good.Rows[i]["goodprice"])-1);
}
txtnm2.Text=Convert.ToString(this.dataSet11.good.Rows[i]["goodnm"]);
inallnum+=number;
txtallnum2.Text=inallnum.ToString();
inallmoney+=number*(Convert.ToInt32(txtprice2.Text));
txtacount2.Text=Convert.ToString(inallmoney);
flag=1;
flaggg=1;
}
}
if(flaggg==0&&txtnm2.Text!="")
{
DataRow newdr=dataSet11.Tables["good"].NewRow();
if(txtid2.Text=="")
{
newdr["goodid"]=this.dataSet11.good.Rows.Count+3;
}
else
{
newdr["goodid"]=txtid2.Text;
}
newdr["goodnm"]=txtnm2.Text;
newdr["goodprice"]=Convert.ToString(Convert.ToInt32(txtprice2.Text)+1);
newdr["goodnum"]=txtnum2.Text;
dataSet11.Tables["good"].Rows.Add(newdr);
this.sqlDataAdapter1.Fill(dataSet11,"good");
this.sqlDataAdapter1.Update(dataSet11,"good");
txtid2.Text=newdr["goodid"].ToString();
txtprice2.Text=Convert.ToString(Convert.ToInt32(newdr["goodprice"])+1);
txtnm2.Text=Convert.ToString(this.dataSet11.good.Rows[i]["goodnm"]);
inallnum+=Convert.ToInt32(txtnum2.Text);
txtallnum2.Text=inallnum.ToString();
inallmoney+=Convert.ToInt32(txtnum2.Text)*inallnum;
txtacount2.Text=Convert.ToString(inallmoney);
flag=1;
}
if(flag == 0)
MessageBox.Show("商品信息未输入全!");
}
catch(Exception err)
{
MessageBox.Show(err.Message);
}
}
private void btncansle2_Click(object sender, System.EventArgs e)
{
txtid2.Clear();
txtnm2.Clear();
txtprice2.Clear();
txtnum2.Clear();
txtacount2.Clear();
txtallnum2.Clear();
inallmoney=0;inallnum=0;
}
private void btnupdata_Click(object sender, System.EventArgs e)
{
this.dataGrid1.UnSelect (this.dataGrid1.CurrentRowIndex);
this.dataGrid1.Select(this.dataGrid1.CurrentRowIndex);
this.sqlDataAdapter1.Update(dataSet11,"good");
}
private void button5_Click(object sender, System.EventArgs e)
{
this.Close();
}
private void btnnext_Click(object sender, System.EventArgs e)
{
try
{
this.dataGrid1.CurrentRowIndex = this.BindingContext[dataSet11.Tables["good"]].Position;
this.dataGrid1.UnSelect(this.dataGrid1.CurrentRowIndex);
this.BindingContext[dataSet11.Tables["good"]].Position++;
this.dataGrid1.CurrentRowIndex = this.BindingContext[dataSet11.Tables["good"]].Position;
this.dataGrid1.Select(this.dataGrid1.CurrentRowIndex);
}
catch (Exception err)
{
MessageBox.Show(err.Message);
}
}
private void btnprev_Click(object sender, System.EventArgs e)
{
try
{
this.dataGrid1.UnSelect(this.dataGrid1.CurrentRowIndex);
if(this.dataGrid1.CurrentRowIndex >0)
this.dataGrid1.CurrentRowIndex --;
this.dataGrid1.Select(this.dataGrid1.CurrentRowIndex);
}
catch (Exception err)
{
MessageBox.Show(err.Message);
}
}
private void listnm_SelectedIndexChanged(object sender, System.EventArgs e)
{
}
private void txtallnum2_TextChanged(object sender, System.EventArgs e)
{
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -