📄 modifycode.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
namespace AssetManagement
{
/// <summary>
/// modifyCode 的摘要说明。
/// </summary>
public class modifyCode : System.Windows.Forms.Form
{
private string employeeNo;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox textBox3;
private System.Windows.Forms.Button button3;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public modifyCode()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
public modifyCode(string st)
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
employeeNo = st;
//
// 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.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.textBox2 = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.textBox3 = new System.Windows.Forms.TextBox();
this.button3 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(72, 256);
this.button1.Name = "button1";
this.button1.TabIndex = 0;
this.button1.Text = "确定";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(168, 256);
this.button2.Name = "button2";
this.button2.TabIndex = 1;
this.button2.Text = "重置";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// label1
//
this.label1.Location = new System.Drawing.Point(40, 48);
this.label1.Name = "label1";
this.label1.TabIndex = 2;
this.label1.Text = "旧密码";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(176, 48);
this.textBox1.Name = "textBox1";
this.textBox1.PasswordChar = '*';
this.textBox1.Size = new System.Drawing.Size(120, 21);
this.textBox1.TabIndex = 3;
this.textBox1.Text = "";
this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged);
//
// label2
//
this.label2.Location = new System.Drawing.Point(40, 104);
this.label2.Name = "label2";
this.label2.TabIndex = 4;
this.label2.Text = "新密码";
this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(176, 104);
this.textBox2.Name = "textBox2";
this.textBox2.PasswordChar = '*';
this.textBox2.Size = new System.Drawing.Size(120, 21);
this.textBox2.TabIndex = 5;
this.textBox2.Text = "";
this.textBox2.TextChanged += new System.EventHandler(this.textBox2_TextChanged);
//
// label3
//
this.label3.Location = new System.Drawing.Point(40, 160);
this.label3.Name = "label3";
this.label3.TabIndex = 6;
this.label3.Text = "确认新密码";
this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// textBox3
//
this.textBox3.Location = new System.Drawing.Point(176, 160);
this.textBox3.Name = "textBox3";
this.textBox3.PasswordChar = '*';
this.textBox3.Size = new System.Drawing.Size(120, 21);
this.textBox3.TabIndex = 7;
this.textBox3.Text = "";
this.textBox3.TextChanged += new System.EventHandler(this.textBox3_TextChanged);
//
// button3
//
this.button3.Location = new System.Drawing.Point(264, 256);
this.button3.Name = "button3";
this.button3.TabIndex = 8;
this.button3.Text = "退出";
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// modifyCode
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(344, 302);
this.Controls.Add(this.button3);
this.Controls.Add(this.textBox3);
this.Controls.Add(this.label3);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.label2);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.label1);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.MaximizeBox = false;
this.Name = "modifyCode";
this.Text = "modifyCode";
this.ResumeLayout(false);
}
#endregion
private void textBox1_TextChanged(object sender, System.EventArgs e)
{
if (this.textBox1.Text.Trim().Length > 8)
{
MessageBox.Show("输入无效!");
this.textBox1.Text = "";
this.textBox1.Focus();
}
}
private void textBox2_TextChanged(object sender, System.EventArgs e)
{
if (this.textBox2.Text.Trim().Length > 8)
{
MessageBox.Show("输入无效!");
this.textBox2.Text = "";
this.textBox2.Focus();
}
}
private void textBox3_TextChanged(object sender, System.EventArgs e)
{
if (this.textBox3.Text.Trim().Length > 8)
{
MessageBox.Show("输入无效!");
this.textBox3.Text = "";
this.textBox3.Focus();
}
}
private void button1_Click(object sender, System.EventArgs e)
{
bool check = false;
if (this.textBox1.Text.Trim() == "")
{
MessageBox.Show("请输入旧密码!");
}
else
{
Connection s = new Connection();
SqlConnection conn = new SqlConnection(s.getConnectionString);
conn.Open();
string str1 = "select * from employee";
SqlCommand cmd = new SqlCommand(str1,conn);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
if (this.employeeNo == Convert.ToString(dr["employeeNo"]))
{
if (this.textBox1.Text.Trim() == Convert.ToString(dr["epassword"]))
{
check = true;
break;
}
}
}
dr.Close();
if (check)
{
if (this.textBox2.Text.Trim() == "")
{
MessageBox.Show("请输入新密码!");
this.textBox2.Focus();
}
else
{
if (this.textBox3.Text.Trim() == "")
{
MessageBox.Show("请输入确认密码!");
this.textBox3.Focus();
}
else
{
if (this.textBox2.Text.Trim() != this.textBox3.Text.Trim())
{
MessageBox.Show("确认密码有误");
this.textBox3.Text = "";
this.textBox3.Focus();
}
else
{
string str2 = "update employee set epassword = '" + this.textBox2.Text.Trim() + "' where employeeNo = '" + this.employeeNo + "'";
SqlCommand cmd1 = new SqlCommand(str2,conn);
try
{
cmd1.ExecuteNonQuery();
MessageBox.Show("密码修改成功!");
this.textBox1.Text = "";
this.textBox2.Text = "";
this.textBox3.Text = "";
}
catch
{
MessageBox.Show("密码修改失败!");
this.textBox1.Text = "";
this.textBox2.Text = "";
this.textBox3.Text = "";
}
}
}
}
}
else
{
MessageBox.Show("输入的旧密码不正确!");
this.textBox1.Text = "";
}
conn.Close();
}
}
private void button2_Click(object sender, System.EventArgs e)
{
this.textBox1.Text = "";
this.textBox2.Text = "";
this.textBox3.Text = "";
}
private void button3_Click(object sender, System.EventArgs e)
{
this.Close();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -