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

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_chk : System.Web.UI.Page
  13. {
  14.     protected void Page_Load(object sender, EventArgs e)
  15.     {
  16.         if (!IsPostBack)
  17.         {
  18.             this.AddTable();
  19.         }
  20.     }
  21.     protected void AddTable()
  22.     {
  23.         SqlConnection conn = dbConnection.getConnection();
  24.         conn.Open();
  25.         ArrayList ids = new ArrayList();
  26.         ArrayList names = new ArrayList();
  27.         SqlCommand cmd = new SqlCommand("select id, code, name from OA_DEPARTMENT where last_id=1 order by sequence, code", conn);
  28.         SqlDataReader dr = cmd.ExecuteReader();
  29.         while (dr.Read())
  30.         {
  31.             ids.Add(dr["id"].ToString());
  32.             names.Add(dr["code"].ToString() + dr["name"].ToString());
  33.         }
  34.         dr.Close();
  35.         for (int i = 0; i < ids.Count; i++)
  36.         {
  37.             TableRow tr1 = new TableRow();
  38.             tr1.BorderWidth = Unit.Pixel(1);
  39.             TableCell td1 = new TableCell();
  40.             td1.Width = Unit.Pixel(150);
  41.             tr1.HorizontalAlign = HorizontalAlign.Left;
  42.             CheckBox cb = new CheckBox();
  43.             cb.ID = "chk" + ids[i].ToString();
  44.             cb.Text = names[i].ToString();
  45.             cb.InputAttributes["parent"] = "1";
  46.             cb.InputAttributes["value"] = ids[i].ToString();
  47.             cb.InputAttributes["onclick"] = "check(" + ids[i] + ")";
  48.             td1.Controls.Add(cb);
  49.             tr1.Cells.Add(td1);
  50.             td1.BorderWidth = Unit.Pixel(1);
  51.             ArrayList ids1 = new ArrayList();
  52.             ArrayList names1 = new ArrayList();
  53.             cmd = new SqlCommand("select id, code, name from OA_DEPARTMENT where last_id=" + ids[i] + " order by sequence, code", conn);
  54.             dr = cmd.ExecuteReader();
  55.             while (dr.Read())
  56.             {
  57.                 ids1.Add(dr["id"].ToString());
  58.                 names1.Add(dr["code"].ToString() + dr["name"].ToString());
  59.             }
  60.             dr.Close();
  61.             Table tb1 = new Table();
  62.             TableCell td2 = new TableCell();
  63.             td2.BorderWidth = Unit.Pixel(1);
  64.             td2.Width = Unit.Pixel(750);
  65.             for (int j = 0; j < ids1.Count; j++)
  66.             {
  67.                 TableRow tr2 = new TableRow();
  68.                 TableCell td3 = new TableCell();
  69.                 td3.BorderWidth = Unit.Pixel(1);
  70.                 td3.Width = Unit.Pixel(200);
  71.                 tr2.HorizontalAlign = HorizontalAlign.Left;
  72.                 cb = new CheckBox();
  73.                 cb.InputAttributes["parent"] = ids[i].ToString();
  74.                 cb.InputAttributes["value"] = ids1[j].ToString();
  75.                 cb.InputAttributes["onclick"] = "check(" + ids1[j] + ")";
  76.                 cb.ID = "chk" + ids1[j].ToString();
  77.                 cb.Text = names1[j].ToString();
  78.                 td3.Controls.Add(cb);
  79.                 tr2.Cells.Add(td3);
  80.                 ArrayList ids2 = new ArrayList();
  81.                 ArrayList names2 = new ArrayList();
  82.                 cmd = new SqlCommand("select id, code, name from OA_DEPARTMENT where last_id=" + ids1[j] + " order by sequence, code", conn);
  83.                 dr = cmd.ExecuteReader();
  84.                 while (dr.Read())
  85.                 {
  86.                     ids2.Add(dr["id"].ToString());
  87.                     names2.Add(dr["code"].ToString() + dr["name"].ToString());
  88.                 }
  89.                 dr.Close();
  90.                 Table tb2 = new Table();
  91.                 TableCell td5 = new TableCell();
  92.                 td5.BorderWidth = Unit.Pixel(1);
  93.                 td5.Width = Unit.Pixel(500);
  94.                 for (int k = 0; k < ids2.Count; k++)
  95.                 {
  96.                     TableRow tr3 = new TableRow();
  97.                     TableCell td4 = new TableCell();
  98.                     td4.BorderWidth = Unit.Pixel(1);
  99.                     td4.Width = Unit.Pixel(220);
  100.                     tr3.HorizontalAlign = HorizontalAlign.Left;
  101.                     cb = new CheckBox();
  102.                     cb.InputAttributes["parent"] = ids1[j].ToString();
  103.                     cb.InputAttributes["value"] = ids2[k].ToString();
  104.                     cb.InputAttributes["onclick"] = "check(" + ids2[k] + ")";
  105.                     cb.ID = "chk" + ids2[k].ToString();
  106.                     cb.Text = names2[k].ToString();
  107.                     td4.Controls.Add(cb);
  108.                     tr3.Cells.Add(td4);
  109.                     tb2.Rows.Add(tr3);
  110.                     ArrayList ids3 = new ArrayList();
  111.                     ArrayList names3 = new ArrayList();
  112.                     cmd = new SqlCommand("select id, code, name from OA_DEPARTMENT where last_id=" + ids2[k] + " order by sequence, code", conn);
  113.                     dr = cmd.ExecuteReader();
  114.                     while (dr.Read())
  115.                     {
  116.                         ids3.Add(dr["id"].ToString());
  117.                         names3.Add(dr["code"].ToString() + dr["name"].ToString());
  118.                     }
  119.                     dr.Close();
  120.                     TableCell td6 = new TableCell();
  121.                     td6.VerticalAlign = VerticalAlign.Top;
  122.                     Table tb3 = new Table();
  123.                     for (int l = 0; l < ids3.Count; l++)
  124.                     {
  125.                         TableRow tr4 = new TableRow();
  126.                         TableCell td7 = new TableCell();
  127.                         td7.BorderWidth = Unit.Pixel(1);
  128.                         td7.Width = Unit.Pixel(280);
  129.                         td7.VerticalAlign = VerticalAlign.Top;
  130.                         tr3.HorizontalAlign = HorizontalAlign.Left;
  131.                         cb = new CheckBox();
  132.                         cb.InputAttributes["parent"] = ids2[k].ToString();
  133.                         cb.InputAttributes["value"] = ids3[l].ToString();
  134.                         cb.InputAttributes["onclick"] = "check(" + ids3[l] + ")";
  135.                         cb.ID = "chk" + ids3[l].ToString();
  136.                         cb.Text = names3[l].ToString();
  137.                         td7.Controls.Add(cb);
  138.                         tr4.Cells.Add(td7);
  139.                         tb3.Rows.Add(tr4);
  140.                     }
  141.                     td6.Controls.Add(tb3);
  142.                     tr3.Cells.Add(td6);
  143.                 }
  144.                 td5.Controls.Add(tb2);
  145.                 tr2.Cells.Add(td5);
  146.                 tb1.Rows.Add(tr2);
  147.             }
  148.             td2.Controls.Add(tb1);
  149.             tr1.Cells.Add(td2);
  150.             TblDepartment.Rows.Add(tr1);
  151.         }
  152.         conn.Close();
  153.     }
  154.     protected void BtnOk_Click(object sender, EventArgs e)
  155.     {
  156.         string names = "";
  157.         if (!DepartmentIds.Value.Equals(""))
  158.         {
  159.             SqlConnection conn = dbConnection.getConnection();
  160.             conn.Open();
  161.             string[] ids = DepartmentIds.Value.Split(new char[] { ',' });
  162.             for (int i = 0; i < ids.Length; i++)
  163.             {
  164.                 SqlCommand cmd = new SqlCommand("select code, name from OA_DEPARTMENT where id="+ids[i], conn);
  165.                 SqlDataReader dr = cmd.ExecuteReader();
  166.                 if (dr.Read())
  167.                 {
  168.                     names = names + dr["code"].ToString() + dr["name"].ToString() + ";";
  169.                 }
  170.                 dr.Close();
  171.             }
  172.             conn.Close();
  173.         }
  174.         Response.Write("<script language='javascript'>");
  175.         Response.Write("opener.document.all.LblDepartments.innerText = '"+names.Substring(0, names.Length-1)+"';");
  176.         Response.Write("opener.document.all.DepartmentIds.value = '"+DepartmentIds.Value+"';");
  177.         Response.Write("self.close();");
  178.         Response.Write("</script>");
  179.     }
  180. }