Files
mapo-core/MP-TAB3/Components/DeclarEditor.razor.cs
Samuele Locatelli cbd4a90d01 DATA:
- Correzione MSE i MSEModel x naming
- fix e test vari su app CORE (IOC/SPEC/TAB3/MON)
2025-04-14 18:25:00 +02:00

234 lines
5.6 KiB
C#

using global::Microsoft.AspNetCore.Components;
using MP.Data;
using MP.Data.DbModels;
using MP.Data.Services;
namespace MP_TAB3.Components
{
public partial class DeclarEditor
{
#region Public Properties
[Parameter]
public EventCallback<bool> E_Updated { get; set; }
[Parameter]
public RegistroDichiarazioniModel? EditRec
{
get => currRec;
set
{
if (currRec != value && value != null)
{
IsNewRec = false;
ShowDetail = true;
currRec = value;
}
}
}
[Parameter]
public MappaStatoExplModel? RecMSE { get; set; } = null;
#endregion Public Properties
#region Protected Properties
protected string btnCss
{
get => ShowDetail ? "bt-dark text-primary border-primary border-2" : "btn-primary";
}
protected string BtnCss
{
get => IsNewRec ? "btn btn-success" : "btn btn-primary";
}
protected string BtnText
{
get => IsNewRec ? "Salva Nuova Dichiarazione" : "Aggiorna Dichiarazione";
}
protected DateTime DateSel
{
get => currRec.DtRec.Round(TimeSpan.FromSeconds(1));
set
{
if (currRec.DtRec != value)
{
currRec.DtRec = value;
}
}
}
protected string faCss
{
get => ShowDetail ? "fa-chevron-up" : "fa-chevron-down";
}
protected List<AnagTagsModel> ListComplete { get; set; } = new List<AnagTagsModel>();
[Inject]
protected MessageService MServ { get; set; } = null!;
[Inject]
protected SharedMemService SMServ { get; set; } = null!;
[Inject]
protected TabDataService TabServ { get; set; } = null!;
protected string TagCodeSel
{
get => currRec.TagCode;
set
{
if (currRec.TagCode != value)
{
currRec.TagCode = value;
}
}
}
protected string Title
{
get => ShowDetail ? "Nascondi Inserimento Dichiarazione" : "Mostra Inserimento Dichiarazione";
}
#endregion Protected Properties
#region Protected Methods
protected void doCancel()
{
DoReset();
}
protected async Task DoSave()
{
if (IsNewRec)
{
// sistemo IdxMacchina SE fosse multi...
string IdxMaccSel = IdxMacc;
bool isMulti = SMServ.DictMacchMulti[IdxMacc] == 1;
if (isMulti)
{
var idxMSel = MServ.UserPrefGet(IdxMacc);
if (!string.IsNullOrEmpty(idxMSel))
{
IdxMaccSel = idxMSel;
}
currRec.IdxMacchina = IdxMaccSel;
}
// inserisco
await TabServ.RegDichiarInsert(currRec);
}
else
{
// altrimetni update...
await TabServ.RegDichiarUpdate(currRec);
}
// reset
DoReset();
ToggleCtrl();
await E_Updated.InvokeAsync(true);
}
protected override async Task OnInitializedAsync()
{
currRec = new RegistroDichiarazioniModel()
{
DtRec = DateTime.Now,
IdxMacchina = IdxMacc,
TagCode = TagCodeSel,
MatrOpr = MatrOpr,
ValString = UserComment
};
await ReloadData();
}
protected async Task ReloadData()
{
ListComplete = await TabServ.AnagTagsOrd();
}
protected void resetDate()
{
DateSel = DateTime.Now;
}
protected void ToggleCtrl()
{
ShowDetail = !ShowDetail;
DateSel = DateTime.Now;
if (!ShowDetail)
{
IsNewRec = true;
UserComment = "";
}
}
#endregion Protected Methods
#region Private Fields
private bool IsNewRec = true;
#endregion Private Fields
#region Private Properties
private string CodArt
{
get => RecMSE != null ? RecMSE.CodArticolo : "";
}
private RegistroDichiarazioniModel currRec { get; set; } = new RegistroDichiarazioniModel();
private string IdxMacc
{
get => RecMSE != null ? RecMSE.IdxMacchina : "";
}
private int idxOdl { get; set; } = 0;
private int IdxOdl
{
get => idxOdl;
set => idxOdl = value;
}
private int MatrOpr
{
get => MServ.MatrOpr;
}
private bool ShowDetail { get; set; } = false;
private string UserComment
{
get => currRec.ValString.Trim();
set
{
if (currRec.ValString != value)
{
currRec.ValString = value;
}
}
}
#endregion Private Properties
#region Private Methods
private void DoReset()
{
UserComment = "";
DateSel = DateTime.Now;
ShowDetail = true;
IsNewRec = true;
}
#endregion Private Methods
}
}