温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:无忧劳保库存系统源码
当前文件:
Labor/organizational.aspx.cs,打开代码结构图
Labor/organizational.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 SqlHelper; 12
using System.Data.SqlClient; 13
public partial class organizational : System.Web.UI.Page 14
{ 15
//定义连接对象 16
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["dbuser"].ConnectionString); 17
18
Helper he = new Helper(); 19
20
static string CNo;//编号 21
22
static int i = 1;//页数 23
24
protected void Page_Load(object sender, EventArgs e) 25
{ 26
GridView1.DataSource = he.BinddivisionInfo(); 27
28
if (!IsPostBack) 29
{ 30
GridView1.DataBind(); 31
32
if (he.IsAdmin(Session["username"].ToString())) 33
{ 34
; 35
} 36
else 37
{ 38
Response.Write("<script>window.showModalDialog('IsAdmin.aspx','','resizable:yes;scroll:yes;status:no;dialogWidth=320px;dialogHeight=230px;center=yes;help=no');</script>"); 39
40
Panel1.Visible = false; 41
42
UpdatePanel2.Visible = false; 43
44
UpdatePanel3.Visible = false; 45
46
return; 47
} 48
Label2.Text = "当前页码是" + Convert.ToString(GridView1.PageIndex + i); 49
TxtDName.Focus(); 50
BindDataBase(); 51
Department.ShowLines = true;//显示连接父节点与子节点间的线条 52
Department.ExpandDepth = 1;//控件显示时所展开的层数 53
} 54
} 55
//绑定TreeView 56
public void BindDataBase() 57
{ 58
SqlDataAdapter da = new SqlDataAdapter("select DepartmentName from division", conn); 59
60
DataSet ds = new DataSet(); 61
62
da.Fill(ds, "division"); 63
64
TreeNode tree = new TreeNode("部门信息"); 65
66
Department.Nodes.Add(tree); 67
68
for (int i = 0; i < ds.Tables["division"].Rows.Count; i++) 69
{ 70
TreeNode tree1 = new TreeNode(ds.Tables["division"].Rows[i]["DepartmentName"].ToString()); 71
72
tree.ChildNodes.Add(tree1); 73
} 74
} 75
protected void BtnAdd_Click(object sender, EventArgs e) 76
{ 77
if (TxtDName.Text.Trim().Length == 0) 78
{ 79
Label1.Text = "请输入部门的名字"; 80
81
TxtDName.Focus(); 82
} 83
else 84
{ 85
if (he.IsDepartment(TxtDName.Text.Trim())) 86
{ 87
Label1.Text = "已经存在此部门了"; 88
89
TxtDName.Focus(); 90
} 91
else 92
{ 93
if (he.ExecSQL("insert into division(DepartmentName) values('" + TxtDName.Text.Trim() + "')")) 94
{ 95
Label1.Text = "成功添加新的部门"; 96
97
System.Web.UI.ScriptManager.RegisterStartupScript(BtnAdd, this.GetType(), "unReport", "history.go(0)", true); 98
} 99
} 100
} 101
} 102
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) 103
{ 104
if (e.CommandName == "del") 105
{ 106
//获取员工的编号 107
int index = Convert.ToInt32(e.CommandArgument); 108
//根据行编号,获取选择的整行 109
GridViewRow selectedRowd = this.GridView1.Rows[index]; 110
//获取学生编号 111
CNo = selectedRowd.Cells[0].Text; 112
113
if (he.ExecSQL("delete from division where DepartmentID='" + CNo + "'")) 114
{ 115
GridView1.DataSource = he.BinddivisionInfo(); 116
117
GridView1.DataBind(); 118
119
System.Web.UI.ScriptManager.RegisterStartupScript(BtnAdd, this.GetType(), "unReport", "history.go(0)", true); 120
} 121
else 122
{ 123
return; 124
} 125
126
} 127
} 128
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) 129
{ 130
if (e.Row.RowType == DataControlRowType.DataRow) 131
{ 132
if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate) 133
{ 134
((LinkButton)e.Row.Cells[2].Controls[0]).Attributes.Add("onclick", "javascript:return confirm('你确认要删除部门:\"" + e.Row.Cells[1].Text.Trim() + "\"吗?')"); 135
} 136
} 137
} 138
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) 139
{ 140
GridView1.PageIndex = e.NewPageIndex; 141
142
Label2.Text = "当前页码是" + Convert.ToString(GridView1.PageIndex + i); 143
144
GridView1.DataBind(); 145
146
} 147
} 148





}
}