Files
limanapp/LiMan.UI/Components/InstAppRelStatus.razor.cs
T
2025-01-13 19:32:15 +01:00

192 lines
6.0 KiB
C#

using LiMan.DB.DTO;
using Microsoft.AspNetCore.Components;
using System;
using System.Collections.Generic;
using System.Linq;
using static EgwCoreLib.Razor.Sorter;
using System.Threading.Tasks;
using LiMan.UI.Data;
namespace LiMan.UI.Components
{
public partial class InstAppRelStatus
{
#region Public Properties
[Parameter]
public List<AppStatusDTO> AppStats { get; set; } = new List<AppStatusDTO>();
#endregion Public Properties
#region Protected Methods
protected override void OnParametersSet()
{
isLoading = true;
UpdateTable();
isLoading = false;
}
protected void setNumPage(int newNum)
{
currPage = newNum;
UpdateTable();
isLoading = false;
}
protected void setNumRec(int newNum)
{
numRecord = newNum;
UpdateTable();
isLoading = false;
}
protected void SortRequested(SortCallBack e)
{
sortField = e.ParamName;
sortAsc = e.IsAscending;
UpdateTable();
}
private bool sortAsc
{
get
{
bool answ = false;
var sVal = MServ.UsrParamGet("InstAppStatsSortAsc");
if (!string.IsNullOrEmpty(sVal))
{
bool.TryParse(sVal, out answ);
}
return answ;
}
set => MServ.UsrParamSet("InstAppStatsSortAsc", $"{value}");
}
private string sortField
{
get => MServ.UsrParamGet("InstAppStatsSortField");
set => MServ.UsrParamSet("InstAppStatsSortField", $"{value}");
}
#endregion Protected Methods
#region Private Fields
private int currPage = 1;
private bool isLoading = false;
private int numRecord = 10;
private int totalCount = 0;
#endregion Private Fields
#region Private Properties
[Inject]
protected MessageService MServ { get; set; } = null!;
private AppStatusDTO? CurrRecord { get; set; } = null;
private List<AppStatusDTO> ListRecord { get; set; } = new List<AppStatusDTO>();
private List<AppStatusDTO> SearchRecord { get; set; } = new List<AppStatusDTO>();
#endregion Private Properties
#region Private Methods
private string checkSelect(string codApp)
{
string answ = (CurrRecord != null && codApp == CurrRecord.CodApp) ? "table-info" : "";
return answ;
}
private string tblCol
{
get => CurrRecord == null ? "col-12" : "col-3";
}
private void DoSelect(AppStatusDTO selRec)
{
CurrRecord = selRec;
}
private void UpdateTable()
{
SearchRecord = AppStats;
totalCount = SearchRecord.Count;
// se ho ordinamento riordino...
if (!string.IsNullOrEmpty(sortField))
{
switch (sortField)
{
case "CodApp":
if (sortAsc)
{
SearchRecord = SearchRecord.OrderBy(x => x.CodApp).ThenByDescending(x => x.NumImp).ToList();
}
else
{
SearchRecord = SearchRecord.OrderByDescending(x => x.CodApp).ThenByDescending(x => x.NumImp).ToList();
}
break;
case "NumInst":
if (sortAsc)
{
SearchRecord = SearchRecord.OrderBy(x => x.NumInst).ThenByDescending(x => x.NumImp).ToList();
}
else
{
SearchRecord = SearchRecord.OrderByDescending(x => x.NumInst).ThenByDescending(x => x.NumImp).ToList();
}
break;
case "NumImp":
if (sortAsc)
{
SearchRecord = SearchRecord.OrderBy(x => x.NumImp).ThenByDescending(x => x.NumInst).ToList();
}
else
{
SearchRecord = SearchRecord.OrderByDescending(x => x.NumImp).ThenByDescending(x => x.NumInst).ToList();
}
break;
case "VersNumCurrent":
if (sortAsc)
{
SearchRecord = SearchRecord.OrderBy(x => x.VersNumCurrent).ThenByDescending(x => x.NumImp).ToList();
}
else
{
SearchRecord = SearchRecord.OrderByDescending(x => x.VersNumCurrent).ThenByDescending(x => x.NumImp).ToList();
}
break;
case "UpdateScore":
if (sortAsc)
{
SearchRecord = SearchRecord.OrderBy(x => x.UpdateScore).ThenByDescending(x => x.NumImp).ToList();
}
else
{
SearchRecord = SearchRecord.OrderByDescending(x => x.UpdateScore).ThenByDescending(x => x.NumImp).ToList();
}
break;
default:
SearchRecord = SearchRecord
.OrderByDescending(x => x.NumImp)
.ToList();
break;
}
}
ListRecord = SearchRecord
.Skip((currPage - 1) * numRecord)
.Take(numRecord)
.ToList();
}
#endregion Private Methods
}
}