From 3a2d6c257f742555c98a8d0d39489a57c5cd9d38 Mon Sep 17 00:00:00 2001 From: DJh2o2 Date: Mon, 14 Mar 2022 20:14:12 +0100 Subject: [PATCH] some minor optimizations of the interface --- .../GremlinData/DBClasses/GenericImporter.cs | 348 +++++++++--------- Gremlin/MVVM/Operations/TexHandler.cs | 2 +- Gremlin/MVVM/Views/QuoteView.xaml | 4 +- Gremlin/MVVM/Views/ShellView.xaml | 6 +- 4 files changed, 179 insertions(+), 181 deletions(-) diff --git a/Gremlin/GremlinData/DBClasses/GenericImporter.cs b/Gremlin/GremlinData/DBClasses/GenericImporter.cs index b8717ce..a7669fb 100644 --- a/Gremlin/GremlinData/DBClasses/GenericImporter.cs +++ b/Gremlin/GremlinData/DBClasses/GenericImporter.cs @@ -288,7 +288,7 @@ namespace Gremlin.GremlinData.DBClasses ImportProducts(mappingTable); break; case "CustomDescription": - ImportCustomDescriptions(mappingTable); + ImportCustomDescriptions();// mappingTable); break; default: return false; @@ -303,7 +303,7 @@ namespace Gremlin.GremlinData.DBClasses return ImportFile(); } - private static bool ImportCustomDescriptions(Dictionary mappingTable) + private static bool ImportCustomDescriptions()//Dictionary mappingTable) { List CDsReadFromFile = new(2500); Encoding = Encoding.GetEncoding("UTF-8"); //Custom-Descriptions-CSV hat festes Encoding. @@ -987,36 +987,36 @@ namespace Gremlin.GremlinData.DBClasses return true; } - private static void SetProperty(object gremlinEntity, PropertyInfo propertyInfo, string value) - { - propertyInfo.SetValue(gremlinEntity, value); - } + //private static void SetProperty(object gremlinEntity, PropertyInfo propertyInfo, string value) + //{ + // propertyInfo.SetValue(gremlinEntity, value); + //} - private static Array GetNewGremlinTypeArray(Assembly assembly, string detectedDataType, int length) - { - Type GremlinType = GetNewGremlinType(assembly, detectedDataType).GetType(); - //Create an one-dimensional array with n+1 or n+2 elements (n = number of datasets, plus heading and/or emptyline at EOF): - return Array.CreateInstance(GremlinType, length); + //private static Array GetNewGremlinTypeArray(Assembly assembly, string detectedDataType, int length) + //{ + // Type GremlinType = GetNewGremlinType(assembly, detectedDataType).GetType(); + // //Create an one-dimensional array with n+1 or n+2 elements (n = number of datasets, plus heading and/or emptyline at EOF): + // return Array.CreateInstance(GremlinType, length); - //Das geht alles nicht: - //List test = new(); - //List test = new(); - //List test = new(); + // //Das geht alles nicht: + // //List test = new(); + // //List test = new(); + // //List test = new(); - ////Das geht: - ////Create iList: - //Type listType = typeof(List<>).MakeGenericType(GremlinType); - //var list = (IList)Activator.CreateInstance(listType); - //list.Add(new Account() { AccountName = "Test" }); - //list.Add(GremlinClassObject); + // ////Das geht: + // ////Create iList: + // //Type listType = typeof(List<>).MakeGenericType(GremlinType); + // //var list = (IList)Activator.CreateInstance(listType); + // //list.Add(new Account() { AccountName = "Test" }); + // //list.Add(GremlinClassObject); - } + //} - private static object GetNewGremlinType(Assembly Gremlin, string detectedDataType) - { - return Activator.CreateInstance(Gremlin.ToString(), "Gremlin." + detectedDataType).Unwrap(); - } + //private static object GetNewGremlinType(Assembly Gremlin, string detectedDataType) + //{ + // return Activator.CreateInstance(Gremlin.ToString(), "Gremlin." + detectedDataType).Unwrap(); + //} public static Dictionary ReadMappingDictionaryFromFile() { @@ -1053,171 +1053,171 @@ namespace Gremlin.GremlinData.DBClasses return result; } - private static void BasimodosCodeDump() - { - //Unfertiger, generischer Code aus der ImportFile() Methode. - //Aufbewahren für später, wenn Zeit ist, das ordentlich zu machen. + //private static void BasimodosCodeDump() + //{ + // //Unfertiger, generischer Code aus der ImportFile() Methode. + // //Aufbewahren für später, wenn Zeit ist, das ordentlich zu machen. - //while (!csvParser.EndOfData) - //{ - // //read - // //new data instance - // //convert - // //validate - // //set metadata: SetMetadataForImport(IMetadata) - // //add to list + // //while (!csvParser.EndOfData) + // //{ + // // //read + // // //new data instance + // // //convert + // // //validate + // // //set metadata: SetMetadataForImport(IMetadata) + // // //add to list - // fields = csvParser.ReadFields(); // Read current line fields, pointer moves to the next line. - // if (fields[0] == "") break; // Am Ende hängt eine leere Zeile, die im Parser einen Fehler auslösen würde. + // // fields = csvParser.ReadFields(); // Read current line fields, pointer moves to the next line. + // // if (fields[0] == "") break; // Am Ende hängt eine leere Zeile, die im Parser einen Fehler auslösen würde. - // //TO DO: vor der foreach "Account" bevorzugt behandeln (Sonderfall bei LSAG: Liste deduplizieren, und als erstes importieren, da sonst keine Contacts importiert werden können). + // // //TO DO: vor der foreach "Account" bevorzugt behandeln (Sonderfall bei LSAG: Liste deduplizieren, und als erstes importieren, da sonst keine Contacts importiert werden können). - // foreach (string detectedDataType in detectedDataTypes) - // { - // //"Account" überspringen, da das vor der foreach schon verarbeitet worden ist. - // if (detectedDataType == "Account") continue; + // // foreach (string detectedDataType in detectedDataTypes) + // // { + // // //"Account" überspringen, da das vor der foreach schon verarbeitet worden ist. + // // if (detectedDataType == "Account") continue; - // Array GremlinTypeArray = GetNewGremlinTypeArray(Gremlin, detectedDataType, numberOfLines); - // Type GremlinType = GetNewGremlinType(Gremlin, detectedDataType).GetType(); - // PropertyInfo[] GremlinTypeProperties = GremlinType.GetProperties(); + // // Array GremlinTypeArray = GetNewGremlinTypeArray(Gremlin, detectedDataType, numberOfLines); + // // Type GremlinType = GetNewGremlinType(Gremlin, detectedDataType).GetType(); + // // PropertyInfo[] GremlinTypeProperties = GremlinType.GetProperties(); - // foreach (PropertyInfo property in GremlinTypeProperties) - // { - // if (mappingTable.TryGetValue(property.Name, out int columnNumber)) - // { - // //convert: - // GremlinTypeConverter.Convert(fields[columnNumber]); - // } - // } - // } + // // foreach (PropertyInfo property in GremlinTypeProperties) + // // { + // // if (mappingTable.TryGetValue(property.Name, out int columnNumber)) + // // { + // // //convert: + // // GremlinTypeConverter.Convert(fields[columnNumber]); + // // } + // // } + // // } - //} + // //} - //using (GremlinContext db = new()) - //{ - // //add to context - // //savechanges - //} - } + // //using (GremlinContext db = new()) + // //{ + // // //add to context + // // //savechanges + // //} + //} //######################################################################################### //Kann gelöscht werden, sobald die generische Funktion zuverlässig funktioniert: //######################################################################################### - private static string RecognizeDataStatic(Dictionary mappingDictionary) - { - //Logik zur Kategorisierung des Datensatzes: - //Alle verpflichtenden Angaben zu einer Klasse vorhanen? - //Alle vom Importer erwarteten Angaben vorhanden? - //Bei den Enums zusätzlich noch proüfem, dass nur zwei Spalten vorhanden sind, sonst könnten LSAG-Daten falsch identifiziert werden. - // - // - - //Products - if (//required by DB: - mappingDictionary.ContainsKey("ProductNumber") - && mappingDictionary.ContainsKey("ListPrice") - //required by importer: - && mappingDictionary.ContainsKey("Weight") - //unique identifier: - && mappingDictionary.ContainsKey("BreakRangeFrom") - ) - { - return "Product"; - } - - //LSAG Contact List Tool List - if (//required by DB: - mappingDictionary.ContainsKey("SAPAccountNumber") - && mappingDictionary.ContainsKey("SAPContactNumber") - && mappingDictionary.ContainsKey("AccountTypeCode") - && mappingDictionary.ContainsKey("SubMarketCode") - && mappingDictionary.ContainsKey("LastName") - && mappingDictionary.ContainsKey("AccountName") - //required by importer: - - //unique identifier: - && mappingDictionary.ContainsKey("MA_ProductInterests") - ) - { - return "LSAG Contact List Tool List"; - } - - //Accounts - if (//required by DB: - mappingDictionary.ContainsKey("AccountName") - && mappingDictionary.ContainsKey("Street") - && mappingDictionary.ContainsKey("ZIP") - && mappingDictionary.ContainsKey("City") - && mappingDictionary.ContainsKey("PhoneNumber") - && mappingDictionary.ContainsKey("SAPAccountNumber") - && mappingDictionary.ContainsKey("AccountCreatedInSAPOn") - && mappingDictionary.ContainsKey("AccountTypeCode") - && mappingDictionary.ContainsKey("SubMarketCode") - //required by importer: - ) - { - return "Account"; - } - - //Contacts - if (//required by DB: - mappingDictionary.ContainsKey("LastName") - && mappingDictionary.ContainsKey("SAPContactNumber") - //required by importer: - && mappingDictionary.ContainsKey("FirstName") - && mappingDictionary.ContainsKey("Gender") - ) - { - return "Contact"; - } - - //Custom Description - if (//required by DB: - mappingDictionary.ContainsKey("Heading") - //required by importer: - && mappingDictionary.ContainsKey("ProductNumber") - && mappingDictionary.ContainsKey("OptionNumber") - && mappingDictionary.ContainsKey("DescriptionText") - //unique identifier: - && mappingDictionary.ContainsKey("CoverletterText") - ) - { - return "CustomDescription"; - } - - - //Pseudo-Enums AccountTypes, SubMarkets, ProductLines for DB-initializing - if (mappingDictionary.Count == 2) - { - if (mappingDictionary.ContainsKey("AccountTypeCode") - && mappingDictionary.ContainsKey("AccountTypeDescription") - && mappingDictionary.Count == 2) - { - return "AccountType"; - } - - if (mappingDictionary.ContainsKey("SubMarketCode") - && mappingDictionary.ContainsKey("SubMarketDescription") - && mappingDictionary.Count == 2) - { - return "SubMarket"; - } - - if (mappingDictionary.ContainsKey("ProductLineCode") - && mappingDictionary.ContainsKey("ProductLineDescription") - && mappingDictionary.Count == 2) - { - return "ProductLine"; - } - } - - return "No entity type unambigiously identified!"; + //private static string RecognizeDataStatic(Dictionary mappingDictionary) + //{ + // //Logik zur Kategorisierung des Datensatzes: + // //Alle verpflichtenden Angaben zu einer Klasse vorhanen? + // //Alle vom Importer erwarteten Angaben vorhanden? + // //Bei den Enums zusätzlich noch proüfem, dass nur zwei Spalten vorhanden sind, sonst könnten LSAG-Daten falsch identifiziert werden. + // // + // // + + // //Products + // if (//required by DB: + // mappingDictionary.ContainsKey("ProductNumber") + // && mappingDictionary.ContainsKey("ListPrice") + // //required by importer: + // && mappingDictionary.ContainsKey("Weight") + // //unique identifier: + // && mappingDictionary.ContainsKey("BreakRangeFrom") + // ) + // { + // return "Product"; + // } + + // //LSAG Contact List Tool List + // if (//required by DB: + // mappingDictionary.ContainsKey("SAPAccountNumber") + // && mappingDictionary.ContainsKey("SAPContactNumber") + // && mappingDictionary.ContainsKey("AccountTypeCode") + // && mappingDictionary.ContainsKey("SubMarketCode") + // && mappingDictionary.ContainsKey("LastName") + // && mappingDictionary.ContainsKey("AccountName") + // //required by importer: + + // //unique identifier: + // && mappingDictionary.ContainsKey("MA_ProductInterests") + // ) + // { + // return "LSAG Contact List Tool List"; + // } + + // //Accounts + // if (//required by DB: + // mappingDictionary.ContainsKey("AccountName") + // && mappingDictionary.ContainsKey("Street") + // && mappingDictionary.ContainsKey("ZIP") + // && mappingDictionary.ContainsKey("City") + // && mappingDictionary.ContainsKey("PhoneNumber") + // && mappingDictionary.ContainsKey("SAPAccountNumber") + // && mappingDictionary.ContainsKey("AccountCreatedInSAPOn") + // && mappingDictionary.ContainsKey("AccountTypeCode") + // && mappingDictionary.ContainsKey("SubMarketCode") + // //required by importer: + // ) + // { + // return "Account"; + // } + + // //Contacts + // if (//required by DB: + // mappingDictionary.ContainsKey("LastName") + // && mappingDictionary.ContainsKey("SAPContactNumber") + // //required by importer: + // && mappingDictionary.ContainsKey("FirstName") + // && mappingDictionary.ContainsKey("Gender") + // ) + // { + // return "Contact"; + // } + + // //Custom Description + // if (//required by DB: + // mappingDictionary.ContainsKey("Heading") + // //required by importer: + // && mappingDictionary.ContainsKey("ProductNumber") + // && mappingDictionary.ContainsKey("OptionNumber") + // && mappingDictionary.ContainsKey("DescriptionText") + // //unique identifier: + // && mappingDictionary.ContainsKey("CoverletterText") + // ) + // { + // return "CustomDescription"; + // } + + + // //Pseudo-Enums AccountTypes, SubMarkets, ProductLines for DB-initializing + // if (mappingDictionary.Count == 2) + // { + // if (mappingDictionary.ContainsKey("AccountTypeCode") + // && mappingDictionary.ContainsKey("AccountTypeDescription") + // && mappingDictionary.Count == 2) + // { + // return "AccountType"; + // } + + // if (mappingDictionary.ContainsKey("SubMarketCode") + // && mappingDictionary.ContainsKey("SubMarketDescription") + // && mappingDictionary.Count == 2) + // { + // return "SubMarket"; + // } + + // if (mappingDictionary.ContainsKey("ProductLineCode") + // && mappingDictionary.ContainsKey("ProductLineDescription") + // && mappingDictionary.Count == 2) + // { + // return "ProductLine"; + // } + // } + + // return "No entity type unambigiously identified!"; - } + //} } } diff --git a/Gremlin/MVVM/Operations/TexHandler.cs b/Gremlin/MVVM/Operations/TexHandler.cs index 622c796..91b51d2 100644 --- a/Gremlin/MVVM/Operations/TexHandler.cs +++ b/Gremlin/MVVM/Operations/TexHandler.cs @@ -26,7 +26,7 @@ namespace Gremlin.MVVM private static void WriteTextToFile(StringBuilder texFile, string datei) { - using (StreamWriter writer = new(datei, false, Encoding.UTF8)) + using StreamWriter writer = new(datei, false, Encoding.UTF8); { writer.WriteLine(texFile.ToString()); } diff --git a/Gremlin/MVVM/Views/QuoteView.xaml b/Gremlin/MVVM/Views/QuoteView.xaml index 53ea773..f2b3169 100644 --- a/Gremlin/MVVM/Views/QuoteView.xaml +++ b/Gremlin/MVVM/Views/QuoteView.xaml @@ -96,8 +96,8 @@ x:Name="LineItemsVM" AutoGenerateColumns="True" CanUserAddRows="False" - Height="300" - Width ="1280" + MinHeight="300" + MaxHeight="600" Margin="10,5,10,5" AlternatingRowBackground="LightGray" /> diff --git a/Gremlin/MVVM/Views/ShellView.xaml b/Gremlin/MVVM/Views/ShellView.xaml index 18314d2..a9765ae 100644 --- a/Gremlin/MVVM/Views/ShellView.xaml +++ b/Gremlin/MVVM/Views/ShellView.xaml @@ -2,7 +2,7 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:cal="http://www.caliburnproject.org" - xmlns:local="clr-namespace:Gremlin.MVVM" xmlns:local1="clr-namespace:Gremlin.MVVM.Views"> + xmlns:local="clr-namespace:Gremlin.MVVM"> + Margin="10,5,10,5"/>