예제 #1
0
        public Lookup_Child(string text, Lookup_Parent lookupParent, Lookup_ParentNullable?lookupParentNullable, bool isStoring = true)
        {
            Key                  = StorageExtensions.NoKey;
            Text                 = text;
            LookupParent         = lookupParent;
            LookupParentNullable = lookupParentNullable;
#if DEBUG
            DC.Trace?.Invoke($"new Lookup_Child: {ToTraceString()}");
#endif
            onConstruct();
            if (DC.Data?.IsTransaction ?? false)
            {
                DC.Data.AddTransaction(new TransactionItem(5, TransactionActivityEnum.New, Key, this));
            }

            if (isStoring)
            {
                Store();
            }
        }
예제 #2
0
 /// <summary>
 /// Called before any property of Lookup_Child is updated and before the HasChanged event gets raised
 /// </summary>
 partial void onUpdating(string text, Lookup_Parent lookupParent, Lookup_ParentNullable?lookupParentNullable, ref bool isCancelled)
 {
 }
예제 #3
0
        public void Update(string text, Lookup_Parent lookupParent, Lookup_ParentNullable?lookupParentNullable)
        {
            if (Key >= 0)
            {
                if (lookupParent.Key < 0)
                {
                    throw new Exception($"Lookup_Child.Update(): It is illegal to add stored Lookup_Child '{this}'" + Environment.NewLine +
                                        $"to LookupParent '{lookupParent}', which is not stored.");
                }
                if (lookupParentNullable?.Key < 0)
                {
                    throw new Exception($"Lookup_Child.Update(): It is illegal to add stored Lookup_Child '{this}'" + Environment.NewLine +
                                        $"to LookupParentNullable '{lookupParentNullable}', which is not stored.");
                }
            }
            var clone       = new Lookup_Child(this);
            var isCancelled = false;

            onUpdating(text, lookupParent, lookupParentNullable, ref isCancelled);
            if (isCancelled)
            {
                return;
            }

#if DEBUG
            DC.Trace?.Invoke($"Updating Lookup_Child: {ToTraceString()}");
#endif
            var isChangeDetected = false;
            if (Text != text)
            {
                Text             = text;
                isChangeDetected = true;
            }
            if (LookupParent != lookupParent)
            {
                LookupParent     = lookupParent;
                isChangeDetected = true;
            }
            if (LookupParentNullable is null)
            {
                if (lookupParentNullable is null)
                {
                    //nothing to do
                }
                else
                {
                    LookupParentNullable = lookupParentNullable;
                    isChangeDetected     = true;
                }
            }
            else
            {
                if (lookupParentNullable is null)
                {
                    LookupParentNullable = null;
                    isChangeDetected     = true;
                }
                else
                {
                    if (LookupParentNullable != lookupParentNullable)
                    {
                        LookupParentNullable = lookupParentNullable;
                        isChangeDetected     = true;
                    }
                }
            }
            if (isChangeDetected)
            {
                onUpdated(clone);
                if (Key >= 0)
                {
                    DC.Data.Lookup_Children.ItemHasChanged(clone, this);
                }
                else if (DC.Data.IsTransaction)
                {
                    DC.Data.AddTransaction(new TransactionItem(5, TransactionActivityEnum.Update, Key, this, oldItem: clone));
                }
                HasChanged?.Invoke(clone, this);
            }
#if DEBUG
            DC.Trace?.Invoke($"Updated Lookup_Child: {ToTraceString()}");
#endif
        }