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

📄 editrole.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 EditOrDeleteRole.
	/// </summary>
	public partial class EditRole : System.Web.UI.Page
	{
	
		private static ArrayList directionID = new ArrayList();
		private int countIndex  = 0;	
		private int repairState = 0;		
		private int markTable   = 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(!Page.IsPostBack)
			{
				BindRoleData();
			}

			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 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.SelectedIndex = 0;
				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);
		}

		private void BindRoleData()
		{
			RoleDB role = new RoleDB();
			SqlDataReader recr = role.GetRoles();

			RoleList.DataSource = recr;
			RoleList.DataTextField = "RoleName";
			RoleList.DataValueField = "ID";
			RoleList.DataBind();

			recr.Close();

			if(RoleList.Items.Count > 0)
			{
				BindRoleInformation(Int32.Parse(RoleList.SelectedValue));
			}
		}

		private void BindRoleInformation(int index)
		{
			ClearSelected();

			if(RoleList.Items.Count > 0)
			{
				RoleDB role = new RoleDB();
				SqlDataReader recr = role.GetSingleRole(index);

				while(recr.Read())
				{
					if(recr["RepairState"].ToString() == "1")
					{
						IsRepairState.Checked = true;
						repairState = 1;
					}
					else
					{
						IsRepairState.Checked = false;
					}

					if(recr["MarkTable"].ToString() == "1")
					{
						IsMarkTable.Checked = true;
						markTable = 1;
					}
					else
					{
						IsMarkTable.Checked = false;
					}
				}				
				recr.Close();
			}

			RoleDirectionDB roleDir = new RoleDirectionDB();
			SqlDataReader recrd = roleDir.GetDirCountByRole(index);

			if(recrd.Read())
			{
				if(Int32.Parse(recrd["DataCount"].ToString()) > 0)
				{
					IsMonitor.Checked = true;
				}
				else
				{
					IsMonitor.Checked = false;
				}
			}
			recrd.Close();

			if(IsMonitor.Checked == true)
			{
				DirectionPanel.Visible = true;
			}
			else
			{
				DirectionPanel.Visible = false;
			}

			if(IsMonitor.Checked == true)
			{
				RoleDirectionDB roleDirection = new RoleDirectionDB();
				SqlDataReader recd = roleDirection.GetDirecrtionByRole(index);

				while(recd.Read())
				{
					DropDownList dropList = null;
					dropList = (DropDownList)Page.FindControl("dropList" + recd["DirectionID"].ToString());
					if(dropList != null)
					{
						dropList.SelectedIndex = 1;
					}
					
					if(dropList != null)
					{
						dropList.Dispose();
					}
				}
				recd.Close();
			}
		}

		private void ClearSelected()
		{
			for(int i = 0; i < directionID.Count; i++)
			{
				DropDownList dropList = null;

				dropList = (DropDownList)Page.FindControl("dropList" + directionID[i].ToString());
				dropList.SelectedIndex = 0;

				dropList.Dispose();
			}
		}

		#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 RoleList_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			BindRoleInformation(Int32.Parse(RoleList.SelectedValue));
		}

		protected void EditRolebtn_Click(object sender, System.EventArgs e)
		{
			RoleDB role = new RoleDB();
			RoleDirectionDB roleDir = new RoleDirectionDB();			

			try
			{
				//注意:同时更新了RoleDirection表中的数据(在存储过程中体现)
				role.UpdateRole(Int32.Parse(RoleList.SelectedValue),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(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(Int32.Parse(RoleList.SelectedValue),Int32.Parse(directionID[i].ToString()));
								dropList.Dispose();
							}
							catch(Exception ex)
							{	
								//更新错误时,撤消上面的更新
								role.UpdateRole(Int32.Parse(RoleList.SelectedValue),repairState,markTable);

								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>");			
		}

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

⌨️ 快捷键说明

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