152 lines
4.4 KiB
C#
152 lines
4.4 KiB
C#
using LiMan.DB.DTO;
|
|
using LiMan.UI.Data;
|
|
using Microsoft.AspNetCore.Components;
|
|
using static EgwCoreLib.Razor.Sorter;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace LiMan.UI.Components
|
|
{
|
|
public partial class ListInfoShort
|
|
{
|
|
#region Public Properties
|
|
|
|
[Parameter]
|
|
public Dictionary<string, string> DetailInfo { get; set; } = new Dictionary<string, string>();
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Protected Properties
|
|
|
|
[Inject]
|
|
protected MessageService MServ { get; set; } = null!;
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
protected override void OnParametersSet()
|
|
{
|
|
ReloadData();
|
|
}
|
|
|
|
protected void setNumPage(int newNum)
|
|
{
|
|
currPage = newNum;
|
|
ReloadData();
|
|
isLoading = false;
|
|
}
|
|
|
|
protected void setNumRec(int newNum)
|
|
{
|
|
numRecord = newNum;
|
|
ReloadData();
|
|
isLoading = false;
|
|
}
|
|
|
|
protected void SortRequested(SortCallBack e)
|
|
{
|
|
isLoading = true;
|
|
if (sortField == e.ParamName)
|
|
{
|
|
sortAsc = e.IsAscending;
|
|
}
|
|
sortField = e.ParamName;
|
|
ReloadData();
|
|
isLoading = false;
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
private int currPage = 1;
|
|
private bool isLoading = false;
|
|
private Dictionary<string, string> ListRecord = new Dictionary<string, string>();
|
|
private int numRecord = 5;
|
|
private Dictionary<string, string> SearchRecord = new Dictionary<string, string>();
|
|
private string sKey = "ListAppShort";
|
|
private int totalCount = 0;
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Properties
|
|
|
|
private bool sortAsc
|
|
{
|
|
get
|
|
{
|
|
bool answ = false;
|
|
var sVal = MServ.UsrParamGet($"{sKey}_sort");
|
|
if (!string.IsNullOrEmpty(sVal))
|
|
{
|
|
bool.TryParse(sVal, out answ);
|
|
}
|
|
return answ;
|
|
}
|
|
set => MServ.UsrParamSet($"{sKey}_sort", $"{value}");
|
|
}
|
|
|
|
private string sortField
|
|
{
|
|
get => MServ.UsrParamGet($"{sKey}_field");
|
|
set => MServ.UsrParamSet($"{sKey}_field", $"{value}");
|
|
}
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Private Methods
|
|
|
|
private void ReloadData()
|
|
{
|
|
SearchRecord = DetailInfo;
|
|
totalCount = SearchRecord.Count;
|
|
// sistemo tabella
|
|
switch (sortField)
|
|
{
|
|
case "Key":
|
|
if (sortAsc)
|
|
{
|
|
SearchRecord = SearchRecord
|
|
.OrderBy(x => x.Key)
|
|
.ThenBy(x => x.Value)
|
|
.ToDictionary(x => x.Key, x => x.Value);
|
|
}
|
|
else
|
|
{
|
|
SearchRecord = SearchRecord
|
|
.OrderByDescending(x => x.Key)
|
|
.ThenBy(x => x.Value)
|
|
.ToDictionary(x => x.Key, x => x.Value);
|
|
}
|
|
break;
|
|
|
|
case "Value":
|
|
if (sortAsc)
|
|
{
|
|
SearchRecord = SearchRecord
|
|
.OrderBy(x => x.Value)
|
|
.ThenBy(x => x.Key)
|
|
.ToDictionary(x => x.Key, x => x.Value);
|
|
}
|
|
else
|
|
{
|
|
SearchRecord = SearchRecord
|
|
.OrderByDescending(x => x.Value)
|
|
.ThenBy(x => x.Key)
|
|
.ToDictionary(x => x.Key, x => x.Value);
|
|
}
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
ListRecord = SearchRecord
|
|
.Skip((currPage - 1) * numRecord)
|
|
.Take(numRecord)
|
|
.ToDictionary(x => x.Key, x => x.Value);
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |