SelectUser.aspx.cs
资源名称:H3_OA.rar [点击查看]
上传用户:li2971742
上传日期:2021-11-18
资源大小:39096k
文件大小:8k
源码类别:
OA系统
开发平台:
C#
- using System;
- using System.Data;
- using System.Configuration;
- using System.Collections;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Web.UI.HtmlControls;
- namespace OThinker.H3.Portal
- {
- /// <summary>
- /// 参数ControlID表示要写回的控件的ID,Mode=Single/Multi表示要选中的是一个值还是多个值
- /// </summary>
- public partial class SelectUser : PortalPage
- {
- private int UnitType
- {
- get
- {
- string type = this.Request.QueryString[Param_UnitType];
- if (type == null || type == "")
- {
- return (int)OThinker.Organization.UnitType.Unspecified;
- }
- else
- {
- return int.Parse(type);
- }
- }
- }
- private bool IsSelectable(OThinker.Organization.UnitType UnitType)
- {
- if (this.UnitType == (int)OThinker.Organization.UnitType.Unspecified)
- {
- return true;
- }
- else
- {
- return (this.UnitType & (int)UnitType) > 0;
- }
- }
- private int VisibleUnitType
- {
- get
- {
- string type = this.Request.QueryString[Param_VisibleUnitType];
- if (type == null || type == "")
- {
- return (int)OThinker.Organization.UnitType.Unspecified;
- }
- else
- {
- return int.Parse(type);
- }
- }
- }
- private OThinker.Organization.VisibleType VisibleType
- {
- get
- {
- string type = this.Request.QueryString[Param_VisibleType];
- if (type == null || type == "")
- {
- return OThinker.Organization.VisibleType.Normal;
- }
- else
- {
- return (OThinker.Organization.VisibleType)int.Parse(type);
- }
- }
- }
- private bool IsVisible(OThinker.Organization.UnitType UnitType)
- {
- if (this.VisibleUnitType == (int)OThinker.Organization.UnitType.Unspecified)
- {
- return true;
- }
- else
- {
- return (this.VisibleUnitType & (int)UnitType) > 0;
- }
- }
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!this.IsPostBack)
- {
- TreeNode root = new TreeNode();
- root.Value = OThinker.H3.Server.Engine.Organization.Company.UnitID;
- root.Text = OThinker.H3.Server.Engine.Organization.Company.Name;
- root.PopulateOnDemand = true;
- root.SelectAction = TreeNodeSelectAction.Select;
- this.SetNodeNavigateUrl(root, OThinker.Organization.UnitType.Company);
- this.UserTree.Nodes.Add(root);
- root.Expand();
- }
- }
- protected void UserTree_TreeNodePopulate(object sender, TreeNodeEventArgs e)
- {
- //if (IsCallback)
- //{
- if (e.Node.ChildNodes.Count == 0)
- {
- LoadChildNode(e.Node);
- }
- //}
- }
- protected void LoadChildNode(TreeNode node)
- {
- string[] children = OThinker.H3.Server.Engine.Organization.GetChildren(node.Value, OThinker.Organization.UnitType.Unspecified, false);
- if (children != null)
- {
- // 按照OrganizationUnit, Group, User的顺序进行排列
- ArrayList unitList = new ArrayList();
- ArrayList keyList = new ArrayList();
- foreach (string child in children)
- {
- OThinker.Organization.Unit unit = OThinker.H3.Server.Engine.Organization.GetUnit(child);
- if (!this.IsVisible(unit.UnitType))
- {
- continue;
- }
- if ((this.VisibleType & ((OThinker.Organization.NonCompany)unit).Visibility) == 0)
- {
- continue;
- }
- switch (unit.UnitType)
- {
- case OThinker.Organization.UnitType.Company:
- keyList.Add("a" + unit.Name);
- break;
- case OThinker.Organization.UnitType.OrganizationUnit:
- keyList.Add("b" + unit.Name);
- break;
- case OThinker.Organization.UnitType.Group:
- keyList.Add("c" + unit.Name);
- break;
- case OThinker.Organization.UnitType.User:
- keyList.Add("d" + unit.Name);
- break;
- default:
- throw new NotImplementedException();
- }
- unitList.Add(unit);
- }
- unitList = OThinker.Data.Sorter.Sort(keyList, unitList);
- foreach (OThinker.Organization.Unit unit in unitList)
- {
- if (unit == null)
- {
- continue;
- }
- TreeNode subNode = new TreeNode(unit.Name);
- subNode.Value = unit.UnitID;
- switch (unit.UnitType)
- {
- case OThinker.Organization.UnitType.User:
- subNode.SelectAction = TreeNodeSelectAction.Select;
- subNode.ImageUrl = "images/IB_Man.gif";
- break;
- case OThinker.Organization.UnitType.OrganizationUnit:
- subNode.SelectAction = TreeNodeSelectAction.SelectExpand;
- subNode.PopulateOnDemand = true;
- subNode.ImageUrl = "images/IB_OU.ico";
- break;
- case OThinker.Organization.UnitType.Group:
- subNode.SelectAction = TreeNodeSelectAction.SelectExpand;
- subNode.PopulateOnDemand = true;
- subNode.ImageUrl = "images/IB_SelectUser.gif";
- break;
- default:
- break;
- }
- this.SetNodeNavigateUrl(subNode, unit.UnitType);
- node.ChildNodes.Add(subNode);
- }
- }
- }
- private void SetNodeNavigateUrl(TreeNode Node, OThinker.Organization.UnitType UnitType)
- {
- // 如果目标类型未指定,则该单元能被选择
- // 如果目标类型和当前类型一致,则该单元能被选择
- // 如果目标类型为组织单元,且该单元类型为Company,则该单元也能被选择
- if (this.IsSelectable(UnitType))
- {
- Node.NavigateUrl = "javascript:selectedUser('" + Node.Text + "', '" + Node.Value + "');";
- }
- else
- {
- Node.NavigateUrl = "javascript:;";
- }
- }
- }
- }