employee_select.aspx.cs
上传用户:xrffrp
上传日期:2022-03-25
资源大小:22155k
文件大小:6k
源码类别:

OA系统

开发平台:

ASP/ASPX

  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.Collections;
  5. using System.Web;
  6. using System.Web.Security;
  7. using System.Web.UI;
  8. using System.Web.UI.WebControls;
  9. using System.Web.UI.WebControls.WebParts;
  10. using System.Web.UI.HtmlControls;
  11. using System.Data.SqlClient;
  12. public partial class web_personnel_department_department_select : System.Web.UI.Page
  13. {
  14.     protected void Page_Load(object sender, EventArgs e)
  15.     {
  16.         if (!IsPostBack)
  17.         {
  18.             this.ListEmployeeBind();
  19.             this.ListSelectedBind();
  20.         }
  21.     }
  22.     //ListEmployee綁定
  23.     protected void ListEmployeeBind()
  24.     {
  25.         SqlConnection conn = dbConnection.getConnection();
  26.         conn.Open();
  27.         string department_id = "0";
  28.         if (Request.QueryString["department_id"] != null)
  29.         {
  30.             department_id = Request.QueryString["department_id"];
  31.         }
  32.         string sql = "select e.id, e.emp_no, e.emp_name, p.name as position from " +
  33.             "OA_EMPLOYEE e inner join OA_EMPLOYEE_POSITION p on e.position=p.id where is_del='N'" +
  34.             " and department_id=" + department_id + " and dimission_date=''";
  35.         SqlCommand cmd = new SqlCommand(sql, conn);
  36.         try
  37.         {
  38.             SqlDataReader dr = cmd.ExecuteReader();
  39.             while (dr.Read())
  40.             {
  41.                 ListItem item = new ListItem();
  42.                 item.Value = dr["id"].ToString();
  43.                 item.Text = dr["emp_no"].ToString() + " " + dr["emp_name"].ToString() + " " + dr["position"].ToString();
  44.                 ListEmployee.Items.Add(item);
  45.             }
  46.             dr.Close();
  47.         }
  48.         catch (Exception ex)
  49.         {
  50.             Response.Write(ex.Message);
  51.         }
  52.         conn.Close();
  53.     }
  54.     protected void BtnAdd_Click(object sender, EventArgs e)
  55.     {
  56.         ArrayList employeeValueList = new ArrayList();
  57.         ArrayList employeeTextList = new ArrayList();
  58.         if (Session["employeeValue"] != null)
  59.         {
  60.             employeeValueList = (ArrayList)Session["employeeValue"];
  61.         }
  62.         if (Session["employeeText"] != null)
  63.         {
  64.             employeeTextList = (ArrayList)Session["employeeText"];
  65.         }
  66.         foreach (ListItem item in ListEmployee.Items)
  67.         {
  68.             if (item.Selected)
  69.             {
  70.                 if (!employeeValueList.Contains(item.Value))
  71.                 {
  72.                     employeeValueList.Add(item.Value);
  73.                     employeeTextList.Add(item.Text);
  74.                 }
  75.             }
  76.         }
  77.         Session["employeeText"] = employeeTextList;
  78.         Session["employeeValue"] = employeeValueList;
  79.         this.ListSelectedBind();
  80.     }
  81.     //ListSelected 綁定
  82.     protected void ListSelectedBind()
  83.     {
  84.         ListSelected.Items.Clear();
  85.         ArrayList employeeValueList = new ArrayList();
  86.         ArrayList employeeTextList = new ArrayList();
  87.         if (Session["employeeValue"] != null)
  88.         {
  89.             employeeValueList = (ArrayList)Session["employeeValue"];
  90.         }
  91.         if (Session["employeeText"] != null)
  92.         {
  93.             employeeTextList = (ArrayList)Session["employeeText"];
  94.         }
  95.         for (int i = 0; i < employeeValueList.Count; i++)
  96.         {
  97.             ListItem item = new ListItem();
  98.             item.Text = employeeTextList[i].ToString();
  99.             item.Value = employeeValueList[i].ToString();
  100.             ListSelected.Items.Add(item);
  101.         }
  102.     }
  103.     protected void BtnDelete_Click(object sender, EventArgs e)
  104.     {
  105.         ArrayList employeeValueList = new ArrayList();
  106.         ArrayList employeeTextList = new ArrayList();
  107.         if (Session["employeeValue"] != null)
  108.         {
  109.             employeeValueList = (ArrayList)Session["employeeValue"];
  110.         }
  111.         if (Session["employeeText"] != null)
  112.         {
  113.             employeeTextList = (ArrayList)Session["employeeText"];
  114.         }
  115.         if (employeeValueList.Count > 0)
  116.         {
  117.             foreach (ListItem item in ListSelected.Items)
  118.             {
  119.                 if (item.Selected)
  120.                 {
  121.                     employeeValueList.Remove(item.Value);
  122.                     employeeTextList.Remove(item.Text);
  123.                 }
  124.             }
  125.         }
  126.         Session["employeeText"] = employeeTextList;
  127.         Session["employeeValue"] = employeeValueList;
  128.         this.ListSelectedBind();
  129.     }
  130.     protected void BtnAddAll_Click(object sender, EventArgs e)
  131.     {
  132.         ArrayList employeeValueList = new ArrayList();
  133.         ArrayList employeeTextList = new ArrayList();
  134.         if (Session["employeeValue"] != null)
  135.         {
  136.             employeeValueList = (ArrayList)Session["employeeValue"];
  137.         }
  138.         if (Session["employeeText"] != null)
  139.         {
  140.             employeeTextList = (ArrayList)Session["employeeText"];
  141.         }
  142.         foreach (ListItem item in ListEmployee.Items)
  143.         {
  144.             if (!employeeValueList.Contains(item.Value))
  145.             {
  146.                 employeeValueList.Add(item.Value);
  147.                 employeeTextList.Add(item.Text);
  148.             }
  149.         }
  150.         Session["employeeText"] = employeeTextList;
  151.         Session["employeeValue"] = employeeValueList;
  152.         this.ListSelectedBind();
  153.     }
  154.     protected void BtnDeleteAll_Click(object sender, EventArgs e)
  155.     {
  156.         ArrayList employeeValueList = new ArrayList();
  157.         ArrayList employeeTextList = new ArrayList();
  158.         if (Session["employeeValue"] != null)
  159.         {
  160.             employeeValueList = (ArrayList)Session["employeeValue"];
  161.         }
  162.         if (Session["employeeText"] != null)
  163.         {
  164.             employeeTextList = (ArrayList)Session["employeeText"];
  165.         }
  166.         if (employeeValueList.Count > 0)
  167.         {
  168.             foreach (ListItem item in ListSelected.Items)
  169.             {
  170.                 employeeValueList.Remove(item.Value);
  171.                 employeeTextList.Remove(item.Text);
  172.             }
  173.         }
  174.         Session["employeeText"] = employeeTextList;
  175.         Session["employeeValue"] = employeeValueList;
  176.         this.ListSelectedBind();
  177.     }
  178.     protected void BtnCancel_Click(object sender, EventArgs e)
  179.     {
  180.         Session.Remove("employeeText");
  181.         Session.Remove("employeeValue");
  182.         //關閉當前窗體
  183.         Response.Write("<script language='javascript'>window.parent.close();</script>");
  184.     }
  185. }