EditUser.aspx.cs
资源名称:H3_OA.rar [点击查看]
上传用户:li2971742
上传日期:2021-11-18
资源大小:39096k
文件大小:17k
源码类别:
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 EditUser : PortalPage
- {
- #region 参数
- protected string ParentID
- {
- get
- {
- return HttpUtility.UrlDecode(this.Request.QueryString[Param_Parent]);
- }
- }
- protected string Alias
- {
- get
- {
- return HttpUtility.UrlDecode(this.Request.QueryString[Param_Alias]);
- }
- }
- protected string ADUser
- {
- get
- {
- return HttpUtility.UrlDecode(this.Request.QueryString[Param_ADUser]);
- }
- }
- private string _EditID = OThinker.Organization.Unit.NullID;
- protected string EditID
- {
- get
- {
- if (this._EditID == OThinker.Organization.Unit.NullID)
- {
- string id = HttpUtility.UrlDecode(this.Request.QueryString[Param_ID]);
- if (id != null && id != "")
- {
- this._EditID = id;
- }
- else
- {
- this._EditID = OThinker.H3.Server.Engine.Organization.GetUserIDByAlias(this.Alias);
- }
- }
- return this._EditID;
- }
- }
- private EditUserType _EditMode = EditUserType.Unspecified;
- /// <summary>
- /// 是否是自己修改自己信息的模式
- /// </summary>
- protected EditUserType EditMode
- {
- get
- {
- if (this._EditMode == EditUserType.Unspecified)
- {
- this.ParseParam();
- }
- return this._EditMode;
- }
- }
- private OThinker.Organization.User _EditUnit = null;
- protected OThinker.Organization.User EditUnit
- {
- get
- {
- if (this._EditUnit == null)
- {
- this.ParseParam();
- }
- return this._EditUnit;
- }
- }
- private void ParseParam()
- {
- if (this.EditID == null || this.EditID == "")
- {
- if (this.UserValidator.ValidateAdministrator())
- {
- this._EditMode = EditUserType.Add;
- if (this.ADUser != null && this.ADUser != "")
- {
- OThinker.Organization.HandleResult result = OThinker.Organization.HandleResult.SUCCESS;
- this._EditUnit = OThinker.H3.Server.Engine.Organization.CreateUser(
- OThinker.H3.Server.Engine.SettingManager.ADPath,
- OThinker.H3.Server.Engine.SettingManager.ADUser,
- OThinker.H3.Server.Engine.SettingManager.ADPassword,
- this.ADUser,
- ref result);
- if (result != OThinker.Organization.HandleResult.SUCCESS)
- {
- this.NotifyResult(result);
- }
- this._EditUnit.ParentID = this.ParentID;
- }
- else
- {
- this._EditUnit = new OThinker.Organization.User(OThinker.H3.Server.Engine.Organization.Company.CompanyID, null, this.ParentID);
- }
- }
- else
- {
- this.NotifyMessage(LackOfAuth);
- }
- }
- else
- {
- OThinker.Organization.Unit unit = OThinker.H3.Server.Engine.Organization.GetUnit(this.EditID);
- if (unit == null || unit.UnitType != OThinker.Organization.UnitType.User)
- {
- this.NotifyMessage("该用户不存在");
- }
- else
- {
- this._EditUnit = (OThinker.Organization.User)unit;
- if (this.UserValidator.ValidateAdministrator())
- {
- // Check whether it is admin mode.
- string strMode = this.Request.QueryString[Param_Mode];
- if (strMode == null || strMode == "")
- {
- this._EditMode = EditUserType.Admin;
- }
- else
- {
- this._EditMode = (EditUserType)Enum.Parse(typeof(EditUserType), strMode);
- }
- }
- else if (this._EditUnit.UnitID == this.UserValidator.UserID)
- {
- this._EditMode = EditUserType.Profile;
- }
- else
- {
- this._EditMode = EditUserType.View;
- }
- }
- }
- }
- #endregion
- 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 + "'");
- // 返回按钮
- 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.lnkSetPassword.Visible = false;
- break;
- case EditUserType.Admin:
- break;
- case EditUserType.Profile:
- this.lnkRemove.Visible = false;
- break;
- case EditUserType.View:
- this.panelControl.Visible = false;
- break;
- }
- this.lnkSetPassword.NavigateUrl = PageName_SetPassword + "?" + Param_ID + "=" + this.EditID;
- // 父对象和经理
- string parentId = this.EditUnit.ParentID;
- string managerId = 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.Profile:
- 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;
- }
- // 公司
- this.lblCompany.Text = OThinker.H3.Server.Engine.Organization.Company.Name;
- this.lblPath.Text = this.EditMode == EditUserType.Add? null : OThinker.H3.Server.Engine.Organization.GetPath(this.EditID);
- // 成本
- this.txtPrice.Text = this.EditMode == EditUserType.Add ? "0" : this.EditUnit.Price.ToString();
- string domain = OThinker.H3.Server.Engine.SettingManager.DomainName;
- string domainPrefix = ((domain == null || domain == "") ? null : (domain + "\"));
- // 用户别名
- this.txtUserAlias.Text = this.EditUnit.Alias == null ? null : domainPrefix + this.EditUnit.Alias;
- if (this.txtUserAlias.Text != null && this.txtUserAlias.Text != "")
- {
- this.txtUserAlias.Enabled = false;
- }
- // 职务
- this.lstTitle.Items.Add(new ListItem("", OThinker.Organization.Title.NullTitleID.ToString()));
- OThinker.Organization.Title[] titles = OThinker.H3.Server.Engine.Organization.GetCompanyTitles();
- if (titles != null)
- {
- foreach (OThinker.Organization.Title title in titles)
- {
- this.lstTitle.Items.Add(new ListItem(title.Name, title.TitleID.ToString()));
- }
- }
- if (this.EditUnit != null && this.EditUnit.TitleID != null)
- {
- OThinker.Organization.Title title = OThinker.H3.Server.Engine.Organization.GetTitle(this.EditUnit.TitleID);
- if (title != null)
- {
- this.lstTitle.SelectedValue = title.TitleID.ToString();
- }
- }
- switch (this.EditMode)
- {
- case EditUserType.Add:
- case EditUserType.Admin:
- break;
- case EditUserType.Profile:
- case EditUserType.View:
- this.txtUserAlias.Enabled = false;
- this.txtPrice.Enabled = false;
- this.lstTitle.Enabled = false;
- break;
- default: throw new NotImplementedException();
- }
- // 委托
- if (this.EditMode != EditUserType.Add)
- {
- OThinker.Organization.User delegatee = (OThinker.Organization.User)OThinker.H3.Server.Engine.Organization.GetUnit(this.EditUnit.DelegateeID);
- if (delegatee != null)
- {
- this.txtDelegatee.LoadSelection(OThinker.H3.Server.Engine.Organization, delegatee.UnitID);
- }
- }
- // 通知
- this.chkNotify.Checked = this.EditUnit == null ? false : this.EditUnit.NotifyWorkItem;
- // 其他信息
- if (this.EditUnit != null)
- {
- // 地址
- this.lblAddress.Text = this.EditUnit == null ? null : this.EditUnit.Address;
- this.txtCountry.Text = this.EditUnit.CountryName;
- this.txtProvince.Text = this.EditUnit.Province;
- this.txtCity.Text = this.EditUnit.City;
- this.txtStreet.Text = this.EditUnit.Street;
- this.txtPostalCode.Text = this.EditUnit.PostalCode;
- this.txtDescription.Text = this.EditUnit.Description;
- this.txtEmail.Text = this.EditUnit.Email;
- this.txtMobile.Text = this.EditUnit.Mobile;
- this.txtOfficePhone.Text = this.EditUnit.OfficePhone;
- this.txtUserName.Text = this.EditUnit.Name;
- }
- switch (this.EditMode)
- {
- case EditUserType.Add:
- case EditUserType.Admin:
- case EditUserType.Profile:
- break;
- case EditUserType.View:
- this.txtCountry.Enabled = false;
- this.txtProvince.Enabled = false;
- this.txtCity.Enabled = false;
- this.txtStreet.Enabled = false;
- this.txtPostalCode.Enabled = false;
- this.txtDelegatee.Editable = false;
- this.chkNotify.Enabled = false;
- this.txtDescription.Enabled = false;
- this.txtEmail.Enabled = false;
- this.txtMobile.Enabled = false;
- this.txtOfficePhone.Enabled = false;
- this.txtUserName.Enabled = false;
- break;
- default: throw new NotImplementedException();
- }
- }
- }
- protected void lnkOk_Click(object sender, EventArgs e)
- {
- OThinker.Organization.User user = null;
- // 检查是否合法
- OThinker.Organization.Unit parent = null;
- if (
- (this.txtParent.Visible == true) &&
- (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("父对象设置为空");
- }
- if (this.txtUserAlias.Enabled && !OThinker.Organization.User.Validate(this.txtUserAlias.Text))
- {
- this.NotifyMessage("用户别名不合法");
- }
- if (this.txtUserAlias.Enabled)
- {
- this.EditUnit.Alias = this.txtUserAlias.Text;
- }
- this.EditUnit.DelegateeID = this.txtDelegatee.SelectedUser;
- this.EditUnit.Description = this.txtDescription.Text;
- this.EditUnit.Email = this.txtEmail.Text;
- this.EditUnit.NotifyWorkItem = this.chkNotify.Checked;
- this.EditUnit.ManagerID = this.txtManager.SelectedUser;
- this.EditUnit.Mobile = this.txtMobile.Text;
- this.EditUnit.OfficePhone = this.txtOfficePhone.Text;
- this.EditUnit.Name = this.txtUserName.Text;
- if (this.txtParent.Visible == true)
- {
- this.EditUnit.ParentID = this.txtParent.SelectedUser;
- }
- // 地址
- this.EditUnit.CountryName = this.txtCountry.Text;
- this.EditUnit.Province = this.txtProvince.Text;
- this.EditUnit.City = this.txtCity.Text;
- this.EditUnit.Street = this.txtStreet.Text;
- this.EditUnit.PostalCode = this.txtPostalCode.Text;
- if (this.lstTitle.SelectedValue != null && this.lstTitle.SelectedValue != "")
- {
- this.EditUnit.TitleID = this.lstTitle.SelectedValue;
- }
- else
- {
- this.EditUnit.TitleID = OThinker.Organization.Title.NullTitleID;
- }
- try
- {
- this.EditUnit.Price = double.Parse(this.txtPrice.Text);
- }
- catch
- {
- this.NotifyMessage("输入的成本字段必须为数值型");
- }
- // 写入服务器
- OThinker.Organization.HandleResult result = OThinker.Organization.HandleResult.SUCCESS;
- if (this.EditMode == EditUserType.Add)
- {
- OThinker.H3.Server.Engine.Organization.AddUnit(this.UserValidator.UserID, this.EditUnit, ref result);
- }
- else
- {
- result = OThinker.H3.Server.Engine.Organization.UpdateUnit(this.UserValidator.UserID, this.EditUnit);
- }
- if (this.EditMode == EditUserType.Profile)
- {
- this.NotifyMessage("修改成功");
- }
- else
- {
- // 显示结果
- this.NotifyResult(result, result == OThinker.Organization.HandleResult.SUCCESS, this.Request.QueryString[Param_ExpandPath]);
- }
- }
- }
- }