frmchangepassword.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
namespace SupermarketProject
{
/// <summary>
/// Summary description for ChangePassword.
/// </summary>
public class frmChangePassword : System.Windows.Forms.Form
{
private System.Windows.Forms.Label lblOldPassword;
private System.Windows.Forms.Label lblRetyeNewPassword;
private System.Windows.Forms.Label lblNewPassword;
private System.Windows.Forms.TextBox txtNewPwd;
private System.Windows.Forms.TextBox txtOldPwd;
private System.Windows.Forms.TextBox txtRNewPwd;
private System.Windows.Forms.Button btnOK;
private System.Windows.Forms.Button btnCancel;
public string userId;
public string password;
private System.Windows.Forms.GroupBox grpLine;
private System.Windows.Forms.HelpProvider hlpPassword;
private System.Windows.Forms.ToolTip tipPassword;
private System.ComponentModel.IContainer components;
public frmChangePassword()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
public frmChangePassword(string usrId,string pwd)
{
InitializeComponent();
this.userId = usrId;
this.password = pwd;
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.lblOldPassword = new System.Windows.Forms.Label();
this.lblRetyeNewPassword = new System.Windows.Forms.Label();
this.lblNewPassword = new System.Windows.Forms.Label();
this.txtNewPwd = new System.Windows.Forms.TextBox();
this.txtOldPwd = new System.Windows.Forms.TextBox();
this.txtRNewPwd = new System.Windows.Forms.TextBox();
this.btnOK = new System.Windows.Forms.Button();
this.btnCancel = new System.Windows.Forms.Button();
this.grpLine = new System.Windows.Forms.GroupBox();
this.hlpPassword = new System.Windows.Forms.HelpProvider();
this.tipPassword = new System.Windows.Forms.ToolTip(this.components);
this.SuspendLayout();
//
// lblOldPassword
//
this.lblOldPassword.Location = new System.Drawing.Point(19, 26);
this.lblOldPassword.Name = "lblOldPassword";
this.lblOldPassword.Size = new System.Drawing.Size(120, 25);
this.lblOldPassword.TabIndex = 0;
this.lblOldPassword.Text = "原密码";
//
// lblRetyeNewPassword
//
this.lblRetyeNewPassword.Location = new System.Drawing.Point(19, 112);
this.lblRetyeNewPassword.Name = "lblRetyeNewPassword";
this.lblRetyeNewPassword.Size = new System.Drawing.Size(163, 25);
this.lblRetyeNewPassword.TabIndex = 4;
this.lblRetyeNewPassword.Text = "确认新密码";
//
// lblNewPassword
//
this.lblNewPassword.Location = new System.Drawing.Point(19, 69);
this.lblNewPassword.Name = "lblNewPassword";
this.lblNewPassword.Size = new System.Drawing.Size(120, 25);
this.lblNewPassword.TabIndex = 2;
this.lblNewPassword.Text = "新密码";
//
// txtNewPwd
//
this.txtNewPwd.Location = new System.Drawing.Point(211, 69);
this.txtNewPwd.Name = "txtNewPwd";
this.txtNewPwd.PasswordChar = '*';
this.txtNewPwd.Size = new System.Drawing.Size(120, 21);
this.txtNewPwd.TabIndex = 3;
this.txtNewPwd.Text = "";
this.txtNewPwd.MouseHover += new System.EventHandler(this.txtNewPwd_MouseHover);
//
// txtOldPwd
//
this.txtOldPwd.Location = new System.Drawing.Point(211, 26);
this.txtOldPwd.Name = "txtOldPwd";
this.txtOldPwd.PasswordChar = '*';
this.txtOldPwd.Size = new System.Drawing.Size(120, 21);
this.txtOldPwd.TabIndex = 1;
this.txtOldPwd.Text = "";
this.txtOldPwd.MouseHover += new System.EventHandler(this.txtOldPwd_MouseHover);
//
// txtRNewPwd
//
this.txtRNewPwd.Location = new System.Drawing.Point(211, 112);
this.txtRNewPwd.Name = "txtRNewPwd";
this.txtRNewPwd.PasswordChar = '*';
this.txtRNewPwd.Size = new System.Drawing.Size(120, 21);
this.txtRNewPwd.TabIndex = 5;
this.txtRNewPwd.Text = "";
this.txtRNewPwd.MouseHover += new System.EventHandler(this.txtRNewPwd_MouseHover);
//
// btnOK
//
this.btnOK.Location = new System.Drawing.Point(317, 155);
this.btnOK.Name = "btnOK";
this.btnOK.Size = new System.Drawing.Size(105, 35);
this.btnOK.TabIndex = 6;
this.btnOK.Text = "确定(&O)";
this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
this.btnOK.MouseHover += new System.EventHandler(this.btnOK_MouseHover);
//
// btnCancel
//
this.btnCancel.Location = new System.Drawing.Point(451, 155);
this.btnCancel.Name = "btnCancel";
this.btnCancel.Size = new System.Drawing.Size(115, 35);
this.btnCancel.TabIndex = 7;
this.btnCancel.Text = "取消(&C)";
this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
//
// grpLine
//
this.grpLine.Location = new System.Drawing.Point(-163, 138);
this.grpLine.Name = "grpLine";
this.grpLine.Size = new System.Drawing.Size(864, 8);
this.grpLine.TabIndex = 9;
this.grpLine.TabStop = false;
//
// tipPassword
//
this.tipPassword.AutomaticDelay = 150;
//
// frmChangePassword
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(568, 205);
this.Controls.Add(this.grpLine);
this.Controls.Add(this.btnCancel);
this.Controls.Add(this.btnOK);
this.Controls.Add(this.txtRNewPwd);
this.Controls.Add(this.txtOldPwd);
this.Controls.Add(this.txtNewPwd);
this.Controls.Add(this.lblNewPassword);
this.Controls.Add(this.lblRetyeNewPassword);
this.Controls.Add(this.lblOldPassword);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.Name = "frmChangePassword";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "修改密码";
this.ResumeLayout(false);
}
#endregion
private void ClearTextData()
{
this.txtOldPwd.Text="";
this.txtNewPwd.Text="";
this.txtRNewPwd.Text="";
this.txtOldPwd.Focus();
}
private void btnOK_Click(object sender, System.EventArgs e)
{
if(this.txtOldPwd.Text.Trim() != this.password)
{
MessageBox.Show("原密码不正确");
this.ClearTextData();
return;
}
if (txtNewPwd.Text.Trim().Length == 0)
{
MessageBox.Show("需要新密码");
txtNewPwd.Focus();
return;
}
if(this.txtNewPwd.Text.Trim() != this.txtRNewPwd.Text.Trim())
{
MessageBox.Show("密码不匹配");
txtNewPwd.Focus();
}
else
{
password = this.txtNewPwd.Text.Trim();
this.Close();
}
}
private void btnCancel_Click(object sender, System.EventArgs e)
{
this.Close();
}
private void txtOldPwd_MouseHover(object sender, System.EventArgs e)
{
this.tipPassword.SetToolTip(this.txtOldPwd,"输入原密码");
}
private void txtNewPwd_MouseHover(object sender, System.EventArgs e)
{
this.tipPassword.SetToolTip(this.txtNewPwd,"输入新密码");
}
private void txtRNewPwd_MouseHover(object sender, System.EventArgs e)
{
this.tipPassword.SetToolTip(this.txtRNewPwd,"确认新密码");
}
private void btnOK_MouseHover(object sender, System.EventArgs e)
{
this.tipPassword.SetToolTip(this.btnOK,"修改原密码并存储到记录表中");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -