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

📄 frmnewuser.cs

📁 本论文叙述了联机考试系统的现状以及C#语言的概况。重点介绍了联机考试系统的实现过程:包括系统分析、 系统调查、 数据流程分析、功能设计、 数据库设计、 系统物理配置方案、 系统实现、 系统测试和调试。
💻 CS
📖 第 1 页 / 共 2 页
字号:
					this.chlPrior.Items.Add(reader.GetString(1));
					//Storing the priorityId to the array arrPrior
					arrPrior[ctr] = reader.GetInt32(0);
					ctr++;
				}
				reader.Close();
			}
			catch(OleDbException myException)
			{
				MessageBox.Show(myException.Message);
				this.Close();
			}
		}
	
		private void chkEmpStat_CheckedChanged(object sender, System.EventArgs e)
		{
			//Storing the current status of the CheckBox to the variable EmpStatus
			this.EmpStatus = this.chkEmpStat.Checked;
		}

		private void ClearDetails()
		{
			this.txtUid.Text = "";
			this.txtName.Text = "";
			this.txtPwd.Text = "";
			this.txtVerPwd.Text = "";
			this.chkEmpStat.Checked=false;
			this.txtEmailId.Text="";
			this.ClearPriorities();
		}

		//Method to clear the priority values from screen
		private void ClearPriorities()
		{
			//Clearing items in the CheckedListBox
			int ctr= 0;
			while(ctr < this.chlPrior.Items.Count)
			{
				this.chlPrior.SetItemChecked(ctr,false);
				ctr++;
			}

		}

		//Method for calculating Cumulative priority
		private void CalculateCumPriority()
		{
			this.cumPriorVal = 0;
			// Cheking the total items in the CheckedListBox chlPrior
			for(int ctr = 0; ctr<=this.chlPrior.Items.Count-1; ctr++)
			{
				//Checking the Selected Items in the CheckedListBox
				if(this.chlPrior.GetItemChecked(ctr))
				{
					this.cumPriorVal += this.arrPrior[ctr];
				}
				
			}
				
		}

		public bool UserIdExistChk()
		{
			int ctr = 0;
			DataConnection.load();
			DataConnection.commnd.CommandText="select usrId from Employees";
			OleDbDataReader reader = DataConnection.commnd.ExecuteReader();
			while(reader.Read())
			{
				if((reader.GetString(0)) == this.txtUid.Text)
				{
					MessageBox.Show("用户标识已存在");
					this.txtUid.Text="";
					this.txtUid.Focus();
					return false;
				}
				ctr++;
			}
			reader.Close();
			return true;
			
		}

		public bool pwdVerification()
		{
			if(this.txtPwd.Text == this.txtVerPwd.Text)
				return true;
			else
				MessageBox.Show("密码不匹配");
			this.txtPwd.Clear();
			this.txtVerPwd.Clear();
			this.txtPwd.Focus();
			return false;
		}

		private void btnOK_Click(object sender, System.EventArgs e)
		{
			if ((this.txtName.Text.Length == 0) || (this.txtUid.Text.Length == 0) || (this.txtEmailId.Text.Length == 0) || (this.txtPwd.Text.Length == 0) || (this.txtVerPwd.Text.Length == 0))
			{
				MessageBox.Show("缺少字段值");
			}
			else if(this.UserIdExistChk()&& this.pwdVerification())
			{
				
				this.CalculateCumPriority();

				if (this.cumPriorVal == 0)				
				{
					MessageBox.Show("优先级必须为特定的值");
					this.chlPrior.Focus();
				}
				else
				{
					//Calling the method CollectEmployeeData
					this.CollectEmployeeData();
				
					//Creating an Object of Usermanagement Class
					UserManagement UAdminMgmt = new UserManagement();
					//Calling the AddEmployee Method of Usermanagement Class and
					//Passing the value of the structure
			UAdminMgmt.AddEmployee(stEmp);
					  
					MessageBox.Show ("成功添加记录");		
					this.Close();
				}
			}
		}

		private void CollectEmployeeData()
		{
			stEmp.UsrId = this.txtUid.Text;
			stEmp.Passwd = this.txtPwd.Text;
			stEmp.PriorityId = this.cumPriorVal;
			stEmp.EmpName = this.txtName.Text;
			stEmp.EmpStatus = this.EmpStatus;
			stEmp.EmailId = this.txtEmailId.Text;
		}

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

		public bool ValidEmailAddress(string emailAddress, out string errorMessage)
		{
			// Confirm that the e-mail address string is not empty.
			if(emailAddress.Length == 0)
			{
				errorMessage = "必须输入电子邮件地址";
				return false;
			}

			// Confirm that there is an "@" and a "." in the e-mail address, and in the correct order.
			if(emailAddress.IndexOf("@") > -1)
			{
				if(emailAddress.IndexOf(".", emailAddress.IndexOf("@") ) > emailAddress.IndexOf("@") )
				{
					errorMessage = "";
					return true;
				}
			}
   
			errorMessage = "应输入格式正确的电子邮件地址。\n" +
				"例如 'someone@example.com' ";
			return false;
		}


	private bool chkAlpha()
{
	for(int i=0; i<this.txtName.Text.Length;i++)
{
	if(! Char.IsLetter(this.txtName.Text,i))
{
	return false;
}
}
	return true;
}

	private void txtName_TextChanged_1(object sender, System.EventArgs e)
{
	this.btnOK.Enabled = true;
	if (this.txtName.Text.Length == 0)
	this.btnOK.Enabled = false;
}

	private void txtName_Leave(object sender, System.EventArgs e)
{
	if(this.txtName.Text.Trim().Length == 0)
{
	errorMsg = "必须输入员工姓名";
				
				
	// Set the ErrorProvider error with the text to display 
	this.errNewUser.SetError(this.txtName, errorMsg);
	this.txtName.Focus();
}
	else 
{
	if (! this.chkAlpha())
{
	errorMsg = "员工姓名必须为字母";
					
// Set the ErrorProvider error with the text to display. 
	this.errNewUser.SetError(this.txtName, errorMsg);
	this.txtName.Focus();	
}
	else
{
	errNewUser.SetError(txtName,"");
}
}
}

	private void txtUid_Leave(object sender, System.EventArgs e)
		{
			if(this.txtUid.Text.Trim().Length == 0)
		{
			errorMsg = "必须输入用户标识。";

			// Set the ErrorProvider error with the text to display. 
			this.errNewUser.SetError(this.txtUid, errorMsg);
            this.txtUid.Focus();
		}
			else
			errNewUser.SetError(txtUid,"");	
		}

	private void txtEmailId_Leave(object sender, System.EventArgs e)
{
	string errorMsg;
	if(!ValidEmailAddress(txtEmailId.Text, out errorMsg))
{
	
	txtEmailId.Select(0, txtEmailId.Text.Length);

	// Set the ErrorProvider error with the text to display. 
	this.errNewUser.SetError(txtEmailId, errorMsg);
    this.txtEmailId.Focus();
}
	else
	this.errNewUser.SetError(txtEmailId, "");
}
	private void txtPwd_Leave(object sender, System.EventArgs e)
{
	if(this.txtPwd.Text.Trim().Length == 0)
{
	errorMsg = "必须输入密码。";

			
	// Set the ErrorProvider error with the text to display. 
	this.errNewUser.SetError(this.txtPwd, errorMsg);
    this.txtPwd.Focus();
}
	else
	this.errNewUser.SetError(this.txtPwd, "");
		
}

		private void txtVerPwd_Leave(object sender, System.EventArgs e)
		{
			if(this.txtVerPwd.Text.Trim().Length == 0)
			{
				errorMsg = "必须进行密码验证。";

				
				// Set the ErrorProvider error with the text to display. 
				this.errNewUser.SetError(this.txtVerPwd, errorMsg);
				this.txtVerPwd.Focus();

			}
			else
			{
				if (!this.txtVerPwd.Text.Trim().Equals(this.txtPwd.Text)) 
				{
					errorMsg = "验证密码必须与密码相同";
					this.errNewUser.SetError(this.txtVerPwd, errorMsg);
					this.txtVerPwd.Focus();
				}
				else
					errNewUser.SetError(txtVerPwd,"");
			}
		}

		private void txtName_MouseHover(object sender, System.EventArgs e)
		{
			this.tipNewUser.SetToolTip(this.txtName ,"输入姓名");	
		
		}

		private void chlPrior_MouseHover(object sender, System.EventArgs e)
		{
			this.tipNewUser.SetToolTip(this.chlPrior ,"选择一个或多个用户身份");	
		
		}

		private void txtEmailId_MouseHover(object sender, System.EventArgs e)
		{
			this.tipNewUser.SetToolTip(this.txtEmailId ,"输入电子邮件地址");	
		
		}

		private void txtPwd_MouseHover(object sender, System.EventArgs e)
		{
			this.tipNewUser.SetToolTip(this.txtPwd ,"输入新的用户名称");	
		
		}

		private void txtVerPwd_MouseHover(object sender, System.EventArgs e)
		{
			this.tipNewUser.SetToolTip(this.txtVerPwd ,"验证密码");	
		}

		private void txtUid_MouseHover(object sender, System.EventArgs e)
		{
			this.tipNewUser.SetToolTip(this.txtUid,"输入用户标识");	
		}

		private void chkEmpStat_MouseHover(object sender, System.EventArgs e)
		{
			this.tipNewUser.SetToolTip(this.chkEmpStat ,"选择员工状态");	
		
		}
}
}

⌨️ 快捷键说明

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