/// <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 BaseDictionaryItemManager(dbHelper, userInfo, tableName); // 管理员取得所有数据 if (BaseUserManager.IsAdministrator(userInfo.Id)) { result = itemDetailsManager.GetDataTable( new KeyValuePair <string, object>(BaseDictionaryItemEntity.FieldDeleted, 0) , BaseDictionaryItemEntity.FieldSortCode); } else { // 管理时需要把所有的数据显示出来,所以无效的数据也需要显示的 // , new KeyValuePair<string, object>(BaseDictionaryItemEntity.FieldEnabled, 1) // 按数据权限来过滤数据 var permissionScopeManager = new BasePermissionScopeManager(dbHelper, userInfo); var ids = permissionScopeManager.GetResourceScopeIds(userInfo.SystemCode, userInfo.Id, tableName, permissionCode); result = itemDetailsManager.GetDataTable(ids); } result.TableName = tableName; }); return(result); }
/// <summary> /// 获取实体 /// </summary> /// <param name="userInfo">用户</param> /// <param name="tableName">表名</param> /// <param name="code">编码</param> /// <returns>数据表</returns> public BaseDictionaryItemEntity GetEntityByCode(BaseUserInfo userInfo, string tableName, string code) { var itemDetailsEntity = new BaseDictionaryItemEntity(); var parameter = ServiceInfo.Create(userInfo, MethodBase.GetCurrentMethod()); ServiceUtil.ProcessUserCenterReadDb(userInfo, parameter, (dbHelper) => { var itemDetailsManager = new BaseDictionaryItemManager(dbHelper, userInfo, tableName); var dt = itemDetailsManager.GetDataTable(new KeyValuePair <string, object>(BaseDictionaryItemEntity.FieldItemKey, code), BaseDictionaryItemEntity.FieldSortCode); if ((dt != null) && (dt.Rows.Count > 0)) { itemDetailsEntity = (BaseDictionaryItemEntity)itemDetailsEntity.GetFrom(dt.Rows[0]); } }); return(itemDetailsEntity); }
/// <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 BaseDictionaryItemManager(dbHelper, userInfo, tableName); // 若是系统管理员,那就返回全部数据 dt = itemDetailsManager.GetDataTable(0, BaseDictionaryItemEntity.FieldSortCode); dt.TableName = tableName; // 管理时需要把所有的数据显示出来,所以无效的数据也需要显示的 // , new KeyValuePair<string, object>(BaseDictionaryItemEntity.FieldEnabled, 1) // 管理时需要把被删除的也需要都显示出来,还能恢复数据才可以 // new KeyValuePair<string, object>(BaseDictionaryItemEntity.FieldDeleted, 0) }); return(dt); }
/// <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 BaseDictionaryItemManager(dbHelper, userInfo, tableName); var parameters = new List <KeyValuePair <string, object> > { new KeyValuePair <string, object>(BaseDictionaryItemEntity.FieldParentId, parentId), new KeyValuePair <string, object>(BaseDictionaryItemEntity.FieldDeleted, 0) }; dt = itemDetailsManager.GetDataTable(parameters, 0, BaseDictionaryItemEntity.FieldSortCode); // result = itemDetailsManager.GetDataTableByParent(parentId); dt.TableName = tableName; }); return(dt); }
/// <summary> /// GetDataTableByCode /// </summary> /// <param name="dbHelper"></param> /// <param name="userInfo"></param> /// <param name="code"></param> /// <returns></returns> public DataTable GetDataTableByCode(IDbHelper dbHelper, BaseUserInfo userInfo, string code) { var result = new DataTable(BaseDictionaryItemEntity.CurrentTableName); // 检查有其他目标数据库表存储了数据 var itemsManager = new BaseDictionaryManager(dbHelper, userInfo); var itemsEntity = BaseEntity.Create <BaseDictionaryEntity>(itemsManager.GetDataTable(new KeyValuePair <string, object>(BaseDictionaryEntity.FieldCode, code))); if (itemsEntity != null) { var itemDetailsManager = new BaseDictionaryItemManager(dbHelper, userInfo); // 这里只要有效的,没被删除的 var parameters = new List <KeyValuePair <string, object> > { // 管理的时候无效的也需要被管理 new KeyValuePair <string, object>(BaseDictionaryItemEntity.FieldDictionaryId, itemsEntity.Id), new KeyValuePair <string, object>(BaseDictionaryItemEntity.FieldEnabled, 1), new KeyValuePair <string, object>(BaseDictionaryItemEntity.FieldDeleted, 0) }; result = itemDetailsManager.GetDataTable(parameters, BaseDictionaryItemEntity.FieldSortCode); } return(result); }