using AppData;
using SteamWare;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace NKC_WF.WebUserControls
{
public partial class cmp_batchDetailMongo : BaseUserControl
{
#region Public Properties
public int BatchId
{
set
{
hfBatchId.Value = value.ToString();
if (value > 0)
{
updateMongoData(value);
}
}
get
{
int answ = 0;
int.TryParse(hfBatchId.Value, out answ);
return answ;
}
}
public string cssSized
{
get
{
string answ = showInline ? "col-6" : "col-12";
return answ;
}
}
public bool showInline
{
set
{
hfShowInline.Value = value.ToString();
}
get
{
bool answ = false;
bool.TryParse(hfShowInline.Value, out answ);
return answ;
}
}
#endregion Public Properties
#region Private Methods
///
/// Aggiorna i dati di stima recuperando da Mongo le risposte complete dal supervisor
///
/// BatchId di cui recuperare le info
private void updateMongoData(int batchId)
{
lblMatDet.Text = "";
lblProdDet.Text = "";
if (memLayer.ML.CRB("enableMongo"))
{
// cerco da lista salvataggi Estim/Nest...
var estimAnsw = ComLib.man.getEstAnsw(batchId);
var nestAnsw = ComLib.man.getNestAnsw(batchId);
StringBuilder sbDebug = new StringBuilder();
sbDebug.AppendLine("Debug Info:");
// elenchi x ricerca duplicati
List partListEstim = new List();
List partListEstimDupl = new List();
List partListNest = new List();
List partListNestDupl = new List();
if (estimAnsw != null)
{
try
{
foreach (var part in estimAnsw.PartList)
{
if (partListEstim.Contains(part.PartId))
{
partListEstimDupl.Add(part.PartId);
}
else
{
partListEstim.Add(part.PartId);
}
}
}
catch
{ }
try
{
sbDebug.AppendLine($"ESTIM: EnvNum: {estimAnsw.EnvNum} | Worktime: {estimAnsw.EstimatedWorktime / 60:N2} min | Processing Runtime {estimAnsw.ProcessingRuntime / 60:N2} min | Parts #: {estimAnsw.PartList.Count} | Distinct Part # {partListEstim.Count}");
// se ho duplicati indico:
if (partListEstimDupl.Count > 0)
{
sbDebug.AppendLine("---------------------");
sbDebug.AppendLine($"ESTIM: FOUND {partListEstimDupl.Count} duplicate:");
foreach (var partId in partListEstimDupl)
{
sbDebug.AppendLine($"{partId}");
}
sbDebug.AppendLine("---------------------");
}
}
catch
{ }
}
if (nestAnsw != null)
{
try
{
if (nestAnsw.BunkList != null)
{
foreach (var bunk in nestAnsw.BunkList)
{
foreach (var sheet in bunk.SheetList)
{
foreach (var part in sheet.PartList)
{
if (partListNest.Contains(part.PartId))
{
partListNestDupl.Add(part.PartId);
}
else
{
partListNest.Add(part.PartId);
}
}
}
}
}
}
catch
{ }
int totKit = 0;
try
{
if (nestAnsw.CartList != null)
{
foreach (var cart in nestAnsw.CartList)
{
totKit += cart.KitList.Count;
}
}
}
catch
{ }
//il tot delle part è in bunk > Sheet > part
int totPartNum = 0;
int totSheet = 0;
List materialsList = new List();
double num = 0;
double den = 1;
double currRatio = 0;
List workRatio = new List();
try
{
if (nestAnsw.BunkList != null)
{
foreach (var bunk in nestAnsw.BunkList)
{
totSheet += bunk.SheetList.Count;
foreach (var sheet in bunk.SheetList)
{
totPartNum += sheet.PartList.Count;
num = sheet.SurfaceWork > 0 ? sheet.SurfaceWork : 0;
den = sheet.SurfaceTotal > 0 ? sheet.SurfaceTotal : 1;
currRatio = ComLib.ratioProt(num, den);
workRatio.Add(currRatio);
if (!materialsList.Contains(sheet.MatId))
{
materialsList.Add(sheet.MatId);
}
}
}
}
}
catch
{ }
try
{
// ordino le medie
workRatio.Sort();
// filtro i valori + bassi solo se richiesto in conf
if (!chkExcludeMin.Checked)
{
// controllo di averne + di 1...
if (workRatio.Count > materialsList.Count * 2)
{
// elimino le + basse quanti materiali ci sono...
workRatio.RemoveRange(0, materialsList.Count);
}
}
double avgRatio = workRatio.Average();
double minRatio = workRatio.Min();
double maxRatio = workRatio.Max();
sbDebug.AppendLine($"NEST: EnvNum: {nestAnsw.EnvNum} | Worktime: {nestAnsw.EstimatedWorktime / 60:N2} min | Processing Runtime {nestAnsw.ProcessingRuntime / 60:N2} min");
lblMatDet.Text = $"avg: {avgRatio:P1} ({minRatio:P1} → {maxRatio:P1}) | {materialsList.Count} materials";
lblProdDet.Text = $"Bunks: {nestAnsw.BunkList.Count} | Sheets: {totSheet} | Carts: {nestAnsw.CartList.Count} | Bins: {nestAnsw.BinList.Count}";
// se ho duplicati indico:
if (partListNestDupl.Count > 0)
{
sbDebug.AppendLine("---------------------");
sbDebug.AppendLine($"NEST: FOUND {partListNestDupl.Count} duplicate:");
foreach (var partId in partListNestDupl)
{
sbDebug.AppendLine($"{partId}");
}
sbDebug.AppendLine("---------------------");
}
// s enon corrispondono
if (partListEstim.Count != partListNest.Count)
{
sbDebug.AppendLine("---------------------");
if (partListEstim.Count > partListNest.Count)
{
sbDebug.AppendLine($"EST OK | NEST missing:");
foreach (var partId in partListEstim)
{
if (!partListNest.Contains(partId))
{
sbDebug.AppendLine($"{partId}");
}
}
}
else
{
sbDebug.AppendLine($"EST missing | NEST OK:");
foreach (var partId in partListNest)
{
if (!partListEstim.Contains(partId))
{
sbDebug.AppendLine($"{partId}");
}
}
}
sbDebug.AppendLine("---------------------");
}
}
catch
{ }
}
divDetJson.Visible = (memLayer.ML.CRS("environment") == "DEV");
if (divDetJson.Visible)
{
lblTestJson.Text = "
" + sbDebug.Replace("\r\n", "
").ToString();
}
}
}
#endregion Private Methods
#region Protected Methods
protected void Page_Load(object sender, EventArgs e)
{
}
#endregion Protected Methods
protected void chkExcludeMin_CheckedChanged(object sender, EventArgs e)
{
updateMongoData(BatchId);
}
}
}