温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:Asp.net考勤系统源码
当前文件:
kaoqin/adminEight.aspx.cs[5K,2009-6-12 11:46:24],打开代码结构图
kaoqin/adminEight.aspx.cs[5K,2009-6-12 11:46:24],打开代码结构图1using System; 2
using System.Collections; 3
using System.ComponentModel; 4
using System.Data; 5
using System.Drawing; 6
using System.Web; 7
using System.Web.SessionState; 8
using System.Web.UI; 9
using System.Web.UI.WebControls; 10
using System.Web.UI.HtmlControls; 11
using System.Data.OleDb; 12
//该源码下载自www.51aspx.com(51aspx.com) 13
14
namespace KaoQin 15
{ 16
/// <summary> 17
/// adminEight 的摘要说明。 18
/// </summary> 19
public class adminEight : System.Web.UI.Page 20
{ 21
protected System.Web.UI.WebControls.Label Label1; 22
protected System.Web.UI.WebControls.Label Label2; 23
protected System.Web.UI.WebControls.TextBox txtCode; 24
protected System.Web.UI.WebControls.Label Label3; 25
protected System.Web.UI.WebControls.Label Label4; 26
protected System.Web.UI.WebControls.TextBox txtPwd; 27
protected System.Web.UI.WebControls.Button Button1; 28
protected System.Web.UI.WebControls.Button Button2; 29
protected System.Web.UI.WebControls.TextBox txtName; 30
protected System.Web.UI.WebControls.DataGrid data; 31
protected System.Web.UI.WebControls.Label info; 32
protected System.Data.DataSet ds; 33
protected System.Data.OleDb.OleDbDataReader reader; 34
protected System.Data.OleDb.OleDbConnection con; 35
protected System.Data.OleDb.OleDbCommand com; 36
protected System.Web.UI.WebControls.Button Button3; 37
protected System.Data.OleDb.OleDbDataAdapter da; 38
39
private void Page_Load(object sender, System.EventArgs e) 40
{ 41
// 在此处放置用户代码以初始化页面 42
if(System.Convert.ToString(Session["admin"]).Equals("")) 43
{ 44
Response.Redirect("admin.aspx"); 45
} 46
else 47
{ 48
string strcon="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Server.MapPath("message.mdb")+";User Id=admin;Password=;"; 49
con=new OleDbConnection(strcon); 50
if(!IsPostBack) 51
{ 52
bind(); 53
} 54
} 55
} 56
57
Web 窗体设计器生成的代码 82
83
private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e) 84
{ 85
data.CurrentPageIndex=e.NewPageIndex; 86
bind(); 87
} 88
89
private void Button1_Click(object sender, System.EventArgs e) 90
{ 91
if(txtCode.Text.Trim().Equals("")) 92
{ 93
info.Text="管理员编号不能为空!"; 94
} 95
else if(txtPwd.Text.Trim().Equals("")) 96
{ 97
info.Text="管理员密码不能为空!"; 98
} 99
else if(txtPwd.Text.Length<6) 100
{ 101
info.Text="管理员密码不能小于6位!"; 102
} 103
else if(txtName.Text.Trim().Equals("")) 104
{ 105
info.Text="管理员姓名不能为空!"; 106
} 107
else 108
{ 109
info.Text=""; 110
string sql2,sql3; 111
int count=0; 112
sql2="select adminId from admin where adminId='"+txtCode.Text.Trim()+"'"; 113
con.Open(); 114
com=new System.Data.OleDb.OleDbCommand(sql2,con); 115
reader=com.ExecuteReader(); 116
while(reader.Read()) 117
{ 118
count++; 119
} 120
reader.Close(); 121
com.Dispose(); 122
con.Close(); 123
if(count==0) 124
{ 125
sql3="insert into admin values('"+txtCode.Text.Trim()+"','"+txtPwd.Text.Trim()+"','"+txtName.Text.Trim()+"')"; 126
con.Open(); 127
com=new System.Data.OleDb.OleDbCommand(sql3,con); 128
com.ExecuteNonQuery(); 129
com.Dispose(); 130
con.Close(); 131
txtCode.Text=""; 132
txtPwd.Text=""; 133
txtName.Text=""; 134
bind(); 135
} 136
else 137
{ 138
info.Text="你添加的管理员编号已存在!"; 139
} 140
con.Close(); 141
} 142
} 143
144
private void Button2_Click(object sender, System.EventArgs e) 145
{ 146
txtCode.Text=""; 147
txtPwd.Text=""; 148
txtName.Text=""; 149
} 150
151
private void data_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) 152
{ 153
string id=(string)data.DataKeys[(int)e.Item.ItemIndex]; 154
if(id.Trim().Equals("admin")) 155
{ 156
info.Text="系统管理员不能删除!"; 157
} 158
else 159
{ 160
string sql4="delete from admin where adminId='"+id+"'"; 161
con.Open(); 162
com=new System.Data.OleDb.OleDbCommand(sql4,con); 163
com.ExecuteNonQuery(); 164
com.Dispose(); 165
con.Close(); 166
bind(); 167
} 168
} 169
170
public void bind() 171
{ 172
con.Open(); 173
ds=new DataSet(); 174
string sql="select * from admin order by adminId desc"; 175
da=new System.Data.OleDb.OleDbDataAdapter(sql,con); 176
da.Fill(ds,"admin"); 177
da.Dispose(); 178
con.Close(); 179
data.DataSource=ds.Tables["admin"].DefaultView; 180
data.DataBind(); 181
} 182
183
private void Button3_Click(object sender, System.EventArgs e) 184
{ 185
Response.Redirect("adminFive.aspx"); 186
} 187
} 188
} 189






}