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

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

开发平台:

C#

  1. using System;
  2. using System.Collections;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Web;
  7. using System.Web.SessionState;
  8. using System.Web.UI;
  9. using System.Web.UI.WebControls;
  10. using System.Web.UI.HtmlControls;
  11. using System.Data.SqlClient;
  12. using UDS.Components;
  13. namespace UDS.SubModule.UnitiveDocument.Document
  14. {
  15. /// <summary>
  16. /// ListView 的摘要说明。
  17. /// </summary>
  18. public class ListView : System.Web.UI.Page
  19. {
  20. protected HttpCookie UserCookie;
  21. protected static string Username;
  22. protected string ClassID;
  23. protected System.Web.UI.WebControls.DataGrid dgDocList;
  24. protected string DisplayType="";
  25. protected static string SortRule="Desc",SortBy="DocAddedDate";
  26. protected System.Web.UI.WebControls.Label lblShowMember;
  27. protected System.Web.UI.WebControls.Label lblManageDirectory;
  28. protected System.Web.UI.WebControls.Label lblDeliveryDoc;
  29. protected System.Web.UI.WebControls.Label lblManagePermission;
  30. protected System.Web.UI.WebControls.Label lblRemove;
  31. protected System.Web.UI.WebControls.Label lblCopy;
  32. protected System.Web.UI.WebControls.LinkButton lnkbtnDelete;
  33. private void Page_Load(object sender, System.EventArgs e)
  34. {
  35. ClassID  = (Request.QueryString["ClassID"]!=null)?Request.QueryString["ClassID"].ToString():"";
  36. DisplayType  = (Request.QueryString["DisplayType"]!=null)?Request.QueryString["DisplayType"].ToString():"0";
  37. UserCookie  = Request.Cookies["Username"];
  38. Username  = UserCookie.Value.ToString();
  39. this.lnkbtnDelete.Attributes ["onclick"]="javascript:return confirm('您确认要丢弃吗?');";
  40. if(!IsPostBack)
  41. {
  42. BindGrid();
  43.     ShowAvailable();
  44. }
  45. }
  46. #region 数据绑定至DataGrid
  47. /// <summary>
  48. /// 将某用户的邮件取出绑定至DataGrid
  49. /// </summary>
  50. protected void BindGrid() 
  51. {   
  52. UserCookie  = Request.Cookies["Username"];
  53. string Username  = UserCookie.Value.ToString();
  54. DocumentClass doc   = new DocumentClass();
  55. SqlDataReader dr          = doc.GetDocListInClass(Int32.Parse(ClassID),Username,Int32.Parse(DisplayType));
  56. DataTable datatable   = Tools.ConvertDataReaderToDataTable(dr);
  57. DataView source     = datatable.DefaultView;
  58. source.Sort      = SortBy+" "+ SortRule;
  59. dgDocList.DataSource   = source;
  60. dgDocList.DataBind(); 
  61. //
  62. // if (datatable.Rows.Count !=0)
  63. // {
  64. // this.lnkbtnDelete.Visible =true;
  65. //
  66. // }
  67. doc   = null;
  68. datatable = null;
  69. #endregion
  70. #region 翻页事件
  71. public void DataGrid_PageChanged(object sender,DataGridPageChangedEventArgs e)
  72. {
  73. dgDocList.CurrentPageIndex = e.NewPageIndex;
  74. BindGrid();
  75. // ShowAvailable();
  76. }
  77. #endregion
  78. #region Web Form Designer generated code
  79. override protected void OnInit(EventArgs e)
  80. {
  81. //
  82. // CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
  83. //
  84. InitializeComponent();
  85. base.OnInit(e);
  86. }
  87. /// <summary>
  88. /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  89. /// 此方法的内容。
  90. /// </summary>
  91. private void InitializeComponent()
  92. {    
  93. this.lnkbtnDelete.Click += new System.EventHandler(this.lnkbtnDelete_Click);
  94. this.Load += new System.EventHandler(this.Page_Load);
  95. }
  96. #endregion
  97. #region 将数据排序
  98. /// <summary>
  99. /// 将信件按照指定字段进行排序
  100. /// </summary>
  101. protected void DataGrid_Sort(Object Src, DataGridSortCommandEventArgs E) 
  102. {
  103. SortRule   = (SortRule=="Desc")?"Asc":"Desc";
  104. SortBy   = E.SortExpression ;
  105. DocumentClass doc   = new DocumentClass();
  106. DataTable datatable   = Tools.ConvertDataReaderToDataTable(doc.GetDocListInClass(Int32.Parse(ClassID),Username,Int32.Parse(DisplayType)));
  107. DataView Source   = datatable.DefaultView;
  108. Source.Sort   = SortBy+" "+ SortRule;
  109. doc   = null;
  110. dgDocList.DataSource = Source;
  111. dgDocList.DataBind();
  112. }
  113. #endregion
  114. #region 根据权限显示相关功能标题
  115. // 设置缺省值
  116. public void ShowAvailable()
  117. {
  118. ProjectClass pjt  = new ProjectClass ();
  119. UserCookie  = Request.Cookies["Username"];
  120. string Username = UserCookie.Value.ToString();
  121. int classID  = Int32.Parse(ClassID);
  122. int cstRightToApproveDocument  = 2;
  123. int cstRightToViewDocument = 10;
  124. int cstRightToBuildNode   = 5;
  125. int cstDisplayMember = 6;
  126. int cstTeamRight = 7;
  127. int cstComposeMail = 11;
  128. int cstDeliveryDoc = 11;
  129. int cstProjectMove = 12;
  130. int cstProjectCopy = 12;
  131. int cstDeleteDocument = 3;
  132. this.lblManageDirectory.Visible = pjt.GetAccessPermission(classID,Username,cstRightToBuildNode);
  133. this.lblDeliveryDoc.Visible     = pjt.GetAccessPermission(classID,Username,cstDeliveryDoc);
  134. this.lblShowMember.Visible      = pjt.GetAccessPermission(classID,Username,cstDisplayMember);
  135. this.lblManagePermission.Visible= pjt.GetAccessPermission(classID,Username,cstTeamRight);
  136. this.lnkbtnDelete.Visible       = pjt.GetAccessPermission(classID,Username,cstDeleteDocument);
  137. this.lblRemove .Visible = pjt.GetAccessPermission(classID,Username,cstProjectMove);
  138. this.lblCopy .Visible = pjt.GetAccessPermission(classID,Username,cstProjectMove);
  139. pjt   = null;
  140. }
  141. #endregion
  142. private void lnkbtnDelete_Click(object sender, System.EventArgs e)
  143. {
  144. DocumentClass doc   = new DocumentClass();
  145. bool sqlFlag   = true;
  146. string sql   = "";
  147. foreach(DataGridItem dgi in dgDocList.Items)
  148. {
  149. CheckBox cb=(CheckBox)(dgi.Cells[0].Controls[1]);
  150. if (cb.Checked==true)
  151. {
  152. int i = dgi.ItemIndex;
  153. string id = dgDocList.DataKeys[i].ToString();
  154. if (sqlFlag)
  155. {
  156. sql+=id;
  157. sqlFlag=false;
  158. }
  159. else
  160. {
  161. sql+=" ,";
  162. sql+=id;
  163. }
  164. }
  165. }
  166. //选择为空
  167. if( sql==String.Empty)
  168. {
  169. Response.Write("<script language=javascript>alert('请选择文档!');window.location='ListView.aspx?ClassID="+ClassID+"';</script>");
  170. }
  171. else
  172. {
  173. int deleteFlag = DisplayType.ToString()=="3"?1:0; 
  174. if(doc.DocDelete(sql,deleteFlag))
  175. {
  176. Response.Write("<script language=javascript>alert('文档丢弃成功!');window.location='ListView.aspx?ClassID="+ClassID+"';</script>");
  177. }
  178. else
  179. {
  180. Server.Transfer("../../Error.aspx");
  181. }
  182. }
  183. doc=null;
  184. }
  185. }
  186. }