示例#1
0
        /// <summary>
        /// 接受更新
        /// </summary>
        /// <returns>数据字典项发生了何种变化。</returns>
        /// <remarks>接受对数据字典项所作的修改,并使更新可见。
        /// 如果数据字典项没有实际变化,则不会进行实质性操作并返回DictionaryEntryChange.None。</remarks>
        protected override DictionaryEntryChange AcceptPrivate()
        {
            if (this.editding)
            {
                // 判断更新内容
                DictionaryEntryChange change = this.Change;

                // 更新值
                this.code    = this.codeT;
                this.pCode   = this.pCodeT;
                this.title   = this.titleT;
                this._value  = this.valueT;
                this.sort    = this.sortT;
                this.visible = this.visibleT;
                this.note    = this.noteT;

                // *T的值现在与正式的值相同了。

                this.editding = false;

                return(change);
            }
            else
            {
                return(DictionaryEntryChange.None);
            }
        }
示例#2
0
        /// <summary>
        /// 更新一个数据字典项。
        /// </summary>
        /// <param name="entry"></param>
        /// <remarks>根据数据字典项对象进行判断,而非Code。</remarks>
        public override void Update(T entry)
        {
            if (!entry.HasChange)
            {
                return;
            }

            try
            {
                this.UpdatePrivate(entry);                     // 持久化 -- 发生错误,引发异常
            }
            catch
            {
                entry.Reject();
                throw;
            }

            // 修改前数据
            string oCode    = entry.Code;               // 原Code
            bool   oVisible = entry.Visible;            // 原Visible
            DictionaryEntryChange change = entry.Accept();

            if (change == DictionaryEntryChange.None)   // 如果没有更新
            {
                return;
            }

            bool[] needSort = new bool[] { false, false };

            lock (this.o_lock)                          // 更新缓存数据
            {
                if ((change & DictionaryEntryChange.Code) == DictionaryEntryChange.Code)
                {
                    this.allData.Remove(oCode);
                    this.allData.Add(entry.Code, entry);
                    // 这里假定如果Code变化会引起Sort变化,那么change应当包括DictionaryEntryChange.Sort。
                    // 故这里不设置需要排序。
                }
                if ((change & DictionaryEntryChange.Visible) == DictionaryEntryChange.Visible)
                {
                    if (entry.Visible != oVisible)
                    {
                        if (entry.Visible)
                        {
                            this.sortDataVisible.Add(entry);
                        }
                        else
                        {
                            this.sortDataVisible.Remove(entry);
                        }
                        needSort[0] = true;
                    }
                }

                if ((change & DictionaryEntryChange.Sort) == DictionaryEntryChange.Sort)
                {
                    needSort[0] = true;
                    needSort[1] = true;
                }

                if (needSort[0])
                {
                    this.sortDataVisible.Sort();
                }
                if (needSort[1])
                {
                    this.sortDataAll.Sort();
                }
            }
        }