SelectUser.aspx.cs
上传用户:li2971742
上传日期:2021-11-18
资源大小:39096k
文件大小:8k
源码类别:

OA系统

开发平台:

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. namespace OThinker.H3.Portal
  12. {
  13.     /// <summary>
  14.     /// 参数ControlID表示要写回的控件的ID,Mode=Single/Multi表示要选中的是一个值还是多个值
  15.     /// </summary>
  16.     public partial class SelectUser : PortalPage
  17.     {
  18.         private int UnitType
  19.         {
  20.             get
  21.             {
  22.                 string type = this.Request.QueryString[Param_UnitType];
  23.                 if (type == null || type == "")
  24.                 {
  25.                     return (int)OThinker.Organization.UnitType.Unspecified;
  26.                 }
  27.                 else
  28.                 {
  29.                     return int.Parse(type);
  30.                 }
  31.             }
  32.         }
  33.         private bool IsSelectable(OThinker.Organization.UnitType UnitType)
  34.         {
  35.             if (this.UnitType == (int)OThinker.Organization.UnitType.Unspecified)
  36.             {
  37.                 return true;
  38.             }
  39.             else
  40.             {
  41.                 return (this.UnitType & (int)UnitType) > 0;
  42.             }
  43.         }
  44.         private int VisibleUnitType
  45.         {
  46.             get
  47.             {
  48.                 string type = this.Request.QueryString[Param_VisibleUnitType];
  49.                 if (type == null || type == "")
  50.                 {
  51.                     return (int)OThinker.Organization.UnitType.Unspecified;
  52.                 }
  53.                 else
  54.                 {
  55.                     return int.Parse(type);
  56.                 }
  57.             }
  58.         }
  59.         private OThinker.Organization.VisibleType VisibleType
  60.         {
  61.             get
  62.             {
  63.                 string type = this.Request.QueryString[Param_VisibleType];
  64.                 if (type == null || type == "")
  65.                 {
  66.                     return OThinker.Organization.VisibleType.Normal;
  67.                 }
  68.                 else
  69.                 {
  70.                     return (OThinker.Organization.VisibleType)int.Parse(type);
  71.                 }
  72.             }
  73.         }
  74.         private bool IsVisible(OThinker.Organization.UnitType UnitType)
  75.         {
  76.             if (this.VisibleUnitType == (int)OThinker.Organization.UnitType.Unspecified)
  77.             {
  78.                 return true;
  79.             }
  80.             else
  81.             {
  82.                 return (this.VisibleUnitType & (int)UnitType) > 0;
  83.             }
  84.         }
  85.         protected void Page_Load(object sender, EventArgs e)
  86.         {
  87.             if (!this.IsPostBack)
  88.             {
  89.                 TreeNode root = new TreeNode();
  90.                 root.Value = OThinker.H3.Server.Engine.Organization.Company.UnitID;
  91.                 root.Text = OThinker.H3.Server.Engine.Organization.Company.Name;
  92.                 root.PopulateOnDemand = true;
  93.                 root.SelectAction = TreeNodeSelectAction.Select;
  94.                 this.SetNodeNavigateUrl(root, OThinker.Organization.UnitType.Company);
  95.                 this.UserTree.Nodes.Add(root);
  96.                 root.Expand();
  97.             }
  98.         }
  99.         protected void UserTree_TreeNodePopulate(object sender, TreeNodeEventArgs e)
  100.         {
  101.             //if (IsCallback)
  102.             //{
  103.             if (e.Node.ChildNodes.Count == 0)
  104.             {
  105.                 LoadChildNode(e.Node);
  106.             }
  107.             //}
  108.         }
  109.         protected void LoadChildNode(TreeNode node)
  110.         {
  111.             string[] children = OThinker.H3.Server.Engine.Organization.GetChildren(node.Value, OThinker.Organization.UnitType.Unspecified, false);
  112.             if (children != null)
  113.             {
  114.                 // 按照OrganizationUnit, Group, User的顺序进行排列
  115.                 ArrayList unitList = new ArrayList();
  116.                 ArrayList keyList = new ArrayList();
  117.                 foreach (string child in children)
  118.                 {
  119.                     OThinker.Organization.Unit unit = OThinker.H3.Server.Engine.Organization.GetUnit(child); 
  120.                     
  121.                     if (!this.IsVisible(unit.UnitType))
  122.                     {
  123.                         continue;
  124.                     }
  125.                     if ((this.VisibleType & ((OThinker.Organization.NonCompany)unit).Visibility) == 0)
  126.                     {
  127.                         continue;
  128.                     }
  129.                     switch (unit.UnitType)
  130.                     {
  131.                         case OThinker.Organization.UnitType.Company:
  132.                             keyList.Add("a" + unit.Name);
  133.                             break;
  134.                         case OThinker.Organization.UnitType.OrganizationUnit:
  135.                             keyList.Add("b" + unit.Name);
  136.                             break;
  137.                         case OThinker.Organization.UnitType.Group:
  138.                             keyList.Add("c" + unit.Name);
  139.                             break;
  140.                         case OThinker.Organization.UnitType.User:
  141.                             keyList.Add("d" + unit.Name);
  142.                             break;
  143.                         default:
  144.                             throw new NotImplementedException();
  145.                     }
  146.                     unitList.Add(unit);
  147.                 }
  148.                 unitList = OThinker.Data.Sorter.Sort(keyList, unitList);
  149.                 foreach (OThinker.Organization.Unit unit in unitList)
  150.                 {
  151.                     if (unit == null)
  152.                     {
  153.                         continue;
  154.                     }
  155.                     TreeNode subNode = new TreeNode(unit.Name);
  156.                     subNode.Value = unit.UnitID;
  157.                     switch (unit.UnitType)
  158.                     {
  159.                         case OThinker.Organization.UnitType.User:
  160.                             subNode.SelectAction = TreeNodeSelectAction.Select;
  161.                             subNode.ImageUrl = "images/IB_Man.gif";
  162.                             break;
  163.                         case OThinker.Organization.UnitType.OrganizationUnit:
  164.                             subNode.SelectAction = TreeNodeSelectAction.SelectExpand;
  165.                             subNode.PopulateOnDemand = true;
  166.                             subNode.ImageUrl = "images/IB_OU.ico";
  167.                             break;
  168.                         case OThinker.Organization.UnitType.Group:
  169.                             subNode.SelectAction = TreeNodeSelectAction.SelectExpand;
  170.                             subNode.PopulateOnDemand = true;
  171.                             subNode.ImageUrl = "images/IB_SelectUser.gif";
  172.                             break;
  173.                         default:
  174.                             break;
  175.                     }
  176.                     
  177.                     this.SetNodeNavigateUrl(subNode, unit.UnitType);
  178.                     node.ChildNodes.Add(subNode);
  179.                 }
  180.             }
  181.         }
  182.         private void SetNodeNavigateUrl(TreeNode Node, OThinker.Organization.UnitType UnitType)
  183.         {
  184.             // 如果目标类型未指定,则该单元能被选择
  185.             // 如果目标类型和当前类型一致,则该单元能被选择
  186.             // 如果目标类型为组织单元,且该单元类型为Company,则该单元也能被选择
  187.             if (this.IsSelectable(UnitType))
  188.             {
  189.                 Node.NavigateUrl = "javascript:selectedUser('" + Node.Text + "', '" + Node.Value + "');";
  190.             }
  191.             else
  192.             {
  193.                 Node.NavigateUrl = "javascript:;";
  194.             }
  195.         }
  196.     }
  197. }