123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215 |
- using System;
- using System.Collections.Generic;
- //using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Data;
- using System.Web.UI.HtmlControls;
- namespace Com.Jpsoft.Hospital.Web.Module.Sys.Re_RoleMenu
- {
- public partial class Insert : Com.Jpsoft.Hospital.Web.Common.BasePage
- {
- Com.Jpsoft.Hospital.Model.jp_sys_right model = new Com.Jpsoft.Hospital.Model.jp_sys_right();
- Com.Jpsoft.Hospital.BLL.jp_sys_right right = new Com.Jpsoft.Hospital.BLL.jp_sys_right();
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!IsPostBack)
- {
- if (Request.QueryString["roleid"] != null && Request.QueryString["roleid"].ToString().Trim() != "")
- {
- //显示角色信息
- int roleid = int.Parse(Request.QueryString["roleid"].ToString());
- Com.Jpsoft.Hospital.Model.jp_sys_role model = new Com.Jpsoft.Hospital.Model.jp_sys_role();
- Com.Jpsoft.Hospital.BLL.jp_sys_role role = new Com.Jpsoft.Hospital.BLL.jp_sys_role();
- model = role.GetModel(roleid);
- this.rolename.Text = model.role_name.ToString();
- this.desc.Text = model.role_desc.ToString();
- //显示菜单信息
- ShowData();
- }
- }
- }
- /// <summary>
- /// 获得权限信息
- /// </summary>
- /// <param name="menuid"></param>
- /// <returns></returns>
- public string GetCheck(object menuid)
- {
- if (!string.IsNullOrEmpty(menuid.ToString()))
- {
- int menu_id = int.Parse(menuid.ToString());
- int roleid = int.Parse(Request.QueryString["roleid"].ToString());
- DataTable dt = right.GetList(" right_roleid=" + roleid).Tables[0];
- if (dt.Rows.Count > 0)
- {
- for (int i = 0; i < dt.Rows.Count; i++)
- {
- //获得菜单ID
- int men = int.Parse(dt.Rows[i]["right_mid"].ToString());
- if (men == menu_id)
- {
- return "checked='checked'";
- }
- }
- }
- }
- return "";
- }
- /// <summary>
- /// 显示角色权限信息
- /// </summary>
- /// <param name="id"></param>
- private void ShowRight(int roleid)
- {
- Com.Jpsoft.Hospital.Model.jp_sys_right model = new Com.Jpsoft.Hospital.Model.jp_sys_right();
- Com.Jpsoft.Hospital.BLL.jp_sys_right right = new Com.Jpsoft.Hospital.BLL.jp_sys_right();
- DataTable dt = right.GetList(" right_roleid=" + roleid).Tables[0];
- if (dt.Rows.Count > 0)
- {
- for (int i = 0; i < dt.Rows.Count; i++)
- {
- //获得菜单ID
- int menuid = int.Parse(dt.Rows[i]["right_mid"].ToString());
-
- //功能ID
- DataTable fun = right.GetList(" right_mid="+menuid).Tables[0];
- if (fun.Rows.Count > 0)
- {
- for (int ii = 0; ii < fun.Rows.Count; ii++)
- {
- int funid = int.Parse(fun.Rows[ii]["right_fid"].ToString());
- }
- }
- }
- }
- }
- /// <summary>
- /// 显示菜单信息
- /// </summary>
- private void ShowData()
- {
- Com.Jpsoft.Hospital.BLL.jp_sys_menu menu = new Com.Jpsoft.Hospital.BLL.jp_sys_menu();
- Com.Jpsoft.Hospital.Model.jp_sys_menu model = new Com.Jpsoft.Hospital.Model.jp_sys_menu();
- DataTable dt = menu.GetList(" menu_url!='#'").Tables[0];
- if (dt.Rows.Count > 0)
- {
- this.repeater.DataSource = dt;
- this.repeater.DataBind();
- }
- }
- /// <summary>
- /// 跳转菜单
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected void btnBack_Click(object sender, EventArgs e)
- {
- Response.Redirect("../Role/List.aspx");
- }
- /// <summary>
- /// 绑定功能选项
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected void repeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
- {
- string input = string.Empty;
- if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
- {
- Label lab = (Label)(e.Item.FindControl("mid"));
- int mid = int.Parse(lab.Text);
- Com.Jpsoft.Hospital.BLL.jp_sys_function function = new Com.Jpsoft.Hospital.BLL.jp_sys_function();
- DataTable fundt = function.GetAllList().Tables[0];
- if (fundt.Rows.Count > 0)
- {
- for (int i = 0; i < fundt.Rows.Count; i++)
- {
- //判断是否存在数据中
-
- //先判断是否是第一次添加
- DataTable role = right.GetList(" right_roleid=" + int.Parse(Request.QueryString["roleid"].ToString())).Tables[0];
- if (role.Rows.Count > 0)
- {
- 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];
- if (dt.Rows.Count > 0)
- {
- 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());
- input = input + name;
- }
- else
- {
- 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());
- input = input + name;
- }
- }
- else
- {
- 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());
- input = input + name;
- }
- }
- Label lal = (Label)(e.Item.FindControl("Label1"));
- lal.Text = input;
- }
- }
- }
- protected void btnAdd_Click(object sender, EventArgs e)
- {
- Com.Jpsoft.Hospital.Model.jp_sys_right model = new Com.Jpsoft.Hospital.Model.jp_sys_right();
- Com.Jpsoft.Hospital.BLL.jp_sys_right right = new Com.Jpsoft.Hospital.BLL.jp_sys_right();
- if (Request.QueryString["roleid"].ToString().Trim() != "" && Request.QueryString["roleid"] != null)
- {
- //获得角色
- int roleid = int.Parse(Request.QueryString["roleid"].ToString());
- //首先在权限表要删除该角色相关的数据信息
- DataTable rightid = right.GetList(" right_roleid="+roleid).Tables[0];
- if (rightid.Rows.Count > 0)
- {
- for (int iii = 0; iii < rightid.Rows.Count; iii++)
- {
- int right_id=int.Parse(rightid.Rows[iii]["right_id"].ToString());
- right.Delete(right_id);
- }
- }
- //获得菜单ID
- string ids = Request.Form["dal"].ToString();
- if (!string.IsNullOrEmpty(ids))
- {
- string[] menuid = ids.Split(',');
- for (int i = 0; i < menuid.Length; i++)
- {
- int menu = int.Parse(menuid[i].ToString());
- //获得功能
- foreach (string key in Request.Form.Keys)
- {
- if (key.IndexOf("funid_") == 0)
- {
- string[] str = Request.Form[key].Split('_');
- if (str[0] == menu.ToString())
- {
- int funid = int.Parse(str[1].ToString());
-
- model.right_roleid = roleid;
- model.right_mid = menu;
- model.right_fid = funid;
- right.Add(model);
- }
- }
- }
- }
- Response.Write("<script>alert('添加成功!');window.location.href='../Role/List.aspx';</script>");
- }
- }
- }
- }
- }
|