Insert.aspx.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. //
  8. using System.Data;
  9. namespace Com.Jpsoft.Hospital.Web.Module.Sys.Re_UserRole
  10. {
  11. public partial class Insert : Com.Jpsoft.Hospital.Web.Common.BasePage
  12. {
  13. Com.Jpsoft.Hospital.BLL.jp_sys_user user = new Com.Jpsoft.Hospital.BLL.jp_sys_user();
  14. Com.Jpsoft.Hospital.Model.jp_sys_user usermodel = new Com.Jpsoft.Hospital.Model.jp_sys_user();
  15. Com.Jpsoft.Hospital.Model.jp_sys_userrole userrolemodel = new Com.Jpsoft.Hospital.Model.jp_sys_userrole();
  16. Com.Jpsoft.Hospital.BLL.jp_sys_userrole userrole = new Com.Jpsoft.Hospital.BLL.jp_sys_userrole();
  17. Com.Jpsoft.Hospital.BLL.jp_sys_role role = new Com.Jpsoft.Hospital.BLL.jp_sys_role();
  18. Com.Jpsoft.Hospital.Model.jp_sys_role rolemodel = new Com.Jpsoft.Hospital.Model.jp_sys_role();
  19. public string CheckBoxName = string.Empty;
  20. public string RoleName = string.Empty;
  21. public string RoleDesc = string.Empty;
  22. protected void Page_Load(object sender, EventArgs e)
  23. {
  24. if (!IsPostBack)
  25. {
  26. if (Request.QueryString["user_id"] != null && Request.QueryString["user_id"].ToString().Trim() != "")
  27. {
  28. int uid = int.Parse(Request.QueryString["user_id"].ToString());
  29. ShowData(uid);
  30. }
  31. }
  32. }
  33. private void ShowData(int id)
  34. {
  35. usermodel = user.GetModel(id);
  36. if (usermodel != null)
  37. {
  38. this.username.Text = usermodel.user_loginname.ToString();
  39. this.remark.Text = usermodel.user_remark.ToString();
  40. this.id.Text = usermodel.user_id.ToString();
  41. }
  42. DataTable dt = role.GetAllList().Tables[0];
  43. if (dt.Rows.Count > 0)
  44. {
  45. this.repeat.DataSource = dt;
  46. this.repeat.DataBind();
  47. }
  48. //进入界面时显示用户的角色信息
  49. DataTable userdt=userrole.GetList(" ur_userid="+usermodel.user_id).Tables[0];
  50. if (userdt.Rows.Count > 0)
  51. {
  52. for (int i = 0; i < userdt.Rows.Count; i++)
  53. {
  54. int ur_roleid = int.Parse(userdt.Rows[i]["ur_roleid"].ToString());
  55. foreach (RepeaterItem ri in repeat.Items)
  56. {
  57. CheckBox cbox =(CheckBox)ri.FindControl("cb");
  58. if (cbox.Text == ur_roleid.ToString())
  59. {
  60. cbox.Checked = true;
  61. }
  62. }
  63. }
  64. }
  65. }
  66. protected void btnBack_Click(object sender, EventArgs e)
  67. {
  68. Response.Redirect("../User/List.aspx");
  69. }
  70. protected void btnOK_Click(object sender, EventArgs e)
  71. {
  72. //删除数据
  73. int uid = int.Parse(this.id.Text);
  74. DataTable dt = userrole.GetList(" ur_userid=" + uid).Tables[0];
  75. if (dt.Rows.Count > 0)
  76. {
  77. for (int i = 0; i < dt.Rows.Count; i++)
  78. {
  79. int urid = int.Parse(dt.Rows[i]["ur_id"].ToString());
  80. try
  81. {
  82. userrole.Delete(urid);
  83. }
  84. catch (Exception ex)
  85. {
  86. Response.Write("<script>alert('添加失败,愿因:"+ex.ToString()+"');</script>");
  87. }
  88. }
  89. }
  90. //添加数据
  91. foreach (RepeaterItem ri in repeat.Items)
  92. {
  93. if (ri.ItemType == ListItemType.Item || ri.ItemType == ListItemType.AlternatingItem)
  94. {
  95. CheckBox cb = ri.FindControl("cb") as CheckBox;
  96. if (cb.Checked == true)
  97. {
  98. userrolemodel.ur_roleid = int.Parse(cb.Text);
  99. userrolemodel.ur_userid = int.Parse(this.id.Text);
  100. userrole.Add(userrolemodel);
  101. Response.Write("<script>alert('添加成功!');</script>");
  102. }
  103. }
  104. }
  105. }
  106. }
  107. }