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

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_mult : System.Web.UI.Page
  13. {
  14.     protected void Page_Load(object sender, EventArgs e)
  15.     {
  16.         if (!IsPostBack)
  17.         {
  18.             this.DepartmentBind();
  19.             this.DepartmentSelectedBind();
  20.         }
  21.     }
  22.     protected void DepartmentBind()
  23.     {
  24.         if (Request.QueryString["department_id"] != null)
  25.         {
  26.             SqlConnection conn = dbConnection.getConnection();
  27.             conn.Open();
  28.             SqlCommand cmd = new SqlCommand("select id, code, name from OA_DEPARTMENT where last_id=" +
  29.                 Request.QueryString["department_id"] + " order by sequence, code", conn);
  30.             SqlDataReader dr = cmd.ExecuteReader();
  31.             while (dr.Read())
  32.             {
  33.                 ListItem item = new ListItem();
  34.                 item.Value = dr["id"].ToString();
  35.                 item.Text = dr["code"].ToString() + dr["name"].ToString();
  36.                 LbDepartment.Items.Add(item);
  37.             }
  38.             dr.Close();
  39.             conn.Close();
  40.         }
  41.     }
  42.     protected void DepartmentSelectedBind()
  43.     {
  44.         LbSelected.Items.Clear();
  45.         if (Session["departmentTexts"] != null && Session["departmentValues"] != null)
  46.         {
  47.             ArrayList departmentTexts = (ArrayList)Session["departmentTexts"];
  48.             ArrayList departmentValues = (ArrayList)Session["departmentValues"];
  49.             for (int i = 0; i < departmentTexts.Count; i++)
  50.             {
  51.                 ListItem item = new ListItem();
  52.                 item.Text = departmentTexts[i].ToString();
  53.                 item.Value = departmentValues[i].ToString();
  54.                 LbSelected.Items.Add(item);
  55.             }
  56.         }
  57.     }
  58.     protected void BtnAdd_Click(object sender, EventArgs e)
  59.     {
  60.         ArrayList departmentTexts = new ArrayList();
  61.         ArrayList departmentValues = new ArrayList();
  62.         if (Session["departmentTexts"] != null && Session["departmentValues"] != null)
  63.         {
  64.             departmentTexts = (ArrayList)Session["departmentTexts"];
  65.             departmentValues = (ArrayList)Session["departmentValues"];
  66.         }
  67.         foreach (ListItem item in LbDepartment.Items)
  68.         {
  69.             if (item.Selected)
  70.             {
  71.                 if (!departmentValues.Contains(item.Value))
  72.                 {
  73.                     departmentValues.Add(item.Value);
  74.                     departmentTexts.Add(item.Text);
  75.                 }
  76.             }
  77.         }
  78.         Session["departmentTexts"] = departmentTexts;
  79.         Session["departmentValues"] = departmentValues;
  80.         this.DepartmentSelectedBind();
  81.     }
  82.     protected void BtnDelete_Click(object sender, EventArgs e)
  83.     {
  84.         ArrayList departmentTexts = new ArrayList();
  85.         ArrayList departmentValues = new ArrayList();
  86.         if (Session["departmentTexts"] != null && Session["departmentValues"] != null)
  87.         {
  88.             departmentTexts = (ArrayList)Session["departmentTexts"];
  89.             departmentValues = (ArrayList)Session["departmentValues"];
  90.         }
  91.         foreach (ListItem item in LbSelected.Items)
  92.         {
  93.             if (item.Selected)
  94.             {
  95.                 if (departmentValues.Contains(item.Value))
  96.                 {
  97.                     departmentValues.Remove(item.Value);
  98.                     departmentTexts.Remove(item.Text);
  99.                 }
  100.             }
  101.         }
  102.         Session["departmentTexts"] = departmentTexts;
  103.         Session["departmentValues"] = departmentValues;
  104.         this.DepartmentSelectedBind();
  105.     }
  106.     protected void BtnAddAll_Click(object sender, EventArgs e)
  107.     {
  108.         ArrayList departmentTexts = new ArrayList();
  109.         ArrayList departmentValues = new ArrayList();
  110.         if (Session["departmentTexts"] != null && Session["departmentValues"] != null)
  111.         {
  112.             departmentTexts = (ArrayList)Session["departmentTexts"];
  113.             departmentValues = (ArrayList)Session["departmentValues"];
  114.         }
  115.         foreach (ListItem item in LbDepartment.Items)
  116.         {
  117.             if (!departmentValues.Contains(item.Value))
  118.             {
  119.                 departmentValues.Add(item.Value);
  120.                 departmentTexts.Add(item.Text);
  121.             }
  122.         }
  123.         Session["departmentTexts"] = departmentTexts;
  124.         Session["departmentValues"] = departmentValues;
  125.         this.DepartmentSelectedBind();
  126.     }
  127.     protected void BtnDeleteAll_Click(object sender, EventArgs e)
  128.     {
  129.         Session.Remove("departmentTexts");
  130.         Session.Remove("departmentValues");
  131.         this.DepartmentSelectedBind();
  132.     }
  133.     protected void BtnCancel_Click(object sender, EventArgs e)
  134.     {
  135.         Session.Remove("departmentTexts");
  136.         Session.Remove("departmentValues");
  137.         //關閉當前窗體
  138.         Response.Write("<script language='javascript'>window.parent.close();</script>");
  139.     }
  140. }