pwd.cs
上传用户:chizxy
上传日期:2014-11-29
资源大小:407k
文件大小:8k
- 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);
- }
- }
- }
- }