From 723cbe777bfeb8059d98b53cbddb7dd005ee6c8e Mon Sep 17 00:00:00 2001 From: Fionn Date: Thu, 24 Feb 2022 15:41:15 +0100 Subject: [PATCH] added comparing offers, fixed minor stupidity --- .../QuantitativerAngebotsvergleich/MainForm.cs | 17 +++++++++++++++-- .../QuantitativerAngebotsvergleich/Offer.cs | 2 +- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/QuantitativerAngebotsvergleich/QuantitativerAngebotsvergleich/MainForm.cs b/QuantitativerAngebotsvergleich/QuantitativerAngebotsvergleich/MainForm.cs index 83d9923..9e96124 100644 --- a/QuantitativerAngebotsvergleich/QuantitativerAngebotsvergleich/MainForm.cs +++ b/QuantitativerAngebotsvergleich/QuantitativerAngebotsvergleich/MainForm.cs @@ -59,6 +59,16 @@ namespace QuantitativerAngebotsvergleich offersTablePanel.Controls.Add(labelDeliveryFee, 0, 7); offersTablePanel.Controls.Add(labelPriceDelivered, 0, 8); + Offer cheapestOffer = null; + + foreach (Offer offer in Offers) + { + if (cheapestOffer == null || offer.PriceDelivered < cheapestOffer.PriceDelivered) + { + cheapestOffer = offer; + } + } + // iterate through all offers and create controls and add them for (int i = 0; i < Offers.Count; i++) { @@ -66,8 +76,6 @@ namespace QuantitativerAngebotsvergleich Offer offer = Offers[i]; offer.offerId = i; - - // save column number int colNumber = i + 1; @@ -84,6 +92,11 @@ namespace QuantitativerAngebotsvergleich Label labelShowDeliveryFee = new() { Text = FormatCurrency(offer.DeliveryFee) }; Label labelShowPriceDelivered = new() { Text = FormatCurrency(offer.PriceDelivered) }; + if (offer == cheapestOffer) + { + labelShowPriceDelivered.BackColor = Color.Green; + } + Console.WriteLine("Adding Controls to Column {0}, ColumnCount is {1}", colNumber, offersTablePanel.ColumnCount); labelShowTitle.MinimumSize = labelShowTitle.GetPreferredSize(default); diff --git a/QuantitativerAngebotsvergleich/QuantitativerAngebotsvergleich/Offer.cs b/QuantitativerAngebotsvergleich/QuantitativerAngebotsvergleich/Offer.cs index d172df3..4b832fb 100644 --- a/QuantitativerAngebotsvergleich/QuantitativerAngebotsvergleich/Offer.cs +++ b/QuantitativerAngebotsvergleich/QuantitativerAngebotsvergleich/Offer.cs @@ -23,6 +23,6 @@ namespace QuantitativerAngebotsvergleich public double PriceTargetPurchase { get => Math.Round(ListPrice - DiscountAmount, 2); } public double EarlyPayDiscountAmount { get => Math.Round(PriceTargetPurchase * EarlyPayDiscount, 2); } public double PriceEarlyPayDiscount { get => Math.Round(PriceTargetPurchase - EarlyPayDiscountAmount, 2); } - public double PriceDelivered { get => Math.Round(PriceTargetPurchase + DeliveryFee, 2); } + public double PriceDelivered { get => Math.Round(PriceEarlyPayDiscount + DeliveryFee, 2); } } }