温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:人事管理系统(课程设计)源码
当前文件:
Mispersonal/WebFiles/User/DisplayUser.aspx.cs,打开代码结构图
Mispersonal/WebFiles/User/DisplayUser.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
public partial class WebFiles_User_User_view : System.Web.UI.Page 13
{ 14
protected void Page_Load(object sender, EventArgs e) 15
{ 16
if (!IsPostBack) 17
{ 18
string id=Request["ID"]; 19
string name=Request["userName"]; 20
Session["ID"] = id; 21
Session["userName"] = name; 22
Bond(); 23
} 24
} 25
private void Bond() 26
{ 27
string id=(string)Session["ID"]; 28
//string name=Session["userName"]; 29
string sql = "select * from [Tb_User_Login] where ID='" + id + "'"; 30
string connstr = ConfigurationManager.ConnectionStrings["Mispersonalconn"].ConnectionString; 31
SqlConnection Sqlconn = new SqlConnection(connstr); 32
SqlDataAdapter sda = new SqlDataAdapter(sql,Sqlconn); 33
SqlCommandBuilder sc=new SqlCommandBuilder(sda); 34
DataSet ds = new DataSet(); 35
36
sda.Fill(ds,"temp"); 37
ds.Tables["temp"].DefaultView.Sort="id"; 38
int index=ds.Tables["temp"].DefaultView.Find(id); 39
TxtUserID.Text=(string)ds.Tables["temp"].Rows[index]["ID"]; 40
TxtUser.Text=(string)ds.Tables["temp"].Rows[index]["userName"]; 41
TxtPass.Text=(string)ds.Tables["temp"].Rows[index]["userPass"]; 42
TxtPass1.Text=(string)ds.Tables["temp"].Rows[index]["userPass"]; 43
role.SelectedValue=(string)ds.Tables["temp"].Rows[index]["userRole"]; 44
45
} 46
protected void Edit_Click(object sender, EventArgs e) 47
{ 48
if ((string)Session["Name"] != "") 49
{ 50
if ((string)Session["role"] == "管理员") 51
{ 52
string id = (string)Session["ID"]; 53
//string name=Session["userName"]; 54
string sql = "select * from [Tb_User_Login] where ID='" + id + "'"; 55
string connstr = ConfigurationManager.ConnectionStrings["Mispersonalconn"].ConnectionString; 56
SqlConnection Sqlconn = new SqlConnection(connstr); 57
SqlDataAdapter sda = new SqlDataAdapter(sql, Sqlconn); 58
SqlCommandBuilder sc = new SqlCommandBuilder(sda); 59
DataSet ds = new DataSet(); 60
61
sda.Fill(ds, "temp"); 62
ds.Tables["temp"].DefaultView.Sort = "id"; 63
int index = ds.Tables["temp"].DefaultView.Find(id); 64
ds.Tables["temp"].Rows[index]["ID"] = TxtUserID.Text.Trim(); 65
ds.Tables["temp"].Rows[index]["userName"] = TxtUser.Text.Trim(); 66
ds.Tables["temp"].Rows[index]["userPass"] = TxtPass.Text.Trim(); 67
ds.Tables["temp"].Rows[index]["userRole"] = role.SelectedValue.Trim(); 68
int rows = sda.Update(ds, "temp"); 69
lbMessage.Text = "您已成功更新" + rows + "条记录!"; 70
} 71
else 72
{ 73
Response.Write("<script>alert('只有管理员才可以进行此操作!')</script>"); 74
} 75
} 76
else 77
{ 78
Response.Redirect("Default.aspx"); ; 79
} 80
} 81
protected void Delete_Click(object sender, EventArgs e) 82
{ 83
if ((string)Session["Name"] != "") 84
{ 85
if ((string)Session["role"] == "管理员") 86
{ 87
string id = (string)Session["ID"]; 88
//string name=Session["userName"]; 89
string sql = "delete from [Tb_User_Login] where ID='" + id + "'"; 90
string connstr = ConfigurationManager.ConnectionStrings["Mispersonalconn"].ConnectionString; 91
SqlConnection Sqlconn = new SqlConnection(connstr); 92
Sqlconn.Open(); 93
SqlCommand sc = new SqlCommand(sql, Sqlconn); 94
// SqlDataAdapter sda= new SqlDataAdapter(); 95
// sda.DeleteCommand = sc; 96
sc.ExecuteNonQuery(); 97
Sqlconn.Close(); 98
// DataSet ds = new DataSet(); 99
// DataTable temp = new DataTable(); 100
// sda.Fill(temp); 101
// SqlCommandBuilder scb = new SqlCommandBuilder(sda); 102
// sda.Update(temp); 103
Response.Redirect("~/WebFiles/User/User_List.aspx"); 104
} 105
else 106
{ 107
Response.Write("<script>alert('只有管理员才可以进行此操作!')</script>"); 108
} 109
} 110
else 111
{ 112
Response.Redirect("Default.aspx"); ; 113
} 114
115
} 116
} 117





}
}