コード例 #1
0
        /// <summary>
        /// This method calculate all the payments for a specific customerId for a specific month
        /// </summary>
        /// <param name="iPurchases">for a specific month</param>
        /// <returns>
        /// Total amount for the specific month calculated from <see cref="Purchases.PurchasesList"/> and <see cref="ItemPricesRoot.ItemPrices.ItemPricesSet"/>
        /// </returns>
        private float CalculateCustomerIdMonthAmount(Purchases iPurchases)
        {
            float aMonthAmount = 0;

            foreach (Purchase aPurchase in iPurchases.PurchasesList)
            {
                foreach (Item aItem in aPurchase.Items)
                {
                    ItemPrice aItemPrice = this.ItemPricesRoot.ItemPrices.ItemPriceSet.First(aItemPrice => aItemPrice.ItemNumber == aItem.ItemNumber);
                    aMonthAmount += aItemPrice.Price;
                }
            }
            // Consider only two decimal digits
            return((float)Math.Round(aMonthAmount, 2));
        }
コード例 #2
0
        public static void Main(string[] args)
        {
            // Deserialize needed data
            XmlParser <ItemPricesRoot> aXmlParser = new XmlParser <ItemPricesRoot>("data");

            aXmlParser.LoadFile("Prices.xml");
            ItemPricesRoot itemPricesRoot = aXmlParser.Deserialize("ItemPricesRoot");

            JsonParser <Payment> aJsonParserPayment = new JsonParser <Payment>("data");

            aJsonParserPayment.LoadFile("Payments.json");
            HashSet <Payment> aPaymentsPayed = new HashSet <Payment> (aJsonParserPayment.Deserialize());

            PurchasesDatParser aPurchasesDatParser = new PurchasesDatParser("data");

            aPurchasesDatParser.LoadFile("Purchases.dat");
            Purchases aPurchases = aPurchasesDatParser.Deserialize();

            PaymentsNotMatchedService aPaymentsNotMatched = new PaymentsNotMatchedService(aPurchases, itemPricesRoot, aPaymentsPayed);


            // Calculate Payments that have no matching
            SortedSet <PaymentNotMatched> aCommonPaymentsWithDiscrepancy = aPaymentsNotMatched.CalculatePaymentsNotMatched();

            // Store Payments that have no matching inside JSON file
            JsonParser <PaymentNotMatched> aJsonParserPaymentWithDiscrepancy = new JsonParser <PaymentNotMatched>("data");

            aJsonParserPaymentWithDiscrepancy.Serialize(aCommonPaymentsWithDiscrepancy, "PaymentsNotMatched.json");

            // Store Payments that have no matching inside CSV file
            PaymentNotMatchedText aPaymentWithDiscrepancyText = new PaymentNotMatchedText();

            using (PaymentNotMatchedWriter aPaymentWithDiscrepancyWriter = new PaymentNotMatchedWriter("data/PaymentsNotMatched.csv", false, Encoding.Default, aPaymentWithDiscrepancyText))
            {
                aPaymentWithDiscrepancyWriter.WritePaymentsNotMatchedToCsv(aCommonPaymentsWithDiscrepancy);
            }

            // Store Payments that have no matching inside HTML file
            using (PaymentNotMatchedWriter aPaymentWithDiscrepancyWriter = new PaymentNotMatchedWriter("data/PaymentsNotMatched.html", false, Encoding.Default, aPaymentWithDiscrepancyText))
            {
                aPaymentWithDiscrepancyWriter.WritePaymentsNotMatchedToHtml(aCommonPaymentsWithDiscrepancy);
            }
        }
コード例 #3
0
 public PaymentsNotMatchedService(Purchases iPurchases, ItemPricesRoot iItemPricesRoot, HashSet <Payment> iPaymentsPayed)
 {
     this.Purchases      = iPurchases;
     this.ItemPricesRoot = iItemPricesRoot;
     this.PaymentsPayed  = iPaymentsPayed;
 }