//新增下级分类 private void mnuAddLowerLevel_Click(object sender, EventArgs e) { if (tvCustomerClass.SelectedNode != null) { tvCustomerClass.LabelEdit = true; TreeNode tmp = new TreeNode("新分类"); CustomerClassEntity customerClassEntity = new CustomerClassEntity(); customerClassEntity.ClassName = "新分类"; customerClassEntity.ParentId = tvCustomerClass.SelectedNode.Parent == null ? null : BusinessLogic.ConvertToNullableInt(((DataRow)this.tvCustomerClass.SelectedNode.Tag)[CustomerTable.FieldId].ToString()); string statusCode = string.Empty; string statusMessage = string.Empty; tmp.Tag = customerClassService.Add(UserInfo, customerClassEntity, out statusCode, out statusMessage); if (statusCode != StatusCode.OKAdd.ToString()) { MessageBoxHelper.ShowWarningMsg(statusMessage); } else { tvCustomerClass.SelectedNode.Nodes.Add(tmp); tmp.BeginEdit(); tvCustomerClass.SelectedNode = tmp; } } }
/// <summary> /// 添加 /// </summary> /// <param name="customerClassEntity">实体</param> /// <returns>主键</returns> public string Add(CustomerClassEntity customerClassEntity, out string statusCode) { string returnValue = string.Empty; returnValue = this.AddEntity(customerClassEntity); statusCode = StatusCode.OKAdd.ToString(); return(returnValue); }
/// <summary> /// 设置实体 /// </summary> /// <param name="customerClassEntity">实体</param> private void SetEntity(SQLBuilder sqlBuilder, CustomerClassEntity customerClassEntity) { SetEntityExpand(sqlBuilder, customerClassEntity); sqlBuilder.SetValue(CustomerClassTable.FieldParentId, customerClassEntity.ParentId); sqlBuilder.SetValue(CustomerClassTable.FieldClassName, customerClassEntity.ClassName); sqlBuilder.SetValue(CustomerClassTable.FieldClassCode, customerClassEntity.ClassCode); sqlBuilder.SetValue(CustomerClassTable.FieldDescription, customerClassEntity.Description); sqlBuilder.SetValue(CustomerClassTable.FieldSortCode, customerClassEntity.SortCode); sqlBuilder.SetValue(CustomerClassTable.FieldDeleteMark, customerClassEntity.DeleteMark); }
/// <summary> /// 更新实体 /// </summary> /// <param name="customerClassEntity">实体</param> public int UpdateEntity(CustomerClassEntity customerClassEntity) { SQLBuilder sqlBuilder = new SQLBuilder(DBProvider); sqlBuilder.BeginUpdate(this.CurrentTableName); this.SetEntity(sqlBuilder, customerClassEntity); if (UserInfo != null) { sqlBuilder.SetValue(CustomerClassTable.FieldModifiedBy, UserInfo.RealName); sqlBuilder.SetValue(CustomerClassTable.FieldModifiedUserId, UserInfo.Id); } sqlBuilder.SetDBNow(CustomerClassTable.FieldModifiedOn); sqlBuilder.SetWhere(CustomerClassTable.FieldId, customerClassEntity.Id); return(sqlBuilder.EndUpdate()); }
/// <summary> /// 更新实体 /// </summary> /// <param name="userInfo">用户</param> /// <param name="entity">实体</param> /// <param name="statusCode">返回状态码</param> /// <param name="statusMessage">返回状态信息</param> /// <returns>影响行数</returns> public int Update(UserInfo userInfo, CustomerClassEntity entity, out string statusCode, out string statusMessage) { int returnValue = 0; statusCode = string.Empty; using (IDbProvider rdiDbProvider = DbFactoryProvider.GetProvider(SystemInfo.RDIFrameworkDbType)) { try { rdiDbProvider.Open(RDIFrameworkDbConection); LogManager.Instance.Add(rdiDbProvider, userInfo, this.serviceName, "更新实体", MethodBase.GetCurrentMethod()); using (IDbProvider dbProvider = DbFactoryProvider.GetProvider(BusinessDbType)) { try { dbProvider.Open(BusinessDbConnection); CustomerClassManager manager = new CustomerClassManager(dbProvider, userInfo); returnValue = manager.UpdateEntity(entity); // returnValue = manager.Update(entity, out statusCode); statusMessage = manager.GetStateMessage(statusCode); } catch (Exception ex) { CiExceptionManager.LogException(rdiDbProvider, userInfo, ex); throw ex; } finally { dbProvider.Close(); } } } catch (Exception ex) { CiExceptionManager.LogException(rdiDbProvider, userInfo, ex); throw ex; } finally { rdiDbProvider.Close(); } } return(returnValue); }
/// <summary> /// 取得实体 /// </summary> /// <param name="userInfo">用户</param> /// <param name="id">主鍵</param> /// <returns>实体</returns> public CustomerClassEntity GetEntity(UserInfo userInfo, string id) { CustomerClassEntity entity = null; using (IDbProvider dbProvider = DbFactoryProvider.GetProvider(BusinessDbType)) { try { dbProvider.Open(BusinessDbConnection); CustomerClassManager manager = new CustomerClassManager(dbProvider, userInfo); entity = manager.GetEntity(id); } catch (Exception ex) { throw ex; } finally { dbProvider.Close(); } } return(entity); }
// 这个是声明扩展方法 partial void SetEntityExpand(SQLBuilder sqlBuilder, CustomerClassEntity customerClassEntity);
/// <summary> /// 添加实体 /// </summary> /// <param name="customerClassEntity">实体</param> public string AddEntity(CustomerClassEntity customerClassEntity) { string sequence = string.Empty; if (customerClassEntity.SortCode == null || customerClassEntity.SortCode == 0) { CiSequenceManager sequenceManager = new CiSequenceManager(DBProvider, this.Identity); sequence = sequenceManager.GetSequence(this.CurrentTableName); customerClassEntity.SortCode = int.Parse(sequence); } SQLBuilder sqlBuilder = new SQLBuilder(DBProvider, this.Identity, this.ReturnId); sqlBuilder.BeginInsert(this.CurrentTableName, CustomerClassTable.FieldId); if (!this.Identity) { sqlBuilder.SetValue(CustomerClassTable.FieldId, customerClassEntity.Id); } else { if (!this.ReturnId && (DBProvider.CurrentDbType == CurrentDbType.Oracle || DBProvider.CurrentDbType == CurrentDbType.DB2)) { if (DBProvider.CurrentDbType == CurrentDbType.Oracle) { sqlBuilder.SetFormula(CustomerClassTable.FieldId, "SEQ_" + this.CurrentTableName.ToUpper() + ".NEXTVAL "); } if (DBProvider.CurrentDbType == CurrentDbType.DB2) { sqlBuilder.SetFormula(CustomerClassTable.FieldId, "NEXT VALUE FOR SEQ_" + this.CurrentTableName.ToUpper()); } } else { if (this.Identity && (DBProvider.CurrentDbType == CurrentDbType.Oracle || DBProvider.CurrentDbType == CurrentDbType.DB2)) { if (customerClassEntity.Id == null) { if (string.IsNullOrEmpty(sequence)) { CiSequenceManager sequenceManager = new CiSequenceManager(DBProvider, this.Identity); sequence = sequenceManager.GetSequence(this.CurrentTableName); } customerClassEntity.Id = int.Parse(sequence); } sqlBuilder.SetValue(CustomerClassTable.FieldId, customerClassEntity.Id); } } } this.SetEntity(sqlBuilder, customerClassEntity); if (UserInfo != null) { sqlBuilder.SetValue(CustomerClassTable.FieldCreateUserId, UserInfo.Id); sqlBuilder.SetValue(CustomerClassTable.FieldCreateBy, UserInfo.RealName); } sqlBuilder.SetDBNow(CustomerClassTable.FieldCreateOn); if (UserInfo != null) { sqlBuilder.SetValue(CustomerClassTable.FieldModifiedBy, UserInfo.RealName); sqlBuilder.SetValue(CustomerClassTable.FieldModifiedUserId, UserInfo.Id); } sqlBuilder.SetDBNow(CustomerClassTable.FieldModifiedOn); if (this.Identity && (DBProvider.CurrentDbType == CurrentDbType.SqlServer || DBProvider.CurrentDbType == CurrentDbType.Access)) { sequence = sqlBuilder.EndInsert().ToString(); } else { sqlBuilder.EndInsert(); } return(sequence); }
/// <summary> /// 更新 /// </summary> /// <param name="customerClassEntity">实体</param> public int Update(CustomerClassEntity customerClassEntity) { return(this.UpdateEntity(customerClassEntity)); }
/// <summary> /// 添加 /// </summary> /// <param name="customerClassEntity">实体</param> /// <param name="identity">自增量方式</param> /// <param name="returnId">返回主键</param> /// <returns>主键</returns> public string Add(CustomerClassEntity customerClassEntity, bool identity, bool returnId) { this.Identity = identity; this.ReturnId = returnId; return(this.AddEntity(customerClassEntity)); }