using AppData; using NKC_SDK; using SteamWare; using System; using System.Web.UI; using System.Web.UI.WebControls; namespace NKC_WF.WebUserControls { public partial class cmp_batchList : BaseUserControl { #region Public Properties public bool ActionEnab { get { return chkActEnab.Checked; } set { chkActEnab.Checked = value; } } public bool deleteEnabled { get { bool answ = false; bool.TryParse(hfDeleteEnabled.Value, out answ); return answ; } set { hfDeleteEnabled.Value = value.ToString(); } } /// /// Indica se abilitare creazioen automatica dei PNG x le parts nel batch /// public bool forceCreatePng { get { bool answ = false; if (!string.IsNullOrEmpty(hfCreatePng.Value)) { bool.TryParse(hfCreatePng.Value, out answ); } return answ; } set { hfCreatePng.Value = $"{value}"; } } /// /// modalità funzionamento controllo /// public BatchListMode listMode { get; set; } = BatchListMode.Standard; public bool showSplit { get { return chkShowSplit.Checked; } set { chkShowSplit.Checked = value; } } #endregion Public Properties #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"; BatchStatus bStatus = (BatchStatus)Enum.Parse(typeof(BatchStatus), _status.ToString()); switch (bStatus) { case BatchStatus.Imported: break; case BatchStatus.EstimationRequested: answ = "btn btn-sm pe-none btn-info"; break; case BatchStatus.EstimationDone: answ = "btn btn-sm pe-none btn-primary"; break; case BatchStatus.NestRequested: answ = "btn btn-sm pe-none btn-warning"; break; case BatchStatus.NestDone: //answ = "font-weight-bold text-success"; answ = "btn btn-sm pe-none btn-success"; break; case BatchStatus.Approved: answ = "btn btn-sm pe-none btn-success"; break; case BatchStatus.Discarded: answ = "btn btn-sm pe-none btn-secondary"; break; case BatchStatus.Errors: case BatchStatus.ErrorsOnEstim: case BatchStatus.ErrorsOnNesting: answ = "btn btn-sm pe-none btn-danger"; break; case BatchStatus.PartOk: answ = "btn btn-sm pe-none btn-outline-success"; break; case BatchStatus.PartKo: answ = "btn btn-sm pe-none btn-outline-secondary"; 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; } public void doUpdate() { lblLastRefresh.Text = $"{DateTime.Now:HH:mm:ss}"; checkFixOds(); grView.DataBind(); currSelRow = lastSelRow; var currBStatus = CurrBatchStatus; fixDetails(); } /// /// 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 #region Protected Properties /// /// BatchId selezionato /// protected int BatchIdSel { get { int answ = 0; if (grView.SelectedValue != null) { int.TryParse(grView.SelectedValue.ToString(), out answ); } return answ; } } /// /// Status corrente del batch /// protected BatchStatus CurrBatchStatus { get { return ComLib.BStatus(BatchIdSel); } } protected int currSelRow { get { return grView.SelectedIndex; } set { grView.SelectedIndex = value; } } protected int lastSelRow { get { int answ = -1; try { answ = memLayer.ML.IntSessionObj("UsrLastBatchSel"); } catch { } return answ; } set { memLayer.ML.setSessionVal("UsrLastBatchSel", value); } } #endregion Protected Properties #region Protected Methods protected void chkShowSplit_CheckedChanged(object sender, EventArgs e) { // deseleziono... resetSelezione(); } protected void ddlStatus_SelectedIndexChanged(object sender, EventArgs e) { checkFixOds(); } protected void grView_PageIndexChanged(object sender, EventArgs e) { checkFixOds(); } protected void grView_SelectedIndexChanged(object sender, EventArgs e) { Timer1.Interval = slowTimer; fixDetails(); } protected void lbRedoEval_Click(object sender, EventArgs e) { LinkButton lbt = (LinkButton)sender; if (!string.IsNullOrEmpty(lbt.CommandArgument)) { // cerco batch... var prevBatch = DLMan.taBL.getLastByTakt(lbt.CommandArgument); if (prevBatch != null && prevBatch.Count > 0) { int BatchId = prevBatch[0].BatchID; // elimino gli errori vecchi della richiesta DS_App.BatchListDataTable batchTab = DLMan.taBL.getByKey(BatchId); if (batchTab != null && batchTab.Rows.Count > 0) { try { var bRow = (DS_App.BatchListRow)batchTab.Rows[0]; DLMan.taEL.deteteByParent("", bRow.EnvNum); // cerco se ci siano batch descendant... var childBatch = DLMan.taBL.getDescendByKey(BatchId); if (childBatch != null && childBatch.Count > 0) { foreach (var item in childBatch) { DLMan.taEL.deteteByParent("", item.EnvNum); } } } catch (Exception exc) { Log.Instance.Error($"Eccezione in eliminazione EL precedenti{Environment.NewLine}{exc}"); } } } // eseguo richiesta reset DLMan.taBL.redoPartValid(lbt.CommandArgument); // eventualmente mando primo batch da validare... bool newValidSent = ComLib.sendFirstValidationBatch(forceCreatePng); // refresh! resetSelezione(); } } protected void lbtDisableDel_Click(object sender, EventArgs e) { deleteEnabled = false; resetSelezione(); } protected void lbtEnableDel_Click(object sender, EventArgs e) { deleteEnabled = true; resetSelezione(); } /// /// comando reset /// /// /// protected void lbtReset_Click(object sender, EventArgs e) { resetSelezione(); } /// /// Caricamento pagina /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { deleteEnabled = false; cmp_numRow.numRow = 25; grView.PageSize = cmp_numRow.numRow; divDetail.Visible = false; // in base al ListMode decido cosa mostrare... checkFixOds(); checkFixMode(); cmp_batchDetail.BtnActEnab = ActionEnab; } cmp_batchDetail.eh_doRefresh += Cmp_batchDetail_eh_doRefresh; cmp_numRow.eh_doRefresh += Cmp_numRow_eh_doRefresh; } protected void Timer1_Tick(object sender, EventArgs e) { doUpdate(); } #endregion Protected Methods #region Private Fields private int fastTimer = 2000; private int slowTimer = 4000; #endregion Private Fields #region Private Methods /// /// In base al modo richiesto imposta filtraggi... /// private void checkFixMode() { ListItem currItem = null; int valore = -100; if (listMode == BatchListMode.Standard || listMode == BatchListMode.FullHistory) { foreach (var item in ddlStatus.Items) { try { currItem = (ListItem)item; int.TryParse(currItem.Value, out valore); if (valore > 7) { currItem.Enabled = false; } } catch { } } } else { foreach (var item in ddlStatus.Items) { try { currItem = (ListItem)item; int.TryParse(currItem.Value, out valore); if (valore < 8 && valore >= 0) { currItem.Enabled = false; } } catch { } } } } private void checkFixOds() { // sistemo tipo di ODS dato config... if (memLayer.ML.CRB("batchListUseStoredLight")) { ods.SelectMethod = "getByStatusLight"; } else { ods.SelectMethod = "getByStatus"; } //ods.SelectMethod= string isPartVal = ""; switch (listMode) { case BatchListMode.PartsEval: isPartVal = "1"; break; case BatchListMode.FileEval: isPartVal = "2"; break; case BatchListMode.FullHistory: isPartVal = "3"; ods.FilterExpression = ""; break; case BatchListMode.Standard: default: isPartVal = "0"; break; } hfPartValid.Value = isPartVal; } private void Cmp_batchDetail_eh_doRefresh(object sender, EventArgs e) { resetSelezione(); } private void Cmp_numRow_eh_doRefresh(object sender, EventArgs e) { // recupero num righe ed aggiorno... grView.PageSize = cmp_numRow.numRow; checkFixOds(); grView.DataBind(); } private void fixDetails() { lastSelRow = currSelRow; divDetail.Visible = currSelRow >= 0; if (divDetail.Visible) { // recupero BatchId selezionato cmp_batchDetail.BatchId = BatchIdSel; cmp_batchDetail.doUpdate(); updPanelDetail.Update(); } } private void resetSelezione() { // reimposto timer rapido... Timer1.Interval = fastTimer; checkFixOds(); currSelRow = -1; lastSelRow = -1; grView.DataBind(); divDetail.Visible = false; updPanelDetail.Update(); raiseReset(); } #endregion Private Methods } }