139 lines
5.3 KiB
C#
139 lines
5.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.Windows;
|
|
|
|
namespace Gremlin.GremlinUI.ViewModels
|
|
{
|
|
internal class LineItemVM : BaseVM
|
|
{
|
|
public ushort Position { get; private set; }
|
|
public ushort Amount { get; internal set; }
|
|
public string ProductNumber { get; private set; }
|
|
public string OptionNumber { get; private set; }
|
|
public string SapShortDescription { get; private set; }
|
|
public CustomDescriptionVM CustomDescription { get; private set; }
|
|
public string ProductLine { get; private set; }
|
|
public decimal TotalDiscount { get; internal set; }
|
|
public decimal CalcNetPrice { get; private set; }
|
|
public decimal CalcTotalNet { get; private set; }
|
|
public decimal ListPrice { get; private set; }
|
|
|
|
internal static ObservableCollection<LineItemVM> ReadLineItemsFromClipboard ()
|
|
{
|
|
if (Clipboard.GetText() != "")
|
|
{
|
|
string clipboard = Clipboard.GetText();
|
|
|
|
//Zeilen aufteilen
|
|
IEnumerable<string> clipboardLines = clipboard.Split(Environment.NewLine.ToCharArray());
|
|
List<string[]> clipboardList = new();
|
|
|
|
foreach (string clipboardLine in clipboardLines)
|
|
{
|
|
if (clipboardLine != "")
|
|
{
|
|
//Nach Trennzeichen trennen
|
|
string[] clipboardLineSplit = clipboardLine.Split('\t');
|
|
clipboardList.Add(clipboardLineSplit);
|
|
}
|
|
}
|
|
|
|
return ParseClipboardList(clipboardList);
|
|
}
|
|
else
|
|
{
|
|
_ = MessageBox.Show("Clipboard ist leer!");
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public static ObservableCollection<LineItemVM> ParseClipboardList(IEnumerable<string[]> lineItemStrings)
|
|
{
|
|
ObservableCollection<LineItemVM> lineItems = new();
|
|
int countError = 0;
|
|
int countEmpty = 0;
|
|
|
|
foreach (string[] lineItemString in lineItemStrings)
|
|
{
|
|
//Anzahl an Spalten entspricht Clipboard
|
|
if (lineItemString.Length == 19)
|
|
{
|
|
//Header ignorieren
|
|
if (lineItemString[0] == "#")
|
|
{
|
|
countEmpty++;
|
|
continue;
|
|
}
|
|
|
|
//Dateiinhalt in Klasse schreiben
|
|
LineItemVM lineItem = new();
|
|
lineItem.Position = ushort.Parse(lineItemString[0]);
|
|
lineItem.ProductNumber = lineItemString[1];
|
|
lineItem.OptionNumber = lineItemString[2];
|
|
lineItem.ProductLine = lineItemString[3];
|
|
lineItem.SapShortDescription = lineItemString[4];
|
|
lineItem.Amount = ushort.Parse(lineItemString[5]);
|
|
lineItem.ListPrice = decimal.Parse(lineItemString[6]);
|
|
lineItem.TotalDiscount = decimal.Parse(lineItemString[9]);
|
|
|
|
//Preise einlesen
|
|
//lineItem.NetPrice = decimal.Parse(lineItemString[10]);
|
|
//lineItem.TotalNet = decimal.Parse(lineItemString[11]);
|
|
|
|
//Preise selbst berechnen
|
|
lineItem.CalcNetPrice = lineItem.ListPrice * (100 - lineItem.TotalDiscount) / 100;
|
|
lineItem.CalcTotalNet = lineItem.CalcNetPrice * lineItem.Amount;
|
|
|
|
//nicht genutzte Felder
|
|
//lineItem.SalesDiscount = decimal.Parse(lineItemString[12]);
|
|
//lineItem.ContractualDiscount = decimal.Parse(lineItemString[13]);
|
|
//lineItem.PromotionalDiscount = decimal.Parse(lineItemString[14]);
|
|
//lineItem.DemoDiscount = decimal.Parse(lineItemString[15]);
|
|
|
|
lineItem.CustomDescription = CustomDescriptionVM.GetCustomDescription(lineItem);
|
|
|
|
lineItems.Add(lineItem);
|
|
}
|
|
else
|
|
{
|
|
_ = MessageBox.Show("Angebot konnte nicht eingelesen werden!");
|
|
countError++;
|
|
continue;
|
|
}
|
|
}
|
|
return lineItems;
|
|
}
|
|
|
|
internal static decimal GetTotalNet(ObservableCollection<LineItemVM> lineItems)
|
|
{
|
|
decimal totalNet = 0;
|
|
foreach (LineItemVM lineItem in lineItems)
|
|
{
|
|
totalNet += lineItem.CalcNetPrice;
|
|
}
|
|
return totalNet;
|
|
}
|
|
|
|
internal static decimal GetTotalDiscount(ObservableCollection<LineItemVM> lineItems)
|
|
{
|
|
decimal totalDiscount = 0;
|
|
foreach (LineItemVM lineItem in lineItems)
|
|
{
|
|
totalDiscount += lineItem.TotalDiscount;
|
|
}
|
|
return totalDiscount;
|
|
}
|
|
|
|
internal static decimal GetTotalListprice(ObservableCollection<LineItemVM> lineItems)
|
|
{
|
|
decimal totalListprice = 0;
|
|
foreach (LineItemVM lineItem in lineItems)
|
|
{
|
|
totalListprice += lineItem.ListPrice;
|
|
}
|
|
return totalListprice;
|
|
}
|
|
}
|
|
}
|