温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:小区物业管理系统源码
当前文件:
SmallHouse/admin/admin.aspx.cs,打开代码结构图
SmallHouse/admin/admin.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 System.Data.SqlClient; 12
13
14
public partial class admin_Default2 : System.Web.UI.Page 15
{ 16
17
18
static string valpass="";//验证原密码是否正确 19
BaseClass bc=new BaseClass(); 20
protected void Page_Load(object sender, EventArgs e) 21
{ 22
23
if (Convert.ToString(Session["UID"]) == "") 24
{ 25
Response.Redirect("login.aspx"); 26
27
} 28
29
if (!IsPostBack) 30
{ 31
this.bind(); 32
} 33
34
35
36
37
} 38
39
//初使时对数据进行绑定 40
protected void bind() 41
{ 42
string sqlstr="select * from admin"; 43
bc.ExecGridView(GridView1, sqlstr); 44
45
46
} 47
48
protected void Button3_Click(object sender, EventArgs e) 49
{ 50
adduser.Visible = true; 51
} 52
53
//取消输入 54
protected void Button1_Click(object sender, EventArgs e) 55
{ 56
tbuser.Text = ""; 57
tbpass.Text = ""; 58
tbtwopass.Text = ""; 59
adduser.Visible = false; 60
} 61
62
//添加用户名 63
protected void btnadduser_Click(object sender, EventArgs e) 64
{ 65
66
try 67
{ 68
if (val()) 69
{ 70
string sqlstr = "insert into admin(name,UID,PWD)values('" + tbname.Text + "','" + tbuser.Text + "','" + tbpass.Text + "')"; 71
72
if (bc.ExecSql(sqlstr)) 73
{ 74
Response.Write("<script language=javascript>alert('用户名添加成功!');</script>"); 75
adduser.Visible = false; 76
this.bind(); 77
78
79
} 80
else 81
{ 82
Response.Write("<script language=javascript>alert('添加失败,请重试!');</script>"); 83
return; 84
} 85
} 86
else 87
{ 88
Response.Write("<script language=javascript>alert('用户名存在,请选择其它用户名!');</script>"); 89
return; 90
} 91
} 92
finally 93
{ 94
bc.Closeconn(); 95
} 96
97
} 98
99
100
//验证新的用户名是否存在 101
protected bool val() 102
{ 103
string conn = Convert.ToString(ConfigurationManager.ConnectionStrings["SmallHouseConn"]); 104
105
SqlConnection sqlcon = new SqlConnection(conn); 106
sqlcon.Open(); 107
string sqlstr = "select count(*) from admin where uid='" + tbuser.Text + "'"; 108
109
110
//Response.Write(sqlstr); 111
SqlCommand scd = new SqlCommand(sqlstr, sqlcon); 112
int count = Convert.ToInt32(scd.ExecuteScalar()); 113
114
//Response.Write(count); 115
//Response.End(); 116
117
if (count <= 0) 118
{ 119
120
return true; 121
} 122
else 123
{ 124
125
return false; 126
127
} 128
} 129
//gridview 数数绑定时执行 130
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) 131
{ 132
if (e.Row.RowType == DataControlRowType.DataRow) 133
{ 134
135
136
((LinkButton)(e.Row.Cells[4].Controls[0])).Attributes.Add("onclick", "return confirm('确定删除吗?')"); 137
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#22dd22';this.Style.color='buttontext';this.Style.cursor='default';"); 138
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='';this.style.color='';"); 139
} 140
} 141
142
143
///修改密码 144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
//删除管理员帐号时执行 159
160
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) 161
{ 162
163
string uid = GridView1.DataKeys[e.RowIndex].Value.ToString(); 164
165
166
if (Session["UID"].ToString() != uid) 167
{ 168
string sqlstr = "delete from admin where ID='" + uid + "'"; 169
//Response.Write(sqlstr); 170
//Response.End(); 171
try 172
{ 173
if (bc.ExecSql(sqlstr)) 174
{ 175
Response.Write("<script>alert('删除管理员帐号成功!');</script>"); 176
this.bind(); 177
} 178
else 179
{ 180
Response.Write("<script>alert('操作失败,请重试!');</script>"); 181
} 182
} 183
catch (Exception ex) 184
{ 185
Response.Write("<script>alert('删除失败,失败原因:" + ex.Message.ToString() + "');</script>"); 186
return; 187
} 188
} 189
else 190
{ 191
Response.Write("<script>alert('管理员用不能删除自已');</script>"); 192
return; 193
} 194
195
196
197
198
} 199
200
}





}
}