Ejemplo n.º 1
0
        public List <Role> GetAllRoles()
        {
            List <Role> roles = new List <Role>();
            string      sql   = "select * from [Role]";
            DataTable   dt    = sqlHelper.Query(sql);

            if (dt != null && dt.Rows.Count > 0)
            {
                PermissionLogic pl = PermissionLogic.GetInstance();
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    Role role = new Role();
                    role.ID          = Convert.ToInt32(dt.Rows[i]["ID"]);
                    role.Name        = dt.Rows[i]["Name"].ToString();
                    role.Flag        = Convert.ToBoolean(dt.Rows[i]["Flag"]);
                    role.Permissions = Common.GetPermissions(dt.Rows[i]["Permissions"].ToString(), pl);
                    if (dt.Rows[i]["Remark"] != null && dt.Rows[i]["Remark"] != DBNull.Value)
                    {
                        role.Remark = dt.Rows[i]["Remark"].ToString();
                    }
                    else
                    {
                        role.Remark = "";
                    }
                    roles.Add(role);
                }
            }
            return(roles);
        }
Ejemplo n.º 2
0
        public static PermissionLogic GetInstance()
        {
            if (instance == null)
            {
                instance = new PermissionLogic();
            }

            return(instance);
        }
Ejemplo n.º 3
0
        public static List <int> GetPermissionIds(string pers, PermissionLogic pl = null)
        {
            List <int> perms = new List <int>();

            string[] ids = pers.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
            if (pl == null)
            {
                pl = PermissionLogic.GetInstance();
            }
            foreach (string id in ids)
            {
                int I;
                if (int.TryParse(id, out I))
                {
                    perms.Add(I);
                }
            }
            return(perms);
        }
Ejemplo n.º 4
0
        public static PermissionCollection GetPermissions(string pers, PermissionLogic pl = null)
        {
            PermissionCollection perms = new PermissionCollection();

            string[] ids = pers.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
            if (pl == null)
            {
                pl = PermissionLogic.GetInstance();
            }
            foreach (string id in ids)
            {
                int I;
                if (int.TryParse(id, out I))
                {
                    Permission perm = pl.GetPermission(I);
                    perms.Add(perm);
                }
            }
            return(perms);
        }