?? pwd.cs
字號:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
namespace MKIms3
{
/// <summary>
/// pwd 的摘要說明。
/// </summary>
public class pwd : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox txt_old_pwd;
private System.Windows.Forms.TextBox txt_new_pwd;
private System.Windows.Forms.TextBox txt_same_pwd;
private System.Windows.Forms.Button btn_ok;
private System.Windows.Forms.Button btn_esc;
private System.Windows.Forms.PictureBox pictureBox1;
/// <summary>
/// 必需的設計器變量。
/// </summary>
private System.ComponentModel.Container components = null;
public pwd()
{
//
// 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(pwd));
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.txt_old_pwd = new System.Windows.Forms.TextBox();
this.txt_new_pwd = new System.Windows.Forms.TextBox();
this.txt_same_pwd = new System.Windows.Forms.TextBox();
this.btn_ok = new System.Windows.Forms.Button();
this.btn_esc = new System.Windows.Forms.Button();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.SuspendLayout();
//
// label1
//
this.label1.Location = new System.Drawing.Point(144, 16);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(56, 23);
this.label1.TabIndex = 0;
this.label1.Text = "舊密碼";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// label2
//
this.label2.Location = new System.Drawing.Point(144, 48);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(56, 23);
this.label2.TabIndex = 1;
this.label2.Text = "新密碼";
this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// label3
//
this.label3.Location = new System.Drawing.Point(144, 80);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(56, 23);
this.label3.TabIndex = 2;
this.label3.Text = "確認密碼";
this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// txt_old_pwd
//
this.txt_old_pwd.Location = new System.Drawing.Point(208, 16);
this.txt_old_pwd.Name = "txt_old_pwd";
this.txt_old_pwd.PasswordChar = '*';
this.txt_old_pwd.Size = new System.Drawing.Size(112, 21);
this.txt_old_pwd.TabIndex = 3;
this.txt_old_pwd.Text = "";
//
// txt_new_pwd
//
this.txt_new_pwd.Location = new System.Drawing.Point(208, 48);
this.txt_new_pwd.Name = "txt_new_pwd";
this.txt_new_pwd.PasswordChar = '*';
this.txt_new_pwd.Size = new System.Drawing.Size(112, 21);
this.txt_new_pwd.TabIndex = 4;
this.txt_new_pwd.Text = "";
//
// txt_same_pwd
//
this.txt_same_pwd.Location = new System.Drawing.Point(208, 80);
this.txt_same_pwd.Name = "txt_same_pwd";
this.txt_same_pwd.PasswordChar = '*';
this.txt_same_pwd.Size = new System.Drawing.Size(112, 21);
this.txt_same_pwd.TabIndex = 5;
this.txt_same_pwd.Text = "";
//
// btn_ok
//
this.btn_ok.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btn_ok.Location = new System.Drawing.Point(152, 120);
this.btn_ok.Name = "btn_ok";
this.btn_ok.Size = new System.Drawing.Size(56, 24);
this.btn_ok.TabIndex = 6;
this.btn_ok.Text = "確認";
this.btn_ok.Click += new System.EventHandler(this.btn_ok_Click);
//
// btn_esc
//
this.btn_esc.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.btn_esc.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btn_esc.Location = new System.Drawing.Point(240, 120);
this.btn_esc.Name = "btn_esc";
this.btn_esc.Size = new System.Drawing.Size(56, 24);
this.btn_esc.TabIndex = 7;
this.btn_esc.Text = "退出";
//
// pictureBox1
//
this.pictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
this.pictureBox1.Location = new System.Drawing.Point(8, 8);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(128, 136);
this.pictureBox1.TabIndex = 8;
this.pictureBox1.TabStop = false;
//
// pwd
//
this.AcceptButton = this.btn_ok;
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.CancelButton = this.btn_esc;
this.ClientSize = new System.Drawing.Size(336, 157);
this.Controls.Add(this.pictureBox1);
this.Controls.Add(this.btn_esc);
this.Controls.Add(this.btn_ok);
this.Controls.Add(this.txt_same_pwd);
this.Controls.Add(this.txt_new_pwd);
this.Controls.Add(this.txt_old_pwd);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "pwd";
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "用戶密碼修改";
this.ResumeLayout(false);
}
#endregion
private void btn_ok_Click(object sender, System.EventArgs e)
{
string pwd = this.txt_old_pwd.Text.Trim();
string newpwd = this.txt_new_pwd.Text.Trim();
string samepwd = this.txt_same_pwd.Text.Trim();
if(pwd.Length==0 || newpwd.Length == 0 || samepwd.Length == 0)
{
MessageBox.Show("所有輸入不能為空,請檢查您的輸入!","錯誤信息",MessageBoxButtons.OK,MessageBoxIcon.Warning);
}
else
{
if(check_old_pwd(pwd))
{
change_pwd(newpwd, samepwd);
}
}
}
private bool check_old_pwd(string pwd)
{
DataBase myDB = new DataBase();
SqlDataReader myReader = null;
SqlParameter[] myParamers={new SqlParameter("@u_name",SqlDbType.Char,10)} ;
myParamers[0].Value = App.u_name;
myReader = myDB.RunProcedure("up_get_upass",myParamers);
if(myReader!=null)
{
if(myReader.Read())
{
if(myReader["u_pass"].ToString().Trim()==pwd)
{
myReader.Close();
//用戶身份合法,可以修改密碼
return true;
}
else
{
MessageBox.Show("原始密碼錯誤!","錯誤信息",MessageBoxButtons.OK,MessageBoxIcon.Warning);
return false;
}
}
else
{
MessageBox.Show("當前用戶信息已被刪除,不能更改密碼","錯誤信息",MessageBoxButtons.OK,MessageBoxIcon.Warning);
return false;
}
}
else
{
return false;
}
}
private void change_pwd(string newpwd,string samepwd)
{
if(newpwd == samepwd)
{
DataBase myDB = new DataBase();
SqlParameter[] myParamers={new SqlParameter("@u_name",SqlDbType.Char,10),
new SqlParameter("@u_pass",SqlDbType.Char,10)
} ;
myParamers[0].Value = App.u_name;
myParamers[1].Value = newpwd;
if(myDB.RunProcedure_Nr("up_change_pwd ",myParamers))
{
MessageBox.Show("密碼修改成功,請保管好您的密碼!","提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
else
{
MessageBox.Show("系統錯誤,密碼修改不成功!","錯誤信息",MessageBoxButtons.OK,MessageBoxIcon.Warning);
}
}
else
{
MessageBox.Show("兩次輸入密碼不一致!","錯誤信息",MessageBoxButtons.OK,MessageBoxIcon.Warning);
}
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -