?? outstorage.cs
字號:
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, 30, 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_out(設備號, 出庫日期, 使用部門, 數量, 經辦人, 備注) VALUES (@設備號, @出庫日期, @使用部門," +
" @數量, @經辦人, @備注); SELECT 設備號, 出庫日期, 使用部門, 數量, 經辦人, 備注 FROM storage_out WHERE (出庫" +
"日期 = @出庫日期)";
this.sqlInsertCommand1.Connection = this.sqlConnection1;
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.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, 30, "備注"));
//
// sqlSelectCommand1
//
this.sqlSelectCommand1.CommandText = "SELECT 設備號, 出庫日期, 使用部門, 數量, 經辦人, 備注 FROM storage_out";
this.sqlSelectCommand1.Connection = this.sqlConnection1;
//
// sqlUpdateCommand1
//
this.sqlUpdateCommand1.CommandText = @"UPDATE storage_out SET 設備號 = @設備號, 出庫日期 = @出庫日期, 使用部門 = @使用部門, 數量 = @數量, 經辦人 = @經辦人, 備注 = @備注 WHERE (出庫日期 = @Original_出庫日期) AND (使用部門 = @Original_使用部門 OR @Original_使用部門 IS NULL AND 使用部門 IS NULL) AND (備注 = @Original_備注 OR @Original_備注 IS NULL AND 備注 IS NULL) AND (數量 = @Original_數量) AND (經辦人 = @Original_經辦人 OR @Original_經辦人 IS NULL AND 經辦人 IS NULL) AND (設備號 = @Original_設備號); SELECT 設備號, 出庫日期, 使用部門, 數量, 經辦人, 備注 FROM storage_out WHERE (出庫日期 = @出庫日期)";
this.sqlUpdateCommand1.Connection = this.sqlConnection1;
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.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, 30, "備注"));
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, 30, 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(24, 8);
this.dataGrid1.Name = "dataGrid1";
this.dataGrid1.Size = new System.Drawing.Size(456, 160);
this.dataGrid1.TabIndex = 3;
this.dataGrid1.Click += new System.EventHandler(this.dataGrid1_Select);
//
// OutStorage
//
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 = "OutStorage";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "設備出庫";
this.Load += new System.EventHandler(this.OutStorage_Load);
this.groupBox1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
this.ResumeLayout(false);
}
#endregion
private void OutStorage_Load(object sender, System.EventArgs e)
{
MyConn.Open();//打開連接
OutStgAdapter.SelectCommand.CommandText = "SELECT * FROM storage_out";
OutStgAdapter.SelectCommand.Connection = MyConn;
OutStgAdapter.Fill(OutStgInfo);//填充數據集
this.dataGrid1.DataSource = OutStgInfo.DefaultView;
OSReport = (CurrencyManager) BindingContext[OutStgInfo];
DataGridTableStyle Out = new DataGridTableStyle();
this.DataBindingsFunction();
Out.AlternatingBackColor = Color.Blue;//顏色設置
Out.MappingName = OutStgInfo.TableName;
this.dataGrid1.Select(0);//選定第一列
this.textNum2.Enabled=false;
}
private void DataBindingsFunction()//綁定
{
this.textNum2.DataBindings.Add("Text",OutStgInfo,"設備號");
this.textDate.DataBindings.Add("Text",OutStgInfo,"出庫日期");
this.textDep.DataBindings.Add("Text",OutStgInfo,"使用部門");
this.textAmount.DataBindings.Add("Text",OutStgInfo,"數量");
this.textMan.DataBindings.Add("Text",OutStgInfo,"經辦人");
this.textExp.DataBindings.Add("Text",OutStgInfo,"備注");
}
private void add_button_Click(object sender, System.EventArgs e)//增加記錄
{
try
{
OSReport = (CurrencyManager)this.BindingContext[OutStgInfo];
OSReport.AddNew();//增加新記錄
this.textDate.Text=DateTime.Now.ToString();
this.textNum2.Enabled=true;
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;
}
OSReport = (CurrencyManager)this.BindingContext[OutStgInfo];
if (this.textNum2.Text.Trim() == ""||this.textAmount.Text.Trim()=="")//檢查不能為空的字段
{
MessageBox.Show("設備號,數量不能為空!");
return;
}
OSReport.EndCurrentEdit();
if(OutStgInfo.GetChanges()!=null)//信息是否被重新編輯
{
if(!change)
{
if(oldtxtAmount==this.textAmount.Text.Trim())
change=false;
else
change=true;
}
OutStgAdapter.UpdateCommand.Connection=MyConn;//更新到數據庫
OutStgAdapter.InsertCommand.Connection=MyConn;
OutStgTran=MyConn.BeginTransaction();
OutStgAdapter.UpdateCommand.Transaction = OutStgTran;
OutStgAdapter.InsertCommand.Transaction = OutStgTran;
this.OutStgAdapter.Update(OutStgInfo);
int cmdresults = 0;
if(change)
{
string driveID=this.textNum2.Text.Trim();
string number=this.textAmount.Text.Trim();
int outnumber=0-(int.Parse(number))+int.Parse(this.oldtxtAmount);
SqlCommand driveStorageUpdateCommand = new SqlCommand();//更新庫存表的現有庫存
driveStorageUpdateCommand.Connection = MyConn;//調用存儲過程
driveStorageUpdateCommand.Transaction = OutStgTran;
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 = outnumber;
driveStorageUpdateCommand.Parameters.Add("@o_ErrMessage",SqlDbType.VarChar,256);
driveStorageUpdateCommand.Parameters["@o_ErrMessage"].Direction = ParameterDirection.Output;
driveStorageUpdateCommand.Parameters.Add("@o_Return",SqlDbType.Int);
driveStorageUpdateCommand.Parameters["@o_Return"].Direction = ParameterDirection.ReturnValue;
cmdresults = driveStorageUpdateCommand.ExecuteNonQuery();
cmdresults = Convert.ToInt16(driveStorageUpdateCommand.Parameters["@o_Return"].Value);
if( cmdresults != 0)
{
MessageBox.Show(driveStorageUpdateCommand.Parameters["@o_ErrMessage"].Value.ToString());
OutStgTran.Rollback();
}
else
{
MessageBox.Show("OK");
OutStgTran.Commit();
}
return;
}
}
else
{
MessageBox.Show("您沒有修改任何信息");
return;
}
}
catch(Exception ex)
{
MessageBox.Show("對不起,您輸入的設備號錯誤!!具體信息:"+ex.ToString());
if( OutStgTran != null )
{
OutStgTran.Rollback();
}
if( MyConn.State != ConnectionState.Closed)
{
MyConn.Close();
}
return;
}
}
private void cancel_button_Click(object sender, System.EventArgs e)
{
try
{
OSReport = (CurrencyManager)this.BindingContext[OutStgInfo];
OSReport.CancelCurrentEdit(); //取消編輯
MessageBox.Show("已經取消!");
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
return;
}
private void dataGrid1_Select(object sender, System.EventArgs e)//在數據集中選定記錄
{
if (this.OutStgInfo.Rows.Count > 0)
{
int currentRow = this.dataGrid1.CurrentCell.RowNumber;
if (currentRow >= 0 && currentRow < OSReport.Count)
OSReport.Position = currentRow;
this.oldtxtAmount=this.textAmount.Text.Trim();
this.textNum2.Enabled=false;
}
}
private void textAmount_Leave(object sender, System.EventArgs e)
{
string num="";
SqlDataAdapter sqlDataAdapter;
DataTable dtable=new DataTable();
if(this.textNum2.Text=="")
{
MessageBox.Show(" 請先輸入出庫的設備號!","提示",MessageBoxButtons.OK);
}
else
{
str = "select * from drivestorage where 設備號 like'"+this.textNum2.Text.ToString().Trim()+"%'";
sqlDataAdapter=new SqlDataAdapter(str,this.MyConn);
sqlDataAdapter.Fill(dtable);
if(dtable.Rows.Count>0)
{
num=dtable.Rows[0][1].ToString().Trim();
}
else
{
MessageBox.Show("沒有該商品!","提示",MessageBoxButtons.OK);
return;
}
if(this.textAmount.Text!="")
{
int Salnum = int.Parse(this.textAmount.Text.ToString().Trim());
int mernum = int.Parse(num);
if(Salnum>mernum)
{
MessageBox.Show("商品余額不足!","提示",MessageBoxButtons.OK);
}
else
{
}
}
else
{
MessageBox.Show("商品數量沒有填寫!","提示",MessageBoxButtons.OK);
}
}
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -