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

📄 usermanage.aspx.cs

📁 这是一个管理系统的源码
💻 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;

namespace Service
{
	/// <summary>
	/// Summary description for UserManage.
	/// </summary>
	public partial class UserManage : System.Web.UI.Page
	{

		public String sOperation = "";
		public String sLinkName  = "";
	
		protected void Page_Load(object sender, System.EventArgs e)
		{
			if(Session["UserID"] == null)
			{
				Response.Redirect("~/Default.aspx");
			}
			else
			{
				String sUserRoleName = UserDB.GetUserLoginRole(Int32.Parse(Session["UserID"].ToString()));
				if(sUserRoleName.IndexOf("Admin") == -1)
				{
					Response.Redirect("~/Default.aspx");
				}
			}

			if(!Page.IsPostBack)
			{
				BindUserData();
			}

			deleteBtn.Attributes.Add("onclick","return confirm('你确定要删除所选择的问题吗?');");

			if(Request.Params["LinkID"] != null)
			{
				GetLinkName(Request.Params["LinkID"].ToString());
			}
		}

		private void GetLinkName(String sLinkID)
		{
			String[] aName = new String[2];
			aName = GlobalVarables.GetLinkName(sLinkID);

			if(GlobalVarables.aLinkName.Count > 0)
			{
				sOperation = aName[0].ToString();
				sLinkName  = aName[1].ToString();
			}
		}

		private void BindUserData()
		{			
			UserList.Items.Clear();

			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.deleteBtn.Click += new System.Web.UI.ImageClickEventHandler(this.deleteBtn_Click);

		}
		#endregion

		private void deleteBtn_Click(object sender, System.Web.UI.ImageClickEventArgs e)
		{
			if(UserList.SelectedIndex > -1)
			{
				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("~/ManageSystem/ErrorPage.aspx?ErrorUrl=" + sRawURL + "&ErrorMessage=" + ex.Message.Replace("\n"," "));
				}

				BindUserData();
			}
			else
			{
				Response.Write("<script>alert(\"请选择你的数据项!\")</script>");
			}
		}

		protected void AddUser_Click(object sender, System.EventArgs e)
		{
			UserDB user = new UserDB();

			if(UserName.Text.Trim() != "")
			{
				try
				{
					user.AddUser(UserName.Text.Trim(),UserDB.Encrypt(UserName.Text.Trim()),
						CleanString.InputText(RealName.Text.Trim(),32),Telephone.Text,
						CleanString.InputText(Address.Text,200));

					Response.Write("<script>alert(\"添加新用户成功!\")</script>");
					RealName.Text  = "";
					Telephone.Text = "";
					Address.Text   = "";
				}
				catch(Exception ex)
				{
					string sRawURL = Request.RawUrl;

					if(sRawURL.IndexOf("?") > -1)
					{
						sRawURL = sRawURL.Substring(0,sRawURL.IndexOf("?"));
					}				
					Response.Redirect("~/DesktopModules/ErrorPage.aspx?ErrorUrl=" + sRawURL + "&ErrorMessage=" + ex.Message.Replace("\n"," "));
				}

				BindUserData();
			}
			else
			{
				Response.Write("<script>alert(\"用户名不能为空!\")</script>");
			}
		}
	}
}

⌨️ 快捷键说明

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