温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:无忧劳保库存系统源码
当前文件:
Labor/mm.aspx.cs,打开代码结构图
Labor/mm.aspx.cs,打开代码结构图1using System; 2
using System.Data; 3
using System.Configuration; 4
using System.Collections; 5
using System.Web; 6
using System.Web.Security; 7
using System.Web.UI; 8
using System.Web.UI.WebControls; 9
using System.Web.UI.WebControls.WebParts; 10
using System.Web.UI.HtmlControls; 11
using SqlHelper; 12
using System.Data.SqlClient; 13
public partial class mm : System.Web.UI.Page 14
{ 15
Helper he = new Helper(); 16
17
static int i = 1;//页数 18
19
static int index;//员工编码号 20
21
static string CNo;//编号 22
23
protected void Page_Load(object sender, EventArgs e) 24
{ 25
GridView1.DataSource = he.BindInfo(); 26
27
if (!IsPostBack) 28
{ 29
30
if (he.IsAdmin(Session["username"].ToString())) 31
{ 32
; 33
} 34
else 35
{ 36
Response.Write("<script>window.showModalDialog('IsAdmin.aspx','','resizable:yes;scroll:yes;status:no;dialogWidth=320px;dialogHeight=230px;center=yes;help=no');</script>"); 37
38
AcceptUpdatePanel.Visible = false; 39
40
UpdatePanel1.Visible = false; 41
42
return; 43
} 44
45
TxtName.Focus(); 46
47
Label2.Text = "当前页码是" + Convert.ToString(GridView1.PageIndex + i); 48
49
GridView1.DataBind(); 50
} 51
} 52
protected void BtnReg_Click(object sender, EventArgs e) 53
{ 54
if (TxtName.Text.Trim().Length == 0) 55
{ 56
Label1.Text = "请输入你的用户名字"; 57
58
TxtName.Focus(); 59
} 60
else if (TxtPass.Text.Trim().Length == 0) 61
{ 62
Label1.Text = "请输入你的用户密码"; 63
64
TxtPass.Focus(); 65
} 66
else 67
{ 68
System.Threading.Thread.Sleep(3000); 69
70
String name = TxtName.Text.Trim(); 71
72
String pass = TxtPass.Text.Trim(); 73
74
if (he.LoginSys(name)) 75
{ 76
Label1.Text = "已经存在此操作人员了!!!"; 77
78
return; 79
} 80
81
if (he.ExecSQL("insert into UserInfo(UserName,UserPass) values('" + name + "','" + pass + "')")) 82
{ 83
Label1.Text = "添加数据成功"; 84
85
GridView1.DataSource = he.BindInfo(); 86
87
GridView1.DataBind(); 88
89
TxtName.Focus(); 90
91
TxtName.Text = ""; 92
93
TxtPass.Text = ""; 94
95
} 96
else 97
{ 98
Label1.Text = "添加数据失败"; 99
} 100
} 101
} 102
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) 103
{ 104
105
switch (e.CommandName) 106
{ 107
case "qxset": 108
//获取员工的编号 109
index = Convert.ToInt32(e.CommandArgument); 110
Button btn = (Button)e.CommandSource; 111
if (btn.Text == "取消管理员权限") 112
{ 113
if (he.ExecSQL("update UserInfo set IsAdmin=" + 0 + " where UserID='" + Convert.ToString(index) + "'")) 114
{ 115
Label3.Text = "权限设置成功"; 116
} 117
else 118
{ 119
Label3.Text = "权限设置失败"; 120
} 121
} 122
else 123
{ 124
if (he.ExecSQL("update UserInfo set IsAdmin=" + 1 + " where UserID='" + Convert.ToString(index) + "'")) 125
{ 126
Label3.Text = "权限设置成功"; 127
} 128
else 129
{ 130
Label3.Text = "权限设置失败"; 131
} 132
} 133
GridView1.DataSource = he.BindInfo(); 134
135
GridView1.DataBind(); 136
137
break; 138
139
case "updates": 140
//获取员工的编号 141
index = Convert.ToInt32(e.CommandArgument); 142
//根据行编号,获取选择的整行 143
GridViewRow selectedRowu = this.GridView1.Rows[index]; 144
//获取学生编号 145
CNo = selectedRowu.Cells[0].Text; 146
147
String[] Info = he.GetUserBasicInfo(CNo); 148
149
TxtName.Text = Info[0]; 150
151
TxtPass.Text = Info[1]; 152
153
TxtName.Enabled = false; 154
155
TxtPass.Focus(); 156
157
break; 158
159
case "del": 160
161
TxtName.Text = ""; 162
163
TxtPass.Text = ""; 164
165
TxtName.Enabled = true; 166
167
//获取员工的编号 168
index = Convert.ToInt32(e.CommandArgument); 169
//根据行编号,获取选择的整行 170
GridViewRow selectedRowd = this.GridView1.Rows[index]; 171
//获取学生编号 172
CNo = selectedRowd.Cells[0].Text; 173
174
if (he.ExecSQL("delete from UserInfo where UserID='" + CNo + "'")) 175
{ 176
GridView1.DataSource = he.BindInfo(); 177
178
GridView1.DataBind(); 179
} 180
else 181
{ 182
return; 183
} 184
185
break; 186
} 187
} 188
//执行分页操作 189
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) 190
{ 191
GridView1.PageIndex = e.NewPageIndex; 192
193
Label2.Text = "当前页码是" + Convert.ToString(GridView1.PageIndex + i); 194
195
GridView1.DataBind(); 196
197
} 198
protected void BtnUp_Click(object sender, EventArgs e) 199
{ 200
if (TxtName.Text.Trim().Length == 0) 201
{ 202
Label1.Text = "请输入你的要更新的用户名字"; 203
204
TxtName.Focus(); 205
} 206
else if (TxtPass.Text.Trim().Length == 0) 207
{ 208
Label1.Text = "请输入你你要更新的用户密码"; 209
210
TxtPass.Focus(); 211
} 212
else 213
{ 214
System.Threading.Thread.Sleep(3000); 215
216
String pass = TxtPass.Text.Trim(); 217
218
if (he.ExecSQL("update UserInfo set UserPass='" + pass + "' where UserID='" + CNo + "'")) 219
{ 220
Label1.Text = "修改数据成功"; 221
222
GridView1.DataBind(); 223
224
TxtName.Focus(); 225
226
TxtName.Text = ""; 227
228
TxtPass.Text = ""; 229
230
TxtName.Enabled = true; 231
232
BtnReg.Enabled = true; 233
234
} 235
else 236
{ 237
Label1.Text = "修改数据失败"; 238
} 239
} 240
} 241
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) 242
{ 243
if (e.Row.RowType == DataControlRowType.DataRow) 244
{ 245
if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate) 246
{ 247
((LinkButton)e.Row.Cells[4].Controls[0]).Attributes.Add("onclick", "javascript:return confirm('你确认要删除用户:\"" + e.Row.Cells[1].Text.Trim() + "\"吗?')"); 248
} 249
} 250
} 251
} 252




Helper he 
}
}