diff --git a/SHERPA.BBM.UI/Pages/Resources.razor b/SHERPA.BBM.UI/Pages/Resources.razor index 4d88bcb..4d393fb 100644 --- a/SHERPA.BBM.UI/Pages/Resources.razor +++ b/SHERPA.BBM.UI/Pages/Resources.razor @@ -1,11 +1,7 @@ @page "/resources/{DocIdReq}" -@using SHERPA.BBM.UI.Data @using SHERPA.BBM.UI.Components -@inject IJSRuntime JSRuntime -@inject BBM_EFService BBMService -
@@ -129,165 +125,3 @@
- -@code { - - private DatabaseModels.BasketsModel[] basketList; - private DatabaseModels.NegotiationsModel[] negotiationList; - - private int numRecord { get; set; } = 10; - - private DatabaseModels.ResourcesModel currItem = null; - private DatabaseModels.ResourcesModel[] itemsList; - - [Parameter] - public string DocIdReq { get; set; } = ""; - private DatabaseModels.DocsModel currDoc = null; - - protected double getQtyTotal() - { - var grandTot = itemsList.Select(x => x.QtyOff).Sum(); - return grandTot; - } - protected double getStdTotal() - { - var grandTot = itemsList.Select(x => x.FinalPrice + x.PriceReduction).Sum(); - return grandTot; - } - protected double getReducTotal() - { - var grandTot = itemsList.Select(x => x.PriceReduction).Sum(); - return grandTot; - } - protected double getGrandTotal() - { - var grandTot = itemsList.Select(x => x.FinalPrice).Sum(); - return grandTot; - } - - protected override void OnParametersSet() - { - int DocId = 0; - int.TryParse(DocIdReq, out DocId); - //the param will be set now - var taskDoc = BBMService.DocGetByKeyAsync(DocId); - currDoc = taskDoc.Result; - updateTable(); - } - - public string checkSelect(int ResourceId) - { - string answ = ""; - if (currItem != null) - { - try - { - answ = (currItem.ResourceId == ResourceId) ? "table-info" : ""; - } - catch - { } - } - return answ; - } - - private BbmResType _SelResType { get; set; } = BbmResType.ND; - private string _SelUM { get; set; } = ""; - - private BbmResType SelResType - { - get - { - return _SelResType; - } - set - { - _SelResType = value; - updateTable(); - } - } - private string SelUM - { - get - { - return _SelUM; - } - set - { - _SelUM = value; - updateTable(); - } - } - - protected async Task updateTable() - { - if (currDoc != null) - { - itemsList = await BBMService.ResourcesGetAsync(currDoc.DocId, SelResType, numRecord); - } - } - - protected async Task ReloadAllData() - { - basketList = await BBMService.BasketsGetAsync("", 0); - negotiationList = await BBMService.NegotiationsGetAsync("", 0); - updateTable(); - } - - protected override async Task OnInitializedAsync() - { - await ReloadAllData(); - } - - protected async Task ForceReload(int newNum) - { - numRecord = newNum; - await ReloadAllData(); - } - - protected void ResetData() - { - BBMService.rollBackEdit(currItem); - currItem = null; - } - - protected async Task UpdateData() - { - currItem = null; - await ReloadAllData(); - } - - protected void CreateNew() - { - // recupero counter - DatabaseModels.ResourcesModel newRecord = new DatabaseModels.ResourcesModel() - { - DocId = currDoc.DocId, - ItemId = 1, - QtyOff = 1, - QtyPrev = 1, - UnitPriceOff = 1, - Ordinal = itemsList.Length + 1 - }; - currItem = newRecord; - } - - protected void Edit(SHERPA.BBM.DatabaseModels.ResourcesModel currRecord) - { - currItem = currRecord; - } - - protected void Move(SHERPA.BBM.DatabaseModels.ResourcesModel currRecord, int move) - { - BBMService.ResourceUpdateOrder(currRecord.ResourceId, move); - updateTable(); - } - protected async Task Delete(SHERPA.BBM.DatabaseModels.ResourcesModel currRecord) - { - if (!await JSRuntime.InvokeAsync("confirm", $"Sicuro di voler eliminare il Documento '{currRecord.ResourceId}'?")) - return; - - BBMService.ResourceDelete(currRecord); - await UpdateData(); - } - -} \ No newline at end of file diff --git a/SHERPA.BBM.UI/Pages/Resources.razor.cs b/SHERPA.BBM.UI/Pages/Resources.razor.cs new file mode 100644 index 0000000..54ffa47 --- /dev/null +++ b/SHERPA.BBM.UI/Pages/Resources.razor.cs @@ -0,0 +1,204 @@ +using Microsoft.AspNetCore.Components; +using Microsoft.JSInterop; +using SHERPA.BBM.UI.Data; +using System.Linq; +using System.Threading.Tasks; + +namespace SHERPA.BBM.UI.Pages +{ + public partial class Resources : ComponentBase + { + #region Private Fields + + private DatabaseModels.BasketsModel[] basketList; + + private DatabaseModels.DocsModel currDoc = null; + + private DatabaseModels.ResourcesModel currItem = null; + + private DatabaseModels.ResourcesModel[] itemsList; + + private DatabaseModels.NegotiationsModel[] negotiationList; + + #endregion Private Fields + + #region Public Properties + + [Parameter] + public string DocIdReq { get; set; } = ""; + + #endregion Public Properties + + #region Private Properties + + private BbmResType _SelResType { get; set; } = BbmResType.ND; + + private string _SelUM { get; set; } = ""; + + [Inject] + private BBM_EFService BBMService { get; set; } + + [Inject] + private IJSRuntime JSRuntime { get; set; } + + private int numRecord { get; set; } = 10; + + private BbmResType SelResType + { + get + { + return _SelResType; + } + set + { + _SelResType = value; + updateTable(); + } + } + + private string SelUM + { + get + { + return _SelUM; + } + set + { + _SelUM = value; + updateTable(); + } + } + + #endregion Private Properties + + #region Public Methods + + public string checkSelect(int ResourceId) + { + string answ = ""; + if (currItem != null) + { + try + { + answ = (currItem.ResourceId == ResourceId) ? "table-info" : ""; + } + catch + { } + } + return answ; + } + + #endregion Public Methods + + #region Protected Methods + + protected void CreateNew() + { + // recupero counter + DatabaseModels.ResourcesModel newRecord = new DatabaseModels.ResourcesModel() + { + DocId = currDoc.DocId, + ItemId = 1, + QtyOff = 1, + QtyPrev = 1, + UnitPriceOff = 1, + Ordinal = itemsList.Length + 1 + }; + currItem = newRecord; + } + + protected async Task Delete(SHERPA.BBM.DatabaseModels.ResourcesModel currRecord) + { + if (!await JSRuntime.InvokeAsync("confirm", $"Sicuro di voler eliminare il Documento '{currRecord.ResourceId}'?")) + return; + + BBMService.ResourceDelete(currRecord); + await UpdateData(); + } + + protected void Edit(SHERPA.BBM.DatabaseModels.ResourcesModel currRecord) + { + currItem = currRecord; + } + + protected async Task ForceReload(int newNum) + { + numRecord = newNum; + await ReloadAllData(); + } + + protected double getGrandTotal() + { + var grandTot = itemsList.Select(x => x.FinalPrice).Sum(); + return grandTot; + } + + protected double getQtyTotal() + { + var grandTot = itemsList.Select(x => x.QtyOff).Sum(); + return grandTot; + } + + protected double getReducTotal() + { + var grandTot = itemsList.Select(x => x.PriceReduction).Sum(); + return grandTot; + } + + protected double getStdTotal() + { + var grandTot = itemsList.Select(x => x.FinalPrice + x.PriceReduction).Sum(); + return grandTot; + } + + protected void Move(SHERPA.BBM.DatabaseModels.ResourcesModel currRecord, int move) + { + BBMService.ResourceUpdateOrder(currRecord.ResourceId, move); + updateTable(); + } + + protected override async Task OnInitializedAsync() + { + await ReloadAllData(); + } + + protected override void OnParametersSet() + { + int DocId = 0; + int.TryParse(DocIdReq, out DocId); + //the param will be set now + var taskDoc = BBMService.DocGetByKeyAsync(DocId); + currDoc = taskDoc.Result; + updateTable(); + } + + protected async Task ReloadAllData() + { + basketList = await BBMService.BasketsGetAsync("", 0); + negotiationList = await BBMService.NegotiationsGetAsync("", 0); + updateTable(); + } + + protected void ResetData() + { + BBMService.rollBackEdit(currItem); + currItem = null; + } + + protected async Task UpdateData() + { + currItem = null; + await ReloadAllData(); + } + + protected async Task updateTable() + { + if (currDoc != null) + { + itemsList = await BBMService.ResourcesGetAsync(currDoc.DocId, SelResType, numRecord); + } + } + + #endregion Protected Methods + } +} \ No newline at end of file diff --git a/SHERPA.BBM.UI/SHERPA.BBM.UI.csproj b/SHERPA.BBM.UI/SHERPA.BBM.UI.csproj index 30aff2c..1a41d05 100644 --- a/SHERPA.BBM.UI/SHERPA.BBM.UI.csproj +++ b/SHERPA.BBM.UI/SHERPA.BBM.UI.csproj @@ -4,7 +4,7 @@ net5.0 60fcdaab-6c1e-4bec-9d88-f7727ef1c12c wwwroot\favicon.ico - 1.0.2105.2254 + 1.0.2105.2258