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

📄 addrole.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;
using System.Text;

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

		private static ArrayList directionID = new ArrayList();
		private int countIndex = 0;	
		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");
				}
			}

			AddDirection();

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

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

			sOperation = aName[0].ToString();
			sLinkName  = aName[1].ToString();
		}

		private void AddDirection()
		{
			directionID.Clear();

			DirectionDB dir = new DirectionDB();
			SqlDataReader recd = dir.GetDirections();

		    countIndex = 0;
			while(recd.Read())
			{
				DropDownList dropList = new DropDownList();
				dropList.ID = "dropList" + recd["ID"].ToString();
				dropList.Width = 100;

				directionID.Add(recd["ID"].ToString());

				HtmlTableCell activeCell = GetActiveCell(countIndex);

				activeCell.Controls.Add(new LiteralControl("<font class=Normal width=100 >" 
					+ recd["DirectionName"].ToString() + ":</font>"));

				dropList.Items.Add(new ListItem("不选择","0"));
				dropList.Items.Add(new ListItem("选择","1"));
				activeCell.Controls.Add(dropList);
				dropList.Dispose();

				activeCell.Controls.Add(new LiteralControl("<br>"));
				activeCell.Controls.Add(new LiteralControl("<br>"));
			
				countIndex++;
			}

			recd.Close();
		}

		private HtmlTableCell GetActiveCell(int index)
		{
            HtmlTableCell cell = null;
			if(index % 3 == 0)
			{
				cell = DirectionLeft;
			}
			if(index % 3 == 1)
			{
				cell = DirectionCenter;
			}
			if(index % 3 == 2)
			{
				cell = DirectionRight;
			}

			return(cell);
		}

		#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()
		{    

		}
		#endregion

		protected void IsMonitor_CheckedChanged(object sender, System.EventArgs e)
		{
			if(IsMonitor.Checked == true)
			{
				DirectionPanel.Visible = true;
			}
			else
			{
				DirectionPanel.Visible = false;
			}		
		}

		protected void AddRolebtn_Click(object sender, System.EventArgs e)
		{
			RoleDB role = new RoleDB();
			RoleDirectionDB roleDir = new RoleDirectionDB();
			
			if(RoleName.Text.Trim().Length > 0)
			{
				int nRoleID = 0;

				try
				{
					nRoleID = role.AddRole(RoleName.Text.Trim(),IsRepairState.Checked == true ? 1:0,IsMarkTable.Checked == true ? 1 : 0);
				}
				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"," "));
				}

				if(nRoleID <= 0)
				{				
					Response.Write("<script>alert(\"添加数据项在数据库已经存在,请重新输入!\");</script>");
					return;
				}

				if(IsMonitor.Checked == true)
				{	
					for(int i = 0; i < directionID.Count; i++)
					{
						DropDownList dropList = (DropDownList)Page.FindControl("dropList" + directionID[i].ToString());
						if(dropList != null)
						{
							if(dropList.SelectedValue.ToString() == "1")
							{
								try
								{
									roleDir.AddRoleDirection(nRoleID,Int32.Parse(directionID[i].ToString()));
									dropList.Dispose();
								}
								catch(Exception ex)
								{
									//由于没有添加成功,应该删除刚刚添加的角色
									role.DeleteRole(nRoleID);

									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"," "));
								}
							}
						}
					}					
				}	
	
				Response.Write("<script>alert(\"添加新的角色成功!\")</script>");	
			}
			else
			{
				Response.Write("<script>alert(\"角色的名称不能为空,请重新输入!\")</script>");
			}
		}
	}
}

⌨️ 快捷键说明

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