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

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. using UDS.Components;
  13. namespace UDS.SubModule.Position
  14. {
  15. /// <summary>
  16. /// ListView 的摘要说明。
  17. /// </summary>
  18. public class ListView : System.Web.UI.Page
  19. {
  20. public static int DisplayType = 0;
  21. public static string PositionID;
  22. protected static string Username;
  23. protected System.Web.UI.WebControls.DataGrid dbStaffList;
  24. protected System.Web.UI.WebControls.LinkButton lbOffLine;
  25. protected System.Web.UI.WebControls.LinkButton lbOnline;
  26. protected System.Web.UI.WebControls.Button cmdNewStaff;
  27. protected System.Web.UI.WebControls.Button cmdPositionOperate;
  28. protected System.Web.UI.WebControls.Button cmdSetRight;
  29. protected System.Web.UI.WebControls.Button cmdOffPosition;
  30. protected System.Web.UI.WebControls.Button cmdChangePosition;
  31. protected System.Web.UI.WebControls.Button cmdUpdateCaste;
  32. protected System.Web.UI.WebControls.CheckBox cbRemind;
  33. protected System.Web.UI.WebControls.Button cmdOnPosition;
  34. private void Page_Load(object sender, System.EventArgs e)
  35. {
  36. // 在此处放置用户代码以初始化页面
  37. if(!Page.IsPostBack)
  38. {
  39. //操作者登录名
  40. HttpCookie UserCookie = Request.Cookies["Username"];
  41. Username = UserCookie.Value.ToString();
  42. if (Request.QueryString["DisplayType"] != null)
  43. DisplayType = Int32.Parse( Request.QueryString["DisplayType"].ToString());
  44. if(DisplayType==0)
  45. {
  46. // lbOnline.BackColor = Color.FromArgb(0xCCCCCC);
  47. // lbOffLine.BackColor =Color.FromArgb(0xFFFFFF);
  48. cmdOnPosition.Visible =false;
  49. cmdOffPosition.Enabled =true;
  50. }
  51. else
  52. {
  53. // lbOnline.BackColor = Color.FromArgb(0xFFFFFF);
  54. // lbOffLine.BackColor =Color.FromArgb(0xCCCCCC);
  55. cmdOnPosition.Visible =true;
  56. cmdOffPosition.Visible =false;
  57. }
  58. if (Request.QueryString["Position_ID"] != null)
  59. PositionID = Request.QueryString["Position_ID"].ToString();
  60. else if (Request.QueryString["PositionID"] != null)
  61. PositionID = Request.QueryString["PositionID"].ToString();
  62. else
  63. PositionID = "1";
  64. //如果要求刷新部门树
  65. if(Request.QueryString["Refresh"] != null )
  66. {
  67. Response.Write("<script language='javascript'>parent.LeftFrame.location.reload();</script>");
  68. }
  69. cmdOnPosition.Attributes.Add("Onclick","javascript:return confirm('是否让选中的人复职?');");
  70. cmdOffPosition.Attributes.Add("Onclick","javascript:return confirm('是否让选中的人离职?');");
  71. BindGrid();
  72. }
  73. }
  74. #region 翻页事件
  75. public void DataGrid_PageChanged(object sender,DataGridPageChangedEventArgs e)
  76. {
  77. dbStaffList.CurrentPageIndex = e.NewPageIndex;
  78. BindGrid();
  79. }
  80. #endregion
  81. private void BindGrid()
  82. {
  83. SqlDataReader dr; //存放人物的数据
  84. Database db = new Database();
  85. SqlParameter[] prams = {
  86.    db.MakeInParam("@Position_ID",SqlDbType.Int,4,PositionID),
  87.    db.MakeInParam("@Dimission",SqlDbType.Bit,1,DisplayType)
  88.    };
  89. db.RunProc("sp_GetStaffInPosition",prams,out dr);
  90. DataTable dt =Tools.ConvertDataReaderToDataTable(dr);
  91. dbStaffList.DataSource = dt.DefaultView;
  92. dbStaffList.DataBind();
  93. }
  94. #region Web Form Designer generated code
  95. override protected void OnInit(EventArgs e)
  96. {
  97. //
  98. // CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
  99. //
  100. InitializeComponent();
  101. base.OnInit(e);
  102. }
  103. /// <summary>
  104. /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  105. /// 此方法的内容。
  106. /// </summary>
  107. private void InitializeComponent()
  108. {    
  109. this.lbOnline.Click += new System.EventHandler(this.lbOnline_Click);
  110. this.lbOffLine.Click += new System.EventHandler(this.lbOffLine_Click);
  111. this.cmdUpdateCaste.Click += new System.EventHandler(this.cmdUpdateCaste_Click);
  112. this.cmdNewStaff.Click += new System.EventHandler(this.cmdNewStaff_Click);
  113. this.cmdPositionOperate.Click += new System.EventHandler(this.cmdPositionOperate_Click);
  114. this.cmdSetRight.Click += new System.EventHandler(this.cmdSetRight_Click);
  115. this.cmdOnPosition.Click += new System.EventHandler(this.cmdOnPosition_Click);
  116. this.cmdOffPosition.Click += new System.EventHandler(this.cmdOffPosition_Click);
  117. this.cmdChangePosition.Click += new System.EventHandler(this.cmdChangePosition_Click);
  118. this.Load += new System.EventHandler(this.Page_Load);
  119. }
  120. #endregion
  121. private string GetSelectedItemID(string controlID)
  122. {
  123. String selectedID;
  124. selectedID = "";
  125. //遍历DataGrid获得checked的ID
  126. foreach (DataGridItem item in dbStaffList.Items)
  127. {
  128. if(((CheckBox)item.FindControl(controlID)).Checked==true )
  129. selectedID += dbStaffList.DataKeys[item.ItemIndex] + ",";
  130. }
  131. if(selectedID.Length>0)
  132. selectedID=selectedID.Substring(0,selectedID.Length-1);
  133. return selectedID;
  134. }
  135. private void lbOffLine_Click(object sender, System.EventArgs e)
  136. {
  137. Server.Transfer("Listview.aspx?PositionID=" + PositionID.ToString() + "&DisplayType=1");
  138. }
  139. private void lbOnline_Click(object sender, System.EventArgs e)
  140. {
  141. Server.Transfer("Listview.aspx?PositionID=" + PositionID.ToString() + "&DisplayType=0");
  142. }
  143. private void cmdNewStaff_Click(object sender, System.EventArgs e)
  144. {
  145. Server.Transfer("NewStaff.aspx?PositionID=" + PositionID.ToString() + "&DisplayType =0");
  146. }
  147. private void cmdPositionOperate_Click(object sender, System.EventArgs e)
  148. {
  149. Server.Transfer("OPosition.aspx?PositionID=" + PositionID.ToString());
  150. }
  151. private void cmdSetRight_Click(object sender, System.EventArgs e)
  152. {
  153. Server.Transfer("../AssignRule/RightListview.aspx?ObjID=" + PositionID.ToString() + "&displayType=0");
  154. }
  155. //离职,复职通知
  156. private void sms_all(int i)
  157. {
  158. string strStaffID=this.GetSelectedItemID("Staff_ID");
  159. SqlDataReader dr_this;//被选择人员
  160. UDS.Components.Staff sta=new UDS.Components.Staff();
  161. dr_this=sta.GetStaffInfo(strStaffID);
  162. SMS sm = new SMS();
  163. //处理短信提醒
  164. while(dr_this.Read())
  165. {
  166. string Position_name=dr_this["Position_name"].ToString();
  167. SqlDataReader dr_isok;//所有在职人员
  168. dr_isok=sta.GetAllStaffs();
  169. while(dr_isok.Read())
  170. {
  171. string Staff_name=dr_isok["Staff_name"].ToString();
  172. if(i==0)
  173. sm.SendMsg(Username,Staff_name,Position_name+" 处员工:"+dr_this["RealName"].ToString()+",已经离职,特此通知.",1,DateTime.Now,"",0,0);
  174. else
  175. sm.SendMsg(Username,dr_isok["Staff_name"].ToString(),dr_this["Position_name"].ToString()+" 处员工:"+dr_this["RealName"].ToString()+",已经恢复原职,特此通知.",1,DateTime.Now,"",0,0);
  176. }
  177. dr_isok.Close();
  178. dr_isok=null;
  179. }
  180. sm = null;
  181. dr_this.Close();
  182. dr_this=null;
  183. }
  184. private void cmdOnPosition_Click(object sender, System.EventArgs e)
  185. {
  186. string selectedID = GetSelectedItemID("Staff_ID");
  187. UDS.Components.Database db = new UDS.Components.Database();
  188. if(selectedID.Trim()!="")
  189. {
  190. SqlParameter[] prams = {
  191.    db.MakeInParam("@StaffIDS",SqlDbType.VarChar,300,selectedID)
  192.    };
  193. db.RunProc("sp_StaffRehab",prams);
  194. if(this.cbRemind.Checked==true)
  195. sms_all(1);
  196. }
  197. Response.Redirect("Listview.aspx?PositionID="+PositionID+"&displayType="+DisplayType.ToString());
  198. }
  199. private void cmdOffPosition_Click(object sender, System.EventArgs e)
  200. {
  201. string selectedID = GetSelectedItemID("Staff_ID");
  202. if(selectedID!="")
  203. {
  204. UDS.Components.Staff person = new UDS.Components.Staff();
  205. if(person.Dimission(selectedID)==true)
  206. {
  207. if(this.cbRemind.Checked==true)
  208. sms_all(0);
  209. //Response.Write("<script language=javascript>alert('离职成功!');</script>");
  210. BindGrid();
  211. }
  212. person = null;
  213. }
  214. else
  215. Response.Write("<script language=javascript>alert('请选择要离职的人员!');</script>");
  216. }
  217. private void cmdChangePosition_Click(object sender, System.EventArgs e)
  218. {
  219. string selectedID = GetSelectedItemID("Staff_ID");
  220. if(selectedID.Trim()!="")
  221. Response.Redirect("ChangePosition.aspx?PositionID="+PositionID+"&StaffIDS="+selectedID+"&DisplayType="+DisplayType.ToString()+"&BackFilePath="+Request.CurrentExecutionFilePath);
  222. else
  223. Response.Write("<script language=javascript>alert('请选择要调职的人员!');</script>");
  224. }
  225. private void cmdUpdateCaste_Click(object sender, System.EventArgs e)
  226. {
  227. Server.Transfer("UpdateCaste.aspx?PositionID=" + PositionID.ToString());
  228. }
  229. }
  230. }