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

📄 frmaddstock.cs

📁 本论文叙述了联机考试系统的现状以及C#语言的概况。重点介绍了联机考试系统的实现过程:包括系统分析、 系统调查、 数据流程分析、功能设计、 数据库设计、 系统物理配置方案、 系统实现、 系统测试和调试。
💻 CS
📖 第 1 页 / 共 2 页
字号:
			this.btnOK.Text = "确定(&O)";
			this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
			this.btnOK.MouseHover += new System.EventHandler(this.btnOK_MouseHover);
			// 
			// btnCancel
			// 
			this.btnCancel.Location = new System.Drawing.Point(566, 448);
			this.btnCancel.Name = "btnCancel";
			this.btnCancel.Size = new System.Drawing.Size(90, 34);
			this.btnCancel.TabIndex = 14;
			this.btnCancel.Text = "取消(&C)";
			this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
			this.btnCancel.MouseHover += new System.EventHandler(this.btnCancel_MouseHover);
			// 
			// dtpStkDate
			// 
			this.dtpStkDate.Location = new System.Drawing.Point(125, 396);
			this.dtpStkDate.Name = "dtpStkDate";
			this.dtpStkDate.Size = new System.Drawing.Size(240, 21);
			this.dtpStkDate.TabIndex = 10;
			this.dtpStkDate.MouseHover += new System.EventHandler(this.dtpStkDate_MouseHover);
			this.dtpStkDate.Leave += new System.EventHandler(this.dtpStkDate_Leave);
			// 
			// errStock
			// 
			this.errStock.ContainerControl = this;
			// 
			// lblProdCatTitle
			// 
			this.lblProdCatTitle.Location = new System.Drawing.Point(19, 26);
			this.lblProdCatTitle.Name = "lblProdCatTitle";
			this.lblProdCatTitle.Size = new System.Drawing.Size(221, 25);
			this.lblProdCatTitle.TabIndex = 0;
			this.lblProdCatTitle.Text = "产品类别";
			this.lblProdCatTitle.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// lblProdTitle
			// 
			this.lblProdTitle.Location = new System.Drawing.Point(355, 26);
			this.lblProdTitle.Name = "lblProdTitle";
			this.lblProdTitle.Size = new System.Drawing.Size(120, 25);
			this.lblProdTitle.TabIndex = 1;
			this.lblProdTitle.Text = "产品标识";
			this.lblProdTitle.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// hlpStock
			// 
			this.hlpStock.HelpNamespace = "";
			// 
			// tipStock
			// 
			this.tipStock.AutomaticDelay = 150;
			// 
			// frmAddStock
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(700, 487);
			this.Controls.Add(this.lblProdTitle);
			this.Controls.Add(this.lblProdCatTitle);
			this.Controls.Add(this.panel1);
			this.Controls.Add(this.btnCancel);
			this.Controls.Add(this.btnOK);
			this.Controls.Add(this.txtStockId);
			this.Controls.Add(this.txtPurPrice);
			this.Controls.Add(this.txtStockQty);
			this.Controls.Add(this.lblStockQty);
			this.Controls.Add(this.lblStkNo);
			this.Controls.Add(this.lblStkDate);
			this.Controls.Add(this.lblPurPrice);
			this.Controls.Add(this.lvwProd);
			this.Controls.Add(this.tvwCatCode);
			this.Controls.Add(this.dtpStkDate);
			this.Name = "frmAddStock";
			this.Text = "添加库存";
			this.Load += new System.EventHandler(this.frmAddStock_Load);
			this.panel1.ResumeLayout(false);
			this.ResumeLayout(false);

		}

		#endregion

		public string errorMsg;


		private void frmAddStock_Load(object sender, System.EventArgs e)
		{
			try
			{
				this.dtpStkDate.Enabled=false;
				this.txtPurPrice.Enabled=false;
                this.txtStockQty.Enabled=false;
				DataConnection.commnd.CommandText ="Select catcode,flvlcatcode from productcategories order by flvlcatcode";
				
				OleDbDataReader reader = DataConnection.commnd.ExecuteReader();
				if (reader.HasRows)
				{
					//create root node
					TreeNode node=tvwCatCode.Nodes.Add("产品类别");
					TreeNode newNode=new TreeNode ();
					string current,parent;
				
					while(reader.Read ())
					{
						current=reader.GetString(0);
						parent=reader.GetString(1);
						if(parent.Equals ("00"))
						{
							newNode=new TreeNode (current);
							node.Nodes.Add(newNode); 
						}
						else
						{
							TreeNode tn=tvwCatCode.TopNode; 
							foreach(TreeNode nd in node.Nodes)
							{
								if (nd.Text.Equals(parent))
								{
									newNode=new TreeNode (current);
									nd.Nodes.Add (current);
								}
								foreach(TreeNode nd2 in nd.Nodes)
								{
									if (nd2.Text.Equals (parent))

									{

										newNode=new TreeNode (current);
										nd2.Nodes.Add (current);
									}
								}
							}
						}
					}//end while
				}
				reader.Close();
			}
			catch(Exception excep)
			{
				MessageBox.Show("发生错误 "+excep.Message.ToString ());
			}
		}

		private void tvwCatCode_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)

		{
			try
			{
				lvwProd.Clear ();

				catCode = tvwCatCode.SelectedNode.Text;  

				
				DataConnection.commnd.CommandText = "Select productid from products where catcode='"+catCode+"'";

				OleDbDataReader reader = DataConnection.commnd.ExecuteReader();

				while(reader.Read ())
				{
					lvwProd.Items.Add (reader.GetString(0));
				}
				reader.Close();
			}

			catch(Exception excep)
			{
				MessageBox.Show("发生错误 "+excep.Message.ToString ());
			}
		}
		private void lvwProd_Click(object sender, System.EventArgs e)
		{

			try
			{
				prodId = lvwProd.SelectedItems[0].Text; 
				DataConnection.commnd.CommandText = "Select * from products where ProductId='"+prodId+"'";
				OleDbDataReader reader = DataConnection.commnd.ExecuteReader();

				reader.Read ();
				txtProdName.Text =reader.GetString (1);
				txtProdDesc.Text =reader.GetString (3);
				txtQty.Text=reader.GetInt32(4).ToString ();  
				txtProdCat.Text =reader.GetString (6);
            
				this.dtpStkDate.Enabled =true;
				this.txtStockQty.Enabled =true;
				this.txtPurPrice.Enabled=true; 
				
				
				reader.Close ();
				DataConnection.commnd.CommandText ="Select max(Stockid) from Stock";

				reader = DataConnection.commnd.ExecuteReader();
                reader.Read();
				int stkid;  
				if (!reader.IsDBNull(0))
					stkid = (reader.GetInt32(0));
				else
					stkid = 0;
					
				stkid = stkid + 1;

			    this.txtStockId.Text= stkid.ToString();
				reader.Close();
			}
			catch(Exception excep)
			{
				MessageBox.Show("发生错误 "+excep.Message.ToString ());
			}
		}

		private void btnOK_Click(object sender, System.EventArgs e)

		{
	        foreach (Control ctrl in this.Controls)
			{
				if (ctrl.GetType().ToString() == "System.Windows.Forms.TextBox") 
				{
					if (ctrl.Text.Trim() =="")
						this.allValidated = false;
				}
				else
				{
					if (this.dtpStkDate.Value.Date.CompareTo(DateTime.Today.Date) > 0) 
						this.allValidated = false;
				}
					
			}
			try
			{
				if (allValidated)
				{
					DataConnection.commnd.CommandText ="Select * from Stock where productid='"+this.prodId+"'" ;

					OleDbDataAdapter adapter=new OleDbDataAdapter (DataConnection.commnd            .CommandText,DataConnection.oleconn);
					DataSet ds = new  DataSet();
					adapter.Fill (ds);
					DataRow drStk = ds.Tables[0].NewRow(); 
                    drStk["StockId"]=Convert.ToInt32(this.txtStockId.Text);
					drStk["ProductId"]=this.prodId.ToString();
					drStk["StkDate"]=this.dtpStkDate.Value.Date.ToString();  
					drStk["PurPrice"]=this.txtPurPrice.Text; 
					drStk["Qty"]=this.txtStockQty.Text;
					
					StockManagement stkMgmt=new StockManagement();
					stkMgmt.AddStock(drStk);
					MessageBox.Show ("成功添加记录");
					this.ClearDetails ();
					this.Close ();
				}
				else
                     MessageBox.Show ("不能添加...为完成详细信息");
			}
			catch(Exception excep)
			{
				MessageBox.Show("发生错误 "+excep.Message.ToString ());
			}
		}
		public void ClearDetails()

		{
			this.txtPurPrice.Text = "";
			this.txtStockQty.Text = "";
			this.dtpStkDate.Value = DateTime.Today;
			this.txtProdName.Text = "";
			this.txtProdDesc.Text = "";
			this.txtQty.Text = "";
			this.txtProdCat.Text = "";
		}


		private bool chkNum(string str)

		{

			for(int i=0; i<str.Length;i++)
			{
				if(! Char.IsNumber(str,i))
				{
					return false;
				}
			}
			return true;
		}
		private void txtStockQty_Leave(object sender, System.EventArgs e)
		{
			if(this.txtStockQty.Text.Trim().Length == 0 || this.txtStockQty.Text == "0")
			{
				errorMsg = "必须输入数量";
                
				// Set the ErrorProvider error with the text to display. 
				this.errStock.SetError(this.txtStockQty, errorMsg);
				this.txtStockQty.Focus(); 
			}

			else
			{
				if (! this.chkNum(this.txtStockQty.Text))
				{
				
					errorMsg = "请输入有效的数量值。";
					// Set the ErrorProvider error with the text to display.
					this.errStock.SetError(this.txtStockQty, errorMsg);
					this.txtStockQty.Focus(); 
				}
				else
				{
					errStock.SetError(txtStockQty,"");
					allValidated=true;
                
				}

			}
		}

		private void btnCancel_Click(object sender, System.EventArgs e)
		{
			
			errStock.SetError(this.txtPurPrice,"");
			errStock.SetError(this.txtStockQty,"");
			errStock.SetError(this.dtpStkDate,"");
			this.Close ();
		}

		private void dtpStkDate_Leave(object sender, System.EventArgs e)
		{
			if (this.dtpStkDate.Value.Date.CompareTo (DateTime.Today.Date) > 0)  
			{
				errorMsg = ("输入有效的日期值");
				this.errStock.SetError(this.dtpStkDate, errorMsg);
				this.dtpStkDate.Focus();	
			}
			else
			{
				errStock.SetError(this.dtpStkDate,"");
				allValidated=true;
			}
		}

		private void tvwCatCode_MouseHover(object sender, System.EventArgs e)
		{
			this.tipStock.SetToolTip(this.tvwCatCode,"类别代码树,方便您的选择");	
		}

		private void lvwProd_MouseHover(object sender, System.EventArgs e)
		{
			this.tipStock.SetToolTip(this.lvwProd,"所选类别的产品列表");
		}

		private void txtPurPrice_MouseHover(object sender, System.EventArgs e)
		{
			this.tipStock.SetToolTip(this.txtPurPrice ,"输入库存的购入价格");	
		}

		private void txtStockQty_MouseHover(object sender, System.EventArgs e)
		{
			this.tipStock.SetToolTip(this.txtQty, "输入库存的数量");	
		}

		private void dtpStkDate_MouseHover(object sender, System.EventArgs e)
		{
			this.tipStock.SetToolTip(this.dtpStkDate ,"选择库存日期");	}

		private void btnOK_MouseHover(object sender, System.EventArgs e)
		{
			this.tipStock.SetToolTip(this.btnOK ,"添加记录");	
		}

		private void btnCancel_MouseHover(object sender, System.EventArgs e)
		{
			this.tipStock.SetToolTip(this.btnCancel ,"不添加退出");	
		
		}

		private void txtPurPrice_Leave(object sender, System.EventArgs e)
		{
			if(this.txtPurPrice.Text.Trim().Length == 0 || this.txtPurPrice.Text == "0")
			{
				errorMsg = "必须输入购入价格";
				// Set the ErrorProvider error with the text to display. 
				this.dtpStkDate.Enabled = false;
				this.errStock.SetError(this.txtPurPrice, errorMsg);
				this.txtPurPrice.Focus();
			}

			else 
			{ 
				if (! this.chkNum(this.txtPurPrice.Text))
				{
				errorMsg = "请输入有效的购入价格值。";
				// Set the ErrorProvider error with the text to display. 
					this.dtpStkDate.Enabled = false;
				this.errStock.SetError(this.txtPurPrice, errorMsg);
				this.txtPurPrice.Focus();
				}
				else
				{
					errStock.SetError(txtPurPrice,"");
					this.dtpStkDate.Enabled = true;
					allValidated=true;
				}
			}
		}
	
	}
}

⌨️ 快捷键说明

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