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

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 EditGroup : PortalPage
  14.     {
  15.         public const char Seperator = ';';
  16.         #region 参数
  17.         protected string ParentID
  18.         {
  19.             get
  20.             {
  21.                 return HttpUtility.UrlDecode(this.Request.QueryString[Param_Parent]);
  22.             }
  23.         }
  24.         protected string ParentGroupID
  25.         {
  26.             get
  27.             {
  28.                 return HttpUtility.UrlDecode(this.Request.QueryString[Param_ParentGroup]);
  29.             }
  30.         }
  31.         protected string EditID
  32.         {
  33.             get
  34.             {
  35.                 return HttpUtility.UrlDecode(this.Request.QueryString[Param_ID]);
  36.             }
  37.         }
  38.         private OThinker.Organization.Group _EditUnit;
  39.         protected OThinker.Organization.Group EditUnit
  40.         {
  41.             get
  42.             {
  43.                 if (this._EditUnit != null)
  44.                 {
  45.                     return this._EditUnit;
  46.                 }
  47.                 else if (EditID == null || EditID == "")
  48.                 {
  49.                     return null;
  50.                 }
  51.                 else
  52.                 {
  53.                     OThinker.Organization.Unit unit = OThinker.H3.Server.Engine.Organization.GetUnit(this.EditID);
  54.                     if (unit == null || unit.UnitType != OThinker.Organization.UnitType.Group)
  55.                     {
  56.                         return null;
  57.                     }
  58.                     this._EditUnit = (OThinker.Organization.Group)unit;
  59.                     return this._EditUnit;
  60.                 }
  61.             }
  62.         }
  63.         #endregion
  64.         private EditUserType _EditMode = EditUserType.Unspecified;
  65.         /// <summary>
  66.         /// 是否是自己修改自己信息的模式
  67.         /// </summary>
  68.         protected EditUserType EditMode
  69.         {
  70.             get
  71.             {
  72.                 if (this._EditMode == EditUserType.Unspecified)
  73.                 {
  74.                     if (this.UserValidator.ValidateAdministrator())
  75.                     {
  76.                         if (this.EditID == null || this.EditID == "")
  77.                         {
  78.                             this._EditMode = EditUserType.Add;
  79.                         }
  80.                         else
  81.                         {
  82.                             this._EditMode = EditUserType.Admin;
  83.                         }
  84.                     }
  85.                     else
  86.                     {
  87.                         this._EditMode = EditUserType.View;
  88.                     }
  89.                 }
  90.                 return this._EditMode;
  91.             }
  92.         }
  93.         protected void Page_Load(object sender, EventArgs e)
  94.         {
  95.             if (!this.IsPostBack)
  96.             {
  97.                 this.lnkRemove.Attributes.Add(
  98.                     "onClick",
  99.                     "if(confirm('确定要删除?'))location='" +
  100.                     PageName_RemoveUnit + "?" +
  101.                     Param_ID + "=" + this.EditID + "&" + Param_ExpandPath + "=" + this.Request.QueryString[Param_ExpandPath] +
  102.                     "'");
  103.                 this.lnkCreateChildGroup.NavigateUrl = PageName_EditGroup + "?" + Param_ParentGroup + "=" + this.EditID + "&" + Param_ExpandPath + "=" + this.Request.QueryString[Param_ExpandPath];
  104.                 // 返回按钮
  105.                 string q = HttpUtility.UrlDecode(this.Request.QueryString[Param_Q]);
  106.                 if (q == null || q == "")
  107.                 {
  108.                     this.lnkReturn.Visible = false;
  109.                 }
  110.                 else
  111.                 {
  112.                     this.lnkReturn.NavigateUrl = q;
  113.                 }
  114.                 // 按钮
  115.                 switch (this.EditMode)
  116.                 {
  117.                     case EditUserType.Add:
  118.                         this.lnkRemove.Visible = false;
  119.                         this.lnkCreateChildGroup.Visible = false;
  120.                         break;
  121.                     case EditUserType.Admin:
  122.                         if (this.EditUnit == null || !this.EditUnit.AllowChildGroup)
  123.                         {
  124.                             this.lnkCreateChildGroup.Visible = false;
  125.                         }
  126.                         break;
  127.                     case EditUserType.View:
  128.                         this.panelButtons.Visible = false;
  129.                         break;
  130.                 }
  131.                 // 公司
  132.                 this.lblCompany.Text = OThinker.H3.Server.Engine.Organization.Company.Name;
  133.                 // 父对象
  134.                 string parentId;
  135.                 OThinker.Organization.Unit parentGroup = null;
  136.                 if (this.EditUnit != null)
  137.                 {
  138.                     parentId = this.EditUnit.ParentID;
  139.                 }
  140.                 else if (this.ParentID != null && this.ParentID != "")
  141.                 {
  142.                     parentId = this.ParentID;
  143.                 }
  144.                 else if (this.ParentGroupID != null && this.ParentGroupID != "" &&
  145.                     (parentGroup = OThinker.H3.Server.Engine.Organization.GetUnit(this.ParentGroupID)) != null &&
  146.                     (parentGroup.UnitType == OThinker.Organization.UnitType.Group) &&
  147.                     ((OThinker.Organization.Group)parentGroup).ParentID != OThinker.H3.Server.Engine.Organization.Company.CompanyID)
  148.                 {
  149.                     parentId = ((OThinker.Organization.Group)parentGroup).ParentID;
  150.                 }
  151.                 else if (OThinker.H3.Server.Engine.Organization.GetUnit(OThinker.Organization.OrganizationUnit.GroupOUID) != null)
  152.                 {
  153.                     parentId = OThinker.Organization.OrganizationUnit.GroupOUID;
  154.                 }
  155.                 else
  156.                 {
  157.                     parentId = OThinker.H3.Server.Engine.Organization.Company.CompanyID;
  158.                 }
  159.                 string managerId = this.EditUnit == null ? null : this.EditUnit.ManagerID;
  160.                 switch (this.EditMode)
  161.                 {
  162.                     case EditUserType.Add:
  163.                     case EditUserType.Admin:
  164.                         this.txtParent.LoadSelection(OThinker.H3.Server.Engine.Organization, parentId);
  165.                         this.txtManager.LoadSelection(OThinker.H3.Server.Engine.Organization, managerId);
  166.                         this.lnkParent.Visible = false;
  167.                         this.lnkManager.Visible = false;
  168.                         break;
  169.                     case EditUserType.View:
  170.                         this.txtParent.Visible = false;
  171.                         this.txtManager.Visible = false;
  172.                         this.lnkParent.Text = OThinker.H3.Server.Engine.Organization.GetFullName(parentId);
  173.                         OThinker.Organization.Unit parentUnit = OThinker.H3.Server.Engine.Organization.GetUnit(parentId);
  174.                         if (parentUnit.UnitType == OThinker.Organization.UnitType.Company)
  175.                         {
  176.                             this.lnkParent.NavigateUrl = PageName_EditCompany;
  177.                         }
  178.                         else
  179.                         {
  180.                             this.lnkParent.NavigateUrl = PageName_EditOrganizationUnit + "?" + Param_ID + "=" + parentId;
  181.                         }
  182.                         if (managerId == null)
  183.                         {
  184.                             this.lnkManager.Text = "未设置";
  185.                         }
  186.                         else
  187.                         {
  188.                             this.lnkManager.Text = OThinker.H3.Server.Engine.Organization.GetFullName(managerId);
  189.                             this.lnkManager.NavigateUrl = PageName_EditUser + "?" + Param_ID + "=" + managerId;
  190.                         }
  191.                         break;
  192.                 }
  193.                 // 可见类型
  194.                 string[] visibilityTypeEnNames = Enum.GetNames(typeof(OThinker.Organization.VisibleType));
  195.                 foreach (string enName in visibilityTypeEnNames)
  196.                 {
  197.                     OThinker.Organization.VisibleType visibilityType = OThinker.Organization.VisibilityTypeConvertor.GetVisibilityType(enName);
  198.                     string cnName = OThinker.Organization.VisibilityTypeConvertor.GetName(visibilityType);
  199.                     this.lstVisibilityType.Items.Add(new ListItem(cnName, enName));
  200.                 }
  201.                 // 其他
  202.                 if (this.EditUnit != null)
  203.                 {
  204.                     this.lblPath.Text = OThinker.H3.Server.Engine.Organization.GetPath(this.EditUnit.UnitID);
  205.                     this.txtName.Text = this.EditUnit.Name;
  206.                     this.txtDescription.Text = this.EditUnit.Description;
  207.                     this.chkAllowChildGroup.Checked = this.EditUnit.AllowChildGroup;
  208.                     this.chkAllowMultiParentGroup.Checked = this.EditUnit.AllowMultiParentGroup;
  209.                     this.txtChildren.LoadSelection(OThinker.H3.Server.Engine.Organization, this.EditUnit.Children);
  210.                     this.txtChildren.GroupSelectable = this.chkAllowChildGroup.Checked;
  211.                     // 可见性
  212.                     this.lstVisibilityType.SelectedValue = this.EditUnit.Visibility.ToString();
  213.                 }
  214.                 switch (this.EditMode)
  215.                 {
  216.                     case EditUserType.View:
  217.                         this.txtName.Enabled = false;
  218.                         this.txtDescription.Enabled = false;
  219.                         this.chkAllowChildGroup.Enabled = false;
  220.                         this.chkAllowMultiParentGroup.Enabled = false;
  221.                         this.txtChildren.Editable = false;
  222.                         this.lstVisibilityType.Enabled = false;
  223.                         break;
  224.                 }
  225.             }
  226.         }
  227.         protected void lnkOk_Click(object sender, EventArgs e)
  228.         {
  229.             // 检查是否合法
  230.             OThinker.Organization.Unit parent = null;
  231.             if (
  232.                 this.txtParent.SelectedUser == null || this.txtParent.SelectedUser == "" ||
  233.                 (parent = OThinker.H3.Server.Engine.Organization.GetUnit(this.txtParent.SelectedUser)) == null ||
  234.                 (parent.UnitType != OThinker.Organization.UnitType.Company && parent.UnitType != OThinker.Organization.UnitType.OrganizationUnit))
  235.             {
  236.                 this.NotifyMessage("父对象设置为空");
  237.             }
  238.             OThinker.Organization.Group group;
  239.             if (this.EditUnit == null)
  240.             {
  241.                 group = new OThinker.Organization.Group(OThinker.H3.Server.Engine.Organization.Company.UnitID, this.txtParent.SelectedUser);
  242.             }
  243.             else
  244.             {
  245.                 group = this.EditUnit;
  246.             }
  247.             group.Name = this.txtName.Text;
  248.             group.Description = this.txtDescription.Text;
  249.             group.AllowChildGroup = this.chkAllowChildGroup.Checked;
  250.             group.AllowMultiParentGroup = this.chkAllowMultiParentGroup.Checked;
  251.             group.ManagerID = this.txtManager.SelectedUser;
  252.             group.ParentID = this.txtParent.SelectedUser;
  253.             group.Children = this.txtChildren.SelectedUsers;
  254.             // 可见类型
  255.             group.Visibility = OThinker.Organization.VisibilityTypeConvertor.GetVisibilityType(this.lstVisibilityType.SelectedValue);
  256.             // 写入服务器
  257.             OThinker.Organization.HandleResult result = OThinker.Organization.HandleResult.SUCCESS;
  258.             if (this.EditUnit == null)
  259.             {
  260.                 OThinker.H3.Server.Engine.Organization.AddUnit(this.UserValidator.UserID, group, ref result);
  261.             }
  262.             else
  263.             {
  264.                 result = OThinker.H3.Server.Engine.Organization.UpdateUnit(this.UserValidator.UserID, group);
  265.             }
  266.             if (result != OThinker.Organization.HandleResult.SUCCESS)
  267.             {
  268.                 // 显示结果
  269.                 this.NotifyResult(
  270.                     result,
  271.                     result == OThinker.Organization.HandleResult.SUCCESS,
  272.                     this.Request.QueryString[Param_ExpandPath]);
  273.             }
  274.             // 编辑父组
  275.             if (this.ParentGroupID != null && this.ParentGroupID != "")
  276.             {
  277.                 OThinker.Organization.Unit parentGroupUnit = OThinker.H3.Server.Engine.Organization.GetUnit(this.ParentGroupID);
  278.                 if (parentGroupUnit != null && parentGroupUnit.UnitType == OThinker.Organization.UnitType.Group)
  279.                 { 
  280.                     OThinker.Organization.Group parentGroup = (OThinker.Organization.Group)parentGroupUnit;
  281.                     parentGroup.AddChild(group.UnitID);
  282.                     result = OThinker.H3.Server.Engine.Organization.UpdateUnit(this.UserValidator.UserID, parentGroup);
  283.                 }
  284.             }
  285.             // 显示结果
  286.             this.NotifyResult(
  287.                 result,
  288.                 result == OThinker.Organization.HandleResult.SUCCESS,
  289.                 this.Request.QueryString[Param_ExpandPath]);
  290.         }
  291.     }
  292. }