ResultList.aspx.cs
上传用户:xuming1973
上传日期:2014-02-27
资源大小:17511k
文件大小:6k
源码类别:

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. namespace UDS.SubModule.Staff.Sch
  13. {
  14. /// <summary>
  15. /// ResultList 的摘要说明。
  16. /// </summary>
  17. public class ResultList : System.Web.UI.Page
  18. {
  19. protected System.Web.UI.WebControls.DataGrid dgrd_StaffList;
  20. private string staffname,mobile,gender,email,bound;
  21. private int positionid;
  22. private int[] displayfieldsid;
  23. private string[] displayfieldsname;
  24. protected System.Web.UI.WebControls.Button btn_Print;
  25. //存放页眉文字
  26. private string[] headtext;
  27. private void Page_Load(object sender, System.EventArgs e)
  28. {
  29. if(!Page.IsPostBack)
  30. {
  31. headtext = new String[dgrd_StaffList.Columns.Count];
  32. for(int i=0;i<dgrd_StaffList.Columns.Count;i++)
  33. {
  34. headtext[i] = dgrd_StaffList.Columns[i].HeaderText;
  35. }
  36. ViewState["headtext"] = headtext;
  37. //获得来源页面的句柄
  38. Search searchform = (Search)Context.Handler;
  39. staffname = searchform.StaffName.Trim();
  40. positionid = searchform.Postion;
  41. mobile = (searchform.MobileSwitch==true)?searchform.Mobile:"";
  42. email = (searchform.EmailSwitch==true)?searchform.Email:"";
  43. gender = (searchform.GenderSwitch==true)?searchform.Gender:"";
  44. bound = searchform.SearchBound;
  45. displayfieldsid = searchform.SelectedFields;
  46. displayfieldsname = searchform.SelectedFieldsName;
  47. ViewState["staffname"] = staffname;
  48. ViewState["positionid"] = positionid.ToString();
  49. ViewState["mobile"] = mobile.ToString();
  50. ViewState["email"] = email.ToString();
  51. ViewState["gender"] = gender.ToString();
  52. ViewState["bound"] = bound.ToString();
  53. ViewState["displayfiledsid"] = displayfieldsid;
  54. Session["staffname"] = staffname;
  55. Session["positionid"] = positionid;
  56. Session["mobile"] = mobile;
  57. Session["email"] = email.ToString();
  58. Session["gender"] = gender.ToString();
  59. Session["bound"] = bound.ToString();
  60. Session["displayfieldsname"] = displayfieldsname;
  61. BindGrid(staffname,positionid,mobile,email,gender,displayfieldsid);
  62. }
  63. else
  64. {
  65. staffname = ViewState["staffname"].ToString();
  66. positionid = Int32.Parse(ViewState["positionid"].ToString());
  67. mobile = ViewState["mobile"].ToString();
  68. email = ViewState["email"].ToString();
  69. gender = ViewState["gender"].ToString();
  70. bound = ViewState["bound"].ToString();
  71. displayfieldsid = (int[])ViewState["displayfiledsid"];
  72. //把页眉复位
  73. headtext = (string[]) ViewState["headtext"];
  74. for(int i=0;i<dgrd_StaffList.Columns.Count;i++)
  75. {
  76. dgrd_StaffList.Columns[i].HeaderText = headtext[i];
  77. }
  78. }
  79. }
  80. private void BindGrid(string staffname,int positionid,string mobile,string email,string gender,int[] displayfiledsid)
  81. {
  82. SqlDataReader dr;
  83. UDS.Components.Staff staff = new UDS.Components.Staff();
  84. dr = staff.Find(staffname,positionid,mobile,email,gender,bound);
  85. DataTable dt = UDS.Components.Tools.ConvertDataReaderToDataTable(dr);
  86. if(ViewState["sortfield"]!=null)
  87. dt.DefaultView.Sort = ViewState["sortfield"] + " " + ViewState["sortdirect"];
  88. dgrd_StaffList.DataSource = dt.DefaultView;
  89. //放入高速缓存中便于打印
  90. Cache["StaffList"] = dt;
  91. for(int i=0;i<displayfieldsid.Length;i++)
  92. {
  93. dgrd_StaffList.Columns[displayfiledsid[i]].Visible = true;
  94. }
  95. dgrd_StaffList.DataBind();
  96. }
  97. #region Web 窗体设计器生成的代码
  98. override protected void OnInit(EventArgs e)
  99. {
  100. //
  101. // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
  102. //
  103. InitializeComponent();
  104. base.OnInit(e);
  105. }
  106. /// <summary>
  107. /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  108. /// 此方法的内容。
  109. /// </summary>
  110. private void InitializeComponent()
  111. {    
  112. this.dgrd_StaffList.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.dgrd_StaffList_PageIndexChanged);
  113. this.dgrd_StaffList.SortCommand += new System.Web.UI.WebControls.DataGridSortCommandEventHandler(this.dgrd_StaffList_SortCommand);
  114. this.btn_Print.Click += new System.EventHandler(this.btn_Print_Click);
  115. this.Load += new System.EventHandler(this.Page_Load);
  116. }
  117. #endregion
  118. private void dgrd_StaffList_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
  119. {
  120. ((DataGrid)source).CurrentPageIndex = e.NewPageIndex;
  121. BindGrid(staffname,positionid,mobile,email,gender,displayfieldsid);
  122. }
  123. private void dgrd_StaffList_SortCommand(object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
  124. {
  125. if(ViewState["sortfield"] == null)
  126. {
  127. ViewState["sortfield"] = e.SortExpression;
  128. ViewState["sortdirect"] = "ASC";
  129. }
  130. else
  131. {
  132. if(ViewState["sortfield"].ToString()==e.SortExpression)
  133. {
  134. ViewState["sortdirect"] = (ViewState["sortdirect"].ToString()=="ASC"?"DESC":"ASC");
  135. }
  136. else
  137. {
  138. ViewState["sortfield"] = e.SortExpression;
  139. ViewState["sortdirect"] = "ASC";
  140. }
  141. }
  142. foreach(DataGridColumn col in  dgrd_StaffList.Columns)
  143. {
  144. if(col.SortExpression.ToString()==ViewState["sortfield"].ToString())
  145. {
  146. if(ViewState["sortdirect"].ToString() == "ASC")
  147. col.HeaderText += "<img src='../../../images/asc.gif' border=0/>";
  148. else
  149. col.HeaderText += "<img src='../../../images/desc.gif' border=0/>";
  150. }
  151. }
  152. BindGrid(staffname,positionid,mobile,email,gender,displayfieldsid);
  153. }
  154. private void btn_Print_Click(object sender, System.EventArgs e)
  155. {
  156. Response.Write("<script>window.open('../Report/StaffReport.aspx','_blank')</script>");
  157. }
  158. }
  159. }