/// <summary> /// 添加实体 /// </summary> /// <param name="addressBookEntity">实体对象</param> /// <returns>代码</returns> public String AddEntity(BaseAdviceEntity myAdviceEntity) { String id = BaseSequenceDao.Instance.NewGuid(); SQLBuilder sqlBuilder = new SQLBuilder(this.DbHelper); sqlBuilder.BeginInsert(BaseAdviceTable.TableName); sqlBuilder.SetValue(BaseAdviceTable.FieldID, id); this.SetEntity(sqlBuilder, myAdviceEntity); if (this.UserInfo != null) { sqlBuilder.SetValue(BaseAdviceTable.FieldCreateUserID, this.UserInfo.ID); } sqlBuilder.SetDBNow(BaseAdviceTable.FieldCreateDate); return sqlBuilder.EndInsert() > 0 ? id : String.Empty; }
/// <summary> /// ���һ����¼ /// </summary> /// <param name="mySend">���Ķ���</param> /// <returns>����</returns> public override String AddEntity(Object myObject) { String id = BaseSequenceDao.Instance.GetSequence(this.DbHelper, BaseAttchmentTable.TableName); BaseAttchmentEntity myAttchment = (BaseAttchmentEntity)myObject; SQLBuilder sqlBuilder = new SQLBuilder(this.DbHelper); sqlBuilder.BeginInsert(BaseAttchmentTable.TableName); sqlBuilder.SetValue(BaseAttchmentTable.FieldID, id); sqlBuilder.SetValue(BaseAttchmentTable.FieldCategoryID, myAttchment.CategoryID); sqlBuilder.SetValue(BaseAttchmentTable.FieldObjectID, myAttchment.ObjectID); sqlBuilder.SetValue(BaseAttchmentTable.FieldFileName, myAttchment.FileName); sqlBuilder.SetValue(BaseAttchmentTable.FieldDescription, myAttchment.Description); sqlBuilder.SetValue(BaseAttchmentTable.FieldCreateUserID, this.UserInfo.ID); sqlBuilder.SetDBNow(BaseAttchmentTable.FieldCreateDate); sqlBuilder.SetDBNow(BaseAttchmentTable.FieldModifyDate); return sqlBuilder.EndInsert() > 0 ? id : String.Empty; }
/// <summary> /// 添加实体 /// </summary> /// <param name="customerEntity">实体</param> public string AddEntity(CustomerEntity customerEntity) { string sequence = string.Empty; if (customerEntity.SortCode == null || customerEntity.SortCode == 0) { CiSequenceManager sequenceManager = new CiSequenceManager(DBProvider, this.Identity); sequence = sequenceManager.GetSequence(this.CurrentTableName); customerEntity.SortCode = int.Parse(sequence); } SQLBuilder sqlBuilder = new SQLBuilder(DBProvider, this.Identity, this.ReturnId); sqlBuilder.BeginInsert(this.CurrentTableName, CustomerTable.FieldId); if (!this.Identity) { sqlBuilder.SetValue(CustomerTable.FieldId, customerEntity.Id); } else { if (!this.ReturnId && (DBProvider.CurrentDbType == CurrentDbType.Oracle || DBProvider.CurrentDbType == CurrentDbType.DB2)) { if (DBProvider.CurrentDbType == CurrentDbType.Oracle) { sqlBuilder.SetFormula(CustomerTable.FieldId, "SEQ_" + this.CurrentTableName.ToUpper() + ".NEXTVAL "); } if (DBProvider.CurrentDbType == CurrentDbType.DB2) { sqlBuilder.SetFormula(CustomerTable.FieldId, "NEXT VALUE FOR SEQ_" + this.CurrentTableName.ToUpper()); } } else { if (this.Identity && (DBProvider.CurrentDbType == CurrentDbType.Oracle || DBProvider.CurrentDbType == CurrentDbType.DB2)) { if (customerEntity.Id == null) { if (string.IsNullOrEmpty(sequence)) { CiSequenceManager sequenceManager = new CiSequenceManager(DBProvider, this.Identity); sequence = sequenceManager.GetSequence(this.CurrentTableName); } customerEntity.Id = int.Parse(sequence); } sqlBuilder.SetValue(CustomerTable.FieldId, customerEntity.Id); } } } this.SetEntity(sqlBuilder, customerEntity); if (UserInfo != null) { sqlBuilder.SetValue(CustomerTable.FieldCreateUserId, UserInfo.Id); sqlBuilder.SetValue(CustomerTable.FieldCreateBy, UserInfo.RealName); } sqlBuilder.SetDBNow(CustomerTable.FieldCreateOn); if (UserInfo != null) { sqlBuilder.SetValue(CustomerTable.FieldModifiedBy, UserInfo.RealName); sqlBuilder.SetValue(CustomerTable.FieldModifiedUserId, UserInfo.Id); } sqlBuilder.SetDBNow(CustomerTable.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="userOrganizeEntity">实体</param> public string AddEntity(BaseUserOrganizeEntity userOrganizeEntity) { string sequence = string.Empty; SQLBuilder sqlBuilder = new SQLBuilder(DbHelper, this.Identity, this.ReturnId); sqlBuilder.BeginInsert(this.CurrentTableName, BaseUserOrganizeEntity.FieldId); if (!this.Identity) { sqlBuilder.SetValue(BaseUserOrganizeEntity.FieldId, userOrganizeEntity.Id); } else { if (!this.ReturnId && (DbHelper.CurrentDbType == DbTypes.Oracle || DbHelper.CurrentDbType == DbTypes.DB2)) { if (DbHelper.CurrentDbType == DbTypes.Oracle) { sqlBuilder.SetFormula(BaseUserOrganizeEntity.FieldId, "SEQ_" + this.CurrentTableName.ToUpper() + ".NEXTVAL "); } if (DbHelper.CurrentDbType == DbTypes.DB2) { sqlBuilder.SetFormula(BaseUserOrganizeEntity.FieldId, "NEXT VALUE FOR SEQ_" + this.CurrentTableName.ToUpper()); } } else { if (this.Identity && (DbHelper.CurrentDbType == DbTypes.Oracle || DbHelper.CurrentDbType == DbTypes.DB2)) { if (userOrganizeEntity.Id == null) { if (string.IsNullOrEmpty(sequence)) { BaseSequenceManager sequenceManager = new BaseSequenceManager(DbHelper, this.Identity); sequence = sequenceManager.GetSequence(this.CurrentTableName); } userOrganizeEntity.Id = int.Parse(sequence); } sqlBuilder.SetValue(BaseUserOrganizeEntity.FieldId, userOrganizeEntity.Id); } } } this.SetEntity(sqlBuilder, userOrganizeEntity); if (UserInfo != null) { sqlBuilder.SetValue(BaseUserOrganizeEntity.FieldCreateUserId, UserInfo.Id); sqlBuilder.SetValue(BaseUserOrganizeEntity.FieldCreateBy, UserInfo.RealName); } sqlBuilder.SetDBNow(BaseUserOrganizeEntity.FieldCreateOn); if (UserInfo != null) { sqlBuilder.SetValue(BaseUserOrganizeEntity.FieldModifiedUserId, UserInfo.Id); sqlBuilder.SetValue(BaseUserOrganizeEntity.FieldModifiedBy, UserInfo.RealName); } sqlBuilder.SetDBNow(BaseUserOrganizeEntity.FieldModifiedOn); if (DbHelper.CurrentDbType == DbTypes.SqlServer && this.Identity) { sequence = sqlBuilder.EndInsert().ToString(); } else { sqlBuilder.EndInsert(); } return sequence; }
/// <summary> /// 添加实体 /// </summary> /// <param name="baseWorkFlowCurrentEntity">实体</param> public string AddEntity(BaseWorkFlowCurrentEntity baseWorkFlowCurrentEntity) { string sequence = string.Empty; this.Identity = false; if (baseWorkFlowCurrentEntity.SortCode == null || baseWorkFlowCurrentEntity.SortCode == 0) { BaseSequenceManager sequenceManager = new BaseSequenceManager(DbHelper, this.Identity); sequence = sequenceManager.GetSequence(this.CurrentTableName); baseWorkFlowCurrentEntity.SortCode = int.Parse(sequence); } if (baseWorkFlowCurrentEntity.Id != null) { sequence = baseWorkFlowCurrentEntity.Id.ToString(); } SQLBuilder sqlBuilder = new SQLBuilder(DbHelper, this.Identity, this.ReturnId); sqlBuilder.BeginInsert(this.CurrentTableName, BaseWorkFlowCurrentEntity.FieldId); if (!this.Identity) { if (string.IsNullOrEmpty(baseWorkFlowCurrentEntity.Id)) { sequence = BaseBusinessLogic.NewGuid(); baseWorkFlowCurrentEntity.Id = sequence; } sqlBuilder.SetValue(BaseWorkFlowCurrentEntity.FieldId, baseWorkFlowCurrentEntity.Id); } else { if (!this.ReturnId && (DbHelper.CurrentDbType == DbTypes.Oracle || DbHelper.CurrentDbType == DbTypes.DB2)) { if (DbHelper.CurrentDbType == DbTypes.Oracle) { sqlBuilder.SetFormula(BaseWorkFlowCurrentEntity.FieldId, "SEQ_" + this.CurrentTableName.ToUpper() + ".NEXTVAL "); } if (DbHelper.CurrentDbType == DbTypes.DB2) { sqlBuilder.SetFormula(BaseWorkFlowCurrentEntity.FieldId, "NEXT VALUE FOR SEQ_" + this.CurrentTableName.ToUpper()); } } else { if (this.Identity && (DbHelper.CurrentDbType == DbTypes.Oracle || DbHelper.CurrentDbType == DbTypes.DB2)) { if (string.IsNullOrEmpty(baseWorkFlowCurrentEntity.Id)) { if (string.IsNullOrEmpty(sequence)) { BaseSequenceManager sequenceManager = new BaseSequenceManager(DbHelper, this.Identity); sequence = sequenceManager.GetSequence(this.CurrentTableName); } baseWorkFlowCurrentEntity.Id = sequence; } sqlBuilder.SetValue(BaseWorkFlowCurrentEntity.FieldId, baseWorkFlowCurrentEntity.Id); } } } this.SetEntity(sqlBuilder, baseWorkFlowCurrentEntity); if (UserInfo != null) { sqlBuilder.SetValue(BaseWorkFlowCurrentEntity.FieldCreateUserId, UserInfo.Id); sqlBuilder.SetValue(BaseWorkFlowCurrentEntity.FieldCreateBy, UserInfo.RealName); } sqlBuilder.SetDBNow(BaseWorkFlowCurrentEntity.FieldCreateOn); if (UserInfo != null) { sqlBuilder.SetValue(BaseWorkFlowCurrentEntity.FieldModifiedUserId, UserInfo.Id); sqlBuilder.SetValue(BaseWorkFlowCurrentEntity.FieldModifiedBy, UserInfo.RealName); } sqlBuilder.SetDBNow(BaseWorkFlowCurrentEntity.FieldModifiedOn); if (this.Identity && (DbHelper.CurrentDbType == DbTypes.SqlServer || DbHelper.CurrentDbType == DbTypes.Access)) { sequence = sqlBuilder.EndInsert().ToString(); } else { sqlBuilder.EndInsert(); } return(sequence); }
/// <summary> /// 同步省市区 /// </summary> private void SyncArea() { Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); var dbHelper = DbHelperFactory.GetHelper(CurrentDbType.SQLite, BillPrintHelper.BillPrintConnectionString); var entity = syncEntities.Find(p => p.Id == "1"); entity.Index = 0; entity.Remark = "开始同步"; gridControl1.RefreshDataSource(); DateTime? modifiedOn = new DateTime(2014, 01, 01); SQLBuilder sqlBuilder = new SQLBuilder(dbHelper); dbHelper.BeginTransaction(); const string url = "http://userCenter.zt-express.com/WebAPIV42/API/Synchronous/GetTopLimitTable"; WebClient webClient = new WebClient(); NameValueCollection postValues = new NameValueCollection { { "userInfo", BaseSystemInfo.UserInfo.Serialize() }, { "systemCode", BaseSystemInfo.SystemCode }, { "securityKey", BaseSystemInfo.SecurityKey }, { "dataBase", "UserCenter" }, { "tableName", BaseAreaEntity.TableName }, { "toTableName", BaseAreaEntity.TableName }, { "topLimit", "10000" }, { "modifiedOn", modifiedOn.Value.ToString(BaseSystemInfo.DateTimeFormat) } }; byte[] responseArray = webClient.UploadValues(url, postValues); string response = Encoding.UTF8.GetString(responseArray); if (!string.IsNullOrEmpty(response)) { dbHelper.ExecuteNonQuery("DELETE FROM " + BaseAreaEntity.TableName); var dataTable = (DataTable)JsonConvert.DeserializeObject(response, typeof(DataTable)); int r; entity.Count = dataTable.Rows.Count; entity.Remark = "正在同步"; gridControl1.RefreshDataSource(); for (r = 0; r < dataTable.Rows.Count; r++) { sqlBuilder.BeginInsert(BaseAreaEntity.TableName); for (int i = 0; i < dataTable.Columns.Count; i++) { sqlBuilder.SetValue(dataTable.Columns[i].ColumnName, dataTable.Rows[r][dataTable.Columns[i].ColumnName]); } sqlBuilder.EndInsert(); entity.Index++; gridControl1.RefreshDataSource(); } // 批量提交 try { dbHelper.CommitTransaction(); } catch (Exception ex) { ProcessException(ex); dbHelper.RollbackTransaction(); } finally { dbHelper.Close(); dbHelper.Dispose(); } stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; string elapsedTime = string.Format("{0}h{1}m{2}s{3}ms", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds); entity.Remark = "同步完成,耗时:" + elapsedTime; gridControl1.RefreshDataSource(); } }
/// <summary> /// 添加实体 /// </summary> /// <param name="fileEntity">实体</param> public string AddEntity(BaseFileEntity fileEntity) { string sequence = string.Empty; sequence = fileEntity.Id; if (fileEntity.SortCode == 0) { BaseSequenceManager sequenceManager = new BaseSequenceManager(DbHelper, this.Identity); sequence = sequenceManager.GetSequence(this.CurrentTableName); fileEntity.SortCode = int.Parse(sequence); } if (fileEntity.Id is string) { this.Identity = false; } SQLBuilder sqlBuilder = new SQLBuilder(DbHelper, this.Identity, this.ReturnId); sqlBuilder.BeginInsert(this.CurrentTableName, BaseFileEntity.FieldId); if (!this.Identity) { sqlBuilder.SetValue(BaseFileEntity.FieldId, fileEntity.Id); } else { if (!this.ReturnId && DbHelper.CurrentDbType == DbTypes.Oracle) { sqlBuilder.SetFormula(BaseFileEntity.FieldId, "SEQ_" + this.CurrentTableName.ToUpper() + ".NEXTVAL "); } else { if (this.Identity && DbHelper.CurrentDbType == DbTypes.Oracle) { if (string.IsNullOrEmpty(fileEntity.Id)) { if (string.IsNullOrEmpty(sequence)) { BaseSequenceManager sequenceManager = new BaseSequenceManager(DbHelper, this.Identity); sequence = sequenceManager.GetSequence(this.CurrentTableName); } fileEntity.Id = sequence; } sqlBuilder.SetValue(BaseFileEntity.FieldId, fileEntity.Id); } } } this.SetEntity(sqlBuilder, fileEntity); if (UserInfo != null) { sqlBuilder.SetValue(BaseFileEntity.FieldCreateUserId, UserInfo.Id); sqlBuilder.SetValue(BaseFileEntity.FieldCreateBy, UserInfo.RealName); } sqlBuilder.SetDBNow(BaseFileEntity.FieldCreateOn); // 这里主要是为了列表里的数据库更好看 sqlBuilder.SetValue(BaseFileEntity.FieldModifiedUserId, fileEntity.ModifiedUserId); sqlBuilder.SetValue(BaseFileEntity.FieldModifiedBy, fileEntity.ModifiedBy); sqlBuilder.SetValue(BaseFileEntity.FieldModifiedOn, fileEntity.ModifiedOn); if (DbHelper.CurrentDbType == DbTypes.SqlServer && this.Identity) { sequence = sqlBuilder.EndInsert().ToString(); } else { sqlBuilder.EndInsert(); } return(sequence); }
/// <summary> /// 添加实体 /// </summary> /// <param name="cASE_PRODUCTINFOEntity">实体</param> public string AddEntity(CASE_PRODUCTINFOEntity cASE_PRODUCTINFOEntity) { string sequence = string.Empty; this.Identity = false; if (cASE_PRODUCTINFOEntity.ID != null) { sequence = cASE_PRODUCTINFOEntity.ID; } SQLBuilder sqlBuilder = new SQLBuilder(DBProvider, this.Identity, this.ReturnId); sqlBuilder.BeginInsert(this.CurrentTableName, CASE_PRODUCTINFOTable.FieldID); if (!this.Identity) { if (string.IsNullOrEmpty(cASE_PRODUCTINFOEntity.ID)) { sequence = BusinessLogic.NewGuid(); cASE_PRODUCTINFOEntity.ID = sequence; } sqlBuilder.SetValue(CASE_PRODUCTINFOTable.FieldID, cASE_PRODUCTINFOEntity.ID); } else { if (!this.ReturnId && (DBProvider.CurrentDbType == CurrentDbType.Oracle || DBProvider.CurrentDbType == CurrentDbType.DB2)) { if (DBProvider.CurrentDbType == CurrentDbType.Oracle) { sqlBuilder.SetFormula(CASE_PRODUCTINFOTable.FieldID, "SEQ_" + this.CurrentTableName.ToUpper() + ".NEXTVAL "); } if (DBProvider.CurrentDbType == CurrentDbType.DB2) { sqlBuilder.SetFormula(CASE_PRODUCTINFOTable.FieldID, "NEXT VALUE FOR SEQ_" + this.CurrentTableName.ToUpper()); } } else { if (this.Identity && (DBProvider.CurrentDbType == CurrentDbType.Oracle || DBProvider.CurrentDbType == CurrentDbType.DB2)) { if (string.IsNullOrEmpty(cASE_PRODUCTINFOEntity.ID)) { if (string.IsNullOrEmpty(sequence)) { CiSequenceManager sequenceManager = new CiSequenceManager(DBProvider, this.Identity); sequence = sequenceManager.GetSequence(this.CurrentTableName); } cASE_PRODUCTINFOEntity.ID = sequence; } sqlBuilder.SetValue(CASE_PRODUCTINFOTable.FieldID, cASE_PRODUCTINFOEntity.ID); } } } this.SetEntity(sqlBuilder, cASE_PRODUCTINFOEntity); if (UserInfo != null) { sqlBuilder.SetValue(CASE_PRODUCTINFOTable.FieldCREATEUSERID, UserInfo.Id); sqlBuilder.SetValue(CASE_PRODUCTINFOTable.FieldCREATEBY, UserInfo.RealName); } sqlBuilder.SetDBNow(CASE_PRODUCTINFOTable.FieldCREATEON); if (UserInfo != null) { sqlBuilder.SetValue(CASE_PRODUCTINFOTable.FieldMODIFIEDUSERID, UserInfo.Id); sqlBuilder.SetValue(CASE_PRODUCTINFOTable.FieldMODIFIEDBY, UserInfo.RealName); } sqlBuilder.SetDBNow(CASE_PRODUCTINFOTable.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="entity">实体</param> public string AddObject(ZtoPrintBillEntity entity, string dataSource = "0") { string key = string.Empty; if (entity.Id != null) { key = entity.Id.ToString(); } SQLBuilder sqlBuilder = new SQLBuilder(DbHelper, this.Identity, this.ReturnId); sqlBuilder.BeginInsert(this.CurrentTableName, this.PrimaryKey); if (!this.Identity) { // 这里已经是指定了主键了,所以不需要返回主键了 sqlBuilder.ReturnId = false; sqlBuilder.SetValue(this.PrimaryKey, entity.Id); } else { if (!this.ReturnId && (DbHelper.CurrentDbType == CurrentDbType.Oracle || DbHelper.CurrentDbType == CurrentDbType.DB2)) { if (DbHelper.CurrentDbType == CurrentDbType.Oracle) { sqlBuilder.SetFormula(this.PrimaryKey, "SEQ_" + this.CurrentTableName.ToUpper() + ".NEXTVAL "); } if (DbHelper.CurrentDbType == CurrentDbType.DB2) { sqlBuilder.SetFormula(this.PrimaryKey, "NEXT VALUE FOR SEQ_" + this.CurrentTableName.ToUpper()); } } else { if (this.Identity && (DbHelper.CurrentDbType == CurrentDbType.Oracle || DbHelper.CurrentDbType == CurrentDbType.DB2)) { BaseSequenceManager sequenceManager = new BaseSequenceManager(DbHelper); // entity.Id = sequenceManager.Increment(this.CurrentTableName); sqlBuilder.SetValue(this.PrimaryKey, entity.Id); } } } this.SetObject(sqlBuilder, entity, dataSource); //if (entity.CreateOn.Year != 1) //{ // sqlBuilder.SetValue(ZtoPrintBillEntity.FieldCreateOn, entity.CreateOn); //} //else //{ sqlBuilder.SetDBNow(ZtoPrintBillEntity.FieldCreateOn); //} sqlBuilder.SetDBNow(ZtoPrintBillEntity.FieldModifiedOn); if (this.Identity && (DbHelper.CurrentDbType == CurrentDbType.SqlServer || DbHelper.CurrentDbType == CurrentDbType.Access)) { key = sqlBuilder.EndInsert().ToString(); } else { sqlBuilder.EndInsert(); } if (this.Identity && (DbHelper.CurrentDbType == CurrentDbType.Oracle || DbHelper.CurrentDbType == CurrentDbType.DB2)) { return(entity.Id.ToString()); } return(key); }