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

📄 inputform.cs

📁 超市管理系统的完整版文档
💻 CS
📖 第 1 页 / 共 2 页
字号:
		#endregion

		private void textBox5_TextChanged(object sender, System.EventArgs e)
		{
		
		}

		private void label2_Click(object sender, System.EventArgs e)
		{
		
		}

		private void label3_Click(object sender, System.EventArgs e)
		{
		
		}

		private void m_bntExit_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}

		private void m_bntClear_Click(object sender, System.EventArgs e)
		{
			txtclear();
		}

		private bool formatcheck()
		{
			if(this.m_txtGoodsCode.Text == "")
			        { MessageBox.Show("商品条码不能为空");return false;}
				
			if(this.m_txtGoodsName.Text == "")
				 	{ MessageBox.Show("商品名称不能为空");return false;}

			if(this.m_txtInprice.Text == "")
					{ MessageBox.Show("商品进价不能为空");return false;}

			if(this.m_txtNumber.Text == "")
					{ MessageBox.Show("进货数目不能为空");return false;}

			if (this.m_txtSupplierID.Text == "")
					{ MessageBox.Show("提供商标识不能为空");return false;}
		   
			return true;
		}

		private void m_bntInput_Click(object sender, System.EventArgs e)
		{

			if(formatcheck())
			{

               string GoodsName = this.m_txtGoodsName.Text;
			   string GoodsCode = this.m_txtGoodsCode.Text;
			   int  num = System.Convert.ToInt32(this.m_txtNumber.Text);
			   string price = this.m_txtInprice.Text;
			   string remark = this.m_txtRemark.Text;
			   string supplierID = this.m_txtSupplierID.Text;
			   string unit = this.m_txtUnit.Text;

               string goodsId ="";
			    
				try
				{
					SqlConnection conn = DBUtil.GetConnection();

					SqlCommand command = new SqlCommand ("select * from goods where GoodsCode='"+GoodsCode+"'",conn);
					command.Connection.Open();

					SqlDataReader  readerset = command.ExecuteReader();
				
					if(readerset.Read())
					{   
                        
						int stocknum =System.Convert.ToInt32(readerset["StockNumber"].ToString());

						command.Connection.Close();

                        int newnum  = num + stocknum;
                      
                        command.CommandText="Update Goods Set "+
							                "GoodsName='"+ GoodsName +"'"+
							                 ",PurchasePrice="+ price+
                                             ",StockNumber=" + newnum.ToString() + 
							                 ",Remark='"+remark+"'"+
							                 ",SupplierID="+supplierID+
											 " where GoodsCode='"+GoodsCode+"'";
					   command.Connection.Open();
					   int res = command.ExecuteNonQuery();  
					   
					}
					else
					{
					   
                        command.Connection.Close();

						command.CommandText="Insert into Goods (GoodsCode,GoodsName,PurchasePrice,StockNumber,Remark,SupplierID,Unit) values ("+
							                "'"+GoodsCode+"'"+
							                ",'"+ GoodsName +"'"+
							                ","+price+
								            "," + num.ToString() + 
								            ",'"+remark+"'"+
								            ","+supplierID+
											",'"+unit+"'"+
								            ")";
						command.Connection.Open();
						int res = command.ExecuteNonQuery();  
                 
						

					}
                   
                    command.CommandText= "select * from Goods where GoodsCode='"+GoodsCode+"'"; 

					

					SqlDataReader  readerset2 = command.ExecuteReader();

					if(readerset2.Read())
					{
					   
					   goodsId = readerset2["GoodsID"].ToString();
					}

                   
					command.Connection.Close();

					command.CommandText="Insert into PurchaseRecord (GoodsID,PurchaserID,SupplierID,PurchaseUnitPrice,PurchaserNumber) values ("+
						                 goodsId.ToString()+
                                         ","+DBUtil.GetEmployeeID().ToString()+
						                 ","+supplierID+
                                         ","+price+
                                         ","+num.ToString()+")";
                   command.Connection.Open();
                   int  res2 = command.ExecuteNonQuery();  
				   command.Connection.Close();
				}
				catch(SqlException ex)
				{
					string s = ex.ToString();
					int wait =1;
				}

				txtclear();
			    MessageBox.Show("商品录入成功");
			}
		
		}

		private void m_txtGoodsCode_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
		{

			if (e.KeyChar != 13 && e.KeyChar != 8 && e.KeyChar!=22 && (e.KeyChar < '0'|| e.KeyChar > '9'))
			{				
				e.Handled = true;
			}

			if(e.KeyChar == 13)
			{  
				e.Handled = true;
				OnGoodsCodeEnter();
			}

		}


		private void OnGoodsCodeEnter()
		{
			string enterGoodsCode = this.m_txtGoodsCode.Text;
            		
            
			try
			{
				SqlConnection conn = DBUtil.GetConnection();

				SqlCommand command = new SqlCommand ("select * from goods where GoodsCode='"+enterGoodsCode+"'",conn);
				command.Connection.Open();

				SqlDataReader  readerset = command.ExecuteReader();
				
				if(readerset.Read())
				{
                   this.m_txtGoodsName.Text = readerset["GoodsName"].ToString();
				   this.m_txtRemark.Text = readerset["remark"].ToString();
				   this.m_txtSupplierID.Text = readerset["SupplierID"].ToString();
				   this.m_txtInprice.Text = readerset["PurchasePrice"].ToString();
					this.m_txtUnit.Text = readerset["Unit"].ToString();
                   
				}
				else
				{
					
				}

				
				command.Connection.Close();
			}
			catch(SqlException ex)
			{
				string s = ex.ToString();
				MessageBox.Show(s);
			}
		
		}

		private void label8_Click(object sender, System.EventArgs e)
		{
		
		}

		private void txtclear()
		{
			this.m_txtGoodsCode.Text = "";
			this.m_txtGoodsName.Text = "";
			this.m_txtInprice.Text = "";
			this.m_txtNumber.Text = "";
			this.m_txtRemark.Text = "";
			this.m_txtSupplierID.Text = "";
			this.m_txtUnit.Text = "";
			this.m_txtUnit.Text = "";
		}

		private void m_bntCheck_Click(object sender, System.EventArgs e)
		{
            
			string supplierID = this.m_txtSupplierID.Text;
			if(supplierID=="")
			{
				MessageBox.Show("被检测供应商号不能为空");
				return;
			}

			try
			{
				SqlConnection conn = DBUtil.GetConnection();

				SqlCommand command = new SqlCommand ("select * from supplier where SupplierID="+supplierID,conn);
				command.Connection.Open();

				SqlDataReader  readerset = command.ExecuteReader();
				
				if(readerset.Read())
				{   
                        MessageBox.Show("有效供应商号");
					    command.Connection.Close();
					    return ;
				        
			    }
				else
				{				
                         MessageBox.Show("无效供应商号");
					    command.Connection.Close();
					    return ;
				}
                   
				
			}catch(SqlException ex)
			{
				string s = ex.ToString();
				MessageBox.Show(s);
				
			}
		    
		}

		private void m_txtInprice_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
		{
			if (e.KeyChar != '.' && e.KeyChar != 8 && e.KeyChar!=22 && (e.KeyChar < '0'|| e.KeyChar > '9'))
			{				
				e.Handled = true;
			}

			
		}

		private void m_txtNumber_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
		{

			if ( e.KeyChar != 8 && e.KeyChar!=22 && (e.KeyChar < '0'|| e.KeyChar > '9'))
			{				
				e.Handled = true;
			}
		
		}

		private void m_txtSupplierID_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
		{
			if ( e.KeyChar != 8 && e.KeyChar!=22 && (e.KeyChar < '0'|| e.KeyChar > '9'))
			{				
				e.Handled = true;
			}
		}


	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -