133 lines
4.6 KiB
C#
133 lines
4.6 KiB
C#
|
|
// FÜR ORIGINAL, SIEHE UNTEN
|
|
|
|
// HIER STEHT MEINE LÖSUNG, DIE NICHT GANZ DER AUFGABENSTELLUNG ENTSPRICHT:
|
|
|
|
using System.Reflection;
|
|
using System.Xml.Serialization;
|
|
using Aufgabe11;
|
|
|
|
|
|
public class Program
|
|
{
|
|
public static void Main()
|
|
{
|
|
Console.WriteLine("Willkommen zu Aufgabe11");
|
|
|
|
SalesRepresentativeRepository repo1 = new SalesRepresentativeRepository();
|
|
|
|
TabelleErstellen("GetSalesRepsFromBadenWuerttembergNew",
|
|
repo1.GetSalesRepsFromBadenWuerttembergNew, getAllSalesRepresentatives());
|
|
TabelleErstellen("GetSalesRepsGroupedByCompanyNew",
|
|
repo1.GetSalesRepsGroupedByCompanyNew, getAllSalesRepresentatives());
|
|
TabelleErstellen("GetTopTenLosersNew",
|
|
repo1.GetTopTenLosersNew, getAllSalesRepresentatives());
|
|
}
|
|
|
|
public static List<SalesRepresentative> getAllSalesRepresentatives()
|
|
{
|
|
List<SalesRepresentative> allRepresentatives;
|
|
XmlSerializer serializer = new XmlSerializer(typeof(List<SalesRepresentative>));
|
|
|
|
using (var stream = new FileStream(@".\vertreter.xml", FileMode.Open))
|
|
{
|
|
allRepresentatives = (List<SalesRepresentative>)serializer.Deserialize(stream);
|
|
}
|
|
|
|
return allRepresentatives;
|
|
}
|
|
|
|
public static void TabelleErstellen(string ueberschrift, Func<List<SalesRepresentative>,
|
|
List<SalesRepresentative>> funktion, List<SalesRepresentative> daten)
|
|
{
|
|
var results = funktion(daten);
|
|
Console.WriteLine($"\n\n{ueberschrift}\n");
|
|
|
|
const int abstand = 23;
|
|
int zaehler = 0;
|
|
List<PropertyInfo> allPropertyInfos = new List<PropertyInfo>();
|
|
|
|
if (results.Count > 0)
|
|
{
|
|
foreach (PropertyInfo property in results[0].GetType().GetProperties())
|
|
{
|
|
Console.Write(property.Name.PadRight(abstand));
|
|
allPropertyInfos.Add(property);
|
|
zaehler++;
|
|
}
|
|
|
|
Console.WriteLine();
|
|
Console.WriteLine(new string('-', zaehler * abstand));
|
|
|
|
foreach (SalesRepresentative representative in results)
|
|
{
|
|
foreach (PropertyInfo property in allPropertyInfos)
|
|
{
|
|
Console.Write((property.GetValue(representative)?.ToString() ?? "NULL").PadRight(abstand));
|
|
}
|
|
|
|
Console.WriteLine();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Console.WriteLine("Es sind keine Elemente vorhanden");
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// EINFACH DIE KOMMENTIERUNG UNKEHREN UM DIE ORIGINALLÖSUNG ZU SEHEN
|
|
// KOMMENTIERT -> NICHT KOMMENTIERT / NICHT KOMMENTIERT -> KOMMENTIERT
|
|
|
|
// AB HIER STEHT DER CODE FÜR DIE AUFGABE:
|
|
|
|
|
|
/*
|
|
using System.Xml.Serialization;
|
|
using Aufgabe11;
|
|
|
|
|
|
Console.WriteLine("Willkommen zu Augfgabe11");
|
|
|
|
List<SalesRepresentative> allRepresentatives;
|
|
XmlSerializer serializer = new XmlSerializer(typeof(List<SalesRepresentative>));
|
|
using (var stream = new FileStream(@".\vertreter.xml", FileMode.Open))
|
|
{
|
|
allRepresentatives = (List<SalesRepresentative>)serializer.Deserialize(stream);
|
|
}
|
|
SalesRepresentativeRepository repo1 = new SalesRepresentativeRepository();
|
|
|
|
|
|
Console.WriteLine("\n GetSalesRepsFromBadenWuerttemberg: ");
|
|
foreach ((string FirstName, string LastName, string Company, decimal SalesVolume) representative in repo1
|
|
.GetSalesRepsFromBadenWuerttemberg(allRepresentatives))
|
|
{
|
|
Console.WriteLine($"Vorname: {representative.FirstName}" +
|
|
$"Nachname: {representative.LastName}" +
|
|
$"Firma: {representative.Company}" +
|
|
$"Umsatz: {representative.SalesVolume}");
|
|
}
|
|
|
|
Console.WriteLine("\n GetSalesRepsGroupedByCompany: ");
|
|
foreach ((string FirstName, string LastName, string Company, string Area, decimal SalesVolume) representative in repo1
|
|
.GetSalesRepsGroupedByCompany(allRepresentatives))
|
|
{
|
|
Console.WriteLine($"Vorname: {representative.FirstName}" +
|
|
$"Nachname: {representative.LastName}" +
|
|
$"Firma: {representative.Company}" +
|
|
$"Gebiet: {representative.Area}" +
|
|
$"Umsatz: {representative.SalesVolume}");
|
|
}
|
|
|
|
Console.WriteLine("\n GetTopTenLosers: ");
|
|
foreach ((string FirstName, string LastName, string Company, string Area, decimal SalesVolume) representative in repo1.GetTopTenLosers(allRepresentatives))
|
|
{
|
|
Console.WriteLine($"Vorname: {representative.FirstName}" +
|
|
$"Nachname: {representative.LastName}" +
|
|
$"Firma: {representative.Company}" +
|
|
$"Gebiet: {representative.Area}" +
|
|
$"Umsatz: {representative.SalesVolume}");
|
|
}
|
|
*/ |