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

📄 frmproductsales.cs

📁 本论文叙述了联机考试系统的现状以及C#语言的概况。重点介绍了联机考试系统的实现过程:包括系统分析、 系统调查、 数据流程分析、功能设计、 数据库设计、 系统物理配置方案、 系统实现、 系统测试和调试。
💻 CS
📖 第 1 页 / 共 3 页
字号:
							this.qoh = reader.GetInt32 (5);
						}
						else
						{
							MessageBox.Show("此产品无详细信息");
						}
					
						reader.Close();
						str="SELECT rate FROM productcategories WHERE catcode in (select catcode from products where productid='"+cboProductId.Text+"')";

						DataConnection.commnd.CommandText =str;
						reader = DataConnection.commnd.ExecuteReader(); 
						if (reader.Read())
						{
							//calculate saleprice as purchase price * rate
							salePrice= purPrice * reader.GetDecimal(0);
							txtSalePrice.Text =salePrice.ToString ();
						}
						reader.Close();
						this.txtQty.Focus();
					}
				}
			}
			catch(Exception excp)
			{
				MessageBox.Show("出错" + excp.Message.ToString());
				this.cboProductId.Text="";
				this.cboProductId.Focus();
			} 
		}
	
		

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

				if (txtQty.Text.Trim()=="")
				{
					errorMsg = "无效的值";
					// Set the ErrorProvider error with the text to display. 
					this.errProductSales.SetError(this.txtQty, errorMsg);
					this.txtQty.Focus(); 
				}

				else if (txtQty.Text.Trim() != "")
				{
					if (int.Parse(txtQty.Text) <=0 )
					{
						errorMsg = "Invalid value";
				// Set the ErrorProvider error with the text to display. 
					this.errProductSales.SetError(this.txtQty, errorMsg);
						this.txtQty.Focus(); 
					}

				this.btnSave.Enabled = true;
				this.btnPrint.Enabled = true;
                this.btnPreview.Enabled = true;

				items[0] = txtProductName.Text;
				items[1] = txtQty.Text;
				items[2] =salePrice.ToString();
				items[3] =totalPrice.ToString();
				ListViewItem lstvwItem =new ListViewItem(items);
				lvwBillDetails.Items.AddRange (new System.Windows.Forms.ListViewItem[] {lstvwItem});
				this.totalbillamt += Convert.ToDecimal (txtTotalPrice.Text);
							
				string str="SELECT stockid FROM stock WHERE productid='"+cboProductId.Text+"'";
				DataConnection.commnd.CommandText =str;
				reader = DataConnection.commnd.ExecuteReader(); 
					if (reader.Read())
					{
						this.stockid =reader.GetInt32 (0);			
						txtTotalBillAmt.Text =this.totalbillamt.ToString ();
			
						//populate bill details info
								
						drBillDet[index] = ds.Tables[1].NewRow(); 
						drBillDet[index]["BillNo"] = this.txtBillNo.Text;
						drBillDet[index]["StockId"] = this.stockid; 
						drBillDet[index]["Quantity"] = this.txtQty.Text; 
						drBillDet[index]["SalePrice"] = this.salePrice; 
			
						//increment counters for the next product
						index++;
						//increase the items in the shopping cart by 1
						prodCount++;
					}					
				}
				reader.Close ();
				this.ClearDetails ();
			}
			catch(Exception excep)
			{ 
				MessageBox.Show("发生错误  "+excep.Message.ToString());
				
			} 
		     }

		private void btnSave_Click(object sender, System.EventArgs e)
		{
			MessageBox.Show ("购物车内含有 "+prodCount.ToString ()+" 产品");
			try
			{
				//populate master bill info
				DataRow drBill;
				DataTable dtBill = ds.Tables[0];
					    		
				drBill = ds.Tables[0].NewRow(); 
				drBill["BillNo"] = this.billNo; 
				drBill["BillDate"] = this.txtBillDate.Text;  
				drBill["Usrid"] = txtUsrId.Text; 
				drBill["TotalBillAmt"] = Convert.ToDecimal (this.totalbillamt); 
				drBill["PaymentMode"] = this.cboPaymentMode.Text; 
				dtBill.Rows.Add(drBill);
			
				for (index = 0;index < prodCount; index++)
				{
					drBillDet[index].SetParentRow(drBill);
					ds.Tables[1].Rows.Add (drBillDet[index]);
				}
				TellerManagement teller =new TellerManagement();
			
				teller.SaveBill(ds);
				
				MessageBox.Show ("帐单已保存!");
				this.btnCancel.Text ="退出";
			}
		
			catch(Exception)
			{ 
				MessageBox.Show("发生错误,操作异常终止");				
			} 
			this.Close();
		}
		public void ClearDetails()
		{
			//clear the details so that the next product can be added
			this.txtProductName.Text = "";
			this.txtQty.Text = "";
			this.txtStockPrice.Text = "";
			this.txtDiscount.Text = "";
			this.txtSalePrice.Text = ""; 
			this.txtTotalPrice.Text = "";
			cboProductId.Text ="";
		}

		private void btnCancel_Click(object sender, System.EventArgs e)
		{
			this.errProductSales.SetError(this.cboProductId,"");
			this.errProductSales.SetError(this.txtQty,"");
			frmMainMenu.varPrdSales = 0;
				this.Close();
		}
					
		private void btnPrint_Click(object sender, System.EventArgs e)
		{
			try
			{
				pDocBill.DefaultPageSettings.Landscape = false;
				pDocBill.Print();
			}			
			catch(Exception excep)
			{
				MessageBox.Show("打印机设置不正确或者未安装。" +excep.Message.ToString());
			}

		}
		
		

		private void pDocBill_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs evt)
		{
	
			System.Drawing.Graphics gdiPage = evt.Graphics;
						
			Font boldFont,regularFont,headerFont,specialFont;
			
			//font for the main title
			boldFont = new Font("Tahoma",24,FontStyle.Bold);
            //change the font for the rest of the text
			regularFont =  new Font("Times New Roman",12);
			//change the font for the headers 
			headerFont = new Font("Times New Roman",12,FontStyle.Bold);
			//special font for some headers
            specialFont = new Font("Times New Roman",12,FontStyle.Bold| FontStyle.Italic);
			//get the margins of the print area			
			float leftMargin = evt.MarginBounds.Left;
			float topMargin = evt.MarginBounds.Top;
			float lineHeight = boldFont.GetHeight(gdiPage);
			float rightMargin = evt.MarginBounds.Right;
			float middle=(rightMargin-leftMargin)/2 -leftMargin;
			
			int lineCount = 0;
			float linesPerPage = evt.MarginBounds.Height/lineHeight;
			//print the header block for the bill
			gdiPage.DrawString(settings.supermarketName.Substring(5),boldFont, Brushes.Black,middle,topMargin+ lineCount*lineHeight);
			
			lineCount += 2;
			//print logo

			Image im = new Bitmap(settings.uiDirectory+@"\IMAGES\dragon.bmp");
			gdiPage.DrawImage(im,middle+100,topMargin + lineCount*lineHeight);
			lineCount += 6;
           //print the address						
			lineHeight = regularFont.GetHeight(gdiPage);
		    settings =new Settings();
			gdiPage.DrawString(settings.address,regularFont, Brushes.Black,leftMargin,topMargin+lineCount*lineHeight);
		
//print the phone and fax	
			
			gdiPage.DrawString(settings.phone,regularFont, Brushes.Black,rightMargin-50,topMargin+lineCount*lineHeight);
			lineCount += 6;

			string headerCol1, headerCol2, headerCol3;
			headerCol1 = "帐单编号: "+txtBillNo.Text.Trim();
			gdiPage.DrawString(headerCol1,headerFont, Brushes.Black,leftMargin,topMargin+lineCount*lineHeight);

			headerCol2 = "日期:"+txtBillDate.Text.Trim();
			gdiPage.DrawString(headerCol2,headerFont, Brushes.Black,leftMargin+headerCol1.Length+200,topMargin+lineCount*lineHeight);
			
			headerCol3 = "收银员标识:"+txtUsrId.Text.Trim();
			gdiPage.DrawString(headerCol3,headerFont, Brushes.Black,leftMargin+headerCol1.Length+headerCol2.Length+400,topMargin+lineCount*lineHeight);

			lineCount+=2;
			gdiPage.DrawString("购买信息:",specialFont, Brushes.Black,leftMargin,topMargin+lineCount*lineHeight);
			lineCount+=2;
			Pen pen = new Pen(Brushes.Black);
            Point point1 = new Point(Convert.ToInt32(leftMargin),Convert.ToInt32(topMargin+lineCount*lineHeight));
            Point point2=new Point(Convert.ToInt32(rightMargin),Convert.ToInt32(topMargin+lineCount*lineHeight));

			gdiPage.DrawLine(pen,point1,point2);
            lineCount+=2;
			//print the header row of the listview
			float nextColumnPosition = leftMargin;
			for (int col = 0;col < lvwBillDetails.Columns.Count; col++)
			{
				gdiPage.DrawString(lvwBillDetails.Columns[col].Text, headerFont, Brushes.Black,nextColumnPosition,topMargin+lineCount*lineHeight);
				nextColumnPosition += lvwBillDetails.Columns[col].Width;
			}
				
	         lineCount+=2;
			//print the contents of the listview
			foreach(Control ctl in this.Controls)
			{
				if (ctl.GetType() == this.lvwBillDetails.GetType())
				{
					for (int row = 0; row < lvwBillDetails.Items.Count;                     row++)
					{
						nextColumnPosition = leftMargin;
						
						for (int col = 0;col < lvwBillDetails.Items[row].SubItems.Count; col++)
						{
							gdiPage.DrawString(lvwBillDetails.Items[row].SubItems[col].Text, regularFont, Brushes.Black,nextColumnPosition,topMargin+lineCount*lineHeight);
							nextColumnPosition += lvwBillDetails.Columns[col].Width;
						}
						lineCount+=3;
					}
				}
			}
			lineCount+=2;
			point1=new Point(Convert.ToInt32(leftMargin),Convert.ToInt32(topMargin+lineCount*lineHeight));
			point2=new Point(Convert.ToInt32(rightMargin),Convert.ToInt32(topMargin+lineCount*lineHeight));
			gdiPage.DrawLine(pen,point1,point2);
			lineCount += 2;
			
			gdiPage.DrawString("总额",headerFont, Brushes.Black,leftMargin,topMargin+lineCount*lineHeight);
			gdiPage.DrawString(this.txtTotalBillAmt.Text,headerFont, Brushes.Black,leftMargin+200,topMargin+lineCount*lineHeight);
		}

		private void txtQty_Leave(object sender, System.EventArgs e)
		{
			if (txtQty.Text.Trim() != "")
			{
				if (int.Parse(txtQty.Text) <=0 )
				{
					errorMsg = "无效的值";
					// Set the ErrorProvider error with the text to display. 
					this.errProductSales.SetError(this.txtQty, errorMsg);
					this.txtQty.Focus(); 
				}

				if (int.Parse(txtQty.Text) >0 )
				{
					int qty = int.Parse(txtQty.Text);
					if (qty > qoh)
					{
						MessageBox.Show ("交易数量不能超过所持有数量");
						this.txtQty.Text="";
						this.txtQty.Focus();  					
					}
					else
					{
						this.errProductSales.SetError(this.txtQty, "");
						this.btnAddItem.Enabled =true; 
						
						//calculate total price
						totalPrice = int.Parse(txtQty.Text)*salePrice; 
			
						//check if discount is valid for current date	
			
						if ( DateTime.Compare(validFrom,DateTime.Today) <0 && DateTime.Compare(DateTime.Today, validTo)<0) 
						{
							//calculate total price after discount
							totalPrice =  totalPrice - ((this.discount/100)*totalPrice); 
						}
						//display total price
						txtTotalPrice.Text = totalPrice.ToString ();
						this.btnAddItem.Focus();  					
					}
				}
			}
		}

		private void frmProductSales_Closing(object sender, System.ComponentModel.CancelEventArgs e)
		{
			frmMainMenu.varPrdSales = 0;
		}

		private void cboProductId_MouseHover(object sender, System.EventArgs e)
		{
		this.tipProdSales.SetToolTip(this.cboProductId,"选择产品标识");	
		}

		private void txtQty_MouseHover(object sender, System.EventArgs e)
		{
		this.tipProdSales.SetToolTip(this.txtQty ,"选择产品数量");	
		}

		private void btnAddItem_MouseHover(object sender, System.EventArgs e)
		{
		this.tipProdSales.SetToolTip(this.btnAddItem,"向购物车中天家更多的产品");	
		}

		private void cboPaymentMode_MouseHover(object sender, System.EventArgs e)
		{
this.tipProdSales.SetToolTip(this.cboProductId,"选择付款方式");			
		}

		private void btnSave_MouseHover(object sender, System.EventArgs e)
		{
	this.tipProdSales.SetToolTip(this.cboProductId,"保存购入记录");		
		}

		private void btnPreview_Click(object sender, System.EventArgs e)
		{
			ppdlgBill.ShowDialog();
			
		}
}

 }

⌨️ 快捷键说明

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