/// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add(XHD.Model.ssn_authority model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into ssn_authority(");
            strSql.Append("Role_id,Factory_Id,App_ids,Menu_ids,Button_ids,Create_id,Create_date)");
            strSql.Append(" values (");
            strSql.Append("@Role_id,@Factory_Id,@App_ids,@Menu_ids,@Button_ids,@Create_id,@Create_date)");
            MySqlParameter[] parameters =
            {
                new MySqlParameter("@Role_id",     MySqlDbType.Int32,       4),
                new MySqlParameter("@Factory_Id",  MySqlDbType.VarChar,    60),
                new MySqlParameter("@App_ids",     MySqlDbType.VarChar,   250),
                new MySqlParameter("@Menu_ids",    MySqlDbType.VarChar, 10000),
                new MySqlParameter("@Button_ids",  MySqlDbType.VarChar, 10000),
                new MySqlParameter("@Create_id",   MySqlDbType.Int32,       4),
                new MySqlParameter("@Create_date", MySqlDbType.DateTime)
            };
            parameters[0].Value = model.Role_id;
            parameters[1].Value = model.Factory_Id;
            parameters[2].Value = model.App_ids;
            parameters[3].Value = model.Menu_ids;
            parameters[4].Value = model.Button_ids;
            parameters[5].Value = model.Create_id;
            parameters[6].Value = model.Create_date;

            DbHelperMySQL.ExecuteSql(strSql.ToString(), parameters);
        }
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public XHD.Model.ssn_authority GetModel()
        {
            //该表无主键信息,请自定义主键/条件字段
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  Role_id,Factory_Id,App_ids,Menu_ids,Button_ids,Create_id,Create_date from ssn_authority ");
            strSql.Append(" where  limit 1 ");
            MySqlParameter[] parameters = { };

            XHD.Model.ssn_authority model = new XHD.Model.ssn_authority();
            DataSet ds = DbHelperMySQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["Role_id"] != null && ds.Tables[0].Rows[0]["Role_id"].ToString() != "")
                {
                    model.Role_id = int.Parse(ds.Tables[0].Rows[0]["Role_id"].ToString());
                }
                if (ds.Tables[0].Rows[0]["App_ids"] != null && ds.Tables[0].Rows[0]["App_ids"].ToString() != "")
                {
                    model.App_ids = ds.Tables[0].Rows[0]["App_ids"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Menu_ids"] != null && ds.Tables[0].Rows[0]["Menu_ids"].ToString() != "")
                {
                    model.Menu_ids = ds.Tables[0].Rows[0]["Menu_ids"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Button_ids"] != null && ds.Tables[0].Rows[0]["Button_ids"].ToString() != "")
                {
                    model.Button_ids = ds.Tables[0].Rows[0]["Button_ids"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Create_id"] != null && ds.Tables[0].Rows[0]["Create_id"].ToString() != "")
                {
                    model.Create_id = int.Parse(ds.Tables[0].Rows[0]["Create_id"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Create_date"] != null && ds.Tables[0].Rows[0]["Create_date"].ToString() != "")
                {
                    model.Create_date = DateTime.Parse(ds.Tables[0].Rows[0]["Create_date"].ToString());
                }
                return(model);
            }
            else
            {
                return(null);
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(XHD.Model.ssn_authority model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update ssn_authority set ");
            strSql.Append("Role_id=@Role_id,");
            strSql.Append("Factory_Id=@Factory_Id,");
            strSql.Append("App_ids=@App_ids,");
            strSql.Append("Menu_ids=@Menu_ids,");
            strSql.Append("Button_ids=@Button_ids,");
            strSql.Append("Create_id=@Create_id,");
            strSql.Append("Create_date=@Create_date");
            strSql.Append(" where ");
            MySqlParameter[] parameters =
            {
                new MySqlParameter("@Role_id",     MySqlDbType.Int32,       4),
                new MySqlParameter("@Factory_Id",  MySqlDbType.VarChar,    60),
                new MySqlParameter("@App_ids",     MySqlDbType.VarChar,   250),
                new MySqlParameter("@Menu_ids",    MySqlDbType.VarChar, 10000),
                new MySqlParameter("@Button_ids",  MySqlDbType.VarChar, 10000),
                new MySqlParameter("@Create_id",   MySqlDbType.Int32,       4),
                new MySqlParameter("@Create_date", MySqlDbType.DateTime)
            };
            parameters[0].Value = model.Role_id;
            parameters[1].Value = model.Factory_Id;
            parameters[2].Value = model.App_ids;
            parameters[3].Value = model.Menu_ids;
            parameters[4].Value = model.Button_ids;
            parameters[5].Value = model.Create_id;
            parameters[6].Value = model.Create_date;

            int rows = DbHelperMySQL.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #4
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            HttpRequest request = context.Request;

            XHD.BLL.ssn_role     role  = new XHD.BLL.ssn_role();
            XHD.BLL.ssn_art_menu menu  = new XHD.BLL.ssn_art_menu();
            XHD.Model.ssn_role   model = new XHD.Model.ssn_role();
            XHD.BLL.ssn_visit    visit = new XHD.BLL.ssn_visit();
            XHD.BLL.ssn_art      art   = new XHD.BLL.ssn_art();
            var    cookie     = context.Request.Cookies[FormsAuthentication.FormsCookieName];
            var    ticket     = FormsAuthentication.Decrypt(cookie.Value);
            string CoockiesID = ticket.UserData;

            XHD.BLL.hr_employee emp = new XHD.BLL.hr_employee();
            int     emp_id          = int.Parse(CoockiesID);
            DataSet dsemp           = emp.GetList("id=" + emp_id);
            string  empname         = string.Empty;
            string  uid             = string.Empty;
            string  factory_Id      = string.Empty;

            if (dsemp != null && dsemp.Tables[0].Rows.Count > 0)
            {
                empname    = dsemp.Tables[0].Rows[0]["name"].ToString();
                uid        = dsemp.Tables[0].Rows[0]["uid"].ToString();
                factory_Id = dsemp.Tables[0].Rows[0]["Factory_Id"].ToString();
            }

            //角色保存
            if (request["Action"] == "SysSave")
            {
                model.RoleName    = PageValidate.InputText(request["T_role"], 250);
                model.RoleSort    = int.Parse(request["T_RoleOrder"]);
                model.RoleDscript = PageValidate.InputText(request["T_Descript"], 255);
                model.Factory_Id  = factory_Id;

                string id = PageValidate.InputText(request["id"], 50);

                if (!string.IsNullOrEmpty(id) && id != "null")
                {
                    DataSet ds = role.GetList("RoleID=" + int.Parse(id));
                    DataRow dr = ds.Tables[0].Rows[0];
                    model.RoleID     = int.Parse(id);
                    model.UpdateDate = DateTime.Now;
                    model.UpdateID   = emp_id;
                    role.Update(model);
                }
                else
                {
                    model.CreateID   = emp_id;
                    model.CreateDate = DateTime.Now;
                    int rid = role.Add(model);
                }
            }

            //验证是否唯一
            else if (request["Action"] == "Exist")
            {
                DataSet ds1 = role.GetList(" RoleName='" + XHD.Common.PageValidate.InputText(request["T_role"], 250) + "'" + " and factory_Id='" + factory_Id + "'");
                context.Response.Write(ds1.Tables[0].Rows.Count > 0 ? "false" : "true");
            }

            //获取角色表格json
            else if (request["Action"] == "grid")
            {
                DataSet ds = role.GetList(0, "factory_Id='" + factory_Id + "'", " RoleSort");

                string dt = XHD.Common.GetGridJSON.DataTableToJSON(ds.Tables[0]);

                context.Response.Write(dt);
            }

            //获取角色信息
            else if (request["Action"] == "form")
            {
                DataSet ds = role.GetList(" RoleID=" + int.Parse(request["id"]));

                string dt = XHD.Common.DataToJson.DataToJSON(ds);

                context.Response.Write(dt);
            }
            //删除角色
            else if (request["Action"] == "del")
            {
                string rid   = request["id"];
                bool   isdel = role.Delete(int.Parse(rid));
                if (isdel)
                {
                    context.Response.Write("true");
                }
                else
                {
                    context.Response.Write("false");
                }

                //角色下员工删除
                XHD.BLL.ssn_role_emp rm = new XHD.BLL.ssn_role_emp();
                rm.Delete("RoleID=" + int.Parse(rid));

                //角色下数据权限删除
                XHD.BLL.ssn_visit data_auth = new XHD.BLL.ssn_visit();
                data_auth.DeleteByRole(int.Parse(rid));

                //角色下功能权限删除
                XHD.BLL.ssn_authority auth = new XHD.BLL.ssn_authority();
                auth.DeleteWhere("Role_id=" + int.Parse(rid));
            }

            #region 权限设置
            //auth
            else if (request["Action"] == "treegrid")
            {
                string appidstr = request["appid"];
                int    appid    = int.Parse(appidstr);

                //获取单位
                string ftyid = PageValidate.InputText(request["factory_id"], 60);
                //设置查询条件
                string wheretext  = "App_id=" + appid; //限制menu
                string wheretext2 = "";                //限制button

                DataTable dt = menu.GetList(wheretext).Tables[0];
                dt.Columns.Add(new DataColumn("Sysroler", typeof(string)));

                XHD.BLL.ssn_button btn = new XHD.BLL.ssn_button();
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    DataSet ds    = btn.GetList(0, "Menu_id=" + dt.Rows[i]["Menu_id"].ToString() + wheretext2, "Btn_order");
                    string  roler = "";
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        for (int j = 0; j < ds.Tables[0].Rows.Count; j++)
                        {
                            roler += ds.Tables[0].Rows[j]["Btn_id"].ToString() + "|" + ds.Tables[0].Rows[j]["Btn_name"].ToString();
                            roler += ",";
                        }
                    }
                    dt.Rows[i][dt.Columns.Count - 1] = roler;
                }
                string dt1 = "{Rows:[" + GetTasksString(0, dt) + "]}";
                context.Response.Write(dt1);
                context.Response.End();
            }
            //get auth
            else if (request["Action"] == "getauth")
            {
                string postdata           = Convert.ToString(HttpContext.Current.Request.QueryString["postdata"]);
                JavaScriptSerializer json = new JavaScriptSerializer();
                save sa = json.Deserialize <save>(postdata);
                XHD.Model.ssn_authority modelauth = new XHD.Model.ssn_authority();
                modelauth.Role_id    = int.Parse(sa.role_id);
                modelauth.App_ids    = sa.app;
                modelauth.Menu_ids   = sa.menu;
                modelauth.Button_ids = sa.btn;

                XHD.BLL.ssn_authority sysau = new XHD.BLL.ssn_authority();

                string  roledata = "0|0";
                DataSet ds       = sysau.GetList("Role_id=" + modelauth.Role_id + " and App_ids='" + modelauth.App_ids + "'");
                if (ds.Tables[0].Rows.Count > 0)
                {
                    DataRow dr = ds.Tables[0].Rows[0];
                    roledata = dr["Menu_ids"] + "|" + dr["Button_ids"];
                }
                context.Response.Write(roledata);
            }
            // save auth
            else if (request["Action"] == "saveauth")
            {
                string postdata           = Convert.ToString(HttpContext.Current.Request.QueryString["postdata"]);
                JavaScriptSerializer json = new JavaScriptSerializer();
                save sa = json.Deserialize <save>(postdata);
                XHD.Model.ssn_authority modelauth = new XHD.Model.ssn_authority();
                modelauth.Role_id    = int.Parse(sa.role_id);
                modelauth.App_ids    = PageValidate.InputText(sa.app, 50);
                modelauth.Menu_ids   = PageValidate.InputText(sa.menu, int.MaxValue);
                modelauth.Button_ids = PageValidate.InputText(sa.btn, int.MaxValue);
                modelauth.Factory_Id = factory_Id;

                XHD.BLL.ssn_authority sysau = new XHD.BLL.ssn_authority();
                //List<string> relstbtn = new List<string>();

                if (!string.IsNullOrEmpty(postdata))
                {
                    //给角色分配权限
                    sysau.DeleteWhere("Role_id=" + modelauth.Role_id + " and App_ids='" + modelauth.App_ids + "'");
                    if (modelauth.Menu_ids != "" || modelauth.Button_ids != ",,")
                    {
                        sysau.Add(modelauth);
                    }
                    context.Response.Write("{sucess:sucess}");
                }
            }
            #endregion

            #region 查看权限设置
            //菜单显示
            else if (request["Action"] == "menuList")
            {
                string appid   = request["appid"];
                string authtxt = PageValidate.InputText(request["auth"], 50);

                if (!string.IsNullOrEmpty(appid))
                {
                    string serchtxt = " App_id=" + int.Parse(appid);
                    //-context.Response.Write(authtxt);
                    DataSet       ds  = menu.GetList(0, serchtxt, " Menu_order");
                    StringBuilder str = new StringBuilder();
                    str.Append("[");
                    str.Append(GetTreeString(0, ds.Tables[0], authtxt));
                    str.Replace(",", "", str.Length - 1, 1);
                    str.Append("]");
                    context.Response.Write(str);
                }
            }

            //显示菜单下的文章
            else if (request["Action"] == "viewgrid")
            {
                //通过菜单id获取旗下的文章
                string menuid = request["menuid"];

                if (!string.IsNullOrEmpty(menuid))
                {
                    string  serchtxt = " Factory_Id='" + factory_Id + "' and Art_Menu_Id=" + int.Parse(menuid) + " and is_del=0 ";
                    DataSet ds       = art.GetList(serchtxt);

                    string dt = XHD.Common.GetGridJSON.DataTableToJSON(ds.Tables[0]);
                    context.Response.Write(dt);
                }
            }

            //保存查看权限
            else if (request["Action"] == "saveview")
            {
                string postdata           = Convert.ToString(HttpContext.Current.Request.QueryString["postdata"]);
                JavaScriptSerializer json = new JavaScriptSerializer();
                view sa = json.Deserialize <view>(postdata);
                XHD.Model.ssn_visit modelview = new XHD.Model.ssn_visit();
                modelview.Role_id     = int.Parse(sa.role_id);
                modelview.App_ids     = PageValidate.InputText(sa.app, 50);
                modelview.Menu_ids    = PageValidate.InputText(sa.menu, int.MaxValue);
                modelview.Art_id      = PageValidate.InputText(sa.art, int.MaxValue);
                modelview.Factory_Id  = factory_Id;
                modelview.Create_id   = emp_id;
                modelview.Create_date = DateTime.Now;

                if (!string.IsNullOrEmpty(postdata))
                {
                    //给角色分配权限
                    visit.DeleteWhere("Role_id=" + modelview.Role_id + " and Menu_ids='" + modelview.Menu_ids + "'");
                    if (modelview.Art_id != "")
                    {
                        visit.Add(modelview);
                    }
                    context.Response.Write("{sucess:sucess}");
                }
            }
            //获取当前角色的权限
            else if (request["Action"] == "getview")
            {
                string postdata           = Convert.ToString(HttpContext.Current.Request.QueryString["postdata"]);
                JavaScriptSerializer json = new JavaScriptSerializer();
                view sa = json.Deserialize <view>(postdata);
                XHD.Model.ssn_visit modelview = new XHD.Model.ssn_visit();
                modelview.Role_id  = int.Parse(sa.role_id);
                modelview.App_ids  = sa.app;
                modelview.Menu_ids = sa.menu;
                modelview.Art_id   = sa.art;

                string  roledata = "";
                DataSet ds       = visit.GetList("Role_id=" + modelview.Role_id + " and Menu_ids='" + modelview.Menu_ids + "'");
                if (ds.Tables[0].Rows.Count > 0)
                {
                    DataRow dr = ds.Tables[0].Rows[0];
                    roledata = dr["Art_id"].ToString();
                }
                context.Response.Write(roledata);
            }

            #endregion
        }