AddUser.aspx.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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 LYFZ.WeixinServers.WeiXinAPP
  8. {
  9. public partial class AddUser : System.Web.UI.Page
  10. {
  11. public string usreName = "";
  12. public string account = "";
  13. public string phone = "";
  14. public string email = "";
  15. public string sex = "";
  16. public int Competence = 0;
  17. public int eid = -1;
  18. LYFZ.WeixinServiceDate.DAL.DAL_AdminUser userDal = new WeixinServiceDate.DAL.DAL_AdminUser();
  19. protected void Page_Load(object sender, EventArgs e)
  20. {
  21. CommonHandler.CheckLoginJump(this);
  22. if (!IsPostBack)
  23. {
  24. if (Request.QueryString["eid"] != null && Request.QueryString["eid"].ToString().Trim().Length > 0)
  25. {
  26. try
  27. {
  28. if (CommonHandler.CheckAdmin(this))
  29. {
  30. eid = Convert.ToInt32(Request.QueryString["eid"].ToString().Trim());
  31. LYFZ.WeixinServiceDate.Model.Model_AdminUser userModel = userDal.GetModel(eid);
  32. usreName = userModel.UserName;
  33. account = userModel.Account;
  34. phone = userModel.Phone;
  35. email = userModel.Email;
  36. sex = userModel.Sex;
  37. Competence = userModel.Competence;
  38. }
  39. }
  40. catch { }
  41. }
  42. else if (Request.QueryString["s"] != null && Request.QueryString["s"].ToString().Trim() == "edit")
  43. {
  44. if (CommonHandler.CheckAdmin(this))
  45. {
  46. getEditID();
  47. AddOrEditUserInfo();
  48. }
  49. }
  50. else if (Request.QueryString["s"] != null && Request.QueryString["s"].ToString().Trim() == "spwd")
  51. {
  52. getEditID();
  53. UpdatePassword();
  54. }
  55. }
  56. }
  57. void getEditID()
  58. {
  59. try
  60. {
  61. eid = Convert.ToInt32(Request.QueryString["id"].ToString().Trim());
  62. }
  63. catch { }
  64. }
  65. void AddOrEditUserInfo()
  66. {
  67. LYFZ.WeixinServiceDate.Model.Model_AdminUser userModel = new WeixinServiceDate.Model.Model_AdminUser();
  68. if (eid > 0)
  69. {
  70. userModel = userDal.GetModel(eid);
  71. }
  72. userModel.UserName = Request.Form["usreName"].ToString();
  73. userModel.Account = Request.Form["account"].ToString();
  74. userModel.Phone = Request.Form["phone"].ToString();
  75. userModel.Email = Request.Form["email"].ToString();
  76. userModel.Sex = Request.Form["sex"].ToString();
  77. userModel.Competence = Convert.ToInt32(Request.Form["Competence"].ToString());
  78. bool ret = false;
  79. if (eid > 0)
  80. {
  81. ret = userDal.Update(userModel);
  82. }
  83. else
  84. {
  85. userModel.Password = "ly1234";
  86. int result = userDal.Add(userModel);
  87. if (result > 0)
  88. {
  89. UserMsegesBox("操作成功");
  90. }
  91. else
  92. {
  93. UserMsegesBox("操作失败,请重试");
  94. }
  95. }
  96. }
  97. void UserMsegesBox(string msg)
  98. {
  99. Response.Write("<script>alert('" + msg + "');document.location='UserList.aspx';</script>"); return;
  100. }
  101. void UpdatePassword()
  102. {
  103. LYFZ.WeixinServiceDate.Model.Model_AdminUser userModel = userDal.GetModel(eid);
  104. userModel.Password = Request.Form["pwd"].ToString();
  105. if (userModel.Password.Trim().Length > 0 && eid > 0)
  106. {
  107. if (userDal.Update(userModel))
  108. {
  109. UserMsegesBox("密码修改成功!"); return;
  110. }
  111. else
  112. {
  113. showMsegesBox("密码修改失败,请重试。");
  114. }
  115. }
  116. else
  117. {
  118. showMsegesBox("密码不能为空");
  119. }
  120. }
  121. void showMsegesBox(string msg)
  122. {
  123. Response.Write("<script>alert('" + msg + "');document.location='Adduser.aspx?eid=" + eid + "';</script>"); return;
  124. }
  125. }
  126. }