📄 modifypassword.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using Model;
using Business_Logic;
namespace Railroad_Trip
{
/// <summary>
/// ModifyPassword 的摘要说明。
/// </summary>
public class ModifyPassword : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox txtUserName;
private System.Windows.Forms.TextBox txtOldPass;
private System.Windows.Forms.TextBox txtNewPass;
private System.Windows.Forms.TextBox txtANewPass;
private string userName,oldPass,newPass,aNewPass;
private System.Windows.Forms.Label lblCancel;
private System.Windows.Forms.Label lblOK;//用户名,旧密码,新密码,重复的新密码
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public ModifyPassword()
{
//
// 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()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(ModifyPassword));
this.txtUserName = new System.Windows.Forms.TextBox();
this.txtOldPass = new System.Windows.Forms.TextBox();
this.txtNewPass = new System.Windows.Forms.TextBox();
this.txtANewPass = new System.Windows.Forms.TextBox();
this.lblCancel = new System.Windows.Forms.Label();
this.lblOK = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// txtUserName
//
this.txtUserName.Location = new System.Drawing.Point(288, 16);
this.txtUserName.Name = "txtUserName";
this.txtUserName.Size = new System.Drawing.Size(108, 21);
this.txtUserName.TabIndex = 0;
this.txtUserName.Text = "";
//
// txtOldPass
//
this.txtOldPass.Location = new System.Drawing.Point(288, 48);
this.txtOldPass.Name = "txtOldPass";
this.txtOldPass.PasswordChar = '*';
this.txtOldPass.Size = new System.Drawing.Size(108, 21);
this.txtOldPass.TabIndex = 1;
this.txtOldPass.Text = "";
//
// txtNewPass
//
this.txtNewPass.Location = new System.Drawing.Point(288, 80);
this.txtNewPass.Name = "txtNewPass";
this.txtNewPass.PasswordChar = '*';
this.txtNewPass.Size = new System.Drawing.Size(108, 21);
this.txtNewPass.TabIndex = 2;
this.txtNewPass.Text = "";
//
// txtANewPass
//
this.txtANewPass.Location = new System.Drawing.Point(288, 112);
this.txtANewPass.Name = "txtANewPass";
this.txtANewPass.PasswordChar = '*';
this.txtANewPass.Size = new System.Drawing.Size(108, 21);
this.txtANewPass.TabIndex = 3;
this.txtANewPass.Text = "";
//
// lblCancel
//
this.lblCancel.BackColor = System.Drawing.Color.Transparent;
this.lblCancel.Location = new System.Drawing.Point(196, 168);
this.lblCancel.Name = "lblCancel";
this.lblCancel.Size = new System.Drawing.Size(88, 24);
this.lblCancel.TabIndex = 6;
this.lblCancel.Click += new System.EventHandler(this.lblCancel_Click);
//
// lblOK
//
this.lblOK.BackColor = System.Drawing.Color.Transparent;
this.lblOK.Location = new System.Drawing.Point(312, 168);
this.lblOK.Name = "lblOK";
this.lblOK.Size = new System.Drawing.Size(92, 24);
this.lblOK.TabIndex = 7;
this.lblOK.Click += new System.EventHandler(this.lblOK_Click);
//
// ModifyPassword
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
this.ClientSize = new System.Drawing.Size(422, 279);
this.Controls.Add(this.lblOK);
this.Controls.Add(this.lblCancel);
this.Controls.Add(this.txtANewPass);
this.Controls.Add(this.txtNewPass);
this.Controls.Add(this.txtOldPass);
this.Controls.Add(this.txtUserName);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.Name = "ModifyPassword";
this.Text = "修改密码";
this.ResumeLayout(false);
}
#endregion
#region 确定提交修改事件
private void lblOK_Click(object sender, System.EventArgs e)
{
//确定事件
userName=txtUserName.Text;
oldPass=txtOldPass.Text;
newPass=txtNewPass.Text;
aNewPass=txtANewPass.Text;
if(txtUserName.Text=="")
{
//判断用户名是否输入
MessageBox.Show("用户名不能为空!","提示");
return;
}
else
{
if(txtOldPass.Text=="")
{
//判断旧密码是否输入
MessageBox.Show("旧密码不能为空!","提示");
return;
}
else
{
if(txtNewPass.Text=="")
{
//判断新密码是否输入
MessageBox.Show("新密码不能为空!","提示");
return;
}
else
{
if(newPass.Length<6)
{
MessageBox.Show("密码的长度至少为6位!","提示");
return;
}
else
{}
if(txtANewPass.Text=="")
{
//判断重复输入的新密码是否输入
MessageBox.Show("请再输入一次新密码!","提示");
return;
}
else
{
if(aNewPass.Length<6)
{
MessageBox.Show("确认密码的长度至少为6位!","提示");
return;
}
else
{}
if(newPass==aNewPass)
{
//判断旧密码与用户名对应否?
LoginEntity data2=new LoginEntity();
data2._UserName=userName;
data2._PassWord=oldPass;
data2._NewPass=aNewPass;
Handle panduan2=new Handle();
if(panduan2.ILogin(data2))
{
//判断修改是否成功
if(panduan2.ModifyPass(data2))
{
MessageBox.Show("修改成功!","提示");
this.Dispose();
}
else
{
MessageBox.Show("修改失败! 稍后再试。","提示");
txtOldPass.Text="";
txtNewPass.Text="";
txtANewPass.Text="";
}
}
else
{
MessageBox.Show("用户名与旧密码不对应!","提示");
txtOldPass.Text="";
return;
}
}
else
{
MessageBox.Show("新密码两次输入的不相同!","提示");
return;
}
}
}
}
}
}
#endregion
private void lblCancel_Click(object sender, System.EventArgs e)
{
//取消事件
this.Dispose();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -