Files
NKC/NKC_WF/site/PlannerReportsDailyStats.aspx.cs

95 lines
3.2 KiB
C#

using AppData;
using NKC_WF.WebUserControls;
using SteamWare;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace NKC_WF.site
{
public partial class PlannerReportsDailyStats : BasePage
{
#region Protected Properties
protected int savedBatchId
{
get
{
return ComLib.getCurrBatchId(PlaceCod);
}
}
#endregion Protected Properties
#region Protected Methods
protected void lbtRefreshData_Click(object sender, EventArgs e)
{
TryUpdateModel();
}
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
((SiteMaster)this.Master).showSearch = false;
}
}
#endregion Protected Methods
#region Private Methods
private void TryUpdateModel()
{
Thread.Sleep(50);
DateTime oggi = DateTime.Today;
// verifica se ci sia VETO x update da redis
string rawVal = memLayer.ML.getRSV(ComLib.redVetoDayStats);
if (string.IsNullOrEmpty(rawVal))
{
// effettuo calcolo statistiche
Stopwatch stopWatchLap = new Stopwatch();
stopWatchLap.Start();
// se non c'è effettua ricalcolo x i giorni necessari (da ultimo ricalcolo oppure da
// valore web.config)
int numDays = memLayer.ML.CRI("repNumDayPre");
// verifico ultimo record...
var tabLast = DLMan.taDayStats.getLast();
try
{
// se vuoto: 90gg
if (tabLast == null || tabLast.Count == 0)
{
numDays = 90;
}
else
{
var lastRec = tabLast[0];
// calcolo x eccesso la differenza in giorni
var dayDiff = Math.Ceiling(oggi.Subtract(lastRec.DataRif).TotalDays + 1);
int numDayLast = (int)dayDiff;
numDays = numDays > numDayLast ? numDays : numDayLast;
}
}
catch
{ }
// verifico ultimo giorno disponibile...
DateTime DateEnd = oggi.AddDays(1);
DateTime DateStart = DateEnd.AddDays(-numDays);
DLMan.taDayStats.ProductionUpdate(DateStart, DateEnd, "*", true);
int vetoRecalcMin = memLayer.ML.CRI("repVetoRecalcMin");
memLayer.ML.setRSV(ComLib.redVetoDayStats, $"Recalc Done | {DateStart} --> {DateEnd}", 60 * vetoRecalcMin);
stopWatchLap.Stop();
lgInfo($"DayStats DB ProductionUpdate: effettuato ricalcolo statistiche | periodo {DateStart} --> {DateEnd} | elapsed: {stopWatchLap.Elapsed.TotalMilliseconds} ms | veto ricalcolo per {vetoRecalcMin} minuti");
}
}
#endregion Private Methods
}
}