EditOrganizationUnit.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 EditOrganizationUnit : PortalPage
- {
- #region 参数
- protected string ParentID
- {
- get
- {
- return HttpUtility.UrlDecode(this.Request.QueryString[Param_Parent]);
- }
- }
- protected string EditID
- {
- get
- {
- return HttpUtility.UrlDecode(this.Request.QueryString[Param_ID]);
- }
- }
- private OThinker.Organization.OrganizationUnit _EditUnit;
- protected OThinker.Organization.OrganizationUnit 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.OrganizationUnit)
- {
- return null;
- }
- this._EditUnit = (OThinker.Organization.OrganizationUnit)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] + "'");
- // 返回按钮
- 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.lnkAddOrganizationUnit.Visible = false;
- this.lnkAddGroup.Visible = false;
- this.lnkAddUser.Visible = false;
- this.lnkSyncUser.Visible = false;
- this.lnkSyncAllUsers.Visible = false;
- break;
- case EditUserType.Admin:
- string param = "?" + Param_Parent + "=" + this.EditID + "&" + Param_Q + "=" + HttpUtility.UrlEncode(this.Request.Url.AbsoluteUri) + "&" + Param_ExpandPath + "=" + this.Request.QueryString[Param_ExpandPath];
- if (this.EditUnit.CanAddOrgUnit)
- {
- this.lnkAddOrganizationUnit.NavigateUrl = PageName_EditOrganizationUnit + param;
- }
- else
- {
- this.lnkAddOrganizationUnit.Visible = false;
- }
- if (this.EditUnit.CanAddGroup)
- {
- this.lnkAddGroup.NavigateUrl = PageName_EditGroup + param;
- }
- else
- {
- this.lnkAddGroup.Visible = false;
- }
- if (this.EditUnit.CanAddUser)
- {
- this.lnkAddUser.NavigateUrl = PageName_EditUser + param;
- this.lnkSyncUser.NavigateUrl = PageName_SyncUser + param;
- this.lnkSyncAllUsers.NavigateUrl = PageName_SyncAllUsers + param;
- }
- else
- {
- this.lnkAddUser.Visible = false;
- this.lnkSyncUser.Visible = false;
- this.lnkSyncAllUsers.Visible = false;
- }
- break;
- case EditUserType.View:
- this.panelEdit.Visible = false;
- break;
- default:
- throw new NotImplementedException();
- }
- // 公司
- this.lblCompany.Text = OThinker.H3.Server.Engine.Organization.Company.Name;
- // 父对象
- string parent = this.EditUnit == null ? this.ParentID : this.EditUnit.ParentID;
- 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, parent);
- 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(parent);
- OThinker.Organization.Unit parentUnit = OThinker.H3.Server.Engine.Organization.GetUnit(parent);
- if (parentUnit.UnitType == OThinker.Organization.UnitType.Company)
- {
- this.lnkParent.NavigateUrl = PageName_EditCompany;
- }
- else
- {
- this.lnkParent.NavigateUrl = PageName_EditOrganizationUnit + "?" + Param_ID + "=" + parent;
- }
- 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;
- default:
- throw new NotImplementedException();
- }
- // 可见类型
- 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.EditID);
- this.txtName.Text = this.EditUnit.Name;
- this.txtDescription.Text = this.EditUnit.Description;
- this.chkOrgUnit.Checked = this.EditUnit.CanAddOrgUnit;
- this.chkGroup.Checked = this.EditUnit.CanAddGroup;
- this.chkUser.Checked = this.EditUnit.CanAddUser;
- // 可见性
- this.lstVisibilityType.SelectedValue = this.EditUnit.Visibility.ToString();
- }
- else
- {
- this.chkOrgUnit.Checked = true;
- this.chkGroup.Checked = true;
- this.chkUser.Checked = true;
- }
- switch (this.EditMode)
- {
- case EditUserType.Add:
- case EditUserType.Admin:
- break;
- case EditUserType.View:
- this.txtName.Enabled = false;
- this.txtDescription.Enabled = false;
- this.chkOrgUnit.Enabled = false;
- this.chkGroup.Enabled = false;
- this.chkUser.Enabled = false;
- this.lstVisibilityType.Enabled = false;
- break;
- default:
- throw new NotImplementedException();
- }
- }
- }
- 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.OrganizationUnit unit = null;
- if (this.EditUnit == null)
- {
- unit = new OThinker.Organization.OrganizationUnit(OThinker.H3.Server.Engine.Organization.Company.UnitID, this.txtParent.SelectedUser);
- }
- else
- {
- unit = this.EditUnit;
- }
- unit.Name = this.txtName.Text;
- unit.Description = this.txtDescription.Text;
- unit.ManagerID = this.txtManager.SelectedUser;
- unit.ParentID = this.txtParent.SelectedUser;
- unit.CanAddOrgUnit = this.chkOrgUnit.Checked;
- unit.CanAddGroup = this.chkGroup.Checked;
- unit.CanAddUser = this.chkUser.Checked;
- // 可见类型
- unit.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, unit, ref result);
- }
- else
- {
- result = OThinker.H3.Server.Engine.Organization.UpdateUnit(this.UserValidator.UserID, unit);
- }
- // 显示结果
- this.NotifyResult(
- result,
- result == OThinker.Organization.HandleResult.SUCCESS,
- this.Request.QueryString[Param_ExpandPath]);
- }
- }
- }