ListView.aspx.cs
上传用户:xgw_05
上传日期:2009-12-11
资源大小:20208k
文件大小:10k
源码类别:

OA系统

开发平台:

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.Linkman
  13. {
  14. /// <summary>
  15. /// ListView 的摘要说明。
  16. /// </summary>
  17. public class ListView : System.Web.UI.Page
  18. {
  19. protected System.Web.UI.WebControls.LinkButton lbtn_Staff;
  20. protected System.Web.UI.WebControls.LinkButton lbtn_Client;
  21. protected System.Web.UI.WebControls.LinkButton lbtn_Custom;
  22. protected System.Web.UI.WebControls.HyperLink lbtn_AddLinkman;
  23. protected System.Web.UI.WebControls.DataGrid dgrd_StaffLinkman;
  24. protected System.Web.UI.WebControls.DataGrid dgrd_ClientLinkman;
  25. protected System.Web.UI.WebControls.DataGrid dgrd_CustomLinkman;
  26. protected System.Web.UI.WebControls.Button btn_Del;
  27. protected System.Web.UI.WebControls.DropDownList ddl_CustomLinkmanType;
  28. protected System.Web.UI.HtmlControls.HtmlTableCell td_Staff;
  29. protected System.Web.UI.HtmlControls.HtmlTableCell td_Client;
  30. protected System.Web.UI.HtmlControls.HtmlTableCell td_Custom;
  31. protected System.Web.UI.HtmlControls.HtmlTableCell td_Add;
  32. private int userid = 0;
  33. private void Page_Load(object sender, System.EventArgs e)
  34. {
  35. userid = Int32.Parse(Request.Cookies["UserID"].Value);
  36. if(!Page.IsPostBack)
  37. {
  38. Session["cm_permission"] = "administrator";
  39. int type = (Request.QueryString["type"]==null)?1:Int32.Parse(Request.QueryString["type"]);
  40. GridBind(type);
  41. }
  42. }
  43. private void GridBind(int type)
  44. {
  45. UDS.Components.MyLinkman linkman = new UDS.Components.MyLinkman();
  46. SqlDataReader dr_linkman = linkman.GetMyLinkman(type,userid);
  47. DataTable dt_linkman = UDS.Components.Tools.ConvertDataReaderToDataTable(dr_linkman);
  48. dt_linkman.TableName = "Linkman";
  49. DataSet ds = new DataSet();
  50. ds.Tables.Add(dt_linkman);
  51. switch(type)
  52. {
  53. case 1:
  54. dgrd_StaffLinkman.Visible = true;
  55. dgrd_ClientLinkman.Visible = false;
  56. dgrd_CustomLinkman.Visible = false;
  57. td_Staff.Attributes["background"]= "../../images/maillistbutton2.gif";
  58. td_Client.Attributes["background"]= "../../images/maillistbutton1.gif";
  59. td_Custom.Attributes["background"]= "../../images/maillistbutton1.gif";
  60. dgrd_StaffLinkman.DataSource = dt_linkman.DefaultView;
  61. dgrd_StaffLinkman.DataKeyField = "Staff_ID";
  62. dgrd_StaffLinkman.DataBind();
  63. break;
  64. case 2:
  65. dgrd_StaffLinkman.Visible = false;
  66. dgrd_ClientLinkman.Visible = true;
  67. dgrd_CustomLinkman.Visible = false;
  68. td_Staff.Attributes["background"]= "../../images/maillistbutton1.gif";
  69. td_Client.Attributes["background"]= "../../images/maillistbutton2.gif";
  70. td_Custom.Attributes["background"]= "../../images/maillistbutton1.gif";
  71. dgrd_ClientLinkman.DataSource = dt_linkman.DefaultView;
  72. dgrd_ClientLinkman.DataKeyField = "ID";
  73. dgrd_ClientLinkman.DataBind();
  74. break;
  75. case 3:
  76. dgrd_StaffLinkman.Visible = false;
  77. dgrd_ClientLinkman.Visible = false;
  78. dgrd_CustomLinkman.Visible = true;
  79. td_Staff.Attributes["background"]= "../../images/maillistbutton1.gif";
  80. td_Client.Attributes["background"]= "../../images/maillistbutton1.gif";
  81. td_Custom.Attributes["background"]= "../../images/maillistbutton2.gif";
  82. dgrd_CustomLinkman.DataSource = dt_linkman.DefaultView;
  83. dgrd_CustomLinkman.DataKeyField = "ID";
  84. dgrd_CustomLinkman.DataBind();
  85. break;
  86. }
  87. }
  88. private void GridCustomLinkmanByType(int type)
  89. {
  90. UDS.Components.MyLinkman linkman = new UDS.Components.MyLinkman();
  91. SqlDataReader dr_linkman = linkman.GetCustomLinkmanByType(type,userid);
  92. DataTable dt_linkman = UDS.Components.Tools.ConvertDataReaderToDataTable(dr_linkman);
  93. dgrd_CustomLinkman.DataSource = dt_linkman.DefaultView;
  94. dgrd_CustomLinkman.DataBind();
  95. }
  96. #region Web Form Designer generated code
  97. override protected void OnInit(EventArgs e)
  98. {
  99. //
  100. // CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
  101. //
  102. InitializeComponent();
  103. base.OnInit(e);
  104. }
  105. /// <summary>
  106. /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  107. /// 此方法的内容。
  108. /// </summary>
  109. private void InitializeComponent()
  110. {    
  111. this.ddl_CustomLinkmanType.SelectedIndexChanged += new System.EventHandler(this.ddl_CustomLinkmanType_SelectedIndexChanged);
  112. this.btn_Del.Click += new System.EventHandler(this.btn_Del_Click);
  113. this.lbtn_Staff.Click += new System.EventHandler(this.lbtn_Click);
  114. this.lbtn_Client.Click += new System.EventHandler(this.lbtn_Click);
  115. this.lbtn_Custom.Click += new System.EventHandler(this.lbtn_Click);
  116. this.dgrd_CustomLinkman.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.dgrd_CustomLinkman_PageIndexChanged);
  117. this.dgrd_ClientLinkman.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.dgrd_ClientLinkman_PageIndexChanged);
  118. this.dgrd_StaffLinkman.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.dgrd_StaffLinkman_PageIndexChanged);
  119. this.Load += new System.EventHandler(this.Page_Load);
  120. }
  121. #endregion
  122. private void lbtn_Click(object sender, System.EventArgs e)
  123. {
  124. if(((Control)sender).ID=="lbtn_Custom")
  125. ddl_CustomLinkmanType.Visible = true;
  126. else
  127. ddl_CustomLinkmanType.Visible = false;
  128. BindTypeList();
  129. GridBind(Int32.Parse(((LinkButton)sender).CommandArgument));
  130. switch(Int32.Parse(((LinkButton)sender).CommandArgument))
  131. {
  132. case 1:
  133. dgrd_StaffLinkman.Visible = true;
  134. dgrd_ClientLinkman.Visible = false;
  135. dgrd_CustomLinkman.Visible = false;
  136. break;
  137. case 2:
  138. dgrd_StaffLinkman.Visible = false;
  139. dgrd_ClientLinkman.Visible = true;
  140. dgrd_CustomLinkman.Visible = false;
  141. break;
  142. case 3:
  143. dgrd_StaffLinkman.Visible = false;
  144. dgrd_ClientLinkman.Visible = false;
  145. dgrd_CustomLinkman.Visible = true;
  146. break;
  147. }
  148. }
  149. private void btn_Del_Click(object sender, System.EventArgs e)
  150. {
  151. string selectedstring = "";
  152. int type = 0;
  153. UDS.Components.MyLinkman mlinkman = new UDS.Components.MyLinkman();
  154. if(dgrd_StaffLinkman.Visible==true)
  155. {
  156. type = 1;
  157. //得到选中的checkbox的id
  158. foreach(DataGridItem dgi in dgrd_StaffLinkman.Items)//找到checkbox control
  159. {
  160. for(int i=0;i<dgi.Cells[0].Controls.Count;i++)
  161. {
  162. if((dgi.Cells[0].Controls[i].GetType().ToString()=="System.Web.UI.WebControls.CheckBox")&&((CheckBox)dgi.Cells[0].Controls[i]).Checked==true)
  163. {
  164. selectedstring += dgrd_StaffLinkman.DataKeys[dgi.ItemIndex] + ",";
  165. }
  166. }
  167. }
  168. }
  169. else if(dgrd_ClientLinkman.Visible==true)
  170. {
  171. type = 2;
  172. foreach(DataGridItem dgi in dgrd_ClientLinkman.Items)//找到checkbox control
  173. {
  174. for(int i=0;i<dgi.Cells[0].Controls.Count;i++)
  175. {
  176. if((dgi.Cells[0].Controls[i].GetType().ToString()=="System.Web.UI.WebControls.CheckBox")&&((CheckBox)dgi.Cells[0].Controls[i]).Checked==true)
  177. {
  178. selectedstring += dgrd_ClientLinkman.DataKeys[dgi.ItemIndex] + ",";
  179. }
  180. }
  181. }
  182. }
  183. else if(dgrd_CustomLinkman.Visible==true)
  184. {
  185. type = 3;
  186. foreach(DataGridItem dgi in dgrd_CustomLinkman.Items)//找到checkbox control
  187. {
  188. for(int i=0;i<dgi.Cells[0].Controls.Count;i++)
  189. {
  190. if((dgi.Cells[0].Controls[i].GetType().ToString()=="System.Web.UI.WebControls.CheckBox")&&((CheckBox)dgi.Cells[0].Controls[i]).Checked==true)
  191. {
  192. selectedstring += dgrd_CustomLinkman.DataKeys[dgi.ItemIndex] + ",";
  193. }
  194. }
  195. }
  196. }
  197. if(selectedstring.IndexOf(",")!=-1)
  198. {
  199. selectedstring = selectedstring.Substring(0,selectedstring.Length-1);
  200. string[] arrselected = selectedstring.Split(',');
  201. for(int i=0;i<arrselected.Length;i++)
  202. {
  203. if(arrselected[i].Trim()!="")
  204. {
  205. mlinkman.DelLinkmanFromList(type,Int32.Parse(arrselected[i]));
  206. }
  207. }
  208. GridBind(type);
  209. }
  210. }
  211. //bound to customlinkmantype
  212. private void BindTypeList()
  213. {
  214. UDS.Components.MyLinkman mylinkman = new UDS.Components.MyLinkman();
  215. ddl_CustomLinkmanType.DataSource = mylinkman.GetCustomLinkmanType();
  216. ddl_CustomLinkmanType.DataValueField = "ID";
  217. ddl_CustomLinkmanType.DataTextField = "type";
  218. ddl_CustomLinkmanType.DataBind();
  219. ddl_CustomLinkmanType.Items.Insert(0,new ListItem("全部","all"));
  220. }
  221. private void dgrd_StaffLinkman_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
  222. {
  223. ((DataGrid)source).CurrentPageIndex = e.NewPageIndex;
  224. GridBind(1);
  225. }
  226. private void dgrd_ClientLinkman_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
  227. {
  228. ((DataGrid)source).CurrentPageIndex = e.NewPageIndex;
  229. GridBind(2);
  230. }
  231. private void dgrd_CustomLinkman_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
  232. {
  233. ((DataGrid)source).CurrentPageIndex = e.NewPageIndex;
  234. if(ddl_CustomLinkmanType.SelectedItem.Value=="all")
  235. GridBind(3);
  236. else
  237. GridCustomLinkmanByType(Int32.Parse(ddl_CustomLinkmanType.SelectedItem.Value));
  238. }
  239. private void ddl_CustomLinkmanType_SelectedIndexChanged(object sender, System.EventArgs e)
  240. {
  241. dgrd_CustomLinkman.CurrentPageIndex = 0;
  242. if(((DropDownList)sender).SelectedItem.Value!="all")
  243. GridCustomLinkmanByType(Int32.Parse(ddl_CustomLinkmanType.SelectedItem.Value));
  244. else
  245. GridBind(3);
  246. }
  247. }
  248. }