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

📄 frmaddcategory.cs

📁 本论文叙述了联机考试系统的现状以及C#语言的概况。重点介绍了联机考试系统的实现过程:包括系统分析、 系统调查、 数据流程分析、功能设计、 数据库设计、 系统物理配置方案、 系统实现、 系统测试和调试。
💻 CS
📖 第 1 页 / 共 2 页
字号:
			frmCategory.addflag =true;
			try
			{
				//populate first level cat code combobox

				DataConnection.commnd.CommandText = "Select catcode	from productcategories where flvlcatcode = '00'";
				OleDbDataReader reader = DataConnection.commnd.ExecuteReader ();
				if (reader.HasRows)
				{
					while(reader.Read())
					{
						cboFlvlCatCode.Items.Add (reader.GetString (0));
					}
				}
				else
                    cboFlvlCatCode.Text ="00";
				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.NumericUpDown") && (ctrl.GetType().ToString() != "System.Windows.Forms.TreeView")&&(ctrl.GetType().ToString() != "System.Windows.Forms.Label"))
				{
					if (ctrl.Text == "")
						allValidated = false;
				}
				else
				{
					if (this.updRate.Value <=0)
						allValidated = false;
				}
						
			}
			try
			{
				if (allValidated)
				{
					strPrdCat stPrdCat = new strPrdCat();
					stPrdCat.CatCode = txtCatCode.Text; 
					stPrdCat.CatTitle = txtCatTitle.Text;
					stPrdCat.CatDesc = txtCatDesc.Text ;
					stPrdCat.FlvlCatCode = cboFlvlCatCode.Text;
					stPrdCat.Rate = rate ;
					StockManagement smgt = new StockManagement();
					smgt.AddProdCat(stPrdCat);
					MessageBox.Show("成功添加记录");
					this.Close();
								
				}
				else 
					MessageBox.Show ("未完成详细信息,不能添加。");
			}

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

		private void btnCancel_Click(object sender, System.EventArgs e)
		{
			
			errCatValidation.SetError(this.cboFlvlCatCode,"");
            errCatValidation.SetError(this.updRate,"");
			errCatValidation.SetError(this.txtCatCode,"");
			errCatValidation.SetError(this.txtCatDesc,"");
			errCatValidation.SetError(this.txtCatTitle,"");
			
			this.Close ();
		}
		public void ClearDetails()
		{
			this.txtCatCode.Text = "";
			this.txtCatTitle.Text = "";
			this.txtCatDesc.Text = "";
			this.cboFlvlCatCode.Text = "";
			this.updRate.Value = 0;
		}

		private void txtCatCode_Leave(object sender, System.EventArgs e)
		{
			bool validFlag = true;
			if (txtCatCode.Text.Trim() == "")
			{
				errorMsg = ("类别代码不能为空");
				this.errCatValidation.SetError(this.txtCatCode, errorMsg);
				this.txtCatCode.Focus ();
				allValidated =false;
				validFlag = false; 
			}
			else
			{
				if (txtCatCode.Text.Length <2 || txtCatCode.Text.Length>2)
				{
					errorMsg = ("类别代码必须为两位");
					this.errCatValidation.SetError(this.txtCatCode, errorMsg);
					validFlag = false; 
					this.txtCatCode.Focus();
				}
				else
				{

					try
					{
						
						DataConnection.commnd.CommandText = "Select catcode	from productcategories";
						OleDbDataReader reader = DataConnection.commnd.ExecuteReader ();
						while(reader.Read() )
						{
							if (reader.GetString (0).Equals(txtCatCode.Text))
							{
								errorMsg = ("类别代码已存在");
								this.errCatValidation.SetError(this.txtCatCode, errorMsg);
							this.txtCatCode.Focus();
								allValidated =false;
								validFlag = false; 
																	  
							}
						}
						reader.Close();
					}
					catch(Exception excep)
					{
						MessageBox.Show("发生错误 "+excep.Message.ToString ());
					}
				}
				if (validFlag == true)
				{
					this.errCatValidation.SetError(this.txtCatCode, "");
					allValidated = true;
				}
				}
		
		}

		private void txtCatTitle_Leave(object sender, System.EventArgs e)
		{
			if (this.txtCatTitle.Text == "")
			{
				errorMsg = ("类别名称不能为空,请输入有效值。");
				this.errCatValidation.SetError(this.txtCatTitle, errorMsg);
				this.txtCatTitle.Focus();
				allValidated =false;
				
			}
			else
			{
				this.errCatValidation.SetError(this.txtCatTitle, "");
				allValidated = true;
			}
		}

		private void txtCatDesc_Leave(object sender, System.EventArgs e)
		{
			if (this.txtCatDesc.Text == "")
			{
				errorMsg = ("类别说明不能为空,请输入有效值。");
				this.errCatValidation.SetError(this.txtCatDesc, errorMsg);
				this.txtCatDesc.Focus();
				allValidated =false;
			

			}
			else
			{
				this.errCatValidation.SetError(this.txtCatDesc, "");
				allValidated = true;
			}
		}

		private void updRate_Leave(object sender, System.EventArgs e)
		{
			if (this.updRate.Value <=0 )
			{
				errorMsg = ("请输入有效的费率值,不能为 0 或负数。");
				this.errCatValidation.SetError(this.updRate, errorMsg);
				this.updRate.Focus ();
				allValidated = false;
			
			}
			else
			{
				this.errCatValidation.SetError(this.updRate, "");
				allValidated=true;
			}
		}

		private void cboFlvlCatCode_Leave(object sender, System.EventArgs e)
		{
			bool validFlag = false;

			if (this.cboFlvlCatCode.Text == "")
			{
				errorMsg = ("第一层类别代码不能为空,请输入有效值。");
				this.errCatValidation.SetError(this.cboFlvlCatCode, errorMsg);
				this.cboFlvlCatCode.Focus ();
				validFlag = false;
				allValidated =false;
			}
			
			foreach(string item in cboFlvlCatCode.Items)
			{
				if (item.Equals(cboFlvlCatCode.Text))
				{
					validFlag = true;
					allValidated=true;
				}

			}
		if (cboFlvlCatCode.Text.Equals ("00"))
				{
					validFlag = true;
					allValidated=true;
				}

			if (validFlag == false)
			{
				errorMsg = ("请输入产品类别的有效值。");
				this.errCatValidation.SetError(this.cboFlvlCatCode, errorMsg);
				this.cboFlvlCatCode.Focus ();
				allValidated = false;
			
			}
			else
			{
				this.errCatValidation.SetError(this.cboFlvlCatCode, "");
				allValidated = true;
			}
			
			
		}

		private void txtCatCode_MouseHover(object sender, System.EventArgs e)
		{
			this.tipNewCategory.SetToolTip(this.txtCatCode ,"输入新的类别代码");	
		
		}

		private void txtCatTitle_MouseHover(object sender, System.EventArgs e)
		{
			this.tipNewCategory.SetToolTip(this.txtCatTitle ,"输入新的类别名称");	
		
		}

		private void txtCatDesc_MouseHover(object sender, System.EventArgs e)
		{
			this.tipNewCategory.SetToolTip(this.txtCatDesc ,"输入说明");	
		
		}

		private void cboFlvlCatCode_MouseHover(object sender, System.EventArgs e)
		{
			this.tipNewCategory.SetToolTip(this.cboFlvlCatCode  ,"选择类别代码值");	
		
		}

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

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

		}
	}

⌨️ 快捷键说明

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