📄 st_useradd.aspx.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.Web.Security;
namespace STGROUP.ST_Book.ST_User
{
/// <summary>
/// ST_StudentAdd 的摘要说明。
/// </summary>
public partial class ST_UserAdd : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox Textbox1;
protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator1;
protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator3;
protected System.Web.UI.WebControls.CompareValidator CompareValidator1;
ST_BookBiz.ST_UserEntity st_entity = new STGROUP.ST_BookBiz.ST_UserEntity();
protected void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
Response.Cache.SetCacheability(HttpCacheability.NoCache);//去掉页面缓存
if(!IsPostBack)
{
//初始化用户信息
ST_BookBiz.ST_User st_user = new STGROUP.ST_BookBiz.ST_User();
if(Request["Action"]=="edit")//更新操作时,初始化数据
{
ST_BookBiz.ST_Identity identity = new ST_BookBiz.ST_Identity(User.Identity.Name);
int userid = identity.UserID;
if (userid == 0)
Response.Redirect("../ST_Login.aspx");
st_entity = st_user.GetUserInfo(userid);
txtNumber.Text = userid.ToString();
txtName.Text = st_entity.ST_Name;
txtAddress.Text = st_entity.ST_Address;
txtEmail.Text = st_entity.ST_Email;
txtPhone.Text = st_entity.ST_Telephone;
txtPostCode.Text = st_entity.ST_Postcode;
txtTrueName.Text = st_entity.ST_TrueName;
txtPass.Text = st_entity.ST_Pass;
RadioButtonList1.SelectedIndex = RadioButtonList1.Items.IndexOf(RadioButtonList1.Items.FindByText(st_entity.ST_Gender));
txtName.ReadOnly = true;
}
}
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
}
#endregion
protected void btnOK_Click(object sender, System.EventArgs e)
{
ST_BookBiz.ST_User st_user = new STGROUP.ST_BookBiz.ST_User();
//判断条件,名称不允许未空,名称长度不超过20个字符
if(txtName.Text=="")
Response.Write("<script defer>alert('名称不允许未空!');</script>");
else if(txtPass.Text=="")
Response.Write("<script defer>alert('密码不允许未空!');</script>");
else if(txtPass.Text != txtPass2.Text)
{
Response.Write("<script defer>alert('密码不一致!');</script>");
}
else if (st_user.ST_IsUserExist(txtName.Text.Trim()) && Request["Action"] == "add")
{
Response.Write("<script defer>alert('用户名已经存在!');</script>");
}
else
{
ST_BookBiz.ST_Identity identity = new ST_BookBiz.ST_Identity(User.Identity.Name);
int userid = identity.UserID;
//用户信息的添加或者删除操作
if (Request["Action"] == "add")
{
userid = 0;
st_entity.ST_Name = txtName.Text;
st_entity.ST_Address = txtAddress.Text;
st_entity.ST_Email = txtEmail.Text;
st_entity.ST_Telephone = txtPhone.Text;
st_entity.ST_Postcode = txtPostCode.Text ;
st_entity.ST_TrueName = txtTrueName.Text;
st_entity.ST_Pass = txtPass.Text;
st_entity.ST_Gender = RadioButtonList1.SelectedValue;
userid = st_user.InsertUser(st_entity);
identity = new ST_BookBiz.ST_Identity(txtName.Text.Trim(), userid);
Context.User = new ST_BookBiz.ST_Principal(identity, new string[] { "User" });
identity.Name = txtName.Text;
identity.Roles = "User";
identity.Save();
FormsAuthentication.SetAuthCookie(txtName.Text, false);//种身份验证票
Response.Redirect("../ST_Common/ST_Main.aspx");
}
else if (Request["Action"] == "edit" && userid!=0)
{
//修改信息
st_entity.ST_Name = txtName.Text;
st_entity.ST_Address = txtAddress.Text;
st_entity.ST_Email = txtEmail.Text;
st_entity.ST_Telephone = txtPhone.Text;
st_entity.ST_Postcode = txtPostCode.Text;
st_entity.ST_TrueName = txtTrueName.Text;
st_entity.ST_Pass = txtPass.Text;
st_entity.ST_Gender = RadioButtonList1.SelectedValue;
st_entity.ST_UserID = userid;
st_user.UpdateUser(st_entity);
string str = "<script language=javascript>alert('更新成功!');</script>";
Response.Write(str);
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -