RoadFlow2.1 临时演示

User.aspx.cs 8.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. namespace WebForm.Platform.Members
  8. {
  9. public partial class User : Common.BasePage
  10. {
  11. protected void Page_Load(object sender, EventArgs e)
  12. {
  13. RoadFlow.Platform.Organize borganize = new RoadFlow.Platform.Organize();
  14. RoadFlow.Platform.Users busers = new RoadFlow.Platform.Users();
  15. RoadFlow.Platform.UsersRelation buserRelation = new RoadFlow.Platform.UsersRelation();
  16. RoadFlow.Data.Model.Users user = null;
  17. RoadFlow.Data.Model.Organize organize = null;
  18. string id = Request.QueryString["id"];
  19. string parentID = Request.QueryString["parentid"];
  20. string parentString = string.Empty;
  21. this.Account.Attributes.Add("validate_url", "CheckAccount.ashx?id=" + id);
  22. Guid userID, organizeID;
  23. if (id.IsGuid(out userID))
  24. {
  25. user = busers.Get(userID);
  26. if (user != null)
  27. {
  28. //所在组织字符串
  29. System.Text.StringBuilder sb = new System.Text.StringBuilder();
  30. var userRelations = buserRelation.GetAllByUserID(user.ID).OrderByDescending(p => p.IsMain);
  31. foreach (var userRelation in userRelations)
  32. {
  33. sb.Append("<div style='margin:3px 0;'>");
  34. sb.Append(borganize.GetAllParentNames(userRelation.OrganizeID, true));
  35. if (userRelation.IsMain == 0)
  36. {
  37. sb.Append("<span style='color:#999'> [兼职]</span>");
  38. }
  39. sb.Append("</div>");
  40. }
  41. this.ParentString.Text = sb.ToString();
  42. var roles = new RoadFlow.Platform.UsersRole().GetByUserIDFromCache(userID);
  43. RoadFlow.Platform.Role brole = new RoadFlow.Platform.Role();
  44. System.Text.StringBuilder rolesb = new System.Text.StringBuilder();
  45. foreach (var role in roles)
  46. {
  47. var role1 = brole.Get(role.RoleID);
  48. if (role1 == null) continue;
  49. rolesb.Append(role1.Name);
  50. rolesb.Append(",");
  51. }
  52. this.RoleString.Text = rolesb.ToString().TrimEnd(',');
  53. }
  54. }
  55. if (parentID.IsGuid(out organizeID))
  56. {
  57. organize = borganize.Get(organizeID);
  58. }
  59. if (IsPostBack)
  60. {
  61. #region 保存
  62. if (!Request.Form["Save"].IsNullOrEmpty() && user != null)
  63. {
  64. string name = Request.Form["Name"];
  65. string account = Request.Form["Account"];
  66. string status = Request.Form["Status"];
  67. string note = Request.Form["Note"];
  68. string oldXML = user.Serialize();
  69. user.Name = name.Trim();
  70. user.Account = account.Trim();
  71. user.Status = status.ToInt(1);
  72. user.Note = note.IsNullOrEmpty() ? null : note.Trim();
  73. busers.Update(user);
  74. RoadFlow.Platform.Log.Add("修改了用户", "", RoadFlow.Platform.Log.Types.组织机构, oldXML, user.Serialize());
  75. Page.ClientScript.RegisterStartupScript(Page.GetType(), "ok", "alert('保存成功!');parent.frames[0].reLoad('" + parentID + "');", true);
  76. }
  77. #endregion
  78. #region 删除用户
  79. if (!Request.Form["DeleteBut"].IsNullOrEmpty() && user != null && organize != null)
  80. {
  81. using (System.Transactions.TransactionScope scope = new System.Transactions.TransactionScope())
  82. {
  83. var urs = buserRelation.GetAllByUserID(user.ID);
  84. busers.Delete(user.ID);
  85. buserRelation.DeleteByUserID(user.ID);
  86. new RoadFlow.Platform.UsersInfo().Delete(user.ID);
  87. new RoadFlow.Platform.UsersRole().DeleteByUserID(user.ID);
  88. //更新父级[ChildsLength]字段
  89. foreach (var ur in urs)
  90. {
  91. borganize.UpdateChildsLength(ur.OrganizeID);
  92. }
  93. scope.Complete();
  94. }
  95. string refreshID = parentID;
  96. string url = string.Empty;
  97. var users = borganize.GetAllUsers(refreshID.ToGuid());
  98. if (users.Count > 0)
  99. {
  100. url = "User.aspx?id=" + users.Last().ID + "&appid=" + Request.QueryString["appid"] + "&tabid=" + Request.QueryString["tabid"] + "&parentid=" + parentID;
  101. }
  102. else
  103. {
  104. refreshID = organize.ParentID == Guid.Empty ? organize.ID.ToString() : organize.ParentID.ToString();
  105. url = "Body.aspx?id=" + parentID + "&appid=" + Request.QueryString["appid"] + "&tabid=" + Request.QueryString["tabid"] + "&parentid=" + organize.ParentID;
  106. }
  107. RoadFlow.Platform.Log.Add("删除了用户", user.Serialize(), RoadFlow.Platform.Log.Types.组织机构);
  108. Page.ClientScript.RegisterStartupScript(Page.GetType(), "ok", "alert('删除成功');parent.frames[0].reLoad('" + refreshID + "');window.location='" + url + "'", true);
  109. new RoadFlow.Platform.AppLibrary().ClearUseMemberCache();
  110. }
  111. #endregion
  112. #region 初始化密码
  113. if (!Request.Form["InitPass"].IsNullOrEmpty() && user != null)
  114. {
  115. string initpass = busers.GetInitPassword();
  116. busers.InitPassword(user.ID);
  117. RoadFlow.Platform.Log.Add("初始化了用户密码", user.Serialize(), RoadFlow.Platform.Log.Types.组织机构);
  118. Page.ClientScript.RegisterStartupScript(Page.GetType(), "ok", "alert('密码已初始化为:" + initpass + "');", true);
  119. }
  120. #endregion
  121. #region 调动
  122. if (!Request.Form["Move1"].IsNullOrEmpty() && user != null)
  123. {
  124. string moveto = Request.Form["movetostation"];
  125. string movetostationjz = Request.Form["movetostationjz"];
  126. Guid moveToID;
  127. if (moveto.IsGuid(out moveToID))
  128. {
  129. using (System.Transactions.TransactionScope scope = new System.Transactions.TransactionScope())
  130. {
  131. var us = buserRelation.GetAllByUserID(user.ID);
  132. if ("1" != movetostationjz)
  133. {
  134. buserRelation.DeleteByUserID(user.ID);
  135. }
  136. RoadFlow.Data.Model.UsersRelation ur = new RoadFlow.Data.Model.UsersRelation();
  137. ur.UserID = user.ID;
  138. ur.OrganizeID = moveToID;
  139. ur.IsMain = "1" == movetostationjz ? 0 : 1;
  140. ur.Sort = buserRelation.GetMaxSort(moveToID);
  141. buserRelation.Add(ur);
  142. foreach (var u in us)
  143. {
  144. borganize.UpdateChildsLength(u.OrganizeID);
  145. }
  146. borganize.UpdateChildsLength(organizeID);
  147. borganize.UpdateChildsLength(moveToID);
  148. scope.Complete();
  149. Page.ClientScript.RegisterStartupScript(Page.GetType(), "ok", "alert('调动成功!');parent.frames[0].reLoad('" + parentID + "');parent.frames[0].reLoad('" + moveto + "')", true);
  150. }
  151. RoadFlow.Platform.Log.Add(("1" == movetostationjz ? "兼职" : "全职") + "调动了人员的岗位", "将人员调往岗位(" + moveto + ")", RoadFlow.Platform.Log.Types.组织机构);
  152. new RoadFlow.Platform.AppLibrary().ClearUseMemberCache();
  153. }
  154. }
  155. #endregion
  156. }
  157. if (user != null)
  158. {
  159. this.Name.Value = user.Name;
  160. this.Account.Value = user.Account;
  161. this.Note.Value = user.Note;
  162. }
  163. this.StatusRadios.Text = borganize.GetStatusRadio("Status", user != null ? user.Status.ToString() : "", "validate=\"radio\"");
  164. }
  165. }
  166. }