温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:学生管理信息系统+留言板
当前文件:
StudentSys/EmpsRecord.cs,打开代码结构图
StudentSys/EmpsRecord.cs,打开代码结构图1namespace StudentSys 2
{ 3
using System; 4
using System.Collections; 5
using System.ComponentModel; 6
using System.Data; 7
using System.Data.OleDb; 8
using System.Drawing; 9
using System.Web; 10
using System.Web.SessionState; 11
using System.Web.UI; 12
using System.Web.UI.WebControls; 13
using System.Web.UI.HtmlControls; 14
using StudentSys.Module; 15
16
public class EmpsRecord : System.Web.UI.Page 17
18
{ 19
20
//更新窗口定义控件的声名 21
protected CCUtility Utility; 22
23
//更新记录表单、变量等的声名 24
protected System.Web.UI.WebControls.Label emps_ValidationSummary; 25
protected System.Web.UI.HtmlControls.HtmlInputButton emps_insert; 26
protected System.Web.UI.HtmlControls.HtmlInputButton emps_update; 27
protected System.Web.UI.HtmlControls.HtmlInputButton emps_delete; 28
protected System.Web.UI.HtmlControls.HtmlInputButton emps_cancel; 29
protected System.Web.UI.HtmlControls.HtmlInputHidden emps_emp_id; 30
protected System.Web.UI.WebControls.TextBox emps_name; 31
protected System.Web.UI.WebControls.TextBox emps_no; 32
protected System.Web.UI.WebControls.TextBox emps_title; 33
protected System.Web.UI.WebControls.TextBox emps_emp_login; 34
protected System.Web.UI.WebControls.TextBox emps_emp_password; 35
protected System.Web.UI.WebControls.DropDownList emps_emp_level; 36
protected System.Web.UI.WebControls.DropDownList emps_dep_id; 37
protected System.Web.UI.WebControls.TextBox emps_address; 38
protected System.Web.UI.WebControls.TextBox emps_email; 39
protected System.Web.UI.WebControls.TextBox emps_work_phone; 40
protected System.Web.UI.WebControls.TextBox emps_home_phone; 41
protected System.Web.UI.WebControls.TextBox emps_cell_phone; 42
protected System.Web.UI.WebControls.CheckBox emps_manmonth; 43
protected System.Web.UI.WebControls.TextBox emps_picture; 44
45
//定义各表单事件保护字符串 46
protected string emps_FormAction="EmpsGrid.aspx?"; 47
protected System.Web.UI.HtmlControls.HtmlInputHidden p_emps_emp_id; 48
protected System.Web.UI.WebControls.Label GridForm_Title; 49
protected System.Web.UI.WebControls.RequiredFieldValidator emps_name_Validator_Req; 50
protected System.Web.UI.WebControls.RequiredFieldValidator emps_no_Validator_Req; 51
protected System.Web.UI.WebControls.RequiredFieldValidator emps_title_Validator_Req; 52
protected System.Web.UI.WebControls.RequiredFieldValidator emps_emp_login_Validator_Req; 53
protected System.Web.UI.WebControls.RequiredFieldValidator emps_emp_password_Validator_Req; 54
protected System.Web.UI.WebControls.RequiredFieldValidator emps_emp_level_Validator_Req; 55
protected System.Web.UI.WebControls.CustomValidator emps_emp_level_Validator_Num; 56
protected System.Web.UI.WebControls.RequiredFieldValidator emps_dep_id_Validator_Req; 57
protected System.Web.UI.WebControls.CustomValidator emps_dep_id_Validator_Num;protected String[] emps_emp_level_lov = "0;None;3;Admin".Split(new Char[] {';'}); 58
59
//初始化事件 60
public EmpsRecord() 61
{ 62
this.Init += new System.EventHandler(Page_Init); 63
} 64
// EmpsRecord中的自定义包含控件结束 65
66
public void ValidateNumeric(object source, ServerValidateEventArgs args) { 67
try{ 68
Decimal temp=Decimal.Parse(args.Value); 69
args.IsValid=true; 70
}catch{ 71
args.IsValid=false; } 72
} 73
74
//定义登录窗口显示控件过程 75
//初始化页面过程,创建一个Utility实例,并调用其相应的各方法 76
protected void Page_Load(object sender, EventArgs e) 77
{ 78
Utility=new CCUtility(this); 79
Utility.CheckSecurity(3); 80
// 完成窗口安全验证 81
82
if (!IsPostBack){ 83
84
p_emps_emp_id.Value = Utility.GetParam("emp_id");Page_Show(sender, e); 85
} 86
} 87
88
//页面关闭过程 89
protected void Page_Unload(object sender, EventArgs e) 90
{ 91
if(Utility!=null) Utility.DBClose(); 92
} 93
94
//窗口中控件定义事件处理过程 95
protected void Page_Init(object sender, EventArgs e) 96
{ 97
InitializeComponent(); 98
} 99
private void InitializeComponent() 100
{ 101
this.emps_insert.ServerClick += new System.EventHandler(this.emps_Action); 102
this.emps_update.ServerClick += new System.EventHandler(this.emps_Action); 103
this.emps_delete.ServerClick += new System.EventHandler(this.emps_Action); 104
this.emps_cancel.ServerClick += new System.EventHandler(this.emps_Action); 105
this.Unload += new System.EventHandler(this.Page_Unload); 106
this.Load += new System.EventHandler(this.Page_Load); 107
108
} 109
110
//定义整体显示页面过程 111
protected void Page_Show(object sender, EventArgs e) 112
{ 113
emps_Show(); 114
115
} 116
117
118
119
// EmpsRecord Show end 120
//完成表单初始化 121
122
123
//定义控制函数,控制按钮的的显示与否 124
//如,当插入记录时,应显示插入、取消按钮,而修改时应显示修改、删除、取消按钮 125
private bool emps_Validate(){ 126
bool result=true; 127
emps_ValidationSummary.Text=""; 128
129
for(int i=0;i<Page.Validators.Count;i++){ 130
if(((System.Web.UI.WebControls.BaseValidator)Page.Validators[i]).ID.ToString().StartsWith("emps")){ 131
if(!Page.Validators[i].IsValid){ 132
emps_ValidationSummary.Text+=Page.Validators[i].ErrorMessage+"<br>"; 133
result=false; 134
} 135
} 136
} 137
138
emps_ValidationSummary.Visible=(!result); 139
return result; 140
} 141
142
//更新记录显示过程 143
void emps_Show() { 144
145
Utility.buildListBox(emps_emp_level.Items,emps_emp_level_lov,null,""); 146
Utility.buildListBox(emps_dep_id.Items,"select dep_id,name from deps order by 2","dep_id","name",null,""); 147
148
bool ActionInsert=true; 149
150
if (p_emps_emp_id.Value.Length > 0 ) { 151
string sWhere = ""; 152
153
sWhere += "emp_id=" + CCUtility.ToSQL(p_emps_emp_id.Value, CCUtility.FIELD_TYPE_Number); 154
155
string sSQL = "select * from emps where " + sWhere; 156
OleDbDataAdapter dsCommand = new OleDbDataAdapter(sSQL, Utility.Connection); 157
DataSet ds = new DataSet(); 158
DataRow row; 159
160
if (dsCommand.Fill(ds, 0, 1, "emps") > 0) { 161
row = ds.Tables[0].Rows[0]; 162
163
emps_emp_id.Value = CCUtility.GetValue(row, "emp_id"); 164
emps_name.Text = CCUtility.GetValue(row, "name"); 165
emps_no.Text = CCUtility.GetValue(row, "emp_no"); 166
emps_title.Text = CCUtility.GetValue(row, "title"); 167
emps_emp_login.Text = CCUtility.GetValue(row, "emp_login"); 168
emps_emp_password.Text = CCUtility.GetValue(row, "emp_password"); 169
170
{string s; 171
s=CCUtility.GetValue(row, "emp_level"); 172
173
try {emps_emp_level.SelectedIndex=emps_emp_level.Items.IndexOf(emps_emp_level.Items.FindByValue(s)); 174
}catch{}} 175
176
177
178
{string s; 179
s=CCUtility.GetValue(row, "dep_id"); 180
181
try {emps_dep_id.SelectedIndex=emps_dep_id.Items.IndexOf(emps_dep_id.Items.FindByValue(s)); 182
}catch{}} 183
184
185
emps_address.Text = CCUtility.GetValue(row, "address"); 186
187
188
emps_email.Text = CCUtility.GetValue(row, "email"); 189
emps_work_phone.Text = CCUtility.GetValue(row, "work_phone"); 190
emps_home_phone.Text = CCUtility.GetValue(row, "home_phone"); 191
emps_cell_phone.Text = CCUtility.GetValue(row, "cell_phone"); 192
emps_manmonth.Checked=CCUtility.GetValue(row, "manmonth").ToLower().Equals("1".ToLower()); 193
194
emps_picture.Text = CCUtility.GetValue(row, "picture"); 195
emps_insert.Visible=false; 196
ActionInsert=false; 197
198
}} 199
200
if(ActionInsert){ 201
202
String pValue; 203
204
pValue = Utility.GetParam("emp_id");emps_emp_id.Value = pValue;emps_delete.Visible=false; 205
emps_update.Visible=false; 206
207
} 208
} 209
210
//插入新记录事件代码 211
bool emps_insert_Click(Object Src, EventArgs E) { 212
string sSQL=""; 213
bool bResult=emps_Validate(); 214
215
int iCount = Utility.DlookupInt("emps", "count(*)", "emp_login=" + CCUtility.ToSQL(Utility.GetParam("emps_emp_login"), CCUtility.FIELD_TYPE_Text)); 216
if (iCount!=0){ 217
emps_ValidationSummary.Visible=true; 218
emps_ValidationSummary.Text+="The value in field Login is already in database."+"<br>"; 219
bResult=false;} 220
221
if(bResult){ 222
223
224
string p2_name=CCUtility.ToSQL(Utility.GetParam("emps_name"), CCUtility.FIELD_TYPE_Text) ; 225
string p2_no=CCUtility.ToSQL(Utility.GetParam("emps_no"), CCUtility.FIELD_TYPE_Text) ; 226
string p2_title=CCUtility.ToSQL(Utility.GetParam("emps_title"), CCUtility.FIELD_TYPE_Text) ; 227
string p2_emp_login=CCUtility.ToSQL(Utility.GetParam("emps_emp_login"), CCUtility.FIELD_TYPE_Text) ; 228
string p2_emp_password=CCUtility.ToSQL(Utility.GetParam("emps_emp_password"), CCUtility.FIELD_TYPE_Text) ; 229
string p2_emp_level=CCUtility.ToSQL(Utility.GetParam("emps_emp_level"), CCUtility.FIELD_TYPE_Number) ; 230
string p2_dep_id=CCUtility.ToSQL(Utility.GetParam("emps_dep_id"), CCUtility.FIELD_TYPE_Number) ; 231
string p2_address=CCUtility.ToSQL(Utility.GetParam("emps_address"), CCUtility.FIELD_TYPE_Text) ; 232
string p2_email=CCUtility.ToSQL(Utility.GetParam("emps_email"), CCUtility.FIELD_TYPE_Text) ; 233
string p2_work_phone=CCUtility.ToSQL(Utility.GetParam("emps_work_phone"), CCUtility.FIELD_TYPE_Text) ; 234
string p2_home_phone=CCUtility.ToSQL(Utility.GetParam("emps_home_phone"), CCUtility.FIELD_TYPE_Text) ; 235
string p2_cell_phone=CCUtility.ToSQL(Utility.GetParam("emps_cell_phone"), CCUtility.FIELD_TYPE_Text) ; 236
string c1_manmonth=CCUtility.getCheckBoxValue(Utility.GetParam("emps_manmonth"), "1", "0", CCUtility.FIELD_TYPE_Number) ; 237
string p2_picture=CCUtility.ToSQL(Utility.GetParam("emps_picture"), CCUtility.FIELD_TYPE_Text) ; 238
239
sSQL = "insert into emps (" + 240
"name," + 241
"emp_no," + 242
"title," + 243
"emp_login," + 244
"emp_password," + 245
"emp_level," + 246
"dep_id," + 247
"address," + 248
"email," + 249
"work_phone," + 250
"home_phone," + 251
"cell_phone," + 252
"manmonth," + 253
"picture)" + 254
" values (" + 255
p2_name + "," + 256
p2_no + "," + 257
p2_title + "," + 258
p2_emp_login + "," + 259
p2_emp_password + "," + 260
p2_emp_level + "," + 261
p2_dep_id + "," + 262
p2_address + "," + 263
p2_email + "," + 264
p2_work_phone + "," + 265
p2_home_phone + "," + 266
p2_cell_phone + "," + 267
c1_manmonth + "," + 268
p2_picture + ")"; 269
OleDbCommand cmd = new OleDbCommand(sSQL, Utility.Connection); 270
try { 271
cmd.ExecuteNonQuery(); 272
} catch(Exception e) { 273
emps_ValidationSummary.Text += e.Message; 274
emps_ValidationSummary.Visible = true; 275
return false; 276
} 277
} 278
return bResult; 279
} 280
281
282
283
//更新记录事件代码 284
bool emps_update_Click(Object Src, EventArgs E) 285
{ 286
string sWhere = ""; 287
string sSQL =""; 288
289
bool bResult=emps_Validate(); 290
if(bResult) 291
{ 292
if (p_emps_emp_id.Value.Length > 0) 293





}