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

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.     public partial class EditOrganization : PortalPage
  14.     {
  15.         public const string Target = "OrganizationMain";
  16.         private int VisibleUnitType
  17.         {
  18.             get
  19.             {
  20.                 string type = this.Request.QueryString[Param_VisibleUnitType];
  21.                 if (type == null || type == "")
  22.                 {
  23.                     return (int)OThinker.Organization.UnitType.Unspecified;
  24.                 }
  25.                 else
  26.                 {
  27.                     return int.Parse(type);
  28.                 }
  29.             }
  30.         }
  31.         private bool IsVisible(OThinker.Organization.UnitType UnitType)
  32.         {
  33.             if (this.VisibleUnitType == (int)OThinker.Organization.UnitType.Unspecified)
  34.             {
  35.                 return true;
  36.             }
  37.             else
  38.             {
  39.                 return (this.VisibleUnitType & (int)UnitType) > 0;
  40.             }
  41.         }
  42.         #region 要展开的节点
  43.         protected string ExpandPath
  44.         {
  45.             get
  46.             {
  47.                 return HttpUtility.UrlDecode(this.Request.QueryString[Param_ExpandPath]);
  48.             }
  49.         }
  50.         private System.Collections.Generic.List<string> _ExpandList = null;
  51.         protected System.Collections.Generic.List<string> ExpandList
  52.         {
  53.             get
  54.             {
  55.                 if (this._ExpandList == null)
  56.                 {
  57.                     this._ExpandList = new System.Collections.Generic.List<string>();
  58.                     if (this.ExpandPath != null && this.ExpandPath != "")
  59.                     {
  60.                         string[] units = this.ExpandPath.Split('/');
  61.                         this._ExpandList = new System.Collections.Generic.List<string>(units);
  62.                     }
  63.                 }
  64.                 return this._ExpandList;
  65.             }
  66.         }
  67.         #endregion
  68.         protected void Page_Load(object sender, EventArgs e)
  69.         {
  70.             if (!this.IsPostBack)
  71.             {
  72.                 //// 验证是否具有管理员权限
  73.                 //if (!this.UserValidator.ValidateAdministrator())
  74.                 //{
  75.                 //    this.NotifyMessage(LackOfAuth);
  76.                 //}
  77.                 TreeNode root = new TreeNode();
  78.                 root.Value = OThinker.H3.Server.Engine.Organization.Company.UnitID;
  79.                 root.Text = OThinker.H3.Server.Engine.Organization.Company.Name;
  80.                 root.NavigateUrl = PageName_EditCompany + "?UnitID=" + OThinker.H3.Server.Engine.Organization.Company.UnitID;
  81.                 root.Target = Target;
  82.                 root.PopulateOnDemand = true;
  83.                 root.SelectAction = TreeNodeSelectAction.Select;
  84.                 root.ImageToolTip = root.Value;
  85.                 this.SetNodeNavigateUrl(root, OThinker.Organization.UnitType.Company);
  86.                 this.UserTree.Nodes.Add(root);
  87.                 root.Expand();
  88.             }
  89.         }
  90.         protected void UserTree_TreeNodePopulate(object sender, TreeNodeEventArgs e)
  91.         {
  92.             //if (IsCallback)
  93.             //{
  94.             if (e.Node.ChildNodes.Count == 0)
  95.             {
  96.                 LoadChildNode(e.Node);
  97.             }
  98.             //}
  99.         }
  100.         protected void LoadChildNode(TreeNode node)
  101.         {
  102.             string[] children = OThinker.H3.Server.Engine.Organization.GetChildren(node.Value, OThinker.Organization.UnitType.Unspecified, false);
  103.             if (children != null)
  104.             {
  105.                 // 按照OrganizationUnit, Group, User的顺序进行排列
  106.                 ArrayList unitList = new ArrayList();
  107.                 ArrayList keyList = new ArrayList();
  108.                 foreach (string child in children)
  109.                 {
  110.                     OThinker.Organization.Unit unit = OThinker.H3.Server.Engine.Organization.GetUnit(child);
  111.                     // 检查是否可见
  112.                     if (!this.IsVisible(unit.UnitType))
  113.                     {
  114.                         continue;
  115.                     }
  116.                     switch (unit.UnitType)
  117.                     {
  118.                         case OThinker.Organization.UnitType.Company:
  119.                             keyList.Add("a" + unit.Name);
  120.                             break;
  121.                         case OThinker.Organization.UnitType.OrganizationUnit:
  122.                             keyList.Add("b" + unit.Name);
  123.                             break;
  124.                         case OThinker.Organization.UnitType.Group:
  125.                             keyList.Add("c" + unit.Name);
  126.                             break;
  127.                         case OThinker.Organization.UnitType.User:
  128.                             keyList.Add("d" + unit.Name);
  129.                             break;
  130.                         default:
  131.                             throw new NotImplementedException();
  132.                     }
  133.                     unitList.Add(unit);
  134.                 }
  135.                 unitList = OThinker.Data.Sorter.Sort(keyList, unitList);
  136.                 foreach (OThinker.Organization.Unit unit in unitList)
  137.                 {
  138.                     if (unit == null)
  139.                     {
  140.                         continue;
  141.                     }
  142.                     TreeNode subNode = new TreeNode(unit.Name);
  143.                     subNode.Value = unit.UnitID;
  144.                     subNode.Target = Target;
  145.                     node.ChildNodes.Add(subNode);
  146.                     string param = "?" + Param_ID + "=" + unit.UnitID + "&" + Param_ExpandPath + "=" + HttpUtility.UrlEncode(subNode.ValuePath);
  147.                     switch (unit.UnitType)
  148.                     {
  149.                         case OThinker.Organization.UnitType.User:
  150.                             subNode.SelectAction = TreeNodeSelectAction.Select;
  151.                             subNode.ImageUrl = "images/IB_Man.gif";
  152.                             subNode.NavigateUrl = PageName_EditUser + param;
  153.                             break;
  154.                         case OThinker.Organization.UnitType.OrganizationUnit:
  155.                             subNode.SelectAction = TreeNodeSelectAction.SelectExpand;
  156.                             subNode.PopulateOnDemand = true;
  157.                             subNode.ImageUrl = "images/IB_OU.ico";
  158.                             subNode.NavigateUrl = PageName_EditOrganizationUnit + param;
  159.                             break;
  160.                         case OThinker.Organization.UnitType.Group:
  161.                             subNode.SelectAction = TreeNodeSelectAction.SelectExpand;
  162.                             subNode.PopulateOnDemand = true;
  163.                             subNode.ImageUrl = "images/IB_SelectUser.gif";
  164.                             subNode.NavigateUrl = PageName_EditGroup + param;
  165.                             break;
  166.                         default:
  167.                             break;
  168.                     }
  169.                     this.SetNodeNavigateUrl(subNode, unit.UnitType);
  170.                     if (this.ExpandList.Contains(subNode.Value))
  171.                     {
  172.                         subNode.Expand();
  173.                     }
  174.                 }
  175.             }
  176.         }
  177.         private void SetNodeNavigateUrl(TreeNode Node, OThinker.Organization.UnitType UnitType)
  178.         {
  179.             // 如果目标类型未指定,则该单元能被选择
  180.             // 如果目标类型和当前类型一致,则该单元能被选择
  181.             // 如果目标类型为组织单元,且该单元类型为Company,则该单元也能被选择
  182.             //string url = null;
  183.             //switch (UnitType)
  184.             //{
  185.             //    case OThinker.Organization.UnitType.Company:
  186.             //        url = PageName_EditCompany;
  187.             //        break;
  188.             //    case OThinker.Organization.UnitType.OrganizationUnit:
  189.             //        url = PageName_EditOrganizationUnit;
  190.             //        break;
  191.             //    case OThinker.Organization.UnitType.Group:
  192.             //        url = PageName_EditGroup;
  193.             //        break;
  194.             //    case OThinker.Organization.UnitType.User:
  195.             //        url = PageName_EditUser;
  196.             //        break;
  197.             //    default:
  198.             //        throw new NotImplementedException();
  199.             //}
  200.             //url += "?" + Param_ID + "=" + Node.Value;
  201.             //Node.NavigateUrl = url;
  202.         }
  203.     }
  204. }