public ChildrenSortedList_Child( DateTime dateKey, string text, ChildrenSortedList_Parent parentWithSortedList, ChildrenSortedList_ParentNullable?parentWithSortedListNullable, bool isStoring = true) { Key = StorageExtensions.NoKey; DateKey = dateKey.Floor(Rounding.Days); Text = text; ParentWithSortedList = parentWithSortedList; ParentWithSortedListNullable = parentWithSortedListNullable; #if DEBUG DC.Trace?.Invoke($"new ChildrenSortedList_Child: {ToTraceString()}"); #endif ParentWithSortedList.AddToChildrenSortedList_Children(this); if (ParentWithSortedListNullable != null) { ParentWithSortedListNullable.AddToChildrenSortedList_Children(this); } onConstruct(); if (DC.Data?.IsTransaction ?? false) { DC.Data.AddTransaction(new TransactionItem(27, TransactionActivityEnum.New, Key, this)); } if (isStoring) { Store(); } }
/// <summary> /// Called before any property of ChildrenSortedList_Child is updated and before the HasChanged event gets raised /// </summary> partial void onUpdating( DateTime dateKey, string text, ChildrenSortedList_Parent parentWithSortedList, ChildrenSortedList_ParentNullable?parentWithSortedListNullable, ref bool isCancelled) { }
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 }