温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:Asp.net2.0值班管理系统源码
当前文件:
DutySystem/DutyStaffMain.aspx.cs[4K,2009-6-12 11:41:29],打开代码结构图
DutySystem/DutyStaffMain.aspx.cs[4K,2009-6-12 11:41:29],打开代码结构图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
12
public partial class DutyStaffMain : System.Web.UI.Page 13
{ 14
protected void Page_Load(object sender, EventArgs e) 15
{ 16
if (!this.IsPostBack) 17
{ 18
bindDropDown(); 19
bindUser(); 20
} 21
} 22
23
private void bindDropDown() 24
{ 25
DataSet ds = DepartmentDao.dsDepartment(); 26
this.DropDownList2.DataSource = ds.Tables[0]; 27
this.DropDownList2.DataTextField = ds.Tables[0].Columns[1].ToString(); 28
this.DropDownList2.DataValueField = ds.Tables[0].Columns[0].ToString(); 29
this.DropDownList2.DataBind(); 30
} 31
private void bindUser() 32
{ 33
if (StaffDao.dsStaff() == null || (StaffDao.dsStaff()).Tables[0].Rows.Count == 0) 34
{ 35
this.Label1.Visible = true; 36
this.GridView1.Visible = false; 37
} 38
else 39
{ 40
this.GridView1.Visible = true; 41
this.GridView1.DataSource = StaffDao.dsStaff(); 42
this.GridView1.DataBind(); 43
} 44
} 45
protected void Button1_Click(object sender, EventArgs e) 46
{ 47
if (string.IsNullOrEmpty(this.TextBox1.Text)) 48
{ 49
this.Label2.Text = "姓名不能为空!"; 50
} 51
else if (string.IsNullOrEmpty(this.TextBox2.Text)) 52
{ 53
this.Label2.Text = "编号不能为空!"; 54
} 55
else 56
{ 57
58
this.Label2.Text = ""; 59
StaffPo sp = new StaffPo(); 60
sp.DepartId = int.Parse(this.DropDownList2.SelectedValue.ToString()); 61
sp.UserId = this.TextBox2.Text; 62
sp.Sex = byte.Parse(this.DropDownList1.SelectedValue); 63
sp.UserName = this.TextBox1.Text; 64
65
StaffDao.insertStaff(sp); 66
bindUser(); 67
} 68
69
} 70
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e) 71
{ 72
this.GridView1.EditIndex = e.NewEditIndex; 73
bindUser(); 74
DropDownList ddl = (DropDownList)this.GridView1.Rows[e.NewEditIndex].FindControl("dl"); 75
ddl.Items.Add(new ListItem("男", "0")); 76
ddl.Items.Add(new ListItem("女", "1")); 77
78
DropDownList ddlt = (DropDownList)this.GridView1.Rows[e.NewEditIndex].FindControl("DropDownList3"); 79
80
ddlt.DataSource = DepartmentDao.dsDepartment().Tables[0]; 81
ddlt.DataTextField = DepartmentDao.dsDepartment().Tables[0].Columns[1].ToString(); 82
ddlt.DataValueField = DepartmentDao.dsDepartment().Tables[0].Columns[0].ToString(); 83
ddlt.DataBind(); 84
} 85
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) 86
{ 87
88
89
90
} 91
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) 92
{ 93
94
95
} 96
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) 97
{ 98
this.GridView1.EditIndex = -1; 99
string userName = ((TextBox)this.GridView1.Rows[e.RowIndex].Cells[1].Controls[0]).Text; 100
byte sex = byte.Parse(((DropDownList)this.GridView1.Rows[e.RowIndex].Cells[2].Controls[1]).SelectedValue.ToString()); 101
102
int departId = int.Parse(((DropDownList)this.GridView1.Rows[e.RowIndex].Cells[3].Controls[1]).SelectedValue.ToString()); 103
string userId = ((TextBox)this.GridView1.Rows[e.RowIndex].Cells[4].Controls[0]).Text; 104
int keyId = int.Parse(this.GridView1.DataKeys[e.RowIndex].Value.ToString()); 105
StaffPo sp = new StaffPo(); 106
sp.UserName = userName; 107
sp.UserId = userId; 108
sp.Sex = sex; 109
sp.DepartId = departId; 110
StaffDao.updateStaff(sp,keyId); 111
112
bindUser(); 113
} 114
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e) 115
{ 116
this.GridView1.EditIndex = -1; 117
bindUser(); 118
} 119
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) 120
{ 121
int keyId = Int32.Parse(this.GridView1.DataKeys[e.RowIndex].Value.ToString()); 122
StaffDao.deleteStaff(keyId); 123
bindUser(); 124
125
126
} 127
} 128






}
}