modifypasswordframe.cs

来自「独立完成考勤管理软件加打卡系统(C#) 是打卡加管理系统软件 」· CS 代码 · 共 449 行 · 第 1/2 页

CS
449
字号
		private System.Data.DataTable userNameTable=new System.Data.DataTable();
		private System.Data.DataSet   userNameSet=new System.Data.DataSet();
		private DataTable tempTable=new DataTable();
		#endregion
		#region 事件初始化...
		private void ModifyPasswordFrame_Load(object sender, System.EventArgs e)
		{
			try
			{
				#region 数据库初始化...
				userNameSet=conn.ExcuteDataSetResult(userNameSql,"System_UserTable");
				userNameTable=userNameSet.Tables[0];
				for(int i=0;i<userNameTable.Rows.Count;i++)
				{
					this.userCom.Items.Add(userNameTable.Rows[i][0].ToString());
				}
				#endregion
				#region 判断当前用户是谁...
                CheckUser();
				#endregion
				#region 检查所有表的内容...
				tempTable=this.ExcuteSql(selectUser,"System_UserTable");
				#endregion
				#region 窗体初始化...
				InitFrame(false);
				#endregion
			}
			catch(Exception exel)
			{
				MessageBox.Show(this,exel.ToString(),"提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
			}
		}
		#endregion
		#region 检查是否为空
		private bool CheckNull()
		{
			try
			{
				if(this.userCom.Text.Equals(""))
				{
					MessageBox.Show(this,"用户名不能为空!!!","提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
					this.userCom.Focus();
					return true;
				}
				else if (this.textpassword.Text.Equals(""))
				{
					MessageBox.Show(this,"密码不能为空!!!","提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
					this.textpassword.Focus();
					return true;
				}
				else if(this.textRePassword.Text.Equals(""))
				{
					MessageBox.Show(this," 确认码不能为空!!!","提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
					this.textRePassword.Focus();
					return true;
				}
				else if (!(this.textpassword.Text.ToString().Equals(this.textRePassword.Text.ToString())))
				{
					MessageBox.Show(this,"密码错误!!!","提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
					this.textpassword.Focus();
					ClearText();
					return true;
				}
			}
			catch(Exception ete)
			{
				MessageBox.Show(this,ete.ToString(),"提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
			}
             return false;
		}
		#endregion 
		#region 确认事件...
		private void btnOk_Click(object sender, System.EventArgs e)
		{
			try
			{
                modifyCurrentUser();
			}
			catch(Exception exlesdf)
			{
				MessageBox.Show(this,exlesdf.ToString(),"提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
			}
		}
		#endregion
		#region 取消事件...
		private void btnCancel_Click(object sender, System.EventArgs e)
		{
		    DialogResult result=MessageBox.Show(this,"是否关闭此窗体啊!!!","提示信息",MessageBoxButtons.YesNo,MessageBoxIcon.Information);
			if(result.Equals(DialogResult.Yes))
			{
				this.Close();
			}
			else
			{
				return;
			}
		}
		#endregion
		#region 判断当前用户是谁...
		private void CheckUser()
		{
			for(int k=0;k<this.userCom.Items.Count;k++)
			{
				if(this.userCom.Items[k].ToString().Trim().Equals(landFrame.strUserName.ToString().Trim()))
				{
					this.userCom.SelectedIndex=k;
				}
			}
		}
		#endregion
		#region 修改密码
		private void modifyCurrentUser()
		{
			try
			{
				if(CheckNull())
				{
					return;
				}
				else if(CheckPasswordFrame.blpassword.Equals(false))
				{
					return;
				}
				else
				{
					if(landFrame.strName.Equals("管理员"))
					{
						string updataStr="update System_UserTable set 密码='"+MD4.EncryptString(this.textRePassword.Text.ToString().Trim())+"'where 用户名称='"+this.userCom.Text.ToString().Trim()+"'";
						int y=conn.ExcuteStrSql(updataStr);
						if(y>0)
						{
							//MessageBox.Show(this,"修改密码成功!!!","提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
							MessageBox.Show(this,"修改密码为:"+this.textRePassword.Text.ToString().Trim(),"提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
							ClearText();
						}
						else
						{
							MessageBox.Show(this,"修改密码失败!!!","提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
							ClearText();
						}
					}
					else
					{
						string updataStr="update System_UserTable set 密码='"+MD4.EncryptString(this.textRePassword.Text.ToString().Trim())+"'where 用户名称='"+this.userCom.Text.ToString().Trim()+"'and 用户类型='普通用户'";
						int y=conn.ExcuteStrSql(updataStr);
						if(y>0)
						{
							//MessageBox.Show(this,"修改密码成功!!!","提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
							MessageBox.Show(this,"修改密码为:"+this.textRePassword.Text.ToString().Trim(),"提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
							ClearText();
						}
						else
						{
							MessageBox.Show(this,"修改密码失败!!!","提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
							ClearText();
						}
					}
				}
			}
			catch(Exception ele)
			{
				MessageBox.Show(this,ele.ToString(),"提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
			}
		}
		#endregion
		#region 检查用户是否存在啊...
		private bool CheckUserExist()
		{
			return true;
		}
		#endregion
		#region 数据库处理函数
		private DataTable ExcuteSql(string strSql,string tableName)
		{
			DataSet dsSet=new DataSet();
			DataTable dsTable=new DataTable();
			try
			{
				dsSet=conn.ExcuteDataSetResult(strSql,tableName);
				dsTable=dsSet.Tables[0];
			}
			catch(Exception eles)
			{
				MessageBox.Show(this,eles.ToString(),"提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
			}
			return dsTable;
		}
		#endregion
		#region 检查清空函数
		private void ClearText()
		{
			this.userCom.Text="";
			this.textpassword.Text="";
			this.textRePassword.Text="";
		}
		#endregion
		#region 窗体初始化...
		private void InitFrame(bool f )
		{
            this.btnOk.Enabled=f;
			this.btnCancel.Enabled=f;
			this.textRePassword.Enabled=f;
			this.textpassword.Enabled=f;
			this.userCom.Enabled=f;
			this.btnCheck.Enabled=!f;
		}
		#endregion
		#region 检验旧密码是正确....
		private void btnCheck_Click(object sender, System.EventArgs e)
		{
		   MessageBox.Show(this,"请输入你的旧密码吗!!!","提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
		   CheckPasswordFrame log=new CheckPasswordFrame();
		   log.ShowDialog();
		   if(CheckPasswordFrame.blpassword.Equals(true))
		   {
			   //MessageBox.Show(this,"请你单击两次此按钮!!!","提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
               this.InitFrame(true);
			   MessageBox.Show(this,"可以修改你的密码啦!!!","提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
		   }
		}
		#endregion
	}
}

⌨️ 快捷键说明

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