|
|
|
|
@ -514,7 +514,7 @@ namespace Gremlin.GremlinData.DBClasses
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static bool ImportContactsFromCSV(string filepath = "", string separator = ";", bool dataHasHeading = true)
|
|
|
|
|
public static bool ImportContactsFromCsv(string filepath = "", string separator = ";", bool dataHasHeading = true)
|
|
|
|
|
{
|
|
|
|
|
//Pfad abfragen über Dtei-Öffnen-Dialog:
|
|
|
|
|
if (filepath == "") filepath = FileHelper.GetFilepathFromUser();
|
|
|
|
|
@ -636,7 +636,7 @@ namespace Gremlin.GremlinData.DBClasses
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static bool ImportAccountsFromCSV(string filepath = "", string separator = ";", bool dataHasHeading = true)
|
|
|
|
|
public static bool ImportAccountsFromCsv(string filepath = "", string separator = ";", bool dataHasHeading = true)
|
|
|
|
|
///Importiert Account Daten aus CSV (erstellt aus LSAG_Contact_List_Tool.xlsx)
|
|
|
|
|
///
|
|
|
|
|
/// - Encoding: Latin1
|
|
|
|
|
@ -1072,7 +1072,7 @@ namespace Gremlin.GremlinData.DBClasses
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static bool ImportProductsFromCSV(string filepath = "", string separator = "|", bool dataHasHeading = true)
|
|
|
|
|
public static bool ImportProductsFromCsv(string filepath = "", string separator = "|", bool dataHasHeading = true)
|
|
|
|
|
///Rückgabe 'false' bei Fehler oder User-Abbruch, ansonsten 'true'.
|
|
|
|
|
///
|
|
|
|
|
///Optionale Argumente:
|
|
|
|
|
@ -1369,7 +1369,7 @@ namespace Gremlin.GremlinData.DBClasses
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static bool UpdateProductsFromCSV(string filepath = "", string separator = "|", bool dataHasHeading = true)
|
|
|
|
|
public static bool UpdateProductsFromCsv(string filepath = "", string separator = "|", bool dataHasHeading = true)
|
|
|
|
|
{
|
|
|
|
|
if (filepath == "") filepath = FileHelper.GetFilepathFromUser(); //Pfad abfragen über Dtei-Öffnen-Dialog.
|
|
|
|
|
string fileName = ExtractFileName(filepath);
|
|
|
|
|
@ -1896,19 +1896,19 @@ namespace Gremlin.GremlinData.DBClasses
|
|
|
|
|
return await Task.Run(() => ImportLSAGContactListToolData());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static async Task<bool> ImportAccountsFromCSVAsync()
|
|
|
|
|
public static async Task<bool> ImportAccountsFromCsvAsync()
|
|
|
|
|
{
|
|
|
|
|
return await Task.Run(() => ImportAccountsFromCSV());
|
|
|
|
|
return await Task.Run(() => ImportAccountsFromCsv());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static async Task<bool> ImportContactsFromCSVAsync()
|
|
|
|
|
public static async Task<bool> ImportContactsFromCsvAsync()
|
|
|
|
|
{
|
|
|
|
|
return await Task.Run(() => ImportContactsFromCSV());
|
|
|
|
|
return await Task.Run(() => ImportContactsFromCsv());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static async Task<bool> ImportProductsFromCSVAsync()
|
|
|
|
|
public static async Task<bool> ImportProductsFromCsvAsync()
|
|
|
|
|
{
|
|
|
|
|
return await Task.Run(() => ImportProductsFromCSV());
|
|
|
|
|
return await Task.Run(() => ImportProductsFromCsv());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static async Task<bool> ImportCustomDescriptionsFromDocxAsync()
|
|
|
|
|
@ -1920,6 +1920,10 @@ namespace Gremlin.GremlinData.DBClasses
|
|
|
|
|
{
|
|
|
|
|
return await Task.Run(() => ImportCustomDescriptionsFromCsv());
|
|
|
|
|
}
|
|
|
|
|
public static async Task<bool> UpdateProductsFromCsvAsync()
|
|
|
|
|
{
|
|
|
|
|
return await Task.Run(() => UpdateProductsFromCsv());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Account ResolveAccountByName(GremlinContext context, string AccName)
|
|
|
|
|
{
|
|
|
|
|
@ -1940,7 +1944,7 @@ namespace Gremlin.GremlinData.DBClasses
|
|
|
|
|
|
|
|
|
|
public static Account ResolveAccountById(GremlinContext context, uint accountId)
|
|
|
|
|
{
|
|
|
|
|
try { return context.Accounts.Where(account => account.AccountId == accountId).First(); }
|
|
|
|
|
try { return context.Accounts.Where(account => account.SAPAccountNumber == accountId).First(); }
|
|
|
|
|
catch { return null; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -2027,112 +2031,6 @@ namespace Gremlin.GremlinData.DBClasses
|
|
|
|
|
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
|
|
|
return new string(Enumerable.Repeat(chars, length).Select(s => s[random.Next(s.Length)]).ToArray());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void InsertTestDataIntoDB()
|
|
|
|
|
{
|
|
|
|
|
using (GremlinContext db = new())
|
|
|
|
|
{
|
|
|
|
|
DateTime now;
|
|
|
|
|
now = DateTime.Now;
|
|
|
|
|
|
|
|
|
|
Random r = new();
|
|
|
|
|
|
|
|
|
|
Contact newContact = new()
|
|
|
|
|
{
|
|
|
|
|
AcademicTitle = RandomString(9),
|
|
|
|
|
FirstName = RandomString(5),
|
|
|
|
|
LastName = RandomString(20),
|
|
|
|
|
Gender = (byte)Gender.Male,
|
|
|
|
|
Department = RandomString(9),
|
|
|
|
|
DataStatus = Status.Active.ToString(),
|
|
|
|
|
DataModificationByUser = "Tester",
|
|
|
|
|
DataCreationDate = now,
|
|
|
|
|
DataModificationDate = now,
|
|
|
|
|
DataValidFrom = now,
|
|
|
|
|
DataValidUntil = FarInTheFuture,
|
|
|
|
|
DataVersionNumber = 1,
|
|
|
|
|
DataVersionComment = "Seeding data for testing.",
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Account newAccount = new()
|
|
|
|
|
{
|
|
|
|
|
AccountName = RandomString(20),
|
|
|
|
|
Street = RandomString(9),
|
|
|
|
|
ZIP = Convert.ToUInt32(r.Next(11111, 99999)),
|
|
|
|
|
City = RandomString(9),
|
|
|
|
|
SAPAccountNumber = Convert.ToUInt32(r.Next(1111111, 99999999)),
|
|
|
|
|
EMail = RandomString(9) + "@" + RandomString(9) + "." + RandomString(3),
|
|
|
|
|
PhoneNumber = "+49 " + r.Next().ToString(),
|
|
|
|
|
DataStatus = Status.Active.ToString(),
|
|
|
|
|
DataModificationByUser = "Tester",
|
|
|
|
|
DataCreationDate = now,
|
|
|
|
|
DataModificationDate = now,
|
|
|
|
|
DataValidFrom = now,
|
|
|
|
|
DataValidUntil = FarInTheFuture,
|
|
|
|
|
DataVersionNumber = 1,
|
|
|
|
|
DataVersionComment = "Seeding data for testing.",
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
AccountType accountType = db.AccountTypes
|
|
|
|
|
.Where(a => a.AccountTypeCode == "FPC")
|
|
|
|
|
.FirstOrDefault();
|
|
|
|
|
newAccount.AccountType = accountType;
|
|
|
|
|
|
|
|
|
|
SubMarket subMarket = db.SubMarkets
|
|
|
|
|
.Where(a => a.SubMarketCode == "CEN")
|
|
|
|
|
.First();
|
|
|
|
|
newAccount.SubMarket = subMarket;
|
|
|
|
|
newContact.Account = newAccount;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_ = db.Add(newAccount);
|
|
|
|
|
_ = db.SaveChanges();
|
|
|
|
|
_ = db.Add(newContact);
|
|
|
|
|
_ = db.SaveChanges();
|
|
|
|
|
_ = MessageBox.Show($"Account {newAccount.AccountName} mit Contact {newContact.LastName} wurde angelegt.");
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
ErrorHandler.ShowErrorInMessageBox(ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static bool InsertProducts(List<Product> products)
|
|
|
|
|
{
|
|
|
|
|
using (GremlinContext db = new())
|
|
|
|
|
{
|
|
|
|
|
DateTime now;
|
|
|
|
|
now = DateTime.Now;
|
|
|
|
|
List<ProductLine> productLines = db.ProductLines.ToList();
|
|
|
|
|
foreach (Product product in products)
|
|
|
|
|
{
|
|
|
|
|
//var query = db.ProductLines
|
|
|
|
|
// .Where(a => a.ProductLineAbbreviation == product.ProductLine.ProductLineAbbreviation)
|
|
|
|
|
// .First();
|
|
|
|
|
//product.ProductLine = query;
|
|
|
|
|
|
|
|
|
|
//product.ProductLine = ResolveProductLine(db, product.ProductLine.ProductLineAbbreviation);
|
|
|
|
|
product.ProductLine = productLines.Find(x => x.ProductLineAbbreviation == product.ProductLine.ProductLineAbbreviation);
|
|
|
|
|
|
|
|
|
|
product.DataValidFrom = now;
|
|
|
|
|
product.DataValidUntil = FarInTheFuture;
|
|
|
|
|
product.DataVersionNumber = 1;
|
|
|
|
|
product.DataVersionComment = "Initial import by CSV Importer (Function DbHelper.ImportProductsFromCSV)";
|
|
|
|
|
product.DataCreationDate = now;
|
|
|
|
|
product.DataModificationDate = now;
|
|
|
|
|
product.DataModificationByUser = "CSVImporter";
|
|
|
|
|
product.DataStatus = Status.Active.ToString();
|
|
|
|
|
product.DataModificationByUser = "CSVImporter";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
db.Products.AddRange(products);
|
|
|
|
|
_ = db.SaveChanges();
|
|
|
|
|
//Bestätigung senden
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class ProductEqualityComparer : IEqualityComparer<Product>
|
|
|
|
|
|