diff --git a/GWMS.Data/Controllers/GWMSController.cs b/GWMS.Data/Controllers/GWMSController.cs index cf55a19..dbbb2c2 100644 --- a/GWMS.Data/Controllers/GWMSController.cs +++ b/GWMS.Data/Controllers/GWMSController.cs @@ -15,7 +15,6 @@ namespace GWMS.Data.Controllers #region Private Fields private static IConfiguration _configuration; - private static GWMSContext dbCtx; private static NLog.Logger Log = LogManager.GetCurrentClassLogger(); #endregion Private Fields @@ -25,8 +24,6 @@ namespace GWMS.Data.Controllers public GWMSController(IConfiguration configuration) { _configuration = configuration; - dbCtx = new GWMSContext(configuration); - //Log.Info("Avviata classe GWMSController"); } #endregion Public Constructors @@ -49,14 +46,17 @@ namespace GWMS.Data.Controllers public bool DbForceMigrate() { bool answ = false; - try + using (GWMSContext localDbCtx = new GWMSContext(_configuration)) { - dbCtx.DbForceMigrate(); - answ = true; - } - catch (Exception exc) - { - Log.Error($"Eccezione in DbForceMigrate"); + try + { + localDbCtx.DbForceMigrate(); + answ = true; + } + catch (Exception exc) + { + Log.Error($"Eccezione in DbForceMigrate"); + } } return answ; } @@ -64,25 +64,30 @@ namespace GWMS.Data.Controllers public void Dispose() { // Clear database context - dbCtx.Dispose(); //Log.Info("Dispose di GWMSController"); } public List GetConfig() { - var dbResult = dbCtx + List dbResult = new List(); + using (GWMSContext localDbCtx = new GWMSContext(_configuration)) + { + dbResult = localDbCtx .DbSetConfig .ToList(); - + } return dbResult; } public List GetItems() { - var dbResult = dbCtx + List dbResult = new List(); + using (GWMSContext localDbCtx = new GWMSContext(_configuration)) + { + dbResult = localDbCtx .DbSetItems .ToList(); - + } return dbResult; } @@ -120,7 +125,10 @@ namespace GWMS.Data.Controllers public List GetOrdersFilt(int PlantId, int SupplierId, int TransporterId, DateTime DtStart, DateTime DtEnd, bool ShowClosed) { - var dbResult = dbCtx + List dbResult = new List(); + using (GWMSContext localDbCtx = new GWMSContext(_configuration)) + { + dbResult = localDbCtx .DbSetOrders .Where(x => (x.PlantId == PlantId || PlantId == 0) && (x.SupplierId == SupplierId || SupplierId == 0) && (x.TransporterId == TransporterId || TransporterId == 0) && (x.DtOrder >= DtStart && x.DtOrder <= DtEnd) && (x.ExecutionQty == 0 || ShowClosed)) .Include(p => p.Plant) @@ -128,13 +136,16 @@ namespace GWMS.Data.Controllers .Include(t => t.Transporter) .OrderByDescending(x => x.DtOrder) .ToList(); - + } return dbResult; } public List GetOrdersOpen(int PlantId) { - var dbResult = dbCtx + List dbResult = new List(); + using (GWMSContext localDbCtx = new GWMSContext(_configuration)) + { + dbResult = localDbCtx .DbSetOrders .Where(x => (x.PlantId == PlantId || PlantId == 0) && (x.DtExecStart < x.DtOrder)) .Include(p => p.Plant) @@ -142,17 +153,20 @@ namespace GWMS.Data.Controllers .Include(t => t.Transporter) .OrderByDescending(x => x.DtOrder) .ToList(); - + } return dbResult; } public PlantDetailModel GetPlant(int PlantId) { - var dbResult = dbCtx + PlantDetailModel dbResult = new PlantDetailModel(); + using (GWMSContext localDbCtx = new GWMSContext(_configuration)) + { + dbResult = localDbCtx .DbSetPlant .Where(x => x.PlantId == PlantId) .FirstOrDefault(); - + } return dbResult; } @@ -165,13 +179,16 @@ namespace GWMS.Data.Controllers /// public List GetPlantLog(int PlantId, DateTime DtMaxDate, int numRec) { - var dbResult = dbCtx + List dbResult = new List(); + using (GWMSContext localDbCtx = new GWMSContext(_configuration)) + { + dbResult = localDbCtx .DbSetPlantLog .Where(x => (x.PlantId == PlantId || PlantId == 0) && x.DtEvent <= DtMaxDate) .OrderByDescending(x => x.DtEvent) .Take(numRec) .ToList(); - + } return dbResult; } @@ -273,10 +290,13 @@ namespace GWMS.Data.Controllers public List GetPlants() { - var dbResult = dbCtx + List dbResult = new List(); + using (GWMSContext localDbCtx = new GWMSContext(_configuration)) + { + dbResult = localDbCtx .DbSetPlant .ToList(); - + } return dbResult; } @@ -304,46 +324,58 @@ namespace GWMS.Data.Controllers /// public List GetRebootLog(int maxNum = 100) { - if (maxNum == 0) + List dbResult = new List(); + using (GWMSContext localDbCtx = new GWMSContext(_configuration)) { - maxNum = dbCtx.DbRebootLog.Count(); + if (maxNum == 0) + { + maxNum = localDbCtx.DbRebootLog.Count(); + } + dbResult = localDbCtx + .DbRebootLog + .OrderByDescending(x => x.DtEvent) + .Take(maxNum) + .ToList(); } - var dbResult = dbCtx - .DbRebootLog - .OrderByDescending(x => x.DtEvent) - .Take(maxNum) - .ToList(); - return dbResult; } public List GetSuppliers() { - var dbResult = dbCtx + List dbResult = new List(); + using (GWMSContext localDbCtx = new GWMSContext(_configuration)) + { + dbResult = localDbCtx .DbSetSupplier .ToList(); - + } return dbResult; } public List GetTransporters() { - var dbResult = dbCtx + List dbResult = new List(); + using (GWMSContext localDbCtx = new GWMSContext(_configuration)) + { + dbResult = localDbCtx .DbSetTransporter .ToList(); - + } return dbResult; } public List GetUsersFilt(UserLevel UsrLvl, int PlantId, int SupplierId, int TransporterId) { - var dbResult = dbCtx + List dbResult = new List(); + using (GWMSContext localDbCtx = new GWMSContext(_configuration)) + { + dbResult = localDbCtx .DbSetUser .Where(x => (x.Livello == UsrLvl || UsrLvl == UserLevel.ND) && (x.MaskPlantId == PlantId || PlantId == 0) && (x.MaskSupplierId == SupplierId || SupplierId == 0) && (x.MaskTranspId == TransporterId || TransporterId == 0)) .OrderBy(x => x.Livello) .ThenBy(x => x.UserName) .ToList(); - + } return dbResult; } @@ -365,15 +397,18 @@ namespace GWMS.Data.Controllers public bool HasPlantLog() { bool answ = false; - try + using (GWMSContext localDbCtx = new GWMSContext(_configuration)) { - var numRecord = dbCtx - .DbSetPlantLog - .Count(); - answ = numRecord > 0; + try + { + var numRecord = localDbCtx + .DbSetPlantLog + .Count(); + answ = numRecord > 0; + } + catch + { } } - catch - { } return answ; } @@ -385,24 +420,27 @@ namespace GWMS.Data.Controllers public bool OrderDelete(OrderModel Item2Del) { bool done = false; - try + using (GWMSContext localDbCtx = new GWMSContext(_configuration)) { - if (Item2Del != null) + try { - var rec2del = dbCtx - .DbSetOrders - .Where(x => x.OrderId == Item2Del.OrderId) - .FirstOrDefault(); - dbCtx - .DbSetOrders - .Remove(rec2del); - dbCtx.SaveChanges(); - done = true; + if (Item2Del != null) + { + var rec2del = localDbCtx + .DbSetOrders + .Where(x => x.OrderId == Item2Del.OrderId) + .FirstOrDefault(); + localDbCtx + .DbSetOrders + .Remove(rec2del); + localDbCtx.SaveChanges(); + done = true; + } + } + catch (Exception exc) + { + Log.Error($"Eccezione in OrderDelete:{Environment.NewLine}{exc}"); } - } - catch (Exception exc) - { - Log.Error($"Eccezione in OrderDelete:{Environment.NewLine}{exc}"); } return done; } @@ -415,16 +453,19 @@ namespace GWMS.Data.Controllers public bool OrderInsert(List newItems) { bool done = false; - try + using (GWMSContext localDbCtx = new GWMSContext(_configuration)) { - dbCtx - .DbSetOrders - .AddRange(newItems); - dbCtx.SaveChanges(); - done = true; + try + { + localDbCtx + .DbSetOrders + .AddRange(newItems); + localDbCtx.SaveChanges(); + done = true; + } + catch (Exception exc) + { } } - catch (Exception exc) - { } return done; } @@ -436,16 +477,16 @@ namespace GWMS.Data.Controllers public bool OrderUpdate(OrderModel updItem) { bool done = false; - try + using (GWMSContext localDbCtx = new GWMSContext(_configuration)) { - OrderModel currData = null; - currData = dbCtx - .DbSetOrders - .Where(x => x.OrderId == updItem.OrderId) - .FirstOrDefault(); - if (currData != null) + try { - using (GWMSContext localDbCtx = new GWMSContext(_configuration)) + OrderModel currData = null; + currData = localDbCtx + .DbSetOrders + .Where(x => x.OrderId == updItem.OrderId) + .FirstOrDefault(); + if (currData != null) { // se ho modificato data --> cambio codice ordine! if (!localDbCtx.Entry(updItem).OriginalValues["DtOrder"].Equals(localDbCtx.Entry(updItem).CurrentValues["DtOrder"])) @@ -456,19 +497,19 @@ namespace GWMS.Data.Controllers localDbCtx.Entry(updItem).State = EntityState.Modified; localDbCtx.SaveChanges(); } + else + { + localDbCtx + .DbSetOrders + .Add(updItem); + localDbCtx.SaveChanges(); + } + done = true; } - else + catch (Exception exc) { - dbCtx - .DbSetOrders - .Add(updItem); - dbCtx.SaveChanges(); + Log.Error($"Eccezione in OrderUpdate:{Environment.NewLine}{exc}"); } - done = true; - } - catch (Exception exc) - { - Log.Error($"Eccezione in OrderUpdate:{Environment.NewLine}{exc}"); } return done; } @@ -591,7 +632,10 @@ namespace GWMS.Data.Controllers /// public List PlantLogGetLastByFlux(int PlantId) { - List lastRec = dbCtx + List lastRec = new List(); + using (GWMSContext localDbCtx = new GWMSContext(_configuration)) + { + lastRec = localDbCtx .DbSetPlantLog .Where(x => x.PlantId == PlantId) .OrderByDescending(o => o.DtEvent) @@ -600,6 +644,7 @@ namespace GWMS.Data.Controllers .GroupBy(g => g.FluxType) .Select(s => s.First()) .ToList(); + } return lastRec; } @@ -611,43 +656,45 @@ namespace GWMS.Data.Controllers public bool PlantLogInsertNew(List newItems) { bool fatto = false; - try + using (GWMSContext localDbCtx = new GWMSContext(_configuration)) { - dbCtx - .DbSetPlantLog - .AddRange(newItems); - dbCtx.SaveChanges(); - fatto = true; + try + { + localDbCtx + .DbSetPlantLog + .AddRange(newItems); + localDbCtx.SaveChanges(); + fatto = true; + } + catch (Exception exc) + { + Log.Error($"Eccezione durante PlantLogInsertNew per {newItems.Count} rec{Environment.NewLine}{exc}"); + } } - catch (Exception exc) - { - Log.Error(exc, $"Eccezione durante PlantLogInsertNew per {newItems.Count} rec"); - } - return fatto; } public bool RecordRebootLog(RebootLogModel newItem) { bool done = false; - try + using (GWMSContext localDbCtx = new GWMSContext(_configuration)) { - dbCtx - .DbRebootLog - .Add(newItem); - dbCtx.SaveChanges(); - done = true; + try + { + localDbCtx + .DbRebootLog + .Add(newItem); + localDbCtx.SaveChanges(); + done = true; + } + catch (Exception exc) + { + Log.Error($"Eccezione durante RecordRebootLog{Environment.NewLine}{exc}"); + } } - catch (Exception exc) - { } return done; } - public void ResetController() - { - dbCtx = new GWMSContext(_configuration); - } - /// /// Annulla modifiche su una specifica entity (cancel update) /// @@ -656,16 +703,19 @@ namespace GWMS.Data.Controllers public bool rollBackEntity(object item) { bool answ = false; - try + using (GWMSContext localDbCtx = new GWMSContext(_configuration)) { - if (dbCtx.Entry(item).State == EntityState.Deleted || dbCtx.Entry(item).State == EntityState.Modified) + try { - dbCtx.Entry(item).Reload(); + if (localDbCtx.Entry(item).State == EntityState.Deleted || localDbCtx.Entry(item).State == EntityState.Modified) + { + localDbCtx.Entry(item).Reload(); + } + } + catch (Exception exc) + { + Log.Error($"Eccezione in rollBackEntity{Environment.NewLine}{exc}"); } - } - catch (Exception exc) - { - Log.Error($"Eccezione in rollBackEntity{Environment.NewLine}{exc}"); } return answ; } @@ -678,27 +728,32 @@ namespace GWMS.Data.Controllers public bool UserUpdate(UserModel updItem) { bool done = false; - try + using (GWMSContext localDbCtx = new GWMSContext(_configuration)) { - var currData = dbCtx - .DbSetUser - .Where(x => x.UserId == updItem.UserId) - .FirstOrDefault(); - if (currData != null) + try { - dbCtx.Entry(updItem).State = EntityState.Modified; - } - else - { - dbCtx + var currData = localDbCtx .DbSetUser - .Add(updItem); + .Where(x => x.UserId == updItem.UserId) + .FirstOrDefault(); + if (currData != null) + { + localDbCtx.Entry(updItem).State = EntityState.Modified; + } + else + { + localDbCtx + .DbSetUser + .Add(updItem); + } + localDbCtx.SaveChanges(); + done = true; + } + catch (Exception exc) + { + Log.Error($"Eccezione durante UserUpdate{Environment.NewLine}{exc}"); } - dbCtx.SaveChanges(); - done = true; } - catch (Exception exc) - { } return done; } @@ -710,18 +765,23 @@ namespace GWMS.Data.Controllers public bool WeekPlanDelete(WeekPlanModel selRecord) { bool done = false; - try + using (GWMSContext localDbCtx = new GWMSContext(_configuration)) { - var item2del = dbCtx - .DbSetPlantSupplWeekPlan - .Where(x => x.WeekPlanId == selRecord.WeekPlanId) - .FirstOrDefault(); - dbCtx.DbSetPlantSupplWeekPlan.Remove(item2del); - dbCtx.SaveChanges(); - done = true; + try + { + var item2del = localDbCtx + .DbSetPlantSupplWeekPlan + .Where(x => x.WeekPlanId == selRecord.WeekPlanId) + .FirstOrDefault(); + localDbCtx.DbSetPlantSupplWeekPlan.Remove(item2del); + localDbCtx.SaveChanges(); + done = true; + } + catch (Exception exc) + { + Log.Error($"Eccezione durante WeekPlanDelete{Environment.NewLine}{exc}"); + } } - catch (Exception exc) - { } return done; } @@ -733,27 +793,39 @@ namespace GWMS.Data.Controllers public bool WeekPlanUpdate(WeekPlanModel updItem) { bool done = false; - try + using (GWMSContext localDbCtx = new GWMSContext(_configuration)) { - var currData = dbCtx - .DbSetPlantSupplWeekPlan - .Where(x => x.WeekPlanId == updItem.WeekPlanId) - .FirstOrDefault(); - if (currData != null) + try { - dbCtx.Entry(updItem).State = EntityState.Modified; - } - else - { - dbCtx + var currData = localDbCtx .DbSetPlantSupplWeekPlan - .Add(updItem); + .Where(x => x.WeekPlanId == updItem.WeekPlanId) + .FirstOrDefault(); + if (currData != null) + { + currData.DayNum = updItem.DayNum; + currData.DeliveryHour = updItem.DeliveryHour; + currData.Note = updItem.Note; + currData.PlantId = updItem.PlantId; + currData.SupplierId = updItem.SupplierId; + currData.TransporterId = updItem.TransporterId; + + localDbCtx.Entry(currData).State = EntityState.Modified; + } + else + { + localDbCtx + .DbSetPlantSupplWeekPlan + .Add(updItem); + } + localDbCtx.SaveChanges(); + done = true; + } + catch (Exception exc) + { + Log.Error($"Eccezione durante WeekPlanUpdate{Environment.NewLine}{exc}"); } - dbCtx.SaveChanges(); - done = true; } - catch (Exception exc) - { } return done; } diff --git a/GWMS.UI/Data/GWMSDataService.cs b/GWMS.UI/Data/GWMSDataService.cs index cdc560b..299e665 100644 --- a/GWMS.UI/Data/GWMSDataService.cs +++ b/GWMS.UI/Data/GWMSDataService.cs @@ -474,7 +474,6 @@ namespace GWMS.UI.Data { done = dbController.OrderDelete(currItem); invalidateAllCache(); - dbController.ResetController(); } catch (Exception exc) { @@ -551,7 +550,6 @@ namespace GWMS.UI.Data { done = dbController.OrderUpdate(currItem); invalidateAllCache(); - dbController.ResetController(); } catch (Exception exc) { @@ -730,11 +728,6 @@ namespace GWMS.UI.Data { } } - public void ResetController() - { - dbController.ResetController(); - } - public void rollBackEdit(object item) { dbController.rollBackEntity(item); diff --git a/GWMS.UI/GWMS.UI.csproj b/GWMS.UI/GWMS.UI.csproj index 2c51b9c..038b995 100644 --- a/GWMS.UI/GWMS.UI.csproj +++ b/GWMS.UI/GWMS.UI.csproj @@ -2,7 +2,7 @@ net5.0 - 1.0.2109.2912 + 1.0.2109.2914 95c9f021-52d1-4390-a670-5810b7b777b0 true true diff --git a/GWMS.UI/Pages/Orders.razor.cs b/GWMS.UI/Pages/Orders.razor.cs index d5b4eea..58a720b 100644 --- a/GWMS.UI/Pages/Orders.razor.cs +++ b/GWMS.UI/Pages/Orders.razor.cs @@ -322,7 +322,6 @@ namespace GWMS.UI.Pages protected override async Task OnInitializedAsync() { - DataService.ResetController(); AppMService.ShowSearch = false; AppMService.PageName = "Ordini"; AppMService.PageIcon = "fas fa-file-invoice pr-2"; @@ -382,7 +381,6 @@ namespace GWMS.UI.Pages protected async Task UpdateData() { currRecord = null; - DataService.ResetController(); await ReloadData(); } diff --git a/GWMS.UI/Pages/PlantAnalisys.razor.cs b/GWMS.UI/Pages/PlantAnalisys.razor.cs index bce32db..ebfbe7e 100644 --- a/GWMS.UI/Pages/PlantAnalisys.razor.cs +++ b/GWMS.UI/Pages/PlantAnalisys.razor.cs @@ -337,7 +337,6 @@ namespace GWMS.UI.Pages protected override async Task OnInitializedAsync() { - DataService.ResetController(); AppMService.ShowSearch = false; AppMService.PageName = "Ordini"; AppMService.PageIcon = "fas fa-file-invoice pr-2"; @@ -396,7 +395,6 @@ namespace GWMS.UI.Pages protected async Task UpdateData() { currRecord = null; - DataService.ResetController(); await DataService.PlantsAnalisysReset(AppMService.Order_Filter); await ReloadData(); } diff --git a/GWMS.UI/Pages/Suppliers.razor.cs b/GWMS.UI/Pages/Suppliers.razor.cs index 0215ad2..c6fb708 100644 --- a/GWMS.UI/Pages/Suppliers.razor.cs +++ b/GWMS.UI/Pages/Suppliers.razor.cs @@ -267,7 +267,6 @@ namespace GWMS.UI.Pages protected override async Task OnInitializedAsync() { - DataService.ResetController(); AppMService.ShowSearch = false; AppMService.PageName = "Fornitore"; AppMService.PageIcon = "fas fa-industry pr-2"; @@ -325,7 +324,6 @@ namespace GWMS.UI.Pages protected async Task UpdateData() { currRecord = null; - DataService.ResetController(); await ReloadData(); } diff --git a/GWMS.UI/Pages/Transporters.razor.cs b/GWMS.UI/Pages/Transporters.razor.cs index 8872576..252ed38 100644 --- a/GWMS.UI/Pages/Transporters.razor.cs +++ b/GWMS.UI/Pages/Transporters.razor.cs @@ -294,7 +294,6 @@ namespace GWMS.UI.Pages protected override async Task OnInitializedAsync() { - DataService.ResetController(); SelPlantId = 0; SelTranspId = 0; AppMService.ShowSearch = false; @@ -373,7 +372,6 @@ namespace GWMS.UI.Pages protected async Task UpdateData() { currRecord = null; - DataService.ResetController(); await ReloadData(); } diff --git a/GWMS.UI/appsettings.Production.json b/GWMS.UI/appsettings.Production.json index 152c032..5308746 100644 --- a/GWMS.UI/appsettings.Production.json +++ b/GWMS.UI/appsettings.Production.json @@ -1,7 +1,7 @@ { "Logging": { "LogLevel": { - "Default": "Trace", + "Default": "Information", "Microsoft": "Warning", "Microsoft.Hosting.Lifetime": "Information" } diff --git a/Resources/ChangeLog.html b/Resources/ChangeLog.html index be499c8..724a7e7 100644 --- a/Resources/ChangeLog.html +++ b/Resources/ChangeLog.html @@ -1,6 +1,6 @@ GWMS - Gas Warehouse Management System -

Versione: 1.0.2109.2912

+

Versione: 1.0.2109.2914


Note di rilascio:
  • diff --git a/Resources/VersNum.txt b/Resources/VersNum.txt index 9b3a73b..02f2be1 100644 --- a/Resources/VersNum.txt +++ b/Resources/VersNum.txt @@ -1 +1 @@ -1.0.2109.2912 +1.0.2109.2914 diff --git a/Resources/manifest.xml b/Resources/manifest.xml index 2a06e38..736725b 100644 --- a/Resources/manifest.xml +++ b/Resources/manifest.xml @@ -1,6 +1,6 @@ - 1.0.2109.2912 + 1.0.2109.2914 http://nexus.steamware.net/repository/SWS/GWMS/stable/0/GWMS.UI.zip http://nexus.steamware.net/repository/SWS/GWMS/stable/0/ChangeLog.html false