Exemplo n.º 1
0
        // perform post intialization
        protected override void OnInitialized()
        {
            base.OnInitialized();

            ProductIdProperty.SetCascadingProperty(Enumerations.Product.Attributes.ProductSubcategoryId, SubcategoryProperty);
            ProductIdProperty.CascadingMatchNulls = true; // blank subcategory will display products with no categories

            SpecialOfferIdProperty.LocalCacheLoader = new SpecialOfferProductReadListCacheLoader(ServiceProvider);
            SpecialOfferIdProperty.SetCacheLoaderParameters(Enumerations.SpecialOfferProduct.Parameters.ProductId, ProductIdProperty);

            // computed property using the entire object
            Expression <Func <SalesOrderDetailObject, object> > xPrice = sod =>
                                                                         sod.ProductIdProperty.IsNull(null) ? null : sod.ProductIdProperty.Value[Enumerations.Product.Attributes.ListPrice];

            UnitPriceProperty.SetComputedValue(xPrice, this);

            // computed property using individual property
            Expression <Func <EnumProperty, object> > xDiscount = spOf =>
                                                                  spOf.IsNull(null) ? null : spOf.Value[Enumerations.SpecialOfferProduct.Attributes.Discount];

            UnitPriceDiscountProperty.SetComputedValue(xDiscount, SpecialOfferIdProperty);

            // computed visible attribute based on discount value
            Expression <Func <PercentFractionProperty, bool> > xDiscountVisible = dp => !dp.IsNull(null) && dp.Value > 0;

            UnitPriceDiscountProperty.SetComputedVisible(xDiscountVisible, UnitPriceDiscountProperty);

            // computed total using a helper function
            Expression <Func <SalesOrderDetailObject, decimal> > xLineTotal = sod =>
                                                                              GetLineTotal(sod.UnitPriceProperty.Value, sod.UnitPriceDiscountProperty.Value, sod.OrderQtyProperty.Value);

            LineTotalProperty.SetComputedValue(xLineTotal, this);
        }
Exemplo n.º 2
0
        // perform post intialization
        protected override void OnInitialized()
        {
            base.OnInitialized();

            ProductIdProperty.Editable             = true;
            ProductIdProperty.IsKey                = true;
            OrderQtyProperty.Editable              = true;
            CarrierTrackingNumberProperty.Editable = true;

            SpecialOfferIdProperty.Editable         = true;
            SpecialOfferIdProperty.LocalCacheLoader = new SpecialOfferProductReadListCacheLoader(ServiceProvider);
            SpecialOfferIdProperty.SetCacheLoaderParameters(Enumerations.SpecialOfferProduct.Parameters.ProductId, ProductIdProperty);

            Expression <Func <EnumIntProperty, DataRow, object> > xPrice = (prod, row) =>
                                                                           prod.IsNull(row) ? null : prod.GetValue(row)[Enumerations.Product.Attributes.ListPrice];

            UnitPriceProperty.SetComputedValue(xPrice, ProductIdProperty);

            Expression <Func <EnumProperty, DataRow, object> > xDiscount = (spOf, row) =>
                                                                           spOf.IsNull(row) ? null : spOf.GetValue(row)[Enumerations.SpecialOfferProduct.Attributes.Discount];

            UnitPriceDiscountProperty.SetComputedValue(xDiscount, SpecialOfferIdProperty);

            Expression <Func <MoneyProperty, PercentFractionProperty, SmallIntegerProperty, DataRow, decimal> > xLineTotal =
                (price, discount, qty, row) => GetLineTotal(price.GetValue(row), discount.GetValue(row), qty.GetValue(row));

            LineTotalProperty.SetComputedValue(xLineTotal, UnitPriceProperty, UnitPriceDiscountProperty, OrderQtyProperty);

            // defer setting up NewAction enabling conditions until the parent is set, which it depends upon
            PropertyChanged += (s, e) =>
            {
                if (e.PropertyName == nameof(Parent) && Parent != null)
                {
                    Expression <Func <DataObject, bool> > xNewEnabled = obj => !obj.IsNew && obj.Editable;
                    NewAction.SetComputedEnabled(xNewEnabled, Parent);
                }
            };
        }