📄 instorage.cs
字号:
this.send_button.Click += new System.EventHandler(this.send_button_Click);
//
// cancel_button
//
this.cancel_button.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.cancel_button.Location = new System.Drawing.Point(376, 96);
this.cancel_button.Name = "cancel_button";
this.cancel_button.Size = new System.Drawing.Size(72, 24);
this.cancel_button.TabIndex = 3;
this.cancel_button.Text = "取消";
this.cancel_button.Click += new System.EventHandler(this.cancel_button_Click);
//
// InStgAdapter
//
this.InStgAdapter.DeleteCommand = this.sqlDeleteCommand1;
this.InStgAdapter.InsertCommand = this.sqlInsertCommand1;
this.InStgAdapter.SelectCommand = this.sqlSelectCommand1;
this.InStgAdapter.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table", "storage_In", new System.Data.Common.DataColumnMapping[] {
new System.Data.Common.DataColumnMapping("入库日期", "入库日期"),
new System.Data.Common.DataColumnMapping("设备号", "设备号"),
new System.Data.Common.DataColumnMapping("供应商", "供应商"),
new System.Data.Common.DataColumnMapping("供应商电话", "供应商电话"),
new System.Data.Common.DataColumnMapping("数量", "数量"),
new System.Data.Common.DataColumnMapping("价格", "价格"),
new System.Data.Common.DataColumnMapping("采购员", "采购员")})});
this.InStgAdapter.UpdateCommand = this.sqlUpdateCommand1;
//
// sqlDeleteCommand1
//
this.sqlDeleteCommand1.CommandText = @"DELETE FROM storage_In WHERE (入库日期 = @Original_入库日期) AND (价格 = @Original_价格 OR @Original_价格 IS NULL AND 价格 IS NULL) AND (供应商 = @Original_供应商 OR @Original_供应商 IS NULL AND 供应商 IS NULL) AND (供应商电话 = @Original_供应商电话 OR @Original_供应商电话 IS NULL AND 供应商电话 IS NULL) AND (数量 = @Original_数量) AND (设备号 = @Original_设备号) AND (采购员 = @Original_采购员 OR @Original_采购员 IS NULL AND 采购员 IS NULL)";
this.sqlDeleteCommand1.Connection = this.sqlConnection1;
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_入库日期", System.Data.SqlDbType.DateTime, 8, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "入库日期", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_价格", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "价格", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_供应商", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "供应商", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_供应商电话", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "供应商电话", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_数量", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "数量", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_设备号", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "设备号", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_采购员", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "采购员", System.Data.DataRowVersion.Original, null));
//
// sqlConnection1
//
this.sqlConnection1.ConnectionString = "workstation id=727CE26111204C4;packet size=4096;user id=sa;data source=\".\";persis" +
"t security info=False;initial catalog=storage";
//
// sqlInsertCommand1
//
this.sqlInsertCommand1.CommandText = "INSERT INTO storage_In(入库日期, 设备号, 供应商, 供应商电话, 数量, 价格, 采购员) VALUES (@入库日期, @设备号, @" +
"供应商, @供应商电话, @数量, @价格, @采购员); SELECT 入库日期, 设备号, 供应商, 供应商电话, 数量, 价格, 采购员 FROM sto" +
"rage_In WHERE (入库日期 = @入库日期)";
this.sqlInsertCommand1.Connection = this.sqlConnection1;
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@入库日期", System.Data.SqlDbType.DateTime, 8, "入库日期"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@设备号", System.Data.SqlDbType.VarChar, 10, "设备号"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@供应商", System.Data.SqlDbType.VarChar, 10, "供应商"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@供应商电话", System.Data.SqlDbType.VarChar, 10, "供应商电话"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@数量", System.Data.SqlDbType.VarChar, 10, "数量"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@价格", System.Data.SqlDbType.VarChar, 10, "价格"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@采购员", System.Data.SqlDbType.VarChar, 10, "采购员"));
//
// sqlSelectCommand1
//
this.sqlSelectCommand1.CommandText = "SELECT 入库日期, 设备号, 供应商, 供应商电话, 数量, 价格, 采购员 FROM storage_In";
this.sqlSelectCommand1.Connection = this.sqlConnection1;
//
// sqlUpdateCommand1
//
this.sqlUpdateCommand1.CommandText = @"UPDATE storage_In SET 入库日期 = @入库日期, 设备号 = @设备号, 供应商 = @供应商, 供应商电话 = @供应商电话, 数量 = @数量, 价格 = @价格, 采购员 = @采购员 WHERE (入库日期 = @Original_入库日期) AND (价格 = @Original_价格 OR @Original_价格 IS NULL AND 价格 IS NULL) AND (供应商 = @Original_供应商 OR @Original_供应商 IS NULL AND 供应商 IS NULL) AND (供应商电话 = @Original_供应商电话 OR @Original_供应商电话 IS NULL AND 供应商电话 IS NULL) AND (数量 = @Original_数量) AND (设备号 = @Original_设备号) AND (采购员 = @Original_采购员 OR @Original_采购员 IS NULL AND 采购员 IS NULL); SELECT 入库日期, 设备号, 供应商, 供应商电话, 数量, 价格, 采购员 FROM storage_In WHERE (入库日期 = @入库日期)";
this.sqlUpdateCommand1.Connection = this.sqlConnection1;
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@入库日期", System.Data.SqlDbType.DateTime, 8, "入库日期"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@设备号", System.Data.SqlDbType.VarChar, 10, "设备号"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@供应商", System.Data.SqlDbType.VarChar, 10, "供应商"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@供应商电话", System.Data.SqlDbType.VarChar, 10, "供应商电话"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@数量", System.Data.SqlDbType.VarChar, 10, "数量"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@价格", System.Data.SqlDbType.VarChar, 10, "价格"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@采购员", System.Data.SqlDbType.VarChar, 10, "采购员"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_入库日期", System.Data.SqlDbType.DateTime, 8, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "入库日期", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_价格", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "价格", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_供应商", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "供应商", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_供应商电话", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "供应商电话", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_数量", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "数量", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_设备号", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "设备号", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_采购员", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "采购员", System.Data.DataRowVersion.Original, null));
//
// dataGrid1
//
this.dataGrid1.DataMember = "";
this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataGrid1.Location = new System.Drawing.Point(16, 16);
this.dataGrid1.Name = "dataGrid1";
this.dataGrid1.Size = new System.Drawing.Size(472, 160);
this.dataGrid1.TabIndex = 6;
this.dataGrid1.Click += new System.EventHandler(this.dataGrid1_Select);
//
// InStorage
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(512, 342);
this.Controls.Add(this.dataGrid1);
this.Controls.Add(this.groupBox1);
this.Name = "InStorage";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "设备入库";
this.Load += new System.EventHandler(this.InStorage_Load);
this.groupBox1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
this.ResumeLayout(false);
}
#endregion
private void label8_Click(object sender, System.EventArgs e)
{
}
private void InStorage_Load(object sender, System.EventArgs e)
{
MyConn.Open();//打开连接
InStgAdapter.SelectCommand.CommandText = "SELECT * FROM storage_In";
InStgAdapter.SelectCommand.Connection = MyConn;
InStgAdapter.Fill(InStgInfo);//填充数据集
this.dataGrid1.DataSource = InStgInfo.DefaultView;
ISReport = (CurrencyManager) BindingContext[InStgInfo];
this.DataBindingsFunction();
DataGridTableStyle ts = new DataGridTableStyle();
ts.AlternatingBackColor = Color.Blue;//颜色设置
ts.MappingName = InStgInfo.TableName;
this.dataGrid1.Select(0);//选定第一列
this.textNum2.Enabled=false;
}
private void DataBindingsFunction()//绑定
{
this.textNum2.DataBindings.Add("Text",InStgInfo,"设备号");
this.textDate.DataBindings.Add("Text",InStgInfo,"入库日期");
this.textSupply.DataBindings.Add("Text",InStgInfo,"供应商");
this.textPho.DataBindings.Add("Text",InStgInfo,"供应商电话");
this.textAmount.DataBindings.Add("Text",InStgInfo,"数量");
this.textCost.DataBindings.Add("Text",InStgInfo,"价格");
this.textMan.DataBindings.Add("Text",InStgInfo,"采购员");
}
private void add_button_Click(object sender, System.EventArgs e)//增加记录
{
try
{
ISReport = (CurrencyManager)this.BindingContext[InStgInfo];
ISReport.AddNew();//增加新记录
this.textNum2.Enabled=true;
this.textDate.Text=DateTime.Now.ToString();
this.change=true;//还库数量更改
this.oldtxtAmount="0";
this.textNum2.Focus();//焦点在第一个字段上
}
catch( Exception ex )
{
MessageBox.Show(ex.Message);
}
}
private void send_button_Click(object sender, System.EventArgs e)//提交信息
{
try
{
if( MyConn.State != ConnectionState.Open)
{
MyConn.Open();
}
if(this.textNum2.Enabled==true)
{
this.textNum2.Enabled=false;
}
ISReport = (CurrencyManager)this.BindingContext[InStgInfo];
if (this.textNum2.Text.Trim() == ""||this.textAmount.Text.Trim()=="")//检查不能为空的字段
{
MessageBox.Show("设备号,数量不能为空!");
return;
}
ISReport.EndCurrentEdit();
if(InStgInfo.GetChanges()!=null)//信息是否被重新编辑
{
if(!change)
{
if(this.oldtxtAmount==this.textAmount.Text.Trim())
change=false;
else
change=true;
}
InStgAdapter.UpdateCommand.Connection=MyConn;//更新到数据库
InStgAdapter.InsertCommand.Connection=MyConn;
InStgTran=MyConn.BeginTransaction();
InStgAdapter.UpdateCommand.Transaction = InStgTran;
InStgAdapter.InsertCommand.Transaction = InStgTran;
this.InStgAdapter.Update(InStgInfo);
if(change)//还库数量字段有新值了
{
string number=this.textAmount.Text.Trim();
int changeAmt=int.Parse(number)-int.Parse(oldtxtAmount);
string driveID=this.textNum2.Text.Trim();
SqlCommand driveStorageUpdateCommand = new SqlCommand();//更新库存表的现有库存
driveStorageUpdateCommand.Connection = MyConn;//调用存储过程
driveStorageUpdateCommand.Transaction = InStgTran;
driveStorageUpdateCommand.CommandType = CommandType.StoredProcedure;
driveStorageUpdateCommand.CommandText = "UpdateStorage";
driveStorageUpdateCommand.Parameters.Add("@i_Drive_ID",SqlDbType.Char,10);
driveStorageUpdateCommand.Parameters["@i_Drive_ID"].Value =driveID;
driveStorageUpdateCommand.Parameters.Add("@i_InOutNumber",SqlDbType.Int);
driveStorageUpdateCommand.Parameters["@i_InOutNumber"].Value = changeAmt;
driveStorageUpdateCommand.Parameters.Add("@o_ErrMessage",SqlDbType.VarChar,256);
driveStorageUpdateCommand.Parameters["@o_ErrMessage"].Direction = ParameterDirection.Output;
driveStorageUpdateCommand.ExecuteNonQuery();
InStgTran.Commit();
MessageBox.Show("OK");
}
}
else
{
MessageBox.Show("您没有修改任何信息");
return;
}
}
catch(Exception ex)
{
MessageBox.Show("对不起,您输入的设备号错误!!具体信息:"+ex.ToString());
if( InStgTran != null )
{
InStgTran.Rollback();
}
if( MyConn.State != ConnectionState.Closed)
{
MyConn.Close();
}
return;
}
}
private void cancel_button_Click(object sender, System.EventArgs e)
{
try
{
ISReport = (CurrencyManager)this.BindingContext[InStgInfo];
ISReport.CancelCurrentEdit(); //取消编辑
MessageBox.Show("已经取消!");
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
return;
}
private void dataGrid1_Select(object sender, System.EventArgs e)//在数据集中选定记录
{
if (this.InStgInfo.Rows.Count > 0)
{
int currentRow = this.dataGrid1.CurrentCell.RowNumber;
if (currentRow >= 0 && currentRow< ISReport.Count)
ISReport.Position = currentRow;
this.oldtxtAmount=this.textAmount.Text.Trim();
this.textNum2.Enabled=false;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -