Files
NKC/NKC_WF/WebUserControls/cmp_batchDetail.ascx.cs
T
Samuele E. Locatelli 82a87a8152 Inizio fix BIN
2020-01-19 12:35:49 +01:00

250 lines
8.0 KiB
C#

using AppData;
using NKC_SDK;
using SteamWare;
using System;
using System.Collections.Generic;
using System.Text;
namespace NKC_WF.WebUserControls
{
public partial class cmp_batchDetail : System.Web.UI.UserControl
{
public event EventHandler eh_doRefresh;
protected void Page_Load(object sender, EventArgs e)
{
}
public int BatchId
{
set
{
hfBatchId.Value = value.ToString();
frmView.DataBind();
if (memLayer.ML.CRB("enableMongo"))
{
// cerco da lista salvataggi Estim/Nest...
var estimAnsw = ComLib.man.getEstAnsw(value);
var nestAnsw = ComLib.man.getNestAnsw(value);
StringBuilder sb = new StringBuilder();
sb.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
{
sb.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)
{
sb.AppendLine("---------------------");
sb.AppendLine($"ESTIM: FOUND {partListEstimDupl.Count} duplicate:");
foreach (var partId in partListEstimDupl)
{
sb.AppendLine($"{partId}");
}
sb.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
{ }
//il tot delle part è in bunk > Sheet > part
int totPartNum = 0;
foreach (var bunk in nestAnsw.BunkList)
{
foreach (var sheet in bunk.SheetList)
{
totPartNum += sheet.PartList.Count;
}
}
try
{
sb.AppendLine($"NEST: EnvNum: {nestAnsw.EnvNum} | Worktime: {nestAnsw.EstimatedWorktime / 60:N2} min | Processing Runtime {nestAnsw.ProcessingRuntime / 60:N2} min | Bunks #: {nestAnsw.BunkList.Count} | Carts #: {nestAnsw.CartList.Count} | Parts #: {totPartNum}");
// se ho duplicati indico:
if (partListNestDupl.Count > 0)
{
sb.AppendLine("---------------------");
sb.AppendLine($"NEST: FOUND {partListNestDupl.Count} duplicate:");
foreach (var partId in partListNestDupl)
{
sb.AppendLine($"{partId}");
}
sb.AppendLine("---------------------");
}
// s enon corrispondono
if (partListEstim.Count != partListNest.Count)
{
sb.AppendLine("---------------------");
if (partListEstim.Count > partListNest.Count)
{
sb.AppendLine($"EST OK | NEST missing:");
foreach (var partId in partListEstim)
{
if (!partListNest.Contains(partId))
{
sb.AppendLine($"{partId}");
}
}
}
else
{
sb.AppendLine($"EST missing | NEST OK:");
foreach (var partId in partListNest)
{
if (!partListEstim.Contains(partId))
{
sb.AppendLine($"{partId}");
}
}
}
sb.AppendLine("---------------------");
}
}
catch
{ }
}
lblTestJson.Text = sb.Replace("\r\n", "<br/>").ToString();
}
}
get
{
int answ = 0;
int.TryParse(hfBatchId.Value, out answ);
return answ;
}
}
/// <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;
}
public bool canStartNew(object _status)
{
bool answ = false;
// in primis controllo SE ci siano task running, nel qual caso è false e basta...
int numEst = DataLayer.man.taBL.getByStatus((int)BatchStatus.EstimationRequested, "", 0).Count;
int numNest = DataLayer.man.taBL.getByStatus((int)BatchStatus.NestRequested, "", 0).Count;
answ = ((numEst + numNest) == 0);
return answ;
}
/// <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)
{
// !!!FIXME!!! inviare a redis...
// 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)
{
// !!!FIXME!!! inviare a redis...
// 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());
}
}
}
}