diff --git a/AppData/ComLib.cs b/AppData/ComLib.cs index ad5be65..fdcf5cb 100644 --- a/AppData/ComLib.cs +++ b/AppData/ComLib.cs @@ -794,6 +794,29 @@ namespace AppData return answ; } + /// + /// Stato batch (bozza/stima/nesting...) + /// + /// + /// + public static BatchStatus BStatus(int BatchId) + { + DataLayer DLMan = new DataLayer(); + BatchStatus answ = BatchStatus.Imported; + DS_App.BatchListDataTable tabBatch = DLMan.taBL.getByKey(BatchId); + if (tabBatch != null && tabBatch.Count > 0) + { + try + { + // mostro split se di tipo 1... + answ = (BatchStatus)tabBatch[0].STATUS; + } + catch + { } + } + return answ; + } + /// /// Tipo batch tra ancestor/descendant /// @@ -802,7 +825,7 @@ namespace AppData public static BatchType BType(int BatchId) { DataLayer DLMan = new DataLayer(); - BatchType answ = NKC_SDK.BatchType.Original; + BatchType answ = BatchType.Original; DS_App.BatchListDataTable tabBatch = DLMan.taBL.getByKey(BatchId); if (tabBatch != null && tabBatch.Count > 0) { diff --git a/NKC_WF/NKC_WF.csproj b/NKC_WF/NKC_WF.csproj index b702569..2eae9ce 100644 --- a/NKC_WF/NKC_WF.csproj +++ b/NKC_WF/NKC_WF.csproj @@ -477,6 +477,9 @@ + + + @@ -1098,6 +1101,27 @@ cmp_batchDetail.ascx + + cmp_batchDetailData.ascx + ASPXCodeBehind + + + cmp_batchDetailData.ascx + + + cmp_batchDetailSplit.ascx + ASPXCodeBehind + + + cmp_batchDetailSplit.ascx + + + cmp_batchDetailSplitInfo.ascx + ASPXCodeBehind + + + cmp_batchDetailSplitInfo.ascx + cmp_batchList.ascx ASPXCodeBehind diff --git a/NKC_WF/WebUserControls/cmp_batchDetail.ascx b/NKC_WF/WebUserControls/cmp_batchDetail.ascx index 396298a..0f7594c 100644 --- a/NKC_WF/WebUserControls/cmp_batchDetail.ascx +++ b/NKC_WF/WebUserControls/cmp_batchDetail.ascx @@ -1,5 +1,7 @@ <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="cmp_batchDetail.ascx.cs" Inherits="NKC_WF.WebUserControls.cmp_batchDetail" %> -<%@ Register Src="~/WebUserControls/cmp_orderExtList.ascx" TagPrefix="uc1" TagName="cmp_orderExtList" %> +<%@ Register Src="~/WebUserControls/cmp_batchDetailSplit.ascx" TagPrefix="uc1" TagName="cmp_batchDetailSplit" %> + +<%--<%@ Register Src="~/WebUserControls/cmp_orderExtList.ascx" TagPrefix="uc1" TagName="cmp_orderExtList" %>--%> @@ -96,7 +98,10 @@ - + + + +<%-- <%: traduci("BatchSplit") %> @@ -122,7 +127,7 @@ - + @@ -142,10 +147,10 @@ - + - \ No newline at end of file +--%> \ No newline at end of file diff --git a/NKC_WF/WebUserControls/cmp_batchDetail.ascx.cs b/NKC_WF/WebUserControls/cmp_batchDetail.ascx.cs index 7f3100d..1683ae2 100644 --- a/NKC_WF/WebUserControls/cmp_batchDetail.ascx.cs +++ b/NKC_WF/WebUserControls/cmp_batchDetail.ascx.cs @@ -10,16 +10,9 @@ namespace NKC_WF.WebUserControls { public partial class cmp_batchDetail : BaseUserControl { - #region Protected Fields - - // place master hard-coded - protected string PlaceCod = "VIRTNE"; - - #endregion Protected Fields - #region Protected Properties - protected bool batchIsAncestor + protected bool BatchIsAncestor { get { @@ -27,96 +20,6 @@ namespace NKC_WF.WebUserControls } } - protected double fullTime - { - get - { - double answ = 1; - if (!string.IsNullOrEmpty(hfFullTime.Value)) - { - double.TryParse(hfFullTime.Value, out answ); - } - return answ; - } - set - { - hfFullTime.Value = $"{value}"; - } - } - - protected int lastValRatio - { - get - { - int answ = 50; - if (!string.IsNullOrEmpty(hfLastRatio.Value)) - { - int.TryParse(hfLastRatio.Value, out answ); - } - return answ; - } - set - { - hfLastRatio.Value = $"{value}"; - } - } - - protected bool needSave - { - get - { - bool answ = true; - bool.TryParse(hfNeedSave.Value, out answ); - return answ; - } - set - { - hfNeedSave.Value = $"{value}"; - } - } - - /// - /// Tabella dei batch Descendant di quello corrente - /// - protected DS_App.BatchListDataTable TabBatchDesc - { - get - { - return ComLib.BatchDescendant(BatchId); - } - } - - protected DS_App.OrderListTreeDataTable TabOrders - { - get - { - // cerco in redis - return ComLib.OrdersExtByBatch(BatchId); - } - } - - protected int valRatio - { - get - { - int answ = 50; - if (!string.IsNullOrEmpty(txtRatio.Text)) - { - int.TryParse(txtRatio.Text, out answ); - } - return answ; - } - set - { - txtRatio.Text = $"{value}"; - // scrivo ANCHE i valori assoluti - lblRatio01.Text = $"{valRatio} %"; - lblRatio02.Text = $"{100 - valRatio} %"; - lblTime01.Text = $"{fullTime * value / (100 * 60):N2} h"; - lblTime02.Text = $"{fullTime * (100 - value) / (100 * 60):N2} h"; - } - } - #endregion Protected Properties #region Public Properties @@ -309,11 +212,9 @@ namespace NKC_WF.WebUserControls lblTestJson.Text = "" + sbDebug.Replace("\r\n", "").ToString(); } } + cmp_batchDetailSplit.BatchId = value; if (BatchId > 0) { - checkCreateDescendant(); - showBatchDescendant(); - fixChildBatch(); fixDisplayDesc(); } } @@ -341,211 +242,15 @@ namespace NKC_WF.WebUserControls #region Private Methods - private void checkCreateDescendant() - { - // se ho un batchId... - if (BatchId != 0) - { - // verifico se ho descendant - if (TabBatchDesc.Rows.Count == 0) - { - // altrimenti creo... - DLMan.taBL.makeDescendantByKey(BatchId, PlaceCod); - } - } - } - - private void fixChildBatch() - { - DS_App.BatchListDataTable TabBatch = TabBatchDesc; - cmp_orderExtListNE01.BatchId = TabBatch.Rows.Count > 0 ? TabBatchDesc[0].BatchID : 0; - cmp_orderExtListNE02.BatchId = TabBatch.Rows.Count > 0 ? TabBatchDesc[1].BatchID : 0; - cmp_orderExtListNE01.doUpdate(); - cmp_orderExtListNE02.doUpdate(); - } - private void fixDisplayDesc() { - divSplit.Visible = batchIsAncestor; - } - - private void fixRatio() - { - // sistemazione ratio calcolata... - DS_App.OrderListTreeDataTable tabNe01 = DLMan.taOLT.getByBatch(cmp_orderExtListNE01.BatchId); - DS_App.OrderListTreeDataTable tabNe02 = DLMan.taOLT.getByBatch(cmp_orderExtListNE02.BatchId); - - double totTime01 = tabNe01.Sum(x => x.EstProcTime); - double totTime02 = tabNe02.Sum(x => x.EstProcTime); - - // aggiorno valore ratio e ratio last... - fullTime = totTime01 + totTime02; - fullTime = fullTime > 0 ? fullTime : 1; - double newRatio = (totTime01 * 100 / fullTime); - valRatio = (int)newRatio; - lastValRatio = valRatio; - } - - /// - /// effettua ribilanciamento ordini partendo da elenco completo e poi assegnando a impianti - /// - private void rebalanceOrder() - { - // solo se variato il ratio... - if (valRatio != lastValRatio) - { - // costruisco vettore durata ordini - OrderSetSim FullSet = new OrderSetSim(); - OrderSetSim SetNe01 = new OrderSetSim(); - OrderSetSim SetNe02 = new OrderSetSim(); - - // creo liste x i valori da processare... - Dictionary RawList = new Dictionary(); - Dictionary OrderedList = new Dictionary(); - - foreach (var item in TabOrders) - { - RawList.Add(item.OrdID, item.EstProcTime); - } - - // ordino la lista x processing successivo - OrderedList = RawList.OrderBy(x => x.Value).ToDictionary(t => t.Key, t => t.Value); - - // salvo i set - FullSet.OrderSet = OrderedList; - - // lavoro sull'ottimizzare il MINORE - double ValRatio = (double)valRatio / 100; - if (ValRatio <= 0.5) - { - SetNe01.TargetValue = FullSet.ActualValue * ValRatio; - SetNe01.OrderSet = findLocalMin(OrderedList, SetNe01.TargetValue); - // l'altro è la differenza - SetNe02.OrderSet = OrderedList; - foreach (var item in SetNe01.OrderSet) - { - SetNe02.OrderSet.Remove(item.Key); - } - } - else - { - SetNe02.TargetValue = FullSet.ActualValue * (1 - ValRatio); - SetNe02.OrderSet = findLocalMin(OrderedList, SetNe02.TargetValue); - // l'altro è la differenza - SetNe01.OrderSet = OrderedList; - foreach (var item in SetNe02.OrderSet) - { - SetNe01.OrderSet.Remove(item.Key); - } - } - - // riorganizzo tabOrders... - foreach (var orderItem in TabOrders) - { - if (SetNe01.OrderSet.ContainsKey(orderItem.OrdID)) - { - if (orderItem.BatchID != cmp_orderExtListNE01.BatchId) - { - DLMan.taOLT.updateBatch(orderItem.BatchID, orderItem.OrdID, cmp_orderExtListNE01.BatchId); - } - } - else - { - if (orderItem.BatchID != cmp_orderExtListNE02.BatchId) - { - DLMan.taOLT.updateBatch(orderItem.BatchID, orderItem.OrdID, cmp_orderExtListNE02.BatchId); - } - } - } - - // --> richiede salvataggio - needSave = true; - } - fixRatio(); - } - - /// - /// Mostro dati dei Batch descendant - /// - private void showBatchDescendant() - { - // suddivido - rebalanceOrder(); + divSplit.Visible = BatchIsAncestor; } #endregion Private Methods #region Protected Methods - /// - /// Cerca il set con lo score migliore calcolando x subset della lista ordinata - /// - /// Lista ordinata oggetti (INT) + valore - /// Valore desiderato (comeSOMMA) - /// - protected Dictionary findLocalMin(Dictionary OrderedList, double TargetVal) - { - Dictionary answ = new Dictionary(); - List Candidates = new List(); - OrderSetSim CurrSimSet = new OrderSetSim(); - - // parte dal valore (singolo) più piccolo tra quelli maggiori del target... se c'è... - var OrdSup = OrderedList.Where(x => x.Value > TargetVal).OrderBy(x => x.Value); - if (OrdSup != null && OrdSup.Any()) - { - var currOrder = OrdSup.FirstOrDefault(); - CurrSimSet = new OrderSetSim(); - CurrSimSet.TargetValue = TargetVal; - CurrSimSet.OrderSet.Add(currOrder.Key, currOrder.Value); - Candidates.Add(CurrSimSet); - } - - // ora guardo gli elementi restanti.. se ci sono - var OrdInf = OrderedList.Where(x => x.Value <= TargetVal).OrderByDescending(x => x.Value).ToDictionary(t => t.Key, t => t.Value); - if (OrdInf != null && OrdInf.Any()) - { - var currOrder = OrdInf.FirstOrDefault(); - CurrSimSet = new OrderSetSim(); - CurrSimSet.TargetValue = TargetVal; - CurrSimSet.OrderSet.Add(currOrder.Key, currOrder.Value); - Candidates.Add(CurrSimSet); - // prendo i restanti tranne il primo - OrdInf.Remove(currOrder.Key); - // se rimane qualcosa... - if (OrdInf != null && OrdInf.Any()) - { - // calcolo il minimo locale nei 2 casi, da soli - Dictionary TestOrderSet01 = findLocalMin(OrdInf, TargetVal); - if (TestOrderSet01.Count > 0) - { - OrderSetSim CurrSet = new OrderSetSim(); - CurrSet.TargetValue = TargetVal; - CurrSet.OrderSet = TestOrderSet01; - Candidates.Add(CurrSet); - } - // ...e con il primo valore... - Dictionary TestOrderSet02 = findLocalMin(OrdInf, TargetVal - currOrder.Value); - TestOrderSet02.Add(currOrder.Key, currOrder.Value); - // verifico se migliorativo... - if (TestOrderSet02.Count > 0) - { - OrderSetSim CurrSet = new OrderSetSim(); - CurrSet.TargetValue = TargetVal - currOrder.Value; - CurrSet.OrderSet = TestOrderSet02; - Candidates.Add(CurrSet); - } - } - } - // cerco il minimo... - if (Candidates != null && Candidates.Count > 0) - { - answ = Candidates.OrderBy(x => x.IndexScore).FirstOrDefault().OrderSet; - } - - // calcolo il minimo e lo restituisco... - return answ; - } - protected void lbtAccept_Click(object sender, EventArgs e) { // registro accettazione Nesting @@ -569,7 +274,7 @@ namespace NKC_WF.WebUserControls // invia a redis a a richiesta... ComLib.sendMaterials(); // controllo SE SIA un batch ANCESTOR --> invio il PRIMO batch da calcolare... - if (batchIsAncestor) + if (BatchIsAncestor) { // effettuo VERA ri-assegnazione ordini/kit a nuovi batch DLMan.taOLT.setBatchSplit(BatchId, true); @@ -613,15 +318,6 @@ namespace NKC_WF.WebUserControls raiseEvent(); } - /// - /// Init di base - /// - /// - protected override void OnInit(EventArgs e) - { - checkCreateDescendant(); - } - protected void Page_Load(object sender, EventArgs e) { } @@ -638,12 +334,6 @@ namespace NKC_WF.WebUserControls return num / den; } - protected void txtRatio_TextChanged(object sender, EventArgs e) - { - rebalanceOrder(); - fixChildBatch(); - } - #endregion Protected Methods #region Internal Methods diff --git a/NKC_WF/WebUserControls/cmp_batchDetail.ascx.designer.cs b/NKC_WF/WebUserControls/cmp_batchDetail.ascx.designer.cs index 7c0a362..e123e67 100644 --- a/NKC_WF/WebUserControls/cmp_batchDetail.ascx.designer.cs +++ b/NKC_WF/WebUserControls/cmp_batchDetail.ascx.designer.cs @@ -78,93 +78,12 @@ namespace NKC_WF.WebUserControls protected global::System.Web.UI.HtmlControls.HtmlGenericControl divSplit; /// - /// hfNeedSave control. + /// cmp_batchDetailSplit control. /// /// /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// - protected global::System.Web.UI.WebControls.HiddenField hfNeedSave; - - /// - /// hfLastRatio control. - /// - /// - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// - protected global::System.Web.UI.WebControls.HiddenField hfLastRatio; - - /// - /// hfFullTime control. - /// - /// - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// - protected global::System.Web.UI.WebControls.HiddenField hfFullTime; - - /// - /// txtRatio control. - /// - /// - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// - protected global::System.Web.UI.WebControls.TextBox txtRatio; - - /// - /// lblTime01 control. - /// - /// - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// - protected global::System.Web.UI.WebControls.Label lblTime01; - - /// - /// lblRatio01 control. - /// - /// - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// - protected global::System.Web.UI.WebControls.Label lblRatio01; - - /// - /// cmp_orderExtListNE01 control. - /// - /// - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// - protected global::NKC_WF.WebUserControls.cmp_orderExtList cmp_orderExtListNE01; - - /// - /// lblTime02 control. - /// - /// - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// - protected global::System.Web.UI.WebControls.Label lblTime02; - - /// - /// lblRatio02 control. - /// - /// - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// - protected global::System.Web.UI.WebControls.Label lblRatio02; - - /// - /// cmp_orderExtListNE02 control. - /// - /// - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// - protected global::NKC_WF.WebUserControls.cmp_orderExtList cmp_orderExtListNE02; + protected global::NKC_WF.WebUserControls.cmp_batchDetailSplit cmp_batchDetailSplit; } } diff --git a/NKC_WF/WebUserControls/cmp_batchDetailData.ascx b/NKC_WF/WebUserControls/cmp_batchDetailData.ascx new file mode 100644 index 0000000..ba5a96a --- /dev/null +++ b/NKC_WF/WebUserControls/cmp_batchDetailData.ascx @@ -0,0 +1 @@ +<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="cmp_batchDetailData.ascx.cs" Inherits="NKC_WF.WebUserControls.cmp_batchDetailData" %> diff --git a/NKC_WF/WebUserControls/cmp_batchDetailData.ascx.cs b/NKC_WF/WebUserControls/cmp_batchDetailData.ascx.cs new file mode 100644 index 0000000..67c14b9 --- /dev/null +++ b/NKC_WF/WebUserControls/cmp_batchDetailData.ascx.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using System.Web.UI; +using System.Web.UI.WebControls; + +namespace NKC_WF.WebUserControls +{ + public partial class cmp_batchDetailData : System.Web.UI.UserControl + { + protected void Page_Load(object sender, EventArgs e) + { + + } + } +} \ No newline at end of file diff --git a/NKC_WF/WebUserControls/cmp_batchDetailData.ascx.designer.cs b/NKC_WF/WebUserControls/cmp_batchDetailData.ascx.designer.cs new file mode 100644 index 0000000..97e1998 --- /dev/null +++ b/NKC_WF/WebUserControls/cmp_batchDetailData.ascx.designer.cs @@ -0,0 +1,16 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + + +namespace NKC_WF.WebUserControls +{ + public partial class cmp_batchDetailData + { + } +} diff --git a/NKC_WF/WebUserControls/cmp_batchDetailSplit.ascx b/NKC_WF/WebUserControls/cmp_batchDetailSplit.ascx new file mode 100644 index 0000000..1ed9625 --- /dev/null +++ b/NKC_WF/WebUserControls/cmp_batchDetailSplit.ascx @@ -0,0 +1,60 @@ +<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="cmp_batchDetailSplit.ascx.cs" Inherits="NKC_WF.WebUserControls.cmp_batchDetailSplit" %> +<%@ Register Src="~/WebUserControls/cmp_orderExtList.ascx" TagPrefix="uc1" TagName="cmp_orderExtList" %> +<%@ Register Src="~/WebUserControls/cmp_batchDetailSplitInfo.ascx" TagPrefix="uc1" TagName="cmp_batchDetailSplitInfo" %> + + + + <%: traduci("BatchSplit") %> + + + + + + + + + + + + + + + + + NE01 + + + + + + + + + + + + + + + + + + + + + NE02 + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/NKC_WF/WebUserControls/cmp_batchDetailSplit.ascx.cs b/NKC_WF/WebUserControls/cmp_batchDetailSplit.ascx.cs new file mode 100644 index 0000000..83df85c --- /dev/null +++ b/NKC_WF/WebUserControls/cmp_batchDetailSplit.ascx.cs @@ -0,0 +1,394 @@ +using AppData; +using NKC_SDK; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using System.Web.UI; +using System.Web.UI.WebControls; + +namespace NKC_WF.WebUserControls +{ + public partial class cmp_batchDetailSplit : BaseUserControl + { + #region Protected Fields + + /// + /// Master Place (hard-coded) + /// + protected string PlaceCod = "VIRTNE"; + + #endregion Protected Fields + + #region Protected Properties + + protected bool BatchIsAncestor + { + get + { + return ComLib.BType(BatchId) == BatchType.Ancestor; + } + } + + /// + /// Status corrente del batch + /// + protected BatchStatus CurrBatchStatus + { + get + { + return ComLib.BStatus(BatchId); + } + } + + protected double fullTime + { + get + { + double answ = 1; + if (!string.IsNullOrEmpty(hfFullTime.Value)) + { + double.TryParse(hfFullTime.Value, out answ); + } + return answ; + } + set + { + hfFullTime.Value = $"{value}"; + } + } + + protected int lastValRatio + { + get + { + int answ = 50; + if (!string.IsNullOrEmpty(hfLastRatio.Value)) + { + int.TryParse(hfLastRatio.Value, out answ); + } + return answ; + } + set + { + hfLastRatio.Value = $"{value}"; + } + } + + protected bool needSave + { + get + { + bool answ = true; + bool.TryParse(hfNeedSave.Value, out answ); + return answ; + } + set + { + hfNeedSave.Value = $"{value}"; + } + } + + /// + /// Tabella dei batch Descendant di quello corrente + /// + protected DS_App.BatchListDataTable TabBatchDesc + { + get + { + return ComLib.BatchDescendant(BatchId); + } + } + + protected DS_App.OrderListTreeDataTable TabOrders + { + get + { + // cerco in redis + return ComLib.OrdersExtByBatch(BatchId); + } + } + + protected int valRatio + { + get + { + int answ = 50; + if (!string.IsNullOrEmpty(txtRatio.Text)) + { + int.TryParse(txtRatio.Text, out answ); + } + return answ; + } + set + { + txtRatio.Text = $"{value}"; + // scrivo ANCHE i valori assoluti + lblRatio01.Text = $"{valRatio} %"; + lblRatio02.Text = $"{100 - valRatio} %"; + lblTime01.Text = $"{fullTime * value / (100 * 60):N2} h"; + lblTime02.Text = $"{fullTime * (100 - value) / (100 * 60):N2} h"; + } + } + + #endregion Protected Properties + + #region Public Properties + + public int BatchId + { + set + { + hfBatchId.Value = value.ToString(); + if (BatchId > 0) + { + checkCreateDescendant(); + showBatchDescendant(); + fixChildBatch(); + checkDisplayMode(); + } + fixRatio(); + } + get + { + int answ = 0; + int.TryParse(hfBatchId.Value, out answ); + return answ; + } + } + + #endregion Public Properties + + #region Private Methods + + private void checkCreateDescendant() + { + // se ho un batchId... + if (BatchId != 0) + { + // verifico se ho descendant + if (TabBatchDesc.Rows.Count == 0) + { + // altrimenti creo... + DLMan.taBL.makeDescendantByKey(BatchId, PlaceCod); + } + } + } + + /// + /// verifico modalità display (editing solo se PRIMA di lanciare nesting...) + /// + private void checkDisplayMode() + { + txtRatio.Visible = (BatchIsAncestor && CurrBatchStatus <= BatchStatus.EstimationDone); + cmp_orderExtListNE01.Visible = txtRatio.Visible; + cmp_orderExtListNE02.Visible = txtRatio.Visible; + cmp_batchDetailSplitInfoNE01.Visible = !txtRatio.Visible; + cmp_batchDetailSplitInfoNE02.Visible = !txtRatio.Visible; + } + + private void fixChildBatch() + { + DS_App.BatchListDataTable TabBatch = TabBatchDesc; + cmp_orderExtListNE01.BatchId = TabBatch.Rows.Count > 0 ? TabBatchDesc[0].BatchID : 0; + cmp_orderExtListNE02.BatchId = TabBatch.Rows.Count > 0 ? TabBatchDesc[1].BatchID : 0; + cmp_orderExtListNE01.doUpdate(); + cmp_orderExtListNE02.doUpdate(); + cmp_batchDetailSplitInfoNE01.BatchId = cmp_orderExtListNE01.BatchId; + cmp_batchDetailSplitInfoNE02.BatchId = cmp_orderExtListNE02.BatchId; + } + + private void fixRatio() + { + // sistemazione ratio calcolata... + DS_App.OrderListTreeDataTable tabNe01 = DLMan.taOLT.getByBatch(cmp_orderExtListNE01.BatchId); + DS_App.OrderListTreeDataTable tabNe02 = DLMan.taOLT.getByBatch(cmp_orderExtListNE02.BatchId); + + double totTime01 = tabNe01.Sum(x => x.EstProcTime); + double totTime02 = tabNe02.Sum(x => x.EstProcTime); + + // aggiorno valore ratio e ratio last... + fullTime = totTime01 + totTime02; + fullTime = fullTime > 0 ? fullTime : 1; + double newRatio = (totTime01 * 100 / fullTime); + valRatio = (int)newRatio; + lastValRatio = valRatio; + } + + /// + /// effettua ribilanciamento ordini partendo da elenco completo e poi assegnando a impianti + /// + private void rebalanceOrder() + { + // solo se variato il ratio... + if (valRatio != lastValRatio) + { + // costruisco vettore durata ordini + OrderSetSim FullSet = new OrderSetSim(); + OrderSetSim SetNe01 = new OrderSetSim(); + OrderSetSim SetNe02 = new OrderSetSim(); + + // creo liste x i valori da processare... + Dictionary RawList = new Dictionary(); + Dictionary OrderedList = new Dictionary(); + + foreach (var item in TabOrders) + { + RawList.Add(item.OrdID, item.EstProcTime); + } + + // ordino la lista x processing successivo + OrderedList = RawList.OrderBy(x => x.Value).ToDictionary(t => t.Key, t => t.Value); + + // salvo i set + FullSet.OrderSet = OrderedList; + + // lavoro sull'ottimizzare il MINORE + double ValRatio = (double)valRatio / 100; + if (ValRatio <= 0.5) + { + SetNe01.TargetValue = FullSet.ActualValue * ValRatio; + SetNe01.OrderSet = findLocalMin(OrderedList, SetNe01.TargetValue); + // l'altro è la differenza + SetNe02.OrderSet = OrderedList; + foreach (var item in SetNe01.OrderSet) + { + SetNe02.OrderSet.Remove(item.Key); + } + } + else + { + SetNe02.TargetValue = FullSet.ActualValue * (1 - ValRatio); + SetNe02.OrderSet = findLocalMin(OrderedList, SetNe02.TargetValue); + // l'altro è la differenza + SetNe01.OrderSet = OrderedList; + foreach (var item in SetNe02.OrderSet) + { + SetNe01.OrderSet.Remove(item.Key); + } + } + + // riorganizzo tabOrders... + foreach (var orderItem in TabOrders) + { + if (SetNe01.OrderSet.ContainsKey(orderItem.OrdID)) + { + if (orderItem.BatchID != cmp_orderExtListNE01.BatchId) + { + DLMan.taOLT.updateBatch(orderItem.BatchID, orderItem.OrdID, cmp_orderExtListNE01.BatchId); + } + } + else + { + if (orderItem.BatchID != cmp_orderExtListNE02.BatchId) + { + DLMan.taOLT.updateBatch(orderItem.BatchID, orderItem.OrdID, cmp_orderExtListNE02.BatchId); + } + } + } + + // --> richiede salvataggio + needSave = true; + } + fixRatio(); + } + + /// + /// Mostro dati dei Batch descendant + /// + private void showBatchDescendant() + { + // suddivido + rebalanceOrder(); + } + + #endregion Private Methods + + #region Protected Methods + + /// + /// Cerca il set con lo score migliore calcolando x subset della lista ordinata + /// + /// Lista ordinata oggetti (INT) + valore + /// Valore desiderato (comeSOMMA) + /// + protected Dictionary findLocalMin(Dictionary OrderedList, double TargetVal) + { + Dictionary answ = new Dictionary(); + List Candidates = new List(); + OrderSetSim CurrSimSet = new OrderSetSim(); + + // parte dal valore (singolo) più piccolo tra quelli maggiori del target... se c'è... + var OrdSup = OrderedList.Where(x => x.Value > TargetVal).OrderBy(x => x.Value); + if (OrdSup != null && OrdSup.Any()) + { + var currOrder = OrdSup.FirstOrDefault(); + CurrSimSet = new OrderSetSim(); + CurrSimSet.TargetValue = TargetVal; + CurrSimSet.OrderSet.Add(currOrder.Key, currOrder.Value); + Candidates.Add(CurrSimSet); + } + + // ora guardo gli elementi restanti.. se ci sono + var OrdInf = OrderedList.Where(x => x.Value <= TargetVal).OrderByDescending(x => x.Value).ToDictionary(t => t.Key, t => t.Value); + if (OrdInf != null && OrdInf.Any()) + { + var currOrder = OrdInf.FirstOrDefault(); + CurrSimSet = new OrderSetSim(); + CurrSimSet.TargetValue = TargetVal; + CurrSimSet.OrderSet.Add(currOrder.Key, currOrder.Value); + Candidates.Add(CurrSimSet); + // prendo i restanti tranne il primo + OrdInf.Remove(currOrder.Key); + // se rimane qualcosa... + if (OrdInf != null && OrdInf.Any()) + { + // calcolo il minimo locale nei 2 casi, da soli + Dictionary TestOrderSet01 = findLocalMin(OrdInf, TargetVal); + if (TestOrderSet01.Count > 0) + { + OrderSetSim CurrSet = new OrderSetSim(); + CurrSet.TargetValue = TargetVal; + CurrSet.OrderSet = TestOrderSet01; + Candidates.Add(CurrSet); + } + // ...e con il primo valore... + Dictionary TestOrderSet02 = findLocalMin(OrdInf, TargetVal - currOrder.Value); + TestOrderSet02.Add(currOrder.Key, currOrder.Value); + // verifico se migliorativo... + if (TestOrderSet02.Count > 0) + { + OrderSetSim CurrSet = new OrderSetSim(); + CurrSet.TargetValue = TargetVal - currOrder.Value; + CurrSet.OrderSet = TestOrderSet02; + Candidates.Add(CurrSet); + } + } + } + // cerco il minimo... + if (Candidates != null && Candidates.Count > 0) + { + answ = Candidates.OrderBy(x => x.IndexScore).FirstOrDefault().OrderSet; + } + + // calcolo il minimo e lo restituisco... + return answ; + } + + protected void Page_Load(object sender, EventArgs e) + { + if (!Page.IsPostBack) + { + checkDisplayMode(); + } + } + + protected void txtRatio_TextChanged(object sender, EventArgs e) + { + rebalanceOrder(); + fixChildBatch(); + } + + #endregion Protected Methods + } +} \ No newline at end of file diff --git a/NKC_WF/WebUserControls/cmp_batchDetailSplit.ascx.designer.cs b/NKC_WF/WebUserControls/cmp_batchDetailSplit.ascx.designer.cs new file mode 100644 index 0000000..d0d3bc9 --- /dev/null +++ b/NKC_WF/WebUserControls/cmp_batchDetailSplit.ascx.designer.cs @@ -0,0 +1,134 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace NKC_WF.WebUserControls +{ + + + public partial class cmp_batchDetailSplit + { + + /// + /// hfBatchId control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.HiddenField hfBatchId; + + /// + /// hfNeedSave control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.HiddenField hfNeedSave; + + /// + /// hfLastRatio control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.HiddenField hfLastRatio; + + /// + /// hfFullTime control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.HiddenField hfFullTime; + + /// + /// txtRatio control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.TextBox txtRatio; + + /// + /// lblTime01 control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.Label lblTime01; + + /// + /// lblRatio01 control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.Label lblRatio01; + + /// + /// cmp_orderExtListNE01 control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::NKC_WF.WebUserControls.cmp_orderExtList cmp_orderExtListNE01; + + /// + /// cmp_batchDetailSplitInfoNE01 control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::NKC_WF.WebUserControls.cmp_batchDetailSplitInfo cmp_batchDetailSplitInfoNE01; + + /// + /// lblTime02 control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.Label lblTime02; + + /// + /// lblRatio02 control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.Label lblRatio02; + + /// + /// cmp_orderExtListNE02 control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::NKC_WF.WebUserControls.cmp_orderExtList cmp_orderExtListNE02; + + /// + /// cmp_batchDetailSplitInfoNE02 control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::NKC_WF.WebUserControls.cmp_batchDetailSplitInfo cmp_batchDetailSplitInfoNE02; + } +} diff --git a/NKC_WF/WebUserControls/cmp_batchDetailSplitInfo.ascx b/NKC_WF/WebUserControls/cmp_batchDetailSplitInfo.ascx new file mode 100644 index 0000000..20fd80e --- /dev/null +++ b/NKC_WF/WebUserControls/cmp_batchDetailSplitInfo.ascx @@ -0,0 +1,40 @@ +<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="cmp_batchDetailSplitInfo.ascx.cs" Inherits="NKC_WF.WebUserControls.cmp_batchDetailSplitInfo" %> + + + + + + + + <%# Eval("Takt") %> + + + Estim.Time: <%# Eval("TotalTime","{0:N2}") %> min + + + + + + + <%# BStatus(Eval("Status")) %> + + + + + + + + + + <%# $"{Eval("Errors")} (tot: {Eval("NumErrPre")} err)" %> + <%# $"{Eval("Errors")} (tot: {Eval("NumErr")} err)" %> + + + + + + + + + + \ No newline at end of file diff --git a/NKC_WF/WebUserControls/cmp_batchDetailSplitInfo.ascx.cs b/NKC_WF/WebUserControls/cmp_batchDetailSplitInfo.ascx.cs new file mode 100644 index 0000000..e448fb9 --- /dev/null +++ b/NKC_WF/WebUserControls/cmp_batchDetailSplitInfo.ascx.cs @@ -0,0 +1,182 @@ +using AppData; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using System.Web.UI; +using System.Web.UI.WebControls; + +namespace NKC_WF.WebUserControls +{ + public partial class cmp_batchDetailSplitInfo : BaseUserControl + { + #region Public Properties + + public int BatchId + { + set + { + hfBatchId.Value = value.ToString(); + } + get + { + int answ = 0; + int.TryParse(hfBatchId.Value, out answ); + return answ; + } + } + + #endregion Public Properties + + #region Protected Methods + + protected void Page_Load(object sender, EventArgs e) + { + } + + #endregion Protected Methods + + #region Public Methods + + /// + /// Converte il codice stato in effettivo campo + /// + /// + /// + public string BStatus(object _status) + { + string answ = ComLib.BatchStatusDescr(_status); + return answ; + } + + /// + /// Codice CSS in base a status... + /// + /// + /// + public string cssByStatus(object _status) + { + string answ = "text-muted"; + int status = -1; + int.TryParse(_status.ToString(), out status); + switch (status) + { + case 1: + answ = "font-weight-bold text-info"; + break; + + case 2: + answ = "font-weight-bold text-primary"; + break; + + case 3: + answ = "font-weight-bold text-warning"; + break; + + case 4: + answ = "font-weight-bold text-danger"; + break; + + case 5: + answ = "font-weight-bold text-success"; + break; + + case 6: + answ = "font-weight-bold text-secondary"; + break; + + default: + break; + } + return answ; + } + + /// + /// Codice CSS in base a BatchType... + /// + /// + /// + public string cssIconByType(object _BatchType) + { + string answ = "fa fa-circle-thin"; + int status = -1; + int.TryParse(_BatchType.ToString(), out status); + switch (status) + { + case 0: + answ = "fa fa-file-text-o"; + break; + + case 1: + answ = "fa fa-file-text"; + break; + + case 2: + answ = "fa fa-scissors"; + break; + + default: + break; + } + return answ; + } + + /// + /// Determina se sia visibile previewin base a BatchType... + /// + /// + /// + public bool hasPreviewByType(object _BatchType) + { + bool answ = false; + int status = -1; + int.TryParse(_BatchType.ToString(), out status); + switch (status) + { + case 0: + case 2: + answ = true; + break; + + case 1: + default: + answ = false; + break; + } + return answ; + } + + /// + /// Verifica se sia visualizzabile preview dato stato + /// + /// + /// + public bool isPreviewVisible(object _status) + { + bool answ = false; + int status = -1; + int.TryParse(_status.ToString(), out status); + // solo stati 4 (nesting done), 5 (approvato), 6 (eliminazione logica) + if (status > 3 && status < 7) + { + answ = true; + } + return answ; + } + + /// + /// Tooltip in base a BatchType... + /// + /// + /// + public string tooltipByType(object _BatchType) + { + string answ = "-"; + + answ = traduci($"tooltipBatchType_{_BatchType}"); + return answ; + } + + #endregion Public Methods + } +} \ No newline at end of file diff --git a/NKC_WF/WebUserControls/cmp_batchDetailSplitInfo.ascx.designer.cs b/NKC_WF/WebUserControls/cmp_batchDetailSplitInfo.ascx.designer.cs new file mode 100644 index 0000000..e77ab01 --- /dev/null +++ b/NKC_WF/WebUserControls/cmp_batchDetailSplitInfo.ascx.designer.cs @@ -0,0 +1,53 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace NKC_WF.WebUserControls +{ + + + public partial class cmp_batchDetailSplitInfo + { + + /// + /// hfBatchId control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.HiddenField hfBatchId; + + /// + /// frmView control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.FormView frmView; + + /// + /// hfDeleteEnabled control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.HiddenField hfDeleteEnabled; + + /// + /// ods control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.ObjectDataSource ods; + } +} diff --git a/NKC_WF/WebUserControls/cmp_orderExtList.ascx b/NKC_WF/WebUserControls/cmp_orderExtList.ascx index beba4e4..4f4ae40 100644 --- a/NKC_WF/WebUserControls/cmp_orderExtList.ascx +++ b/NKC_WF/WebUserControls/cmp_orderExtList.ascx @@ -1,6 +1,6 @@ <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="cmp_orderExtList.ascx.cs" Inherits="NKC_WF.WebUserControls.cmp_orderExtList" %> - + No record