public static void inlineData(DataTable table, ContextManager cm, CallerController <CallerData> cc) { foreach (var ff in table.getFormat()) { if (ff.getType() == FieldFormat.DATA_FIELD) { foreach (var rec in table) { var data = rec.getData(ff.getName()); data.fetchData(cm, cc); data.setId(null); } } if (ff.getType() != FieldFormat.DATATABLE_FIELD) { continue; } foreach (var rec in table) { var dt = rec.getDataTable(ff.getName()); inlineData(dt, cm, cc); } } }
public void cloneFormatFromTable() { if (table != null) { format = table.getFormat().Clone() as TableFormat; } else { throw new InvalidOperationException("Table not defined"); } }
public static HashSet <String> copy(DataTable source, DataTable target, bool copyReadOnlyFields, bool copyNonReplicatableFields, bool removeRecordsFromTarget, ICollection <String> fields) { if (target.getFormat().getKeyFields().Count == 0) { return(copyWithoutKeyFields(source, target, copyReadOnlyFields, copyNonReplicatableFields, removeRecordsFromTarget, fields)); } return(copyWithKeyFields(source, target, copyReadOnlyFields, copyNonReplicatableFields, removeRecordsFromTarget, fields)); }
public override bool Equals(Object obj) { if (obj == null) { return(false); } if (!(obj is DataTable)) { return(false); } DataTable other = (DataTable)obj; if (!format.Equals(other.getFormat())) { return(false); } if (getRecordCount() != other.getRecordCount()) { return(false); } if (!Util.equals(quality, other.quality)) { return(false); } for (int i = 0; i < getRecordCount(); i++) { if (!getRecord(i).Equals(other.getRecord(i))) { return(false); } } return(true); }
private static HashSet <String> copyWithKeyFields(DataTable source, DataTable target, bool copyReadOnlyFields, bool copyNonReplicatableFields, bool removeRecordsFromTarget, ICollection <String> fields) { var errors = new HashSet <String>(); var keyFields = target.getFormat().getKeyFields(); foreach (var fieldName in keyFields) { if (!source.getFormat().hasField(fieldName)) { return(copyWithoutKeyFields(source, target, copyReadOnlyFields, copyNonReplicatableFields, removeRecordsFromTarget, fields)); } } var recordsToRemove = new List <DataRecord>(); foreach (var targetRec in target) { var query = new Query(); foreach (var keyField in keyFields) { query.addCondition(new QueryCondition(keyField, targetRec.getValue(keyField))); } var sourceRec = source.select(query); if (!removeRecordsFromTarget || sourceRec != null) { continue; } if (target.getRecordCount() > target.getFormat().getMinRecords()) { recordsToRemove.Add(targetRec); } else { if (source.getFormat().getMinRecords() != source.getFormat().getMaxRecords()) { errors.Add(Cres.get().getString("dtTargetTableMinRecordsReached")); } break; } } foreach (var each in recordsToRemove) { target.removeRecord(each); } foreach (var sourceRec in source) { var query = new Query(); foreach (var keyField in keyFields) { query.addCondition(new QueryCondition(keyField, sourceRec.getValue(keyField))); } var targetRec = target.select(query); if (targetRec == null) { if (target.getRecordCount() < target.getFormat().getMaxRecords()) { var newRec = new DataRecord(target.getFormat()); // We are not using target.addRecord() to avoid key field validation errors foreach ( var each in copyRecord(sourceRec, newRec, copyReadOnlyFields, copyNonReplicatableFields, fields)) { errors.Add(each); } target.addRecord(newRec); } else { if (source.getFormat().getMinRecords() != source.getFormat().getMaxRecords()) { errors.Add(Cres.get().getString("dtTargetTableMaxRecordsReached")); } } } else { foreach ( var each in copyRecord(sourceRec, targetRec, copyReadOnlyFields, copyNonReplicatableFields, fields)) { errors.Add(each); } } } return(errors); }
private static HashSet <string> copyWithoutKeyFields(DataTable source, DataTable target, bool copyReadOnlyFields, bool copyNonReplicatableFields, bool removeRecordsFromTarget, ICollection <String> fields) { var errors = new HashSet <String>(); while (removeRecordsFromTarget && target.getRecordCount() > source.getRecordCount()) { if (target.getRecordCount() > target.getFormat().getMinRecords()) { target.removeRecord(target.getRecordCount() - 1); } else { if (source.getFormat().getMinRecords() != source.getFormat().getMaxRecords()) { errors.Add(Cres.get().getString("dtTargetTableMinRecordsReached")); } break; } } for (var i = 0; i < Math.Min(source.getRecordCount(), target.getRecordCount()); i++) { var srcRec = source.getRecord(i); var tgtRec = target.getRecord(i); foreach (var each in copyRecord(srcRec, tgtRec, copyReadOnlyFields, copyNonReplicatableFields, fields)) { errors.Add(each); } } if (source.getRecordCount() > target.getRecordCount()) { for (var i = target.getRecordCount(); i < Math.Min(target.getFormat().getMaxRecords(), source.getRecordCount()); i++) { foreach ( var each in copyRecord(source.getRecord(i), target.addRecord(), copyReadOnlyFields, copyNonReplicatableFields, fields)) { errors.Add(each); } } } if (source.getRecordCount() > target.getFormat().getMaxRecords()) { if (source.getFormat().getMinRecords() != source.getFormat().getMaxRecords()) { errors.Add(Cres.get().getString("dtTargetTableMaxRecordsReached")); } } return(errors); }
public string extendMessage(FieldFormat other) { if (!this.getName().Equals(other.getName())) { return("Wrong name: need " + this.getName() + ", found " + other.getName()); } if (!Util.equals(this.getDescription(), other.getDescription())) { return("Wrong description: need " + this.getDescription() + ", found " + other.getDescription()); } if (!Util.equals(this.getHelp(), other.getHelp())) { return("Wrong help: need " + this.getHelp() + ", found " + other.getHelp()); } if (this.getType() != other.getType()) { return("Wrong type: need " + this.getType() + ", found " + other.getType()); } if (!this.isNullable() && other.isNullable()) { return("Different nullable flags: need " + this.isNullable() + ", found " + other.isNullable()); } if (this.isReadonly() != other.isReadonly()) { return("Different readonly flags: need " + this.isReadonly() + ", found " + other.isReadonly()); } if (this.isHidden() != other.isHidden()) { return("Different hidden flags: need " + this.isHidden() + ", found " + other.isHidden()); } if (!isExtendableSelectionValues() || !other.isExtendableSelectionValues()) { bool selectionValuesOk = other.getSelectionValues() == null || Util.equals(getSelectionValues(), other.getSelectionValues()); if (!selectionValuesOk && getSelectionValues() != null) { bool foundMissingValues = false; foreach (var value in getSelectionValues().Keys) { if (!other.getSelectionValues().ContainsKey(value)) { foundMissingValues = true; } } if (!foundMissingValues) { selectionValuesOk = true; } } if (!selectionValuesOk) { return("Different selection values: need " + other.getSelectionValues() + ", found " + getSelectionValues()); } } if (!Util.equals(this.getEditor(), other.getEditor())) { return("Different editor: need " + this.getEditor() + ", found " + other.getEditor()); } if (!Util.equals(this.getEditorOptions(), other.getEditorOptions())) { return("Different editor options: need " + this.getEditorOptions() + ", found " + other.getEditorOptions()); } if (!Util.equals(getIcon(), other.getIcon())) { return("Wrong icon: need " + getIcon() + ", found " + other.getIcon()); } //if (!Util.equals(getGroup(), other.getGroup())) //{ // return "Wrong group: need " + getGroup() + ", found " + other.getGroup(); //} List <FieldValidator> otherValidators = other.getValidators(); foreach (var otherValidator in otherValidators) { if (!this.getValidators().Contains(otherValidator)) { return("Different validators: need " + this.getValidators() + ", found " + other.getValidators()); } } if (this.getDefaultValue() != null && (this.getDefaultValue() is DataTable) && (other.getDefaultValue() != null) && (other.getDefaultValue() is DataTable)) { DataTable my = this.getDefaultValue() as DataTable; DataTable another = other.getDefaultValue() as DataTable; string msg = my.getFormat().extendMessage(another.getFormat()); if (msg != null) { return("Field format doesn't match: " + msg); } } return(null); }