d344b49ff0
- continuo implementazione gestione KIT
534 lines
14 KiB
C#
534 lines
14 KiB
C#
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.JSInterop;
|
|
using MP.Data.DbModels;
|
|
using MP.SPEC.Data;
|
|
|
|
namespace MP.SPEC.Components
|
|
{
|
|
public partial class ScratchPodlKit : ComponentBase, IDisposable
|
|
{
|
|
#region Public Methods
|
|
|
|
public void Dispose()
|
|
{
|
|
EditRecord = null;
|
|
SearchRecords = null;
|
|
ListRecords = null;
|
|
GC.Collect();
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Protected Fields
|
|
|
|
protected int kitCount = 0;
|
|
|
|
protected int totalCount = 0;
|
|
|
|
#endregion Protected Fields
|
|
|
|
#region Protected Properties
|
|
|
|
[Inject]
|
|
protected IJSRuntime JSRuntime { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected MpDataService MDService { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected NavigationManager NavManager { get; set; } = null!;
|
|
|
|
protected string SearchComm
|
|
{
|
|
get => sCodComm;
|
|
set
|
|
{
|
|
if (sCodComm != value)
|
|
{
|
|
sCodComm = value;
|
|
currPage = 1;
|
|
ListRecords = null;
|
|
ReloadData();
|
|
}
|
|
}
|
|
}
|
|
|
|
protected string sParentCss
|
|
{
|
|
get => string.IsNullOrEmpty(sCodComm) ? "btn-secondary" : "btn-primary";
|
|
}
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
protected string checkSelect(IstanzeKitModel currRec)
|
|
{
|
|
string answ = "";
|
|
if (EditRecord != null)
|
|
{
|
|
try
|
|
{
|
|
answ = (EditRecord.KeyKit == currRec.KeyKit && EditRecord.KeyExtOrd == currRec.KeyExtOrd) ? "table-info" : "";
|
|
}
|
|
catch
|
|
{ }
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
protected bool DelEnabled(IstanzeKitModel reqRec)
|
|
{
|
|
bool answ = false;
|
|
|
|
return answ;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Verifica eliminabilità del record: se è avviato il PODL non è liminabile...
|
|
/// </summary>
|
|
/// <param name="reqRec"></param>
|
|
/// <returns></returns>
|
|
protected async Task DoCancel()
|
|
{
|
|
EditRecord = null;
|
|
ReloadData();
|
|
await Task.Delay(1);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Eliminazione record selezionato (previa conferma)
|
|
/// </summary>
|
|
/// <param name="selRec"></param>
|
|
/// <returns></returns>
|
|
protected async Task DoDelete(IstanzeKitModel selRec)
|
|
{
|
|
if (!await JSRuntime.InvokeAsync<bool>("confirm", "Eliminazione riga Istanza KIT: sei sicuro di voler procedere?"))
|
|
return;
|
|
|
|
await Task.Delay(1);
|
|
var done = await MDService.IstKitDelete(selRec);
|
|
EditRecord = null;
|
|
ReloadData();
|
|
await Task.Delay(1);
|
|
}
|
|
|
|
protected async Task DoUpdate(IstanzeKitModel selRec)
|
|
{
|
|
if (!await JSRuntime.InvokeAsync<bool>("confirm", "Confermi di voler salvare le modifiche?"))
|
|
return;
|
|
|
|
await Task.Delay(1);
|
|
var done = await MDService.IstKitUpsert(selRec);
|
|
EditRecord = null;
|
|
ReloadData();
|
|
await Task.Delay(1);
|
|
}
|
|
|
|
private bool OptAdmKitEnabled = false;
|
|
|
|
protected override void OnInitialized()
|
|
{
|
|
numRecord = 10;
|
|
// gestione di base dei KIT
|
|
string rawVal = MDService.ConfigTryGet("OptAdmKitEnabled");
|
|
if (!string.IsNullOrEmpty(rawVal))
|
|
{
|
|
bool.TryParse(rawVal, out OptAdmKitEnabled);
|
|
}
|
|
// conf variabili decodifica
|
|
regExp_KO = MDService.ConfigTryGet("regExp_KO");
|
|
regExp_OK = MDService.ConfigTryGet("regExp_OK");
|
|
regExp_KitStart = MDService.ConfigTryGet("regExp_KitStart");
|
|
regExp_KitSave = MDService.ConfigTryGet("regExp_KitSave");
|
|
// altre variabili
|
|
rawVal = MDService.ConfigTryGet("SPEC_nArtSearch");
|
|
if (!string.IsNullOrEmpty(rawVal))
|
|
{
|
|
int.TryParse(rawVal, out minChar);
|
|
}
|
|
}
|
|
|
|
#if false
|
|
protected override void OnAfterRender(bool firstRender)
|
|
{
|
|
if (firstRender)
|
|
{
|
|
if (OptAdmKitEnabled)
|
|
{
|
|
doReset();
|
|
}
|
|
}
|
|
//base.OnAfterRender(firstRender);
|
|
}
|
|
#endif
|
|
|
|
|
|
|
|
protected override void OnParametersSet()
|
|
{
|
|
ReloadData();
|
|
}
|
|
|
|
protected void ResetData()
|
|
{
|
|
EditRecord = null;
|
|
}
|
|
|
|
protected void ResetParent()
|
|
{
|
|
SearchComm = "";
|
|
ReloadData();
|
|
}
|
|
|
|
protected void ResetSel()
|
|
{
|
|
EditRecord = null;
|
|
}
|
|
|
|
protected void SelRecord(IstanzeKitModel selRec)
|
|
{
|
|
EditRecord = selRec;
|
|
}
|
|
|
|
protected void SetNumPage(int newNum)
|
|
{
|
|
currPage = newNum;
|
|
}
|
|
|
|
protected void SetNumRec(int newNum)
|
|
{
|
|
currPage = 1;
|
|
numRecord = newNum;
|
|
}
|
|
|
|
protected void UpdateData()
|
|
{
|
|
EditRecord = null;
|
|
ReloadData();
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
/// <summary>
|
|
/// Boolear controllo visualizzazione ricerca articoli
|
|
/// </summary>
|
|
private bool doSearchArt = false;
|
|
|
|
private IstanzeKitModel? EditRecord = null;
|
|
|
|
private List<IstanzeKitModel>? ListRecords;
|
|
|
|
private int minChar = 2;
|
|
|
|
/// <summary>
|
|
/// RegExp x SAVE KIT
|
|
/// </summary>
|
|
private string regExp_KitSave = "#RKE";
|
|
|
|
/// <summary>
|
|
/// RegExp x START KIT
|
|
/// </summary>
|
|
private string regExp_KitStart = "#RKS";
|
|
|
|
/// <summary>
|
|
/// RegExp x RESET / CANCEL
|
|
/// </summary>
|
|
private string regExp_KO = "#RKO";
|
|
|
|
/// <summary>
|
|
/// RegExp x CONFERMA
|
|
/// </summary>
|
|
private string regExp_OK = "#ROK";
|
|
|
|
private List<IstanzeKitModel>? SearchRecords;
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Properties
|
|
|
|
private int _currPage { get; set; } = 1;
|
|
|
|
private int _numRecord { get; set; } = 10;
|
|
|
|
private int currPage
|
|
{
|
|
get => _currPage;
|
|
set
|
|
{
|
|
if (_currPage != value)
|
|
{
|
|
_currPage = value;
|
|
ReloadData();
|
|
}
|
|
}
|
|
}
|
|
|
|
private bool isLoading { get; set; } = false;
|
|
|
|
private int numRecord
|
|
{
|
|
get => _numRecord;
|
|
set
|
|
{
|
|
if (_numRecord != value)
|
|
{
|
|
_numRecord = value;
|
|
ReloadData();
|
|
}
|
|
}
|
|
}
|
|
|
|
private string sCodComm { get; set; } = "";
|
|
|
|
private bool ShowCharts { get; set; } = false;
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Private Methods
|
|
|
|
private void ReloadData()
|
|
{
|
|
isLoading = true;
|
|
SearchRecords = MDService.IstKitFilt("", "");
|
|
totalCount = SearchRecords.Count;
|
|
// conto i kit = distinct...
|
|
kitCount = SearchRecords.GroupBy(x => x.CodArtParent).Count();
|
|
ListRecords = SearchRecords
|
|
.Skip(numRecord * (currPage - 1))
|
|
.Take(numRecord)
|
|
.ToList();
|
|
isLoading = false;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Toggle modale ricerca articoli
|
|
/// </summary>
|
|
private void SearchArtToggle()
|
|
{
|
|
doSearchArt = !doSearchArt;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Salva selezione articolo
|
|
/// </summary>
|
|
/// <param name="codArt"></param>
|
|
private void SetCodArtChild(string codArt)
|
|
{
|
|
if (EditRecord != null)
|
|
{
|
|
EditRecord.CodArtChild = codArt;
|
|
doSearchArt = false;
|
|
}
|
|
}
|
|
|
|
#endregion Private Methods
|
|
|
|
|
|
#if false
|
|
|
|
|
|
public string codKitTemp
|
|
{
|
|
get
|
|
{
|
|
return memLayer.ML.StringSessionObj(string.Format("codKitTemp_{0}", uid));
|
|
}
|
|
set
|
|
{
|
|
memLayer.ML.setSessionVal(string.Format("codKitTemp_{0}", uid), value);
|
|
hlCodKitTemp.Value = value;
|
|
grViewWSK.DataBind();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ultimo Codice KIT creato
|
|
/// </summary>
|
|
public string lastKitMade
|
|
{
|
|
get
|
|
{
|
|
return memLayer.ML.StringSessionObj("lastKitMade");
|
|
}
|
|
set
|
|
{
|
|
memLayer.ML.setSessionVal("lastKitMade", value);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Aggiunge (in obj OrdineKit) l'ordine coi parametri indicati
|
|
/// </summary>
|
|
/// <param name="codOrd"></param>
|
|
/// <param name="codArt"></param>
|
|
/// <param name="descArt"></param>
|
|
/// <param name="qta"></param>
|
|
/// <returns></returns>
|
|
public bool addOrdArt(string codOrd, string codArt, string descArt, int qta)
|
|
{
|
|
bool answ = false;
|
|
// verifico di avere un codiceKIT
|
|
checkCodKit();
|
|
// salvo info x il cod temporaneo...
|
|
DataLayerObj.taWKS.insertQuery(codKitTemp, codOrd, codArt, descArt, qta);
|
|
// verifico SE HO un KIT riconosciuto e quindi un CodArt di KIT valido...
|
|
string currCodArtKit = "###";
|
|
var TksTab = DataLayerObj.taTKS.GetData(codKitTemp, 1);
|
|
bool showPODL = false;
|
|
if (TksTab.Rows.Count > 0)
|
|
{
|
|
// verifico se ho aderenza 100%...
|
|
if (TksTab[0].TotalScore == 1)
|
|
{
|
|
currCodArtKit = TksTab[0].CodArtParent;
|
|
showPODL = true;
|
|
}
|
|
}
|
|
hfCodArtKit.Value = currCodArtKit;
|
|
divPODL.Visible = showPODL;
|
|
answ = true;
|
|
grViewWSK.DataBind();
|
|
grViewKitSel.DataBind();
|
|
grViewPODL.DataBind();
|
|
grViewIstanzeKIT.DataBind();
|
|
return answ;
|
|
}
|
|
|
|
|
|
private void doReset()
|
|
{
|
|
// elimino eventuali record ODL
|
|
DataLayerObj.taWKS.deleteQuery(codKitTemp);
|
|
codKitTemp = "";
|
|
divPODL.Visible = false;
|
|
checkCodKit();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ultimo input registrato
|
|
/// </summary>
|
|
public string lastInput
|
|
{
|
|
get
|
|
{
|
|
return hlLastInput.Value;
|
|
}
|
|
set
|
|
{
|
|
hlLastInput.Value = value;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Aggiorno controllo secondo ULTIMO input
|
|
/// </summary>
|
|
public void doUpdate()
|
|
{
|
|
// aggiorno label...
|
|
messOut = "";
|
|
// controllo input (reset/inizio o salva...)
|
|
if (lastInput == regExp_KO)
|
|
{
|
|
// resetto dati
|
|
doReset();
|
|
messOut = "Effettuato reset!";
|
|
}
|
|
else if (lastInput == regExp_KitStart)
|
|
{
|
|
// resetto dati
|
|
doReset();
|
|
messOut = "Inizio configurazione KIT";
|
|
}
|
|
else if (lastInput == regExp_KitSave)
|
|
{
|
|
// controllo SE HO un kit selezionato...
|
|
string currCodArtKit = "###";
|
|
var TksTab = DataLayerObj.taTKS.GetData(codKitTemp, 1);
|
|
bool showPODL = false;
|
|
if (TksTab.Rows.Count > 0)
|
|
{
|
|
// verifico se ho aderenza 100%...
|
|
if (TksTab[0].TotalScore == 1)
|
|
{
|
|
currCodArtKit = TksTab[0].CodArtParent;
|
|
showPODL = true;
|
|
}
|
|
}
|
|
if (showPODL)
|
|
{
|
|
// in questo caso creo istanza!
|
|
creazioneIstanzaKit(currCodArtKit);
|
|
}
|
|
}
|
|
else if (lastInput == regExp_OK)
|
|
{
|
|
}
|
|
// ennesimo check cod TEMP
|
|
checkCodKit();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Verifico SE HO un codKit Temporaneo sennò lo creo...
|
|
/// </summary>
|
|
private void checkCodKit()
|
|
{
|
|
if (codKitTemp == "")
|
|
{
|
|
// genero un NUOVO cod temp kit...
|
|
codKitTemp = string.Format("KIT_{0:yyMMdd_HHmmss}", DateTime.Now);
|
|
}
|
|
}
|
|
|
|
public string messOut
|
|
{
|
|
set
|
|
{
|
|
lblOut.Text = value;
|
|
}
|
|
get
|
|
{
|
|
return lblOut.Text;
|
|
}
|
|
}
|
|
|
|
protected void grViewKitSel_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
// se ho selezionato recupero CHIAVE = CodArticolo del KIT
|
|
string CodArtParent = grViewKitSel.SelectedValue.ToString();
|
|
// crea KIT x quel CodArtParent...
|
|
creazioneIstanzaKit(CodArtParent);
|
|
}
|
|
/// <summary>
|
|
/// Crea una NUOVA istanza KIT
|
|
/// </summary>
|
|
/// <param name="CodArtParent">CodArt dell'Assieme/KIT</param>
|
|
private void creazioneIstanzaKit(string CodArtParent)
|
|
{
|
|
// calcolo NUOVO codice kit...
|
|
var tabKey = DataLayerObj.taIstK.getNewKey();
|
|
if (tabKey.Rows.Count == 1)
|
|
{
|
|
// stacco un NUOVO codice KIT
|
|
lastKitMade = tabKey[0].KeyKit;
|
|
// inserisco ISTANZA KIT!
|
|
DataLayerObj.taIstK.insertByWKS(lastKitMade, CodArtParent, codKitTemp);
|
|
// faccio reset valori WKS...
|
|
doReset();
|
|
// ora resetto ordine caricato...
|
|
messOut = string.Format("Creato NUOVA P.ODL cod {0} per il KIT {1}", lastKitMade, CodArtParent);
|
|
// sollevo evento x impostare lettura KIT a BARCODE (x conferma successiva...)
|
|
// sollevo evento nuovo valore...
|
|
if (eh_selKit != null)
|
|
{
|
|
eh_selKit(this, new EventArgs());
|
|
}
|
|
}
|
|
}
|
|
#endif
|
|
|
|
}
|
|
} |