/// <summary> /// 设置实体 /// </summary> /// <param name="sqlBuilder">SQL语句生成器</param> /// <param name="piOrganizeEntity">实体</param> private void SetEntity(SQLBuilder sqlBuilder, PiOrganizeEntity piOrganizeEntity) { sqlBuilder.SetValue(PiOrganizeTable.FieldParentId, piOrganizeEntity.ParentId); sqlBuilder.SetValue(PiOrganizeTable.FieldCode, piOrganizeEntity.Code); sqlBuilder.SetValue(PiOrganizeTable.FieldShortName, piOrganizeEntity.ShortName); sqlBuilder.SetValue(PiOrganizeTable.FieldFullName, piOrganizeEntity.FullName); sqlBuilder.SetValue(PiOrganizeTable.FieldCategory, piOrganizeEntity.Category); sqlBuilder.SetValue(PiOrganizeTable.FieldOuterPhone, piOrganizeEntity.OuterPhone); sqlBuilder.SetValue(PiOrganizeTable.FieldInnerPhone, piOrganizeEntity.InnerPhone); sqlBuilder.SetValue(PiOrganizeTable.FieldFax, piOrganizeEntity.Fax); sqlBuilder.SetValue(PiOrganizeTable.FieldPostalcode, piOrganizeEntity.Postalcode); sqlBuilder.SetValue(PiOrganizeTable.FieldAddress, piOrganizeEntity.Address); sqlBuilder.SetValue(PiOrganizeTable.FieldWeb, piOrganizeEntity.Web); sqlBuilder.SetValue(PiOrganizeTable.FieldManagerId, piOrganizeEntity.ManagerId); sqlBuilder.SetValue(PiOrganizeTable.FieldManager, piOrganizeEntity.Manager); sqlBuilder.SetValue(PiOrganizeTable.FieldLayer, piOrganizeEntity.Layer); sqlBuilder.SetValue(PiOrganizeTable.FieldAssistantManagerId, piOrganizeEntity.AssistantManagerId); sqlBuilder.SetValue(PiOrganizeTable.FieldAssistantManager, piOrganizeEntity.AssistantManager); sqlBuilder.SetValue(PiOrganizeTable.FieldIsInnerOrganize, piOrganizeEntity.IsInnerOrganize); sqlBuilder.SetValue(PiOrganizeTable.FieldEnabled, piOrganizeEntity.Enabled); sqlBuilder.SetValue(PiOrganizeTable.FieldBank, piOrganizeEntity.Bank); sqlBuilder.SetValue(PiOrganizeTable.FieldBankAccount, piOrganizeEntity.BankAccount); sqlBuilder.SetValue(PiOrganizeTable.FieldSortCode, piOrganizeEntity.SortCode); sqlBuilder.SetValue(PiOrganizeTable.FieldDescription, piOrganizeEntity.Description); sqlBuilder.SetValue(PiOrganizeTable.FieldModifiedUserId, piOrganizeEntity.ModifiedUserId); sqlBuilder.SetValue(PiOrganizeTable.FieldModifiedBy, piOrganizeEntity.ModifiedBy); }
/// <summary> /// 更新实体 /// </summary> /// <param name="piOrganizeEntity">实体</param> public int UpdateEntity(PiOrganizeEntity piOrganizeEntity) { SQLBuilder sqlBuilder = new SQLBuilder(DBProvider); sqlBuilder.BeginUpdate(this.CurrentTableName); this.SetEntity(sqlBuilder, piOrganizeEntity); sqlBuilder.SetDBNow(PiOrganizeTable.FieldModifiedOn); sqlBuilder.SetWhere(PiOrganizeTable.FieldId, piOrganizeEntity.Id); return(sqlBuilder.EndUpdate()); }
/// <summary> /// 取得实体 /// </summary> /// <param name="userInfo">用户</param> /// <param name="id">主鍵</param> /// <returns>实体</returns> public PiOrganizeEntity GetEntity(UserInfo userInfo, string id) { PiOrganizeEntity entity = null; var parameter = ParameterUtil.CreateWithMessage(userInfo, MethodBase.GetCurrentMethod(), this.serviceName, RDIFrameworkMessage.OrganizeService_GetEntity); ServiceUtil.ProcessRDIReadDb(userInfo, parameter, dbProvider => { var manager = new PiOrganizeManager(dbProvider, userInfo); entity = manager.GetEntity(id); }); return(entity); }
public DataTable GetFullNameDepartment(DataTable dataTable) { foreach (DataRow dr in dataTable.Rows) { //PiOrganizeEntity subCompanyNameEntity = RDIFrameworkService.Instance.OrganizeService.GetEntity(UserInfo, dr[PiOrganizeTable.FieldParentId].ToString()); //dr[PiOrganizeTable.FieldFullName] = subCompanyNameEntity.FullName.ToString() + "--" + dr[PiOrganizeTable.FieldFullName].ToString(); //PiOrganizeEntity companyEntity = RDIFrameworkService.Instance.OrganizeService.GetEntity(UserInfo, subCompanyNameEntity.ParentId.ToString()); //dr[PiOrganizeTable.FieldFullName] = companyEntity.FullName.ToString() + "--" + dr[PiOrganizeTable.FieldFullName].ToString(); PiOrganizeEntity subCompanyNameEntity = GetEntity(dr[PiOrganizeTable.FieldParentId].ToString()); dr[PiOrganizeTable.FieldFullName] = subCompanyNameEntity.FullName + "--" + dr[PiOrganizeTable.FieldFullName].ToString(); PiOrganizeEntity companyEntity = GetEntity(subCompanyNameEntity.ParentId); dr[PiOrganizeTable.FieldFullName] = companyEntity.FullName + "--" + dr[PiOrganizeTable.FieldFullName].ToString(); } return(dataTable); }
/// <summary> /// 更新实体 /// </summary> /// <param name="userInfo">用户</param> /// <param name="entity">实体</param> /// <param name="statusMessage">返回狀態訊息</param> /// <returns>影响的行数</returns> public int Update(UserInfo userInfo, PiOrganizeEntity entity, out string statusMessage) { int returnValue = 0; string returnCode = string.Empty; string returnMessage = string.Empty; var parameter = ParameterUtil.CreateWithMessage(userInfo, MethodBase.GetCurrentMethod(), this.serviceName, RDIFrameworkMessage.OrganizeService_Update); ServiceUtil.ProcessRDIReadDb(userInfo, parameter, dbProvider => { var manager = new PiOrganizeManager(dbProvider, userInfo); returnValue = manager.Update(entity, out returnCode); returnMessage = manager.GetStateMessage(returnCode); }); statusMessage = returnMessage; return(returnValue); }
public override int BatchSave(DataTable dataTable) { int returnValue = 0; PiOrganizeEntity organizeEntity = new PiOrganizeEntity(); foreach (DataRow dataRow in dataTable.Rows) { // 删除状态 if (dataRow.RowState == DataRowState.Deleted) { string id = dataRow[PiOrganizeTable.FieldId, DataRowVersion.Original].ToString(); if (id.Length > 0) { returnValue += this.DeleteEntity(id); } } // 被修改过 if (dataRow.RowState == DataRowState.Modified) { string id = dataRow[PiOrganizeTable.FieldId, DataRowVersion.Original].ToString(); if (id.Length > 0) { organizeEntity.GetFrom(dataRow); returnValue += this.UpdateEntity(organizeEntity); } } // 添加状态 if (dataRow.RowState == DataRowState.Added) { organizeEntity.GetFrom(dataRow); returnValue += !string.IsNullOrEmpty(this.AddEntity(organizeEntity)) ? 1 : 0; } if (dataRow.RowState == DataRowState.Unchanged) { continue; } if (dataRow.RowState == DataRowState.Detached) { continue; } } return(returnValue); }
public int Update(PiOrganizeEntity organizeEntity, out string statusCode) { int returnValue = 0; string[] names = { PiOrganizeTable.FieldParentId, PiOrganizeTable.FieldFullName, PiOrganizeTable.FieldDeleteMark }; Object[] values = { organizeEntity.ParentId, organizeEntity.FullName, 0 }; if (this.Exists(names, values, organizeEntity.Id)) { // 名称已重复 statusCode = StatusCode.ErrorNameExist.ToString(); } else { // 检查编号是否重复 names = new string[] { PiOrganizeTable.FieldCode, PiOrganizeTable.FieldDeleteMark }; values = new object[] { organizeEntity.Code, 0 }; if (organizeEntity.Code.Length > 0 && this.Exists(names, values, organizeEntity.Id)) { // 编号已重复 statusCode = StatusCode.ErrorCodeExist.ToString(); } else { // 1:更新部门的信息 returnValue = this.UpdateEntity(organizeEntity); // 2:更新组织机构时,同步更新用户表的公司、分公司、部门、子部门、工作组 var userManager = new PiUserManager(this.DBProvider, this.UserInfo); userManager.SetProperty(new KeyValuePair <string, object>(PiUserTable.FieldCompanyId, organizeEntity.Id), new KeyValuePair <string, object>(PiUserTable.FieldCompanyName, organizeEntity.FullName)); userManager.SetProperty(new KeyValuePair <string, object>(PiUserTable.FieldSubCompanyId, organizeEntity.Id), new KeyValuePair <string, object>(PiUserTable.FieldSubCompanyName, organizeEntity.FullName)); userManager.SetProperty(new KeyValuePair <string, object>(PiUserTable.FieldDepartmentId, organizeEntity.Id), new KeyValuePair <string, object>(PiUserTable.FieldDepartmentName, organizeEntity.FullName)); userManager.SetProperty(new KeyValuePair <string, object>(PiUserTable.FieldSubDepartmentId, organizeEntity.Id), new KeyValuePair <string, object>(PiUserTable.FieldSubDepartmentName, organizeEntity.FullName)); userManager.SetProperty(new KeyValuePair <string, object>(PiUserTable.FieldWorkgroupId, organizeEntity.Id), new KeyValuePair <string, object>(PiUserTable.FieldWorkgroupName, organizeEntity.FullName)); statusCode = returnValue == 1 ? StatusCode.OKUpdate.ToString() : StatusCode.ErrorChanged.ToString(); } } return(returnValue); }
public string AddEntity(PiOrganizeEntity entity) { string statusCode = string.Empty; return(this.AddEntity(entity, out statusCode)); }
/// <summary> /// 添加实体 /// </summary> /// <param name="piOrganizeEntity">实体</param> public string AddEntity(PiOrganizeEntity piOrganizeEntity, out string statusCode) { string sequence = string.Empty; statusCode = string.Empty; string[] names = new string[] { PiOrganizeTable.FieldParentId, PiOrganizeTable.FieldFullName, PiOrganizeTable.FieldDeleteMark }; object[] values = new object[] { piOrganizeEntity.ParentId, piOrganizeEntity.FullName, piOrganizeEntity.DeleteMark }; if (this.Exists(names, values)) { // 名称已重复 statusCode = StatusCode.ErrorNameExist.ToString(); } else { if (piOrganizeEntity.SortCode == null || piOrganizeEntity.SortCode == 0) { CiSequenceManager sequenceManager = new CiSequenceManager(DBProvider, this.Identity); sequence = sequenceManager.GetSequence(this.CurrentTableName, sequenceManager.DefaultSequence); piOrganizeEntity.SortCode = int.Parse(sequence); } this.Identity = false; SQLBuilder sqlBuilder = new SQLBuilder(DBProvider, this.Identity, this.ReturnId); sqlBuilder.BeginInsert(this.CurrentTableName, PiOrganizeTable.FieldId); if (!this.Identity) { if (String.IsNullOrEmpty(piOrganizeEntity.Id)) { sequence = BusinessLogic.NewGuid(); piOrganizeEntity.Id = sequence; } sqlBuilder.SetValue(PiOrganizeTable.FieldId, piOrganizeEntity.Id); } else { if (!this.ReturnId && (DBProvider.CurrentDbType == CurrentDbType.Oracle || DBProvider.CurrentDbType == CurrentDbType.DB2)) { if (DBProvider.CurrentDbType == CurrentDbType.Oracle) { sqlBuilder.SetFormula(PiOrganizeTable.FieldId, "SEQ_" + this.CurrentTableName.ToUpper() + ".NEXTVAL "); } if (DBProvider.CurrentDbType == CurrentDbType.DB2) { sqlBuilder.SetFormula(PiOrganizeTable.FieldId, "NEXT VALUE FOR SEQ_" + this.CurrentTableName.ToUpper()); } } else { if (this.Identity && (DBProvider.CurrentDbType == CurrentDbType.Oracle || DBProvider.CurrentDbType == CurrentDbType.DB2)) { if (piOrganizeEntity.Id == null) { if (string.IsNullOrEmpty(sequence)) { CiSequenceManager sequenceManager = new CiSequenceManager(DBProvider, this.Identity); sequence = sequenceManager.GetSequence(this.CurrentTableName); } piOrganizeEntity.Id = sequence; } sqlBuilder.SetValue(PiOrganizeTable.FieldId, piOrganizeEntity.Id); } } } this.SetEntity(sqlBuilder, piOrganizeEntity); //if (UserInfo != null) //{ // sqlBuilder.SetValue(PiOrganizeTable.FieldCreateUserId, UserInfo.Id); // sqlBuilder.SetValue(PiOrganizeTable.FieldCreateBy, UserInfo.RealName); //} sqlBuilder.SetDBNow(PiOrganizeTable.FieldCreateOn); sqlBuilder.SetDBNow(PiOrganizeTable.FieldModifiedOn); if (this.Identity && (DBProvider.CurrentDbType == CurrentDbType.SqlServer || DBProvider.CurrentDbType == CurrentDbType.Access)) { sequence = sqlBuilder.EndInsert().ToString(); // 运行成功 statusCode = StatusCode.OKAdd.ToString(); } else { sqlBuilder.EndInsert(); // 运行成功 statusCode = StatusCode.OKAdd.ToString(); } } return(sequence); }