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

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 EditUser : 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 Alias
  24.         {
  25.             get
  26.             {
  27.                 return HttpUtility.UrlDecode(this.Request.QueryString[Param_Alias]);
  28.             }
  29.         }
  30.         protected string ADUser
  31.         {
  32.             get
  33.             {
  34.                 return HttpUtility.UrlDecode(this.Request.QueryString[Param_ADUser]);
  35.             }
  36.         }
  37.         private string _EditID = OThinker.Organization.Unit.NullID;
  38.         protected string EditID
  39.         {
  40.             get
  41.             {
  42.                 if (this._EditID == OThinker.Organization.Unit.NullID)
  43.                 {
  44.                     string id = HttpUtility.UrlDecode(this.Request.QueryString[Param_ID]);
  45.                     if (id != null && id != "")
  46.                     {
  47.                         this._EditID = id;
  48.                     }
  49.                     else
  50.                     {
  51.                         this._EditID = OThinker.H3.Server.Engine.Organization.GetUserIDByAlias(this.Alias);
  52.                     }
  53.                 }
  54.                 return this._EditID;
  55.             }
  56.         }
  57.         private EditUserType _EditMode = EditUserType.Unspecified;
  58.         /// <summary>
  59.         /// 是否是自己修改自己信息的模式
  60.         /// </summary>
  61.         protected EditUserType EditMode
  62.         {
  63.             get
  64.             {
  65.                 if (this._EditMode == EditUserType.Unspecified)
  66.                 {
  67.                     this.ParseParam();
  68.                 }
  69.                 return this._EditMode;
  70.             }
  71.         }
  72.         private OThinker.Organization.User _EditUnit = null;
  73.         protected OThinker.Organization.User EditUnit
  74.         {
  75.             get
  76.             {
  77.                 if (this._EditUnit == null)
  78.                 {
  79.                     this.ParseParam();
  80.                 }
  81.                 return this._EditUnit;
  82.             }
  83.         }
  84.         private void ParseParam()
  85.         {
  86.             if (this.EditID == null || this.EditID == "")
  87.             {
  88.                 if (this.UserValidator.ValidateAdministrator())
  89.                 {
  90.                     this._EditMode = EditUserType.Add;
  91.                     if (this.ADUser != null && this.ADUser != "")
  92.                     {
  93.                         OThinker.Organization.HandleResult result = OThinker.Organization.HandleResult.SUCCESS;
  94.                         this._EditUnit = OThinker.H3.Server.Engine.Organization.CreateUser(
  95.                             OThinker.H3.Server.Engine.SettingManager.ADPath,
  96.                             OThinker.H3.Server.Engine.SettingManager.ADUser,
  97.                             OThinker.H3.Server.Engine.SettingManager.ADPassword,
  98.                             this.ADUser,
  99.                             ref result);
  100.                         if (result != OThinker.Organization.HandleResult.SUCCESS)
  101.                         {
  102.                             this.NotifyResult(result);
  103.                         }
  104.                         this._EditUnit.ParentID = this.ParentID;
  105.                     }
  106.                     else
  107.                     {
  108.                         this._EditUnit = new OThinker.Organization.User(OThinker.H3.Server.Engine.Organization.Company.CompanyID, null, this.ParentID);
  109.                     }
  110.                 }
  111.                 else
  112.                 {
  113.                     this.NotifyMessage(LackOfAuth);
  114.                 }
  115.             }
  116.             else
  117.             {
  118.                 OThinker.Organization.Unit unit = OThinker.H3.Server.Engine.Organization.GetUnit(this.EditID);
  119.                 if (unit == null || unit.UnitType != OThinker.Organization.UnitType.User)
  120.                 {
  121.                     this.NotifyMessage("该用户不存在");
  122.                 }
  123.                 else
  124.                 {
  125.                     this._EditUnit = (OThinker.Organization.User)unit;
  126.                     if (this.UserValidator.ValidateAdministrator())
  127.                     {
  128.                         // Check whether it is admin mode.
  129.                         string strMode = this.Request.QueryString[Param_Mode];
  130.                         if (strMode == null || strMode == "")
  131.                         {
  132.                             this._EditMode = EditUserType.Admin;
  133.                         }
  134.                         else
  135.                         {
  136.                             this._EditMode = (EditUserType)Enum.Parse(typeof(EditUserType), strMode);
  137.                         }
  138.                     }
  139.                     else if (this._EditUnit.UnitID == this.UserValidator.UserID)
  140.                     {
  141.                         this._EditMode = EditUserType.Profile;
  142.                     }
  143.                     else
  144.                     {
  145.                         this._EditMode = EditUserType.View;
  146.                     }
  147.                 }
  148.             }
  149.         }
  150.         #endregion
  151.         protected void Page_Load(object sender, EventArgs e)
  152.         {
  153.             if (!this.IsPostBack)
  154.             {
  155.                 this.lnkRemove.Attributes.Add("onClick", "if(confirm('确定要删除?'))location='" + PageName_RemoveUnit + "?" + Param_ID + "=" + this.EditID + "'");
  156.                 
  157.                 // 返回按钮
  158.                 string q = HttpUtility.UrlDecode(this.Request.QueryString[Param_Q]);
  159.                 if (q == null || q == "")
  160.                 {
  161.                     this.lnkReturn.Visible = false;
  162.                 }
  163.                 else
  164.                 {
  165.                     this.lnkReturn.NavigateUrl = q;
  166.                 }
  167.                 // 按钮
  168.                 switch (this.EditMode)
  169.                 {
  170.                     case EditUserType.Add:
  171.                         this.lnkRemove.Visible = false;
  172.                         this.lnkSetPassword.Visible = false;
  173.                         break;
  174.                     case EditUserType.Admin:
  175.                         break;
  176.                     case EditUserType.Profile:
  177.                         this.lnkRemove.Visible = false;
  178.                         break;
  179.                     case EditUserType.View:
  180.                         this.panelControl.Visible = false;
  181.                         break;
  182.                 }
  183.                 this.lnkSetPassword.NavigateUrl = PageName_SetPassword + "?" + Param_ID + "=" + this.EditID;
  184.                 // 父对象和经理
  185.                 string parentId = this.EditUnit.ParentID;
  186.                 string managerId = this.EditUnit.ManagerID;
  187.                 switch (this.EditMode)
  188.                 {
  189.                     case EditUserType.Add:
  190.                     case EditUserType.Admin:
  191.                         this.txtParent.LoadSelection(OThinker.H3.Server.Engine.Organization, parentId);
  192.                         this.txtManager.LoadSelection(OThinker.H3.Server.Engine.Organization, managerId);
  193.                         this.lnkParent.Visible = false;
  194.                         this.lnkManager.Visible = false;
  195.                         break;
  196.                     case EditUserType.Profile:
  197.                     case EditUserType.View:
  198.                         this.txtParent.Visible = false;
  199.                         this.txtManager.Visible = false;
  200.                         this.lnkParent.Text = OThinker.H3.Server.Engine.Organization.GetFullName(parentId);
  201.                         OThinker.Organization.Unit parentUnit = OThinker.H3.Server.Engine.Organization.GetUnit(parentId);
  202.                         if (parentUnit.UnitType == OThinker.Organization.UnitType.Company)
  203.                         {
  204.                             this.lnkParent.NavigateUrl = PageName_EditCompany;
  205.                         }
  206.                         else
  207.                         {
  208.                             this.lnkParent.NavigateUrl = PageName_EditOrganizationUnit + "?" + Param_ID + "=" + parentId;
  209.                         }
  210.                         if (managerId == null)
  211.                         {
  212.                             this.lnkManager.Text = "未设置";
  213.                         }
  214.                         else
  215.                         {
  216.                             this.lnkManager.Text = OThinker.H3.Server.Engine.Organization.GetFullName(managerId);
  217.                             this.lnkManager.NavigateUrl = PageName_EditUser + "?" + Param_ID + "=" + managerId;
  218.                         }
  219.                         break;
  220.                 }
  221.                 // 公司
  222.                 this.lblCompany.Text = OThinker.H3.Server.Engine.Organization.Company.Name;
  223.                 this.lblPath.Text = this.EditMode == EditUserType.Add? null : OThinker.H3.Server.Engine.Organization.GetPath(this.EditID);
  224.                 // 成本
  225.                 this.txtPrice.Text = this.EditMode == EditUserType.Add ? "0" : this.EditUnit.Price.ToString();
  226.                 string domain = OThinker.H3.Server.Engine.SettingManager.DomainName;
  227.                 string domainPrefix = ((domain == null || domain == "") ? null : (domain + "\"));
  228.                 // 用户别名
  229.                 this.txtUserAlias.Text = this.EditUnit.Alias == null ? null : domainPrefix + this.EditUnit.Alias;
  230.                 if (this.txtUserAlias.Text != null && this.txtUserAlias.Text != "")
  231.                 {
  232.                     this.txtUserAlias.Enabled = false;
  233.                 }
  234.                 // 职务
  235.                 this.lstTitle.Items.Add(new ListItem("", OThinker.Organization.Title.NullTitleID.ToString()));
  236.                 OThinker.Organization.Title[] titles = OThinker.H3.Server.Engine.Organization.GetCompanyTitles();
  237.                 if (titles != null)
  238.                 {
  239.                     foreach (OThinker.Organization.Title title in titles)
  240.                     {
  241.                         this.lstTitle.Items.Add(new ListItem(title.Name, title.TitleID.ToString()));
  242.                     }
  243.                 }
  244.                 if (this.EditUnit != null && this.EditUnit.TitleID != null)
  245.                 {
  246.                     OThinker.Organization.Title title = OThinker.H3.Server.Engine.Organization.GetTitle(this.EditUnit.TitleID);
  247.                     if (title != null)
  248.                     {
  249.                         this.lstTitle.SelectedValue = title.TitleID.ToString();
  250.                     }
  251.                 }
  252.                 switch (this.EditMode)
  253.                 {
  254.                     case EditUserType.Add:
  255.                     case EditUserType.Admin:
  256.                         break;
  257.                     case EditUserType.Profile:
  258.                     case EditUserType.View:
  259.                         this.txtUserAlias.Enabled = false;
  260.                         this.txtPrice.Enabled = false;
  261.                         this.lstTitle.Enabled = false;
  262.                         break;
  263.                     default: throw new NotImplementedException();
  264.                 }
  265.                 // 委托
  266.                 if (this.EditMode != EditUserType.Add)
  267.                 {
  268.                     OThinker.Organization.User delegatee = (OThinker.Organization.User)OThinker.H3.Server.Engine.Organization.GetUnit(this.EditUnit.DelegateeID);
  269.                     if (delegatee != null)
  270.                     {
  271.                         this.txtDelegatee.LoadSelection(OThinker.H3.Server.Engine.Organization, delegatee.UnitID);
  272.                     }
  273.                 }
  274.                 // 通知
  275.                 this.chkNotify.Checked = this.EditUnit == null ? false : this.EditUnit.NotifyWorkItem;
  276.                 // 其他信息
  277.                 if (this.EditUnit != null)
  278.                 {
  279.                     // 地址
  280.                     this.lblAddress.Text = this.EditUnit == null ? null : this.EditUnit.Address;
  281.                     this.txtCountry.Text = this.EditUnit.CountryName;
  282.                     this.txtProvince.Text = this.EditUnit.Province;
  283.                     this.txtCity.Text = this.EditUnit.City;
  284.                     this.txtStreet.Text = this.EditUnit.Street;
  285.                     this.txtPostalCode.Text = this.EditUnit.PostalCode;
  286.                     this.txtDescription.Text = this.EditUnit.Description;
  287.                     this.txtEmail.Text = this.EditUnit.Email;
  288.                     this.txtMobile.Text = this.EditUnit.Mobile;
  289.                     this.txtOfficePhone.Text = this.EditUnit.OfficePhone;
  290.                     this.txtUserName.Text = this.EditUnit.Name;
  291.                 }
  292.                 switch (this.EditMode)
  293.                 {
  294.                     case EditUserType.Add:
  295.                     case EditUserType.Admin:
  296.                     case EditUserType.Profile:
  297.                         break;
  298.                     case EditUserType.View:
  299.                         this.txtCountry.Enabled = false;
  300.                         this.txtProvince.Enabled = false;
  301.                         this.txtCity.Enabled = false;
  302.                         this.txtStreet.Enabled = false;
  303.                         this.txtPostalCode.Enabled = false;
  304.                         this.txtDelegatee.Editable = false;
  305.                         this.chkNotify.Enabled = false;
  306.                         this.txtDescription.Enabled = false;
  307.                         this.txtEmail.Enabled = false;
  308.                         this.txtMobile.Enabled = false;
  309.                         this.txtOfficePhone.Enabled = false;
  310.                         this.txtUserName.Enabled = false;
  311.                         break;
  312.                     default: throw new NotImplementedException();
  313.                 }
  314.             }
  315.         }
  316.         protected void lnkOk_Click(object sender, EventArgs e)
  317.         {
  318.             OThinker.Organization.User user = null;
  319.             // 检查是否合法
  320.             OThinker.Organization.Unit parent = null;
  321.             if (
  322.                 (this.txtParent.Visible == true) &&
  323.                 (this.txtParent.SelectedUser == null || this.txtParent.SelectedUser == "" ||
  324.                 (parent = OThinker.H3.Server.Engine.Organization.GetUnit(this.txtParent.SelectedUser)) == null ||
  325.                 (parent.UnitType != OThinker.Organization.UnitType.Company && parent.UnitType != OThinker.Organization.UnitType.OrganizationUnit)))
  326.             {
  327.                 this.NotifyMessage("父对象设置为空");
  328.             }
  329.             if (this.txtUserAlias.Enabled && !OThinker.Organization.User.Validate(this.txtUserAlias.Text))
  330.             {
  331.                 this.NotifyMessage("用户别名不合法");
  332.             }
  333.             if (this.txtUserAlias.Enabled)
  334.             {
  335.                 this.EditUnit.Alias = this.txtUserAlias.Text;
  336.             }
  337.             this.EditUnit.DelegateeID = this.txtDelegatee.SelectedUser;
  338.             this.EditUnit.Description = this.txtDescription.Text;
  339.             this.EditUnit.Email = this.txtEmail.Text;
  340.             this.EditUnit.NotifyWorkItem = this.chkNotify.Checked;
  341.             this.EditUnit.ManagerID = this.txtManager.SelectedUser;
  342.             this.EditUnit.Mobile = this.txtMobile.Text;
  343.             this.EditUnit.OfficePhone = this.txtOfficePhone.Text;
  344.             this.EditUnit.Name = this.txtUserName.Text;
  345.             if (this.txtParent.Visible == true)
  346.             {
  347.                 this.EditUnit.ParentID = this.txtParent.SelectedUser;
  348.             }
  349.             // 地址
  350.             this.EditUnit.CountryName = this.txtCountry.Text;
  351.             this.EditUnit.Province = this.txtProvince.Text;
  352.             this.EditUnit.City = this.txtCity.Text;
  353.             this.EditUnit.Street = this.txtStreet.Text;
  354.             this.EditUnit.PostalCode = this.txtPostalCode.Text;
  355.             
  356.             if (this.lstTitle.SelectedValue != null && this.lstTitle.SelectedValue != "")
  357.             {
  358.                 this.EditUnit.TitleID = this.lstTitle.SelectedValue;
  359.             }
  360.             else
  361.             {
  362.                 this.EditUnit.TitleID = OThinker.Organization.Title.NullTitleID;
  363.             }
  364.             try
  365.             {
  366.                 this.EditUnit.Price = double.Parse(this.txtPrice.Text);
  367.             }
  368.             catch
  369.             {
  370.                 this.NotifyMessage("输入的成本字段必须为数值型");
  371.             }
  372.             // 写入服务器
  373.             OThinker.Organization.HandleResult result = OThinker.Organization.HandleResult.SUCCESS;
  374.             if (this.EditMode == EditUserType.Add)
  375.             {
  376.                 OThinker.H3.Server.Engine.Organization.AddUnit(this.UserValidator.UserID, this.EditUnit, ref result);
  377.             }
  378.             else
  379.             {
  380.                 result = OThinker.H3.Server.Engine.Organization.UpdateUnit(this.UserValidator.UserID, this.EditUnit);
  381.             }
  382.             if (this.EditMode == EditUserType.Profile)
  383.             {
  384.                 this.NotifyMessage("修改成功");
  385.             }
  386.             else
  387.             {
  388.                 // 显示结果
  389.                 this.NotifyResult(result, result == OThinker.Organization.HandleResult.SUCCESS, this.Request.QueryString[Param_ExpandPath]);
  390.             }
  391.         }
  392.     }
  393. }