Ejemplo n.º 1
0
        /// <summary>
        /// 按操作权限获取列表
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="tableName">目标表</param>
        /// <param name="permissionCode">操作权限</param>
        /// <returns>数据表</returns>
        public DataTable GetDataTableByPermission(BaseUserInfo userInfo, string tableName, string permissionCode = "Resource.ManagePermission")
        {
            DataTable result = null;

            var parameter = ServiceInfo.Create(userInfo, MethodBase.GetCurrentMethod());

            ServiceUtil.ProcessUserCenterReadDb(userInfo, parameter, (dbHelper) =>
            {
                var itemDetailsManager = new BaseItemDetailsManager(dbHelper, userInfo, tableName);

                // 管理员取得所有数据
                if (userInfo.IsAdministrator)
                {
                    result = itemDetailsManager.GetDataTable(
                        new KeyValuePair <string, object>(BaseItemDetailsEntity.FieldDeletionStateCode, 0)
                        , BaseItemDetailsEntity.FieldSortCode);
                }
                else
                {
                    // 管理时需要把所有的数据显示出来,所以无效的数据也需要显示的
                    // , new KeyValuePair<string, object>(BaseItemDetailsEntity.FieldEnabled, 1)

                    // 按数据权限来过滤数据
                    BasePermissionScopeManager permissionScopeManager = new BasePermissionScopeManager(dbHelper, userInfo);
                    string[] ids = permissionScopeManager.GetResourceScopeIds(userInfo.SystemCode, userInfo.Id, tableName, permissionCode);
                    result       = itemDetailsManager.GetDataTable(ids);
                }
                result.TableName = tableName;
            });
            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 获取列表
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="tableName">目标表</param>
        /// <returns>数据表</returns>
        public DataTable GetDataTable(BaseUserInfo userInfo, string tableName)
        {
            var dt = new DataTable(tableName);

            var parameter = ServiceInfo.Create(userInfo, MethodBase.GetCurrentMethod());

            ServiceUtil.ProcessBusinessDb(userInfo, parameter, (dbHelper) =>
            {
                BaseItemDetailsManager itemDetailsManager = new BaseItemDetailsManager(dbHelper, userInfo, tableName);
                // 若是系统管理员,那就返回全部数据
                if (userInfo.IsAdministrator)
                {
                    dt = itemDetailsManager.GetDataTable(
                        new KeyValuePair <string, object>(BaseItemDetailsEntity.FieldDeletionStateCode, 0)
                        , BaseItemDetailsEntity.FieldSortCode);
                }
                else
                {
                    // 按数据权限来过滤数据
                    BasePermissionScopeManager permissionScopeManager = new BasePermissionScopeManager(dbHelper, userInfo);
                    string[] ids = permissionScopeManager.GetResourceScopeIds(userInfo.SystemCode, userInfo.Id, tableName, "Resource.ManagePermission");
                    dt           = itemDetailsManager.GetDataTable(ids);
                }
                dt.TableName = tableName;
                // 管理时需要把所有的数据显示出来,所以无效的数据也需要显示的
                // , new KeyValuePair<string, object>(BaseItemDetailsEntity.FieldEnabled, 1)
            });
            return(dt);
        }
Ejemplo n.º 3
0
        public DataTable GetDataTableByCode(IDbHelper dbHelper, BaseUserInfo userInfo, string code)
        {
            // 2013-09-07 吉日嘎拉 目标表,这样来个默认的表名,有助于提高稳定性,可以有一定的容错功能
            string targetTable = "Items" + code;
            var    dt          = new DataTable(BaseItemDetailsEntity.TableName);
            // 检查有其他目标数据库表存储了数据
            BaseItemsManager itemsManager = new BaseItemsManager(dbHelper, userInfo);
            BaseItemsEntity  itemsEntity  = BaseEntity.Create <BaseItemsEntity>(itemsManager.GetDataTable(new KeyValuePair <string, object>(BaseItemsEntity.FieldCode, code)));

            if (itemsEntity != null && !String.IsNullOrEmpty(itemsEntity.TargetTable))
            {
                targetTable = itemsEntity.TargetTable;
            }

            BaseItemDetailsManager itemDetailsManager = new BaseItemDetailsManager(dbHelper, userInfo);

            itemDetailsManager = new BaseItemDetailsManager(dbHelper, userInfo, targetTable);
            // 这里只要有效的,没被删除的
            List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >();

            // 管理的时候无效的也需要被管理
            parameters.Add(new KeyValuePair <string, object>(BaseItemDetailsEntity.FieldEnabled, 1));
            parameters.Add(new KeyValuePair <string, object>(BaseItemDetailsEntity.FieldDeletionStateCode, 0));

            // 管理员取得所有数据,没采用数据权限的开关
            if (userInfo.IsAdministrator || !BaseSystemInfo.UsePermissionScope)
            {
                dt = itemDetailsManager.GetDataTable(parameters, BaseItemDetailsEntity.FieldSortCode);
            }
            else
            {
                // 按数据权限来过滤数据
                BasePermissionScopeManager permissionScopeManager = new BasePermissionScopeManager(dbHelper, userInfo);
                string[] ids = permissionScopeManager.GetResourceScopeIds(userInfo.SystemCode, userInfo.Id, itemsEntity.TargetTable, "Resource.ManagePermission");
                dt = itemDetailsManager.GetDataTable(ids);
                // 这里其实未必限制了有效的
                // BaseBusinessLogic.SetFilter(result, BaseItemDetailsEntity.FieldDeletionStateCode, "0");
                // BaseBusinessLogic.SetFilter(result, BaseItemDetailsEntity.FieldEnabled, "1");
            }
            dt.TableName = itemsEntity.TargetTable;
            return(dt);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 获取列表
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="tableName">目标表</param>
        /// <returns>数据表</returns>
        public DataTable GetDataTable(BaseUserInfo userInfo, string tableName)
        {
            // 写入调试信息
#if (DEBUG)
            int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod());
#endif

            // 加强安全验证防止未授权匿名调用
#if (!DEBUG)
            LogOnService.UserIsLogOn(userInfo);
#endif

            DataTable dataTable = new DataTable(tableName);
            using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType))
            {
                try
                {
                    dbHelper.Open(UserCenterDbConnection);
                    BaseItemDetailsManager itemDetailsManager = new BaseItemDetailsManager(dbHelper, userInfo, tableName);
                    // 检查有其他目标数据库表存储了数据
                    // BaseItemsManager itemsManager = new BaseItemsManager(dbHelper, userInfo);
                    // BaseItemsEntity itemsEntity = new BaseItemsEntity(itemsManager.Get(BaseItemDetailsEntity.FieldItemCode, itemCode));
                    // if (!String.IsNullOrEmpty(itemsEntity.TargetTable))
                    // {
                    //     itemDetailsManager = new BaseItemDetailsManager(dbHelper, userInfo, itemsEntity.TargetTable);
                    // }
                    // dataTable = itemDetailsManager.GetDataTable(BaseItemDetailsEntity.FieldDeletionStateCode, 0, BaseItemDetailsEntity.FieldEnabled, 1, BaseItemDetailsEntity.FieldSortCode);
                    // 前台管理时,应该把有效无效的都显示出来,主要是为了管理设置时无效的也可以显示出来,下拉框时需要自己控制一下
                    dataTable           = itemDetailsManager.GetDataTable(new KeyValuePair <string, object>(BaseItemDetailsEntity.FieldDeletionStateCode, 0), BaseItemDetailsEntity.FieldSortCode);
                    dataTable.TableName = tableName;
                    // 添加日志
                    BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, AppMessage.ItemDetailsService_GetDataTable, MethodBase.GetCurrentMethod());
                }
                catch (Exception ex)
                {
                    BaseExceptionManager.LogException(dbHelper, userInfo, ex);
                    throw ex;
                }
                finally
                {
                    dbHelper.Close();
                }
            }

            // 写入调试信息
#if (DEBUG)
            BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart);
#endif

            return(dataTable);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 绑定下拉列表
        /// </summary>
        /// <param name="userInfo">用户信息</param>
        /// <param name="dropDownList">下拉列表</param>
        /// <param name="itemsTableName">表名</param>
        /// <param name="addEmptyItem">是否增加空行</param>
        public static void GetItemDetails(BaseUserInfo userInfo, DropDownList dropDownList, string itemsTableName, bool addEmptyItem = true)
        {
            BaseItemDetailsManager manager = new BaseItemDetailsManager(itemsTableName);
            var dt = manager.GetDataTable(new KeyValuePair <string, object>(BaseItemDetailsEntity.FieldEnabled, 1)
                                          , new KeyValuePair <string, object>(BaseItemDetailsEntity.FieldDeletionStateCode, 0));

            dropDownList.DataValueField = BaseItemDetailsEntity.FieldItemCode;
            dropDownList.DataTextField  = BaseItemDetailsEntity.FieldItemName;
            dt.DefaultView.Sort         = BaseItemDetailsEntity.FieldSortCode;
            dropDownList.DataSource     = dt.DefaultView;
            dropDownList.DataBind();
            if (addEmptyItem)
            {
                dropDownList.Items.Insert(0, new ListItem());
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 获取实体
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="id">主键</param>
        /// <returns>数据表</returns>
        public BaseItemDetailsEntity GetObjectByCode(BaseUserInfo userInfo, string tableName, string code)
        {
            BaseItemDetailsEntity itemDetailsEntity = new BaseItemDetailsEntity();

            var parameter = ServiceInfo.Create(userInfo, MethodBase.GetCurrentMethod());

            ServiceUtil.ProcessUserCenterReadDb(userInfo, parameter, (dbHelper) =>
            {
                var itemDetailsManager = new BaseItemDetailsManager(dbHelper, userInfo, tableName);
                var dt = itemDetailsManager.GetDataTable(new KeyValuePair <string, object>(BaseItemDetailsEntity.FieldItemCode, code), BaseItemDetailsEntity.FieldSortCode);
                if ((dt != null) && (dt.Rows.Count > 0))
                {
                    itemDetailsEntity = (BaseItemDetailsEntity)itemDetailsEntity.GetFrom(dt.Rows[0]);
                }
            });
            return(itemDetailsEntity);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 获取实体
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="id">主键</param>
        /// <returns>数据表</returns>
        public BaseItemDetailsEntity GetEntityByCode(BaseUserInfo userInfo, string tableName, string code)
        {
            // 写入调试信息
            #if (DEBUG)
            int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod());
            #endif

            // 加强安全验证防止未授权匿名调用
            #if (!DEBUG)
            LogOnService.UserIsLogOn(userInfo);
            #endif

            BaseItemDetailsEntity itemDetailsEntity = new BaseItemDetailsEntity();
            using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType))
            {
                try
                {
                    dbHelper.Open(UserCenterDbConnection);
                    BaseItemDetailsManager itemDetailsManager = new BaseItemDetailsManager(dbHelper, userInfo, tableName);
                    DataTable datatable = itemDetailsManager.GetDataTable(new KeyValuePair <string, object>(BaseItemDetailsEntity.FieldItemCode, code), BaseItemDetailsEntity.FieldSortCode);
                    if ((datatable != null) && (datatable.Rows.Count > 0))
                    {
                        itemDetailsEntity = itemDetailsEntity.GetFrom(datatable.Rows[0]);
                    }
                    BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, AppMessage.ItemDetailsService_GetEntity, MethodBase.GetCurrentMethod());
                }
                catch (Exception ex)
                {
                    BaseExceptionManager.LogException(dbHelper, userInfo, ex);
                    throw ex;
                }
                finally
                {
                    dbHelper.Close();
                }
            }

            // 写入调试信息
            #if (DEBUG)
            BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart);
            #endif

            return(itemDetailsEntity);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 获取列表
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="tableName">目标表</param>
        /// <returns>数据表</returns>
        public DataTable GetDataTable(BaseUserInfo userInfo, string tableName)
        {
            var dt = new DataTable(tableName);

            var parameter = ServiceInfo.Create(userInfo, MethodBase.GetCurrentMethod());

            ServiceUtil.ProcessUserCenterReadDb(userInfo, parameter, (dbHelper) =>
            {
                var itemDetailsManager = new BaseItemDetailsManager(dbHelper, userInfo, tableName);
                // 若是系统管理员,那就返回全部数据
                dt           = itemDetailsManager.GetDataTable(0, BaseItemDetailsEntity.FieldSortCode);
                dt.TableName = tableName;
                // 管理时需要把所有的数据显示出来,所以无效的数据也需要显示的
                // , new KeyValuePair<string, object>(BaseItemDetailsEntity.FieldEnabled, 1)
                // 管理时需要把被删除的也需要都显示出来,还能恢复数据才可以
                // new KeyValuePair<string, object>(BaseItemDetailsEntity.FieldDeletionStateCode, 0)
            });
            return(dt);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 获取子列表
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="tableName">目标表</param>
        /// <param name="parentId">父级主键</param>
        /// <returns>数据表</returns>
        public DataTable GetDataTableByParent(BaseUserInfo userInfo, string tableName, string parentId)
        {
            var dt = new DataTable(tableName);

            var parameter = ServiceInfo.Create(userInfo, MethodBase.GetCurrentMethod());

            ServiceUtil.ProcessUserCenterReadDb(userInfo, parameter, (dbHelper) =>
            {
                var itemDetailsManager = new BaseItemDetailsManager(dbHelper, userInfo, tableName);
                List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >();
                parameters.Add(new KeyValuePair <string, object>(BaseItemDetailsEntity.FieldParentId, parentId));
                parameters.Add(new KeyValuePair <string, object>(BaseItemDetailsEntity.FieldDeletionStateCode, 0));
                dt = itemDetailsManager.GetDataTable(parameters, 0, BaseItemDetailsEntity.FieldSortCode);
                // result = itemDetailsManager.GetDataTableByParent(parentId);
                dt.TableName = tableName;
            });

            return(dt);
        }
Ejemplo n.º 10
0
        public DataTable GetDataTableByCode(IDbHelper dbHelper, BaseUserInfo userInfo, string code)
        {
            var result = new DataTable(BaseItemDetailsEntity.TableName);
            // 检查有其他目标数据库表存储了数据
            var             itemsManager = new BaseItemsManager(dbHelper, userInfo);
            BaseItemsEntity itemsEntity  = BaseEntity.Create <BaseItemsEntity>(itemsManager.GetDataTable(new KeyValuePair <string, object>(BaseItemsEntity.FieldCode, code)));

            if (!String.IsNullOrEmpty(itemsEntity.TargetTable))
            {
                BaseItemDetailsManager itemDetailsManager = new BaseItemDetailsManager(dbHelper, userInfo, itemsEntity.TargetTable);
                // 这里只要有效的,没被删除的
                List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >();
                // 管理的时候无效的也需要被管理
                parameters.Add(new KeyValuePair <string, object>(BaseItemDetailsEntity.FieldEnabled, 1));
                parameters.Add(new KeyValuePair <string, object>(BaseItemDetailsEntity.FieldDeletionStateCode, 0));

                result           = itemDetailsManager.GetDataTable(parameters, BaseItemDetailsEntity.FieldSortCode);
                result.TableName = itemsEntity.TargetTable;
            }
            return(result);
        }