private int GetAuthType(Guid authSourceFid)
        {
            int dataCnt = new MenuDAL().GetCounts("and [VALID_FLAG] <> 0 and [NEED_AUTH] = 1 and [FID] = '" + authSourceFid + "'");

            if (dataCnt > 0)
            {
                return(1);
            }
            dataCnt = new MenuActionDAL().GetCounts("and [VALID_FLAG] <> 0 and [NEED_AUTH] = 1 and [FID] = '" + authSourceFid + "'");
            if (dataCnt > 0)
            {
                return(2);
            }
            dataCnt = new ReportDAL().GetCounts("and [VALID_FLAG] <> 0 and [IS_AUTH] = 1 and [FID] = '" + authSourceFid + "'");
            if (dataCnt > 0)
            {
                return(3);
            }
            dataCnt = new ChartDAL().GetCounts("and [VALID_FLAG] <> 0 and [IS_AUTH] = 1 and [FID] = '" + authSourceFid + "'");
            if (dataCnt > 0)
            {
                return(4);
            }
            return(0);
        }
        /// <summary>
        /// 菜单添加功能
        /// </summary>
        /// <param name="menuFid"></param>
        /// <param name="actionFid"></param>
        /// <param name="clientJs"></param>
        /// <param name="actionOrder"></param>
        /// <param name="needAuth"></param>
        /// <param name="detailFlag"></param>
        /// <param name="loginUser"></param>
        /// <returns></returns>
        public bool SetMenuAction(Guid menuFid, Guid actionFid, string clientJs, int actionOrder, bool needAuth, bool detailFlag, string loginUser)
        {
            MenuActionDAL menuActionDal = new MenuActionDAL();
            ///查看关系是否已存在
            MenuActionInfo menuActionInfo = menuActionDal.GetInfo(menuFid, actionFid);

            if (menuActionInfo == null)
            {
                menuActionInfo             = new MenuActionInfo();
                menuActionInfo.Fid         = Guid.NewGuid();
                menuActionInfo.MenuFid     = menuFid;
                menuActionInfo.ActionFid   = actionFid;
                menuActionInfo.ClientJs    = clientJs;
                menuActionInfo.ActionOrder = actionOrder;
                menuActionInfo.NeedAuth    = needAuth;
                menuActionInfo.DetailFlag  = detailFlag;
                menuActionInfo.ValidFlag   = true;
                menuActionInfo.CreateDate  = DateTime.Now;
                menuActionInfo.CreateUser  = loginUser;
                return(menuActionDal.Add(menuActionInfo) > 0 ? true : false);
            }
            menuActionInfo.ClientJs    = clientJs;
            menuActionInfo.ActionOrder = actionOrder;
            menuActionInfo.NeedAuth    = needAuth;
            menuActionInfo.DetailFlag  = detailFlag;
            menuActionInfo.ModifyDate  = DateTime.Now;
            menuActionInfo.ModifyUser  = loginUser;
            return(menuActionDal.Update(menuActionInfo) > 0 ? true : false);
            ///
        }
        /// <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());
        }