@ -5,22 +5,22 @@ using Microsoft.VisualBasic.FileIO;
using MySqlConnector ;
using System ;
using System.Collections.Generic ;
using System.Diagnostics ;
using System.Data ;
using System.Globalization ;
using System.Linq ;
using System.Text ;
using System.Threading.Tasks ;
using System.Windows ;
using static Gremlin . GremlinData . EntityClasses . Enums ;
using Gremlin.GremlinUtilities ;
using Gremlin.GremlinData.EntityClasses ;
using static Gremlin . GremlinData . EntityClasses . Enums ;
namespace Gremlin.GremlinData.DBClasses
{
internal static class DbHelper
{
private static readonly DateTime FarInTheFuture = DateTime . Parse ( "2050-12-31t00:00:00.000000z" , CultureInfo . CurrentCulture ) ;
private static readonly ParallelOptions parallelOptions = new ( ) { MaxDegreeOfParallelism = Environment . ProcessorCount * 2 } ;
public static bool CheckDatabaseConnection ( string connectionString )
{
@ -115,7 +115,7 @@ namespace Gremlin.GremlinData.DBClasses
using ( GremlinContext db = new ( ) )
{
_ = db. ProductLines . Add ( PlToBeAdded ) ;
db. ProductLines . Add ( PlToBeAdded ) ;
db . SaveChanges ( ) ;
}
}
@ -1049,7 +1049,8 @@ namespace Gremlin.GremlinData.DBClasses
//Eingelesenen Contacts in DB schreiben:
using ( GremlinContext db = new ( ) )
{
DateTime now = DateTime . Now ;
DateTime now ;
now = DateTime . Now ;
foreach ( Contact contact in ContactsReadFromFile )
{
@ -1417,8 +1418,7 @@ namespace Gremlin.GremlinData.DBClasses
////Counter für Debugging
//int x = 0;
//Multithreading
_ = Parallel . ForEach ( NonNewProducts , parallelOptions , ( product ) = >
foreach ( Product product in NonNewProducts )
{
////Debugging-Counter
//x++;
@ -1433,7 +1433,7 @@ namespace Gremlin.GremlinData.DBClasses
if ( ExistingProduct = = null )
{
NewProducts . Add ( product ) ;
return ;
continue ;
}
//Wenn keine Änderung, dann nur DataVersionComment mit CPL-Dateinamen aktualisieren...
@ -1501,13 +1501,13 @@ namespace Gremlin.GremlinData.DBClasses
NewProducts . Add ( UpdatedProduct ) ;
}
UpdatedProducts . Add ( ExistingProduct ) ;
} ) ;
}
_ = InsertProducts ( NewProducts ) ; //enthält auch ResolvePL()
db . Products . UpdateRange ( ObsoleteProducts ) ;
db . Products . UpdateRange ( UpdatedProducts ) ;
int changes = db . SaveChanges ( ) ;
_ = MessageBox . Show ( $"Es wurden {changes} Änderungen an der Datenbank durchgeführt. \n Davon waren {UpdatedProducts.Count} UpdatedProducts, {ObsoleteProducts.Count} ObsoleteProducts und {NewProducts.Count} NewProducts ") ;
Debug. WriteLine ( $"Es wurden {changes} Änderungen an der Datenbank durchgeführt. ") ;
}
return true ;
@ -1952,10 +1952,10 @@ namespace Gremlin.GremlinData.DBClasses
{
try
{
AccountType accountType = context . AccountTypes
. Where ( a ccount = > a ccount . AccountTypeCode = = AccTypeCode )
AccountType query = context . AccountTypes
. Where ( a = > a . AccountTypeCode = = AccTypeCode )
. First ( ) ;
return accountType ;
return query ;
}
catch
{