protected void Page_Load(object sender, EventArgs e) { this.Account.Attributes.Add("validate_url", "CheckAccount.ashx"); FoWoSoft.Platform.Organize borganize = new FoWoSoft.Platform.Organize(); FoWoSoft.Platform.Users busers = new FoWoSoft.Platform.Users(); string id = Request.QueryString["id"]; string name = string.Empty; string account = string.Empty; string status = string.Empty; string note = string.Empty; Guid parentID; if (IsPostBack && id.IsGuid(out parentID)) { name = Request.Form["Name"]; account = Request.Form["Account"]; status = Request.Form["Status"]; note = Request.Form["Note"]; Guid userID = Guid.NewGuid(); string userXML = string.Empty; using (System.Transactions.TransactionScope scope = new System.Transactions.TransactionScope()) { //添加人员 FoWoSoft.Data.Model.Users user = new FoWoSoft.Data.Model.Users(); user.Account = account.Trim(); user.Name = name.Trim(); user.Note = note.IsNullOrEmpty() ? null : note; user.Password = busers.GetUserEncryptionPassword(userID.ToString(), busers.GetInitPassword()); user.Sort = 1; user.Status = status.IsInt() ? status.ToInt() : 0; user.ID = userID; busers.Add(user); //添加关系 FoWoSoft.Data.Model.UsersRelation userRelation = new FoWoSoft.Data.Model.UsersRelation(); userRelation.IsMain = 1; userRelation.OrganizeID = parentID; userRelation.Sort = new FoWoSoft.Platform.UsersRelation().GetMaxSort(parentID); userRelation.UserID = userID; new FoWoSoft.Platform.UsersRelation().Add(userRelation); //更新父级[ChildsLength]字段 borganize.UpdateChildsLength(parentID); //更新角色 new FoWoSoft.Platform.UsersRole().UpdateByUserID(userID); userXML = user.Serialize(); scope.Complete(); } FoWoSoft.Platform.Log.Add("添加了人员", userXML, FoWoSoft.Platform.Log.Types.组织机构); Page.ClientScript.RegisterStartupScript(Page.GetType(), "ok", "alert('添加成功!');parent.frames[0].reLoad('" + id + "');window.location=window.location;", true); } this.StatusRadios.Text = borganize.GetStatusRadio("Status", "0", "validate=\"radio\""); }
protected void Page_Load(object sender, EventArgs e) { FoWoSoft.Platform.Organize borganize = new FoWoSoft.Platform.Organize(); FoWoSoft.Data.Model.Organize org = null; string id = Request.QueryString["id"]; string name = string.Empty; string type = string.Empty; string status = string.Empty; string note = string.Empty; Guid orgID; if (id.IsGuid(out orgID)) { org = borganize.Get(orgID); } if (IsPostBack && org != null) { name = Request.Form["Name"]; type = Request.Form["Type"]; status = Request.Form["Status"]; note = Request.Form["note"]; FoWoSoft.Data.Model.Organize org1 = new FoWoSoft.Data.Model.Organize(); Guid org1ID = Guid.NewGuid(); org1.ID = org1ID; org1.Name = name.Trim(); org1.Note = note.IsNullOrEmpty() ? null : note.Trim(); org1.Number = org.Number + "," + org1ID.ToString().ToLower(); org1.ParentID = org.ID; org1.Sort = borganize.GetMaxSort(org.ID); org1.Status = status.IsInt() ? status.ToInt() : 0; org1.Type = type.ToInt(); org1.Depth = org.Depth + 1; using (System.Transactions.TransactionScope scope = new System.Transactions.TransactionScope()) { borganize.Add(org1); //更新父级[ChildsLength]字段 borganize.UpdateChildsLength(org.ID); scope.Complete(); } FoWoSoft.Platform.Log.Add("添加了组织机构", org1.Serialize(), FoWoSoft.Platform.Log.Types.组织机构); Page.ClientScript.RegisterStartupScript(Page.GetType(), "ok", "alert('添加成功!');parent.frames[0].reLoad('" + id + "');window.location=window.location;", true); } this.TypeRadios.Text = borganize.GetTypeRadio("Type", type, "validate=\"radio\""); this.StatusRadios.Text = borganize.GetStatusRadio("Status", "0", "validate=\"radio\""); }
/// <summary> /// 重建组织结构 /// </summary> /// <param name="g">首Guid</param> public void organizeResize(Guid g) { var first = borganize.Get(g); var s = borganize.GetChilds(first.ID); if (s == null) { return; } foreach (var org in s) { org.Number = org.ParentID.ToString() + "," + first.ID.ToString().ToLower(); borganize.Update(org); borganize.UpdateChildsLength(org.ID); organizeResize(org.ID); } }
protected void Page_Load(object sender, EventArgs e) { FoWoSoft.Platform.Organize borganize = new FoWoSoft.Platform.Organize(); FoWoSoft.Platform.Users busers = new FoWoSoft.Platform.Users(); FoWoSoft.Platform.UsersRelation buserRelation = new FoWoSoft.Platform.UsersRelation(); FoWoSoft.Data.Model.Users user = null; FoWoSoft.Data.Model.Organize organize = null; string id = Request.QueryString["id"]; string parentID = Request.QueryString["parentid"]; string parentString = string.Empty; this.Account.Attributes.Add("validate_url", "CheckAccount.ashx?id=" + id); Guid userID, organizeID; if (id.IsGuid(out userID)) { user = busers.Get(userID); if (user != null) { //所在组织字符串 System.Text.StringBuilder sb = new System.Text.StringBuilder(); var userRelations = buserRelation.GetAllByUserID(user.ID).OrderByDescending(p => p.IsMain); foreach (var userRelation in userRelations) { sb.Append("<div style='margin:3px 0;'>"); sb.Append(borganize.GetAllParentNames(userRelation.OrganizeID, true)); if (userRelation.IsMain == 0) { sb.Append("<span style='color:#999'> [兼职]</span>"); } sb.Append("</div>"); } this.ParentString.Text = sb.ToString(); var roles = new FoWoSoft.Platform.UsersRole().GetByUserIDFromCache(userID); FoWoSoft.Platform.Role brole = new FoWoSoft.Platform.Role(); System.Text.StringBuilder rolesb = new System.Text.StringBuilder(); foreach (var role in roles) { var role1 = brole.Get(role.RoleID); if (role1 == null) { continue; } rolesb.Append(role1.Name); rolesb.Append(","); } this.RoleString.Text = rolesb.ToString().TrimEnd(','); } } if (parentID.IsGuid(out organizeID)) { organize = borganize.Get(organizeID); } if (IsPostBack) { #region 保存 if (!Request.Form["Save"].IsNullOrEmpty() && user != null) { string name = Request.Form["Name"]; string account = Request.Form["Account"]; string status = Request.Form["Status"]; string note = Request.Form["Note"]; string oldXML = user.Serialize(); user.Name = name.Trim(); user.Account = account.Trim(); user.Status = status.ToInt(1); user.Note = note.IsNullOrEmpty() ? null : note.Trim(); busers.Update(user); FoWoSoft.Platform.Log.Add("修改了用户", "", FoWoSoft.Platform.Log.Types.组织机构, oldXML, user.Serialize()); Page.ClientScript.RegisterStartupScript(Page.GetType(), "ok", "alert('保存成功!');parent.frames[0].reLoad('" + parentID + "');", true); } #endregion #region 除用户 if (!Request.Form["DeleteBut"].IsNullOrEmpty() && user != null && organize != null) { using (System.Transactions.TransactionScope scope = new System.Transactions.TransactionScope()) { var urs = buserRelation.GetAllByUserID(user.ID); busers.Delete(user.ID); buserRelation.DeleteByUserID(user.ID); new FoWoSoft.Platform.UsersInfo().Delete(user.ID); new FoWoSoft.Platform.UsersRole().DeleteByUserID(user.ID); //更新父级[ChildsLength]字段 foreach (var ur in urs) { borganize.UpdateChildsLength(ur.OrganizeID); } scope.Complete(); } string refreshID = parentID; string url = string.Empty; var users = borganize.GetAllUsers(refreshID.ToGuid()); if (users.Count > 0) { url = "User.aspx?id=" + users.Last().ID + "&appid=" + Request.QueryString["appid"] + "&tabid=" + Request.QueryString["tabid"] + "&parentid=" + parentID; } else { refreshID = organize.ParentID == Guid.Empty ? organize.ID.ToString() : organize.ParentID.ToString(); url = "Body.aspx?id=" + parentID + "&appid=" + Request.QueryString["appid"] + "&tabid=" + Request.QueryString["tabid"] + "&parentid=" + organize.ParentID; } FoWoSoft.Platform.Log.Add("删除了用户", user.Serialize(), FoWoSoft.Platform.Log.Types.组织机构); Page.ClientScript.RegisterStartupScript(Page.GetType(), "ok", "alert('删除成功');parent.frames[0].reLoad('" + refreshID + "');window.location='" + url + "'", true); new FoWoSoft.Platform.AppLibrary().ClearUseMemberCache(); } #endregion #region 初始化密码 if (!Request.Form["InitPass"].IsNullOrEmpty() && user != null) { string initpass = busers.GetInitPassword(); busers.InitPassword(user.ID); FoWoSoft.Platform.Log.Add("初始化了用户密码", user.Serialize(), FoWoSoft.Platform.Log.Types.组织机构); Page.ClientScript.RegisterStartupScript(Page.GetType(), "ok", "alert('密码已初始化为:" + initpass + "');", true); } #endregion #region 调动 if (!Request.Form["Move1"].IsNullOrEmpty() && user != null) { string moveto = Request.Form["movetostation"]; string movetostationjz = Request.Form["movetostationjz"]; Guid moveToID; if (moveto.IsGuid(out moveToID)) { using (System.Transactions.TransactionScope scope = new System.Transactions.TransactionScope()) { var us = buserRelation.GetAllByUserID(user.ID); if ("1" != movetostationjz) { buserRelation.DeleteByUserID(user.ID); } FoWoSoft.Data.Model.UsersRelation ur = new FoWoSoft.Data.Model.UsersRelation(); ur.UserID = user.ID; ur.OrganizeID = moveToID; ur.IsMain = "1" == movetostationjz ? 0 : 1; ur.Sort = buserRelation.GetMaxSort(moveToID); buserRelation.Add(ur); foreach (var u in us) { borganize.UpdateChildsLength(u.OrganizeID); } borganize.UpdateChildsLength(organizeID); borganize.UpdateChildsLength(moveToID); scope.Complete(); Page.ClientScript.RegisterStartupScript(Page.GetType(), "ok", "alert('调动成功!');parent.frames[0].reLoad('" + parentID + "');parent.frames[0].reLoad('" + moveto + "')", true); } FoWoSoft.Platform.Log.Add(("1" == movetostationjz ? "兼职" : "全职") + "调动了人员的岗位", "将人员调往岗位(" + moveto + ")", FoWoSoft.Platform.Log.Types.组织机构); new FoWoSoft.Platform.AppLibrary().ClearUseMemberCache(); } } #endregion } if (user != null) { this.Name.Value = user.Name; this.Account.Value = user.Account; this.Note.Value = user.Note; } this.StatusRadios.Text = borganize.GetStatusRadio("Status", user != null ? user.Status.ToString() : "", "validate=\"radio\""); }