温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:Asp.net2.0任务分配系统源码
当前文件:
AssignWorkSystem/Tasks/TasksMain.aspx.cs[8K,2009-6-12 11:32:51],打开代码结构图
AssignWorkSystem/Tasks/TasksMain.aspx.cs[8K,2009-6-12 11:32:51],打开代码结构图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 Tasks_TasksMain : System.Web.UI.Page 13
{ 14
protected void Page_Load(object sender, EventArgs e) 15
{ 16
if (!this.IsPostBack) 17
{ 18
this.Label1.Text = UtilCommon.DisplayUserInfo(User.Identity.Name, Roles.GetRolesForUser()[0].ToString()); 19
bindDropDown(); 20
bindProjectDrop(); 21
bindTask(); 22
checkAuthen(); 23
} 24
} 25
26
private void checkAuthen() 27
{ 28
//administrator角色只可以查看项目信息,无权修改 29
if (Roles.GetRolesForUser(User.Identity.Name)[0].ToLower() == "administrator") 30
{ 31
this.GridView1.Columns[6].Visible = false; 32
this.GridView1.Columns[7].Visible = false; 33
this.Panel1.Visible = false; 34
35
} 36
//只有项目经理,即Manager角色的用户才可以创建并修改项目信息 37
else 38
{ 39
40
} 41
} 42
43
44
private void bindTask() 45
{ 46
DataSet ds = TaskDao.dsTask(); 47
if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0) 48
{ 49
this.GridView1.Visible = true; 50
this.Label2.Visible = false; 51
this.GridView1.DataSource = ds; 52
this.GridView1.DataBind(); 53
54
} 55
else 56
{ 57
this.GridView1.Visible = false; 58
this.Label2.Visible = true; 59
} 60
this.Label4.Text = "Task List:共[" + ds.Tables[0].Rows.Count + "]条任务信息"; 61
} 62
private void bindProjectDrop() 63
{ 64
DataSet ds = ProjectDao.dsProject(); 65
DataTable dt = ds.Tables[0]; 66
this.DropDownList1.DataSource = dt; 67
this.DropDownList1.DataTextField = dt.Columns[1].ToString(); 68
this.DropDownList1.DataValueField = dt.Columns[0].ToString(); 69
this.DropDownList1.DataBind(); 70
71
} 72
73
private void bindDropDown() 74
{ 75
ArrayList array1 = new ArrayList(); 76
for (int i = 0; i < 12; i++) 77
{ 78
array1.Add((i + 1)+""); 79
} 80
this.DropDownList2.DataSource = array1; 81
this.DropDownList2.DataBind(); 82
this.DropDownList5.DataSource = array1; 83
this.DropDownList5.DataBind(); 84
85
foreach (ListItem li in this.DropDownList2.Items) 86
{ 87
if (li.Text == DateTime.Today.Month.ToString()) 88
li.Selected = true; 89
} 90
foreach (ListItem li in this.DropDownList5.Items) 91
{ 92
if (li.Text == DateTime.Today.Month.ToString()) 93
li.Selected = true; 94
} 95
ArrayList array2 = new ArrayList(); 96
for(int i=2000;i<=2009;i++) 97
{ 98
array2.Add(i+""); 99
} 100
this.DropDownList4.DataSource = array2; 101
this.DropDownList4.DataBind(); 102
this.DropDownList7.DataSource = array2; 103
this.DropDownList7.DataBind(); 104
foreach (ListItem li in this.DropDownList4.Items) 105
{ 106
if (li.Text == DateTime.Today.Year.ToString()) 107
li.Selected = true; 108
} 109
foreach (ListItem li in this.DropDownList7.Items) 110
{ 111
if (li.Text == DateTime.Today.Year.ToString()) 112
li.Selected = true; 113
} 114
115
bindDay(int.Parse(this.DropDownList2.SelectedItem.Text),int.Parse(this.DropDownList4.SelectedItem.Text),this.DropDownList3); 116
bindDay(int.Parse(this.DropDownList5.SelectedItem.Text), int.Parse(this.DropDownList7.SelectedItem.Text), this.DropDownList6); 117
118
} 119
120
private void bindDay(int month,int year,DropDownList dropDownList) 121
{ 122
int days = 30; 123
if (month == 2) 124
{ 125
if (DateTime.IsLeapYear(year)) 126
days = 29; 127
else 128
days = 28; 129
} 130
if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month ==12) 131
days = 31; 132
ArrayList array = new ArrayList(); 133
for (int i = 0; i < days; i++) 134
{ 135
array.Add((i+1)+""); 136
} 137
dropDownList.DataSource = array; 138
dropDownList.DataBind(); 139
foreach (ListItem li in dropDownList.Items) 140
{ 141
if (li.Text == DateTime.Today.Day.ToString()) 142
li.Selected = true; 143
} 144
145
//this.DropDownList6.DataSource = array; 146
// this.DropDownList6.DataBind(); 147
148
149
} 150
protected void DropDownList4_SelectedIndexChanged(object sender, EventArgs e) 151
{ 152
bindDay(int.Parse(this.DropDownList2.SelectedItem.Text), int.Parse(this.DropDownList4.SelectedItem.Text), this.DropDownList3); 153
} 154
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e) 155
{ 156
bindDay(int.Parse(this.DropDownList2.SelectedItem.Text), int.Parse(this.DropDownList4.SelectedItem.Text), this.DropDownList3); 157
} 158
protected void DropDownList5_SelectedIndexChanged(object sender, EventArgs e) 159
{ 160
bindDay(int.Parse(this.DropDownList5.SelectedItem.Text), int.Parse(this.DropDownList7.SelectedItem.Text), this.DropDownList6); 161
} 162
protected void DropDownList7_SelectedIndexChanged(object sender, EventArgs e) 163
{ 164
bindDay(int.Parse(this.DropDownList5.SelectedItem.Text), int.Parse(this.DropDownList7.SelectedItem.Text), this.DropDownList6); 165
} 166
protected void Button1_Click(object sender, EventArgs e) 167
{ 168
if (string.IsNullOrEmpty(this.TextBox1.Text)) 169
{ 170
this.Label3.Text = "请输入任务名称"; 171
} 172
else 173
{ 174
this.Label3.Text = ""; 175
string taskName = this.TextBox1.Text; 176
int projectId = int.Parse(this.DropDownList1.SelectedValue.ToString()); 177
DateTime d1 = new DateTime(int.Parse(this.DropDownList4.SelectedItem.Text), int.Parse(this.DropDownList2.SelectedItem.Text), int.Parse(this.DropDownList3.SelectedItem.Text)); 178
DateTime d2 = new DateTime(int.Parse(this.DropDownList7.SelectedItem.Text), int.Parse(this.DropDownList5.SelectedItem.Text), int.Parse(this.DropDownList6.SelectedItem.Text)); 179
TaskDao.insertTask(taskName, projectId, d1, d2, this.TextBox2.Text); 180
bindTask(); 181
this.TextBox1.Text = ""; 182
this.TextBox2.Text = ""; 183
184
185
} 186
} 187
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) 188
{ 189
int keyId = int.Parse(this.GridView1.DataKeys[e.RowIndex].Value.ToString()); 190
TaskDao.deleteTask(keyId); 191
bindTask(); 192
} 193
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e) 194
{ 195
this.GridView1.EditIndex = e.NewEditIndex; 196
bindTask(); 197
} 198
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e) 199
{ 200
this.GridView1.EditIndex = -1; 201
bindTask(); 202
} 203
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) 204
{ 205
206
bool flag = true; 207
TextBox taskTb = this.GridView1.Rows[e.RowIndex].Cells[2].Controls[0] as TextBox; 208
TextBox beginDateTb = this.GridView1.Rows[e.RowIndex].Cells[3].Controls[0] as TextBox; 209
TextBox endDateTb = this.GridView1.Rows[e.RowIndex].Cells[4].Controls[0] as TextBox; 210
211
TextBox commentTb = this.GridView1.Rows[e.RowIndex].Cells[5].Controls[0] as TextBox; 212
int keyId = int.Parse(this.GridView1.DataKeys[e.RowIndex].Value.ToString()); 213
string taskName = taskTb.Text; 214
DateTime beginDate = DateTime.Today; ; 215
try 216
{ 217
beginDate = DateTime.Parse(beginDateTb.Text); 218
} 219
catch 220
{ 221
flag = false; 222
} 223
DateTime endDate = DateTime.Today; 224
try 225
{ 226
227
endDate = DateTime.Parse(endDateTb.Text); 228
} 229
catch 230
{ 231
flag = false; 232
} 233
string taskComment = commentTb.Text; 234
if (flag) 235
{ 236
237
TaskDao.updateTask(taskName, beginDate, endDate, taskComment, keyId); 238
this.GridView1.EditIndex = -1; 239
bindTask(); 240
241
} 242
243
244
} 245
} 246






}
}