📄 frmrepwd.cs
字号:
using System;
using System.Data.SqlClient;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
namespace MainPrj_CarShop
{
/// <summary>
/// frmRePwd 的摘要说明。
/// </summary>
public class frmRePwd : System.Windows.Forms.Form
{
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
private string _userID;
private System.Windows.Forms.TextBox txtNewPwd;
private System.Windows.Forms.TextBox txtOrgPwd;
private System.Windows.Forms.TextBox txtName;
private System.Windows.Forms.TextBox txtRePwd;
private System.Data.SqlClient.SqlConnection _sqlCon;
private System.Data.SqlClient.SqlCommand _sqlComRePwd;
private System.Data.SqlClient.SqlCommand _sqlQuery;
private string _userName;
public frmRePwd(string userID,string userName)
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
this._userID=userID;
this._userName=userName;
//
// 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.groupBox1 = new System.Windows.Forms.GroupBox();
this.txtRePwd = new System.Windows.Forms.TextBox();
this.label4 = new System.Windows.Forms.Label();
this.txtNewPwd = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.txtOrgPwd = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.txtName = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this._sqlCon = new System.Data.SqlClient.SqlConnection();
this._sqlComRePwd = new System.Data.SqlClient.SqlCommand();
this._sqlQuery = new System.Data.SqlClient.SqlCommand();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// groupBox1
//
this.groupBox1.Controls.Add(this.txtRePwd);
this.groupBox1.Controls.Add(this.label4);
this.groupBox1.Controls.Add(this.txtNewPwd);
this.groupBox1.Controls.Add(this.label3);
this.groupBox1.Controls.Add(this.txtOrgPwd);
this.groupBox1.Controls.Add(this.label2);
this.groupBox1.Controls.Add(this.txtName);
this.groupBox1.Controls.Add(this.label1);
this.groupBox1.Dock = System.Windows.Forms.DockStyle.Top;
this.groupBox1.Location = new System.Drawing.Point(0, 0);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(290, 192);
this.groupBox1.TabIndex = 6;
this.groupBox1.TabStop = false;
//
// txtRePwd
//
this.txtRePwd.Location = new System.Drawing.Point(105, 152);
this.txtRePwd.Name = "txtRePwd";
this.txtRePwd.PasswordChar = '@';
this.txtRePwd.Size = new System.Drawing.Size(152, 23);
this.txtRePwd.TabIndex = 13;
this.txtRePwd.Text = "";
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(33, 154);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(63, 19);
this.label4.TabIndex = 12;
this.label4.Text = "重复密码";
//
// txtNewPwd
//
this.txtNewPwd.Location = new System.Drawing.Point(104, 112);
this.txtNewPwd.Name = "txtNewPwd";
this.txtNewPwd.PasswordChar = '@';
this.txtNewPwd.Size = new System.Drawing.Size(152, 23);
this.txtNewPwd.TabIndex = 11;
this.txtNewPwd.Text = "";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(48, 114);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(48, 19);
this.label3.TabIndex = 10;
this.label3.Text = "新密码";
//
// txtOrgPwd
//
this.txtOrgPwd.Location = new System.Drawing.Point(104, 72);
this.txtOrgPwd.Name = "txtOrgPwd";
this.txtOrgPwd.PasswordChar = '@';
this.txtOrgPwd.Size = new System.Drawing.Size(152, 23);
this.txtOrgPwd.TabIndex = 9;
this.txtOrgPwd.Text = "";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(32, 74);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(63, 19);
this.label2.TabIndex = 8;
this.label2.Text = "原始密码";
//
// txtName
//
this.txtName.BackColor = System.Drawing.Color.LightGoldenrodYellow;
this.txtName.Location = new System.Drawing.Point(104, 32);
this.txtName.Name = "txtName";
this.txtName.ReadOnly = true;
this.txtName.Size = new System.Drawing.Size(152, 23);
this.txtName.TabIndex = 7;
this.txtName.TabStop = false;
this.txtName.Text = "";
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(32, 34);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(63, 19);
this.label1.TabIndex = 6;
this.label1.Text = "您的姓名";
//
// button1
//
this.button1.BackColor = System.Drawing.Color.LightSteelBlue;
this.button1.Location = new System.Drawing.Point(48, 208);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(80, 32);
this.button1.TabIndex = 7;
this.button1.Text = "提交(&C)";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.BackColor = System.Drawing.Color.LightSteelBlue;
this.button2.Location = new System.Drawing.Point(160, 208);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(80, 32);
this.button2.TabIndex = 7;
this.button2.Text = "返回(&E)";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// _sqlCon
//
this._sqlCon.ConnectionString = "workstation id=Nebular;packet size=4096;user id=sa;data source=\".\";persist securi" +
"ty info=False;initial catalog=dbCarsys";
//
// _sqlComRePwd
//
this._sqlComRePwd.CommandText = "UPDATE tblUser SET uPwd = @uPwd WHERE (uCode = @uCode)";
this._sqlComRePwd.Connection = this._sqlCon;
this._sqlComRePwd.Parameters.Add(new System.Data.SqlClient.SqlParameter("@uPwd", System.Data.SqlDbType.VarChar, 10, "uPwd"));
this._sqlComRePwd.Parameters.Add(new System.Data.SqlClient.SqlParameter("@uCode", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "uCode", System.Data.DataRowVersion.Original, null));
//
// _sqlQuery
//
this._sqlQuery.CommandText = "SELECT 1 AS Expr1 FROM tblUser WHERE (uCode = @uCode) AND (uPwd = @uPwd)";
this._sqlQuery.Connection = this._sqlCon;
this._sqlQuery.Parameters.Add(new System.Data.SqlClient.SqlParameter("@uCode", System.Data.SqlDbType.VarChar, 10, "uCode"));
this._sqlQuery.Parameters.Add(new System.Data.SqlClient.SqlParameter("@uPwd", System.Data.SqlDbType.VarChar, 10, "uPwd"));
//
// frmRePwd
//
this.AutoScaleBaseSize = new System.Drawing.Size(7, 16);
this.BackColor = System.Drawing.Color.WhiteSmoke;
this.ClientSize = new System.Drawing.Size(290, 256);
this.Controls.Add(this.button1);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.button2);
this.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "frmRePwd";
this.Text = "修改登陆密码";
this.Load += new System.EventHandler(this.frmRePwd_Load);
this.groupBox1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private void button1_Click(object sender, System.EventArgs e)
{
if(!CheckBox())
return;
try
{
this._sqlCon.Open();
this._sqlQuery.Parameters[0].Value=this._userID;
this._sqlQuery.Parameters[1].Value=this.txtOrgPwd.Text;
if(this._sqlQuery.ExecuteScalar()==null)
{
MessageBox.Show("原始密码输入错误!");
this.txtOrgPwd.Focus();
return;
}
this._sqlComRePwd.Parameters[0].Value=this.txtNewPwd.Text;
this._sqlComRePwd.Parameters[1].Value=this._userID;
this._sqlComRePwd.ExecuteNonQuery();
MessageBox.Show("密码修改成功!","修改密码成功",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
catch(SqlException ex)
{
MessageBox.Show("数据库错误!请与管理员联系。\n"+ex.Message,"错误",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
catch(Exception ex)
{
MessageBox.Show("数据库错误!请与管理员联系。\n"+ex.Message,"错误",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
finally
{
this._sqlCon.Close();
}
}
private bool CheckBox()
{
try
{
if(txtOrgPwd.Text=="")
{
MessageBox.Show("原始密码不得为空!","错误",MessageBoxButtons.OK,MessageBoxIcon.Error);
this.txtOrgPwd.Focus();
return false;
}
if(txtNewPwd.Text=="")
{
MessageBox.Show("新密码不得为空!","错误",MessageBoxButtons.OK,MessageBoxIcon.Error);
this.txtNewPwd.Focus();
return false;
}
if(txtRePwd.Text=="")
{
MessageBox.Show("请重复新密码!","错误",MessageBoxButtons.OK,MessageBoxIcon.Error);
this.txtRePwd.Focus();
return false;
}
if(txtRePwd.Text!=txtNewPwd.Text)
{
MessageBox.Show("两次输入的密码不同,请检查输入!","错误",MessageBoxButtons.OK,MessageBoxIcon.Error);
this.txtRePwd.Focus();
this.txtRePwd.SelectAll();
return false;
}
}
catch(Exception ex)
{
MessageBox.Show("系统发生一个异常的错误!请与管理员联系。\n"+ex.Message,"系统错误",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
return true;
}
private void frmRePwd_Load(object sender, System.EventArgs e)
{
try
{
this.txtName.Text=this._userName;
}
catch(Exception ex)
{
MessageBox.Show("系统发生一个异常的错误!请与管理员联系。\n"+ex.Message,"系统错误",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}
private void button2_Click(object sender, System.EventArgs e)
{
try
{
this.Close();
}
catch(Exception ex)
{
MessageBox.Show("系统发生一个异常的错误!请与管理员联系。\n"+ex.Message,"系统错误",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -