/// <summary> /// 按父节点获取列表 /// </summary> /// <param name="userInfo">用户</param> /// <param name="tableName">目标表</param> /// <param name="parentId">父级主键</param> /// <returns>数据表</returns> public DataTable GetDataTableByParent(BaseUserInfo userInfo, string parentId) { // 写入调试信息 #if (DEBUG) int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod()); #endif // 加强安全验证防止未授权匿名调用 #if (!DEBUG) LogOnService.UserIsLogOn(userInfo); #endif DataTable dataTable = new DataTable(BaseItemsEntity.TableName); using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType)) { try { dbHelper.Open(UserCenterDbConnection); string tableName = BaseItemsEntity.TableName; if (!string.IsNullOrEmpty(BaseSystemInfo.SystemCode)) { tableName = BaseSystemInfo.SystemCode + "Items"; } BaseItemsManager itemsManager = new BaseItemsManager(dbHelper, userInfo, tableName); dataTable = itemsManager.GetDataTableByParent(parentId); dataTable.TableName = tableName; // 添加日志 BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, AppMessage.ItemsService_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; }
/// <summary> /// 添加实体 /// </summary> /// <param name="userInfo">用户</param> /// <param name="itemsEntity">实体</param> /// <param name="statusCode">返回状态码</param> /// <param name="statusMessage">返回状态信息</param> /// <returns>数据表</returns> public string Add(BaseUserInfo userInfo, BaseItemsEntity itemsEntity, out string statusCode, out string statusMessage) { // 写入调试信息 #if (DEBUG) int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod()); #endif // 加强安全验证防止未授权匿名调用 #if (!DEBUG) LogOnService.UserIsLogOn(userInfo); #endif string returnValue = string.Empty; statusCode = string.Empty; statusMessage = string.Empty; using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType)) { try { dbHelper.Open(UserCenterDbConnection); string tableName = BaseItemsEntity.TableName; if (!string.IsNullOrEmpty(BaseSystemInfo.SystemCode)) { tableName = BaseSystemInfo.SystemCode + "Items"; } BaseItemsManager itemsManager = new BaseItemsManager(dbHelper, userInfo, tableName); // 调用方法,并且返回运行结果 returnValue = itemsManager.Add(itemsEntity, out statusCode); statusMessage = itemsManager.GetStateMessage(statusCode); BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, AppMessage.ItemsService_Add, 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> /// <returns>数据表</returns> public DataTable GetDataTable(BaseUserInfo userInfo) { // 写入调试信息 #if (DEBUG) int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod()); #endif // 加强安全验证防止未授权匿名调用 #if (!DEBUG) LogOnService.UserIsLogOn(userInfo); #endif DataTable dataTable = new DataTable(BaseItemsEntity.TableName); using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType)) { try { dbHelper.Open(UserCenterDbConnection); string tableName = BaseItemsEntity.TableName; if (!string.IsNullOrEmpty(BaseSystemInfo.SystemCode)) { tableName = BaseSystemInfo.SystemCode + "Items"; } BaseItemsManager itemsManager = new BaseItemsManager(dbHelper, userInfo, tableName); // 若是系统管理员,那就返回全部数据 if (userInfo.IsAdministrator) { dataTable = itemsManager.GetDataTable(); } else { // 按数据权限来过滤数据 BasePermissionScopeManager permissionScopeManager = new BasePermissionScopeManager(dbHelper, userInfo); string[] ids = permissionScopeManager.GetResourceScopeIds(userInfo.Id, BaseItemsEntity.TableName, "Resource.ManagePermission"); dataTable = itemsManager.GetDataTable(ids); } dataTable.TableName = tableName; // 添加日志 BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, AppMessage.ItemsService_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="tableName">目标表</param> /// <param name="id">主键</param> /// <returns>影响的行数</returns> public int Delete(BaseUserInfo userInfo, string tableName, string id) { // 写入调试信息 #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); BaseItemsManager itemsManager = new BaseItemsManager(dbHelper, userInfo, tableName); returnValue = itemsManager.Delete(id); BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, AppMessage.ItemsService_Delete, 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> /// <param name="statusCode">状态返回码</param> /// <param name="statusMessage">状态返回信息</param> public void CreateTable(BaseUserInfo userInfo, string tableName, 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; using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType)) { try { dbHelper.Open(UserCenterDbConnection); BaseItemsManager itemsManager = new BaseItemsManager(dbHelper, userInfo); // 创建表结构 itemsManager.CreateTable(tableName, out statusCode); statusMessage = itemsManager.GetStateMessage(statusCode); BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, AppMessage.ItemsService_CreateTable, MethodBase.GetCurrentMethod()); } catch (Exception ex) { BaseExceptionManager.LogException(dbHelper, userInfo, ex); throw ex; } finally { dbHelper.Close(); } } // 写入调试信息 #if (DEBUG) BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart); #endif }
/// <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); BaseItemsManager itemsManager = new BaseItemsManager(dbHelper, userInfo, tableName); for (int i = 0; i < ids.Length; i++) { returnValue += itemsManager.SetProperty(ids[i], new KeyValuePair<string, object>(BaseItemsEntity.FieldParentId, targetId)); } BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, AppMessage.ItemsService_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; }
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; }