Files
mapo-core/MP.SPEC/Components/RecipeArchMan.razor.cs
T
2023-04-03 19:36:28 +02:00

175 lines
5.0 KiB
C#

using Microsoft.AspNetCore.Components;
using MP.Data.MgModels;
using MP.SPEC.Data;
namespace MP.SPEC.Components
{
public partial class RecipeArchMan
{
#region Public Properties
[Parameter]
public EventCallback<bool> CancelEvent { get; set; }
[Parameter]
public int IdxPODL { get; set; } = 0;
[Parameter]
public string RecipeCode { get; set; } = "";
[Parameter]
public string RecipeArchPath { get; set; } = "";
#endregion Public Properties
#region Protected Fields
protected bool isLoading = false;
protected bool showSearch = false;
protected bool showDetail = false;
#endregion Protected Fields
#region Protected Properties
protected RecipeModel? CurrRecipe { get; set; } = null;
[Inject]
protected MpDataService MDService { get; set; } = null!;
protected RecipeModel? OrigRecipe { get; set; } = null;
#endregion Protected Properties
#region Protected Methods
protected override async Task OnParametersSetAsync()
{
await ReloadData();
}
#endregion Protected Methods
#region Private Fields
private List<string> recipeList = new List<string>();
private List<string> list2show = new List<string>();
#endregion Private Fields
#region Private Properties
private bool needSave
{
get
{
bool answ = false;
if (CurrRecipe != null && OrigRecipe != null)
{
answ = !(CurrRecipe.HeadVal.SequenceEqual(OrigRecipe.HeadVal));
if (!answ)
{
// verifico nu righe...
answ = (CurrRecipe.RowsVal.Count != OrigRecipe.RowsVal.Count);
if (!answ)
{
try
{
foreach (var item in CurrRecipe.RowsVal)
{
answ = !(item.Value.SequenceEqual(OrigRecipe.RowsVal[item.Key]));
if (answ)
{
break;
}
}
}
catch (Exception exc)
{
answ = true;
}
}
}
}
return answ;
}
}
#endregion Private Properties
#region Private Methods
private async Task showSelect()
{
isLoading = true;
// carico dati x ricerca...
await ReloadData();
// mostro!
showSearch = true;
isLoading = false;
await Task.Delay(1);
}
protected string _searchVal = "";
protected string searchVal
{
get => _searchVal;
set
{
if (_searchVal != value)
{
_searchVal = value;
var pUpd = Task.Run(async () => await ReloadData());
pUpd.Wait();
}
}
}
protected int _numShow = 10;
protected int numShow
{
get => _numShow;
set
{
if (_numShow != value)
{
_numShow = value;
var pUpd = Task.Run(async () => await ReloadData());
pUpd.Wait();
}
}
}
private async Task ReloadData()
{
await Task.Delay(1);
isLoading = true;
if (IdxPODL != 0 && !string.IsNullOrEmpty(RecipeArchPath))
{
recipeList = Directory.GetFiles(RecipeArchPath).ToList();
list2show = recipeList.Where(x => string.IsNullOrEmpty(searchVal) || x.Contains(searchVal)).Take(numShow).ToList();
#if false
CurrRecipe = new RecipeModel();
// effettua ricerca ricetta su MongoDb
CurrRecipe = await MDService.RecipeGetByPODL(IdxPODL);
// se non trova crea nuova...
if (CurrRecipe == null)
{
Dictionary<string, string> CalcArgs = await getCalcArgs();
CurrRecipe = MDService.InitRecipe(RecipeArchPath, IdxPODL, CalcArgs);
// la salvo...
await MDService.RecipeSetByPODL(CurrRecipe);
}
// rileggo la default
OrigRecipe = await MDService.RecipeGetByPODL(IdxPODL);
fixRowsShowStatus();
#endif
}
await Task.Delay(1);
isLoading = false;
}
#endregion Private Methods
}
}