ListView.aspx.cs
上传用户:jdb8708888
上传日期:2013-05-29
资源大小:19971k
文件大小:7k
源码类别:

WEB源码(ASP,PHP,...)

开发平台:

C#

  1. using System;
  2. using System.Collections;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Data.SqlClient;
  6. using System.Drawing;
  7. using System.Web;
  8. using System.Web.SessionState;
  9. using System.Web.UI;
  10. using System.Web.UI.WebControls;
  11. using System.Web.UI.HtmlControls;
  12. using UDS.Components;
  13. namespace UDS.SubModule.Department
  14. {
  15. /// <summary>
  16. /// ListView 的摘要说明。
  17. /// </summary>
  18. public class ListView : System.Web.UI.Page
  19. {
  20. public static int DisplayType = 0;
  21. public static string DeptID;
  22. protected System.Web.UI.WebControls.DataGrid dbStaffList;
  23. protected System.Web.UI.WebControls.LinkButton lbOffLine;
  24. protected System.Web.UI.WebControls.LinkButton lbOnline;
  25. protected System.Web.UI.WebControls.Button cmdNewStaff;
  26. protected System.Web.UI.WebControls.Button cmdDepartmentOperate;
  27. protected System.Web.UI.WebControls.Button cmdSetRight;
  28. protected System.Web.UI.WebControls.Button cmdOffDepartment;
  29. protected System.Web.UI.WebControls.Button cmdChangeDepartment;
  30. protected System.Web.UI.WebControls.Button cmdOnDepartment;
  31. private void Page_Load(object sender, System.EventArgs e)
  32. {
  33. // 在此处放置用户代码以初始化页面
  34. if(!Page.IsPostBack)
  35. {
  36. if (Request.QueryString["DisplayType"] != null)
  37. DisplayType = Int32.Parse( Request.QueryString["DisplayType"].ToString());
  38. if(DisplayType==0)
  39. {
  40. // lbOnline.BackColor = Color.FromArgb(0xCCCCCC);
  41. // lbOffLine.BackColor =Color.FromArgb(0xFFFFFF);
  42. cmdOnDepartment.Visible =false;
  43. cmdOffDepartment.Visible =true;
  44. }
  45. else
  46. {
  47. // lbOnline.BackColor = Color.FromArgb(0xFFFFFF);
  48. // lbOffLine.BackColor =Color.FromArgb(0xCCCCCC);
  49. cmdOnDepartment.Visible =true;
  50. cmdOffDepartment.Visible =false;
  51. }
  52. if (Request.QueryString["DeptID"] != null)
  53. DeptID = Request.QueryString["DeptID"].ToString();
  54. else
  55. DeptID = "1";
  56. //如果要求刷新部门树
  57. if(Request.QueryString["Refresh"] != null )
  58. {
  59. Response.Write("<script language='javascript'>parent.contents.location.reload();</script>");
  60. }
  61. cmdOnDepartment.Attributes.Add("Onclick","javascript:return confirm('是否让选中的人复职?');");
  62. cmdOffDepartment.Attributes.Add("Onclick","javascript:return confirm('是否让选中的人离职?');");
  63. BindGrid();
  64. }
  65. }
  66. #region 翻页事件
  67. public void DataGrid_PageChanged(object sender,DataGridPageChangedEventArgs e)
  68. {
  69. dbStaffList.CurrentPageIndex = e.NewPageIndex;
  70. BindGrid();
  71. }
  72. #endregion
  73. private void BindGrid()
  74. {
  75. SqlDataReader dr; //存放人物的数据
  76. Database db = new Database();
  77. SqlParameter[] prams = {
  78.    db.MakeInParam("@Dept_ID",SqlDbType.Int,4,DeptID),
  79.    db.MakeInParam("@Dimission",SqlDbType.Bit,1,DisplayType)
  80.    };
  81. db.RunProc("sp_GetStaffInDepartment",prams,out dr);
  82. DataTable dt =Tools.ConvertDataReaderToDataTable(dr);
  83. dbStaffList.DataSource = dt.DefaultView;
  84. dbStaffList.DataBind();
  85. }
  86. #region Web Form Designer generated code
  87. override protected void OnInit(EventArgs e)
  88. {
  89. //
  90. // CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
  91. //
  92. InitializeComponent();
  93. base.OnInit(e);
  94. }
  95. /// <summary>
  96. /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  97. /// 此方法的内容。
  98. /// </summary>
  99. private void InitializeComponent()
  100. {    
  101. this.lbOnline.Click += new System.EventHandler(this.lbOnline_Click);
  102. this.lbOffLine.Click += new System.EventHandler(this.lbOffLine_Click);
  103. this.cmdNewStaff.Click += new System.EventHandler(this.cmdNewStaff_Click);
  104. this.cmdDepartmentOperate.Click += new System.EventHandler(this.cmdDepartmentOperate_Click);
  105. this.cmdSetRight.Click += new System.EventHandler(this.cmdSetRight_Click);
  106. this.cmdOnDepartment.Click += new System.EventHandler(this.cmdOnDepartment_Click);
  107. this.cmdOffDepartment.Click += new System.EventHandler(this.cmdOffDepartment_Click);
  108. this.cmdChangeDepartment.Click += new System.EventHandler(this.cmdChangeDepartment_Click);
  109. this.Load += new System.EventHandler(this.Page_Load);
  110. }
  111. #endregion
  112. private string GetSelectedItemID(string controlID)
  113. {
  114. String selectedID;
  115. selectedID = "";
  116. //遍历DataGrid获得checked的ID
  117. foreach (DataGridItem item in dbStaffList.Items)
  118. {
  119. if(((CheckBox)item.FindControl(controlID)).Checked==true )
  120. selectedID += dbStaffList.DataKeys[item.ItemIndex] + ",";
  121. }
  122. if(selectedID.Length>0)
  123. selectedID=selectedID.Substring(0,selectedID.Length-1);
  124. return selectedID;
  125. }
  126. private void lbOffLine_Click(object sender, System.EventArgs e)
  127. {
  128. Server.Transfer("Listview.aspx?DeptID=" + DeptID.ToString() + "&DisplayType=1");
  129. }
  130. private void lbOnline_Click(object sender, System.EventArgs e)
  131. {
  132. Server.Transfer("Listview.aspx?DeptID=" + DeptID.ToString() + "&DisplayType=0");
  133. }
  134. private void cmdNewStaff_Click(object sender, System.EventArgs e)
  135. {
  136. Server.Transfer("NewStaff.aspx?DeptID=" + DeptID.ToString() + "&DisplayType =0");
  137. }
  138. private void cmdDepartmentOperate_Click(object sender, System.EventArgs e)
  139. {
  140. Server.Transfer("ODepartment.aspx?DeptID=" + DeptID.ToString());
  141. }
  142. private void cmdSetRight_Click(object sender, System.EventArgs e)
  143. {
  144. Server.Transfer("../AssignRule/RightListview.aspx?ObjID=" + DeptID.ToString() + "&displayType=0");
  145. }
  146. private void cmdOnDepartment_Click(object sender, System.EventArgs e)
  147. {
  148. string selectedID = GetSelectedItemID("Staff_ID");
  149. UDS.Components.Database db = new UDS.Components.Database();
  150. if(selectedID.Trim()!="")
  151. {
  152. SqlParameter[] prams = {
  153.    db.MakeInParam("@StaffIDS",SqlDbType.VarChar,300,selectedID)
  154.    };
  155. db.RunProc("sp_StaffRehab",prams);
  156. }
  157. Response.Redirect("Listview.aspx?DeptID="+DeptID+"&displayType="+DisplayType.ToString());
  158. }
  159. private void cmdOffDepartment_Click(object sender, System.EventArgs e)
  160. {
  161. string selectedID = GetSelectedItemID("Staff_ID");
  162. if(selectedID!="")
  163. {
  164. UDS.Components.Staff person = new UDS.Components.Staff();
  165. if(person.Dimission(selectedID)==true)
  166. {
  167. //Response.Write("<script language=javascript>alert('离职成功!');</script>");
  168. BindGrid();
  169. }
  170. person = null;
  171. }
  172. else
  173. Response.Write("<script language=javascript>alert('请选择要离职的人员!');</script>");
  174. }
  175. private void cmdChangeDepartment_Click(object sender, System.EventArgs e)
  176. {
  177. string selectedID = GetSelectedItemID("Staff_ID");
  178. if(selectedID.Trim()!="")
  179. Response.Redirect("ChangeDepartment.aspx?DeptID="+DeptID+"&StaffIDS="+selectedID+"&DisplayType="+DisplayType.ToString()+"&BackFilePath="+Request.CurrentExecutionFilePath);
  180. else
  181. Response.Write("<script language=javascript>alert('请选择要调职的人员!');</script>");
  182. }
  183. }
  184. }