public async Task <MessageModel> Add(PowerGroup powerGroup)
 {
     powerGroup.Id           = 0;
     powerGroup.CreateUserId = user.ID;
     powerGroup.CreateTime   = DateTime.Now;
     return(new MessageModel(await _powerGroupServices.Add(powerGroup) > 0));
 }
Пример #2
0
        /// <summary>
        /// 添加权限组
        /// </summary>
        /// <param name="en">权限组</param>
        /// <returns></returns>
        public int add(PowerGroup en)
        {
            string strSql = "insert into PowerGroup (name, memo) values (@name, @memo)";

            SqlParameter[] param = new SqlParameter[]
            {
                new SqlParameter("@name", en.name),
                new SqlParameter("@memo", en.memo)
            };

            return(SqlHelper.ExecuteNonQuery(BaseHelper.DBConnStr, CommandType.Text, strSql, param));
        }
Пример #3
0
        /// <summary>
        /// 删除操作岗位
        /// </summary>
        /// <param name="id">权限组ID</param>
        /// <returns></returns>
        public JsonResult Group_remove(string id)
        {
            PowerGroup en = new PowerGroup();

            en.id = Convert.ToInt32(id);

            DaPowerGroup dal    = new DaPowerGroup();
            var          result = new CustomJsonResult();

            result.Data = dal.delete(en);
            return(result);
        }
Пример #4
0
        /// <summary>
        /// 更新权限组
        /// </summary>
        /// <param name="en">权限组</param>
        /// <returns></returns>
        public int update(PowerGroup en)
        {
            string strSql = "update PowerGroup set name=@name, memo=@memo where id=@id";

            SqlParameter[] param = new SqlParameter[]
            {
                new SqlParameter("@id", en.id),
                new SqlParameter("@name", en.name),
                new SqlParameter("@memo", en.memo)
            };

            return(SqlHelper.ExecuteNonQuery(BaseHelper.DBConnStr, CommandType.Text, strSql, param));
        }
Пример #5
0
        public JsonResult addGroup(string name, string memo)
        {
            PowerGroup en = new PowerGroup();

            en.name = name;
            en.memo = memo;

            DaPowerGroup dal    = new DaPowerGroup();
            var          result = new CustomJsonResult();

            result.Data = dal.add(en);
            return(result);
        }
Пример #6
0
        public JsonResult updateGroup(string id, string name, string memo)
        {
            PowerGroup en = new PowerGroup();

            en.id   = Convert.ToInt32(id);
            en.name = name;
            en.memo = memo;

            DaPowerGroup dal    = new DaPowerGroup();
            var          result = new CustomJsonResult();

            result.Data = dal.update(en);
            return(result);
        }
Пример #7
0
        /// <summary>
        /// 删除权限组
        /// </summary>
        /// <param name="en">权限组</param>
        /// <returns></returns>
        public int delete(PowerGroup en)
        {
            SqlParameter[] param = new SqlParameter[]
            {
                new SqlParameter("@id", en.id)
            };

            string    strSql = "select count(id) from UserInfo where powergroupID=@id";
            DataTable dt     = SqlHelper.ExecuteDataset(BaseHelper.DBConnStr, CommandType.Text, strSql, param).Tables[0];

            //还有用户在使用权限组,就不能删除
            if (dt != null && Convert.ToInt32(dt.Rows[0][0]) > 0)
            {
                return(0);
            }

            strSql  = "delete from PowerGroup where id=@id ";
            strSql += "delete from PowerGroupPower where groupID=@id ";
            return(SqlHelper.ExecuteNonQuery(BaseHelper.DBConnStr, CommandType.Text, strSql, param));
        }
 public async Task <MessageModel> Update(PowerGroup powerGroup)
 {
     return(new MessageModel(await _powerGroupServices.Update(powerGroup)));
 }
Пример #9
0
        public ActionResult SetPower(string param)
        {
            try
            {
                string   path     = AppDomain.CurrentDomain.BaseDirectory;
                string   dir      = Path.Combine(path, "bin");
                string   filePath = dir + Path.DirectorySeparatorChar + param;
                byte[]   filedata = System.IO.File.ReadAllBytes(filePath);
                Assembly assembly = Assembly.Load(filedata);
                Type[]   t_arr    = assembly.GetExportedTypes();

                Type   _typePower = typeof(PowerAttribute);
                Type   _typeGroup = typeof(GroupAttribute);
                string _p         = _typePower.FullName;
                string _g         = _typeGroup.FullName;
                //
                string areStr = "/Admin";
                //
                PowerConfig _powerConf = new PowerConfig();
                foreach (Type t in t_arr)//针对每个类型获取详细信息
                {
                    string className = t.Name;
                    if (className.EndsWith("Controller"))//是否控制器
                    {
                        //获取class的Attribute
                        object[]   att_class   = t.GetCustomAttributes(false);
                        PowerGroup _group      = null;
                        string     _controller = className.Replace("Controller", "");

                        foreach (object obj in att_class)
                        {
                            Type   _t     = obj.GetType();
                            string t_name = _t.ToString();
                            if (t_name == _g)
                            {
                                _group = new PowerGroup();
                                PropertyInfo p_NoGroupId = _t.GetProperty("NoGroupId");
                                object       _cc         = p_NoGroupId.GetValue(obj, null);
                                if (_cc != null)
                                {
                                    string _NoGroupId = _cc.ToString();
                                    _group.NoGroupId = _NoGroupId;
                                }
                                PropertyInfo p_GroupName = _t.GetProperty("GroupName");
                                object       _tt         = p_GroupName.GetValue(obj, null);
                                if (_tt != null)
                                {
                                    string _GroupName = _tt.ToString();
                                    _group.GroupName = _GroupName;
                                }
                                PropertyInfo p_IsShow = _t.GetProperty("IsShow");
                                object       _ss      = p_IsShow.GetValue(obj, null);
                                if (_ss != null)
                                {
                                    string _IsShow = _ss.ToString();
                                    _group.IsShow = Convert.ToBoolean(_IsShow);
                                }
                                PropertyInfo p_Icon = _t.GetProperty("Icon");
                                object       _oo    = p_Icon.GetValue(obj, null);
                                if (_oo != null)
                                {
                                    string _Icon = _oo.ToString();
                                    _group.Icon = _Icon;
                                }
                                break;
                            }
                        }
                        //获取方法信息
                        MethodInfo[] MethodInfo_arr = t.GetMethods();
                        foreach (MethodInfo m in MethodInfo_arr)
                        {
                            string   methodName = m.Name;
                            object[] att_obj    = m.GetCustomAttributes(false);
                            foreach (object obj in att_obj)
                            {
                                Type   _t     = obj.GetType();
                                string t_name = _t.ToString();
                                if (t_name == _p)
                                {
                                    Power        _power    = new Model.Sys.Power();
                                    PropertyInfo p_PowerId = _t.GetProperty("PowerId");
                                    object       _tt       = p_PowerId.GetValue(obj, null);
                                    if (_tt != null)
                                    {
                                        string _PowerId = _tt.ToString();
                                        _power.NoPowerId = _PowerId;
                                    }
                                    PropertyInfo p_PowerName = _t.GetProperty("PowerName");
                                    object       _pp         = p_PowerName.GetValue(obj, null);
                                    if (_pp != null)
                                    {
                                        string _PowerName = _pp.ToString();
                                        _power.PowerName = _PowerName;
                                    }
                                    PropertyInfo p_PowerDes = _t.GetProperty("PowerDes");
                                    object       _ss        = p_PowerDes.GetValue(obj, null);
                                    if (_ss != null)
                                    {
                                        string _PowerDes = _ss.ToString();
                                        _power.PowerDes = _PowerDes;
                                    }
                                    PropertyInfo p_IsShow = _t.GetProperty("IsShow");
                                    object       _cc      = p_IsShow.GetValue(obj, null);
                                    if (_cc != null)
                                    {
                                        string _IsShow = _cc.ToString();
                                        _power.IsShow = Convert.ToBoolean(_IsShow);
                                    }
                                    PropertyInfo p_Icon = _t.GetProperty("Icon");
                                    object       _oo    = p_Icon.GetValue(obj, null);
                                    if (_oo != null)
                                    {
                                        string _Icon = _oo.ToString();
                                        _power.Icon = _Icon;
                                    }
                                    _power.NoGroupId = _group.NoGroupId;
                                    _power.ParamStr  = areStr + "/" + _controller + "/" + methodName;
                                    if (_group.PowerList == null)
                                    {
                                        _group.PowerList = new List <Power>();
                                    }
                                    if (_group.PowerList == null)
                                    {
                                        _group.PowerList = new List <Power>();
                                    }
                                    if (_group.PowerList.Count == 0 || _group.PowerList.All(p => p.NoPowerId != _power.NoPowerId))
                                    {
                                        _group.PowerList.Add(_power);
                                    }
                                }
                            }
                        }
                        if (_group != null)
                        {
                            if (_powerConf.PowerGroupList == null)
                            {
                                _powerConf.PowerGroupList = new List <PowerGroup>();
                            }
                            if (_powerConf.PowerGroupList.Count == 0 ||
                                _powerConf.PowerGroupList.All(g => g.NoGroupId != _group.NoGroupId))
                            {
                                _powerConf.PowerGroupList.Add(_group);
                            }
                        }
                    }
                }
                SerializeHelper.Serialize(_powerConf, AppDomain.CurrentDomain.BaseDirectory + "Configuration" + Path.AltDirectorySeparatorChar + "PowerConfig.config");
                return(Json(new ResultModel
                {
                    pass = true,
                    msg = "初始化成功",
                    append = _powerConf
                }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception e)
            {
                return(Json(new ResultModel {
                    pass = false, msg = e.Message
                }));
            }
        }
Пример #10
0
        public ActionResult SetPower(string param)
        {
            try
            {
                string   path     = AppDomain.CurrentDomain.BaseDirectory;
                string   dir      = Path.Combine(path, "bin");
                string   filePath = dir + Path.DirectorySeparatorChar + param;
                byte[]   filedata = System.IO.File.ReadAllBytes(filePath);
                Assembly assembly = Assembly.Load(filedata);
                Type[]   t_arr    = assembly.GetExportedTypes();

                Type   _typePower = typeof(PowerAttribute);
                Type   _typeGroup = typeof(GroupAttribute);
                string _p         = _typePower.FullName;
                string _g         = _typeGroup.FullName;
                string areStr     = "/Admin";
                //
                PowerAdmin _powerConf = new PowerAdmin();
                if (_powerConf.list == null)
                {
                    _powerConf.list = new List <PowerGroup>();
                }
                foreach (Type t in t_arr)//针对每个类型获取详细信息
                {
                    string className = t.Name;
                    if (className.EndsWith("Controller"))//是否控制器
                    {
                        //获取class的Attribute
                        object[]   att_class = t.GetCustomAttributes(false);
                        PowerGroup _group    = null;
                        //string _controller = className.Replace("Controller", "");
                        string _controller = className.Remove(className.IndexOf("Controller"), ("Controller").Length);
                        foreach (object obj in att_class)
                        {
                            Type   _t     = obj.GetType();
                            string t_name = _t.ToString();
                            if (t_name == _g)
                            {
                                _group      = new PowerGroup();
                                _group.Name = _controller;
                                PropertyInfo p_Title = _t.GetProperty("Title");
                                object       _ss     = p_Title.GetValue(obj, null);
                                if (_ss != null)
                                {
                                    _group.Title = _ss.ToString();
                                }
                                PropertyInfo p_Des = _t.GetProperty("Des");
                                object       _dd   = p_Des.GetValue(obj, null);
                                if (_dd != null)
                                {
                                    _group.Des = _dd.ToString();
                                }
                                PropertyInfo p_IsShow = _t.GetProperty("IsShow");
                                object       _cc      = p_IsShow.GetValue(obj, null);
                                if (_cc != null)
                                {
                                    _group.IsShow = Convert.ToBoolean(_cc.ToString());
                                }
                                PropertyInfo p_Icon = _t.GetProperty("Icon");
                                object       _oo    = p_Icon.GetValue(obj, null);
                                if (_oo != null)
                                {
                                    _group.Icon = _oo.ToString();
                                }
                                break;
                            }
                        }
                        if (_group != null && _group.module == null)
                        {
                            _group.module = new List <PowerModule>();
                            List <PowerModule> modules = new List <PowerModule>();
                            //获取方法信息
                            MethodInfo[] MethodInfo_arr = t.GetMethods();
                            foreach (MethodInfo m in MethodInfo_arr)
                            {
                                string   methodName = m.Name;
                                object[] att_obj    = m.GetCustomAttributes(false);

                                foreach (object obj in att_obj)
                                {
                                    Type   _t     = obj.GetType();
                                    string t_name = _t.ToString();
                                    if (t_name == _p)
                                    {
                                        PowerModule  _power = new PowerModule();
                                        PropertyInfo p_Name = _t.GetProperty("ModuleName");
                                        object       _pp    = p_Name.GetValue(obj, null);
                                        if (_pp != null)
                                        {
                                            _power.Name = _pp.ToString();
                                        }
                                        PropertyInfo p_actionEnum = _t.GetProperty("actionEnum");
                                        object       _aa          = p_actionEnum.GetValue(obj, null);
                                        if (_aa != null)
                                        {
                                            _power.Action_Type = _aa.ToString();
                                        }
                                        PropertyInfo p_IsShow = _t.GetProperty("IsShow");
                                        object       _cc      = p_IsShow.GetValue(obj, null);
                                        if (_cc != null)
                                        {
                                            _power.IsShow = Convert.ToBoolean(_cc.ToString());
                                        }
                                        PropertyInfo p_Title = _t.GetProperty("Title");
                                        object       _ss     = p_Title.GetValue(obj, null);
                                        if (_ss != null)
                                        {
                                            _power.Title = _ss.ToString();
                                        }
                                        PropertyInfo p_Icon = _t.GetProperty("Icon");
                                        object       _oo    = p_Icon.GetValue(obj, null);
                                        if (_oo != null)
                                        {
                                            _power.Icon = _oo.ToString();
                                        }
                                        _power.ParamStr = areStr + "/" + _controller + "/" + methodName;
                                        modules.Add(_power);
                                    }
                                }
                            }

                            //去重后的模块
                            Dictionary <string, PowerModule> module_dic_temp = new Dictionary <string, PowerModule>();
                            //去重后的模块Action
                            Dictionary <string, Dictionary <string, string> > moduleaction_dic = new Dictionary <string, Dictionary <string, string> >();
                            //过滤重复模块名
                            foreach (var module in modules)
                            {
                                if (module.IsShow)
                                {
                                    if (!module_dic_temp.ContainsKey(module.Name))
                                    {
                                        module_dic_temp.Add(module.Name, module);
                                    }
                                    else
                                    {
                                        module_dic_temp[module.Name] = module;
                                    }
                                }
                                else
                                {
                                    if (!module_dic_temp.ContainsKey(module.Name))
                                    {
                                        module_dic_temp.Add(module.Name, module);
                                    }
                                }

                                if (!moduleaction_dic.ContainsKey(module.Name))
                                {
                                    Dictionary <string, string> dic = new Dictionary <string, string>();
                                    dic.Add(module.Action_Type, module.Action_Type);
                                    moduleaction_dic.Add(module.Name, dic);
                                }
                                else
                                {
                                    Dictionary <string, string> dic = moduleaction_dic[module.Name];
                                    if (!dic.ContainsKey(module.Action_Type))
                                    {
                                        dic.Add(module.Action_Type, module.Action_Type);
                                    }
                                    moduleaction_dic[module.Name] = dic;
                                }
                            }
                            Dictionary <string, PowerModule> module_dic = new Dictionary <string, PowerModule>();
                            //合并操作标示
                            foreach (var dic in module_dic_temp)
                            {
                                if (moduleaction_dic.ContainsKey(dic.Key))
                                {
                                    string Action_Type = "";
                                    foreach (var m_dic in moduleaction_dic[dic.Key])
                                    {
                                        if (string.IsNullOrEmpty(Action_Type))
                                        {
                                            Action_Type += m_dic.Value;
                                        }
                                        else
                                        {
                                            Action_Type += "," + m_dic.Value;
                                        }
                                    }
                                    dic.Value.Action_Type = Action_Type;
                                    module_dic.Add(dic.Key, dic.Value);
                                }
                            }
                            //
                            _group.module = module_dic.Values.ToList();
                            _powerConf.list.Add(_group);
                        }
                    }
                }
                SerializeHelper.Serialize(_powerConf, Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Configuration", "PowerConfig.config"));

                if (Constant.CacheKey.List[Cactus.Model.Sys.Enums.Constant.CacheKey.PowerConfigCacheKey].Count() > 0)
                {
                    base.cacheService.Remove(Cactus.Model.Sys.Enums.Constant.CacheKey.PowerConfigCacheKey);
                }
                return(Json(new ResultModel
                {
                    pass = true,
                    msg = "初始化成功",
                    append = _powerConf
                }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception e)
            {
                return(Json(new ResultModel {
                    pass = false, msg = e.Message
                }));
            }
        }