Beispiel #1
0
        protected virtual void OnOrderChanged(ManagedPropertyChangedEventArgs e)
        {
            var value = e.NewValue as PurchaseOrder;

            var children = this.StorageInItemList;
            children.Clear();
            if (value != null)
            {
                foreach (PurchaseOrderItem item in value.PurchaseOrderItemList)
                {
                    if (item.AmountLeft > 0)
                    {
                        var siItem = new StorageInBillItem
                        {
                            Id = RafyEnvironment.NewLocalId(),
                            Product = item.Product,
                            Amount = item.AmountLeft,
                            UnitPrice = item.RawPrice
                        };
                        children.Add(siItem);
                    }
                }
            }

            this.NotifyPropertyChanged(StorageInItemListProperty);
            this.NotifyPropertyChanged(View_SupplierNameProperty);
        }
Beispiel #2
0
        /// <summary>
        /// 当实体的某个属性变更时,自动向父级实体的指定属性汇总。
        /// </summary>
        /// <param name="entity">实体对象</param>
        /// <param name="changedPropertyArgs">实体属性变更时的参数</param>
        /// <param name="toTreeParent">
        /// 如果实体是树型对象,那么这个参数表明是否需要把值汇总到树中的父对象的同一个属性值上。
        /// </param>
        /// <param name="toParentProperty">
        /// 指示需要把值汇总到组合父对象的哪一个属性上。这个属性只支持直接父对象,不支持多级父对象。
        /// </param>
        /// <threadsafety static="true" instance="true"/>
        public static void AutoCollectAsChanged(
            Entity entity, ManagedPropertyChangedEventArgs changedPropertyArgs,
            bool toTreeParent = true,
            IManagedProperty toParentProperty = null
            )
        {
            if (toTreeParent)
            {
                if (entity.IsTreeParentLoaded && entity.TreeParent != null)
                {
                    CalculateCollectValue(entity.TreeParent, changedPropertyArgs.Property, changedPropertyArgs);
                    //如果已经向树型父汇总,则不向父对象汇总,直接返回
                    return;
                }
            }

            if (toParentProperty != null)
            {
                var parent = entity.FindParentEntity();
                if (parent != null)
                {
                    CalculateCollectValue(parent, toParentProperty, changedPropertyArgs);
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// 向子类公布一个方法,这样子类可以使用 IManagedProperty 来进行属性变更通知。
        /// 注意,这个方法发布的事件,NewValue、OldValue 将不可用。
        /// </summary>
        /// <param name="property"></param>
        /// <param name="source"></param>
        public void NotifyPropertyChanged(IManagedProperty property, ManagedPropertyChangedSource source = ManagedPropertyChangedSource.FromProperty)
        {
            var propertyInternal = property as IManagedPropertyInternal;

            if (property.IsReadOnly)
            {
                propertyInternal.RaiseReadOnlyPropertyChanged(this, source);
            }
            else
            {
                var defaultValue = property.GetMeta(this).DefaultValue;
                var args         = new ManagedPropertyChangedEventArgs(property, defaultValue, defaultValue, source);
                this.RaisePropertyChanged(args);
            }
        }
Beispiel #4
0
        internal void RaisePropertyChanged(ManagedPropertyChangedEventArgs e)
        {
            this.OnPropertyChanged(e);

            var p = e.Property as IManagedPropertyInternal;

            var dependencies = p.ReadonlyDependencies;

            if (dependencies.Count > 0)
            {
                for (int i = 0, c = dependencies.Count; i < c; i++)
                {
                    var dp = dependencies[i] as IManagedPropertyInternal;
                    dp.RaiseReadOnlyPropertyChanged(this, e.Source);
                }
            }
        }
Beispiel #5
0
        /// <summary>
        /// 这个事件不可以屏敝,否则状态会出问题。
        /// </summary>
        /// <param name="e"></param>
        protected override void OnPropertyChanged(ManagedPropertyChangedEventArgs e)
        {
            var meta = e.Property.DefaultMeta as IPropertyMetadata;
            if (meta.AffectStatus)
            {
                this.MarkModifiedIfUnchanged();

                this.NotifyIfInRedundancyPath(e.Property as IProperty);
            }

            base.OnPropertyChanged(e);
        }
Beispiel #6
0
 /// <summary>
 /// 子类重写此方法实现某个扩展属性变更后的处理函数
 /// </summary>
 /// <param name="e"></param>
 protected virtual void OnPropertyChanged(ManagedPropertyChangedEventArgs e)
 {
     this.OnPropertyChanged(e.Property.Name);
 }
Beispiel #7
0
        /// <summary>
        /// 设置某个属性的值。
        /// </summary>
        /// <param name="property"></param>
        /// <param name="value"></param>
        /// <param name="source"></param>
        /// <returns>返回最终使用的值。</returns>
        private object _SetProperty(IManagedProperty property, object value, ManagedPropertyChangedSource source)
        {
            object finalValue = null;

            CheckEditing(property);

            var meta = property.GetMeta(this) as IManagedPropertyMetadataInternal;

            finalValue = meta.DefaultValue;

            value = CoerceType(property, value);

            bool isReset = false;

            if (NeedReset(property, value))
            {
                isReset = true;
                value   = meta.DefaultValue;
            }

            bool cancel = meta.RaisePropertyChangingMetaEvent(this, ref value, source);

            if (!cancel)
            {
                bool   hasOldValue = false;
                object oldValue    = null;

                //这个 if 块中的代码:查找或创建对应 property 的 field,同时记录可能存在的历史值。
                if (property.LifeCycle == ManagedPropertyLifeCycle.Compile)
                {
                    var index = property.TypeCompiledIndex;
                    var field = this._compiledFields[index];
                    if (field.HasValue)
                    {
                        oldValue    = field.Value;
                        hasOldValue = true;
                    }

                    if (isReset)
                    {
                        this._compiledFields[index].ResetValue();
                    }
                    else
                    {
                        this._compiledFields[index]._value = value;
                    }
                }
                else
                {
                    if (this._runtimeFields == null)
                    {
                        if (!isReset)
                        {
                            this._runtimeFields = new Dictionary <IManagedProperty, ManagedPropertyField>();
                        }
                    }
                    else
                    {
                        var oldField = new ManagedPropertyField();
                        if (this._runtimeFields.TryGetValue(property, out oldField))
                        {
                            oldValue    = oldField.Value;
                            hasOldValue = true;
                        }
                    }

                    if (isReset)
                    {
                        if (hasOldValue)
                        {
                            this._runtimeFields.Remove(property);
                        }
                    }
                    else
                    {
                        //使用新的 field
                        var field = new ManagedPropertyField
                        {
                            _property = property,
                            _value    = value
                        };
                        if (hasOldValue)
                        {
                            this._runtimeFields[property] = field;
                        }
                        else
                        {
                            this._runtimeFields.Add(property, field);
                        }
                    }
                }

                if (!hasOldValue)
                {
                    oldValue = meta.DefaultValue;
                }

                if (!object.Equals(oldValue, value))
                {
                    var args = new ManagedPropertyChangedEventArgs(property, oldValue, value, source);

                    //发生 Meta 中的回调事件
                    meta.RaisePropertyChangedMetaEvent(this, args);

                    //发生外部事件
                    this.RaisePropertyChanged(args);

                    finalValue = value;
                }
            }

            return(finalValue);
        }
Beispiel #8
0
 protected virtual void OnAmountChanged(ManagedPropertyChangedEventArgs e)
 {
 }
Beispiel #9
0
 void IManagedPropertyMetadataInternal.RaisePropertyChangedMetaEvent(ManagedPropertyObject sender, ManagedPropertyChangedEventArgs e)
 {
     if (this._propertyChangedCallBack != null)
     {
         this._propertyChangedCallBack(sender, e);
     }
 }
Beispiel #10
0
 private static void CalculateCollectValue(Entity entity, IManagedProperty property, ManagedPropertyChangedEventArgs args)
 {
     var distance = Convert.ToDouble(args.NewValue) - Convert.ToDouble(args.OldValue);
     var oldValue = Convert.ToDouble(entity.GetProperty(property));
     entity.SetProperty(property, oldValue + distance);
 }
Beispiel #11
0
 private void OnTimeChanged(ManagedPropertyChangedEventArgs e)
 {
     if (e.Source == ManagedPropertyChangedSource.FromUIOperating)
     {
         this.TimeSpanType = TimeSpanType.Custom;
     }
 }
Beispiel #12
0
        protected virtual void OnTimeSpanTypeChanged(ManagedPropertyChangedEventArgs e)
        {
            var today = DateTime.Today;
            switch ((TimeSpanType)e.NewValue)
            {
                case TimeSpanType.Today:
                    this.From = this.To = today;
                    break;
                case TimeSpanType.Week:
                    var dayOfWeek = (int)today.DayOfWeek;
                    if (dayOfWeek == 0) dayOfWeek = 7;
                    dayOfWeek--;//0-6

                    var monday = today.AddDays(-dayOfWeek);
                    this.From = monday;
                    this.To = monday.AddDays(6);
                    break;
                case TimeSpanType.Month:
                    this.From = new DateTime(today.Year, today.Month, 1);
                    this.To = new DateTime(today.Year, today.Month, DateTime.DaysInMonth(today.Year, today.Month));
                    break;
                case TimeSpanType.LastMonth:
                    this.From = today.AddDays(-30);
                    this.To = today;
                    break;
                case TimeSpanType.Year:
                    this.From = new DateTime(today.Year, 1, 1);
                    this.To = new DateTime(today.Year, 12, DateTime.DaysInMonth(today.Year, 12));
                    break;
                case TimeSpanType.All:
                    this.From = new DateTime(1800, 1, 1);
                    this.To = new DateTime(9999, 12, 31);
                    break;
                case TimeSpanType.Custom:
                    //Custom 不需要走下面的逻辑。
                    return;
                default:
                    break;
            }
            var to = this.To;
            this.To = to.Add(new TimeSpan(23, 59, 59));
        }