温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:企业资源维护综合管理系统项目源码
当前文件:
EnterpriseResource/Admins/AddRole.aspx.cs[5K,2009-6-12 11:41:55],打开代码结构图
EnterpriseResource/Admins/AddRole.aspx.cs[5K,2009-6-12 11:41:55],打开代码结构图1using System; 2
using System.Collections; 3
using System.ComponentModel; 4
using System.Data; 5
using System.Drawing; 6
using System.Web; 7
using System.Web.SessionState; 8
using System.Web.UI; 9
using System.Web.UI.WebControls; 10
using System.Web.UI.HtmlControls; 11
using System.Data.SqlClient; 12
using System.Text; 13
14
namespace 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






}