/// <summary> /// /// </summary> /// <param name="attribute"></param> /// <param name="valueStr"></param> /// <param name="dbFields"></param> /// <returns></returns> protected virtual bool setDBSegmentAttribute(DBSegment dbSegment, string attribute, string valueStr, List <DBField> dbFields) { int tmp; switch (attribute) { case ConstInterface.MG_ATTR_FLAGS: IntUtil.TryParse(valueStr, out tmp); dbSegment.Flags = tmp; break; case ConstInterface.MG_ATTR_ISN: IntUtil.TryParse(valueStr, out tmp); dbSegment.Isn = tmp; break; case ConstInterface.MG_ATTR_FLD_ISN: int fldIsn; IntUtil.TryParse(valueStr, out fldIsn); dbSegment.Field = dbFields.Find(x => x.Isn == fldIsn); break; default: return(false); } return(true); }
/// <summary> /// build sort key /// </summary> /// <returns>DbKey</returns> internal DBKey Build() { DBKey sortKey = new DBKey(); sortKey.SetMask(KeyMasks.KeySortMask); sortKey.SetMask(KeyMasks.KeyTypeVirtual); if (mainView.LocalDataviewManager.Task.UniqueSort == UniqueTskSort.Unique) { sortKey.SetMask(KeyMasks.UniqueKeyModeMask); } else { sortKey.SetMask(KeyMasks.DuplicateKeyModeMask); } for (int i = 0; i < RuntimeSorts.getSize(); i++) { int indexInView = RuntimeSorts.getSort(i).fldIdx; if (IsFieldSortable(indexInView)) { Sort sort = RuntimeSorts.getSort(i); DBSegment seg = BuildSegment(sort.dir, sort.fldIdx); sortKey.Segments.Add(seg); } } if (sortKey.Segments.Count == 0) { return(null); } return(sortKey); }
/// <summary> /// /// </summary> /// <param name="attributes"></param> /// <param name="dbFields"></param> internal void SetDBSegmentAttributes(DBSegment dbSegment, NameValueCollection attributes, List <DBField> dbFields) { IEnumerator enumerator = attributes.GetEnumerator(); while (enumerator.MoveNext()) { String attr = (String)enumerator.Current; setDBSegmentAttribute(dbSegment, attr, attributes[attr], dbFields); } }
/// <summary> /// build segment for Sort Key /// </summary> /// <param name="dir"></param> /// <param name="fldIdx"></param> internal DBSegment BuildSegment(Boolean dir, int fldIdx) { DBSegment seg = new DBSegment(); int realFldIdx = mainView.GetFieldIndexInViewByIndexInRecord(fldIdx - 1); seg.Field = mainView.GetDbField(realFldIdx); seg.SetMask(dir == true ? SegMasks.SegDirAscendingMask : SegMasks.SegDirDescendingMask); return(seg); }
/// <summary> /// /// </summary> /// <param name="elementName"></param> /// <param name="elementValue"></param> /// <param name="attributes"></param> public void endElement(string elementName, string elementValue, NameValueCollection attributes) { switch (elementName) { case ConstInterface.MG_TAG_KEYS: case ConstInterface.MG_TAG_SEGS: case ConstInterface.MG_TAG_FLDS: // closing collection - do nothing return; case ConstInterface.MG_TAG_DBH: case ConstInterface.MG_TAG_DBH_DATA_ID: // set the attributes dataSourceBuilder.SetAttributes(dataSourceDefinition, attributes); break; case ConstInterface.MG_TAG_FLD: // create the field and add it to the DataSourceDefinition DBField field = new DBField(); dataSourceBuilder.SetDBFieldAttributes(field, attributes); dataSourceBuilder.AddField(dataSourceDefinition, field); break; case ConstInterface.MG_TAG_KEY: // create the key and add it to the DataSourceDefinition DBKey key = new DBKey(); dataSourceBuilder.SetDBKeyAttributes(key, attributes); // Add the segments collection and reset the local one key.Segments = segments; segments = new List <DBSegment>(); dataSourceBuilder.AddKey(dataSourceDefinition, key); break; case ConstInterface.MG_TAG_SEG: // create the segment and add it to the DataSourceDefinition DBSegment segment = new DBSegment(); dataSourceBuilder.SetDBSegmentAttributes(segment, attributes, dataSourceDefinition.Fields); dataSourceBuilder.AddSegment(dataSourceDefinition, segment); break; case ConstInterface.MG_TAG_SEGMENT: // Get the segment's isn and add the segment to the local segment collection. This way it will be added // later to the right key int isn; IntUtil.TryParse((string)attributes.GetValues(0)[0], out isn); segments.Add(dataSourceDefinition.Segments.Find(x => x.Isn == isn)); break; } }
/// <summary> /// compares old segment with new segment /// </summary> /// <param name="oldSegment"></param> /// <param name="newSegment"></param> /// <returns>returns success if no mismatch found</returns> private ComparisonResult CompareSegment(DBSegment oldSegment, DBSegment newSegment) { if (oldSegment.Field.Isn != newSegment.Field.Isn) { return(ComparisonResult.Failed); } if ((oldSegment.CheckMask(SegMasks.SegDirAscendingMask) && newSegment.CheckMask(SegMasks.SegDirDescendingMask)) || (newSegment.CheckMask(SegMasks.SegDirAscendingMask) && oldSegment.CheckMask(SegMasks.SegDirDescendingMask))) { return(ComparisonResult.Failed); } return(ComparisonResult.Success); }
/// <summary> /// compares old key with new key /// </summary> /// <param name="oldKey"></param> /// <param name="newKey"></param> /// <returns>returns success if no mismatch found</returns> private ComparisonResult CompareKey(DBKey oldKey, DBKey newKey) { if (oldKey.CheckMask(KeyMasks.KeyTypeVirtual) && newKey.CheckMask(KeyMasks.KeyTypeVirtual)) { return(ComparisonResult.Success); } if (oldKey.Segments.Count != newKey.Segments.Count) { return(ComparisonResult.Failed); } if ((oldKey.CheckMask(KeyMasks.DuplicateKeyModeMask) && newKey.CheckMask(KeyMasks.UniqueKeyModeMask)) || (newKey.CheckMask(KeyMasks.DuplicateKeyModeMask) && oldKey.CheckMask(KeyMasks.UniqueKeyModeMask))) { return(ComparisonResult.Failed); } if ((oldKey.CheckMask(KeyMasks.KeyTypeVirtual) && newKey.CheckMask(KeyMasks.KeyTypeReal)) || (newKey.CheckMask(KeyMasks.KeyTypeVirtual) && oldKey.CheckMask(KeyMasks.KeyTypeReal))) { return(ComparisonResult.Failed); } if ((oldKey.CheckMask(KeyMasks.KeyPrimaryMask) && !newKey.CheckMask(KeyMasks.KeyPrimaryMask)) || (newKey.CheckMask(KeyMasks.KeyPrimaryMask) && !oldKey.CheckMask(KeyMasks.KeyPrimaryMask))) { return(ComparisonResult.Failed); } // compare segments of real keys for (int idx = 0; idx < oldKey.Segments.Count; idx++) { DBSegment oldSegment = oldKey.Segments[idx]; DBSegment newSegment = newKey.Segments[idx]; if (CompareSegment(oldSegment, newSegment) == ComparisonResult.Failed) { return(ComparisonResult.Failed); } } return(ComparisonResult.Success); }
/// <summary> /// /// </summary> /// <param name="segment"></param> internal void AddSegment(DataSourceDefinition dataSourceDefinition, DBSegment segment) { dataSourceDefinition.Segments.Add(segment); }