315 lines
13 KiB
C#
315 lines
13 KiB
C#
using AppData;
|
|
using NKC_SDK;
|
|
using SteamWare;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
|
|
namespace NKC_WF.WebUserControls
|
|
{
|
|
|
|
public partial class cmp_batchDetail : BaseUserControl
|
|
{
|
|
public event EventHandler eh_doRefresh;
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
public int BatchId
|
|
{
|
|
set
|
|
{
|
|
hfBatchId.Value = value.ToString();
|
|
frmView.DataBind();
|
|
lblMatDet.Text = "";
|
|
lblProdDet.Text = "";
|
|
if (memLayer.ML.CRB("enableMongo"))
|
|
{
|
|
// cerco da lista salvataggi Estim/Nest...
|
|
var estimAnsw = ComLib.man.getEstAnsw(value);
|
|
var nestAnsw = ComLib.man.getNestAnsw(value);
|
|
StringBuilder sbDebug = new StringBuilder();
|
|
sbDebug.AppendLine("Debug Info:");
|
|
// elenchi x ricerca duplicati
|
|
List<int> partListEstim = new List<int>();
|
|
List<int> partListEstimDupl = new List<int>();
|
|
List<int> partListNest = new List<int>();
|
|
List<int> partListNestDupl = new List<int>();
|
|
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
|
|
{
|
|
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
|
|
{
|
|
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<int> materialsList = new List<int>();
|
|
double num = 0;
|
|
double den = 1;
|
|
double currRatio = 0;
|
|
List<double> workRatio = new List<double>();
|
|
try
|
|
{
|
|
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 = ratioProt(num, den);
|
|
workRatio.Add(currRatio);
|
|
if (!materialsList.Contains(sheet.MatId))
|
|
{
|
|
materialsList.Add(sheet.MatId);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch
|
|
{ }
|
|
try
|
|
{
|
|
// ordino le medie
|
|
workRatio.Sort();
|
|
// 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: <b>{avgRatio:P1}</b> (<b>{minRatio:P1}</b> → <b>{maxRatio:P1}</b>) | {materialsList.Count} materials";
|
|
lblProdDet.Text = $"Bunks: <b>{nestAnsw.BunkList.Count}</b> | Sheets: <b>{totSheet}</b> | Carts: <b>{nestAnsw.CartList.Count}</b> | Bins: <b>{nestAnsw.BinList.Count}</b>";
|
|
// 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
|
|
{ }
|
|
}
|
|
if (memLayer.ML.CRS("environment") == "DEV")
|
|
{
|
|
lblTestJson.Text = "<hr/>" + sbDebug.Replace("\r\n", "<br/>").ToString();
|
|
}
|
|
}
|
|
}
|
|
get
|
|
{
|
|
int answ = 0;
|
|
int.TryParse(hfBatchId.Value, out answ);
|
|
return answ;
|
|
}
|
|
}
|
|
|
|
internal void doUpdate()
|
|
{
|
|
frmView.DataBind();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Effettua divisione evitando zeri a den...
|
|
/// </summary>
|
|
/// <param name="num"></param>
|
|
/// <param name="den"></param>
|
|
/// <returns></returns>
|
|
protected double ratioProt(double num, double den)
|
|
{
|
|
den = den == 0 ? 1 : den;
|
|
return num / den;
|
|
}
|
|
/// <summary>
|
|
/// Controlla se lo stato sia uguale a quello richiesto
|
|
/// </summary>
|
|
/// <param name="_status"></param>
|
|
/// <param name="statusReq"></param>
|
|
/// <returns></returns>
|
|
public bool checkStatus(object _status, BatchStatus statusReq)
|
|
{
|
|
bool answ = false;
|
|
int status = -1;
|
|
int.TryParse(_status.ToString(), out status);
|
|
answ = (status == (int)statusReq);
|
|
return answ;
|
|
}
|
|
/// <summary>
|
|
/// verifica possibilità avvio TASK x presenza task NON chiusi
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public bool canStartNew
|
|
{
|
|
get
|
|
{
|
|
return ComLib.canStartNew;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Converte il codice stato in effettivo campo
|
|
/// </summary>
|
|
/// <param name="_status"></param>
|
|
/// <returns></returns>
|
|
public string BStatus(object _status)
|
|
{
|
|
string answ = ComLib.BatchStatusDescr(_status);
|
|
return answ;
|
|
}
|
|
|
|
protected void lbtAccept_Click(object sender, EventArgs e)
|
|
{
|
|
// registro accettazione Nesting
|
|
DataLayer.man.taBL.acceptBatch(BatchId, DataLayer.man.CodSoggCurrUser);
|
|
raiseEvent();
|
|
}
|
|
|
|
protected void lbtStopEstim_Click(object sender, EventArgs e)
|
|
{
|
|
// resetto richiesta
|
|
ComLib.resetBatchReq();
|
|
// registro su DB nesting iniziato...
|
|
DataLayer.man.taBL.updateStatus(BatchId, (int)BatchStatus.Imported, "", -1);
|
|
raiseEvent();
|
|
}
|
|
|
|
protected void lbtSendEstim_Click(object sender, EventArgs e)
|
|
{
|
|
// invia a redis una richiesta...
|
|
ComLib.sendMaterials();
|
|
ComLib.sendBatchReq(BatchId, "Estimation", 1);
|
|
|
|
// registro su DB nesting iniziato...
|
|
DataLayer.man.taBL.updateStatus(BatchId, (int)BatchStatus.EstimationRequested, "", 0);
|
|
raiseEvent();
|
|
}
|
|
protected void lbtStopNesting_Click(object sender, EventArgs e)
|
|
{
|
|
// resetto richiesta
|
|
ComLib.resetBatchReq();
|
|
// registro su DB nesting iniziato...
|
|
DataLayer.man.taBL.updateStatus(BatchId, (int)BatchStatus.EstimationDone, "", -1);
|
|
raiseEvent();
|
|
}
|
|
|
|
protected void lbtSendNesting_Click(object sender, EventArgs e)
|
|
{
|
|
// invia a redis a a richiesta...
|
|
ComLib.sendMaterials();
|
|
ComLib.sendBatchReq(BatchId, "Nesting", 2);
|
|
|
|
// registro su DB nesting iniziato...
|
|
DataLayer.man.taBL.updateStatus(BatchId, (int)BatchStatus.NestRequested, "", -1);
|
|
raiseEvent();
|
|
}
|
|
|
|
private void raiseEvent()
|
|
{
|
|
// se qualcuno ascolta sollevo evento nuovo valore...
|
|
if (eh_doRefresh != null)
|
|
{
|
|
eh_doRefresh(this, new EventArgs());
|
|
}
|
|
}
|
|
}
|
|
} |