From 0887815fc3cf5adfeeee45583c4772bf9ae35ba1 Mon Sep 17 00:00:00 2001 From: Fionn Date: Tue, 26 Apr 2022 10:45:28 +0200 Subject: [PATCH] added delivery options and default amount --- .../DeliveryOption.cs | 71 +++++++++++++++++ .../MainForm.cs | 21 ++++- .../MetaForm.cs | 3 +- .../QuantitativerAngebotsvergleich/Offer.cs | 6 +- .../OfferDetail.Designer.cs | 78 ++++++++++++++----- .../OfferDetail.cs | 16 ++++ 6 files changed, 171 insertions(+), 24 deletions(-) create mode 100644 QuantitativerAngebotsvergleich/QuantitativerAngebotsvergleich/DeliveryOption.cs diff --git a/QuantitativerAngebotsvergleich/QuantitativerAngebotsvergleich/DeliveryOption.cs b/QuantitativerAngebotsvergleich/QuantitativerAngebotsvergleich/DeliveryOption.cs new file mode 100644 index 0000000..037219b --- /dev/null +++ b/QuantitativerAngebotsvergleich/QuantitativerAngebotsvergleich/DeliveryOption.cs @@ -0,0 +1,71 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace QuantitativerAngebotsvergleich +{ + public class DeliveryOptionUtils + { + public static double GetDiscountFromDeliveryOption(DeliveryOption deliveryOption) + { + switch (deliveryOption) + { + case DeliveryOption.DHL: + { + return 0; + } + case DeliveryOption.Hermes: + { + return 0.01; + } + case DeliveryOption.DPD: + { + return 0.02; + } + case DeliveryOption.PickUp: + { + return 0.05; + } + } + + return 0; + } + + public static List GetPossibleDeliveryOptions() + { + DeliveryOption[] deliveryOptions = (DeliveryOption[])Enum.GetValues(typeof(DeliveryOption)); + List possibleDeliveryOptions = new List(deliveryOptions); + + return possibleDeliveryOptions; + } + + public static List GetPossibleDeliveryOptionDetails() + { + List options = GetPossibleDeliveryOptions(); + List possibleDeliveryOptionsDetails = new List(); + + foreach(DeliveryOption option in options) + { + possibleDeliveryOptionsDetails.Add(new() { DeliveryOption = option, Discount = GetDiscountFromDeliveryOption(option) }); + } + + return possibleDeliveryOptionsDetails; + } + } + + public class DeliveryOptionDetails { + public DeliveryOption DeliveryOption { get; set; } + public double Discount { get; set; } + public string Label { get => $"{DeliveryOption} ({Discount * 100}%)"; } + } + + public enum DeliveryOption + { + DHL, + Hermes, + DPD, + PickUp + } +} diff --git a/QuantitativerAngebotsvergleich/QuantitativerAngebotsvergleich/MainForm.cs b/QuantitativerAngebotsvergleich/QuantitativerAngebotsvergleich/MainForm.cs index 9e96124..5891609 100644 --- a/QuantitativerAngebotsvergleich/QuantitativerAngebotsvergleich/MainForm.cs +++ b/QuantitativerAngebotsvergleich/QuantitativerAngebotsvergleich/MainForm.cs @@ -2,12 +2,13 @@ namespace QuantitativerAngebotsvergleich { public partial class MainForm : Form { - internal OfferMeta Meta = new(); + internal OfferMeta Meta; private List Offers = new(); public MainForm() { InitializeComponent(); + SaveMeta(new()); } public void AddOffer(Offer offer) @@ -117,7 +118,7 @@ namespace QuantitativerAngebotsvergleich // disable add button if coutn of offers is 2 or more buttonAddNewOffer.Enabled = Offers.Count < 2; - } + } private void buttonAddNewOffer_Click(object sender, EventArgs e) { @@ -137,7 +138,21 @@ namespace QuantitativerAngebotsvergleich public class OfferMeta { - public int Amount { get; set; } = 0; + private int _amount = 0; + + public int Amount { + get { + if (_amount < 1) { + return 1; + } else { + return _amount; + } + } + set { + _amount = value; + } + } + public string Currency { get; set; } = "€"; } } \ No newline at end of file diff --git a/QuantitativerAngebotsvergleich/QuantitativerAngebotsvergleich/MetaForm.cs b/QuantitativerAngebotsvergleich/QuantitativerAngebotsvergleich/MetaForm.cs index 8c2c7e6..ad5de32 100644 --- a/QuantitativerAngebotsvergleich/QuantitativerAngebotsvergleich/MetaForm.cs +++ b/QuantitativerAngebotsvergleich/QuantitativerAngebotsvergleich/MetaForm.cs @@ -27,7 +27,8 @@ namespace QuantitativerAngebotsvergleich internal void RedrawFields() { - + textBoxAmount.Text = meta.Amount.ToString(); + textBoxCurrency.Text = meta.Currency; } private void FormFieldUpdate(Control sender) diff --git a/QuantitativerAngebotsvergleich/QuantitativerAngebotsvergleich/Offer.cs b/QuantitativerAngebotsvergleich/QuantitativerAngebotsvergleich/Offer.cs index 4b832fb..9ceb279 100644 --- a/QuantitativerAngebotsvergleich/QuantitativerAngebotsvergleich/Offer.cs +++ b/QuantitativerAngebotsvergleich/QuantitativerAngebotsvergleich/Offer.cs @@ -17,12 +17,16 @@ namespace QuantitativerAngebotsvergleich public double Discount { get; set; } public double EarlyPayDiscount { get; set; } public double DeliveryFee { get; set; } + public DeliveryOption DeliveryOption { get; set; } // calculated Values public double DiscountAmount { get => Math.Round(ListPrice * Discount, 2); } 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(PriceEarlyPayDiscount + DeliveryFee, 2); } + private double PriceDeliveredPreDiscount { get => Math.Round(PriceEarlyPayDiscount + DeliveryFee, 2); } + private double DiscountFromDeliveryOption { get => DeliveryOptionUtils.GetDiscountFromDeliveryOption(DeliveryOption); } + public double DiscountAmountFromDeliveryOption { get => Math.Round(PriceDeliveredPreDiscount * DiscountFromDeliveryOption); } + public double PriceDelivered { get => Math.Round(PriceDeliveredPreDiscount - DiscountAmountFromDeliveryOption); } } } diff --git a/QuantitativerAngebotsvergleich/QuantitativerAngebotsvergleich/OfferDetail.Designer.cs b/QuantitativerAngebotsvergleich/QuantitativerAngebotsvergleich/OfferDetail.Designer.cs index 0bb6408..7ee60c1 100644 --- a/QuantitativerAngebotsvergleich/QuantitativerAngebotsvergleich/OfferDetail.Designer.cs +++ b/QuantitativerAngebotsvergleich/QuantitativerAngebotsvergleich/OfferDetail.Designer.cs @@ -31,7 +31,6 @@ this.buttonAddOffer = new System.Windows.Forms.Button(); this.textBoxInputListPrice = new System.Windows.Forms.TextBox(); this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); - this.labelPriceDelivered = new System.Windows.Forms.Label(); this.labelOutputDiscount = new System.Windows.Forms.Label(); this.labelField = new System.Windows.Forms.Label(); this.labelInput = new System.Windows.Forms.Label(); @@ -51,6 +50,10 @@ this.labelOutputPriceEarlyPayDiscount = new System.Windows.Forms.Label(); this.labelOutputDeliveryFee = new System.Windows.Forms.Label(); this.labelOutputPriceDelivered = new System.Windows.Forms.Label(); + this.labelPriceDelivered = new System.Windows.Forms.Label(); + this.labelInputDeliveryTypeDiscount = new System.Windows.Forms.Label(); + this.labelDeliveryTypeDiscount = new System.Windows.Forms.Label(); + this.listBoxDeliveryOption = new System.Windows.Forms.ComboBox(); this.labelInputLabel = new System.Windows.Forms.Label(); this.textBoxInputLabel = new System.Windows.Forms.TextBox(); this.buttonDelete = new System.Windows.Forms.Button(); @@ -59,7 +62,7 @@ // // buttonAddOffer // - this.buttonAddOffer.Location = new System.Drawing.Point(247, 283); + this.buttonAddOffer.Location = new System.Drawing.Point(247, 313); this.buttonAddOffer.Name = "buttonAddOffer"; this.buttonAddOffer.Size = new System.Drawing.Size(226, 23); this.buttonAddOffer.TabIndex = 0; @@ -81,7 +84,6 @@ this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 33.33332F)); this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 33.33334F)); this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 33.33334F)); - this.tableLayoutPanel1.Controls.Add(this.labelPriceDelivered, 0, 7); this.tableLayoutPanel1.Controls.Add(this.labelOutputDiscount, 2, 2); this.tableLayoutPanel1.Controls.Add(this.textBoxInputListPrice, 1, 1); this.tableLayoutPanel1.Controls.Add(this.labelField, 0, 0); @@ -101,10 +103,14 @@ this.tableLayoutPanel1.Controls.Add(this.labelOutputEarlyPayDiscount, 2, 4); this.tableLayoutPanel1.Controls.Add(this.labelOutputPriceEarlyPayDiscount, 2, 5); this.tableLayoutPanel1.Controls.Add(this.labelOutputDeliveryFee, 2, 6); - this.tableLayoutPanel1.Controls.Add(this.labelOutputPriceDelivered, 2, 7); + this.tableLayoutPanel1.Controls.Add(this.labelOutputPriceDelivered, 2, 8); + this.tableLayoutPanel1.Controls.Add(this.labelPriceDelivered, 0, 8); + this.tableLayoutPanel1.Controls.Add(this.labelInputDeliveryTypeDiscount, 0, 7); + this.tableLayoutPanel1.Controls.Add(this.labelDeliveryTypeDiscount, 2, 7); + this.tableLayoutPanel1.Controls.Add(this.listBoxDeliveryOption, 1, 7); this.tableLayoutPanel1.Location = new System.Drawing.Point(12, 35); this.tableLayoutPanel1.Name = "tableLayoutPanel1"; - this.tableLayoutPanel1.RowCount = 8; + this.tableLayoutPanel1.RowCount = 9; this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 30F)); this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 30F)); @@ -113,19 +119,10 @@ this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 30F)); this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 30F)); this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 30F)); - this.tableLayoutPanel1.Size = new System.Drawing.Size(461, 242); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.tableLayoutPanel1.Size = new System.Drawing.Size(461, 279); this.tableLayoutPanel1.TabIndex = 3; // - // labelPriceDelivered - // - this.labelPriceDelivered.AutoSize = true; - this.labelPriceDelivered.Location = new System.Drawing.Point(3, 200); - this.labelPriceDelivered.Name = "labelPriceDelivered"; - this.labelPriceDelivered.Padding = new System.Windows.Forms.Padding(0, 6, 0, 0); - this.labelPriceDelivered.Size = new System.Drawing.Size(69, 21); - this.labelPriceDelivered.TabIndex = 14; - this.labelPriceDelivered.Text = "Bezugspreis"; - // // labelOutputDiscount // this.labelOutputDiscount.AutoSize = true; @@ -303,13 +300,53 @@ // labelOutputPriceDelivered // this.labelOutputPriceDelivered.AutoSize = true; - this.labelOutputPriceDelivered.Location = new System.Drawing.Point(309, 200); + this.labelOutputPriceDelivered.Location = new System.Drawing.Point(309, 230); this.labelOutputPriceDelivered.Name = "labelOutputPriceDelivered"; this.labelOutputPriceDelivered.Padding = new System.Windows.Forms.Padding(0, 6, 0, 0); this.labelOutputPriceDelivered.Size = new System.Drawing.Size(145, 21); this.labelOutputPriceDelivered.TabIndex = 25; this.labelOutputPriceDelivered.Text = "labelOutputPriceDelivered"; // + // labelPriceDelivered + // + this.labelPriceDelivered.AutoSize = true; + this.labelPriceDelivered.Location = new System.Drawing.Point(3, 230); + this.labelPriceDelivered.Name = "labelPriceDelivered"; + this.labelPriceDelivered.Padding = new System.Windows.Forms.Padding(0, 6, 0, 0); + this.labelPriceDelivered.Size = new System.Drawing.Size(69, 21); + this.labelPriceDelivered.TabIndex = 14; + this.labelPriceDelivered.Text = "Bezugspreis"; + // + // labelInputDeliveryTypeDiscount + // + this.labelInputDeliveryTypeDiscount.AutoSize = true; + this.labelInputDeliveryTypeDiscount.Location = new System.Drawing.Point(3, 200); + this.labelInputDeliveryTypeDiscount.Name = "labelInputDeliveryTypeDiscount"; + this.labelInputDeliveryTypeDiscount.Padding = new System.Windows.Forms.Padding(0, 6, 0, 0); + this.labelInputDeliveryTypeDiscount.Size = new System.Drawing.Size(89, 21); + this.labelInputDeliveryTypeDiscount.TabIndex = 26; + this.labelInputDeliveryTypeDiscount.Text = "Bezugsartrabatt"; + // + // labelDeliveryTypeDiscount + // + this.labelDeliveryTypeDiscount.AutoSize = true; + this.labelDeliveryTypeDiscount.Location = new System.Drawing.Point(309, 200); + this.labelDeliveryTypeDiscount.Name = "labelDeliveryTypeDiscount"; + this.labelDeliveryTypeDiscount.Padding = new System.Windows.Forms.Padding(0, 6, 0, 0); + this.labelDeliveryTypeDiscount.Size = new System.Drawing.Size(145, 21); + this.labelDeliveryTypeDiscount.TabIndex = 27; + this.labelDeliveryTypeDiscount.Text = "labelDeliveryTypeDiscount"; + // + // listBoxDeliveryOption + // + this.listBoxDeliveryOption.FormattingEnabled = true; + this.listBoxDeliveryOption.ItemHeight = 15; + this.listBoxDeliveryOption.Location = new System.Drawing.Point(156, 203); + this.listBoxDeliveryOption.Name = "listBoxDeliveryOption"; + this.listBoxDeliveryOption.Size = new System.Drawing.Size(146, 19); + this.listBoxDeliveryOption.TabIndex = 28; + this.listBoxDeliveryOption.SelectedIndexChanged += new System.EventHandler(this.FormFieldUpdate); + // // labelInputLabel // this.labelInputLabel.AutoSize = true; @@ -329,7 +366,7 @@ // // buttonDelete // - this.buttonDelete.Location = new System.Drawing.Point(15, 283); + this.buttonDelete.Location = new System.Drawing.Point(12, 313); this.buttonDelete.Name = "buttonDelete"; this.buttonDelete.Size = new System.Drawing.Size(226, 23); this.buttonDelete.TabIndex = 27; @@ -341,7 +378,7 @@ // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(485, 316); + this.ClientSize = new System.Drawing.Size(485, 384); this.Controls.Add(this.buttonDelete); this.Controls.Add(this.textBoxInputLabel); this.Controls.Add(this.labelInputLabel); @@ -387,5 +424,8 @@ private Label labelInputLabel; private TextBox textBoxInputLabel; private Button buttonDelete; + private Label labelInputDeliveryTypeDiscount; + private Label labelDeliveryTypeDiscount; + private ComboBox listBoxDeliveryOption; } } \ No newline at end of file diff --git a/QuantitativerAngebotsvergleich/QuantitativerAngebotsvergleich/OfferDetail.cs b/QuantitativerAngebotsvergleich/QuantitativerAngebotsvergleich/OfferDetail.cs index ee934f5..2d6b7a9 100644 --- a/QuantitativerAngebotsvergleich/QuantitativerAngebotsvergleich/OfferDetail.cs +++ b/QuantitativerAngebotsvergleich/QuantitativerAngebotsvergleich/OfferDetail.cs @@ -23,6 +23,11 @@ namespace QuantitativerAngebotsvergleich this.existingOfferId = existingOffer == null ? -1 : existingOffer.offerId; this.mainForm = mainForm; + // set up list box for delivery option + listBoxDeliveryOption.DataSource = DeliveryOptionUtils.GetPossibleDeliveryOptionDetails(); + listBoxDeliveryOption.DisplayMember = nameof(DeliveryOptionDetails.Label); + listBoxDeliveryOption.ValueMember = nameof(DeliveryOptionDetails.DeliveryOption); + if (existingOffer == null) { this.Text = "Angebot hinzufügen"; @@ -51,12 +56,19 @@ namespace QuantitativerAngebotsvergleich private void RedrawFields() { + if (offer == null) + { + Console.WriteLine("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"); + return; + } + labelOutputListPrice.Text = $"{mainForm.Meta.Currency} {offer.ListPrice}"; labelOutputDiscount.Text = $"{mainForm.Meta.Currency} {offer.DiscountAmount}"; labelOutputPriceTargetPurchase.Text = $"{mainForm.Meta.Currency} {offer.PriceTargetPurchase}"; labelOutputEarlyPayDiscount.Text = $"{mainForm.Meta.Currency} {offer.EarlyPayDiscountAmount}"; labelOutputPriceEarlyPayDiscount.Text = $"{mainForm.Meta.Currency} {offer.PriceEarlyPayDiscount}"; labelOutputDeliveryFee.Text = $"{mainForm.Meta.Currency} {offer.DeliveryFee}"; + labelDeliveryTypeDiscount.Text = $"{mainForm.Meta.Currency} {offer.DiscountAmountFromDeliveryOption}"; labelOutputPriceDelivered.Text = $"{mainForm.Meta.Currency} {offer.PriceDelivered}"; } @@ -84,6 +96,10 @@ namespace QuantitativerAngebotsvergleich { offer.Label = sender.Text; } + else if (sender == listBoxDeliveryOption) + { + offer.DeliveryOption = (DeliveryOption)listBoxDeliveryOption.SelectedValue; + } } catch (Exception e) { }