示例#1
0
        public static BaseItemDetailsEntity GetObjectByCache(string tableName, string id)
        {
            BaseItemDetailsEntity result = null;

            string key = "ItemDetails:" + tableName;

            if (!string.IsNullOrEmpty(id))
            {
                key = "ItemDetails:" + tableName + ":" + id;
            }
            result = GetCache(key);

            if (result == null)
            {
                // 动态读取表中的数据
                BaseItemDetailsManager manager = new BaseItemDetailsManager(tableName);
                result = manager.GetObject(id);
                // 若是空的不用缓存,继续读取实体
                if (result != null)
                {
                    SetCache(tableName, result);
                }
            }

            return(result);
        }
示例#2
0
        public List <BaseItemDetailsEntity> GetListByCode(IDbHelper dbHelper, BaseUserInfo userInfo, string code)
        {
            // 2013-09-07 吉日嘎拉 目标表,这样来个默认的表名,有助于提高稳定性,可以有一定的容错功能
            string targetTable = "Items" + code;

            // 检查有其他目标数据库表存储了数据
            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));

            return(itemDetailsManager.GetList <BaseItemDetailsEntity>(parameters, BaseItemDetailsEntity.FieldSortCode));
        }
        public DataTable GetDataTableByCode(IDbHelper dbHelper, BaseUserInfo userInfo, string code)
        {
            // 加强安全验证防止未授权匿名调用
#if (!DEBUG)
            LogOnService.UserIsLogOn(userInfo);
#endif

            DataTable dataTable = new DataTable(BaseItemDetailsEntity.TableName);
            BaseItemDetailsManager itemDetailsManager = new BaseItemDetailsManager(dbHelper, userInfo);
            // 检查有其他目标数据库表存储了数据
            BaseItemsManager itemsManager = new BaseItemsManager(dbHelper, userInfo);
            BaseItemsEntity  itemsEntity  = new BaseItemsEntity(itemsManager.GetDataTable(new KeyValuePair <string, object>(BaseItemsEntity.FieldCode, code)));
            if (!String.IsNullOrEmpty(itemsEntity.TargetTable))
            {
                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));

            dataTable           = itemDetailsManager.GetDataTable(parameters, BaseItemDetailsEntity.FieldSortCode);
            dataTable.TableName = itemsEntity.TargetTable;
            return(dataTable);
        }
        /// <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);
        }
示例#5
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);
        }
示例#6
0
        /// <summary>
        /// 获取模块菜单表,从缓存读取
        /// 2016-03-14 吉日嘎拉 更新有缓存功能
        /// </summary>
        /// <param name="tableName">表名</param>
        /// <param name="refresh">刷新</param>
        /// <returns>选项数据列表</returns>
        public static List <BaseItemDetailsEntity> GetEntitiesByCache(string tableName, bool refresh = false)
        {
            List <BaseItemDetailsEntity> result = null;

            string key = "ItemDetails:" + tableName;

            if (!refresh)
            {
                result = GetListCache(key);
            }

            if (result == null)
            {
                // 这里只要有效的,没被删除的
                BaseItemDetailsManager itemDetailsManager        = new BaseItemDetailsManager(tableName);
                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.GetList <BaseItemDetailsEntity>(parameters, BaseItemDetailsEntity.FieldSortCode);

                // 若是空的不用缓存,继续读取实体
                if (result != null)
                {
                    SetListCache(key, result);
                }
            }

            return(result);
        }
示例#7
0
        /// <summary>
        /// 删除实体
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="tableName">目标表</param>
        /// <param name="id">主键</param>
        /// <returns>影响的行数</returns>
        public int Delete(BaseUserInfo userInfo, string tableName, string id)
        {
            int result = 0;

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

            ServiceUtil.ProcessBusinessDb(userInfo, parameter, (dbHelper) =>
            {
                BaseItemDetailsManager itemDetailsManager = new BaseItemDetailsManager(dbHelper, userInfo, tableName);
                result = itemDetailsManager.Delete(id);
            });
            return(result);
        }
示例#8
0
        /// <summary>
        /// 获取实体
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="id">主键</param>
        /// <returns>数据表</returns>
        public BaseItemDetailsEntity GetObject(BaseUserInfo userInfo, string tableName, string id)
        {
            BaseItemDetailsEntity entity = null;

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

            ServiceUtil.ProcessBusinessDb(userInfo, parameter, (dbHelper) =>
            {
                BaseItemDetailsManager itemDetailsManager = new BaseItemDetailsManager(dbHelper, userInfo, tableName);
                entity = itemDetailsManager.GetObject(id);
            });
            return(entity);
        }
        /// <summary>
        /// 批量保存
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="result">数据表</param>
        /// <returns>影响行数</returns>
        public int Save(BaseUserInfo userInfo, DataTable dt)
        {
            int result = 0;

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

            ServiceUtil.ProcessUserCenterWriteDb(userInfo, parameter, (dbHelper) =>
            {
                var itemDetailsManager = new BaseItemDetailsManager(dbHelper, userInfo, dt.TableName);
                result = itemDetailsManager.Save(dt);
            });
            return(result);
        }
        /// <summary>
        /// 批量重新生成排序码
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="ids">主键数组</param>
        /// <returns>影响行数</returns>
        public int BatchSetSortCode(BaseUserInfo userInfo, string tableName, string[] ids)
        {
            int result = 0;

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

            ServiceUtil.ProcessUserCenterWriteDb(userInfo, parameter, (dbHelper) =>
            {
                var itemDetailsManager = new BaseItemDetailsManager(dbHelper, userInfo, tableName);
                result = itemDetailsManager.BatchSetSortCode(ids);
            });
            return(result);
        }
示例#11
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);
        }
        /// <summary>
        /// 移动数据
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="id">主键</param>
        /// <param name="parentId">父主键</param>
        /// <returns>影响行数</returns>
        public int MoveTo(BaseUserInfo userInfo, string tableName, string id, string parentId)
        {
            int result = 0;

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

            ServiceUtil.ProcessUserCenterWriteDb(userInfo, parameter, (dbHelper) =>
            {
                var itemDetailsManager = new BaseItemDetailsManager(dbHelper, userInfo, tableName);
                result = itemDetailsManager.MoveTo(id, parentId);
            });

            return(result);
        }
示例#13
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.ProcessBusinessDb(userInfo, parameter, (dbHelper) =>
            {
                BaseItemDetailsManager itemDetailsManager = new BaseItemDetailsManager(dbHelper, userInfo, tableName);
                dt           = itemDetailsManager.GetDataTableByParent(parentId);
                dt.TableName = tableName;
            });

            return(dt);
        }
示例#14
0
        /// <summary>
        /// 1:默认从只读的缓存服务器获取数据
        /// 2:若读取不到,就会到接口上获取,接口会把数据缓存到只读服务器上,为下次阅读提高性能
        /// </summary>
        /// <param name="userInfo"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public static BaseItemDetailsEntity GetObjectByCache(BaseUserInfo userInfo, string tableName, string id)
        {
            BaseItemDetailsEntity result = null;

            string key = "ItemDetails:" + tableName + ":" + id;
            result = BaseItemDetailsManager.GetCache(key);

            // 远程通过接口获取数据
            if (result == null)
            {
                result = GetObject(userInfo, tableName, id);
            }

            return result;
        }
示例#15
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());
            }
        }
        /// <summary>
        /// 批量移动
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="tableName">目标表</param>
        /// <param name="ids">编码主键数组</param>
        /// <param name="targetId">目标主键</param>
        /// <returns>影响行数</returns>
        public int BatchMoveTo(BaseUserInfo userInfo, string tableName, string[] ids, string targetId)
        {
            int result = 0;

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

            ServiceUtil.ProcessUserCenterWriteDb(userInfo, parameter, (dbHelper) =>
            {
                var itemDetailsManager = new BaseItemDetailsManager(dbHelper, userInfo, tableName);
                for (int i = 0; i < ids.Length; i++)
                {
                    result += itemDetailsManager.SetProperty(ids[i], new KeyValuePair <string, object>(BaseItemDetailsEntity.FieldParentId, targetId));
                }
            });
            return(result);
        }
        /// <summary>
        /// 获取列表
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="tableName">目标表</param>
        /// <returns>列表</returns>
        public List <BaseItemDetailsEntity> GetList(BaseUserInfo userInfo, string tableName)
        {
            List <BaseItemDetailsEntity> entityList = new List <BaseItemDetailsEntity>();

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

            ServiceUtil.ProcessUserCenterReadDb(userInfo, parameter, (dbHelper) =>
            {
                var itemDetailsManager = new BaseItemDetailsManager(dbHelper, userInfo, tableName);
                entityList             = itemDetailsManager.GetList <BaseItemDetailsEntity>(
                    new KeyValuePair <string, object>(BaseItemDetailsEntity.FieldDeletionStateCode, 0)
                    , BaseItemDetailsEntity.FieldSortCode);
                // 管理时需要把所有的数据显示出来,所以无效的数据也需要显示的
                // , new KeyValuePair<string, object>(BaseItemDetailsEntity.FieldEnabled, 1)
            });
            return(entityList);
        }
        /// <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);
        }
示例#19
0
        public static string[] GetSystemCodes()
        {
            string[] result = null;

            List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >();

            parameters.Add(new KeyValuePair <string, object>(BaseItemDetailsEntity.FieldIsPublic, 1));
            parameters.Add(new KeyValuePair <string, object>(BaseItemDetailsEntity.FieldEnabled, 1));
            parameters.Add(new KeyValuePair <string, object>(BaseItemDetailsEntity.FieldDeletionStateCode, 0));

            string tableName = "ItemsSystem";
            BaseItemDetailsManager itemDetailsManager = new BaseItemDetailsManager(tableName);

            result = itemDetailsManager.GetProperties(parameters, BaseItemDetailsEntity.FieldItemCode);

            return(result);
        }
示例#20
0
        /// <summary>
        /// 更新实体
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="dataTable">数据表</param>
        /// <param name="statusCode">返回状态码</param>
        /// <param name="statusMessage">返回状态信息</param>
        /// <returns>数据表</returns>
        public int Update(BaseUserInfo userInfo, string tableName, BaseItemDetailsEntity itemDetailsEntity, out string statusCode, out string statusMessage)
        {
            // 写入调试信息
#if (DEBUG)
            int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod());
#endif

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

            statusCode    = string.Empty;
            statusMessage = string.Empty;
            int returnValue = 0;

            using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType))
            {
                try
                {
                    dbHelper.Open(UserCenterDbConnection);
                    BaseItemDetailsManager itemDetailsManager = new BaseItemDetailsManager(dbHelper, userInfo, tableName);
                    // 编辑数据
                    returnValue   = itemDetailsManager.Update(itemDetailsEntity, out statusCode);
                    statusMessage = itemDetailsManager.GetStateMessage(statusCode);
                    BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, AppMessage.ItemDetailsService_Update, MethodBase.GetCurrentMethod());
                }
                catch (Exception ex)
                {
                    BaseExceptionManager.LogException(dbHelper, userInfo, ex);
                    throw ex;
                }
                finally
                {
                    dbHelper.Close();
                }
            }

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

            return(returnValue);
        }
示例#21
0
        public static List<BaseItemDetailsEntity> GetListByTargetTableByCache(BaseUserInfo userInfo, string systemCode, string tableName)
        {
            List<BaseItemDetailsEntity> result = null;

            if (!string.IsNullOrEmpty(tableName))
            {
                string key = "ItemDetails:" + tableName;
                result = BaseItemDetailsManager.GetListCache(key);
            }

            // 远程通过接口获取数据
            if (result == null)
            {
                result = GetListByTargetTable(userInfo, systemCode, tableName);
            }

            return result;
        }
示例#22
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);
        }
示例#23
0
        /// <summary>
        /// 批量移动
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="tableName">目标表</param>
        /// <param name="ids">编码主键数组</param>
        /// <param name="targetId">目标主键</param>
        /// <returns>影响行数</returns>
        public int BatchMoveTo(BaseUserInfo userInfo, string tableName, string[] ids, string targetId)
        {
            // 写入调试信息
#if (DEBUG)
            int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod());
#endif

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

            int returnValue = 0;
            using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType))
            {
                try
                {
                    dbHelper.Open(UserCenterDbConnection);
                    BaseItemDetailsManager itemDetailsManager = new BaseItemDetailsManager(dbHelper, userInfo, tableName);
                    for (int i = 0; i < ids.Length; i++)
                    {
                        returnValue += itemDetailsManager.SetProperty(ids[i], new KeyValuePair <string, object>(BaseItemDetailsEntity.FieldParentId, targetId));
                    }
                    BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, AppMessage.ItemDetailsService_BatchMoveTo, MethodBase.GetCurrentMethod());
                }
                catch (Exception ex)
                {
                    BaseExceptionManager.LogException(dbHelper, userInfo, ex);
                    throw ex;
                }
                finally
                {
                    dbHelper.Close();
                }
            }

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

            return(returnValue);
        }
        /// <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);
        }
        /// <summary>
        /// 更新实体
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="entity">实体</param>
        /// <param name="statusCode">返回状态码</param>
        /// <param name="statusMessage">返回状态信息</param>
        /// <returns>数据表</returns>
        public int Update(BaseUserInfo userInfo, string tableName, BaseItemDetailsEntity entity, out string statusCode, out string statusMessage)
        {
            int result = 0;

            string returnCode    = string.Empty;
            string returnMessage = string.Empty;
            var    parameter     = ServiceInfo.Create(userInfo, MethodBase.GetCurrentMethod());

            ServiceUtil.ProcessUserCenterWriteDb(userInfo, parameter, (dbHelper) =>
            {
                var itemDetailsManager = new BaseItemDetailsManager(dbHelper, userInfo, tableName);
                // 编辑数据
                result        = itemDetailsManager.Update(entity, out returnCode);
                returnMessage = itemDetailsManager.GetStateMessage(returnCode);
            });
            statusCode    = returnCode;
            statusMessage = returnMessage;
            return(result);
        }
        public List <BaseItemDetailsEntity> GetListByTargetTable(IDbHelper dbHelper, BaseUserInfo userInfo, string tableName)
        {
            List <BaseItemDetailsEntity> result = null;
            // 检查有其他目标数据库表存储了数据
            var             itemsManager = new BaseItemsManager(dbHelper, userInfo);
            BaseItemsEntity itemsEntity  = BaseEntity.Create <BaseItemsEntity>(itemsManager.GetDataTable(new KeyValuePair <string, object>(BaseItemsEntity.FieldTargetTable, tableName)));

            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.GetList <BaseItemDetailsEntity>(parameters, BaseItemDetailsEntity.FieldSortCode);
            }
            return(result);
        }
        /// <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);
        }
示例#28
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)
        {
            // 写入调试信息
#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);
                    dataTable           = itemDetailsManager.GetDataTableByParent(parentId);
                    dataTable.TableName = tableName;
                    // 添加日志
                    BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, AppMessage.ItemDetailsService_GetDataTableByParent, 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);
        }
示例#29
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);
        }
示例#30
0
        /// <summary>
        /// 添加实体
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="result">数据表</param>
        /// <param name="statusCode">返回状态码</param>
        /// <param name="statusMessage">返回状态信息</param>
        /// <returns>数据表</returns>
        public string Add(BaseUserInfo userInfo, string tableName, BaseItemDetailsEntity entity, out string statusCode, out string statusMessage)
        {
            string result = string.Empty;

            string returnCode    = string.Empty;
            string returnMessage = string.Empty;

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

            ServiceUtil.ProcessBusinessDb(userInfo, parameter, (dbHelper) =>
            {
                BaseItemDetailsManager itemDetailsManager = new BaseItemDetailsManager(dbHelper, userInfo, tableName);
                // 调用方法,并且返回运行结果
                result        = itemDetailsManager.Add(entity, out returnCode);
                returnMessage = itemDetailsManager.GetStateMessage(returnCode);
            });
            statusCode    = returnCode;
            statusMessage = returnMessage;
            return(result);
        }