⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dlgpwdset.cs

📁 功能设计:平台管理、收费点维护、收费项目管理、缴费管理
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.OracleClient;


namespace GlobleUtility
{
	/// <summary>
	/// 类名: CdlgPwdSet 
	/// 功能: 修改管理员密码
	/// 使用方法: 调用该类的构造函数,然后以有模式方式显示窗体
	/// </summary>
	public class CdlgPwdSet : System.Windows.Forms.Form
	{
		private string m_sUserName;		//管理员用户名
		//private string m_sDbUser;		//数据库用户名
		
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.TextBox txtOldPwd;
		private System.Windows.Forms.TextBox txtConfirmPwd;
		private System.Windows.Forms.Button btnOk;
		private System.Windows.Forms.Button btnCancle;
		private System.Windows.Forms.TextBox txtNewPwd;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		//构造函数中需要传递两个参数,管理员用户名和数据库用户名
		//public CdlgPwdSet(string userName, string dbUser)
		public CdlgPwdSet(string userName)
		{
			this.m_sUserName = userName;
			//this.m_sDbUser = dbUser;
			//
			// 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()
		{
			this.label1 = new System.Windows.Forms.Label();
			this.label2 = new System.Windows.Forms.Label();
			this.label3 = new System.Windows.Forms.Label();
			this.txtOldPwd = new System.Windows.Forms.TextBox();
			this.txtNewPwd = new System.Windows.Forms.TextBox();
			this.txtConfirmPwd = new System.Windows.Forms.TextBox();
			this.btnOk = new System.Windows.Forms.Button();
			this.btnCancle = new System.Windows.Forms.Button();
			this.SuspendLayout();
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(16, 16);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(48, 16);
			this.label1.TabIndex = 0;
			this.label1.Text = "旧密码";
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(16, 48);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(48, 16);
			this.label2.TabIndex = 0;
			this.label2.Text = "新密码";
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(16, 80);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(72, 16);
			this.label3.TabIndex = 0;
			this.label3.Text = "确认新密码";
			// 
			// txtOldPwd
			// 
			this.txtOldPwd.Location = new System.Drawing.Point(88, 16);
			this.txtOldPwd.Name = "txtOldPwd";
			this.txtOldPwd.PasswordChar = '*';
			this.txtOldPwd.Size = new System.Drawing.Size(152, 21);
			this.txtOldPwd.TabIndex = 1;
			this.txtOldPwd.Text = "";
			this.txtOldPwd.TextChanged += new System.EventHandler(this.txtOldPwd_TextChanged);
			// 
			// txtNewPwd
			// 
			this.txtNewPwd.Location = new System.Drawing.Point(88, 48);
			this.txtNewPwd.Name = "txtNewPwd";
			this.txtNewPwd.PasswordChar = '*';
			this.txtNewPwd.Size = new System.Drawing.Size(152, 21);
			this.txtNewPwd.TabIndex = 1;
			this.txtNewPwd.Text = "";
			this.txtNewPwd.TextChanged += new System.EventHandler(this.txtNewPwd_TextChanged);
			// 
			// txtConfirmPwd
			// 
			this.txtConfirmPwd.Location = new System.Drawing.Point(88, 80);
			this.txtConfirmPwd.Name = "txtConfirmPwd";
			this.txtConfirmPwd.PasswordChar = '*';
			this.txtConfirmPwd.Size = new System.Drawing.Size(152, 21);
			this.txtConfirmPwd.TabIndex = 1;
			this.txtConfirmPwd.Text = "";
			this.txtConfirmPwd.TextChanged += new System.EventHandler(this.txtConfirmPwd_TextChanged);
			// 
			// btnOk
			// 
			this.btnOk.Enabled = false;
			this.btnOk.Location = new System.Drawing.Point(88, 120);
			this.btnOk.Name = "btnOk";
			this.btnOk.Size = new System.Drawing.Size(72, 24);
			this.btnOk.TabIndex = 2;
			this.btnOk.Text = "确认(&O)";
			this.btnOk.Click += new System.EventHandler(this.btnOk_Click);
			// 
			// btnCancle
			// 
			this.btnCancle.Location = new System.Drawing.Point(168, 120);
			this.btnCancle.Name = "btnCancle";
			this.btnCancle.Size = new System.Drawing.Size(72, 24);
			this.btnCancle.TabIndex = 2;
			this.btnCancle.Text = "取消(&C)";
			this.btnCancle.Click += new System.EventHandler(this.btnCancle_Click);
			// 
			// CdlgPwdSet
			// 
			this.AcceptButton = this.btnOk;
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.CancelButton = this.btnCancle;
			this.ClientSize = new System.Drawing.Size(258, 154);
			this.Controls.Add(this.btnOk);
			this.Controls.Add(this.txtOldPwd);
			this.Controls.Add(this.txtNewPwd);
			this.Controls.Add(this.txtConfirmPwd);
			this.Controls.Add(this.label1);
			this.Controls.Add(this.label2);
			this.Controls.Add(this.label3);
			this.Controls.Add(this.btnCancle);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Name = "CdlgPwdSet";
			this.ShowInTaskbar = false;
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
			this.Text = "修改密码";
			this.ResumeLayout(false);

		}
		#endregion

		//清除三个密码框中的文字
		private void ClearAll()
		{
			txtOldPwd.Clear();
			txtNewPwd.Clear();
			txtConfirmPwd.Clear();
		}

		//“取消”按钮的点击事件
		private void btnCancle_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}

		/****************************************************************************
		Function Description:
			“确定”按钮的点击事件,主要有以下几个步骤:
			1、检查新密码与确认密码是否一致,不一致返回;
			2、检查旧密码是否正确,不正确返回;
			3、修改密码。
			其中2、3步用存储过程实现。
		Arguments:
			sender:	消息源
			e:		消息内容
		Return Value:
			NONE
		History:
			Created on 07/26/2004 by chenxiaoxu@ailab.net
		*****************************************************************************/
		private void btnOk_Click(object sender, System.EventArgs e)
		{
			//检查新密码与确认密码是否一致,不一致返回
			ErrorCode E = new ErrorCode();
			if (txtNewPwd.Text != txtConfirmPwd.Text)
			{
				E.ShowMessage(ErrorCode.E_5_PwdNotMatch_Code);
				ClearAll();
				txtOldPwd.Focus();
				return;
			}

			//调用存储过程“Common.SP_AdminPwd_Modify”修改管理员密码
			OracleParameter[] inParam = {new OracleParameter(), new OracleParameter(), new OracleParameter()};
			inParam[0].ParameterName = "p_UserName";
			inParam[0].OracleType = OracleType.VarChar;
			inParam[0].Value = m_sUserName;

			inParam[1].ParameterName = "p_OldPwd";
			inParam[1].OracleType = OracleType.VarChar;
			inParam[1].Value = txtOldPwd.Text;

			inParam[2].ParameterName = "p_NewPwd";
			inParam[2].OracleType = OracleType.VarChar;
			inParam[2].Value = txtNewPwd.Text;

			OracleParameter[] outParam = {new OracleParameter()};
			outParam[0].ParameterName = "p_Result";
			outParam[0].OracleType = OracleType.Int32;
			outParam[0].Direction = ParameterDirection.Output;

			try
			{
				GlobleHelper.ExecStoredProc("SP_AdminPwd_Modify", inParam, ref outParam);
			}
			catch
			{
				E.ShowMessage(ErrorCode.E_8_DBUnknownError_Code);
				return;
			}

			int error = Convert.ToInt32(outParam[0].Value);
			if (error != 0)
			{
				E.ShowMessage(error);
				ClearAll();
				txtOldPwd.Focus();
				return;
			}

			MessageBox.Show(this, "密码修改成功!", "更改密码", MessageBoxButtons.OK, MessageBoxIcon.Information);
			this.Close();
		}

		//检查数据的合法性。注意,这里只是简单地检查是否有字符输入
		private bool ValidateParam()
		{
			if(txtOldPwd.Text.Trim().Length == 0)
				return false;
			if(txtNewPwd.Text.Trim().Length == 0)
				return false;
			if(txtConfirmPwd.Text.Trim().Length == 0)
				return false;

			return true;
		}

		private void txtOldPwd_TextChanged(object sender, System.EventArgs e)
		{
			if(ValidateParam())
				btnOk.Enabled = true;
			else
				btnOk.Enabled = false;
		}

		private void txtNewPwd_TextChanged(object sender, System.EventArgs e)
		{
			if(ValidateParam())
				btnOk.Enabled = true;
			else
				btnOk.Enabled = false;
		}

		private void txtConfirmPwd_TextChanged(object sender, System.EventArgs e)
		{
			if(ValidateParam())
				btnOk.Enabled = true;
			else
				btnOk.Enabled = false;
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -