Esempio n. 1
0
        /// <summary>
        /// The Calculate.
        /// </summary>
        /// <param name="values">The values<see cref="IList{double}"/>.</param>
        /// <param name="statisticsMethod">The statisticsOutput<see cref="StatisticsMethod"/>.</param>
        /// <param name="digits">The digit<see cref="int"/>.</param>
        /// <returns>The <see cref="string"/>.</returns>
        public static string Calculate(this IList <double> values, StatisticsMethod statisticsMethod, int digits = 0)
        {
            double result;

            switch (statisticsMethod)
            {
            case StatisticsMethod.None:
                return(null);

            case StatisticsMethod.Average:
                result = values.GetAverage();
                return($"Average: {result.Format(digits)}");

            case StatisticsMethod.Percentage:
                return("Total: 100%");

            case StatisticsMethod.PercentageAverage:
                result = values.GetAverage();
                return($"Average: {result.Format(digits)}%");

            case StatisticsMethod.Total:
                result = values.GetTotal();
                return($"Total: {result.Format(digits)}");

            default:
                result = values.GetTotal();
                return($"Total: {result.Format(digits)}");
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Статистика по товару
        /// </summary>
        /// <returns>Логическое значение</returns>
        public static bool StatisticsProduct()
        {
            decimal AverageCostOfGoods  = 0;
            decimal AverageSellingPrice = 0;
            var     ProductsInStock     = ProductBll.ProductsInStock();
            var     ProductsInSales     = ProductBll.ProductsInSales();

            foreach (var item in ProductsInStock)
            {
                AverageCostOfGoods += item.CostPrice;
            }
            foreach (var item in ProductsInSales)
            {
                AverageCostOfGoods  += item.CostPrice;
                AverageSellingPrice += item.Price;
            }
            Statistics statistics = new Statistics
            {
                NumberOfGoodsSold      = ProductsInSales.Count(),
                QuantityOfGoodsInStock = ProductsInStock.Count(),
                AverageCostOfGoods     = AverageCostOfGoods,
                AverageSellingPrice    = AverageSellingPrice,
                Date = DateTime.Now
            };

            return(StatisticsMethod.AddItem(statistics));
        }