EmpTree.aspx.cs
上传用户:tiancihang
上传日期:2014-03-12
资源大小:21387k
文件大小:6k
源码类别:

.net编程

开发平台:

C#

  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 com.etong.DAL.FC;
  12. public partial class EmpTree : System.Web.UI.Page
  13. {
  14.     protected void Page_Load(object sender, EventArgs e)
  15.     {
  16.         Response.Buffer = true;
  17.         Response.ExpiresAbsolute = System.DateTime.Now;
  18.         Response.Expires = 0;
  19.         Response.CacheControl = "no-cache";
  20.         if (!IsPostBack)
  21.         {
  22.             int rows = 0, i = 0, prentID = 0, OrgLevel = 0, OrgID = 0;
  23.             DataView dv = new DataView();
  24.             EtongFlyChou EFly = new EtongFlyChou();
  25.             string PrentID, OrgName, StrOrgID, StrPath;
  26.             Array OrgArr;
  27.             int PrentIndex, TwoIndex = 0;
  28.             bool bl = true;
  29.             //Array ThreeIndex;
  30.             dv = EFly.ReadOrgData();
  31.             rows = dv.Count;
  32.             int[] ThreeIndex = new int[rows];
  33.             for (i = 0; i < rows; i++)
  34.             {
  35.                 OrgArr = dv.Table.Rows[i].ItemArray;
  36.                 PrentID = Convert.ToString(OrgArr.GetValue(1));
  37.                 OrgName = Convert.ToString(OrgArr.GetValue(2));
  38.                 OrgLevel = Convert.ToInt32(OrgArr.GetValue(5));
  39.                 StrOrgID = Convert.ToString(OrgArr.GetValue(0));
  40.                 OrgID = Convert.ToInt32(OrgArr.GetValue(0));
  41.                 StrPath = Convert.ToString(OrgArr.GetValue(8));
  42.                 if (PrentID != "" && PrentID != null)
  43.                 {
  44.                     prentID = Convert.ToInt32(PrentID);
  45.                     TreeNode trnode = new TreeNode();
  46.                     if (prentID == -1)
  47.                     {
  48.                         trnode.Text = OrgName;
  49.                         trnode.Value = StrOrgID;
  50.                         trnode.ToolTip = OrgName;
  51.                         OrgTree.Nodes.Add(trnode);
  52.                     }
  53.                     else
  54.                     {
  55.                         trnode.Text = OrgName;
  56.                         trnode.Value = StrOrgID;
  57.                         trnode.ToolTip = OrgName;
  58.                         if (OrgLevel == 2)
  59.                         {
  60.                             trnode.ImageToolTip = Convert.ToString(TwoIndex);
  61.                             OrgTree.Nodes[0].ChildNodes.Add(trnode);
  62.                             TwoIndex++;
  63.                         }
  64.                         if (OrgLevel == 3)
  65.                         {
  66.                             PrentIndex = Convert.ToInt32(OrgTree.FindNode(EFly.GetParentNode(PrentID)).ImageToolTip);
  67.                             ThreeIndex[PrentIndex]++;
  68.                             trnode.ImageToolTip = Convert.ToString(ThreeIndex[PrentIndex] - 1);
  69.                             OrgTree.Nodes[0].ChildNodes[PrentIndex].ChildNodes.Add(trnode);
  70.                         }
  71.                         //OrgTree.Nodes.Add(trnode);
  72.                     }
  73.                 }
  74.             }
  75.             ///value 值用"职工"区别
  76.             string EmpName, StrEmpID;
  77.             int PrOrgID, PID;
  78.             rows = OrgLevel = 0;
  79.             dv = EFly.ReadEmpData();
  80.             rows = dv.Count;
  81.             for (i = 0; i < rows; i++)
  82.             {
  83.                 OrgArr = dv.Table.Rows[i].ItemArray;
  84.                 StrEmpID = Convert.ToString(OrgArr.GetValue(0));
  85.                 EmpName = Convert.ToString(OrgArr.GetValue(1));
  86.                 OrgLevel = Convert.ToInt32(OrgArr.GetValue(3));
  87.                 PrOrgID = Convert.ToInt32(OrgArr.GetValue(2));
  88.                 TreeNode trnode = new TreeNode();
  89.                 trnode.Text = EmpName;
  90.                 trnode.ToolTip = EmpName;
  91.                 trnode.Value = "职工" + StrEmpID;
  92.                 trnode.ImageUrl = "image/user.gif";
  93.                 //trnode.ImageToolTip = StrEmpID;
  94.                 if (OrgLevel == 1)
  95.                 {
  96.                     OrgTree.Nodes[0].ChildNodes.Add(trnode);
  97.                 }
  98.                 else if (OrgLevel == 2)
  99.                 {
  100.                     PrOrgID = Convert.ToInt32(OrgTree.FindNode(EFly.GetParentNode(Convert.ToString(PrOrgID))).ImageToolTip);
  101.                     OrgTree.Nodes[0].ChildNodes[PrOrgID].ChildNodes.Add(trnode);
  102.                 }
  103.                 else if (OrgLevel == 3)
  104.                 {
  105.                     PID = Convert.ToInt32(EFly.GetParentID(Convert.ToString(PrOrgID)));
  106.                     PrOrgID = Convert.ToInt32(OrgTree.FindNode(EFly.GetParentNode(Convert.ToString(PrOrgID))).ImageToolTip);
  107.                     PID = Convert.ToInt32(OrgTree.FindNode(EFly.GetParentNode(Convert.ToString(PID))).ImageToolTip);
  108.                     OrgTree.Nodes[0].ChildNodes[PID].ChildNodes[PrOrgID].ChildNodes.Add(trnode);
  109.                 }
  110.             }
  111.             OrgTree.CollapseAll();
  112.             OrgTree.Nodes[0].Expand();
  113.         }
  114.     }
  115.     protected void OrgTree_SelectedNodeChanged(object sender, EventArgs e)
  116.     {
  117.         string EmId = "", EMName = "";
  118.         EmId = OrgTree.SelectedValue;
  119.         EMName = OrgTree.SelectedNode.Text;
  120.         int EmidLen = EmId.Length;
  121.         if (EmidLen > 2)
  122.         {
  123.             string firstword = EmId.Substring(0, 2).ToString();
  124.             if (firstword == "职工")
  125.             {
  126.                 string secondword = "";
  127.                    secondword=EmId.Substring(2).ToString()+ "" + "," + EMName.ToString();
  128.               
  129.                 ClientScript.RegisterStartupScript(this.GetType(), "", "<script>window.returnValue='" + secondword + "';window.close();</script>");
  130.                // Response.Write("<script>window.returnValue=" + secondword + " ;window.close();</script>");
  131.                // return;
  132.             }
  133.             else
  134.                 ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('系统提示:请选择职工');</script>");
  135.         }
  136.         else
  137.             ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('系统提示:请选择职工');</script>");
  138.      
  139.     }
  140. }