📄 user.aspx.cs
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class User : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//读取信息
if (!IsPostBack)
{
userInfo();
}
}
//函数userInfo()用于读取页面基本信息
private void userInfo()
{
//检查用户编号是否有值
if (Session["userID"] != null)
{
//将Session实体化
int userID = Int32.Parse(Session["userID"].ToString());
//根据用户编号实例化用户信息
string strSql = "SELECT [userID],[userLoginID],[userPwd],[userName],[userStauts],[scID] FROM [userInfo] WHERE [userID] ='" + userID + "'";
UserInfo txtuserinfo = new UserInfo();
txtuserinfo = DBHelper.sqllogin(strSql);
//显示用户登录名,并设置为无法更改
txtLoginID.Text = txtuserinfo.UserLoginID;
txtLoginID.Enabled = false;
//显示用户姓名
txtName.Text = txtuserinfo.UserName;
//选择用户身份,并设置为无法更改
statusDDL.SelectedValue = txtuserinfo.UserStauts.ToString();
statusDDL.Enabled = false;
}
}
//增加或修改用户信息
protected void Button1_Click(object sender, EventArgs e)
{
//进行非空判断,若为空则返回错误信息
if (!txtLoginID.Text.Equals("") && !txtPwd.Text.Equals("") && !txtRePwd.Text.Equals("") && !txtName.Text.Equals("") && Int32.Parse(statusDDL.SelectedValue)!=0)
{
//进行密码重复输入判断,若两次输入不一致则返回错误信息
if (txtRePwd.Text.Equals(txtPwd.Text))
{
//实例化所填写的用户信息
UserInfo userinfo = new UserInfo();
userinfo.UserLoginID = txtLoginID.Text;
userinfo.UserPwd = txtRePwd.Text;
userinfo.UserName = txtName.Text;
userinfo.UserStauts = Int32.Parse(statusDDL.SelectedValue);
//根据Session内容有无判断用户行为为修改或新增
if (Session["userID"] != null)
{
//读取用户编号
userinfo.UserID = Int32.Parse(Session["userID"].ToString());
//修改用户信息
string strSql = "UPDATE [userInfo] SET [userLoginID] = '" + userinfo.UserLoginID + "',[userPwd] = '" + userinfo.UserPwd + "',[userName] = '" + userinfo.UserName + "',[userStauts] = '" + userinfo.UserStauts + "' WHERE [userID] = '" + userinfo.UserID + "'";
int i = DBHelper.sqlinit(strSql);
if (i > 0)
{
//清空用户编号的Session,并返回上一页面
Session["userID"] = null;
Response.Redirect("Manager.aspx");
}
}
else
{
//进行用户登录ID是否重复的判断,若重复则返回错误信息
string strSql = "SELECT [userID],[userLoginID],[userPwd],[userName],[userStauts],[scID] FROM [userInfo] WHERE [userLoginID] ='" + txtLoginID.Text + "'";
if (DBHelper.sqlLoad(strSql).Rows.Count == 0)
{
//增加新课程
strSql = "INSERT INTO [userInfo]([userLoginID],[userPwd],[userName],[userStauts],[scID])VALUES('" + userinfo.UserLoginID + "','" + userinfo.UserPwd + "','" + userinfo.UserName + "','" + userinfo.UserStauts + "',0)";
int i = DBHelper.sqlinit(strSql);
if (i > 0)
{
//返回上一页面
Response.Redirect("Manager.aspx");
}
}
else
{
txtMsg.Text = "登录名重复!";
}
}
}
else
{
txtMsg.Text = "两次密码输入不一致!";
}
}
else
{
txtMsg.Text = "输入信息不完整!";
}
}
//返回上一页面
protected void Button2_Click(object sender, EventArgs e)
{
//清空用户编号的Session并返回上一页面
Session["userID"] = null;
Response.Redirect("Manager.aspx");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -