You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
158 lines
5.7 KiB
158 lines
5.7 KiB
namespace QuantitativerAngebotsvergleich
|
|
{
|
|
public partial class MainForm : Form
|
|
{
|
|
internal OfferMeta Meta;
|
|
private List<Offer> Offers = new();
|
|
|
|
public MainForm()
|
|
{
|
|
InitializeComponent();
|
|
SaveMeta(new());
|
|
}
|
|
|
|
public void AddOffer(Offer offer)
|
|
{
|
|
Offers.Add(offer);
|
|
RedrawFields();
|
|
}
|
|
|
|
public void OverwriteOffer(int index, Offer newOffer)
|
|
{
|
|
Offers[index] = newOffer;
|
|
RedrawFields();
|
|
}
|
|
|
|
public void DeleteOffer(int index)
|
|
{
|
|
Offers.RemoveAt(index);
|
|
RedrawFields();
|
|
}
|
|
|
|
public void SaveMeta(OfferMeta meta)
|
|
{
|
|
Meta = meta;
|
|
|
|
buttonMetaData.Text = $"Metadaten | Währung: {Meta.Currency} | Menge: {Meta.Amount}";
|
|
}
|
|
|
|
public void RedrawFields()
|
|
{
|
|
|
|
// get rid of all controls ad column styles
|
|
offersTablePanel.Controls.Clear();
|
|
offersTablePanel.ColumnStyles.Clear();
|
|
|
|
// add column style for label col
|
|
offersTablePanel.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize));
|
|
|
|
// set column count to fit all offers
|
|
offersTablePanel.ColumnCount = Offers.Count + 1;
|
|
|
|
// add all controls back
|
|
offersTablePanel.Controls.Add(labelOfferTitle, 0, 0);
|
|
offersTablePanel.Controls.Add(labelEdit, 0, 1);
|
|
offersTablePanel.Controls.Add(labelListPrice, 0, 2);
|
|
offersTablePanel.Controls.Add(labelDiscount, 0, 3);
|
|
offersTablePanel.Controls.Add(labelPriceTargetPurchase, 0, 4);
|
|
offersTablePanel.Controls.Add(labelEarlyPayDiscount, 0, 5);
|
|
offersTablePanel.Controls.Add(labelPriceEarlyPayDiscount, 0, 6);
|
|
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++)
|
|
{
|
|
// take offer and set offer id for later modification
|
|
Offer offer = Offers[i];
|
|
offer.offerId = i;
|
|
|
|
// save column number
|
|
int colNumber = i + 1;
|
|
|
|
// create button and add click handler
|
|
Button editButton = new() { Text = "Bearbeiten" };
|
|
editButton.Click += (s, e) => { new OfferDetail(this, offer).Show(); };
|
|
|
|
Label labelShowTitle = new() { Text = offer.Label };
|
|
Label labelShowListPrice = new() { Text = FormatCurrency(offer.ListPrice) };
|
|
Label labelShowDiscount = new() { Text = FormatCurrency(offer.DiscountAmount) };
|
|
Label labelShowPriceTargetPurchase = new() { Text = FormatCurrency(offer.PriceTargetPurchase) };
|
|
Label labelShowEarlyPayDiscount = new() { Text = FormatCurrency(offer.EarlyPayDiscountAmount) };
|
|
Label labelShowPriceEarlyPay = new() { Text = FormatCurrency(offer.PriceEarlyPayDiscount) };
|
|
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);
|
|
|
|
// add col styling
|
|
offersTablePanel.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize));
|
|
|
|
offersTablePanel.Controls.Add(labelShowTitle, colNumber, 0);
|
|
offersTablePanel.Controls.Add(editButton, colNumber, 1);
|
|
offersTablePanel.Controls.Add(labelShowListPrice, colNumber, 2);
|
|
offersTablePanel.Controls.Add(labelShowDiscount, colNumber, 3);
|
|
offersTablePanel.Controls.Add(labelShowPriceTargetPurchase, colNumber, 4);
|
|
offersTablePanel.Controls.Add(labelShowEarlyPayDiscount, colNumber, 5);
|
|
offersTablePanel.Controls.Add(labelShowPriceEarlyPay, colNumber, 6);
|
|
offersTablePanel.Controls.Add(labelShowDeliveryFee, colNumber, 7);
|
|
offersTablePanel.Controls.Add(labelShowPriceDelivered, colNumber, 8);
|
|
}
|
|
|
|
// disable add button if coutn of offers is 2 or more
|
|
buttonAddNewOffer.Enabled = Offers.Count < 2;
|
|
}
|
|
|
|
private void buttonAddNewOffer_Click(object sender, EventArgs e)
|
|
{
|
|
new OfferDetail(this, null).Show();
|
|
}
|
|
|
|
private string FormatCurrency(dynamic val)
|
|
{
|
|
return $"{Meta.Currency} {val}";
|
|
}
|
|
|
|
private void buttonMetaData_Click(object sender, EventArgs e)
|
|
{
|
|
new MetaForm(this, Meta).Show();
|
|
}
|
|
}
|
|
|
|
public class OfferMeta
|
|
{
|
|
private int _amount = 0;
|
|
|
|
public int Amount {
|
|
get {
|
|
if (_amount < 1) {
|
|
return 1;
|
|
} else {
|
|
return _amount;
|
|
}
|
|
}
|
|
set {
|
|
_amount = value;
|
|
}
|
|
}
|
|
|
|
public string Currency { get; set; } = "€";
|
|
}
|
|
} |