/// <summary> /// Undoes the request. /// </summary> /// <returns></returns> public int UndoRequest() { if (this.undoRecords == null || this.undoRecords.Count == 0) { return(-1); } CRMDatabase database = this.DataStore.DatabaseInstance; database.BeginTransaction(); int ret = 0; foreach (UPCRMUndoRecord record in this.undoRecords) { ret = record.UndoWithTransaction(database); if (ret != 0) { break; } } if (ret == 0) { database.Commit(); } else { database.Rollback(); } return(ret); }
/// <summary> /// Method Populates Multi Field Array /// </summary> /// <param name="crmDatabase"> /// Database object /// </param> /// <param name="fieldInfo"> /// FieldInfo object</param> /// <returns> /// MultiField Array of integers /// </returns> private int[] PopulateMultiFieldArray(CRMDatabase crmDatabase, FieldInfo fieldInfo) { var multiFieldCount = 0; var multiFieldArray = (int[])null; if (crmDatabase != null) { var tableInfo = crmDatabase.DataModel.InternalGetTableInfo(_infoAreaId); fieldInfo = tableInfo?.GetFieldInfo(FieldIndex); if (fieldInfo != null && fieldInfo.ArrayFieldCount > 1) { var count = fieldInfo.ArrayFieldCount; multiFieldArray = new int[count]; for (var i = 0; i < count; i++) { multiFieldArray[multiFieldCount] = fieldInfo.ArrayFieldIndices[i]; if (tableInfo.GetFieldInfoByIndex(multiFieldArray[multiFieldCount]) != null) { ++multiFieldCount; } } if (multiFieldCount < 2) { multiFieldArray = null; multiFieldCount = 0; } } } return(multiFieldArray); }
/// <summary> /// Initializes a new instance of the <see cref="UPCatalog"/> class. /// </summary> /// <param name="catNo"> /// The cat no. /// </param> /// <param name="crmDatabase"> /// The CRM database. /// </param> /// <param name="isFixed"> /// if set to <c>true</c> [is fixed]. /// </param> public UPCatalog(int catNo, CRMDatabase crmDatabase, bool isFixed) { this.catNo = catNo; this._fixed = isFixed; this.catInitialized = false; this.catalogInfo = null; this.crmDatabase = crmDatabase; }
/// <summary> /// Initializes a new instance of the <see cref="Query"/> class. /// </summary> /// <param name="crmDatabase"> /// The CRM database. /// </param> /// <param name="infoAreaId"> /// The information area identifier. /// </param> public Query(CRMDatabase crmDatabase, string infoAreaId) { this.RootTreeItem = new QueryTreeItem(crmDatabase, infoAreaId); this.sortFields = null; this.MaxResultRowCount = this.SkipResultRowCount = 0; this.crmDatabase = crmDatabase; this.UseVirtualLinks = true; this.CollationName = null; this.IgnoreLookupOnRoot = crmDatabase.HasLookupRecords(infoAreaId); this.foreignRoot = false; }
/// <summary> /// Creates the query condition options. /// </summary> /// <param name="crmDatabase"> /// The CRM database. /// </param> /// <param name="options"> /// The options. /// </param> /// <returns> /// The <see cref="TreeItemConditionRelation"/>. /// </returns> public override TreeItemCondition CreateQueryConditionOptions(CRMDatabase crmDatabase, int options) { var condition = new TreeItemConditionRelation(this.relation); foreach (var subCondition in this.conditions) { condition.AddSubCondition(subCondition.CreateQueryConditionOptions(crmDatabase, options)); } return(condition); }
/// <summary> /// Initializes a new instance of the <see cref="Query"/> class. /// </summary> /// <param name="rootTreeItem"> /// The root tree item. /// </param> /// <param name="isForign"> /// if set to <c>true</c> [foreign root]. /// </param> public Query(QueryTreeItem rootTreeItem, bool isForign) { this.RootTreeItem = rootTreeItem; this.UseVirtualLinks = rootTreeItem.UseVirtualLinks; this.IgnoreLookupOnRoot = rootTreeItem.IgnoreLookupRows; this.sortFields = null; this.MaxResultRowCount = this.SkipResultRowCount = 0; this.crmDatabase = rootTreeItem.CrmDatabase; this.CollationName = null; this.foreignRoot = isForign; }
/// <summary> /// Checks the after cache save. /// </summary> /// <returns></returns> public int CheckAfterCacheSave() { CRMDatabase database = this.DataStore.DatabaseInstance; int ret = 0; int count = this.undoRecords.Count; for (int i = 0; ret == 0 && i < count; i++) { UPCRMUndoRecord undoRecord = this.undoRecords[i]; ret = undoRecord.CheckAfterCacheSave(database); } return(ret); }
/// <summary> /// Initializes the c data. /// </summary> /// <param name="database"> /// The database. /// </param> public void InitCData(CRMDatabase database) { if (_cdataInitialized) { return; } _cdataInitialized = true; var infoAreaIdString = InfoAreaId; _tableInfo = database.GetTableInfoByInfoArea(infoAreaIdString); if (_tableInfo == null) { return; } _sourceFieldCount = _fieldIds?.Count ?? 0; _intArray = new FieldIdType[_sourceFieldCount + 1]; _fieldCount = 0; var linkFields = GetUPContainerFieldMetaInfoLinkFields(); _cLinkFieldCount = 0; _cLinkMapCount = 0; if (linkFields?.Any() == true) { PopulateLinkMapAndCLinkFieldsFromLinkFields(linkFields); } else if (Links?.Any() == true) { PopulateLinkMapAndCLinkFieldsFromLinks(); } else { _cLinkFields = null; _linkMap = null; } _recordTemplate = new RecordTemplate( database, _isSync, infoAreaIdString, _fieldCount, _intArray, _cLinkFieldCount, _cLinkFields?.ToList(), false, false); }
/// <summary> /// Initializes a new instance of the <see cref="RecordTemplate"/> class. /// </summary> /// <param name="database"> /// The database. /// </param> /// <param name="isSync"> /// if set to <c>true</c> [is synchronize]. /// </param> /// <param name="infoAreaId"> /// The information area identifier. /// </param> /// <param name="fieldIdCount"> /// The field identifier count. /// </param> /// <param name="fieldids"> /// The fieldids. /// </param> /// <param name="linkFieldNameCount"> /// The link field name count. /// </param> /// <param name="linkFieldNames"> /// The link field names. /// </param> /// <param name="includeLookupForNew"> /// if set to <c>true</c> [include lookup for new]. /// </param> /// <param name="includeLookupForUpdate"> /// if set to <c>true</c> [include lookup for update]. /// </param> public RecordTemplate( CRMDatabase database, bool isSync, string infoAreaId, int fieldIdCount, FieldIdType[] fieldids, int linkFieldNameCount, List <string> linkFieldNames, bool includeLookupForNew, bool includeLookupForUpdate) : this(database, infoAreaId, fieldIdCount, fieldids, linkFieldNameCount, linkFieldNames) { this.isSync = isSync; this.IncludeLookupForNew = includeLookupForNew; this.IncludeLookupForUpdate = includeLookupForUpdate; }
/// <summary> /// Creates the query condition options. /// </summary> /// <param name="crmDatabase">The CRM database.</param> /// <param name="options">The options.</param> /// <returns><see cref="TreeItemCondition"/></returns> public override TreeItemCondition CreateQueryConditionOptions(CRMDatabase crmDatabase, int options) { var fieldInfo = (FieldInfo)null; var multiFieldArray = PopulateMultiFieldArray(crmDatabase, fieldInfo); var multiFieldCount = multiFieldArray?.Length; var fieldValueArray = SetFieldValueArray(options, out var emptyFieldValue); var rootCondition = (TreeItemConditionRelation)null; var compare = string.Empty; if (multiFieldArray != null || fieldValueArray?.Count > 1) { if (fieldInfo != null && fieldInfo.FieldType == Constants.FieldInfoFieldTypeK && fieldValueArray?.Count == 1 && fieldValueArray[0].Equals("0")) { emptyFieldValue = true; } if (CompareOperator == Constants.InequalOperation) { rootCondition = new TreeItemConditionRelation(emptyFieldValue ? Constants.OrOperation : Constants.AndOperation); compare = Constants.InequalOperation; } else { rootCondition = new TreeItemConditionRelation(emptyFieldValue ? Constants.AndOperation : Constants.OrOperation); compare = Constants.EqualOperation; } } else { compare = !string.IsNullOrWhiteSpace(CompareOperator) ? CompareOperator : Constants.EqualOperation; return(emptyFieldValue ? new TreeItemConditionFieldValue((FieldIdType)FieldIndex, string.Empty, compare) : new TreeItemConditionFieldValue((FieldIdType)FieldIndex, fieldValueArray[0].ToString(), compare)); } AddTreeItemSubConditions(multiFieldArray, rootCondition, fieldValueArray, emptyFieldValue, compare); return(rootCondition); }
/// <summary> /// Initializes a new instance of the <see cref="RecordTemplate"/> class. /// </summary> /// <param name="database"> /// The database. /// </param> /// <param name="infoAreaId"> /// The information area identifier. /// </param> /// <param name="fieldIdCount"> /// The field identifier count. /// </param> /// <param name="fieldids"> /// The fieldids. /// </param> /// <param name="linkFieldNameCount"> /// The link field name count. /// </param> /// <param name="linkFieldNames"> /// The link field names. /// </param> public RecordTemplate( CRMDatabase database, string infoAreaId, int fieldIdCount, FieldIdType[] fieldids, int linkFieldNameCount, List <string> linkFieldNames) { this.Database = database; this.InfoAreaId = infoAreaId; this.FieldIdCount = fieldIdCount; this.fieldIds = fieldids; this.LinkFieldNameCount = linkFieldNameCount; if (linkFieldNames != null && linkFieldNameCount > 0) { this.linkFieldNames = new List <string>(); for (var i = 0; i < linkFieldNameCount; i++) { this.linkFieldNames.Add(linkFieldNames[i]); } } else { this.linkFieldNames = null; } this.insertStatementString = null; this.updateStatementString = null; this.selectStatementString = null; this.existsStatementString = null; this.deleteStatementString = null; this.tableinfo = null; this.insertStatement = null; this.updateStatement = null; this.selectStatement = null; this.existsStatement = null; this.deleteStatement = null; }
/// <summary> /// Loads this instance. /// </summary> /// <returns></returns> private int Load() { CRMDatabase database = this.DataStore.DatabaseInstance; DatabaseRecordSet recordSet = new DatabaseRecordSet(database); int ret = recordSet.Execute("SELECT infoareaid, recordid, rollbackinfo FROM rollbackinfo WHERE requestnr = ?", this.RequestId); if (ret != 0) { return(ret); } int rowCount = recordSet.GetRowCount(); for (int i = 0; i < rowCount; i++) { DatabaseRow row = recordSet.GetRow(i); string recordIdentification = $"{row.GetColumn(0)}.{row.GetColumn(1)}"; var rollbackinfo = row.GetColumn(2); this.AddRecordIdentificationRollbackInfo(recordIdentification, rollbackinfo); } return(0); }
/// <summary> /// Initializes a new instance of the <see cref="RecordTemplate"/> class. /// </summary> /// <param name="database"> /// The database. /// </param> /// <param name="infoAreaId"> /// The information area identifier. /// </param> /// <param name="fieldIdCount"> /// The field identifier count. /// </param> /// <param name="fieldids"> /// The fieldids. /// </param> public RecordTemplate(CRMDatabase database, string infoAreaId, int fieldIdCount, FieldIdType[] fieldids) : this(database, infoAreaId, fieldIdCount, fieldids, 0, null) { this.isSync = false; }
/// <summary> /// Initializes a new instance of the <see cref="DataModel"/> class. /// </summary> /// <param name="crmDatabase"> /// The CRM database. /// </param> public DataModel(CRMDatabase crmDatabase) { this.Unsorted = false; this.TableInfos = null; this.Database = crmDatabase; }
/// <summary> /// Checks the update before cache save with database. /// </summary> /// <param name="database">The database.</param> /// <returns>0, if success, else error number</returns> private int CheckUpdateBeforeCacheSaveWithDatabase(DatabaseBase database) { UPCRMTableInfo tableInfo = this.UndoRequest.DataStore.TableInfoForInfoArea(this.RecordIdentification.InfoAreaId()); StringBuilder selectStatement = new StringBuilder(); selectStatement.Append("SELECT "); bool first = true; List <string> allColumns = this.FieldDictionary.Keys.ToList(); foreach (string columnName in allColumns) { if (first) { first = false; } else { selectStatement.Append(", "); } selectStatement.Append(columnName); } if (first) { selectStatement.Append("recid"); } selectStatement.Append($" FROM {tableInfo.DatabaseTableName} WHERE recid = ?"); CRMDatabase db = this.UndoRequest.DataStore.DatabaseInstance; DatabaseRecordSet rs = new DatabaseRecordSet(db); if (!rs.Query.Prepare(selectStatement.ToString())) { return(-1); } rs.Query.Bind(1, this.RecordIdentification.RecordId()); int ret = rs.Execute(); if (ret != 0) { return(ret); } int rc = rs.GetRowCount(); if (rc == 0) { this.Mode = "UpdateNew"; this.UndoOperation = "Delete"; return(0); } if (rc > 1) { return(-1); } this.UndoOperation = "Update"; int colIndex = 0; DatabaseRow row = rs.GetRow(0); foreach (string col in allColumns) { string v = row.GetColumn(colIndex++); if (v != null) { UPCRMUndoField undoField = this.FieldDictionary[col]; undoField.OldValue = v; } } return(0); }
/// <summary> /// Initializes a new instance of the <see cref="FixedCatalogInfo"/> class. /// </summary> /// <param name="database"> /// The database. /// </param> /// <param name="catalogNr"> /// The catalog nr. /// </param> public FixedCatalogInfo(CRMDatabase database, int catalogNr) : base(database, catalogNr) { }
/// <summary> /// Initializes a new instance of the <see cref="DependentCatalogInfo"/> class. /// </summary> /// <param name="database"> /// The database. /// </param> /// <param name="catalogNr"> /// The catalog nr. /// </param> /// <param name="parentCatalogNr"> /// The parent catalog nr. /// </param> public DependentCatalogInfo(CRMDatabase database, int catalogNr, int parentCatalogNr) : base(database, catalogNr) { this.ParentCatalogNr = parentCatalogNr; }
/// <summary> /// Initializes a new instance of the <see cref="RecordTemplate"/> class. /// </summary> /// <param name="database"> /// The database. /// </param> /// <param name="infoAreaId"> /// The information area identifier. /// </param> public RecordTemplate(CRMDatabase database, string infoAreaId) : this(database, infoAreaId, 0, null, 0, null) { this.isSync = false; }
/// <summary> /// Addtoes the parent item CRM database options. /// </summary> /// <param name="parentItem"> /// The parent item. /// </param> /// <param name="crmDatabase"> /// The CRM database. /// </param> /// <param name="options"> /// The options. /// </param> /// <returns> /// The <see cref="QueryTreeItem"/>. /// </returns> public QueryTreeItem AddtoParentItemCrmDatabaseOptions(QueryTreeItem parentItem, CRMDatabase crmDatabase, int options) { if (!this._cdataInitialized) { this.InitCData(crmDatabase); } if (this._recordTemplate == null) { return(null); } var queryTreeItem = new QueryTreeItem((RecordTemplate)this._recordTemplate, this._linkId); if (this.IgnoreLookup) { queryTreeItem.SetIgnoreLookupRows(true); } this._queryTreeItem = queryTreeItem; if (this.Condition != null) { queryTreeItem.AddCondition(this.Condition.CreateQueryConditionOptions(crmDatabase, options)); } var count = this.subTables?.Count; for (int i = 0; i < count; i++) { this.subTables[i].AddtoParentItemCrmDatabaseOptions(this._queryTreeItem, crmDatabase, options); } parentItem?.AddSubNode(this.ParentRelation, queryTreeItem); return(queryTreeItem); }
/// <summary> /// Saves this instance. /// </summary> /// <returns></returns> public int Save() { if (this.undoRecords.Count == 0) { return(-1); } CRMDatabase database = this.DataStore.DatabaseInstance; database.BeginTransaction(); DatabaseStatement statement = new DatabaseStatement(database); if (!statement.Prepare("DELETE FROM rollbackinfo WHERE requestnr = ?")) { return(-1); } statement.Bind(this.RequestId); int ret = statement.Execute(); if (ret != 0) { return(ret); } statement = new DatabaseStatement(database); if (!statement.Prepare("INSERT INTO rollbackinfo (requestnr, infoareaid, recordid, rollbackinfo) VALUES (?,?,?,?)")) { return(-1); } int recordCount = this.undoRecords.Count; for (int i = 0; ret == 0 && i < recordCount; i++) { UPCRMUndoRecord undoRecord = this.undoRecords[i]; statement.Reset(); statement.Bind(1, this.RequestId); string infoAreaId = undoRecord.RecordIdentification.InfoAreaId(); string recordId = undoRecord.RecordIdentification.RecordId(); string rollbackInfo = undoRecord.RollbackInfo; if (string.IsNullOrEmpty(infoAreaId) || string.IsNullOrEmpty(recordId) || string.IsNullOrEmpty(rollbackInfo)) { continue; } statement.Bind(2, infoAreaId); statement.Bind(3, recordId); statement.Bind(4, rollbackInfo); ret = statement.Execute(); } if (ret == 0) { database.Commit(); } else { database.Rollback(); } return(ret); }
/// <summary> /// Creates the query condition options. /// </summary> /// <param name="crmDatabase"> /// The CRM database. /// </param> /// <param name="options"> /// The options. /// </param> /// <returns> /// The <see cref="TreeItemCondition"/>. /// </returns> public virtual TreeItemCondition CreateQueryConditionOptions(CRMDatabase crmDatabase, int options) => null;
/// <summary> /// Initializes a new instance of the <see cref="CatalogInfo"/> class. /// </summary> /// <param name="database"> /// The database. /// </param> /// <param name="catalogNr"> /// The catalog nr. /// </param> public CatalogInfo(CRMDatabase database, int catalogNr) { this.CatalogNr = catalogNr; this.Database = database; }
/// <summary> /// Sets the template. /// </summary> /// <param name="database"> /// The database. /// </param> /// <param name="fieldIdCount"> /// The field identifier count. /// </param> /// <param name="fieldids"> /// The fieldids. /// </param> public void SetTemplate(CRMDatabase database, int fieldIdCount, FieldIdType[] fieldids) { this.ReplaceRecordTemplate( new RecordTemplate(database, this.ident?.InfoAreaId, fieldIdCount, fieldids), true); }
/// <summary> /// Initializes a new instance of the <see cref="VariableCatalogInfo"/> class. /// </summary> /// <param name="database"> /// The database. /// </param> /// <param name="catalogNr"> /// The catalog nr. /// </param> public VariableCatalogInfo(CRMDatabase database, int catalogNr) : base(database, catalogNr) { }