温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:无忧劳保库存系统源码
当前文件:
Labor/employees.aspx.cs,打开代码结构图
Labor/employees.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
public partial class employees : System.Web.UI.Page 13
{ 14
Helper he = new Helper(); 15
16
static int i = 1;//页数 17
18
static int index;//员工编码号 19
20
static string CNo;//编号 21
22
static String sex; 23
24
protected void Page_Load(object sender, EventArgs e) 25
{ 26
GridView1.DataSource = he.EmpBindInfo(); 27
28
if (!IsPostBack) 29
{ 30
31
if (he.IsAdmin(Session["username"].ToString())) 32
{ 33
; 34
} 35
else 36
{ 37
Response.Write("<script>window.showModalDialog('IsAdmin.aspx','','resizable:yes;scroll:yes;status:no;dialogWidth=320px;dialogHeight=230px;center=yes;help=no');</script>"); 38
39
UpdatePanel2.Visible = false; 40
41
UpdatePanel1.Visible = false; 42
43
return; 44
} 45
46
TxtName.Focus(); 47
48
Label3.Text = "当前页码是" + Convert.ToString(GridView1.PageIndex + i); 49
50
GridView1.DataBind(); 51
} 52
} 53
//全选 54
public void CheckAll(object sender, System.EventArgs e) 55
{ 56
CheckBox cball = (CheckBox)sender; 57
58
if (cball.Text == "做删除标记") 59
{ 60
foreach (GridViewRow gvr in this.GridView1.Rows) 61
{ 62
CheckBox cb = (CheckBox)gvr.FindControl("ItemC"); 63
64
cb.Checked = cball.Checked; 65
66
if (cball.Checked) 67
{ 68
BtnDelAll.Visible = true; 69
70
BtnDelAll.Text = "全部删除"; 71
72
TxtName.Text = ""; 73
74
TxtDName.Text = ""; 75
76
TxtDID.Text = ""; 77
78
TxtBirthDay.Text = ""; 79
80
BtnAdd.Enabled = true; 81
82
} 83
else 84
{ 85
BtnDelAll.Visible = false; 86
87
BtnDelAll.Text = ""; 88
89
} 90
} 91
} 92
} 93
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) 94
{ 95
GridView1.PageIndex = e.NewPageIndex; 96
97
Label3.Text = "当前页码是" + Convert.ToString(GridView1.PageIndex + i); 98
99
GridView1.DataBind(); 100
} 101
protected void BtnDelAll_Click(object sender, EventArgs e) 102
{ 103
foreach (GridViewRow gv in this.GridView1.Rows) 104
{ 105
CheckBox cb = (CheckBox)gv.FindControl("ItemC"); 106
if (cb.Checked) 107
{ 108
if (he.ExecSQL("delete from Emp")) 109
{ 110
Label3.Visible = false; 111
112
BtnDelAll.Visible = false; 113
114
GridView1.DataSource = he.EmpBindInfo(); 115
116
GridView1.DataBind(); 117
} 118
else 119
{ 120
Label4.Text = "数据删除失败"; 121
} 122
} 123
else 124
{ 125
Label4.Text = "现在不能执行此命令,因为记录没有全部做删除标记"; 126
} 127
} 128
} 129
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) 130
{ 131
switch (e.CommandName) 132
{ 133
case "up": 134
//获取员工的编号 135
index = Convert.ToInt32(e.CommandArgument); 136
//根据行编号,获取选择的整行 137
GridViewRow selectedRowu = this.GridView1.Rows[index]; 138
//获取学生编号 139
CNo = selectedRowu.Cells[0].Text; 140
141
String[] info = he.GetEmpBasicInfo(CNo); 142
143
TxtName.Text = info[0]; 144
145
if (info[1] == "男") 146
{ 147
RadioButton1.Checked = true; 148
149
RadioButton2.Checked = false; 150
} 151
else 152
{ 153
RadioButton2.Checked = true; 154
155
RadioButton1.Checked = false; 156
} 157
TxtBirthDay.Text = info[2]; 158
159
TxtDID.Text = info[3]; 160
161
TxtDName.Text = info[4]; 162
163
BtnAdd.Enabled = false; 164
165
TxtName.Focus(); 166
167
break; 168
169
case "del": 170
//获取员工的编号 171
index = Convert.ToInt32(e.CommandArgument); 172
//根据行编号,获取选择的整行 173
GridViewRow selectedRowd = this.GridView1.Rows[index]; 174
//获取学生编号 175
CNo = selectedRowd.Cells[0].Text; 176
177
if (he.ExecSQL("delete from Emp where EmpID='" + CNo + "'")) 178
{ 179
GridView1.DataSource = he.EmpBindInfo(); 180
181
GridView1.DataBind(); 182
} 183
else 184
{ 185
return; 186
} 187
188
break; 189
} 190
} 191
protected void BtnUp_Click(object sender, EventArgs e) 192
{ 193
194
} 195
protected void BtnAdd_Click(object sender, EventArgs e) 196
{ 197
if (TxtName.Text.Trim().Length == 0) 198
{ 199
Label1.Text = "请输入职员的姓名"; 200
201
TxtName.Focus(); 202
} 203
else if (TxtBirthDay.Text.Trim().Length == 0) 204
{ 205
Label1.Text = "请选择职员的出生日期"; 206
207
TxtBirthDay.Focus(); 208
} 209
else if (TxtDID.Text.Trim().Length == 0) 210
{ 211
Label1.Text = "请选择职员所在部门信息"; 212
} 213
else 214
{ 215
if (!he.IsDepartment(TxtDName.Text.Trim())) 216
{ 217
Label1.Text = "系统不存在此部门"; 218
} 219
else if (!he.IsDID(TxtDID.Text.Trim())) 220
{ 221
Label1.Text = "系统不存在此部门编号"; 222
} 223
else 224
{ 225
System.Threading.Thread.Sleep(3000); 226
227
Label1.Text = ""; 228
229
if (RadioButton1.Checked) 230
{ 231
sex = "男"; 232
} 233
else 234
{ 235
sex = "女"; 236
} 237
238
if (he.ExecSQL("insert into Emp(EmpName,Sex,BirthDay,DepartmentID,DepartmentName) values('" + TxtName.Text.Trim() + "','" + sex + "','" + TxtBirthDay.Text.Trim() + "','" + TxtDID.Text.Trim() + "','" + TxtDName.Text.Trim() + "')")) 239
{ 240
241
TxtName.Text = ""; 242
243
TxtDName.Text = ""; 244
245
TxtDID.Text = ""; 246
247
TxtBirthDay.Text = ""; 248
249
TxtName.Focus(); 250
251
GridView1.DataSource = he.EmpBindInfo(); 252
253
GridView1.DataBind(); 254
255
} 256
else 257
{ 258
Label1.Text = "数据插入失败"; 259
} 260
} 261
} 262
} 263
protected void RadioButton1_CheckedChanged(object sender, EventArgs e) 264
{ 265
if (RadioButton1.Checked) 266
{ 267
sex = "男"; 268
} 269
else 270
{ 271
sex = "女"; 272
} 273
} 274
protected void RadioButton2_CheckedChanged(object sender, EventArgs e) 275
{ 276
if (RadioButton2.Checked) 277
{ 278
sex = "女"; 279
} 280
else 281
{ 282
sex = "男"; 283
} 284
} 285
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) 286
{ 287
if (e.Row.RowType == DataControlRowType.DataRow) 288
{ 289
if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate) 290
{ 291
((LinkButton)e.Row.Cells[7].Controls[0]).Attributes.Add("onclick", "javascript:return confirm('你确认要删除员工:\"" + e.Row.Cells[1].Text + "\"吗?')"); 292
} 293
} 294
} 295
} 296




Helper he 
}
}