예제 #1
0
        void UpdateSources(List <ImageSource> discIcons)
        {
            if (VRObjectEditObject.VideoRentObject == null)
            {
                return;
            }
            MovieItemFormat[]  formats       = EnumHelper.GetValues <MovieItemFormat>();
            MovieItemFormat?[] formatsAndAll = new MovieItemFormat?[formats.Length + 1];
            for (int i = 0; i < formats.Length; ++i)
            {
                formatsAndAll[i] = formats[i];
            }
            formatsAndAll[formatsAndAll.Length - 1] = null;
            MovieItem.CountInfo           countInfo   = new MovieItem.CountInfo(VRObjectEditObject.VideoRentObject.Items);
            List <MovieFormatInfo>        formatInfos = new List <MovieFormatInfo>();
            List <RentalsChartSourceItem> rentals     = new List <RentalsChartSourceItem>();

            for (int i = 0; i < formatsAndAll.Length; ++i)
            {
                MovieCategoryPrice categoryPrice = formatsAndAll[i] == null ? null : VRObjectEditObject.VideoRentObject.Category.GetPrice(formatsAndAll[i].Value);
                ImageSource        formatImage   = i == formatsAndAll.Length - 1 ? null : discIcons[i];
                MovieFormatInfo    info          = new MovieFormatInfo(formatsAndAll[i], countInfo, categoryPrice, formatImage);
                formatInfos.Add(info);
                rentals.Add(new RentalsChartSourceItem(info.FormatText, info.FormatDetailsDictionary));
            }
            UpdateSourcesFields(countInfo, formatInfos, rentals);
        }
예제 #2
0
 public MovieFormatInfo(MovieItemFormat?format, MovieItem.CountInfo countInfo, MovieCategoryPrice categoryPrice, ImageSource formatIcon)
 {
     CategoryPrice = categoryPrice;
     CountInfo     = countInfo;
     Format        = format;
     FormatIcon    = formatIcon;
     UpdateFields();
 }
예제 #3
0
        static object GetPropertyValueByName(MovieCategoryPrice price, string propertyName)
        {
            PropertyInfo propertyInfo;

            if (!propertyInfos.TryGetValue(propertyName, out propertyInfo))
            {
                propertyInfo = typeof(MovieCategoryPrice).GetProperty(propertyName);
                propertyInfos.Add(propertyName, propertyInfo);
            }
            return(propertyInfo.GetValue(price, null));
        }
예제 #4
0
 void UpdateAllPoints(MovieCategoryPrice price)
 {
     for (int i = 1; i < 8; ++i)
     {
         string      fieldName = string.Format(fieldNamePattern, i);
         string      key       = string.Format(pointsKeyPattern, price.Format, fieldName);
         SeriesPoint point     = null;
         if (pointsDictionary.TryGetValue(key, out point))
         {
             point.Value = GetPropertyValueByNameWithEnsure(price, fieldName);
         }
     }
 }
예제 #5
0
        void UpdatePoint(MovieCategoryPrice price, string fieldName)
        {
            SeriesPoint point = null;

            if (fieldName == reserveFieldName)
            {
                UpdateAllPoints(price);
            }
            else
            {
                if (!string.IsNullOrEmpty(fieldName) && pointsDictionary.TryGetValue(string.Format(pointsKeyPattern, ((MovieCategoryPrice)price).Format, fieldName), out point))
                {
                    point.Value = GetPropertyValueByNameWithEnsure(price, fieldName);
                }
            }
        }
예제 #6
0
        public void MovieItem_CalcOnOrderPrice()
        {
            MovieCategory      newFilms      = new MovieCategory(Session);
            MovieCategoryPrice newFilmsOnDVD = newFilms.GetPrice(MovieItemFormat.DVD);

            newFilmsOnDVD.LateRentPrice  = 4;
            newFilmsOnDVD.Days1RentPrice = 2;
            newFilmsOnDVD.Days2RentPrice = 1;
            Avatar.Category = newFilms;
            MovieItem avatarItem   = Avatar.Items[0];
            decimal   onOrderPrice = avatarItem.CalcOnOrderPrice(9);

            Assert.AreEqual(7 * 1 + (9 - 7) * 4, onOrderPrice);
            onOrderPrice = avatarItem.CalcOnOrderPrice(1);
            Assert.AreEqual(1 * 2, onOrderPrice);
        }
예제 #7
0
        public void CreatingAndDeletingPrices()
        {
            MovieCategory category = new MovieCategory(Session);

            foreach (MovieItemFormat format in EnumHelper.GetValues <MovieItemFormat>())
            {
                MovieCategoryPrice price = category.GetPrice(MovieItemFormat.DVD);
                Assert.IsNotNull(price);
            }
            XPCollection <MovieCategoryPrice> prices = category.Prices;

            category.Delete();
            foreach (MovieCategoryPrice price in prices)
            {
                Assert.IsTrue(price.IsDeleted);
            }
        }
예제 #8
0
        LineSeries2D GenerateSerie(MovieCategoryPrice price)
        {
            LineSeries2D serie = new LineSeries2D()
            {
                DisplayName = price.Format.ToString(), LabelsVisibility = true
            };

            for (int i = 1; i <= MovieCategoryPrice.TermsRentCount; ++i)
            {
                string      fieldName = string.Format(fieldNamePattern, i);
                string      key       = string.Format(pointsKeyPattern, price.Format, fieldName);
                SeriesPoint point     = null;
                if (!pointsDictionary.TryGetValue(key, out point))
                {
                    point = new SeriesPoint(i, GetPropertyValueByNameWithEnsure(price, fieldName));
                    pointsDictionary.Add(key, point);
                }
                serie.Points.Add(point);
            }
            UpdateSubscriptionToPropertyChanged(price);
            return(serie);
        }
예제 #9
0
        public void MovieItem_CalcRentMaxDaysCount()
        {
            MovieCategory      newFilms      = new MovieCategory(Session);
            MovieCategoryPrice newFilmsOnDVD = newFilms.GetPrice(MovieItemFormat.DVD);

            newFilmsOnDVD.LateRentPrice  = 1;
            newFilmsOnDVD.Days1RentPrice = 2;
            newFilmsOnDVD.Days2RentPrice = 1;
            Avatar.Category = newFilms;
            MovieItem avatarItem = Avatar.Items[0];

            avatarItem.SellingPrice = 2;
            Assert.AreEqual(0, avatarItem.CalcRentMaxDaysCount());
            avatarItem.SellingPrice = 4;
            Assert.AreEqual(3, avatarItem.CalcRentMaxDaysCount());
            avatarItem.SellingPrice = 10;
            Assert.AreEqual(9, avatarItem.CalcRentMaxDaysCount());
            avatarItem.SellingPrice = 10.5m;
            Assert.AreEqual(10, avatarItem.CalcRentMaxDaysCount());
            avatarItem.AvailableForSell = false;
            Assert.AreEqual(-1, avatarItem.CalcRentMaxDaysCount());
        }
예제 #10
0
        static double GetPropertyValueByNameWithEnsure(MovieCategoryPrice price, string propertyName)
        {
            object value = GetPropertyValueByName(price, propertyName);

            return(value == null || (double)(decimal)value == 0.0 ? (double)(decimal)(GetPropertyValueByName(price, reserveFieldName)) : (double)(decimal)value);
        }
예제 #11
0
 protected override void DisposeManaged()
 {
     CategoryPrice = null;
     base.DisposeManaged();
 }
예제 #12
0
 protected override void UpdateOverride()
 {
     CategoryPrice = MovieCategoryPriceEditObjectParent.GetCategoryPrice(categoryPriceOid);
 }