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

📄 stuserupdatepwd.aspx.cs

📁 数据库:Microsoft SQL Server 2000。 技术平台:Microsoft .NET Framework 2.0.0.0版本。 IIS:Internet Informati
💻 CS
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Configuration;

namespace STcontract.User
{
	/// <summary>
	/// UserUpdatePwd 的摘要说明。
	/// </summary>
	public class UserUpdatePwd : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.TextBox Tbx_pwdok;
		protected System.Web.UI.WebControls.CompareValidator Cv_pwd;
		protected System.Web.UI.WebControls.Panel STPn_user;
		protected System.Web.UI.WebControls.Button STUpdate_ok;
		protected System.Web.UI.WebControls.TextBox STNew_pwd;
		protected System.Web.UI.WebControls.Label STUserPwd;
		protected System.Web.UI.WebControls.TextBox STOld_pwd;
		protected System.Web.UI.WebControls.Button STBack;
		private string STNickName;
		SqlConnection STconn;
		
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			// 在此处放置用户代码以初始化页面
			if(Session["STNickName"] != null)
			{
				//获得数据库连接字符串
				string STconnection = ConfigurationSettings.AppSettings["strconnection"];
				STconn = new SqlConnection(STconnection);	
				//获取登录用户的登录名
				STNickName = Session["STNickName"].ToString();
				STconn.Open();
				//创建查询登录用户密码的sql语句
				string STstrsql = "select STUserPwd from STUser where STNickName = '" + STNickName + "'";
				//创建数据库的SqlCommand对象
				SqlCommand STcmd = new SqlCommand(STstrsql,STconn);
				//执行SqlCommand对象中数据的读取
				SqlDataReader STsdr = STcmd.ExecuteReader();
				while(STsdr.Read())
				{
					//将获得的用户名密码保存到会话中
					Session["STUserPwd"] = STsdr["STUserPwd"];
				}
			}
			else
			{
				Response.Redirect("../Index.aspx");
			}
			
		}

		#region Web 窗体设计器生成的代码
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{    
			this.STUpdate_ok.Click += new System.EventHandler(this.STUpdate_ok_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion



		//点击修改按钮所触发的事件
		private void STUpdate_ok_Click(object sender, System.EventArgs e)
		{
			
			//判断原密码是否为空
			if(STOld_pwd.Text == Session["STUserPwd"].ToString() && STOld_pwd.Text != "")
			{
				//判断新密码和确认密码是否为空,是否相等
				if(STNew_pwd.Text == Tbx_pwdok.Text && STNew_pwd.Text != "" && Tbx_pwdok.Text !="")
				{
					//获得数据库连接字符串
					string STconnection = ConfigurationSettings.AppSettings["strconnection"];
					SqlConnection STconn = new SqlConnection(STconnection);	
					STconn.Open();
					//根据文本框里的内容创建修改密码的sql语句
					string STstrsql="update STUser set STUserPwd = '"+ STNew_pwd.Text + "' where STNickName = '" + STNickName+"'";
					SqlCommand STcmd = new SqlCommand(STstrsql,STconn);
					try
					{
						//执行sql语句
						STcmd.ExecuteNonQuery();
						//提示修改成功
						STUserPwd.Text="修改成功!";
						Response.Redirect("STUserInfo.aspx");

					}
					catch(SqlException)
					{
						STUserPwd.Text="修改有误!";
						STUserPwd.Visible=true;
					}
					STconn.Close();
				}
				else
				{
					STUserPwd.Text = "确认密码不正确!";
				}
			}
			else
			{
				STUserPwd.Text = "原密码不正确!";
			}
		}


	}
}

⌨️ 快捷键说明

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