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

📄 frmstockmanagement.cs

📁 本论文叙述了联机考试系统的现状以及C#语言的概况。重点介绍了联机考试系统的实现过程:包括系统分析、 系统调查、 数据流程分析、功能设计、 数据库设计、 系统物理配置方案、 系统实现、 系统测试和调试。
💻 CS
📖 第 1 页 / 共 2 页
字号:
			// frmStockManagement
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 14);
			this.ClientSize = new System.Drawing.Size(784, 421);
			this.Controls.Add(this.dbgItemsList);
			this.Controls.Add(this.panel2);
			this.Controls.Add(this.panel1);
			this.Font = new System.Drawing.Font("Times New Roman", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.Name = "frmStockManagement";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "库存管理";
			this.Closing += new System.ComponentModel.CancelEventHandler(this.frmStockManagement_Closing);
			this.Load += new System.EventHandler(this.frmStockManagement_Load);
			this.Paint += new System.Windows.Forms.PaintEventHandler(this.frmStockManagement_Paint);
			this.panel1.ResumeLayout(false);
			this.panel2.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.dbgItemsList)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion

		private void btnSearch_Click(object sender, System.EventArgs e)
		{
			try
			{
				//if the ProductName textbox is not null
				if(this.txtProdName.Text!="")
				{
					searchvalue[0] =  this.txtProdName.Text;
				}
				else
				{
					//Setting the first array to null
					searchvalue[0] = "";
				}

				//if the second field (Combobox) is not null
				if(this.cboCatTitle.Text!="")
				{
					searchvalue[1] =  this.cboCatTitle.Text;
				}
				else
				{
					searchvalue[1] = "";
				}
				

				//if the third field is not null
				if(this.dtpStkDate.Enabled)
				{
				searchvalue[2] =  this.dtpStkDate.Value.ToShortDateString();
				}
				else
				{
					searchvalue[2] = "";
				}
				
		
				//Create an Object of StockManagement
				StockManagement stkmgmt = new StockManagement();

				//Counting the number of values fetched from the database 
				// and specifying the datasource
				DataTable stockDetails  = stkmgmt.FetchStockDetails(searchvalue);
				if(stockDetails.Rows.Count >0)
				{
					this.dbgItemsList.DataSource = stockDetails;
					this.btnUpdate.Enabled       = true; 
                    this.btnPrint.Enabled        = true; 
					this.btnPrintPreview.Enabled = true; 
				}

				else
				{ 
					// If No records are fetched clearing the Datagrid and setting 
					// the datasource as null
					this.dbgItemsList.DataSource = null;
					MessageBox.Show("未找到任何记录");
				}
			}
			catch(Exception excep)
			{
				MessageBox.Show ("发生错误  "+excep.Message.ToString ());
			}
		}

		private void frmStockManagement_Load(object sender, System.EventArgs e)
		{
			populateComboBox();
		}

		private void btnExit_Click(object sender, System.EventArgs e)
		{
			try
			{
			
				frmMainMenu.varStkMgmt = 0;
				this.Close();
			}
			catch(Exception excep)
			{
				MessageBox.Show ("发生错误  "+excep.Message.ToString ());
			}
		}
		private void btnUpdate_Click(object sender, System.EventArgs e)
		{
			if (this.stkid != 0)
			{
				frmUpdateStock fUpdateStock = new frmUpdateStock(stkid);
				fUpdateStock.MdiParent = this.ParentForm;
				fUpdateStock.Show();
				

			}
		}

		private void btnNew_Click(object sender, System.EventArgs e)
		{
			try
			{
				frmAddStock fAddStock=new frmAddStock();
				fAddStock.MdiParent = this.ParentForm;
				fAddStock.Show();
				searchvalue[0]="";
				searchvalue[1]="";
				searchvalue[2] =  this.dtpStkDate.Value.ToShortDateString();
				
			}
			catch(Exception excep)
			{
				MessageBox.Show ("发生错误  "+excep.Message.ToString ());
			}
		}
		private void dbgItemsList_CurrentCellChanged(object sender, System.EventArgs e)
		{
			try
			{	
				DataTable dtStock =(DataTable)dbgItemsList.DataSource; 
			
				DataRow drStock = dtStock.Rows[dbgItemsList.CurrentRowIndex];  

				this.stkid = int.Parse (drStock[0].ToString()) ;		
			}
			catch(Exception excep)
			{
				MessageBox.Show ("发生错误  "+excep.Message.ToString ());
			}
		}
		private void frmStockManagement_Closing(object sender, System.ComponentModel.CancelEventArgs e)
		{
			frmMainMenu.varStkMgmt = 0;
		}

		private void chkDate_CheckedChanged(object sender, System.EventArgs e)
		{
			if (this.chkDate.Checked) 
			{
				this.lblStkDate.Enabled=true; 
				this.dtpStkDate.Enabled=true;
			}
			else
			{
				if (this.lblStkDate.Enabled)
				{
					this.lblStkDate.Enabled=false; 
					this.dtpStkDate.Enabled=false; 
				}
			}
		}	
		public void populateComboBox()
		{
			try
			{
				//check if combobox already has items, if yes clear all items and                    //re-populate again
				
				if (this.cboCatTitle.Items.Count >0)
				{
					this.cboCatTitle.Items.Clear ();
				}
				//Populate combobox - Category Title
				DataConnection.commnd.CommandText="select distinct CatTitle from ProductCategories";
				OleDbDataReader reader = DataConnection.commnd.ExecuteReader();
				while(reader.Read())
				{
					this.cboCatTitle.Items.Add(reader.GetString(0));
				}
				reader.Close();
			}
			catch(Exception excep)
			{
				MessageBox.Show ("发生错误  "+excep.Message.ToString ());
			}
		}

		private void txtProdName_MouseHover(object sender, System.EventArgs e)
		{
			this.tipStockMgmt.SetToolTip(this.txtProdName ,"选择产品名称用来搜索...(可选)");	
		
		}

		private void cboCatTitle_MouseHover(object sender, System.EventArgs e)
		{
			this.tipStockMgmt.SetToolTip(this.cboCatTitle ,"选择类别名称用来搜索...(可选)");	
		
		}

		private void chkDate_MouseHover(object sender, System.EventArgs e)
		{
			this.tipStockMgmt.SetToolTip(this.chkDate,"点击这里将包括日期搜索");	
		
		}

		private void dtpStkDate_MouseHover(object sender, System.EventArgs e)
		{
		this.tipStockMgmt.SetToolTip(this.btnPrint,"选择产品名称用来搜索...(可选)");
		}

		private void dbgItemsList_MouseHover(object sender, System.EventArgs e)
		{
		this.tipStockMgmt.SetToolTip(this.btnPrint,"如果要更新信息,从这里选择记录");	
		}

		private void btnNew_MouseHover(object sender, System.EventArgs e)
		{
		this.tipStockMgmt.SetToolTip(this.btnNew,"添加新库存");	
		}

		private void btnUpdate_MouseHover(object sender, System.EventArgs e)
		{
			this.tipStockMgmt.SetToolTip(this.btnUpdate,"更新库存信息");	
		
		}

		private void btnPrint_Click(object sender, System.EventArgs e)
		{
			try
			{
				/*DataTable dt=(DataTable)this.dbgItemsList.DataSource; 
				dataGridPrinter = new DataGridPrinter(this.dbgItemsList, pDoc,dt);
				dataGridPrinter.PageNumber = 1;
				dataGridPrinter.RowCount = 0;*/
				if (pdlgStock.ShowDialog() == DialogResult.OK)
				{
					pDoc.Print();
				}
			}
			catch(Exception excep)
			{
				MessageBox.Show("打印时发生错误" +excep.Message.ToString());
			}
			}
		private void pDoc_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
		{
			try
			{
				DataTable dt=(DataTable)this.dbgItemsList.DataSource; 
				dataGridPrinter = new DataGridPrinter(this.dbgItemsList, pDoc,dt);
				dataGridPrinter.PageNumber = 1;
				dataGridPrinter.RowCount = 0;

				Graphics	g = e.Graphics;
				DrawTopLabel(g);
				bool more = dataGridPrinter.DrawDataGrid(g);
				if (more == true)
				{
					e.HasMorePages = true;
					dataGridPrinter.PageNumber++;
				}
			}
		
			catch(Exception excep)
			{
				MessageBox.Show("打印时发生错误 " +excep.Message.ToString());
			}
		}
		void DrawTopLabel(Graphics g)
		{
			int TopMargin = pDoc.DefaultPageSettings.Margins.Top;
            lblHeading.Text ="库存信息";
			g.FillRectangle(new SolidBrush(lblHeading.BackColor), lblHeading.Location.X, lblHeading.Location.Y + TopMargin, lblHeading.Size.Width, lblHeading.Size.Height);
			g.DrawString(lblHeading.Text, lblHeading.Font, new SolidBrush(lblHeading.ForeColor), lblHeading.Location.X + 50, lblHeading.Location.Y + TopMargin, new StringFormat());
		}

		private void btnPrintPreview_Click(object sender, System.EventArgs e)
		{
			this.ppdlgStock.ShowDialog();
		}

		
		private void frmStockManagement_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
		{
			// if datagrid needs to be refreshed after 
			// any new/update operation
			try
			{
			
			if (this.dbgItemsList.DataSource!=null)
				{
					searchvalue[0] = "";
					searchvalue[1] = "";
					searchvalue[2] = "";
				    StockManagement stkMgmt = new StockManagement();
					this.dbgItemsList.DataSource = null;
					this.dbgItemsList.DataSource = stkMgmt.FetchStockDetails(searchvalue);
					dbgItemsList.Refresh(); 
				}
			}
			catch(Exception excep)
			{
				MessageBox.Show ("发生错误  "+excep.Message.ToString ());
			}
		}

		
		
	}
}

⌨️ 快捷键说明

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