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

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
  14. {
  15. /// <summary>
  16. /// MemberListView 的摘要说明。
  17. /// </summary>
  18. public class MemberListView : System.Web.UI.Page
  19. {
  20. protected HttpCookie UserCookie;
  21. protected static string Username;
  22. protected static string ClassID;
  23. protected System.Web.UI.WebControls.DataGrid dgMemberList;
  24. protected System.Web.UI.WebControls.Label lblStaff_Name;
  25. protected System.Web.UI.WebControls.Label lblRealName;
  26. protected System.Web.UI.WebControls.Label lblSex;
  27. protected System.Web.UI.WebControls.Label lblEmail;
  28. protected System.Web.UI.WebControls.Label lblRegistedDate;
  29. protected System.Web.UI.HtmlControls.HtmlForm DisplayStaffInfo;
  30. protected System.Web.UI.WebControls.Button cmdDelete;
  31. protected System.Web.UI.WebControls.Button btnLeader;
  32. protected System.Web.UI.WebControls.Button btnAdd;
  33. protected System.Web.UI.WebControls.CheckBox cbRemind;
  34. protected static string DisplayType="";
  35. private void Page_Load(object sender, System.EventArgs e)
  36. {
  37. ClassID  = (Request.QueryString["TeamID"]!=null)?Request.QueryString["TeamID"].ToString():"";
  38. DisplayType  = (Request.QueryString["DisplayType"]!=null)?Request.QueryString["DisplayType"].ToString():"0";
  39. UserCookie  = Request.Cookies["Username"];
  40. Username  = UserCookie.Value.ToString();
  41. if(!IsPostBack)
  42. {
  43. BindGrid();
  44. }
  45. }
  46. #region 数据绑定至DataGrid
  47. /// <summary>
  48. /// 将某用户的邮件取出绑定至DataGrid
  49. /// </summary>
  50. protected void BindGrid() 
  51. {   
  52. Team team   = new Team();
  53. DataTable datatable   = new DataTable();
  54. switch (DisplayType) {
  55. case "0":
  56. datatable =  Tools.ConvertDataReaderToDataTable(team.GetStaffInTeam(Int32.Parse(ClassID)));
  57. this.btnAdd.Visible    = false;
  58. this.cmdDelete.Visible = true;
  59. this.btnLeader.Visible = true;
  60. break;
  61. case "1":
  62. datatable =  Tools.ConvertDataReaderToDataTable(team.GetStaffNotInTeam(Int32.Parse(ClassID)));
  63. this.btnAdd.Visible    = true;
  64. this.cmdDelete.Visible = false;
  65. this.btnLeader.Visible = false;
  66. this.dgMemberList.Columns.Remove(this.dgMemberList .Columns[3]);
  67. break;
  68. case "2":
  69. datatable =  Tools.ConvertDataReaderToDataTable(team.GetStaffSubscriptionTeam(Int32.Parse(ClassID)));
  70. this.btnAdd.Visible    = false;
  71. this.cmdDelete.Visible = false;
  72. this.btnLeader.Visible = false;
  73. this.dgMemberList.Columns.Remove(this.dgMemberList .Columns[3]);
  74. break;
  75. default:
  76. break;
  77. }
  78. dgMemberList.DataSource   = datatable.DefaultView;
  79. dgMemberList.DataBind(); 
  80. if (datatable.Rows.Count !=0)
  81. {
  82. this.cmdDelete.Attributes ["onclick"]="javascript:return confirm('您确认要选中的人员脱离组吗?');";
  83. this.btnLeader.Attributes ["onclick"]="javascript:return confirm('您确认要选中的人员设置为组长吗?');";
  84. this.btnAdd.Attributes ["onclick"]   ="javascript:return confirm('您确认要加入该成员吗?');";
  85. }
  86. team   = null;
  87. datatable = null;
  88. #endregion
  89. #region 翻页事件
  90. public void DataGrid_PageChanged(object sender,DataGridPageChangedEventArgs e)
  91. {
  92. dgMemberList.CurrentPageIndex = e.NewPageIndex;
  93. BindGrid();
  94. }
  95. #endregion
  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.cmdDelete.Click += new System.EventHandler(this.cmdDelete_Click);
  112. this.btnLeader.Click += new System.EventHandler(this.btnLeader_Click);
  113. this.btnAdd.Click += new System.EventHandler(this.btnAdd_Click);
  114. this.Load += new System.EventHandler(this.Page_Load);
  115. }
  116. #endregion
  117. #region 小组成员变化的消息通知函数 i为0表示脱离组,i为1表示加入组,i为2表示成为组长
  118. private void sms_all(int ii)
  119. {
  120. string sql   = "";//所被选择的成员ID集合
  121. bool sqlFlag   = true;
  122. foreach(DataGridItem dgi in this.dgMemberList.Items)
  123. {
  124. CheckBox cb=(CheckBox)(dgi.Cells[0].Controls[1]);
  125. if (cb.Checked==true)
  126. {
  127. int i = dgi.ItemIndex;
  128. string id = dgMemberList.DataKeys[i].ToString();
  129. if (sqlFlag)
  130. {
  131. sql+=""+id;
  132. sqlFlag=false;
  133. }
  134. else
  135. {
  136. sql+=" ,";
  137. sql+=id;
  138. }
  139. }
  140. }
  141. SqlDataReader dr_this;//被选择人员
  142. UDS.Components.Staff sta=new UDS.Components.Staff();
  143. dr_this=sta.GetStaffInfo(sql);
  144. SqlDataReader dr_allTeam;//所有组员
  145. Team steam=new Team();
  146. dr_allTeam=steam.GetStaffInTeam(Convert.ToInt32(ClassID));
  147. SqlDataReader dr_allTeamMaster;//所有组长
  148. ProjectClass prj=new ProjectClass();
  149. dr_allTeamMaster=prj.GetLeader(Convert.ToInt32(ClassID));
  150. SqlDataReader dataReader;//项目信息
  151. dataReader = prj.GetClassInfo(Convert.ToInt32(ClassID));
  152. string Team_name="";//项目名字
  153. if(dataReader.Read())
  154. {
  155. Team_name=dataReader[0].ToString()+",";
  156. }
  157. dataReader.Close();
  158. dataReader=null;
  159.   
  160. string Staff_name="";//被选择人员名字
  161. while(dr_this.Read())
  162. {
  163. Staff_name+=dr_this["RealName"].ToString()+",";
  164. }
  165. dr_this.Close();
  166. dr_this=null;
  167. string name_teamMaster="";//所有组长的名字
  168. while(dr_allTeamMaster.Read())
  169. {
  170. name_teamMaster+=dr_allTeamMaster["RealName"].ToString()+",";
  171. }
  172. dr_allTeamMaster.Close();
  173. dr_allTeamMaster=null;
  174. SMS sm = new SMS();
  175. //处理短信提醒
  176. while(dr_allTeam.Read())//i为0表示脱离组,i为1表示加入组,i为2表示成为组长
  177. {
  178. if(ii==0)
  179. sm.SendMsg(Username,dr_allTeam["Staff_name"].ToString(),Team_name+" 项目处员工:"+Staff_name+"已经脱离本项目,特此通知.",1,DateTime.Now,"",0,0);
  180. else if(ii==1)
  181. sm.SendMsg(Username,dr_allTeam["Staff_name"].ToString(),"员工:"+Staff_name+"已经加入项目:"+Team_name+",特此通知.",1,DateTime.Now,"",0,0);
  182. else if(ii==2)
  183. sm.SendMsg(Username,dr_allTeam["Staff_name"].ToString(),Team_name+" 项目处员工:"+Staff_name+"已经替代"+name_teamMaster+",成为项目组长,特此通知.",1,DateTime.Now,"",0,0);
  184. }
  185. sm = null;
  186. dr_allTeam.Close();
  187. dr_allTeam=null;
  188. }
  189. #endregion
  190. #region 设置组长
  191. private void lnkbtnLeader_Click(object sender, System.EventArgs e)
  192. {
  193. }
  194. #endregion
  195. #region 加入成员至组
  196. private void lnkbtnAdd_Click(object sender, System.EventArgs e)
  197. {
  198. }
  199. #endregion
  200. #region 人员脱离
  201. private void cmdDelete_Click(object sender, System.EventArgs e)
  202. {
  203. Team team   = new Team();
  204. bool sqlFlag   = true;
  205. string sql   = "";
  206. foreach(DataGridItem dgi in this.dgMemberList.Items)
  207. {
  208. CheckBox cb=(CheckBox)(dgi.Cells[0].Controls[1]);
  209. if (cb.Checked==true)
  210. {
  211. int i = dgi.ItemIndex;
  212. string id = dgMemberList.DataKeys[i].ToString();
  213. if (sqlFlag)
  214. {
  215. sql+=""+id;
  216. sqlFlag=false;
  217. }
  218. else
  219. {
  220. sql+=" ,";
  221. sql+=id;
  222. }
  223. }
  224. }
  225. //选择为空
  226. if( sql==String.Empty)
  227. {
  228. Response.Write("<script language=javascript>alert('请选择人员!');window.location='MemberListView.aspx?TeamID="+ClassID+"';</script>");
  229. }
  230. else
  231. {
  232. if(this.cbRemind.Checked==true)
  233. sms_all(0);
  234. if(team.DeleteStaffFromTeam(sql,Int32.Parse(ClassID)))
  235. {
  236. Response.Write("<script language=javascript>alert('人员脱离成功!');window.location='MemberListView.aspx?TeamID="+ClassID+"';</script>");
  237. }
  238. else
  239. {
  240. Server.Transfer("../Error.aspx");
  241. }
  242. }
  243. team=null;
  244. }
  245. #endregion
  246. private void btnLeader_Click(object sender, System.EventArgs e)
  247. {
  248. Team team   = new Team();
  249. bool sqlFlag   = true;
  250. string sql   = "";
  251. foreach(DataGridItem dgi in this.dgMemberList.Items)
  252. {
  253. CheckBox cb=(CheckBox)(dgi.Cells[0].Controls[1]);
  254. if (cb.Checked==true)
  255. {
  256. int i = dgi.ItemIndex;
  257. string id = dgMemberList.DataKeys[i].ToString();
  258. if (sqlFlag)
  259. {
  260. sql+=""+id;
  261. sqlFlag=false;
  262. }
  263. else
  264. {
  265. sql+=" ,";
  266. sql+=id;
  267. }
  268. }
  269. }
  270. //选择为空
  271. if( sql==String.Empty)
  272. {
  273. Response.Write("<script language=javascript>alert('请选择人员!');window.location='MemberListView.aspx?TeamID="+ClassID+"';</script>");
  274. }
  275. else
  276. {
  277. if(this.cbRemind.Checked==true)
  278. sms_all(2);
  279. if(team.SetLeader(sql,Int32.Parse(ClassID)))
  280. {
  281. Response.Write("<script language=javascript>alert('设置组长成功!');window.location='MemberListView.aspx?TeamID="+ClassID+"';</script>");
  282. }
  283. else
  284. {
  285. Server.Transfer("../Error.aspx");
  286. }
  287. }
  288. team=null;
  289. }
  290. private void btnAdd_Click(object sender, System.EventArgs e)
  291. {
  292. Team team   = new Team();
  293. bool sqlFlag   = true;
  294. string sql   = "";
  295. foreach(DataGridItem dgi in this.dgMemberList.Items)
  296. {
  297. CheckBox cb=(CheckBox)(dgi.Cells[0].Controls[1]);
  298. if (cb.Checked==true)
  299. {
  300. int i = dgi.ItemIndex;
  301. string id = dgMemberList.DataKeys[i].ToString();
  302. if (sqlFlag)
  303. {
  304. sql+=""+id;
  305. sqlFlag=false;
  306. }
  307. else
  308. {
  309. sql+=" ,";
  310. sql+=id;
  311. }
  312. }
  313. }
  314. //选择为空
  315. if( sql==String.Empty)
  316. {
  317. Response.Write("<script language=javascript>alert('请选择人员!');window.location='MemberListView.aspx?TeamID="+ClassID+"';</script>");
  318. }
  319. else
  320. {
  321. if(team.AddMemberToTeam(sql,Int32.Parse(ClassID)))
  322. {
  323. if(this.cbRemind.Checked==true)
  324. sms_all(1);
  325. Response.Write("<script language=javascript>alert('加入成员至组成功!');window.location='MemberListView.aspx?TeamID="+ClassID+"';</script>");
  326. }
  327. else
  328. {
  329. Server.Transfer("../Error.aspx");
  330. }
  331. }
  332. team=null;
  333. }
  334. }
  335. }