📄 usermanage.aspx.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace ComputerWeb
{
/// <summary>
/// Summary description for ManageUser.
/// </summary>
public class ManageUser : System.Web.UI.Page
{
protected System.Web.UI.WebControls.ListBox UserList;
protected System.Web.UI.WebControls.Button AddUser;
protected System.Web.UI.WebControls.Button DeleteUser;
protected System.Web.UI.WebControls.Button UpdateUser;
protected System.Web.UI.WebControls.TextBox Password;
protected System.Web.UI.WebControls.Button SureBtn;
protected System.Web.UI.WebControls.TextBox UserName;
protected System.Web.UI.WebControls.Panel PanelPassword;
protected System.Web.UI.WebControls.Panel PanelAll;
protected System.Web.UI.WebControls.Panel PanelSure;
private static String commandName = "";
private void Page_Load(object sender, System.EventArgs e)
{
if(Session["UserID"] == null)
{
Response.Redirect("~/Admin/Default.aspx");
}
//判定是否有管理员权限
if(Session["UserID"] != null)
{
if(UserDB.IsValidAdmin(Int32.Parse(Session["UserID"].ToString())) == false)
{
if(UserDB.IsValidChannel(Int32.Parse(Session["UserID"].ToString())) == true)
{
Response.Write("<script>alert(\"你没有权限访问,请跟管理员联系!\")</script>");
Response.Write("<script>history.back();</script>");
}
else
{
Response.Write("<script>parent.location='default.aspx';</script>");
}
}
}
else
{
Response.Write("<script>parent.location='default.aspx';</script>");
}
if(!Page.IsPostBack)
{
BindData();
}
}
private void BindData()
{
UserDB user = new UserDB();
SqlDataReader recu = user.GetUsers();
UserList.DataSource = recu;
UserList.DataTextField = "UserName";
UserList.DataValueField = "ID";
UserList.DataBind();
recu.Close();
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.AddUser.Click += new System.EventHandler(this.AddUser_Click);
this.UpdateUser.Click += new System.EventHandler(this.UpdateUser_Click);
this.DeleteUser.Click += new System.EventHandler(this.DeleteUser_Click);
this.SureBtn.Click += new System.EventHandler(this.SureBtn_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void AddUser_Click(object sender, System.EventArgs e)
{
// commandName = ((Button)sender).CommandName;
//
// //设计控件的可见性和可用性
// UserName.Enabled = true;
// Password.Enabled = true;
// PanelAll.Visible = true;
// PanelPassword.Visible = true;
// PanelSure.Visible = true;
//
// UserName.Text = "";
// Password.Text = "";
}
private void UpdateUser_Click(object sender, System.EventArgs e)
{
// if(UserList.SelectedIndex > -1)
// {
// //设计控件的可见性和可用性
// UserName.Enabled = false;
// Password.Enabled = false;
// PanelPassword.Visible = false;
// PanelSure.Visible = true;
// PanelAll.Visible = true;
//
// commandName = ((Button)sender).CommandName;
//
// UserDB user = new UserDB();
// SqlDataReader recu = user.GetSingleUser(Int32.Parse(UserList.SelectedValue));
//
// while(recu.Read())
// {
// UserName.Text = recu["UserName"].ToString();
// IsValidState.SelectedIndex = Int32.Parse(recu["IsValid"].ToString());
// }
// recu.Close();
// }
// else
// {
// Response.Write("<script>alert(\"请选择要修改的用户!\")</script>");
// }
}
private void DeleteUser_Click(object sender, System.EventArgs e)
{
// if(UserList.SelectedIndex > -1)
// {
// //设计控件的可见性和可用性
// UserName.Enabled = false;
// Password.Enabled = false;
// PanelPassword.Visible = false;
// PanelSure.Visible = true;
// PanelAll.Visible = true;
//
// commandName = ((Button)sender).CommandName;
//
// UserDB user = new UserDB();
// SqlDataReader recu = user.GetSingleUser(Int32.Parse(UserList.SelectedValue));
//
// while(recu.Read())
// {
// UserName.Text = recu["UserName"].ToString();
// IsValidState.SelectedIndex = Int32.Parse(recu["IsValid"].ToString());
// }
// recu.Close();
// }
// else
// {
// Response.Write("<script>alert(\"请选择要修改的用户!\")</script>");
// }
}
private void SureBtn_Click(object sender, System.EventArgs e)
{
// switch(commandName)
// {
// case "add":
// {
// AddNewUser();
// break;
// }
// case "update":
// {
// UpdateUserState();
// break;
// }
// case "delete":
// {
// DeleteSingleUser();
// break;
// }
// default:
// {
// break;
// }
// }
//
// PanelAll.Visible = false;
// PanelSure.Visible = false;
//
// //绑定数据
// BindData();
}
private void AddNewUser()
{
// if(UserName.Text.Trim() != "")
// {
// UserDB user = new UserDB();
//
// try
// {
// user.AddUser(UserName.Text,UserDB.Encrypt(Password.Text),2,Int32.Parse(IsValidState.SelectedValue));
// }
// catch(Exception ex)
// {
// string sRawURL = Request.RawUrl;
//
// if(sRawURL.IndexOf("?") > -1)
// {
// sRawURL = sRawURL.Substring(0,sRawURL.IndexOf("?"));
// }
// Response.Redirect("~/Admin/AdminDenid.aspx?ErrorURL=" + sRawURL + "&ErrorInfo=" + ex.Message.Replace("\n","<br>"));
// }
//
// UserName.Text = "";
// Password.Text = "";
// }
// else
// {
// Response.Write("<script>alert(\"你输入的用户名为空,请重新输入!\")</script>");
// }
}
private void UpdateUserState()
{
// UserDB user = new UserDB();
//
// try
// {
// user.UpdateUserState(Int32.Parse(UserList.SelectedValue),Int32.Parse(IsValidState.SelectedValue));
// }
// catch(Exception ex)
// {
// string sRawURL = Request.RawUrl;
//
// if(sRawURL.IndexOf("?") > -1)
// {
// sRawURL = sRawURL.Substring(0,sRawURL.IndexOf("?"));
// }
// Response.Redirect("~/Admin/AdminDenid.aspx?ErrorURL=" + sRawURL + "&ErrorInfo=" + ex.Message.Replace("\n","<br>"));
// }
}
private void DeleteSingleUser()
{
// UserDB user = new UserDB();
//
// try
// {
// user.DeleteUser(Int32.Parse(UserList.SelectedValue));
// }
// catch(Exception ex)
// {
// string sRawURL = Request.RawUrl;
//
// if(sRawURL.IndexOf("?") > -1)
// {
// sRawURL = sRawURL.Substring(0,sRawURL.IndexOf("?"));
// }
// Response.Redirect("~/Admin/AdminDenid.aspx?ErrorURL=" + sRawURL + "&ErrorInfo=" + ex.Message.Replace("\n","<br>"));
// }
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -