C#.NET 大型通用信息化系統集成快速開發平臺 4.1 版本 - 大數據分頁功能改進、數據權限改進

代碼生成器大數據分頁安全

 

下面參考代碼是簡易的數據權限的實現,大多狀況下下面的數據權限的功能能夠知足不少企業的須要了大數據

        #region public DataTable GetDataTableByPage(BaseUserInfo userInfo, out int recordCount, int pageIndex = 0, int pageSize = 20, string sortExpression = null, string sortDire = null) 分頁查詢
        /// <summary>
        /// 分頁查詢
        /// </summary>
        /// <param name="userInfo">用戶</param>
        /// <param name="recordCount">記錄數</param>
        /// <param name="pageIndex">當前頁</param>
        /// <param name="pageSize">每頁顯示記錄條數</param>
        /// <param name="sortExpression">排序字段</param>
        /// <param name="sortDire">排序方向</param>
        /// <returns>數據表</returns>
        public DataTable GetDataTableByPage(BaseUserInfo userInfo, out int recordCount, int pageIndex = 0, int pageSize = 20, string sortExpression = null, string sortDire = null)
        {
            // 寫入調試信息
            #if (DEBUG)
                int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod());
            #endif

            // 加強安全驗證防止未登陸用戶調用
            #if (!DEBUG)
                LogOnService.UserIsLogOn(userInfo);
            #endif

            var dt = new DataTable(LanNiaoKeJiEntity.TableName);
            
            using (IDbHelper ucDbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType))
            {
                try
                {
                    ucDbHelper.Open(UserCenterDbConnection);
                    BaseLogManager.Instance.Add(userInfo, this.serviceName, "取得列表", MethodBase.GetCurrentMethod());

                    using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.BusinessDbType))
                    {
                        try
                        {
                            dbHelper.Open(BusinessDbConnection);
                            // 取得列表
                            LanNiaoKeJiManager manager = new LanNiaoKeJiManager(dbHelper, userInfo);
                            string order = sortExpression + " " + sortDire;
                            string whereConditional = string.Empty;
                            List<IDbDataParameter> dbParameters = new List<IDbDataParameter>();
                            BaseUserManager userManager = new BaseUserManager();
                            if (userManager.IsInRoleByCode(userInfo, "User"))
                            {
                                // 普通用戶,只能看本身的
                                whereConditional = BaseBusinessLogic.FieldUserId + "=" + dbHelper.GetParameter(BaseBusinessLogic.FieldUserId);
                                dbParameters.Add(dbHelper.MakeParameter(BaseBusinessLogic.FieldUserId, userInfo.Id));
                            }
                            else if (userManager.IsInRoleByCode(userInfo, "DepartmentManager"))
                            {
                                // 部門主管,只能看本身部門的
                                whereConditional = BaseBusinessLogic.FieldDepartmentId + "=" + dbHelper.GetParameter(BaseBusinessLogic.FieldDepartmentId);
                                dbParameters.Add(dbHelper.MakeParameter(BaseBusinessLogic.FieldDepartmentId, userInfo.DepartmentId));
                            }
                            else if (userManager.IsInRoleByCode(userInfo, "CompanyManager"))
                            {
                                // 公司主管,只能看本身公司的
                                whereConditional = BaseBusinessLogic.FieldCompanyId + "=" + dbHelper.GetParameter(BaseBusinessLogic.FieldCompanyId);
                                dbParameters.Add(dbHelper.MakeParameter(BaseBusinessLogic.FieldCompanyId, userInfo.CompanyId));
                            }
                            else if (userManager.IsInRoleByCode(userInfo, "Manager"))
                            {
                                // 管理者,能夠看全部的,不限制條件
                            }
                            dt.TableName = LanNiaoKeJiEntity.TableName;
                        }
                        catch (Exception ex)
                        {
                            BaseExceptionManager.LogException(ucDbHelper, userInfo, ex);
                            throw;
                        }
                        finally
                        {
                            dbHelper.Close();
                        }
                    }
                }
                catch (Exception ex)
                {
                    BaseExceptionManager.LogException(ucDbHelper, userInfo, ex);
                    throw;
                }
                finally
                {
                    ucDbHelper.Close();
                }
            }

            // 寫入調試信息
            #if (DEBUG)
                BaseBusinessLogic.EndDebug(userInfo, MethodBase.GetCurrentMethod(), milliStart);
            #endif

            return dt;
        }
        #endregion
相關文章
相關標籤/搜索