📄 changepasswordform.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Data;
using SupDataBase;
namespace WindowsApplication1
{
/// <summary>
/// ChangePasswordForm 的摘要说明。
/// </summary>
public class ChangePasswordForm : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button m_OKButton;
private System.Windows.Forms.Button m_CancelButton;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.TextBox m_OldPasswordText;
private System.Windows.Forms.TextBox m_NewPasswordText;
private SqlConnection m_Connection;
private SqlDataAdapter m_sqlDataAdapter;
private string epassword;
private string eemployeeID;
private bool isCorrect;
private System.Windows.Forms.TextBox m_NewPasswordAgainText;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public ChangePasswordForm(string password,string employeeID)
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
epassword=password;
eemployeeID=employeeID;
//
// 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.label1 = new System.Windows.Forms.Label();
this.m_OldPasswordText = new System.Windows.Forms.TextBox();
this.m_OKButton = new System.Windows.Forms.Button();
this.m_CancelButton = new System.Windows.Forms.Button();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.m_NewPasswordText = new System.Windows.Forms.TextBox();
this.m_NewPasswordAgainText = new System.Windows.Forms.TextBox();
this.m_sqlDataAdapter = new System.Data.SqlClient.SqlDataAdapter();
this.SuspendLayout();
//
// label1
//
this.label1.Dock = System.Windows.Forms.DockStyle.Top;
this.label1.Location = new System.Drawing.Point(0, 0);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(248, 23);
this.label1.TabIndex = 0;
this.label1.Text = "请在下面的输入框中输入您的密码:";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// m_OldPasswordText
//
this.m_OldPasswordText.Location = new System.Drawing.Point(120, 32);
this.m_OldPasswordText.Name = "m_OldPasswordText";
this.m_OldPasswordText.PasswordChar = '*';
this.m_OldPasswordText.Size = new System.Drawing.Size(104, 21);
this.m_OldPasswordText.TabIndex = 0;
this.m_OldPasswordText.Text = "";
//
// m_OKButton
//
this.m_OKButton.DialogResult = System.Windows.Forms.DialogResult.OK;
this.m_OKButton.Location = new System.Drawing.Point(32, 144);
this.m_OKButton.Name = "m_OKButton";
this.m_OKButton.Size = new System.Drawing.Size(72, 24);
this.m_OKButton.TabIndex = 3;
this.m_OKButton.Text = "确定";
this.m_OKButton.Click += new System.EventHandler(this.m_OKButton_Click);
//
// m_CancelButton
//
this.m_CancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.m_CancelButton.Location = new System.Drawing.Point(136, 144);
this.m_CancelButton.Name = "m_CancelButton";
this.m_CancelButton.Size = new System.Drawing.Size(72, 24);
this.m_CancelButton.TabIndex = 4;
this.m_CancelButton.Text = "取消";
this.m_CancelButton.Click += new System.EventHandler(this.m_CancelButton_Click);
//
// label2
//
this.label2.Location = new System.Drawing.Point(8, 32);
this.label2.Name = "label2";
this.label2.TabIndex = 4;
this.label2.Text = "原始密码:";
this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// label3
//
this.label3.Location = new System.Drawing.Point(8, 72);
this.label3.Name = "label3";
this.label3.TabIndex = 5;
this.label3.Text = "新密码:";
this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// label4
//
this.label4.Location = new System.Drawing.Point(8, 112);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(104, 23);
this.label4.TabIndex = 6;
this.label4.Text = "再次输入新密码:";
//
// m_NewPasswordText
//
this.m_NewPasswordText.Location = new System.Drawing.Point(120, 72);
this.m_NewPasswordText.Name = "m_NewPasswordText";
this.m_NewPasswordText.PasswordChar = '*';
this.m_NewPasswordText.Size = new System.Drawing.Size(104, 21);
this.m_NewPasswordText.TabIndex = 1;
this.m_NewPasswordText.Text = "";
//
// m_NewPasswordAgainText
//
this.m_NewPasswordAgainText.Location = new System.Drawing.Point(120, 112);
this.m_NewPasswordAgainText.Name = "m_NewPasswordAgainText";
this.m_NewPasswordAgainText.PasswordChar = '*';
this.m_NewPasswordAgainText.Size = new System.Drawing.Size(104, 21);
this.m_NewPasswordAgainText.TabIndex = 2;
this.m_NewPasswordAgainText.Text = "";
//
// ChangePasswordForm
//
this.AcceptButton = this.m_OKButton;
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.CancelButton = this.m_CancelButton;
this.ClientSize = new System.Drawing.Size(248, 174);
this.Controls.Add(this.m_NewPasswordAgainText);
this.Controls.Add(this.m_NewPasswordText);
this.Controls.Add(this.m_OldPasswordText);
this.Controls.Add(this.label4);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.m_CancelButton);
this.Controls.Add(this.m_OKButton);
this.Controls.Add(this.label1);
this.MaximizeBox = false;
this.MinimizeBox = false;
this.MinimumSize = new System.Drawing.Size(256, 128);
this.Name = "ChangePasswordForm";
this.Text = "修改密码";
this.ResumeLayout(false);
}
#endregion
private void m_CancelButton_Click(object sender, System.EventArgs e)
{
this.Close();
}
private void m_OKButton_Click(object sender, System.EventArgs e)
{
string oldpassword=m_OldPasswordText.Text;
string newpassword=m_NewPasswordText.Text;
string newpwdagain=m_NewPasswordAgainText.Text;
if (oldpassword.Equals(""))
{
MessageBox.Show(this,"输入的旧密码不能为空!","错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
m_OldPasswordText.Focus();
}
else
{
if (newpassword.Equals(""))
{
MessageBox.Show(this,"输入的新密码不能为空!","错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
m_NewPasswordText.Focus();
}
else
{
if (newpwdagain.Equals(""))
{
MessageBox.Show(this,"第二次输入的新密码不能为空!","错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
m_NewPasswordAgainText.Focus();
}
else
{
if (!oldpassword.Equals(epassword))
{
MessageBox.Show(this,"输入的旧密码错误!","错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
m_OldPasswordText.Focus();
}
else
{
if (!newpassword.Equals(newpwdagain))
{
m_NewPasswordText.Focus();
MessageBox.Show(this,"两次输入的新密码不一致!\n请重新输入!","错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
//连接数据库,修改密码
SqlCommand m_sqjUpdateCommand=new SqlCommand();
m_sqlDataAdapter.UpdateCommand=m_sqjUpdateCommand;
m_sqjUpdateCommand.Connection=m_Connection;
m_sqjUpdateCommand.CommandText="update Employee set Password=@password where EmployeeID=@employeeID";
m_sqjUpdateCommand.Parameters.Add(new SqlParameter("@password", SqlDbType.VarChar, 50));
m_sqjUpdateCommand.Parameters["@password"].Value=newpassword;
m_sqjUpdateCommand.Parameters.Add(new SqlParameter("@employeeID", SqlDbType.VarChar, 50));
m_sqjUpdateCommand.Parameters["@employeeID"].Value=eemployeeID;
try
{
m_sqjUpdateCommand.Connection.Open();
m_sqjUpdateCommand.ExecuteNonQuery();
m_sqjUpdateCommand.Connection.Close();
MessageBox.Show(this,"已经成功修改密码!","正确");
isCorrect=true;
epassword=newpassword;
this.Close();
}
catch (SqlException e1)
{
MessageBox.Show(this,e1.Message,"错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
}
}
}
public bool IsCorrect
{
get
{
return isCorrect;
}
}
public string Password
{
get
{
return epassword;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -