Split resources --> cs

This commit is contained in:
Samuele E. Locatelli
2021-05-14 22:58:48 +02:00
parent c409931138
commit b16c232d8d
3 changed files with 205 additions and 167 deletions
-166
View File
@@ -1,11 +1,7 @@
@page "/resources/{DocIdReq}"
@using SHERPA.BBM.UI.Data
@using SHERPA.BBM.UI.Components
@inject IJSRuntime JSRuntime
@inject BBM_EFService BBMService
<div class="card">
<div class="card-header">
<div class="row">
@@ -129,165 +125,3 @@
</div>
</div>
</div>
@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<bool>("confirm", $"Sicuro di voler eliminare il Documento '{currRecord.ResourceId}'?"))
return;
BBMService.ResourceDelete(currRecord);
await UpdateData();
}
}
+204
View File
@@ -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<bool>("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
}
}
+1 -1
View File
@@ -4,7 +4,7 @@
<TargetFramework>net5.0</TargetFramework>
<UserSecretsId>60fcdaab-6c1e-4bec-9d88-f7727ef1c12c</UserSecretsId>
<ApplicationIcon>wwwroot\favicon.ico</ApplicationIcon>
<Version>1.0.2105.2254</Version>
<Version>1.0.2105.2258</Version>
</PropertyGroup>
<ItemGroup>