⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 outstorage.cs

📁 仓库管理系统源代码 c#+sql2000
💻 CS
📖 第 1 页 / 共 2 页
字号:
			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 + -