152 lines
6.7 KiB
C#
152 lines
6.7 KiB
C#
using Caliburn.Micro;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.Windows;
|
|
|
|
namespace Gremlin.MVVM
|
|
{
|
|
public class LineItemViewModel : PropertyChangedBase
|
|
{
|
|
private ushort _position;
|
|
private ushort _amount;
|
|
private string _productNumber;
|
|
private string _optionNumber;
|
|
private string _sapShortDescription;
|
|
private CustomDescriptionViewModel _customDescriptionVM;
|
|
private string _productLine;
|
|
private decimal _totalDiscount;
|
|
private decimal _calcNetPrice;
|
|
private decimal _calcTotalNet;
|
|
private decimal _listPrice;
|
|
|
|
public ushort Position { get => _position; internal set { _position = value; NotifyOfPropertyChange(() => Position); } }
|
|
public ushort Amount { get => _amount; internal set { _amount = value; NotifyOfPropertyChange(() => Amount); } }
|
|
public string ProductNumber { get => _productNumber; internal set { _productNumber = value; NotifyOfPropertyChange(() => ProductNumber); }}
|
|
public string OptionNumber { get => _optionNumber; internal set { _optionNumber = value; NotifyOfPropertyChange(() => OptionNumber); }}
|
|
public string SapShortDescription { get => _sapShortDescription; internal set { _sapShortDescription = value; NotifyOfPropertyChange(() => SapShortDescription); }}
|
|
public CustomDescriptionViewModel CustomDescriptionVM { get => _customDescriptionVM; internal set { _customDescriptionVM = value; NotifyOfPropertyChange(() => CustomDescriptionVM); }}
|
|
public string ProductLine { get => _productLine; internal set { _productLine = value; NotifyOfPropertyChange(() => ProductLine); }}
|
|
public decimal TotalDiscount { get => _totalDiscount; internal set { _totalDiscount = value; NotifyOfPropertyChange(() => TotalDiscount); }}
|
|
public decimal CalcNetPrice { get => _calcNetPrice; internal set { _calcNetPrice = value; NotifyOfPropertyChange(() => CalcNetPrice); }}
|
|
public decimal CalcTotalNet { get => _calcTotalNet; internal set { _calcTotalNet = value; NotifyOfPropertyChange(() => CalcTotalNet); }}
|
|
public decimal ListPrice { get => _listPrice; internal set { _listPrice = value; NotifyOfPropertyChange(() => ListPrice); }}
|
|
|
|
internal static ObservableCollection<LineItemViewModel> 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<LineItemViewModel> ParseClipboardList(IEnumerable<string[]> lineItemStrings)
|
|
{
|
|
ObservableCollection<LineItemViewModel> 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
|
|
LineItemViewModel 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.CustomDescriptionVM = CustomDescriptionViewModel.GetCustomDescription(lineItem);
|
|
|
|
lineItems.Add(lineItem);
|
|
}
|
|
else
|
|
{
|
|
_ = MessageBox.Show("Angebot konnte nicht eingelesen werden!");
|
|
countError++;
|
|
continue;
|
|
}
|
|
}
|
|
return lineItems;
|
|
}
|
|
|
|
internal static decimal GetTotalNet(ObservableCollection<LineItemViewModel> lineItems)
|
|
{
|
|
decimal totalNet = 0;
|
|
foreach (LineItemViewModel lineItem in lineItems)
|
|
{
|
|
totalNet += lineItem.CalcNetPrice;
|
|
}
|
|
return totalNet;
|
|
}
|
|
|
|
internal static decimal GetTotalDiscount(ObservableCollection<LineItemViewModel> lineItems)
|
|
{
|
|
decimal totalDiscount = 0;
|
|
foreach (LineItemViewModel lineItem in lineItems)
|
|
{
|
|
totalDiscount += lineItem.TotalDiscount;
|
|
}
|
|
return totalDiscount;
|
|
}
|
|
|
|
internal static decimal GetTotalListprice(ObservableCollection<LineItemViewModel> lineItems)
|
|
{
|
|
decimal totalListprice = 0;
|
|
foreach (LineItemViewModel lineItem in lineItems)
|
|
{
|
|
totalListprice += lineItem.ListPrice;
|
|
}
|
|
return totalListprice;
|
|
}
|
|
}
|
|
}
|