コード例 #1
0
        public ChildrenDictionary_Child(
            DateTime dateKey,
            string text,
            ChildrenDictionary_Parent parentWithDictionary,
            ChildrenDictionary_ParentNullable?parentWithDictionaryNullable,
            bool isStoring = true)
        {
            Key     = StorageExtensions.NoKey;
            DateKey = dateKey.Floor(Rounding.Days);
            Text    = text;
            ParentWithDictionary         = parentWithDictionary;
            ParentWithDictionaryNullable = parentWithDictionaryNullable;
#if DEBUG
            DC.Trace?.Invoke($"new ChildrenDictionary_Child: {ToTraceString()}");
#endif
            ParentWithDictionary.AddToChildrenDictionary_Children(this);
            if (ParentWithDictionaryNullable != null)
            {
                ParentWithDictionaryNullable.AddToChildrenDictionary_Children(this);
            }
            onConstruct();
            if (DC.Data?.IsTransaction ?? false)
            {
                DC.Data.AddTransaction(new TransactionItem(24, TransactionActivityEnum.New, Key, this));
            }

            if (isStoring)
            {
                Store();
            }
        }
コード例 #2
0
        public void Update(DateTime dateKey, string text, ChildrenDictionary_Parent parentWithDictionary, ChildrenDictionary_ParentNullable?parentWithDictionaryNullable)
        {
            if (Key >= 0)
            {
                if (parentWithDictionary.Key < 0)
                {
                    throw new Exception($"ChildrenDictionary_Child.Update(): It is illegal to add stored ChildrenDictionary_Child '{this}'" + Environment.NewLine +
                                        $"to ParentWithDictionary '{parentWithDictionary}', which is not stored.");
                }
                if (parentWithDictionaryNullable?.Key < 0)
                {
                    throw new Exception($"ChildrenDictionary_Child.Update(): It is illegal to add stored ChildrenDictionary_Child '{this}'" + Environment.NewLine +
                                        $"to ParentWithDictionaryNullable '{parentWithDictionaryNullable}', which is not stored.");
                }
            }
            var clone       = new ChildrenDictionary_Child(this);
            var isCancelled = false;

            onUpdating(dateKey, text, parentWithDictionary, parentWithDictionaryNullable, ref isCancelled);
            if (isCancelled)
            {
                return;
            }

#if DEBUG
            DC.Trace?.Invoke($"Updating ChildrenDictionary_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 (ParentWithDictionary != parentWithDictionary || clone.DateKey != DateKey)
            {
                ParentWithDictionary.RemoveFromChildrenDictionary_Children(clone);
                ParentWithDictionary = parentWithDictionary;
                ParentWithDictionary.AddToChildrenDictionary_Children(this);
                isChangeDetected = true;
            }
            if (ParentWithDictionaryNullable is null)
            {
                if (parentWithDictionaryNullable is null)
                {
                    //nothing to do
                }
                else
                {
                    ParentWithDictionaryNullable = parentWithDictionaryNullable;
                    ParentWithDictionaryNullable.AddToChildrenDictionary_Children(this);
                    isChangeDetected = true;
                }
            }
            else
            {
                if (parentWithDictionaryNullable is null)
                {
                    ParentWithDictionaryNullable.RemoveFromChildrenDictionary_Children(clone);
                    ParentWithDictionaryNullable = null;
                    isChangeDetected             = true;
                }
                else
                {
                    if (ParentWithDictionaryNullable != parentWithDictionaryNullable || clone.DateKey != DateKey)
                    {
                        ParentWithDictionaryNullable.RemoveFromChildrenDictionary_Children(clone);
                        ParentWithDictionaryNullable = parentWithDictionaryNullable;
                        ParentWithDictionaryNullable.AddToChildrenDictionary_Children(this);
                        isChangeDetected = true;
                    }
                }
            }
            if (isChangeDetected)
            {
                onUpdated(clone);
                if (Key >= 0)
                {
                    DC.Data.ChildrenDictionary_Children.ItemHasChanged(clone, this);
                }
                else if (DC.Data.IsTransaction)
                {
                    DC.Data.AddTransaction(new TransactionItem(24, TransactionActivityEnum.Update, Key, this, oldItem: clone));
                }
                HasChanged?.Invoke(clone, this);
            }
#if DEBUG
            DC.Trace?.Invoke($"Updated ChildrenDictionary_Child: {ToTraceString()}");
#endif
        }