public override string ToString() { var returnString = $"Key: {Key.ToKeyString()}," + $" DateKey: {DateKey.ToShortDateString()}," + $" Text: {Text}," + $" ParentWithSortedList: {ParentWithSortedList.ToShortString()}," + $" ParentWithSortedListNullable: {ParentWithSortedListNullable?.ToShortString()};"; onToString(ref returnString); return(returnString); }
public string ToShortString() { var returnString = $"{Key.ToKeyString()}," + $" {DateKey.ToShortDateString()}," + $" {Text}," + $" {ParentWithSortedList.ToShortString()}," + $" {ParentWithSortedListNullable?.ToShortString()}"; onToShortString(ref returnString); return(returnString); }
public string ToTraceString() { var returnString = $"{this.GetKeyOrHash()}|" + $" {DateKey.ToShortDateString()}|" + $" {Text}|" + $" ParentWithSortedList {ParentWithSortedList.GetKeyOrHash()}|" + $" ParentWithSortedListNullable {ParentWithSortedListNullable?.GetKeyOrHash()}"; onToTraceString(ref returnString); return(returnString); }
private ChildrenSortedList_Child(int key, CsvReader csvReader) { Key = key; DateKey = csvReader.ReadDate(); Text = csvReader.ReadString(); var childrenSortedList_ParentKey = csvReader.ReadInt(); if (DC.Data.ChildrenSortedList_Parents.TryGetValue(childrenSortedList_ParentKey, out var parentWithSortedList)) { ParentWithSortedList = parentWithSortedList; } else { throw new Exception($"Read ChildrenSortedList_Child from CSV file: Cannot find ParentWithSortedList with key {childrenSortedList_ParentKey}." + Environment.NewLine + csvReader.PresentContent); } var parentWithSortedListNullableKey = csvReader.ReadIntNull(); if (parentWithSortedListNullableKey.HasValue) { if (DC.Data.ChildrenSortedList_ParentNullables.TryGetValue(parentWithSortedListNullableKey.Value, out var parentWithSortedListNullable)) { ParentWithSortedListNullable = parentWithSortedListNullable; } else { ParentWithSortedListNullable = ChildrenSortedList_ParentNullable.NoChildrenSortedList_ParentNullable; } } if (ParentWithSortedList != ChildrenSortedList_Parent.NoChildrenSortedList_Parent) { ParentWithSortedList.AddToChildrenSortedList_Children(this); } if (parentWithSortedListNullableKey.HasValue && ParentWithSortedListNullable != ChildrenSortedList_ParentNullable.NoChildrenSortedList_ParentNullable) { ParentWithSortedListNullable !.AddToChildrenSortedList_Children(this); } onCsvConstruct(); }
public void Update(DateTime dateKey, string text, ChildrenSortedList_Parent parentWithSortedList, ChildrenSortedList_ParentNullable?parentWithSortedListNullable) { if (Key >= 0) { if (parentWithSortedList.Key < 0) { throw new Exception($"ChildrenSortedList_Child.Update(): It is illegal to add stored ChildrenSortedList_Child '{this}'" + Environment.NewLine + $"to ParentWithSortedList '{parentWithSortedList}', which is not stored."); } if (parentWithSortedListNullable?.Key < 0) { throw new Exception($"ChildrenSortedList_Child.Update(): It is illegal to add stored ChildrenSortedList_Child '{this}'" + Environment.NewLine + $"to ParentWithSortedListNullable '{parentWithSortedListNullable}', which is not stored."); } } var clone = new ChildrenSortedList_Child(this); var isCancelled = false; onUpdating(dateKey, text, parentWithSortedList, parentWithSortedListNullable, ref isCancelled); if (isCancelled) { return; } #if DEBUG DC.Trace?.Invoke($"Updating ChildrenSortedList_Child: {ToTraceString()}"); #endif var isChangeDetected = false; var dateKeyRounded = dateKey.Floor(Rounding.Days); if (DateKey != dateKeyRounded) { DateKey = dateKeyRounded; isChangeDetected = true; } if (Text != text) { Text = text; isChangeDetected = true; } if (ParentWithSortedList != parentWithSortedList || clone.DateKey != DateKey) { ParentWithSortedList.RemoveFromChildrenSortedList_Children(clone); ParentWithSortedList = parentWithSortedList; ParentWithSortedList.AddToChildrenSortedList_Children(this); isChangeDetected = true; } if (ParentWithSortedListNullable is null) { if (parentWithSortedListNullable is null) { //nothing to do } else { ParentWithSortedListNullable = parentWithSortedListNullable; ParentWithSortedListNullable.AddToChildrenSortedList_Children(this); isChangeDetected = true; } } else { if (parentWithSortedListNullable is null) { ParentWithSortedListNullable.RemoveFromChildrenSortedList_Children(clone); ParentWithSortedListNullable = null; isChangeDetected = true; } else { if (ParentWithSortedListNullable != parentWithSortedListNullable || clone.DateKey != DateKey) { ParentWithSortedListNullable.RemoveFromChildrenSortedList_Children(clone); ParentWithSortedListNullable = parentWithSortedListNullable; ParentWithSortedListNullable.AddToChildrenSortedList_Children(this); isChangeDetected = true; } } } if (isChangeDetected) { onUpdated(clone); if (Key >= 0) { DC.Data.ChildrenSortedList_Children.ItemHasChanged(clone, this); } else if (DC.Data.IsTransaction) { DC.Data.AddTransaction(new TransactionItem(27, TransactionActivityEnum.Update, Key, this, oldItem: clone)); } HasChanged?.Invoke(clone, this); } #if DEBUG DC.Trace?.Invoke($"Updated ChildrenSortedList_Child: {ToTraceString()}"); #endif }