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); }
public static BaseItemDetailsEntity GetObject(BaseUserInfo userInfo, string tableName, string id) { BaseItemDetailsEntity result = null; string url = BaseSystemInfo.UserCenterHost + "/UserCenterV42/ItemDetailsService.ashx"; WebClient webClient = new WebClient(); NameValueCollection postValues = new NameValueCollection(); postValues.Add("system", BaseSystemInfo.SoftFullName); postValues.Add("systemCode", BaseSystemInfo.SystemCode); postValues.Add("securityKey", BaseSystemInfo.SecurityKey); // 2015-11-25 吉日嘎拉,这里还是从缓存里获取就可以了,提高登录的效率。 postValues.Add("function", "GetObject"); postValues.Add("tableName", tableName); postValues.Add("userInfo", userInfo.Serialize()); postValues.Add("encrypted", true.ToString()); postValues.Add("id", SecretUtil.Encrypt(id)); // 向服务器发送POST数据 byte[] responseArray = webClient.UploadValues(url, postValues); string response = Encoding.UTF8.GetString(responseArray); if (!string.IsNullOrEmpty(response)) { result = JsonConvert.DeserializeObject<BaseItemDetailsEntity>(response); } return result; }
/// <summary> /// 批量进行保存 /// </summary> /// <param name="dataTable">数据表</param> /// <returns>影响行数</returns> public override int BatchSave(DataTable dataTable) { int returnValue = 0; BaseItemDetailsEntity itemDetailsEntity = new BaseItemDetailsEntity(); foreach (DataRow dataRow in dataTable.Rows) { // 删除状态 if (dataRow.RowState == DataRowState.Deleted) { string id = dataRow[BaseItemDetailsEntity.FieldId, DataRowVersion.Original].ToString(); if (id.Length > 0) { if (itemDetailsEntity.AllowDelete == 1) { returnValue += this.Delete(id); } } } // 被修改过 if (dataRow.RowState == DataRowState.Modified) { string id = dataRow[BaseItemDetailsEntity.FieldId, DataRowVersion.Original].ToString(); if (id.Length > 0) { itemDetailsEntity.GetFrom(dataRow); // 判断是否允许编辑 if (itemDetailsEntity.AllowEdit == 1) { returnValue += this.UpdateEntity(itemDetailsEntity); } else { // 不允许编辑,但是排序还是允许的 returnValue += this.SetProperty(id, new KeyValuePair <string, object>(BaseItemDetailsEntity.FieldSortCode, itemDetailsEntity.SortCode)); } } } // 添加状态 if (dataRow.RowState == DataRowState.Added) { itemDetailsEntity.GetFrom(dataRow); returnValue += this.AddEntity(itemDetailsEntity).Length > 0 ? 1 : 0; } if (dataRow.RowState == DataRowState.Unchanged) { continue; } if (dataRow.RowState == DataRowState.Detached) { continue; } } return(returnValue); }
private static void SetCache(string tableName, BaseItemDetailsEntity entity) { if (entity != null) { string key = string.Empty; using (var redisClient = PooledRedisHelper.GetClient()) { key = "ItemDetails:" + tableName + ":" + entity.Id; redisClient.Set <BaseItemDetailsEntity>(key, entity, DateTime.Now.AddMinutes(10)); } } }
/// <summary> /// 添加 /// </summary> /// <param name="itemDetailsEntity">实体</param> /// <param name="statusCode">返回状态码</param> /// <returns>主键</returns> public string Add(BaseItemDetailsEntity itemDetailsEntity, out string statusCode) { string returnValue = string.Empty; // 检查编号是否重复 //if (!String.IsNullOrEmpty(itemDetailsEntity.ItemCode)) //{ // if (this.Exists(BaseItemDetailsEntity.FieldItemCode, itemDetailsEntity.ItemCode)) // { // // 编号已重复 // statusCode = StatusCode.ErrorCodeExist.ToString(); // return returnValue; // } //} //if (!String.IsNullOrEmpty(itemDetailsEntity.ItemName)) //{ // // 检查名称是否重复 // if (this.Exists(BaseItemDetailsEntity.FieldItemName, itemDetailsEntity.ItemName)) // { // // 名称已重复 // statusCode = StatusCode.ErrorFullNameExist.ToString(); // return returnValue; // } //} //if (!String.IsNullOrEmpty(itemDetailsEntity.ItemValue)) //{ // // 检查值是否重复 // if (this.Exists(BaseItemDetailsEntity.FieldItemValue, itemDetailsEntity.ItemValue)) // { // // 值已重复 // statusCode = StatusCode.ErrorValueExist.ToString(); // return returnValue; // } //} List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >(); parameters.Add(new KeyValuePair <string, object>(BaseItemDetailsEntity.FieldItemCode, itemDetailsEntity.ItemCode)); parameters.Add(new KeyValuePair <string, object>(BaseItemDetailsEntity.FieldItemName, itemDetailsEntity.ItemName)); parameters.Add(new KeyValuePair <string, object>(BaseItemDetailsEntity.FieldDeletionStateCode, 0)); if (this.Exists(parameters)) { // 名称已重复 statusCode = StatusCode.Exist.ToString(); return(returnValue); } // 运行成功 returnValue = this.AddEntity(itemDetailsEntity); statusCode = StatusCode.OKAdd.ToString(); return(returnValue); }
/// <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); }
public static BaseItemDetailsEntity GetCache(string key) { BaseItemDetailsEntity result = null; if (!string.IsNullOrWhiteSpace(key)) { using (var redisClient = PooledRedisHelper.GetClient()) { result = redisClient.Get <BaseItemDetailsEntity>(key); } } return(result); }
/// <summary> /// 设置实体 /// </summary> /// <param name="entity">实体</param> private void SetObject(SQLBuilder sqlBuilder, BaseItemDetailsEntity entity) { sqlBuilder.SetValue(BaseItemDetailsEntity.FieldParentId, entity.ParentId); sqlBuilder.SetValue(BaseItemDetailsEntity.FieldItemCode, entity.ItemCode); sqlBuilder.SetValue(BaseItemDetailsEntity.FieldItemName, entity.ItemName); sqlBuilder.SetValue(BaseItemDetailsEntity.FieldItemValue, entity.ItemValue); sqlBuilder.SetValue(BaseItemDetailsEntity.FieldAllowEdit, entity.AllowEdit); sqlBuilder.SetValue(BaseItemDetailsEntity.FieldAllowDelete, entity.AllowDelete); sqlBuilder.SetValue(BaseItemDetailsEntity.FieldIsPublic, entity.IsPublic); sqlBuilder.SetValue(BaseItemDetailsEntity.FieldEnabled, entity.Enabled); sqlBuilder.SetValue(BaseItemDetailsEntity.FieldDeletionStateCode, entity.DeletionStateCode); sqlBuilder.SetValue(BaseItemDetailsEntity.FieldSortCode, entity.SortCode); sqlBuilder.SetValue(BaseItemDetailsEntity.FieldDescription, entity.Description); SetObjectExpand(sqlBuilder, entity); }
/// <summary> /// 通过选项值获取选项的显示内容 /// 这里是进行了内存缓存处理,减少数据库的I/O处理,提高程序的运行性能, /// 若有数据修改过,重新启动一下程序就可以了,这些基础数据也不是天天修改来修改去的, /// 所以没必要过度担忧,当然有需要时也可以写个刷新缓存的程序 /// </summary> /// <param name="tableName">选项表名</param> /// <param name="itemValue">选项值</param> /// <returns>显示值</returns> public static string GetItemName(string tableName, string itemValue) { string result = itemValue; if (!string.IsNullOrEmpty(itemValue)) { List <BaseItemDetailsEntity> list = GetEntities(tableName); BaseItemDetailsEntity itemDetailsEntity = list.FirstOrDefault(entity => !string.IsNullOrEmpty(entity.ItemValue) && entity.ItemValue.Equals(itemValue)); if (itemDetailsEntity != null) { result = itemDetailsEntity.ItemName; } } return(result); }
/// <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; }
/// <summary> /// 更新实体 /// </summary> /// <param name="entity">实体</param> public int UpdateObject(BaseItemDetailsEntity entity) { SQLBuilder sqlBuilder = new SQLBuilder(DbHelper); sqlBuilder.BeginUpdate(this.CurrentTableName); this.SetObject(sqlBuilder, entity); if (UserInfo != null) { sqlBuilder.SetValue(BaseItemDetailsEntity.FieldModifiedUserId, UserInfo.Id); sqlBuilder.SetValue(BaseItemDetailsEntity.FieldModifiedBy, UserInfo.RealName); } sqlBuilder.SetDBNow(BaseItemDetailsEntity.FieldModifiedOn); sqlBuilder.SetWhere(BaseItemDetailsEntity.FieldId, entity.Id); return(sqlBuilder.EndUpdate()); }
/// <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); }
/// <summary> /// 批量进行保存 /// </summary> /// <param name="result">数据表</param> /// <returns>影响行数</returns> public int Save(DataTable dt) { int result = 0; if (dt != null) { this.CurrentTableName = dt.TableName; this.Delete(); BaseItemDetailsEntity entity = new BaseItemDetailsEntity(); foreach (DataRow dr in dt.Rows) { entity.GetFrom(dr); result += this.AddObject(entity).Length > 0 ? 1 : 0; } } return(result); }
/// <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); }
/// <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); }
/// <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); }
/// <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); }
/// <summary> /// 更新 /// </summary> /// <param name="entity">实体</param> /// <param name="statusCode">返回状态码</param> /// <returns>影响行数</returns> public int Update(BaseItemDetailsEntity entity, out string statusCode) { int result = 0; // 检查是否已被其他人修改 //if (DbLogic.IsModifed(DbHelper, this.CurrentTableName, itemDetailsEntity.Id, itemDetailsEntity.ModifiedUserId, itemDetailsEntity.ModifiedOn)) //{ // // 数据已经被修改 // statusCode = StatusCode.ErrorChanged.ToString(); //} // 检查编号是否重复 // if (this.Exists(BaseItemDetailsEntity.FieldItemCode, itemDetailsEntity.ItemCode, itemDetailsEntity.Id)) // if (this.Exists(BaseItemDetailsEntity.FieldItemValue, itemDetailsEntity.ItemValue, itemDetailsEntity.Id)) // 检查名称是否重复 List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >(); if (entity.ParentId.HasValue) { parameters.Add(new KeyValuePair <string, object>(BaseItemDetailsEntity.FieldParentId, entity.ParentId)); } parameters.Add(new KeyValuePair <string, object>(BaseItemDetailsEntity.FieldItemCode, entity.ItemCode)); // parameters.Add(new KeyValuePair<string, object>(BaseItemDetailsEntity.FieldItemName, entity.ItemName)); parameters.Add(new KeyValuePair <string, object>(BaseItemDetailsEntity.FieldDeletionStateCode, 0)); if (this.Exists(parameters, entity.Id)) { // 名称已重复 statusCode = Status.Exist.ToString(); return(result); } result = this.UpdateObject(entity); if (result == 1) { statusCode = Status.OKUpdate.ToString(); } else { statusCode = Status.ErrorDeleted.ToString(); } return(result); }
/// <summary> /// 获取实体 /// </summary> /// <param name="userInfo">用户</param> /// <param name="id">主键</param> /// <returns>数据表</returns> public BaseItemDetailsEntity GetEntity(BaseUserInfo userInfo, string tableName, string id) { // 写入调试信息 #if (DEBUG) int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod()); #endif // 加强安全验证防止未授权匿名调用 #if (!DEBUG) LogOnService.UserIsLogOn(userInfo); #endif BaseItemDetailsEntity itemDetailsEntity = null; using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType)) { try { dbHelper.Open(UserCenterDbConnection); BaseItemDetailsManager itemDetailsManager = new BaseItemDetailsManager(dbHelper, userInfo, tableName); itemDetailsEntity = itemDetailsManager.GetEntity(id); 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); }
/// <summary> /// 更新 /// </summary> /// <param name="itemDetailsEntity">实体</param> public int Update(BaseItemDetailsEntity itemDetailsEntity) { return(this.UpdateEntity(itemDetailsEntity)); }
partial void SetObjectExpand(SQLBuilder sqlBuilder, BaseItemDetailsEntity entity);
/// <summary> /// 添加实体 /// </summary> /// <param name="entity">实体</param> public string AddObject(BaseItemDetailsEntity entity) { string sequence = string.Empty; if (!entity.SortCode.HasValue) { BaseSequenceManager sequenceManager = new BaseSequenceManager(DbHelper, this.Identity); sequence = sequenceManager.Increment(this.CurrentTableName); entity.SortCode = int.Parse(sequence); } SQLBuilder sqlBuilder = new SQLBuilder(DbHelper, this.Identity, this.ReturnId); sqlBuilder.BeginInsert(this.CurrentTableName, BaseItemDetailsEntity.FieldId); if (!this.Identity || (entity.Id.HasValue && entity.Id != 0)) { sqlBuilder.SetValue(BaseItemDetailsEntity.FieldId, entity.Id); sequence = entity.Id.ToString(); } else { if (!this.ReturnId && (DbHelper.CurrentDbType == CurrentDbType.Oracle || DbHelper.CurrentDbType == CurrentDbType.DB2)) { if (DbHelper.CurrentDbType == CurrentDbType.Oracle) { sqlBuilder.SetFormula(BaseItemDetailsEntity.FieldId, "SEQ_" + this.CurrentTableName.ToUpper() + ".NEXTVAL "); } if (DbHelper.CurrentDbType == CurrentDbType.DB2) { sqlBuilder.SetFormula(BaseItemDetailsEntity.FieldId, "NEXT VALUE FOR SEQ_" + this.CurrentTableName.ToUpper()); } } else { if (this.Identity && (DbHelper.CurrentDbType == CurrentDbType.Oracle || DbHelper.CurrentDbType == CurrentDbType.DB2)) { if (string.IsNullOrEmpty(sequence)) { BaseSequenceManager sequenceManager = new BaseSequenceManager(DbHelper, this.Identity); sequence = sequenceManager.Increment(this.CurrentTableName); } entity.Id = int.Parse(sequence); sqlBuilder.SetValue(BaseItemDetailsEntity.FieldId, entity.Id); } } } this.SetObject(sqlBuilder, entity); // 创建人信息 if (!string.IsNullOrEmpty(entity.CreateUserId)) { sqlBuilder.SetValue(BaseItemDetailsEntity.FieldCreateUserId, entity.CreateUserId); } else { if (UserInfo != null) { sqlBuilder.SetValue(BaseItemDetailsEntity.FieldCreateUserId, UserInfo.Id); } } if (!string.IsNullOrEmpty(entity.CreateBy)) { sqlBuilder.SetValue(BaseItemDetailsEntity.FieldCreateBy, entity.CreateBy); } else { if (UserInfo != null) { sqlBuilder.SetValue(BaseItemDetailsEntity.FieldCreateBy, UserInfo.RealName); } } if (entity.CreateOn.HasValue) { sqlBuilder.SetValue(BaseItemDetailsEntity.FieldCreateOn, entity.CreateOn); } else { sqlBuilder.SetDBNow(BaseItemDetailsEntity.FieldCreateOn); } // 修改人信息 if (!string.IsNullOrEmpty(entity.ModifiedUserId)) { sqlBuilder.SetValue(BaseItemDetailsEntity.FieldModifiedUserId, entity.ModifiedUserId); } else { if (UserInfo != null) { sqlBuilder.SetValue(BaseItemDetailsEntity.FieldModifiedUserId, UserInfo.Id); } } if (!string.IsNullOrEmpty(entity.ModifiedBy)) { sqlBuilder.SetValue(BaseItemDetailsEntity.FieldModifiedBy, entity.ModifiedBy); } else { if (UserInfo != null) { sqlBuilder.SetValue(BaseItemDetailsEntity.FieldModifiedBy, UserInfo.RealName); } } if (entity.ModifiedOn.HasValue) { sqlBuilder.SetValue(BaseItemDetailsEntity.FieldModifiedOn, entity.ModifiedOn); } else { sqlBuilder.SetDBNow(BaseItemDetailsEntity.FieldModifiedOn); } if (DbHelper.CurrentDbType == CurrentDbType.SqlServer && this.Identity) { sequence = sqlBuilder.EndInsert().ToString(); } else { sqlBuilder.EndInsert(); } return(sequence); }
/// <summary> /// 更新 /// </summary> /// <param name="entity">实体</param> public int Update(BaseItemDetailsEntity entity) { return(this.UpdateObject(entity)); }
/// <summary> /// 添加 /// </summary> /// <param name="entity">实体</param> /// <param name="identity">自增量方式</param> /// <param name="returnId">返回主鍵</param> /// <returns>主键</returns> public string Add(BaseItemDetailsEntity entity, bool identity, bool returnId) { this.Identity = identity; this.ReturnId = returnId; return(this.AddObject(entity)); }
/// <summary> /// 添加 /// </summary> /// <param name="entity">实体</param> /// <returns>主键</returns> public string Add(BaseItemDetailsEntity entity) { return(this.AddObject(entity)); }
partial void SetEntityExpand(SQLBuilder sqlBuilder, BaseItemDetailsEntity itemDetailsEntity);
/// <summary> /// 添加实体 /// </summary> /// <param name="itemDetailsEntity">实体</param> public string AddEntity(BaseItemDetailsEntity itemDetailsEntity) { string sequence = string.Empty; if (itemDetailsEntity.SortCode == 0) { BaseSequenceManager sequenceManager = new BaseSequenceManager(DbHelper, this.Identity); sequence = sequenceManager.GetSequence(this.CurrentTableName); itemDetailsEntity.SortCode = int.Parse(sequence); } SQLBuilder sqlBuilder = new SQLBuilder(DbHelper, this.Identity, this.ReturnId); sqlBuilder.BeginInsert(this.CurrentTableName, BaseItemDetailsEntity.FieldId); if (!this.Identity) { sqlBuilder.SetValue(BaseItemDetailsEntity.FieldId, itemDetailsEntity.Id); } else { if (!this.ReturnId && (DbHelper.CurrentDbType == CurrentDbType.Oracle || DbHelper.CurrentDbType == CurrentDbType.DB2)) { if (DbHelper.CurrentDbType == CurrentDbType.Oracle) { sqlBuilder.SetFormula(BaseItemDetailsEntity.FieldId, "SEQ_" + this.CurrentTableName.ToUpper() + ".NEXTVAL "); } if (DbHelper.CurrentDbType == CurrentDbType.DB2) { sqlBuilder.SetFormula(BaseItemDetailsEntity.FieldId, "NEXT VALUE FOR SEQ_" + this.CurrentTableName.ToUpper()); } } else { if (this.Identity && (DbHelper.CurrentDbType == CurrentDbType.Oracle || DbHelper.CurrentDbType == CurrentDbType.DB2)) { if (string.IsNullOrEmpty(sequence)) { BaseSequenceManager sequenceManager = new BaseSequenceManager(DbHelper, this.Identity); sequence = sequenceManager.GetSequence(this.CurrentTableName); } itemDetailsEntity.Id = int.Parse(sequence); sqlBuilder.SetValue(BaseItemDetailsEntity.FieldId, itemDetailsEntity.Id); } } } this.SetEntity(sqlBuilder, itemDetailsEntity); if (UserInfo != null) { sqlBuilder.SetValue(BaseItemDetailsEntity.FieldCreateUserId, UserInfo.Id); sqlBuilder.SetValue(BaseItemDetailsEntity.FieldCreateBy, UserInfo.RealName); } sqlBuilder.SetDBNow(BaseItemDetailsEntity.FieldCreateOn); if (UserInfo != null) { sqlBuilder.SetValue(BaseItemDetailsEntity.FieldModifiedUserId, UserInfo.Id); sqlBuilder.SetValue(BaseItemDetailsEntity.FieldModifiedBy, UserInfo.RealName); } sqlBuilder.SetDBNow(BaseItemDetailsEntity.FieldModifiedOn); if (DbHelper.CurrentDbType == CurrentDbType.SqlServer && this.Identity) { sequence = sqlBuilder.EndInsert().ToString(); } else { sqlBuilder.EndInsert(); } return(sequence); }
/// <summary> /// 获取实体 /// </summary> /// <param name="id">主键</param> public BaseItemDetailsEntity GetEntity(string id) { BaseItemDetailsEntity itemDetailsEntity = new BaseItemDetailsEntity(this.GetDataTable(new KeyValuePair <string, object>(BaseItemDetailsEntity.FieldId, id))); return(itemDetailsEntity); }
/// <summary> /// 添加 /// </summary> /// <param name="itemDetailsEntity">实体</param> /// <returns>主键</returns> public string Add(BaseItemDetailsEntity itemDetailsEntity) { return(this.AddEntity(itemDetailsEntity)); }
/// <summary> /// 添加 /// </summary> /// <param name="entity">实体</param> /// <param name="statusCode">返回状态码</param> /// <returns>主键</returns> public string Add(BaseItemDetailsEntity entity, out string statusCode) { string result = string.Empty; // 检查编号是否重复 if (!String.IsNullOrEmpty(entity.ItemCode)) { List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >(); parameters.Add(new KeyValuePair <string, object>(BaseItemDetailsEntity.FieldItemCode, entity.ItemCode)); parameters.Add(new KeyValuePair <string, object>(BaseItemDetailsEntity.FieldDeletionStateCode, 0)); if (this.Exists(parameters)) { // 编号已重复 statusCode = Status.ErrorCodeExist.ToString(); return(result); } } /* * * if (!String.IsNullOrEmpty(entity.ItemName)) * { * if (this.Exists(new KeyValuePair<string, object>(BaseItemDetailsEntity.FieldItemName, entity.ItemName))) * { * // 名称已重复 * statusCode = Status.ErrorNameExist.ToString(); * return result; * } * } * * if (!String.IsNullOrEmpty(entity.ItemValue)) * { * if (this.Exists(new KeyValuePair<string, object>(BaseItemDetailsEntity.FieldItemValue, entity.ItemValue))) * { * // 值已重复 * statusCode = Status.ErrorValueExist.ToString(); * return result; * } * } * * List<KeyValuePair<string, object>> parameters = new List<KeyValuePair<string, object>>(); * if (entity.ParentId.HasValue) * { * parameters.Add(new KeyValuePair<string, object>(BaseItemDetailsEntity.FieldParentId, entity.ParentId)); * } * parameters.Add(new KeyValuePair<string, object>(BaseItemDetailsEntity.FieldItemCode, entity.ItemCode)); * parameters.Add(new KeyValuePair<string, object>(BaseItemDetailsEntity.FieldItemName, entity.ItemName)); * parameters.Add(new KeyValuePair<string, object>(BaseItemDetailsEntity.FieldDeletionStateCode, 0)); * * if (this.Exists(parameters)) * { * // 名称已重复 * statusCode = Status.Exist.ToString(); * return result; * } */ // 运行成功 result = this.AddObject(entity); statusCode = Status.OKAdd.ToString(); return(result); }