234 lines
5.8 KiB
C#
234 lines
5.8 KiB
C#
using Microsoft.AspNetCore.Components;
|
|
using SHERPA.BBM.CORE.DbModels;
|
|
|
|
namespace SHERPA.BBM.UI.Components
|
|
{
|
|
public partial class ResourcesEditor
|
|
{
|
|
#region Public Properties
|
|
|
|
[Parameter]
|
|
public ResourcesModel currItem
|
|
{
|
|
get
|
|
{
|
|
return _currItem;
|
|
}
|
|
|
|
set
|
|
{
|
|
_currItem = value;
|
|
}
|
|
}
|
|
|
|
[Parameter]
|
|
public int currResTypeId
|
|
{
|
|
get
|
|
{
|
|
return _currResTypeId;
|
|
}
|
|
|
|
set
|
|
{
|
|
if (!_currResTypeId.Equals(value))
|
|
{
|
|
_currResTypeId = value;
|
|
ReloadAllData().ConfigureAwait(false);
|
|
}
|
|
}
|
|
}
|
|
|
|
[Parameter]
|
|
public EventCallback<int> DataReset { get; set; }
|
|
|
|
[Parameter]
|
|
public EventCallback<int> DataUpdated { get; set; }
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Protected Fields
|
|
|
|
protected ResourcesModel _currItem = new ResourcesModel();
|
|
protected int _currResTypeId = 0;
|
|
protected int _selTagId = 0;
|
|
|
|
#endregion Protected Fields
|
|
|
|
#region Protected Properties
|
|
|
|
protected int SelectedItemId
|
|
{
|
|
get
|
|
{
|
|
int answ = 0;
|
|
if (_currItem != null)
|
|
{
|
|
answ = _currItem.ItemId;
|
|
}
|
|
|
|
return answ;
|
|
}
|
|
|
|
set
|
|
{
|
|
_currItem.ItemId = value;
|
|
// verifico e imposto valori di conseguenza...
|
|
var selTask = BBMService.ItemFind(value);
|
|
if (selTask != null)
|
|
{
|
|
_currItem.UnitPriceOff = selTask.Result.UnitPrice;
|
|
_currItem.FinalPrice = _currItem.UnitPriceOff * _currItem.QtyOff;
|
|
}
|
|
}
|
|
}
|
|
|
|
protected double SelPercRed
|
|
{
|
|
get
|
|
{
|
|
double answ = 0;
|
|
if (_currItem != null)
|
|
{
|
|
answ = _currItem.PercReduction;
|
|
}
|
|
|
|
return answ;
|
|
}
|
|
|
|
set
|
|
{
|
|
// se > 1 --> divido per 100...
|
|
value = value > 1 ? value / 100 : value;
|
|
_currItem.PercReduction = value;
|
|
}
|
|
}
|
|
|
|
protected double SelPriceOff
|
|
{
|
|
get
|
|
{
|
|
double answ = 0;
|
|
if (_currItem != null)
|
|
{
|
|
answ = _currItem.UnitPriceOff;
|
|
}
|
|
|
|
return answ;
|
|
}
|
|
|
|
set
|
|
{
|
|
_currItem.UnitPriceOff = value;
|
|
// verifico e imposto valori di conseguenza...
|
|
var selTask = BBMService.ItemFind(_currItem.ItemId);
|
|
if (selTask != null)
|
|
{
|
|
_currItem.FinalPrice = _currItem.UnitPriceOff * _currItem.QtyOff;
|
|
}
|
|
}
|
|
}
|
|
|
|
protected double SelQtyOff
|
|
{
|
|
get
|
|
{
|
|
double answ = 0;
|
|
if (_currItem != null)
|
|
{
|
|
answ = _currItem.QtyOff;
|
|
}
|
|
|
|
return answ;
|
|
}
|
|
|
|
set
|
|
{
|
|
_currItem.QtyOff = value;
|
|
// verifico e imposto valori di conseguenza...
|
|
var selTask = BBMService.ItemFind(_currItem.ItemId);
|
|
if (selTask != null)
|
|
{
|
|
_currItem.UnitPriceOff = selTask.Result.UnitPrice;
|
|
_currItem.FinalPrice = _currItem.UnitPriceOff * _currItem.QtyOff;
|
|
}
|
|
}
|
|
}
|
|
|
|
protected int SelTagId
|
|
{
|
|
get
|
|
{
|
|
return _selTagId;
|
|
}
|
|
|
|
set
|
|
{
|
|
if (_selTagId != value)
|
|
{
|
|
_selTagId = value;
|
|
ReloadAllData().ConfigureAwait(false);
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
await ReloadAllData();
|
|
}
|
|
|
|
protected async Task ReloadAllData()
|
|
{
|
|
tagsList = await BBMService.TagsGetAll(TagType.Items);
|
|
ListResType = await BBMService.ItemResTypeGetAll();
|
|
var rawItems = await BBMService.ItemsGetFilt(currResTypeId, "");
|
|
// filtro x tag se necessario...
|
|
if (SelTagId != 0)
|
|
{
|
|
itemsList = rawItems.Where(x => x.TagNav.Any(t => t.TagId == SelTagId)).ToList();
|
|
}
|
|
else
|
|
{
|
|
itemsList = rawItems;
|
|
}
|
|
// ordino x importo
|
|
itemsList = itemsList.OrderByDescending(x => x.UnitPrice).ToList();
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
private List<vItemsDataModel>? itemsList;
|
|
private List<ItemResTypeModel> ListResType = new List<ItemResTypeModel>();
|
|
private List<TagModel>? tagsList;
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Methods
|
|
|
|
private async Task CancelUpdate()
|
|
{
|
|
await DataReset.InvokeAsync(0);
|
|
}
|
|
|
|
private async Task SaveUpdate()
|
|
{
|
|
if (_currItem != null)
|
|
{
|
|
await BBMService.ResourceUpdate(_currItem);
|
|
await DataUpdated.InvokeAsync(1);
|
|
}
|
|
else
|
|
{
|
|
Console.WriteLine("Resource null!");
|
|
}
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |