Files
lux/Lux.UI/Components/Pages/Offers.razor.cs
T
2025-08-08 16:35:29 +02:00

205 lines
4.7 KiB
C#

using EgwCoreLib.Lux.Data.DbModel;
using EgwCoreLib.Lux.Data.Services;
using EgwCoreLib.Razor;
using Microsoft.AspNetCore.Components;
using NLog.LayoutRenderers;
namespace Lux.UI.Components.Pages
{
public partial class Offers
{
#region Protected Enums
/// <summary>
/// Stato compilazione offerta
/// </summary>
protected enum CompileStep
{
Draft = 0,
Header = 1,
General,
Rows,
Delivery,
FinalCheck
}
#endregion Protected Enums
#region Protected Properties
protected string DivMainCss
{
get => SelRecord != null ? "col-6" : "col-12";
}
[Inject]
protected DataLayerServices DLService { get; set; } = null!;
#endregion Protected Properties
#region Protected Methods
protected string CheckSelect(OfferModel curRec)
{
string answ = "";
if (SelRecord != null)
{
answ = curRec.OfferID == SelRecord.OfferID ? "table-info" : "";
}
return answ;
}
protected void DoAdd()
{
EditRecord = new OfferModel()
{
RefYear = DateTime.Today.Year,
Description = $"Nuova Offerta {DateTime.Today:ddd yyyy.MM.dd}",
ValidUntil = DateTime.Today.AddMonths(1)
};
}
protected void DoEdit(OfferModel curRec)
{
currStep = CompileStep.Header;
EditRecord = curRec;
}
protected void DoReset()
{
EditRecord = null;
SelRecord = null;
}
protected void DoSelect(OfferModel curRec)
{
SelRecord = curRec;
}
protected override async Task OnInitializedAsync()
{
SetupArrows();
await ReloadData();
UpdateTable();
}
#endregion Protected Methods
#region Private Fields
private List<OfferModel> AllRecords = new List<OfferModel>();
private int currPage = 1;
private CompileStep currStep = CompileStep.Draft;
private OfferModel? EditRecord = null;
private bool isLoading = false;
private List<OfferModel> ListRecords = new List<OfferModel>();
private int numRecord = 10;
private OfferModel? SelRecord = null;
private int totalCount = 0;
private string txtStyle = "font-size: 1.2em; font-weight:bold; fill: white;";
#endregion Private Fields
#region Private Properties
private List<string> listBord01 { get; set; } = new();
#endregion Private Properties
#region Private Methods
private void AdvStep(CompileStep newStep)
{
currStep = newStep;
}
private string ArrowBackCol(CompileStep arrowStep)
{
string answ = $"fill: #000000;";
if (arrowStep == currStep)
{
answ = $"fill: #123456;";
}
else if (arrowStep < currStep)
{
answ = $"fill: #456789;";
}
else
{
answ = $"fill: #89ABCD;";
}
return answ;
}
private void DoClose()
{
EditRecord = null;
}
/// <summary>
/// Legge i dati dei record completi
/// </summary>
private async Task ReloadData()
{
AllRecords = await DLService.OfferGetAll();
totalCount = AllRecords.Count();
}
private void SetupArrows()
{
listBord01 = new();
listBord01.Add("");
listBord01.Add("White");
listBord01.Add("");
listBord01.Add("");
}
/// <summary>
/// Filtro e paginazione
/// </summary>
private void UpdateTable()
{
// fix paginazione
ListRecords = AllRecords
.Skip(numRecord * (currPage - 1))
.Take(numRecord)
.ToList();
}
#endregion Private Methods
#if false
protected void SetNumRec(int newNum)
{
numRecord = newNum;
RefreshDisplay();
}
protected void SetPage(int newNum)
{
currPage = newNum;
RefreshDisplay();
}
protected void SortRequested(Sorter.SortCallBack e)
{
if (sortField == e.ParamName)
{
sortAsc = e.IsAscending;
}
sortField = e.ParamName;
RefreshDisplay();
}
#endif
}
}