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

📄 frmupdatestock.cs

📁 本论文叙述了联机考试系统的现状以及C#语言的概况。重点介绍了联机考试系统的实现过程:包括系统分析、 系统调查、 数据流程分析、功能设计、 数据库设计、 系统物理配置方案、 系统实现、 系统测试和调试。
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.OleDb; 

namespace SupermarketProject
{
	/// <summary>
	/// Summary description for frmUpdateStock.
	/// </summary>

	public class frmUpdateStock : System.Windows.Forms.Form
	{
		
		private System.Windows.Forms.Button btnCancel;
		private System.Windows.Forms.Button btnOK;
		private System.Windows.Forms.TextBox txtPurPrice;
		private System.Windows.Forms.TextBox txtStockQty;
		private System.Windows.Forms.Label lblStockQty;
		private System.Windows.Forms.Label lblStkNo;
		private System.Windows.Forms.Label label6;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.DateTimePicker dtpStkDate;
		private System.Windows.Forms.TextBox txtStockId;
		private System.ComponentModel.IContainer components;
		private System.Windows.Forms.ErrorProvider errStock;
		private System.Windows.Forms.HelpProvider hlpUpdateStock;
		private System.Windows.Forms.ToolTip tipUpdateStock;

		//other variables
		public string errorMsg;
        private int stkid;
        private DataRow drStkBeforeUpdate;
     	private bool allValidated ;
		private System.Windows.Forms.Label lblStockDate;
		private System.Windows.Forms.Label lblPurPrice;
		private Settings settings;

		private DataRow drStk;

		public frmUpdateStock(int stkid)
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();
			settings =new Settings();
			
            this.hlpUpdateStock.HelpNamespace = 
				settings.uiDirectory+ @"\HELP\SupermarketHelp.chm"; 
			this.stkid =stkid;
			
		
	}


		/// <summary>

		/// Clean up any resources being used.

		/// </summary>

		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code

		/// <summary>

		/// Required method for Designer support - do not modify

		/// the contents of this method with the code editor.

		/// </summary>

		private void InitializeComponent()

		{
			this.components = new System.ComponentModel.Container();
			this.btnCancel = new System.Windows.Forms.Button();
			this.btnOK = new System.Windows.Forms.Button();
			this.txtStockId = new System.Windows.Forms.TextBox();
			this.txtPurPrice = new System.Windows.Forms.TextBox();
			this.txtStockQty = new System.Windows.Forms.TextBox();
			this.lblStockQty = new System.Windows.Forms.Label();
			this.lblStkNo = new System.Windows.Forms.Label();
			this.label6 = new System.Windows.Forms.Label();
			this.label5 = new System.Windows.Forms.Label();
			this.dtpStkDate = new System.Windows.Forms.DateTimePicker();
			this.lblStockDate = new System.Windows.Forms.Label();
			this.lblPurPrice = new System.Windows.Forms.Label();
			this.errStock = new System.Windows.Forms.ErrorProvider();
			this.hlpUpdateStock = new System.Windows.Forms.HelpProvider();
			this.tipUpdateStock = new System.Windows.Forms.ToolTip(this.components);
			this.SuspendLayout();
			// 
			// btnCancel
			// 
			this.btnCancel.Location = new System.Drawing.Point(442, 164);
			this.btnCancel.Name = "btnCancel";
			this.btnCancel.Size = new System.Drawing.Size(90, 43);
			this.btnCancel.TabIndex = 9;
			this.btnCancel.Text = "取消(&C)";
			this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
			// 
			// btnOK
			// 
			this.btnOK.Location = new System.Drawing.Point(326, 164);
			this.btnOK.Name = "btnOK";
			this.btnOK.Size = new System.Drawing.Size(90, 43);
			this.btnOK.TabIndex = 8;
			this.btnOK.Text = "确定(&O)";
			this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
			// 
			// txtStockId
			// 
			this.txtStockId.Location = new System.Drawing.Point(115, 34);
			this.txtStockId.Name = "txtStockId";
			this.txtStockId.ReadOnly = true;
			this.txtStockId.Size = new System.Drawing.Size(120, 21);
			this.txtStockId.TabIndex = 1;
			this.txtStockId.Text = "";
			// 
			// txtPurPrice
			// 
			this.txtPurPrice.Location = new System.Drawing.Point(115, 138);
			this.txtPurPrice.Name = "txtPurPrice";
			this.txtPurPrice.Size = new System.Drawing.Size(120, 21);
			this.txtPurPrice.TabIndex = 7;
			this.txtPurPrice.Text = "";
			this.txtPurPrice.MouseHover += new System.EventHandler(this.txtPurPrice_MouseHover);
			this.txtPurPrice.Leave += new System.EventHandler(this.txtPurPrice_Leave);
			// 
			// txtStockQty
			// 
			this.txtStockQty.Location = new System.Drawing.Point(384, 34);
			this.txtStockQty.Name = "txtStockQty";
			this.txtStockQty.Size = new System.Drawing.Size(120, 21);
			this.txtStockQty.TabIndex = 3;
			this.txtStockQty.Text = "";
			this.txtStockQty.MouseHover += new System.EventHandler(this.txtStockQty_MouseHover);
			this.txtStockQty.TextChanged += new System.EventHandler(this.txtStockQty_TextChanged);
			this.txtStockQty.Leave += new System.EventHandler(this.txtStockQty_Leave);
			// 
			// lblStockQty
			// 
			this.lblStockQty.Location = new System.Drawing.Point(298, 34);
			this.lblStockQty.Name = "lblStockQty";
			this.lblStockQty.Size = new System.Drawing.Size(57, 25);
			this.lblStockQty.TabIndex = 2;
			this.lblStockQty.Text = "数量";
			// 
			// lblStkNo
			// 
			this.lblStkNo.Location = new System.Drawing.Point(10, 34);
			this.lblStkNo.Name = "lblStkNo";
			this.lblStkNo.Size = new System.Drawing.Size(67, 25);
			this.lblStkNo.TabIndex = 0;
			this.lblStkNo.Text = "库存标识";
			// 
			// label6
			// 
			this.label6.Location = new System.Drawing.Point(-133, 148);
			this.label6.Name = "label6";
			this.label6.Size = new System.Drawing.Size(111, 24);
			this.label6.TabIndex = 23;
			this.label6.Text = "Stock Date";
			// 
			// label5
			// 
			this.label5.Location = new System.Drawing.Point(-133, 96);
			this.label5.Name = "label5";
			this.label5.Size = new System.Drawing.Size(133, 25);
			this.label5.TabIndex = 22;
			this.label5.Text = "Purchase Price";
			// 
			// dtpStkDate
			// 
			this.dtpStkDate.Location = new System.Drawing.Point(115, 95);
			this.dtpStkDate.Name = "dtpStkDate";
			this.dtpStkDate.Size = new System.Drawing.Size(240, 21);
			this.dtpStkDate.TabIndex = 5;
			this.dtpStkDate.MouseHover += new System.EventHandler(this.dtpStkDate_MouseHover);
			this.dtpStkDate.Leave += new System.EventHandler(this.dtpStkDate_Leave);
			// 
			// lblStockDate
			// 
			this.lblStockDate.Location = new System.Drawing.Point(10, 95);
			this.lblStockDate.Name = "lblStockDate";
			this.lblStockDate.Size = new System.Drawing.Size(96, 25);
			this.lblStockDate.TabIndex = 4;
			this.lblStockDate.Text = "库存日期";
			// 
			// lblPurPrice
			// 
			this.lblPurPrice.Location = new System.Drawing.Point(10, 138);
			this.lblPurPrice.Name = "lblPurPrice";
			this.lblPurPrice.Size = new System.Drawing.Size(96, 26);
			this.lblPurPrice.TabIndex = 6;
			this.lblPurPrice.Text = "购入价格";
			// 
			// errStock
			// 
			this.errStock.ContainerControl = this;
			// 
			// hlpUpdateStock
			// 
			this.hlpUpdateStock.HelpNamespace = "D:\\Project10102004\\HTM_FILES_FOR_HELP\\SUPERMARKETHELP.CHM";
			// 
			// frmUpdateStock
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(576, 229);
			this.Controls.Add(this.lblStockDate);
			this.Controls.Add(this.lblPurPrice);
			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.label6);
			this.Controls.Add(this.label5);
			this.Controls.Add(this.dtpStkDate);
			this.Name = "frmUpdateStock";
			this.Text = "更新库存";
			this.Load += new System.EventHandler(this.frmUpdateStock_Load);
			this.ResumeLayout(false);

		}

		#endregion

		public void ClearDetails()
		{
			this.txtPurPrice.Text = "";
			this.txtStockQty.Text = "";
			this.dtpStkDate.Value = DateTime.Today;
		}

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


		private void frmUpdateStock_Load(object sender, System.EventArgs e)
		{
			try
			{
				string commandText ="Select * from Stock where stockid = "+this.stkid;
				
				OleDbDataAdapter adapter = new OleDbDataAdapter(commandText,DataConnection.oleconn);
			
				DataSet dset=new DataSet();
				adapter.Fill(dset);
								
				DataRow currRow  = dset.Tables[0].Rows[0];

				txtStockId.Text  =  currRow[0].ToString();
				dtpStkDate.Value = (System.DateTime)currRow[3];
				txtPurPrice.Text = currRow[4].ToString();
				txtStockQty.Text = currRow[2].ToString();

				drStkBeforeUpdate  = dset.Tables[0].NewRow(); 
					
				drStkBeforeUpdate.ItemArray = currRow.ItemArray;

				drStk    = dset.Tables[0].NewRow(); 

			}
			catch(Exception excep)
			{
				MessageBox.Show ("发生错误  "+excep.Message.ToString ());
			}
		}

		//checks whether the characters in the entered string are numeric

		private bool chkNum(string str)
		{
			for(int i=0; i<str.Length;i++)
			{
				if(! Char.IsNumber(str,i))
				{
					return false;
				}
			}
			return true;
		}
		private void txtPurPrice_Leave(object sender, System.EventArgs e)
		{
			if(this.txtPurPrice.Text.Trim().Length == 0 || this.txtPurPrice.Text == "0")
			{
				errorMsg = "必须输入购入价格";
				this.errStock.SetError(this.txtPurPrice, errorMsg);
				this.txtPurPrice.Focus(); 
			}

			else if (! this.chkNum(this.txtPurPrice.Text))
			{

				errorMsg = "购入价格必须是数字";
				this.errStock.SetError(this.txtPurPrice, errorMsg);
				this.txtPurPrice.Focus(); 
			
			}

			else
			{
					errStock.SetError(txtPurPrice,"");
					this.allValidated = true;
			}
		}
		

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

			if (this.txtStockQty.Text.Trim().Length==0||this.txtStockQty.Text=="0")
			{
				errorMsg="必须输入数量";
				this.errStock.SetError(this.txtStockQty,errorMsg);
				this.txtStockQty.Focus(); 
			}

			else
			{
				if(!this.chkNum(this.txtStockQty.Text))
				{
					errorMsg="数量必须是数字";
					this.errStock.SetError(this.txtStockQty,errorMsg);
					this.txtStockQty.Focus(); 
				}
				else
				{
					this.allValidated = true;
					errStock.SetError(txtStockQty,"");
				}
			}
		}

		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,"");
				this.allValidated=true;
			}		
		}
		private void btnOK_Click(object sender, System.EventArgs e)
		{
			try
			{
				//to check if the data has been modified we store the data 
				//before updation into a datarow, and after updation into another datarow 
				//and compare the two
				drStk["StkDate"] = this.dtpStkDate.Value.Date; 
				drStk["PurPrice"]= this.txtPurPrice.Text; 
				drStk["Qty"]     = this.txtStockQty.Text;
				drStk["StockId"] = this.stkid;
				
				if (drStk["StkDate"].Equals(drStkBeforeUpdate["StkDate"]) &&   
					drStk["PurPrice"].Equals(drStkBeforeUpdate["PurPrice"]) && drStk["Qty"].Equals(drStkBeforeUpdate["Qty"]))
				{
					MessageBox.Show( "没有任何修改");
				}
				else
				{
				  StockManagement stkMgmt=new StockManagement();
				  stkMgmt.UpdateStock(drStk);
				  MessageBox.Show( "成功更新记录");
				  this.Close();
				}
							}
			catch(Exception excep)
			{
				MessageBox.Show ("发生错误  "+excep.Message.ToString ());
			}
		}

		private void txtPurPrice_MouseHover(object sender, System.EventArgs e)
		{
			this.tipUpdateStock.SetToolTip(this.txtPurPrice,"输入购入价格");
		
		}
		private void txtStockQty_MouseHover(object sender, System.EventArgs e)
		{
			this.tipUpdateStock.SetToolTip(this.txtStockQty,"输入库存数量");
		
		}

		private void dtpStkDate_MouseHover(object sender, System.EventArgs e)
		{
			this.tipUpdateStock.SetToolTip(this.dtpStkDate,"输入库存日期");
		
		}

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

		
	}
}

⌨️ 快捷键说明

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