예제 #1
0
        /// <summary>
        /// 只获取弹出窗体的授权动作
        /// </summary>
        /// <param name="menuFid"></param>
        /// <param name="roleFid"></param>
        /// <param name="entityName"></param>
        /// <param name="formEditWidth"></param>
        /// <param name="formEditHeight"></param>
        /// <param name="formUrl"></param>
        /// <returns></returns>
        public List <ActionInfo> GetFormActions(Guid menuFid, Guid roleFid, string entityName, out int formEditWidth, out int formEditHeight, out string formUrl)
        {
            ///out默认值
            formEditWidth  = 800;
            formEditHeight = 480;
            formUrl        = string.Empty;
            ///弹出窗体,在菜单管理中限制同级菜单名称不能重复
            MenuInfo formMenuInfo = new MenuDAL().GetInfo(entityName, menuFid);

            if (formMenuInfo == null)
            {
                throw new Exception("MC:0x00000028");///菜单数据错误
            }
            ///窗体属性
            formEditWidth  = formMenuInfo.EditFormWidth.GetValueOrDefault();
            formEditHeight = formMenuInfo.EditFormHeight.GetValueOrDefault();
            formUrl        = formMenuInfo.LinkUrl;

            ///所有按钮,后期按MENU_FID区分
            List <MenuActionInfo> menuAtions = dal.GetList("[MENU_FID] = N'" + formMenuInfo.Fid.GetValueOrDefault() + "'", string.Empty);

            ///无按钮
            if (menuAtions.Count == 0)
            {
                return(new List <ActionInfo>());
            }
            ///不需要授权页面按钮的FID
            List <Guid> menuActionFids = menuAtions.Where(d => !d.NeedAuth.GetValueOrDefault()).Select(d => d.Fid.GetValueOrDefault()).ToList();
            ///获取已授权的按钮GUID
            List <Guid> sourceFids = new RoleAuthDAL().GetAuthSourceFidsByRoleFidAuthTypeInSourceFids(roleFid
                                                                                                      , (int)AuthTypeConstants.ACTION///授权类型为按钮
                                                                                                      , menuAtions.Count(d => d.NeedAuth.GetValueOrDefault()) == 0 ? string.Empty : "'" + string.Join("','", menuAtions.Where(d => d.NeedAuth.GetValueOrDefault()).Select(d => d.Fid.GetValueOrDefault()).ToArray()) + "'");

            ///可以显示的页面按钮
            menuActionFids.AddRange(sourceFids);
            if (menuActionFids.Count == 0)
            {
                return(new List <ActionInfo>());
            }
            ///获取所有的动作按钮
            List <ActionInfo> actionList  = new ActionDAL().GetList("[FID] in ('" + string.Join("','", menuAtions.Where(d => menuActionFids.Contains(d.Fid.GetValueOrDefault())).Select(d => d.ActionFid.GetValueOrDefault()).ToArray()) + "')", string.Empty);
            List <ActionInfo> actionInfos = new List <ActionInfo>();

            foreach (var menuActionFid in menuActionFids)
            {
                MenuActionInfo menuActionInfo = menuAtions.FirstOrDefault(d => d.Fid.GetValueOrDefault() == menuActionFid);
                if (menuActionInfo == null)
                {
                    continue;
                }
                ActionInfo actionInfo = actionList.FirstOrDefault(d => d.Fid.GetValueOrDefault() == menuActionInfo.ActionFid.GetValueOrDefault()).Clone();
                if (actionInfo == null)
                {
                    continue;
                }
                actionInfo.IsListAction = false;
                actionInfo.DisplayOrder = menuActionInfo.ActionOrder.GetValueOrDefault();
                actionInfo.ClientJs     = menuActionInfo.ClientJs;
                actionInfo.Fid          = menuActionInfo.Fid;
                actionInfo.DetailFlag   = menuActionInfo.DetailFlag.GetValueOrDefault();
                actionInfos.Add(actionInfo);
            }
            return(actionInfos.OrderBy(d => d.DisplayOrder).ToList());
        }
예제 #2
0
        /// <summary>
        /// 获取所有需要授权的项目,其中IS_AUTH=TRUE表示已经授权
        /// </summary>
        /// <param name="roleFid"></param>
        /// <returns></returns>
        public List <RoleAuthInfo> GetRoleAuthList(Guid roleFid)
        {
            ///需要授权的菜单
            List <MenuInfo> menus = new MenuDAL().GetList("and [VALID_FLAG] <> 0", string.Empty);
            ///需要授权的功能项
            List <MenuActionInfo> menuactions = new MenuActionDAL().GetList("and [VALID_FLAG] <> 0", string.Empty);
            ///功能项
            List <ActionInfo> actions = new ActionDAL().GetList("and [VALID_FLAG] <> 0", string.Empty);
            ///需要授权的报表
            List <ReportInfo> reports = new ReportDAL().GetList("and [VALID_FLAG] <> 0", string.Empty);
            ///需要授权的图表
            List <ChartInfo> charts = new ChartDAL().GetList("and [VALID_FLAG] <> 0", string.Empty);
            ///角色对应已授权的项目
            List <RoleAuthInfo> roleauths = new RoleAuthDAL().GetList("and [ROLE_FID] = '" + roleFid + "' and [IS_AUTH] <> 0 and [VALID_FLAG] <> 0", string.Empty);

            List <RoleAuthInfo> list = new List <RoleAuthInfo>();

            ///菜单
            foreach (var item in menus)
            {
                RoleAuthInfo info = new RoleAuthInfo();
                info.AuthSourceFid  = item.Fid;
                info.AuthSourceName = item.MenuName + "|" + item.MenuNameCn;
                info.AuthType       = 1;
                info.AuthTypeName   = "菜单";
                info.DisplayOrder   = item.DisplayOrder.GetValueOrDefault();
                if (item.NeedAuth.GetValueOrDefault())
                {
                    var roleauth = roleauths.FirstOrDefault(d => d.AuthSourceFid == item.Fid && d.AuthType == 1);
                    info.IsAuth = roleauth == null ? false : true;
                }
                else
                {
                    info.IsAuth = true;
                }
                info.ParentSourceFid = item.ParentMenuFid.GetValueOrDefault();
                list.Add(info);
            }
            ///功能
            foreach (var item in menuactions)
            {
                RoleAuthInfo info = new RoleAuthInfo();
                info.AuthSourceFid = item.Fid;
                var action = actions.FirstOrDefault(d => d.Fid == item.ActionFid);
                if (action == null)
                {
                    continue;
                }
                info.AuthSourceName = action.ActionName + "|" + action.ActionNameCn;
                info.AuthType       = 2;
                info.AuthTypeName   = "功能";
                info.DisplayOrder   = item.ActionOrder.GetValueOrDefault();
                if (item.NeedAuth.GetValueOrDefault())
                {
                    var roleauth = roleauths.FirstOrDefault(d => d.AuthSourceFid == item.Fid && d.AuthType == 2);
                    info.IsAuth = roleauth == null ? false : true;
                }
                else
                {
                    info.IsAuth = true;
                }
                info.ParentSourceFid = item.MenuFid.GetValueOrDefault();
                var menuinfo = list.FirstOrDefault(d => d.AuthType == 1 && d.AuthSourceFid == item.MenuFid);
                if (menuinfo == null)
                {
                    continue;
                }
                list.Add(info);
            }
            RoleAuthInfo reportauth = new RoleAuthInfo();

            reportauth.AuthSourceFid   = Guid.Parse("2238F7AD-9196-4B53-A0D0-81460FDA1F4C");
            reportauth.AuthSourceName  = "REPORT|报表";
            reportauth.AuthType        = 1;
            reportauth.AuthTypeName    = "菜单";
            reportauth.IsAuth          = true;
            reportauth.DisplayOrder    = int.MaxValue - 1;
            reportauth.ParentSourceFid = Guid.Empty;
            list.Add(reportauth);
            ///报表
            foreach (var item in reports)
            {
                RoleAuthInfo info = new RoleAuthInfo();
                info.AuthSourceFid  = item.Fid;
                info.AuthSourceName = item.NameEn + "|" + item.Name;
                info.AuthType       = 3;
                info.AuthTypeName   = "报表";
                if (item.IsAuth.GetValueOrDefault())
                {
                    var roleauth = roleauths.FirstOrDefault(d => d.AuthSourceFid == item.Fid && d.AuthType == 3);
                    info.IsAuth = roleauth == null ? false : true;
                }
                else
                {
                    info.IsAuth = true;
                }
                info.ParentSourceFid = reportauth.AuthSourceFid.GetValueOrDefault();
                list.Add(info);
            }
            RoleAuthInfo chartauth = new RoleAuthInfo();

            chartauth.AuthSourceFid   = Guid.Parse("6E714DD6-2D41-45AE-88C2-433EEF1973E9");
            chartauth.AuthSourceName  = "CHART|图表";
            chartauth.AuthType        = 1;
            chartauth.AuthTypeName    = "菜单";
            chartauth.IsAuth          = true;
            chartauth.DisplayOrder    = int.MaxValue;
            chartauth.ParentSourceFid = Guid.Empty;
            list.Add(chartauth);
            ///图表
            foreach (var item in charts)
            {
                RoleAuthInfo info = new RoleAuthInfo();
                info.AuthSourceFid  = item.Fid;
                info.AuthSourceName = item.NameEn + "|" + item.Name;
                info.AuthType       = 4;
                info.AuthTypeName   = "图表";
                if (item.IsAuth.GetValueOrDefault())
                {
                    var roleauth = roleauths.FirstOrDefault(d => d.AuthSourceFid == item.Fid && d.AuthType == 4);
                    info.IsAuth = roleauth == null ? false : true;
                }
                else
                {
                    info.IsAuth = true;
                }
                info.ParentSourceFid = chartauth.AuthSourceFid.GetValueOrDefault();
                list.Add(info);
            }
            return(list.OrderBy(d => d.DisplayOrder).ToList());
        }