Insert.aspx.cs 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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. using System.Data;
  8. using System.Web.UI.HtmlControls;
  9. namespace Com.Jpsoft.Hospital.Web.Module.Sys.Re_RoleMenu
  10. {
  11. public partial class Insert : Com.Jpsoft.Hospital.Web.Common.BasePage
  12. {
  13. Com.Jpsoft.Hospital.Model.jp_sys_right model = new Com.Jpsoft.Hospital.Model.jp_sys_right();
  14. Com.Jpsoft.Hospital.BLL.jp_sys_right right = new Com.Jpsoft.Hospital.BLL.jp_sys_right();
  15. protected void Page_Load(object sender, EventArgs e)
  16. {
  17. if (!IsPostBack)
  18. {
  19. if (Request.QueryString["roleid"] != null && Request.QueryString["roleid"].ToString().Trim() != "")
  20. {
  21. //显示角色信息
  22. int roleid = int.Parse(Request.QueryString["roleid"].ToString());
  23. Com.Jpsoft.Hospital.Model.jp_sys_role model = new Com.Jpsoft.Hospital.Model.jp_sys_role();
  24. Com.Jpsoft.Hospital.BLL.jp_sys_role role = new Com.Jpsoft.Hospital.BLL.jp_sys_role();
  25. model = role.GetModel(roleid);
  26. this.rolename.Text = model.role_name.ToString();
  27. this.desc.Text = model.role_desc.ToString();
  28. //显示菜单信息
  29. ShowData();
  30. }
  31. }
  32. }
  33. /// <summary>
  34. /// 获得权限信息
  35. /// </summary>
  36. /// <param name="menuid"></param>
  37. /// <returns></returns>
  38. public string GetCheck(object menuid)
  39. {
  40. if (!string.IsNullOrEmpty(menuid.ToString()))
  41. {
  42. int menu_id = int.Parse(menuid.ToString());
  43. int roleid = int.Parse(Request.QueryString["roleid"].ToString());
  44. DataTable dt = right.GetList(" right_roleid=" + roleid).Tables[0];
  45. if (dt.Rows.Count > 0)
  46. {
  47. for (int i = 0; i < dt.Rows.Count; i++)
  48. {
  49. //获得菜单ID
  50. int men = int.Parse(dt.Rows[i]["right_mid"].ToString());
  51. if (men == menu_id)
  52. {
  53. return "checked='checked'";
  54. }
  55. }
  56. }
  57. }
  58. return "";
  59. }
  60. /// <summary>
  61. /// 显示角色权限信息
  62. /// </summary>
  63. /// <param name="id"></param>
  64. private void ShowRight(int roleid)
  65. {
  66. Com.Jpsoft.Hospital.Model.jp_sys_right model = new Com.Jpsoft.Hospital.Model.jp_sys_right();
  67. Com.Jpsoft.Hospital.BLL.jp_sys_right right = new Com.Jpsoft.Hospital.BLL.jp_sys_right();
  68. DataTable dt = right.GetList(" right_roleid=" + roleid).Tables[0];
  69. if (dt.Rows.Count > 0)
  70. {
  71. for (int i = 0; i < dt.Rows.Count; i++)
  72. {
  73. //获得菜单ID
  74. int menuid = int.Parse(dt.Rows[i]["right_mid"].ToString());
  75. //功能ID
  76. DataTable fun = right.GetList(" right_mid="+menuid).Tables[0];
  77. if (fun.Rows.Count > 0)
  78. {
  79. for (int ii = 0; ii < fun.Rows.Count; ii++)
  80. {
  81. int funid = int.Parse(fun.Rows[ii]["right_fid"].ToString());
  82. }
  83. }
  84. }
  85. }
  86. }
  87. /// <summary>
  88. /// 显示菜单信息
  89. /// </summary>
  90. private void ShowData()
  91. {
  92. Com.Jpsoft.Hospital.BLL.jp_sys_menu menu = new Com.Jpsoft.Hospital.BLL.jp_sys_menu();
  93. Com.Jpsoft.Hospital.Model.jp_sys_menu model = new Com.Jpsoft.Hospital.Model.jp_sys_menu();
  94. DataTable dt = menu.GetList(" menu_url!='#'").Tables[0];
  95. if (dt.Rows.Count > 0)
  96. {
  97. this.repeater.DataSource = dt;
  98. this.repeater.DataBind();
  99. }
  100. }
  101. /// <summary>
  102. /// 跳转菜单
  103. /// </summary>
  104. /// <param name="sender"></param>
  105. /// <param name="e"></param>
  106. protected void btnBack_Click(object sender, EventArgs e)
  107. {
  108. Response.Redirect("../Role/List.aspx");
  109. }
  110. /// <summary>
  111. /// 绑定功能选项
  112. /// </summary>
  113. /// <param name="sender"></param>
  114. /// <param name="e"></param>
  115. protected void repeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
  116. {
  117. string input = string.Empty;
  118. if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
  119. {
  120. Label lab = (Label)(e.Item.FindControl("mid"));
  121. int mid = int.Parse(lab.Text);
  122. Com.Jpsoft.Hospital.BLL.jp_sys_function function = new Com.Jpsoft.Hospital.BLL.jp_sys_function();
  123. DataTable fundt = function.GetAllList().Tables[0];
  124. if (fundt.Rows.Count > 0)
  125. {
  126. for (int i = 0; i < fundt.Rows.Count; i++)
  127. {
  128. //判断是否存在数据中
  129. //先判断是否是第一次添加
  130. DataTable role = right.GetList(" right_roleid=" + int.Parse(Request.QueryString["roleid"].ToString())).Tables[0];
  131. if (role.Rows.Count > 0)
  132. {
  133. DataTable dt = right.GetList(" right_roleid=" + int.Parse(Request.QueryString["roleid"].ToString()) + "and right_mid=" + mid + " and right_fid=" + int.Parse(fundt.Rows[i]["fun_id"].ToString())).Tables[0];
  134. if (dt.Rows.Count > 0)
  135. {
  136. string name = string.Format("<input type='checkbox' checked='checked' id='funid{0}' name='funid_{1}_{2}' value='{3}_{4}'/>{5}", int.Parse(fundt.Rows[i]["fun_id"].ToString()), mid, int.Parse(fundt.Rows[i]["fun_id"].ToString()), mid, int.Parse(fundt.Rows[i]["fun_id"].ToString()), fundt.Rows[i]["fun_name"].ToString());
  137. input = input + name;
  138. }
  139. else
  140. {
  141. string name = string.Format("<input type='checkbox' id='funid{0}' name='funid_{1}_{2}' value='{3}_{4}'/>{5}", int.Parse(fundt.Rows[i]["fun_id"].ToString()), mid, int.Parse(fundt.Rows[i]["fun_id"].ToString()), mid, int.Parse(fundt.Rows[i]["fun_id"].ToString()), fundt.Rows[i]["fun_name"].ToString());
  142. input = input + name;
  143. }
  144. }
  145. else
  146. {
  147. string name = string.Format("<input type='checkbox' checked='checked' id='funid{0}' name='funid_{1}_{2}' value='{3}_{4}'/>{5}", int.Parse(fundt.Rows[i]["fun_id"].ToString()), mid, int.Parse(fundt.Rows[i]["fun_id"].ToString()), mid, int.Parse(fundt.Rows[i]["fun_id"].ToString()), fundt.Rows[i]["fun_name"].ToString());
  148. input = input + name;
  149. }
  150. }
  151. Label lal = (Label)(e.Item.FindControl("Label1"));
  152. lal.Text = input;
  153. }
  154. }
  155. }
  156. protected void btnAdd_Click(object sender, EventArgs e)
  157. {
  158. Com.Jpsoft.Hospital.Model.jp_sys_right model = new Com.Jpsoft.Hospital.Model.jp_sys_right();
  159. Com.Jpsoft.Hospital.BLL.jp_sys_right right = new Com.Jpsoft.Hospital.BLL.jp_sys_right();
  160. if (Request.QueryString["roleid"].ToString().Trim() != "" && Request.QueryString["roleid"] != null)
  161. {
  162. //获得角色
  163. int roleid = int.Parse(Request.QueryString["roleid"].ToString());
  164. //首先在权限表要删除该角色相关的数据信息
  165. DataTable rightid = right.GetList(" right_roleid="+roleid).Tables[0];
  166. if (rightid.Rows.Count > 0)
  167. {
  168. for (int iii = 0; iii < rightid.Rows.Count; iii++)
  169. {
  170. int right_id=int.Parse(rightid.Rows[iii]["right_id"].ToString());
  171. right.Delete(right_id);
  172. }
  173. }
  174. //获得菜单ID
  175. string ids = Request.Form["dal"].ToString();
  176. if (!string.IsNullOrEmpty(ids))
  177. {
  178. string[] menuid = ids.Split(',');
  179. for (int i = 0; i < menuid.Length; i++)
  180. {
  181. int menu = int.Parse(menuid[i].ToString());
  182. //获得功能
  183. foreach (string key in Request.Form.Keys)
  184. {
  185. if (key.IndexOf("funid_") == 0)
  186. {
  187. string[] str = Request.Form[key].Split('_');
  188. if (str[0] == menu.ToString())
  189. {
  190. int funid = int.Parse(str[1].ToString());
  191. model.right_roleid = roleid;
  192. model.right_mid = menu;
  193. model.right_fid = funid;
  194. right.Add(model);
  195. }
  196. }
  197. }
  198. }
  199. Response.Write("<script>alert('添加成功!');window.location.href='../Role/List.aspx';</script>");
  200. }
  201. }
  202. }
  203. }
  204. }