added delivery options and default amount

main
Fionn 3 years ago
parent 723cbe777b
commit 0887815fc3

@ -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<DeliveryOption> GetPossibleDeliveryOptions()
{
DeliveryOption[] deliveryOptions = (DeliveryOption[])Enum.GetValues(typeof(DeliveryOption));
List<DeliveryOption> possibleDeliveryOptions = new List<DeliveryOption>(deliveryOptions);
return possibleDeliveryOptions;
}
public static List<DeliveryOptionDetails> GetPossibleDeliveryOptionDetails()
{
List<DeliveryOption> options = GetPossibleDeliveryOptions();
List<DeliveryOptionDetails> possibleDeliveryOptionsDetails = new List<DeliveryOptionDetails>();
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
}
}

@ -2,12 +2,13 @@ namespace QuantitativerAngebotsvergleich
{ {
public partial class MainForm : Form public partial class MainForm : Form
{ {
internal OfferMeta Meta = new(); internal OfferMeta Meta;
private List<Offer> Offers = new(); private List<Offer> Offers = new();
public MainForm() public MainForm()
{ {
InitializeComponent(); InitializeComponent();
SaveMeta(new());
} }
public void AddOffer(Offer offer) public void AddOffer(Offer offer)
@ -137,7 +138,21 @@ namespace QuantitativerAngebotsvergleich
public class OfferMeta 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; } = "€"; public string Currency { get; set; } = "€";
} }
} }

@ -27,7 +27,8 @@ namespace QuantitativerAngebotsvergleich
internal void RedrawFields() internal void RedrawFields()
{ {
textBoxAmount.Text = meta.Amount.ToString();
textBoxCurrency.Text = meta.Currency;
} }
private void FormFieldUpdate(Control sender) private void FormFieldUpdate(Control sender)

@ -17,12 +17,16 @@ namespace QuantitativerAngebotsvergleich
public double Discount { get; set; } public double Discount { get; set; }
public double EarlyPayDiscount { get; set; } public double EarlyPayDiscount { get; set; }
public double DeliveryFee { get; set; } public double DeliveryFee { get; set; }
public DeliveryOption DeliveryOption { get; set; }
// calculated Values // calculated Values
public double DiscountAmount { get => Math.Round(ListPrice * Discount, 2); } public double DiscountAmount { get => Math.Round(ListPrice * Discount, 2); }
public double PriceTargetPurchase { get => Math.Round(ListPrice - DiscountAmount, 2); } public double PriceTargetPurchase { get => Math.Round(ListPrice - DiscountAmount, 2); }
public double EarlyPayDiscountAmount { get => Math.Round(PriceTargetPurchase * EarlyPayDiscount, 2); } public double EarlyPayDiscountAmount { get => Math.Round(PriceTargetPurchase * EarlyPayDiscount, 2); }
public double PriceEarlyPayDiscount { get => Math.Round(PriceTargetPurchase - EarlyPayDiscountAmount, 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); }
} }
} }

@ -31,7 +31,6 @@
this.buttonAddOffer = new System.Windows.Forms.Button(); this.buttonAddOffer = new System.Windows.Forms.Button();
this.textBoxInputListPrice = new System.Windows.Forms.TextBox(); this.textBoxInputListPrice = new System.Windows.Forms.TextBox();
this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
this.labelPriceDelivered = new System.Windows.Forms.Label();
this.labelOutputDiscount = new System.Windows.Forms.Label(); this.labelOutputDiscount = new System.Windows.Forms.Label();
this.labelField = new System.Windows.Forms.Label(); this.labelField = new System.Windows.Forms.Label();
this.labelInput = new System.Windows.Forms.Label(); this.labelInput = new System.Windows.Forms.Label();
@ -51,6 +50,10 @@
this.labelOutputPriceEarlyPayDiscount = new System.Windows.Forms.Label(); this.labelOutputPriceEarlyPayDiscount = new System.Windows.Forms.Label();
this.labelOutputDeliveryFee = new System.Windows.Forms.Label(); this.labelOutputDeliveryFee = new System.Windows.Forms.Label();
this.labelOutputPriceDelivered = 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.labelInputLabel = new System.Windows.Forms.Label();
this.textBoxInputLabel = new System.Windows.Forms.TextBox(); this.textBoxInputLabel = new System.Windows.Forms.TextBox();
this.buttonDelete = new System.Windows.Forms.Button(); this.buttonDelete = new System.Windows.Forms.Button();
@ -59,7 +62,7 @@
// //
// buttonAddOffer // 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.Name = "buttonAddOffer";
this.buttonAddOffer.Size = new System.Drawing.Size(226, 23); this.buttonAddOffer.Size = new System.Drawing.Size(226, 23);
this.buttonAddOffer.TabIndex = 0; 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.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.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.labelOutputDiscount, 2, 2);
this.tableLayoutPanel1.Controls.Add(this.textBoxInputListPrice, 1, 1); this.tableLayoutPanel1.Controls.Add(this.textBoxInputListPrice, 1, 1);
this.tableLayoutPanel1.Controls.Add(this.labelField, 0, 0); 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.labelOutputEarlyPayDiscount, 2, 4);
this.tableLayoutPanel1.Controls.Add(this.labelOutputPriceEarlyPayDiscount, 2, 5); this.tableLayoutPanel1.Controls.Add(this.labelOutputPriceEarlyPayDiscount, 2, 5);
this.tableLayoutPanel1.Controls.Add(this.labelOutputDeliveryFee, 2, 6); 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.Location = new System.Drawing.Point(12, 35);
this.tableLayoutPanel1.Name = "tableLayoutPanel1"; 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, 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));
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.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; 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 // labelOutputDiscount
// //
this.labelOutputDiscount.AutoSize = true; this.labelOutputDiscount.AutoSize = true;
@ -303,13 +300,53 @@
// labelOutputPriceDelivered // labelOutputPriceDelivered
// //
this.labelOutputPriceDelivered.AutoSize = true; 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.Name = "labelOutputPriceDelivered";
this.labelOutputPriceDelivered.Padding = new System.Windows.Forms.Padding(0, 6, 0, 0); this.labelOutputPriceDelivered.Padding = new System.Windows.Forms.Padding(0, 6, 0, 0);
this.labelOutputPriceDelivered.Size = new System.Drawing.Size(145, 21); this.labelOutputPriceDelivered.Size = new System.Drawing.Size(145, 21);
this.labelOutputPriceDelivered.TabIndex = 25; this.labelOutputPriceDelivered.TabIndex = 25;
this.labelOutputPriceDelivered.Text = "labelOutputPriceDelivered"; 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 // labelInputLabel
// //
this.labelInputLabel.AutoSize = true; this.labelInputLabel.AutoSize = true;
@ -329,7 +366,7 @@
// //
// buttonDelete // 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.Name = "buttonDelete";
this.buttonDelete.Size = new System.Drawing.Size(226, 23); this.buttonDelete.Size = new System.Drawing.Size(226, 23);
this.buttonDelete.TabIndex = 27; this.buttonDelete.TabIndex = 27;
@ -341,7 +378,7 @@
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 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.buttonDelete);
this.Controls.Add(this.textBoxInputLabel); this.Controls.Add(this.textBoxInputLabel);
this.Controls.Add(this.labelInputLabel); this.Controls.Add(this.labelInputLabel);
@ -387,5 +424,8 @@
private Label labelInputLabel; private Label labelInputLabel;
private TextBox textBoxInputLabel; private TextBox textBoxInputLabel;
private Button buttonDelete; private Button buttonDelete;
private Label labelInputDeliveryTypeDiscount;
private Label labelDeliveryTypeDiscount;
private ComboBox listBoxDeliveryOption;
} }
} }

@ -23,6 +23,11 @@ namespace QuantitativerAngebotsvergleich
this.existingOfferId = existingOffer == null ? -1 : existingOffer.offerId; this.existingOfferId = existingOffer == null ? -1 : existingOffer.offerId;
this.mainForm = mainForm; 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) if (existingOffer == null)
{ {
this.Text = "Angebot hinzufügen"; this.Text = "Angebot hinzufügen";
@ -51,12 +56,19 @@ namespace QuantitativerAngebotsvergleich
private void RedrawFields() private void RedrawFields()
{ {
if (offer == null)
{
Console.WriteLine("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
return;
}
labelOutputListPrice.Text = $"{mainForm.Meta.Currency} {offer.ListPrice}"; labelOutputListPrice.Text = $"{mainForm.Meta.Currency} {offer.ListPrice}";
labelOutputDiscount.Text = $"{mainForm.Meta.Currency} {offer.DiscountAmount}"; labelOutputDiscount.Text = $"{mainForm.Meta.Currency} {offer.DiscountAmount}";
labelOutputPriceTargetPurchase.Text = $"{mainForm.Meta.Currency} {offer.PriceTargetPurchase}"; labelOutputPriceTargetPurchase.Text = $"{mainForm.Meta.Currency} {offer.PriceTargetPurchase}";
labelOutputEarlyPayDiscount.Text = $"{mainForm.Meta.Currency} {offer.EarlyPayDiscountAmount}"; labelOutputEarlyPayDiscount.Text = $"{mainForm.Meta.Currency} {offer.EarlyPayDiscountAmount}";
labelOutputPriceEarlyPayDiscount.Text = $"{mainForm.Meta.Currency} {offer.PriceEarlyPayDiscount}"; labelOutputPriceEarlyPayDiscount.Text = $"{mainForm.Meta.Currency} {offer.PriceEarlyPayDiscount}";
labelOutputDeliveryFee.Text = $"{mainForm.Meta.Currency} {offer.DeliveryFee}"; labelOutputDeliveryFee.Text = $"{mainForm.Meta.Currency} {offer.DeliveryFee}";
labelDeliveryTypeDiscount.Text = $"{mainForm.Meta.Currency} {offer.DiscountAmountFromDeliveryOption}";
labelOutputPriceDelivered.Text = $"{mainForm.Meta.Currency} {offer.PriceDelivered}"; labelOutputPriceDelivered.Text = $"{mainForm.Meta.Currency} {offer.PriceDelivered}";
} }
@ -84,6 +96,10 @@ namespace QuantitativerAngebotsvergleich
{ {
offer.Label = sender.Text; offer.Label = sender.Text;
} }
else if (sender == listBoxDeliveryOption)
{
offer.DeliveryOption = (DeliveryOption)listBoxDeliveryOption.SelectedValue;
}
} }
catch (Exception e) { } catch (Exception e) { }

Loading…
Cancel
Save