Exemplo n.º 1
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         try{
             string RoleId = Request.QueryString["RoleId"];
             ljxpower.BLL.tb_roles   bll   = new ljxpower.BLL.tb_roles();
             ljxpower.Model.tb_roles model = bll.GetModel(int.Parse(RoleId));
             lblRole.Text = model.RolesName;
             HdId.Value   = RoleId;
             BindDataList();
         }catch {
             Response.Redirect("RolesList.html");
         }
     }
 }
Exemplo n.º 2
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string RoleId = "0";

            if (context.Request.QueryString["type"] == "edit")//获取角色信息
            {
                int Id = int.Parse(context.Request.QueryString["Id"]);
                ljxpower.BLL.tb_roles   bll   = new ljxpower.BLL.tb_roles();
                ljxpower.Model.tb_roles model = bll.GetModel(Id);
                StringBuilder           sb    = new StringBuilder();
                sb.Append(model.RolesName + ",");
                sb.Append(model.Remark + ",");
                ljxpower.BLL.com_user          ubll = new ljxpower.BLL.com_user();
                List <ljxpower.Model.com_user> list = ubll.GetModelList(" Userid in(select UserId from tb_rolesadduser where RolesId=" + Id + ")");
                foreach (ljxpower.Model.com_user item in list)
                {
                    sb.Append("<div onclick='ss(" + item.userid + ")' height='23px'><input type='hidden' value='" + item.userid + "' />" + item.password + "|" + item.username + "</div>");
                }
                context.Response.Write(sb.ToString());
            }
            else if (context.Request.QueryString["type"] == "getUser")//获取未绑定到当前角色的用户
            {
                StringBuilder                  sb   = new StringBuilder();
                ljxpower.BLL.com_user          ubll = new ljxpower.BLL.com_user();
                List <ljxpower.Model.com_user> list = new List <ljxpower.Model.com_user>();
                //if (context.Request.QueryString["Id"] != null && context.Request.QueryString["Id"] != "")
                //{
                //    int Id = int.Parse(context.Request.QueryString["Id"]);
                //    list = ubll.GetModelList(" Userid not in(select UserId from tb_rolesadduser where RolesId=" + Id + ")");
                //}
                //else
                //{
                list = ubll.GetModelList("");
                // }
                foreach (ljxpower.Model.com_user item in list)
                {
                    sb.Append("<div><input name=\"chkItem\" value=\"<div onclick='ss(" + item.userid + ")' height='23px'><input type='hidden' value='" + item.userid + "'  />" + item.password + "|" + item.username + "</div>\" type=\"checkbox\" /> ");
                    sb.Append(item.password + "|" + item.username + "</div>");
                }
                context.Response.Write(sb.ToString());
            }
            else if (context.Request.QueryString["type"] == "save")//保存角色信息
            {
                string name   = context.Request.QueryString["name"];
                string remark = context.Request.QueryString["remark"];
                int    Id     = int.Parse(context.Request.QueryString["Id"]);
                ljxpower.BLL.tb_roles   bll   = new ljxpower.BLL.tb_roles();
                ljxpower.Model.tb_roles model = bll.GetModel(Id);
                model.Remark    = remark;
                model.RolesName = name;
                context.Response.Write(bll.Update1(model));
            }
            else if (context.Request.QueryString["type"] == "add")//添加
            {
                string name   = context.Request.QueryString["name"];
                string remark = context.Request.QueryString["remark"];
                ljxpower.Model.tb_roles model = new ljxpower.Model.tb_roles();
                ljxpower.BLL.tb_roles   bll   = new ljxpower.BLL.tb_roles();
                model.Remark    = remark;
                model.RolesName = name;
                if (bll.Add1(model) > 0)
                {
                    context.Response.Write("true");
                }
                else
                {
                    context.Response.Write("false");
                }
            }
            else if (context.Request.QueryString["type"] == "delRole")//删除角色
            {
                int Id = int.Parse(context.Request.QueryString["Id"]);
                ljxpower.BLL.tb_roles bll = new ljxpower.BLL.tb_roles();

                ljxpower.BLL.tb_rolesadduser rbll = new ljxpower.BLL.tb_rolesadduser();
                rbll.Delete(Id);
                context.Response.Write(bll.Delete(Id));
            }
            else if (context.Request.QueryString["type"] == "Distri")//获取已分配的权限
            {
                int Id = int.Parse(context.Request.QueryString["Id"]);
                ljxpower.BLL.tb_rolesandnavigation          bll  = new ljxpower.BLL.tb_rolesandnavigation();
                List <ljxpower.Model.tb_rolesandnavigation> list = new List <ljxpower.Model.tb_rolesandnavigation>();
                list = bll.GetModelList(" RolesId=" + Id);
                StringBuilder sb = new StringBuilder();
                foreach (ljxpower.Model.tb_rolesandnavigation model in list)
                {
                    sb.Append(model.NavigationId + ",");
                }
                if (sb.Length > 0)
                {
                    sb.Remove(sb.Length - 1, 1);
                }
                context.Response.Write(sb.ToString());
            }
            else if (context.Request.QueryString["type"] == "saveDistri")
            {
                int           Id   = int.Parse(context.Request.QueryString["Id"]);
                string        nav  = context.Request.QueryString["nav"];
                string[]      str  = nav.Split(',');
                List <string> list = new List <string>();
                string        sql  = "delete tb_rolesandnavigation where RolesId=" + Id;
                foreach (string ss in str)
                {
                    ljxpower.BLL.tb_navigation   bll   = new ljxpower.BLL.tb_navigation();
                    ljxpower.Model.tb_navigation model = bll.GetModel(int.Parse(ss));
                    if (model.ParentId != 0)
                    {
                        string sql3 = "delete tb_rolesandnavigation where RolesId=" + Id + " and NavigationId=" + model.ParentId;
                        string sql1 = "insert into tb_rolesandnavigation (RolesId,NavigationId) values(" + Id + "," + model.ParentId + ")";
                        list.Add(sql3);
                        list.Add(sql1);
                    }
                    string sql2 = "insert into tb_rolesandnavigation (RolesId,NavigationId) values(" + Id + "," + ss + ")";
                    list.Add(sql2);
                }
                ljxpower.Common.DbHelperMySQL.ExecuteSqlTran(list);
            }
            else if (context.Request.QueryString["type"] == "savenav")
            {
                RoleId = context.Request["RoleId"].ToString();
                string        NavId = context.Request["NavId"].ToString();
                List <string> list  = new List <string>();
                list.Add("delete from tb_rolesandnavigation where RolesId=" + RoleId);
                string[] str = NavId.Split('|');
                for (int i = 0; i < str.Length - 1; i++)
                {
                    string[] str2 = str[i].Split(',');
                    if (str2.Length == 2)
                    {
                        list.Add(" insert into tb_rolesandnavigation(RolesId,NavigationId,ButtonId) values(" + RoleId + "," + str2[0] + ",0)");
                    }
                    else
                    {
                        for (int j = 1; j < str2.Length - 1; j++)
                        {
                            list.Add(" insert into tb_rolesandnavigation(RolesId,NavigationId,ButtonId) values(" + RoleId + "," + str2[0] + "," + str2[j] + ")");
                        }
                    }
                }
                ljxpower.Common.DbHelperMySQL.ExecuteSqlTran(list);
                context.Response.Write("Hello World");
            }
            else if (context.Request.QueryString["type"] == "query")
            {
                ljxpower.BLL.tb_roles          bll  = new ljxpower.BLL.tb_roles();
                List <ljxpower.Model.tb_roles> list = bll.GetModelList("");
                StringBuilder sb = new StringBuilder();
                sb.Append("[");
                foreach (ljxpower.Model.tb_roles item in list)
                {
                    sb.Append("{\"Id\":" + item.Id + ",");
                    sb.Append("\"Name\":\"" + item.RolesName + "\",");
                    sb.Append("\"Remark\":\"" + item.Remark + "\"},");
                }
                if (sb.Length > 1)
                {
                    sb.Remove(sb.Length - 1, 1);
                }
                sb.Append("]");
                context.Response.Write(sb.ToString());
            }

            /////////////////////////////////////

            else if (context.Request["type"].ToString() == "ljxquery")
            {
                RoleId = context.Request["RoleId"].ToString();
                getdata(RoleId, context);
            }
            else if (context.Request["type"] == "pageload")
            {
                //设置内容权限,读取内容权限,保留在本页中。
                string str1 = context.Request.UrlReferrer.LocalPath;
                if (str1.Length > 3)
                {
                    str1 = str1.Substring(1);
                }
                string pageljxfun = getstrif(str1, context);
                context.Response.Write(pageljxfun);
                //context.Response.Write("OK");
                //return;
            }
            else if (context.Request["type"] == "ljxsave")
            {
                //设置内容权限,读取内容权限,保留在本页中。
                RoleId = context.Request["RoleId"].ToString();
                string        NavId = context.Request["NavId"].ToString();
                List <string> list  = new List <string>();
                list.Add("delete from tb_rolesandnavigation where RolesId=" + RoleId);
                string[] str = NavId.Split('|');
                for (int i = 0; i < str.Length - 1; i++)
                {
                    string[] str2 = str[i].Split(',');
                    if (str2.Length == 2)
                    {
                        list.Add(" insert into tb_rolesandnavigation(RolesId,NavigationId,ButtonId) values(" + RoleId + "," + str2[0] + ",0)");
                    }
                    else
                    {
                        for (int j = 1; j < str2.Length - 1; j++)
                        {
                            list.Add(" insert into tb_rolesandnavigation(RolesId,NavigationId,ButtonId) values(" + RoleId + "," + str2[0] + "," + str2[j] + ")");
                        }
                    }
                }
                ljxpower.Common.DbHelperMySQL.ExecuteSqlTran(list);
                context.Response.Write("OK");
                //return;
            }
        }