温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:人事管理系统(课程设计)源码
当前文件:
Mispersonal/WebFiles/Department/DisplayDepart.aspx.cs,打开代码结构图
Mispersonal/WebFiles/Department/DisplayDepart.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_Department_View_Depart : System.Web.UI.Page 13
{ 14
protected void Page_Load(object sender, EventArgs e) 15
{ 16
if (!IsPostBack) 17
{ 18
string id = Request["D_ID"]; 19
string name = Request["D_Name"]; 20
Session["D_ID"] = id; 21
Session["D_Name"] = name; 22
Bond(); 23
} 24
} 25
private void Bond() 26
{ 27
string id = (string)Session["D_ID"]; 28
string sql = "select * from [Tb_department] where D_ID='" + id + "'"; 29
string connstr = ConfigurationManager.ConnectionStrings["Mispersonalconn"].ConnectionString; 30
SqlConnection Sqlconn = new SqlConnection(connstr); 31
Sqlconn.Open(); 32
SqlCommand sc = new SqlCommand(sql, Sqlconn); 33
SqlDataReader myreader = sc.ExecuteReader(); 34
if (myreader.Read()) 35
{ 36
TxtID.Text = myreader[0].ToString(); 37
TxtName.Text = myreader[1].ToString(); 38
TxtTel.Text = myreader[2].ToString(); 39
TxtAddress.Text = myreader[3].ToString(); 40
TxtChief.Text = myreader[4].ToString(); 41
TxtBelong.Text = myreader[5].ToString(); 42
Sqlconn.Close(); 43
} 44
} 45
protected void Edit_Click(object sender, EventArgs e) 46
{ 47
if ((string)Session["Name"] != "") 48
{ 49
if ((string)Session["role"] == "管理员") 50
{ 51
string sql = "Update [Tb_department] set D_Name='" 52
+TxtName.Text.Trim()+"',D_Tel='" 53
+TxtTel.Text.Trim()+"',D_Address='" 54
+TxtAddress.Text.Trim()+"',D_Chief='" 55
+TxtChief.Text.Trim()+"',D_Belong='" 56
+TxtBelong.Text.Trim()+"'"+"where D_ID='" 57
+TxtID.Text.Trim()+"' "; 58
string connstr = ConfigurationManager.ConnectionStrings["Mispersonalconn"].ConnectionString; 59
SqlConnection Sqlconn = new SqlConnection(connstr); 60
Sqlconn.Open(); 61
SqlCommand sc = new SqlCommand(sql, Sqlconn); 62
sc.ExecuteNonQuery(); 63
lbMessage.Text = "您已成功更新1条记录!"; 64
Sqlconn.Close(); 65
} 66
else 67
{ 68
Response.Write("<script>alert('只有管理员才可以进行此操作!')</script>"); 69
} 70
} 71
else 72
{ 73
Response.Redirect("Default.aspx"); ; 74
} 75
} 76
protected void Delete_Click(object sender, EventArgs e) 77
{ 78
if ((string)Session["Name"] != "") 79
{ 80
if ((string)Session["role"] == "管理员") 81
{ 82
string id = (string)Session["D_ID"]; 83
string sql = "delete from [Tb_department] where D_ID='" + id + "'"; 84
string connstr = ConfigurationManager.ConnectionStrings["Mispersonalconn"].ConnectionString; 85
SqlConnection Sqlconn = new SqlConnection(connstr); 86
Sqlconn.Open(); 87
SqlCommand sc = new SqlCommand(sql, Sqlconn); 88
sc.ExecuteNonQuery(); 89
Sqlconn.Close(); 90
Response.Redirect("~/WebFiles/Department/List_Depart.aspx"); 91
} 92
else 93
{ 94
Response.Write("<script>alert('只有管理员才可以进行此操作!')</script>"); 95
} 96
} 97
else 98
{ 99
Response.Redirect("Default.aspx"); ; 100
} 101
102
} 103
} 104





}
}