EditGroup.aspx.cs
资源名称:H3_OA.rar [点击查看]
上传用户:li2971742
上传日期:2021-11-18
资源大小:39096k
文件大小:13k
源码类别:
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
- {
- public partial class EditGroup : PortalPage
- {
- public const char Seperator = ';';
- #region 参数
- protected string ParentID
- {
- get
- {
- return HttpUtility.UrlDecode(this.Request.QueryString[Param_Parent]);
- }
- }
- protected string ParentGroupID
- {
- get
- {
- return HttpUtility.UrlDecode(this.Request.QueryString[Param_ParentGroup]);
- }
- }
- protected string EditID
- {
- get
- {
- return HttpUtility.UrlDecode(this.Request.QueryString[Param_ID]);
- }
- }
- private OThinker.Organization.Group _EditUnit;
- protected OThinker.Organization.Group EditUnit
- {
- get
- {
- if (this._EditUnit != null)
- {
- return this._EditUnit;
- }
- else if (EditID == null || EditID == "")
- {
- return null;
- }
- else
- {
- OThinker.Organization.Unit unit = OThinker.H3.Server.Engine.Organization.GetUnit(this.EditID);
- if (unit == null || unit.UnitType != OThinker.Organization.UnitType.Group)
- {
- return null;
- }
- this._EditUnit = (OThinker.Organization.Group)unit;
- return this._EditUnit;
- }
- }
- }
- #endregion
- private EditUserType _EditMode = EditUserType.Unspecified;
- /// <summary>
- /// 是否是自己修改自己信息的模式
- /// </summary>
- protected EditUserType EditMode
- {
- get
- {
- if (this._EditMode == EditUserType.Unspecified)
- {
- if (this.UserValidator.ValidateAdministrator())
- {
- if (this.EditID == null || this.EditID == "")
- {
- this._EditMode = EditUserType.Add;
- }
- else
- {
- this._EditMode = EditUserType.Admin;
- }
- }
- else
- {
- this._EditMode = EditUserType.View;
- }
- }
- return this._EditMode;
- }
- }
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!this.IsPostBack)
- {
- this.lnkRemove.Attributes.Add(
- "onClick",
- "if(confirm('确定要删除?'))location='" +
- PageName_RemoveUnit + "?" +
- Param_ID + "=" + this.EditID + "&" + Param_ExpandPath + "=" + this.Request.QueryString[Param_ExpandPath] +
- "'");
- this.lnkCreateChildGroup.NavigateUrl = PageName_EditGroup + "?" + Param_ParentGroup + "=" + this.EditID + "&" + Param_ExpandPath + "=" + this.Request.QueryString[Param_ExpandPath];
- // 返回按钮
- string q = HttpUtility.UrlDecode(this.Request.QueryString[Param_Q]);
- if (q == null || q == "")
- {
- this.lnkReturn.Visible = false;
- }
- else
- {
- this.lnkReturn.NavigateUrl = q;
- }
- // 按钮
- switch (this.EditMode)
- {
- case EditUserType.Add:
- this.lnkRemove.Visible = false;
- this.lnkCreateChildGroup.Visible = false;
- break;
- case EditUserType.Admin:
- if (this.EditUnit == null || !this.EditUnit.AllowChildGroup)
- {
- this.lnkCreateChildGroup.Visible = false;
- }
- break;
- case EditUserType.View:
- this.panelButtons.Visible = false;
- break;
- }
- // 公司
- this.lblCompany.Text = OThinker.H3.Server.Engine.Organization.Company.Name;
- // 父对象
- string parentId;
- OThinker.Organization.Unit parentGroup = null;
- if (this.EditUnit != null)
- {
- parentId = this.EditUnit.ParentID;
- }
- else if (this.ParentID != null && this.ParentID != "")
- {
- parentId = this.ParentID;
- }
- else if (this.ParentGroupID != null && this.ParentGroupID != "" &&
- (parentGroup = OThinker.H3.Server.Engine.Organization.GetUnit(this.ParentGroupID)) != null &&
- (parentGroup.UnitType == OThinker.Organization.UnitType.Group) &&
- ((OThinker.Organization.Group)parentGroup).ParentID != OThinker.H3.Server.Engine.Organization.Company.CompanyID)
- {
- parentId = ((OThinker.Organization.Group)parentGroup).ParentID;
- }
- else if (OThinker.H3.Server.Engine.Organization.GetUnit(OThinker.Organization.OrganizationUnit.GroupOUID) != null)
- {
- parentId = OThinker.Organization.OrganizationUnit.GroupOUID;
- }
- else
- {
- parentId = OThinker.H3.Server.Engine.Organization.Company.CompanyID;
- }
- string managerId = this.EditUnit == null ? null : this.EditUnit.ManagerID;
- switch (this.EditMode)
- {
- case EditUserType.Add:
- case EditUserType.Admin:
- this.txtParent.LoadSelection(OThinker.H3.Server.Engine.Organization, parentId);
- this.txtManager.LoadSelection(OThinker.H3.Server.Engine.Organization, managerId);
- this.lnkParent.Visible = false;
- this.lnkManager.Visible = false;
- break;
- case EditUserType.View:
- this.txtParent.Visible = false;
- this.txtManager.Visible = false;
- this.lnkParent.Text = OThinker.H3.Server.Engine.Organization.GetFullName(parentId);
- OThinker.Organization.Unit parentUnit = OThinker.H3.Server.Engine.Organization.GetUnit(parentId);
- if (parentUnit.UnitType == OThinker.Organization.UnitType.Company)
- {
- this.lnkParent.NavigateUrl = PageName_EditCompany;
- }
- else
- {
- this.lnkParent.NavigateUrl = PageName_EditOrganizationUnit + "?" + Param_ID + "=" + parentId;
- }
- if (managerId == null)
- {
- this.lnkManager.Text = "未设置";
- }
- else
- {
- this.lnkManager.Text = OThinker.H3.Server.Engine.Organization.GetFullName(managerId);
- this.lnkManager.NavigateUrl = PageName_EditUser + "?" + Param_ID + "=" + managerId;
- }
- break;
- }
- // 可见类型
- string[] visibilityTypeEnNames = Enum.GetNames(typeof(OThinker.Organization.VisibleType));
- foreach (string enName in visibilityTypeEnNames)
- {
- OThinker.Organization.VisibleType visibilityType = OThinker.Organization.VisibilityTypeConvertor.GetVisibilityType(enName);
- string cnName = OThinker.Organization.VisibilityTypeConvertor.GetName(visibilityType);
- this.lstVisibilityType.Items.Add(new ListItem(cnName, enName));
- }
- // 其他
- if (this.EditUnit != null)
- {
- this.lblPath.Text = OThinker.H3.Server.Engine.Organization.GetPath(this.EditUnit.UnitID);
- this.txtName.Text = this.EditUnit.Name;
- this.txtDescription.Text = this.EditUnit.Description;
- this.chkAllowChildGroup.Checked = this.EditUnit.AllowChildGroup;
- this.chkAllowMultiParentGroup.Checked = this.EditUnit.AllowMultiParentGroup;
- this.txtChildren.LoadSelection(OThinker.H3.Server.Engine.Organization, this.EditUnit.Children);
- this.txtChildren.GroupSelectable = this.chkAllowChildGroup.Checked;
- // 可见性
- this.lstVisibilityType.SelectedValue = this.EditUnit.Visibility.ToString();
- }
- switch (this.EditMode)
- {
- case EditUserType.View:
- this.txtName.Enabled = false;
- this.txtDescription.Enabled = false;
- this.chkAllowChildGroup.Enabled = false;
- this.chkAllowMultiParentGroup.Enabled = false;
- this.txtChildren.Editable = false;
- this.lstVisibilityType.Enabled = false;
- break;
- }
- }
- }
- protected void lnkOk_Click(object sender, EventArgs e)
- {
- // 检查是否合法
- OThinker.Organization.Unit parent = null;
- if (
- this.txtParent.SelectedUser == null || this.txtParent.SelectedUser == "" ||
- (parent = OThinker.H3.Server.Engine.Organization.GetUnit(this.txtParent.SelectedUser)) == null ||
- (parent.UnitType != OThinker.Organization.UnitType.Company && parent.UnitType != OThinker.Organization.UnitType.OrganizationUnit))
- {
- this.NotifyMessage("父对象设置为空");
- }
- OThinker.Organization.Group group;
- if (this.EditUnit == null)
- {
- group = new OThinker.Organization.Group(OThinker.H3.Server.Engine.Organization.Company.UnitID, this.txtParent.SelectedUser);
- }
- else
- {
- group = this.EditUnit;
- }
- group.Name = this.txtName.Text;
- group.Description = this.txtDescription.Text;
- group.AllowChildGroup = this.chkAllowChildGroup.Checked;
- group.AllowMultiParentGroup = this.chkAllowMultiParentGroup.Checked;
- group.ManagerID = this.txtManager.SelectedUser;
- group.ParentID = this.txtParent.SelectedUser;
- group.Children = this.txtChildren.SelectedUsers;
- // 可见类型
- group.Visibility = OThinker.Organization.VisibilityTypeConvertor.GetVisibilityType(this.lstVisibilityType.SelectedValue);
- // 写入服务器
- OThinker.Organization.HandleResult result = OThinker.Organization.HandleResult.SUCCESS;
- if (this.EditUnit == null)
- {
- OThinker.H3.Server.Engine.Organization.AddUnit(this.UserValidator.UserID, group, ref result);
- }
- else
- {
- result = OThinker.H3.Server.Engine.Organization.UpdateUnit(this.UserValidator.UserID, group);
- }
- if (result != OThinker.Organization.HandleResult.SUCCESS)
- {
- // 显示结果
- this.NotifyResult(
- result,
- result == OThinker.Organization.HandleResult.SUCCESS,
- this.Request.QueryString[Param_ExpandPath]);
- }
- // 编辑父组
- if (this.ParentGroupID != null && this.ParentGroupID != "")
- {
- OThinker.Organization.Unit parentGroupUnit = OThinker.H3.Server.Engine.Organization.GetUnit(this.ParentGroupID);
- if (parentGroupUnit != null && parentGroupUnit.UnitType == OThinker.Organization.UnitType.Group)
- {
- OThinker.Organization.Group parentGroup = (OThinker.Organization.Group)parentGroupUnit;
- parentGroup.AddChild(group.UnitID);
- result = OThinker.H3.Server.Engine.Organization.UpdateUnit(this.UserValidator.UserID, parentGroup);
- }
- }
- // 显示结果
- this.NotifyResult(
- result,
- result == OThinker.Organization.HandleResult.SUCCESS,
- this.Request.QueryString[Param_ExpandPath]);
- }
- }
- }