DataLayer:
- aggiunta record avvio app + chiusura se necessario - fix dbCtxname - check sync logMachine
This commit is contained in:
@@ -90,29 +90,25 @@ namespace EgtBEAMWALL.DataLayer.Controllers
|
||||
/// <returns></returns>
|
||||
public bool Create(LogMachineModel newLogMac)
|
||||
{
|
||||
bool fatto = false;
|
||||
bool done = false;
|
||||
try
|
||||
{
|
||||
try
|
||||
using (var locDbCtx = new DatabaseContext(DbConfig.CONNECTION_STRING))
|
||||
{
|
||||
using (var locallocalDbCtx = new DatabaseContext(DbConfig.CONNECTION_STRING))
|
||||
{
|
||||
// Add to database
|
||||
locallocalDbCtx.LogMachineList.Add(newLogMac);
|
||||
// Commit changes
|
||||
locallocalDbCtx.SaveChanges();
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
string errMessage = $"EXCEPTION on LogMachine.Create: {Environment.NewLine}{exc}";
|
||||
Console.WriteLine(errMessage);
|
||||
Log.Error(errMessage);
|
||||
// Add to database
|
||||
locDbCtx.LogMachineList.Add(newLogMac);
|
||||
// Commit changes
|
||||
locDbCtx.SaveChanges();
|
||||
done = true;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
return fatto;
|
||||
catch (Exception exc)
|
||||
{
|
||||
string errMessage = $"EXCEPTION on LogMachine.Create: {Environment.NewLine}{exc}";
|
||||
Console.WriteLine(errMessage);
|
||||
Log.Error(errMessage);
|
||||
}
|
||||
return done;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -262,6 +258,78 @@ namespace EgtBEAMWALL.DataLayer.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creazione LOG record di avvio programma
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public bool RecordAppStartup()
|
||||
{
|
||||
bool done = false;
|
||||
try
|
||||
{
|
||||
using (var locDbCtx = new DatabaseContext(DbConfig.CONNECTION_STRING))
|
||||
{
|
||||
// cerco ultimo record registrato
|
||||
var lastRec = locDbCtx
|
||||
.LogMachineList
|
||||
.OrderByDescending(x => x.DtEvent)
|
||||
.FirstOrDefault();
|
||||
|
||||
// cerco ultimo evento chiusura
|
||||
var lastRecClose = locDbCtx
|
||||
.LogMachineList
|
||||
.Where(x => x.EvType == Core.MachLog.MachLogTypes.APPLICATION
|
||||
&& x.VarValue == "0")
|
||||
.OrderByDescending(x => x.DtEvent)
|
||||
.FirstOrDefault();
|
||||
|
||||
// preparo nuovo record avvio!
|
||||
LogMachineModel recStartApp = new LogMachineModel()
|
||||
{
|
||||
DtEvent = DateTime.Now.AddSeconds(-1),
|
||||
EvType = Core.MachLog.MachLogTypes.APPLICATION,
|
||||
VarValue = "1",
|
||||
ProdId = lastRec != null ? lastRec.ProdId : 0,
|
||||
ProjCloudId = lastRec != null ? lastRec.ProjCloudId : 0,
|
||||
SupervId = lastRec != null ? lastRec.SupervId : "1"
|
||||
};
|
||||
|
||||
// verifico esistenza record chiusura...
|
||||
if (lastRecClose != null && lastRec != null)
|
||||
{
|
||||
// se l'ultimo record registrato NON fosse di chiusura... lo genero!
|
||||
if (lastRecClose.DtEvent < lastRec.DtEvent)
|
||||
{
|
||||
var recCloseApp = new LogMachineModel()
|
||||
{
|
||||
DtEvent = lastRec.DtEvent.AddSeconds(1),
|
||||
EvType = recStartApp.EvType,
|
||||
VarValue = "0",
|
||||
ProdId = lastRec != null ? lastRec.ProdId : 0,
|
||||
ProjCloudId = lastRec != null ? lastRec.ProjCloudId : 0,
|
||||
SupervId = lastRec != null ? lastRec.SupervId : "1"
|
||||
};
|
||||
// aggiungo rec chiusura
|
||||
locDbCtx.LogMachineList.Add(recCloseApp);
|
||||
}
|
||||
}
|
||||
|
||||
// aggiungo rec avvio
|
||||
locDbCtx.LogMachineList.Add(recStartApp);
|
||||
// salvataggio
|
||||
locDbCtx.SaveChanges();
|
||||
done = true;
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
string errMessage = $"EXCEPTION on LogMachine.RecordAppStartup: {Environment.NewLine}{exc}";
|
||||
Console.WriteLine(errMessage);
|
||||
Log.Error(errMessage);
|
||||
}
|
||||
return done;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Aggiorna i record indicati inserendo dataora corrente x DtSent
|
||||
/// </summary>
|
||||
|
||||
@@ -265,7 +265,7 @@ namespace EgtBEAMWALL.DataLayer.Controllers
|
||||
/// <param name="num2send">num max di record da inviare (std: 1000)</param>
|
||||
/// <param name="tryFixProj">Ture: cerca di sistemare ProdId e ProjCloudId prima di inviare</param>
|
||||
/// <returns></returns>
|
||||
public SyncResult CloudLogMaccSyncro(int batchSize = 50, int num2send = 1000, bool tryFixProj = false)
|
||||
public SyncResult CloudLogMaccSyncro(int batchSize = 100, int num2send = 2000, bool tryFixProj = false)
|
||||
{
|
||||
SyncResult answ = SyncResult.ERR_ND;
|
||||
// verifico server ok
|
||||
|
||||
@@ -203,9 +203,9 @@ namespace EgtBEAMWALL.DataLayer.Controllers
|
||||
public PartModel FindByPartId(int ProdId, int PartId)
|
||||
{
|
||||
PartModel answ = null;
|
||||
using (DatabaseContext locallocalDbCtx = new DatabaseContext(DbConfig.CONNECTION_STRING))
|
||||
using (DatabaseContext locDbCtx = new DatabaseContext(DbConfig.CONNECTION_STRING))
|
||||
{
|
||||
answ = locallocalDbCtx
|
||||
answ = locDbCtx
|
||||
.PartList
|
||||
.Where(x => x.MachGroup.Prod.ProdId == ProdId && x.PartId == PartId)
|
||||
.FirstOrDefault();
|
||||
@@ -221,10 +221,10 @@ namespace EgtBEAMWALL.DataLayer.Controllers
|
||||
public bool Update(PartModel updItem)
|
||||
{
|
||||
bool done = false;
|
||||
using (DatabaseContext locallocalDbCtx = new DatabaseContext(DbConfig.CONNECTION_STRING))
|
||||
using (DatabaseContext locDbCtx = new DatabaseContext(DbConfig.CONNECTION_STRING))
|
||||
{
|
||||
var myStatusMapCtrl = new StatusMapController();
|
||||
var item2upd = locallocalDbCtx
|
||||
var item2upd = locDbCtx
|
||||
.PartList
|
||||
.Where(x => x.PartDbId == updItem.PartDbId)
|
||||
.SingleOrDefault();
|
||||
@@ -233,14 +233,14 @@ namespace EgtBEAMWALL.DataLayer.Controllers
|
||||
try
|
||||
{
|
||||
// update, vers 1...
|
||||
locallocalDbCtx.Entry(item2upd).CurrentValues.SetValues(updItem);
|
||||
locDbCtx.Entry(item2upd).CurrentValues.SetValues(updItem);
|
||||
|
||||
//// update, vers 2
|
||||
//localDbCtx.PartList.Remove(item2del);
|
||||
//localDbCtx.PartList.Add(updItem);
|
||||
|
||||
// Commit changes
|
||||
locallocalDbCtx.SaveChanges();
|
||||
locDbCtx.SaveChanges();
|
||||
done = true;
|
||||
// aggiorno info sullo status
|
||||
myStatusMapCtrl.UpdateAction("", updItem.MachGroup.Prod.ProdId, updItem.PartId, Core.StatusMapItemType.Part, Core.StatusMapOpType.MachGroupMod, "");
|
||||
@@ -271,13 +271,13 @@ namespace EgtBEAMWALL.DataLayer.Controllers
|
||||
public bool UpdateEnd(int ProdId, int MachGroupId, int PartId, DateTime DtEnd)
|
||||
{
|
||||
bool done = false;
|
||||
using (DatabaseContext locallocalDbCtx = new DatabaseContext(DbConfig.CONNECTION_STRING))
|
||||
using (DatabaseContext locDbCtx = new DatabaseContext(DbConfig.CONNECTION_STRING))
|
||||
{
|
||||
var myStatusMapCtrl = new StatusMapController();
|
||||
try
|
||||
{
|
||||
// aggiorno
|
||||
var item2upd = locallocalDbCtx
|
||||
var item2upd = locDbCtx
|
||||
.PartList
|
||||
.Where(x => x.MachGroup.Prod.ProdId == ProdId && x.MachGroup.MachGroupId == MachGroupId && x.PartId == PartId)
|
||||
.FirstOrDefault();
|
||||
@@ -286,7 +286,7 @@ namespace EgtBEAMWALL.DataLayer.Controllers
|
||||
{
|
||||
item2upd.DtEnd = DtEnd;
|
||||
// Commit changes
|
||||
locallocalDbCtx.SaveChanges();
|
||||
locDbCtx.SaveChanges();
|
||||
done = true;
|
||||
// aggiorno info sullo status
|
||||
myStatusMapCtrl.UpdateAction("", ProdId, PartId, Core.StatusMapItemType.Part, DtEnd == DateTime.MinValue ? Core.StatusMapOpType.ResetPartEnd : Core.StatusMapOpType.PartEnd, "");
|
||||
@@ -317,13 +317,13 @@ namespace EgtBEAMWALL.DataLayer.Controllers
|
||||
public bool UpdateStart(int ProdId, int MachGroupId, int PartId, DateTime DtStart)
|
||||
{
|
||||
bool done = false;
|
||||
using (DatabaseContext locallocalDbCtx = new DatabaseContext(DbConfig.CONNECTION_STRING))
|
||||
using (DatabaseContext locDbCtx = new DatabaseContext(DbConfig.CONNECTION_STRING))
|
||||
{
|
||||
var myStatusMapCtrl = new StatusMapController();
|
||||
try
|
||||
{
|
||||
// aggiorno
|
||||
var item2upd = locallocalDbCtx
|
||||
var item2upd = locDbCtx
|
||||
.PartList
|
||||
.Where(x => x.MachGroup.Prod.ProdId == ProdId && x.MachGroup.MachGroupId == MachGroupId && x.PartId == PartId)
|
||||
.FirstOrDefault();
|
||||
@@ -331,7 +331,7 @@ namespace EgtBEAMWALL.DataLayer.Controllers
|
||||
{
|
||||
item2upd.DtStart = DtStart;
|
||||
// Commit changes
|
||||
locallocalDbCtx.SaveChanges();
|
||||
locDbCtx.SaveChanges();
|
||||
done = true;
|
||||
// aggiorno info sullo status
|
||||
myStatusMapCtrl.UpdateAction("", ProdId, PartId, Core.StatusMapItemType.Part, DtStart == DateTime.MinValue ? Core.StatusMapOpType.ResetPartStart : Core.StatusMapOpType.PartStart, "");
|
||||
@@ -363,13 +363,13 @@ namespace EgtBEAMWALL.DataLayer.Controllers
|
||||
public bool UpdateStatus(int ProdId, int MachGroupId, int PartId, Core.ItemState newState)
|
||||
{
|
||||
bool done = false;
|
||||
using (DatabaseContext locallocalDbCtx = new DatabaseContext(DbConfig.CONNECTION_STRING))
|
||||
using (DatabaseContext locDbCtx = new DatabaseContext(DbConfig.CONNECTION_STRING))
|
||||
{
|
||||
var myStatusMapCtrl = new StatusMapController();
|
||||
try
|
||||
{
|
||||
// aggiorno
|
||||
var item2upd = locallocalDbCtx
|
||||
var item2upd = locDbCtx
|
||||
.PartList
|
||||
.Where(x => x.MachGroup.Prod.ProdId == ProdId && x.MachGroup.MachGroupId == MachGroupId && x.PartId == PartId)
|
||||
.FirstOrDefault();
|
||||
@@ -377,7 +377,7 @@ namespace EgtBEAMWALL.DataLayer.Controllers
|
||||
{
|
||||
item2upd.State = newState;
|
||||
// Commit changes
|
||||
locallocalDbCtx.SaveChanges();
|
||||
locDbCtx.SaveChanges();
|
||||
done = true;
|
||||
// aggiorno info sullo status
|
||||
myStatusMapCtrl.UpdateAction("", ProdId, PartId, Core.StatusMapItemType.Part, newState == Core.ItemState.Scrapped ? Core.StatusMapOpType.SetPartScrapped : Core.StatusMapOpType.MachGroupMod, "");
|
||||
@@ -414,9 +414,9 @@ namespace EgtBEAMWALL.DataLayer.Controllers
|
||||
{
|
||||
int BtlPartDbId = 0;
|
||||
|
||||
using (DatabaseContext locallocalDbCtx = new DatabaseContext(DbConfig.CONNECTION_STRING))
|
||||
using (DatabaseContext locDbCtx = new DatabaseContext(DbConfig.CONNECTION_STRING))
|
||||
{
|
||||
var btlPart = locallocalDbCtx
|
||||
var btlPart = locDbCtx
|
||||
.BTLPartList
|
||||
.Where(x => x.Project.ProjId == ProjId && x.PDN == PDN)
|
||||
.SingleOrDefault();
|
||||
|
||||
Reference in New Issue
Block a user