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