📄 pwdmodifymodule.ascx.cs
字号:
namespace KhfwWeb.Modules
{
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
/// <summary>
/// PwdModifyModule 的摘要说明。
/// </summary>
public class PwdModifyModule :ModuleBase
{
protected System.Web.UI.WebControls.Label UserNameLabel;
protected System.Web.UI.WebControls.TextBox OldPwdTextBox;
protected System.Web.UI.WebControls.RequiredFieldValidator OldPwdRequiredFieldValidator;
protected System.Web.UI.WebControls.CustomValidator ValidateCustomValidator;
protected System.Web.UI.WebControls.TextBox NewPwdTextBox;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
protected System.Web.UI.WebControls.CompareValidator CompareValidator1;
protected System.Web.UI.WebControls.TextBox ConfirmPwdTextBox;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator2;
protected System.Web.UI.WebControls.CompareValidator CompareValidator2;
protected System.Web.UI.WebControls.ValidationSummary LogonValidationSummary;
protected System.Web.UI.WebControls.Button ModifyButton;
protected System.Web.UI.WebControls.Label ShowMsg;
private void Page_Load(object sender, System.EventArgs e)
{
UserNameLabel.Text=Request.QueryString["UserName"].ToString();
}
//验证原密码是否正确
public void IsPwdValidate(object source, System.Web.UI.WebControls.ServerValidateEventArgs args)
{
//从文件Web.config中读取连接字符串
string sqldb= ConfigurationSettings.AppSettings["ConnectionString"];
//连接JdglSys数据库
SqlConnection Conn= new SqlConnection (sqldb);
Conn.Open ();
//构造SQL语句,该语句在UsersInfo表中检查密码是否正确
string checksql= "select * from UsersInfo where Name='"+UserNameLabel.Text.Trim() +"'and Password='"+OldPwdTextBox.Text.Trim()+"'";
//创建Command对象
SqlCommand mycommand=new SqlCommand (checksql,Conn);
//执行ExecuteReader ()方法
SqlDataReader dr=mycommand.ExecuteReader ();
if(dr.Read ())
{
args.IsValid =true;//密码正确
}
else
{
args.IsValid =false;//密码不正确
}
//关闭连接
Conn.Close();
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器
/// 修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.ModifyButton.Click += new System.EventHandler(this.ModifyButton_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void ModifyButton_Click(object sender, System.EventArgs e)
{
if(Page.IsValid)
{
//修改密码
//从文件Web.config中读取连接字符串
string sqldb = ConfigurationSettings.AppSettings["ConnectionString"];
//连接JdglSys数据库
SqlConnection Conn = new SqlConnection (sqldb);
Conn.Open ();
//定义sql语句
String updatesql="update UsersInfo set Password= @Password where Name = @Name";
//利用Command对象调用updatesql
SqlCommand mycommand=new SqlCommand (updatesql,Conn);
//添加参数
mycommand.Parameters .Add ("@Name",SqlDbType.VarChar);
mycommand.Parameters .Add ("@Password",SqlDbType.VarChar);
//给存储过程的参数赋值
mycommand.Parameters ["@Name"].Value =UserNameLabel.Text;
mycommand.Parameters ["@Password"].Value =NewPwdTextBox.Text.Trim();
try
{
mycommand.ExecuteNonQuery();
ShowMsg.Text="密码修改成功,请注销后验证新密码";
ShowMsg.Style["color"]="green";}
catch(SqlException error)
{
ShowMsg.Text="密码修改未成功,请稍后再试。原因:"+error.Message;
ShowMsg.Style["color"]="red";
}
//关闭连接
Conn.Close();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -