Asp.net源码专业站
首页->商务办公->企业资源维护综合管理系统项目源码>>Admins/AddRole.aspx.cs>>源码在线查看
温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:企业资源维护综合管理系统项目源码
当前文件:文件类型 EnterpriseResource/Admins/AddRole.aspx.cs[5K,2009-6-12 11:41:55]打开代码结构图
普通视图
		            
1using System; 2using System.Collections; 3using System.ComponentModel; 4using System.Data; 5using System.Drawing; 6using System.Web; 7using System.Web.SessionState; 8using System.Web.UI; 9using System.Web.UI.WebControls; 10using System.Web.UI.HtmlControls; 11using System.Data.SqlClient; 12using System.Text; 13 14namespace Service 15{ 16 /// <summary> 17 /// Summary description for RoleManage. 18 /// </summary> 19 public partial class AddRole : System.Web.UI.Page 20 { 21 22 private static ArrayList directionID = new ArrayList(); 23 private int countIndex = 0; 24 public String sOperation = ""; 25 public String sLinkName = ""; 26 27 protected void Page_Load(object sender, System.EventArgs e) 28 { 29 if(Session["UserID"] == null) 30 { 31 Response.Redirect("~/Default.aspx"); 32 } 33 else 34 { 35 String sUserRoleName = UserDB.GetUserLoginRole(Int32.Parse(Session["UserID"].ToString())); 36 if(sUserRoleName.IndexOf("Admin") == -1) 37 { 38 Response.Redirect("~/Default.aspx"); 39 } 40 } 41 42 AddDirection(); 43 44 if(Request.Params["LinkID"] != null) 45 { 46 GetLinkName(Request.Params["LinkID"].ToString()); 47 } 48 } 49 50 private void GetLinkName(String sLinkID) 51 { 52 String[] aName = new String[2]; 53 aName = GlobalVarables.GetLinkName(sLinkID); 54 55 sOperation = aName[0].ToString(); 56 sLinkName = aName[1].ToString(); 57 } 58 59 private void AddDirection() 60 { 61 directionID.Clear(); 62 63 DirectionDB dir = new DirectionDB(); 64 SqlDataReader recd = dir.GetDirections(); 65 66 countIndex = 0; 67 while(recd.Read()) 68 { 69 DropDownList dropList = new DropDownList(); 70 dropList.ID = "dropList" + recd["ID"].ToString(); 71 dropList.Width = 100; 72 73 directionID.Add(recd["ID"].ToString()); 74 75 HtmlTableCell activeCell = GetActiveCell(countIndex); 76 77 activeCell.Controls.Add(new LiteralControl("<font class=Normal width=100 >" 78 + recd["DirectionName"].ToString() + ":</font>")); 79 80 dropList.Items.Add(new ListItem("不选择","0")); 81 dropList.Items.Add(new ListItem("选择","1")); 82 activeCell.Controls.Add(dropList); 83 dropList.Dispose(); 84 85 activeCell.Controls.Add(new LiteralControl("<br>")); 86 activeCell.Controls.Add(new LiteralControl("<br>")); 87 88 countIndex++; 89 } 90 91 recd.Close(); 92 } 93 94 private HtmlTableCell GetActiveCell(int index) 95 { 96 HtmlTableCell cell = null; 97 if(index % 3 == 0) 98 { 99 cell = DirectionLeft; 100 } 101 if(index % 3 == 1) 102 { 103 cell = DirectionCenter; 104 } 105 if(index % 3 == 2) 106 { 107 cell = DirectionRight; 108 } 109 110 return(cell); 111 } 112 113 Web Form Designer generated code 132 133 protected void IsMonitor_CheckedChanged(object sender, System.EventArgs e) 134 { 135 if(IsMonitor.Checked == true) 136 { 137 DirectionPanel.Visible = true; 138 } 139 else 140 { 141 DirectionPanel.Visible = false; 142 } 143 } 144 145 protected void AddRolebtn_Click(object sender, System.EventArgs e) 146 { 147 RoleDB role = new RoleDB(); 148 RoleDirectionDB roleDir = new RoleDirectionDB(); 149 150 if(RoleName.Text.Trim().Length > 0) 151 { 152 int nRoleID = 0; 153 154 try 155 { 156 nRoleID = role.AddRole(RoleName.Text.Trim(),IsRepairState.Checked == true ? 1:0,IsMarkTable.Checked == true ? 1 : 0); 157 } 158 catch(Exception ex) 159 { 160 string sRawURL = Request.RawUrl; 161 162 if(sRawURL.IndexOf("?") > -1) 163 { 164 sRawURL = sRawURL.Substring(0,sRawURL.IndexOf("?")); 165 } 166 Response.Redirect("~/ManageSystem/ErrorPage.aspx?ErrorUrl=" + sRawURL + "&ErrorMessage=" + ex.Message.Replace("\n"," ")); 167 } 168 169 if(nRoleID <= 0) 170 { 171 Response.Write("<script>alert(\"添加数据项在数据库已经存在,请重新输入!\");</script>"); 172 return; 173 } 174 175 if(IsMonitor.Checked == true) 176 { 177 for(int i = 0; i < directionID.Count; i++) 178 { 179 DropDownList dropList = (DropDownList)Page.FindControl("dropList" + directionID[i].ToString()); 180 if(dropList != null) 181 { 182 if(dropList.SelectedValue.ToString() == "1") 183 { 184 try 185 { 186 roleDir.AddRoleDirection(nRoleID,Int32.Parse(directionID[i].ToString())); 187 dropList.Dispose(); 188 } 189 catch(Exception ex) 190 { 191 //由于没有添加成功,应该删除刚刚添加的角色 192 role.DeleteRole(nRoleID); 193 194 string sRawURL = Request.RawUrl; 195 196 if(sRawURL.IndexOf("?") > -1) 197 { 198 sRawURL = sRawURL.Substring(0,sRawURL.IndexOf("?")); 199 } 200 Response.Redirect("~/ManageSystem/ErrorPage.aspx?ErrorUrl=" + sRawURL + "&ErrorMessage=" + ex.Message.Replace("\n"," ")); 201 } 202 } 203 } 204 } 205 } 206 207 Response.Write("<script>alert(\"添加新的角色成功!\")</script>"); 208 } 209 else 210 { 211 Response.Write("<script>alert(\"角色的名称不能为空,请重新输入!\")</script>"); 212 } 213 } 214 } 215} 216
还没有找到您心仪的内容?请用.net源码大搜捕
代码片断 打包下载该项目完整源码:企业资源维护综合管理系统项目源码
51Aspx.com 版权所有 CopyRight © 2006-2010. 京ICP备06046876号 本站法律顾问:ITlaw-庄毅雄律师
返回顶部
客户服务:点击这里进行客户咨询 业务合作:点击这里洽谈业务合作 合作热线:010-68880146