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

📄 modifypasswd.cs

📁 工资结算系统 拥有权限控制 临时工资表 自动导入导出Excel 以及邮件群发功能
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.OleDb;

namespace HrSalary.a_user
{
	/// <summary>
	/// RectifyPasswd 的摘要说明。
	/// </summary>
	public class ModifyPasswd : System.Windows.Forms.Form
	{
		private System.Windows.Forms.TextBox Oldp_textBox1;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.TextBox Newp_textBox2;
		private System.Windows.Forms.TextBox Renewp_textBox3;
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.Button button2;
		private System.Windows.Forms.TextBox textBox1;
		private System.Windows.Forms.Label label4;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;
		 private OleDbConnection dbCon = null;

		public ModifyPasswd()
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();

			//
			// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
			//
		}

		/// <summary>
		/// 清理所有正在使用的资源。
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows 窗体设计器生成的代码
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			this.Oldp_textBox1 = new System.Windows.Forms.TextBox();
			this.label1 = new System.Windows.Forms.Label();
			this.label2 = new System.Windows.Forms.Label();
			this.label3 = new System.Windows.Forms.Label();
			this.Newp_textBox2 = new System.Windows.Forms.TextBox();
			this.Renewp_textBox3 = new System.Windows.Forms.TextBox();
			this.button1 = new System.Windows.Forms.Button();
			this.button2 = new System.Windows.Forms.Button();
			this.textBox1 = new System.Windows.Forms.TextBox();
			this.label4 = new System.Windows.Forms.Label();
			this.SuspendLayout();
			// 
			// Oldp_textBox1
			// 
			this.Oldp_textBox1.Location = new System.Drawing.Point(104, 48);
			this.Oldp_textBox1.Name = "Oldp_textBox1";
			this.Oldp_textBox1.PasswordChar = '*';
			this.Oldp_textBox1.Size = new System.Drawing.Size(128, 21);
			this.Oldp_textBox1.TabIndex = 0;
			this.Oldp_textBox1.Text = "";
			// 
			// label1
			// 
			this.label1.ForeColor = System.Drawing.Color.Blue;
			this.label1.Location = new System.Drawing.Point(48, 48);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(56, 16);
			this.label1.TabIndex = 1;
			this.label1.Text = "旧密码:";
			// 
			// label2
			// 
			this.label2.ForeColor = System.Drawing.Color.Blue;
			this.label2.Location = new System.Drawing.Point(48, 88);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(56, 16);
			this.label2.TabIndex = 2;
			this.label2.Text = "新密码:";
			// 
			// label3
			// 
			this.label3.ForeColor = System.Drawing.Color.Blue;
			this.label3.Location = new System.Drawing.Point(24, 120);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(80, 16);
			this.label3.TabIndex = 3;
			this.label3.Text = "确认新密码:";
			// 
			// Newp_textBox2
			// 
			this.Newp_textBox2.Location = new System.Drawing.Point(104, 88);
			this.Newp_textBox2.Name = "Newp_textBox2";
			this.Newp_textBox2.PasswordChar = '*';
			this.Newp_textBox2.Size = new System.Drawing.Size(128, 21);
			this.Newp_textBox2.TabIndex = 4;
			this.Newp_textBox2.Text = "";
			// 
			// Renewp_textBox3
			// 
			this.Renewp_textBox3.Location = new System.Drawing.Point(104, 120);
			this.Renewp_textBox3.Name = "Renewp_textBox3";
			this.Renewp_textBox3.PasswordChar = '*';
			this.Renewp_textBox3.Size = new System.Drawing.Size(128, 21);
			this.Renewp_textBox3.TabIndex = 5;
			this.Renewp_textBox3.Text = "";
			// 
			// button1
			// 
			this.button1.BackColor = System.Drawing.SystemColors.ControlLight;
			this.button1.ForeColor = System.Drawing.Color.Blue;
			this.button1.Location = new System.Drawing.Point(56, 160);
			this.button1.Name = "button1";
			this.button1.Size = new System.Drawing.Size(80, 23);
			this.button1.TabIndex = 6;
			this.button1.Text = "确认";
			this.button1.Click += new System.EventHandler(this.button1_Click);
			// 
			// button2
			// 
			this.button2.BackColor = System.Drawing.SystemColors.ControlLight;
			this.button2.ForeColor = System.Drawing.Color.Blue;
			this.button2.Location = new System.Drawing.Point(184, 160);
			this.button2.Name = "button2";
			this.button2.Size = new System.Drawing.Size(80, 23);
			this.button2.TabIndex = 7;
			this.button2.Text = "取消";
			this.button2.Click += new System.EventHandler(this.button2_Click);
			// 
			// textBox1
			// 
			this.textBox1.Location = new System.Drawing.Point(104, 16);
			this.textBox1.Name = "textBox1";
			this.textBox1.Size = new System.Drawing.Size(128, 21);
			this.textBox1.TabIndex = 8;
			this.textBox1.Text = "";
			// 
			// label4
			// 
			this.label4.ForeColor = System.Drawing.Color.Blue;
			this.label4.Location = new System.Drawing.Point(48, 16);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(56, 16);
			this.label4.TabIndex = 9;
			this.label4.Text = "用户名:";
			// 
			// ModifyPasswd
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.BackColor = System.Drawing.Color.AliceBlue;
			this.ClientSize = new System.Drawing.Size(304, 197);
			this.Controls.Add(this.label4);
			this.Controls.Add(this.textBox1);
			this.Controls.Add(this.button2);
			this.Controls.Add(this.button1);
			this.Controls.Add(this.Renewp_textBox3);
			this.Controls.Add(this.Newp_textBox2);
			this.Controls.Add(this.label3);
			this.Controls.Add(this.label2);
			this.Controls.Add(this.label1);
			this.Controls.Add(this.Oldp_textBox1);
			this.Name = "ModifyPasswd";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
			this.Text = "修改密码";
			this.ResumeLayout(false);

		}
		#endregion

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

		private void button1_Click(object sender, System.EventArgs e)
		{
			try
			{
			string error="";
			if(this.textBox1.Text=="" || this.textBox1.Text.Trim().Equals(""))
			{	
				error+="错!用户名为空\n";
				MessageBox.Show(error+"请重试!!!");
				return;
			}	
			if(!this.Renewp_textBox3.Text.Equals(this.Newp_textBox2.Text))
			{
				error+="错!新密码不一致\n";
				MessageBox.Show(error+"请重试!!!");
				return;
			}
				if(dbCon==null) dbCon = MainForm.getConnection();
				OleDbCommand cmd10 = dbCon.CreateCommand();
				cmd10.CommandText = "select passwd from a_user where name='"+this.textBox1.Text+"'";
				OleDbDataReader reader10 = cmd10.ExecuteReader();
				if(reader10.Read()) 
				{
					if(!reader10.GetString(0).Equals(this.Oldp_textBox1.Text))
						{
							error+="错!密码不正确\n";
							MessageBox.Show(error+"请重试!!!");
							reader10.Close();
							cmd10.Dispose();
							return;
						}
				}
				else
				{
					error+="错!无此用户\n";
					MessageBox.Show(error+"请重试!!!");
					reader10.Close();
					cmd10.Dispose();
					return;
				}
				reader10.Close();
				cmd10.Dispose();
				a_user_PasswdModify();				
			}
			catch(Exception eee)
			{
				MessageBox.Show(eee.ToString());
			}
		}
      
		private void  a_user_PasswdModify()
		{
			try
			{				 

				if(dbCon==null) dbCon = MainForm.getConnection();
				OleDbCommand cmd11 = dbCon.CreateCommand();
				cmd11.CommandText = "update a_user set passwd='"+this.Newp_textBox2.Text+"' where name='"+this.textBox1.Text+"' and passwd='"+this.Oldp_textBox1.Text+"'";//this.Newp_textBox2.Text.Equals(this.Renewp_textBox3.Text);
				
				int result = cmd11.ExecuteNonQuery();
				if(result==1)
					
					MessageBox.Show("密码修改成功!");
									
				cmd11.Dispose();
				this.Close();		
			}
			catch(Exception ee)
			{
				MessageBox.Show(ee.ToString());
			}
		}

	}
}

⌨️ 快捷键说明

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