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.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.Role
  14. {
  15. /// <summary>
  16. /// ListView 的摘要说明。
  17. /// </summary>
  18. public class ListView : System.Web.UI.Page
  19. {
  20. public int DisplayType;
  21. public int RoleID;
  22. protected System.Web.UI.WebControls.DataGrid dbStaffList;
  23. protected System.Web.UI.WebControls.LinkButton lbMember;
  24. protected System.Web.UI.WebControls.LinkButton lbNonMember;
  25. protected System.Web.UI.WebControls.Button cmdManageRole;
  26. protected System.Web.UI.WebControls.Button cmdManageRight;
  27. protected System.Web.UI.WebControls.Button cmdDeleteStaffFromRole;
  28. protected System.Web.UI.WebControls.Button cmdAddToRole;
  29. private bool refresh;
  30. private void Page_Load(object sender, System.EventArgs e)
  31. {
  32. // 在此处放置用户代码以初始化页面
  33. RoleID =Int32.Parse((Request.QueryString["Role_ID"]==null)?"0":Request.QueryString["Role_ID"].ToString());
  34. DisplayType = Int32.Parse((Request.QueryString["DisplayType"]==null)?"0":Request.QueryString["DisplayType"].ToString());
  35. if(!Page.IsPostBack)
  36. {
  37. if(DisplayType==0)
  38. {
  39. cmdAddToRole.Visible = false;
  40. cmdDeleteStaffFromRole.Visible = true;
  41. }
  42. else
  43. {
  44. cmdAddToRole.Visible = true;
  45. cmdDeleteStaffFromRole.Visible = false;
  46. }
  47. refresh = (Request.QueryString["Refresh"]==null)?false:true;
  48. if(refresh)
  49. Response.Write("<script language='javascript'>parent.LeftFrame.location.reload();</script>");
  50. BindGrid();
  51. cmdAddToRole.Attributes.Add("OnClick","javascript:return confirm('是否把选定人员加入到角色!');");
  52. cmdDeleteStaffFromRole.Attributes.Add("OnClick","javascript:return confirm('是否把选定人员从角色脱离!');");
  53. }
  54. }
  55. public string GetSelectImage(string NormalImg,string SelectedImg,int selected,int position)
  56. {
  57. if(selected==position)
  58. return SelectedImg;
  59. else
  60. return NormalImg;
  61. }
  62. private void BindGrid()
  63. {
  64. SqlDataReader dr; //存放人物的数据
  65. Database db = new Database();
  66. SqlParameter[] prams = {
  67.    db.MakeInParam("@RoleID",SqlDbType.Int,4,RoleID)
  68.    };
  69. if(DisplayType==0)
  70. db.RunProc("sp_GetStaffInRole",prams,out dr);
  71. else
  72. db.RunProc("sp_GetStaffNotInRole",prams,out dr);
  73. DataTable dt =Tools.ConvertDataReaderToDataTable(dr);
  74. dbStaffList.DataSource = dt.DefaultView;
  75. dbStaffList.DataBind();
  76. }
  77. #region 翻页事件
  78. public void DataGrid_PageChanged(object sender,DataGridPageChangedEventArgs e)
  79. {
  80. dbStaffList.CurrentPageIndex = e.NewPageIndex;
  81. BindGrid();
  82. }
  83. #endregion
  84. #region Web Form Designer generated code
  85. override protected void OnInit(EventArgs e)
  86. {
  87. //
  88. // CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
  89. //
  90. InitializeComponent();
  91. base.OnInit(e);
  92. }
  93. /// <summary>
  94. /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  95. /// 此方法的内容。
  96. /// </summary>
  97. private void InitializeComponent()
  98. {    
  99. this.lbMember.Click += new System.EventHandler(this.lbMember_Click);
  100. this.lbNonMember.Click += new System.EventHandler(this.lbNonMember_Click);
  101. this.cmdManageRole.Click += new System.EventHandler(this.cmdManageRole_Click);
  102. this.cmdManageRight.Click += new System.EventHandler(this.cmdManageRight_Click);
  103. this.cmdDeleteStaffFromRole.Click += new System.EventHandler(this.cmdDeleteStaffFromRole_Click);
  104. this.cmdAddToRole.Click += new System.EventHandler(this.cmdAddToRole_Click);
  105. this.Load += new System.EventHandler(this.Page_Load);
  106. }
  107. #endregion
  108. private string GetSelectedItemID(string controlID)
  109. {
  110. String selectedID;
  111. selectedID = "";
  112. //遍历DataGrid获得checked的ID
  113. foreach (DataGridItem item in dbStaffList.Items)
  114. {
  115. if(((CheckBox)item.FindControl(controlID)).Checked==true )
  116. selectedID += dbStaffList.DataKeys[item.ItemIndex] + ",";
  117. }
  118. if(selectedID.Length>0)
  119. selectedID=selectedID.Substring(0,selectedID.Length-1);
  120. return selectedID;
  121. }
  122. private void lbMember_Click(object sender, System.EventArgs e)
  123. {
  124. Server.Transfer("Listview.aspx?Role_ID=" + RoleID.ToString() + "&DisplayType=0" );
  125. }
  126. private void lbNonMember_Click(object sender, System.EventArgs e)
  127. {
  128. Server.Transfer("Listview.aspx?Role_ID=" + RoleID.ToString() + "&DisplayType=1" );
  129. }
  130. private void cmdManageRole_Click(object sender, System.EventArgs e)
  131. {
  132. Server.Transfer("ORole.aspx?Role_ID=" + RoleID.ToString());
  133. }
  134. private void cmdManageRight_Click(object sender, System.EventArgs e)
  135. {
  136. Server.Transfer("../AssignRule/RightListview.aspx?ObjID=" +RoleID.ToString() + "&DisplayType=2");
  137. }
  138. private void cmdDeleteStaffFromRole_Click(object sender, System.EventArgs e)
  139. {
  140. string selectID =GetSelectedItemID("Staff_ID");
  141. if(selectID.Trim()!="")
  142. {
  143. if(UDS.Components.Role.DelStaffFromRole(RoleID,selectID)!=0)
  144. {
  145. UDS.Components.Error.Log("脱离角色出错!");
  146. Response.Redirect("../Error.aspx");
  147. }
  148. else
  149. Response.Redirect("ListView.aspx?Role_ID="+RoleID.ToString()+"&DisplayType="+DisplayType.ToString());
  150. }
  151. else
  152. Response.Write("<script language='javascript'>alert('请选择要脱离的人员');</script>");
  153. }
  154. private void cmdAddToRole_Click(object sender, System.EventArgs e)
  155. {
  156. string selectID =GetSelectedItemID("Staff_ID");
  157. if(selectID.Trim()!="")
  158. {
  159. if(UDS.Components.Role.AddStaffFromRole(RoleID,selectID)!=0)
  160. {
  161. UDS.Components.Error.Log("加入角色出错!");
  162. Response.Redirect("../Error.aspx");
  163. }
  164. else
  165. Response.Redirect("ListView.aspx?Role_ID="+RoleID.ToString()+"&DisplayType="+DisplayType.ToString());
  166. }
  167. else
  168. Response.Write("<script language='javascript'>alert('请选择要脱离的人员');</script>");
  169. }
  170. }
  171. }