예제 #1
0
파일: BF_BULLETIN.cs 프로젝트: radtek/SRMS
        /// <summary>
        /// 得到有权限阅读的公告集合
        /// </summary>
        /// <param name="userId">用户ID</param>
        /// <param name="topNum">读取多少条,默认为全部</param>
        /// <returns></returns>
        public List <Entity> GetUserPowerRead(int?userId = null, int topNum = 0)
        {
            List <Entity> returnList = new List <Entity>();

            if (userId == null)
            {
                userId = SystemSession.UserID;
            }

            BF_USER.Entity userData = BF_USER.Instance.GetEntityByKey <BF_USER.Entity>(userId);
            int            dept     = userData.DEPT_ID;                                                          //当前用户所在部门ID

            string[] roles = userData.ROLE_IDS.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); //当前用户所属角色

            #region 得到公告集合
            Order          order        = new Order("UPDATE_TIME", "desc");
            IList <Entity> bulletinList = Instance.GetList <Entity>(order, "IS_ENABLE=1", null);//得到所有可用的公告列表

            order = new Order("id", "DESC");
            IList <BF_DEPARTMENT.Entity> allDepart = BF_DEPARTMENT.Instance.GetList <BF_DEPARTMENT.Entity>(order);//得到所有部门集合

            if (bulletinList == null)
            {
                return(null);
            }

            ///开始查找公告集合
            foreach (Entity bulletin in bulletinList)
            {
                if (topNum > 0 && returnList.Count >= topNum)//默认读取所有公告,如果指定了读取条数,就按指定的数目来读
                {
                    return(returnList);
                }
                bool isOk = false;                                                                                           //是否找到
                #region 部门查询
                string[] deptList = bulletin.RECV_DEPT_IDS.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); //部门列表ID
                if (deptList.Length > 0)
                {
                    foreach (string deptItem in deptList)
                    {
                        if (dept.ToString() == deptItem)
                        {
                            returnList.Add(bulletin);//记录可看的公告
                            isOk = true;
                            break;
                        }
                    }
                }
                #endregion
                if (isOk)//找到了,就找下一个
                {
                    continue;
                }
                #region 角色查询
                string[] roleList = bulletin.RECV_ROLE_IDS.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);//角色列表
                if (roleList.Length > 0 && roles.Length > 0)
                {
                    foreach (string roleItem in roles)
                    {
                        foreach (var role in roleList)
                        {
                            if (roleItem == role)
                            {
                                returnList.Add(bulletin);//记录可看的公告
                                isOk = true;
                                break;
                            }
                        }
                        if (isOk)//找到了,就找下一个
                        {
                            break;
                        }
                    }
                }
                #endregion
            }
            #endregion

            return(returnList);
        }
예제 #2
0
        /// <summary>
        /// 写入SESSION
        /// </summary>
        /// <param name="userID"></param>
        /// <param name="userName">用户登录名</param>
        /// <param name="fullUserName">用户中文名</param>
        /// <param name="departmentID"></param>
        /// <param name="dicMenus"></param>
        public static void WriteSession(int userID, string userName, string fullUserName, int departmentID, Dictionary <int, BF_MENU.Entity> dicMenus)
        {
            Dictionary <string, int> dicMenuURLs = new Dictionary <string, int>();

            BF_USER.Entity userEntity = BF_USER.Instance.GetEntityByKey <BF_USER.Entity>(userID);
            //BF_DEPARTMENT.Entity deptEntity = BF_DEPARTMENT.Instance.GetEntityByKey<BF_DEPARTMENT.Entity>(departmentCode);
            BF_DEPARTMENT.Entity deptEntity = BF_DEPARTMENT.Instance.GetEntityByKey <BF_DEPARTMENT.Entity>(departmentID);

            foreach (var kvp in dicMenus)
            {
                if (string.IsNullOrWhiteSpace(kvp.Value.URL) == true)
                {
                    continue;
                }
                string url = kvp.Value.URL.ToLower();
                if (dicMenuURLs.ContainsKey(url) == false)
                {
                    dicMenuURLs.Add(url, kvp.Key);
                }
            }

            if (IsWindowsServiceApplication == true)
            {
                _userID       = userID;
                _userName     = userName;
                _fullUserName = fullUserName;
                _departmentID = departmentID;
                _dicMenus     = dicMenus;
                _dicMenuURLs  = dicMenuURLs;
                if (deptEntity != null)
                {
                    _departmentID    = deptEntity.ID;
                    _departmentCode  = deptEntity.DEPT_CODE;
                    _departmentName  = deptEntity.NAME;
                    _departmentLevel = deptEntity.DEPT_LEVEL;
                    _deptFlag        = deptEntity.DEPT_FLAG;
                    _deptExtend1     = deptEntity.EXTEND_1;
                    _deptExtend2     = deptEntity.EXTEND_2;
                    _deptExtend3     = deptEntity.EXTEND_3;
                    _deptExtend4     = deptEntity.EXTEND_4;
                    _deptExtend5     = deptEntity.EXTEND_5;
                }
                else
                {
                    _departmentID    = -1;
                    _departmentLevel = -1;
                }

                _userFlag1   = userEntity.FLAG_1;
                _userFlag2   = userEntity.FLAG_2;
                _userFlag3   = userEntity.FLAG_3;
                _userExtend1 = userEntity.EXTEND_1;
                _userExtend2 = userEntity.EXTEND_2;
                _userExtend3 = userEntity.EXTEND_3;
            }
            else
            {
                HttpContext.Current.Session["BEF_USER_ID"]        = userID;
                HttpContext.Current.Session["BEF_USER_NAME"]      = userName;
                HttpContext.Current.Session["BEF_FULL_USER_NAME"] = fullUserName;
                HttpContext.Current.Session["BEF_DEPARTMENT_ID"]  = departmentID;

                HttpContext.Current.Session["BEF_MENUS"]     = dicMenus;
                HttpContext.Current.Session["BEF_MENU_URLS"] = dicMenuURLs;
                //扩展
                HttpContext.Current.Session["BEF_USER_FLAG_1"]   = userEntity.FLAG_1;
                HttpContext.Current.Session["BEF_USER_FLAG_2"]   = userEntity.FLAG_2;
                HttpContext.Current.Session["BEF_USER_FLAG_3"]   = userEntity.FLAG_3;
                HttpContext.Current.Session["BEF_USER_EXTEND_1"] = userEntity.EXTEND_1;
                HttpContext.Current.Session["BEF_USER_EXTEND_2"] = userEntity.EXTEND_2;
                HttpContext.Current.Session["BEF_USER_EXTEND_3"] = userEntity.EXTEND_3;

                if (deptEntity != null)
                {
                    HttpContext.Current.Session["BEF_DEPARTMENT_ID"]    = deptEntity.ID;
                    HttpContext.Current.Session["BEF_DEPARTMENT_CODE"]  = deptEntity.DEPT_CODE;
                    HttpContext.Current.Session["BEF_DEPARTMENT_NAME"]  = deptEntity.NAME;
                    HttpContext.Current.Session["BEF_DEPARTMENT_LEVEL"] = deptEntity.DEPT_LEVEL;

                    HttpContext.Current.Session["BEF_DEPT_FLAG"]     = deptEntity.DEPT_FLAG;
                    HttpContext.Current.Session["BEF_DEPT_EXTEND_1"] = deptEntity.EXTEND_1;
                    HttpContext.Current.Session["BEF_DEPT_EXTEND_2"] = deptEntity.EXTEND_2;
                    HttpContext.Current.Session["BEF_DEPT_EXTEND_3"] = deptEntity.EXTEND_3;
                    HttpContext.Current.Session["BEF_DEPT_EXTEND_4"] = deptEntity.EXTEND_4;
                    HttpContext.Current.Session["BEF_DEPT_EXTEND_5"] = deptEntity.EXTEND_5;
                }
                else
                {
                    HttpContext.Current.Session["BEF_DEPARTMENT_ID"]    = -1;
                    HttpContext.Current.Session["BEF_DEPARTMENT_CODE"]  = 0;
                    HttpContext.Current.Session["BEF_DEPARTMENT_NAME"]  = "";
                    HttpContext.Current.Session["BEF_DEPARTMENT_LEVEL"] = -1;

                    HttpContext.Current.Session["BEF_DEPT_FLAG"]     = 0;
                    HttpContext.Current.Session["BEF_DEPT_EXTEND_1"] = "";
                    HttpContext.Current.Session["BEF_DEPT_EXTEND_2"] = "";
                    HttpContext.Current.Session["BEF_DEPT_EXTEND_3"] = "";
                    HttpContext.Current.Session["BEF_DEPT_EXTEND_4"] = "";
                    HttpContext.Current.Session["BEF_DEPT_EXTEND_5"] = "";
                }

                //SESSION失效时间
                HttpContext.Current.Session.Timeout = BF_SYS_CONFIG.SessionTime;
            }
        }