OK ODL alla data

This commit is contained in:
Samuele Locatelli
2022-11-29 09:45:27 +01:00
parent 46ba6078e3
commit 63545c6f3d
+33 -32
View File
@@ -7,6 +7,8 @@ using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Web.Mvc;
namespace MP_IO.Controllers
@@ -1020,45 +1022,44 @@ namespace MP_IO.Controllers
public string getOdlAtDate(string id, string dateRif)
{
string answ = "";
bool canInsert = false;
// attenzione! poiché nell'URL il carattere "#" viene filtrato ci aspettiamo il
// carattere "|" che poi trasformiamo ora in "#"
id = id.Replace("|", "#");
// converto la data in formato dateTime... e ottengo intervallo data indicata da mezzanotte a 23:59:59...
CultureInfo provider = CultureInfo.InvariantCulture;
DateTime dtFrom = DateTime.ParseExact(dateRif, "yyyyMMdd", provider);
// data fine giorno dopo
DateTime dtTo = dtFrom.AddDays(1);
// cerco ODL alla data (validi)
DataLayer DataLayerObj = new DataLayer();
DS_ProdTempi.ODLDataTable odlList = DataLayerObj.taODL.getByMacchinaPeriodoNoNull(id, dtFrom, dtTo);
// se > 1 --> prendo il + durevole
if (odlList.Count > 1)
DateTime dtFrom = DateTime.Today;
bool fatto = DateTime.TryParseExact(dateRif, "yyyyMMdd", provider, DateTimeStyles.None, out dtFrom);
if (fatto)
{
canInsert = true;
}
else if (odlList.Count > 0)
{
canInsert = true;
}
else
{
// errore manca ODL!!!!
answ = "NO";
}
// procedo se possibile
if (canInsert)
{
//try
//{
// answ = $"{DataLayerObj.currODL(id)}";
//}
//catch (Exception exc)
//{
// logger.lg.scriviLog(string.Format("Errore in getOdlAtDate (get){0}{1}", Environment.NewLine, exc));
// answ = "NO";
//}
// data fine giorno dopo
DateTime dtTo = dtFrom.AddDays(1);
// cerco ODL alla data (validi)
DataLayer DataLayerObj = new DataLayer();
DS_ProdTempi.ODLDataTable odlList = DataLayerObj.taODL.getByMacchinaPeriodoNoNull(id, dtFrom, dtTo);
int idxOdl = 0;
// se > 1 --> prendo il + durevole
if (odlList.Count > 1)
{
double maxPeriod = 0;
foreach (var item in odlList)
{
DateTime dtStart = item.DataInizio > dtFrom ? item.DataInizio : dtFrom;
DateTime dtEnd = item.DataFine < dtTo ? item.DataFine : dtTo;
double currPeriod = dtEnd.Subtract(dtStart).TotalMinutes;
if (currPeriod > maxPeriod)
{
maxPeriod = currPeriod;
idxOdl = item.IdxODL;
}
}
}
else if (odlList.Count == 1)
{
idxOdl = odlList[0].IdxODL;
}
// conversione!
answ = $"{idxOdl}";
}
return answ;
}