5d72d21fb1
Update gestione paginazione (visibile solo dove serve) + fix calcolo di alcuni intems male filtrati
210 lines
6.0 KiB
C#
210 lines
6.0 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;
|
|
using MailKit;
|
|
using System;
|
|
|
|
namespace LiMan.UI.Components
|
|
{
|
|
public partial class ListInfoShort
|
|
{
|
|
#region Public Properties
|
|
|
|
[Parameter]
|
|
public Dictionary<string, string> DetailInfo { get; set; } = new Dictionary<string, string>();
|
|
|
|
[Parameter]
|
|
public bool EnabAbbrev { get; set; } = false;
|
|
|
|
[Parameter]
|
|
public int MaxKeyChar { get; set; } = 20;
|
|
|
|
[Parameter]
|
|
public int MaxValChar { get; set; } = 40;
|
|
|
|
[Parameter]
|
|
public string Title { get; set; } = "Detail";
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Protected Properties
|
|
|
|
[Inject]
|
|
protected MessageService MServ { get; set; } = null!;
|
|
|
|
#endregion Protected Properties
|
|
|
|
protected MarkupString FixChars(string oString)
|
|
{
|
|
return new MarkupString(oString.Replace(Environment.NewLine, "<br/>"));
|
|
}
|
|
|
|
#region Protected Methods
|
|
|
|
protected override void OnParametersSet()
|
|
{
|
|
currPage = 1;
|
|
ReloadData();
|
|
}
|
|
|
|
protected void setNumPage(int newNum)
|
|
{
|
|
currPage = newNum;
|
|
ReloadData();
|
|
isLoading = false;
|
|
}
|
|
|
|
protected void setNumRec(int newNum)
|
|
{
|
|
currPage = 1;
|
|
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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Chiave sel x display dettaglio
|
|
/// </summary>
|
|
private string keySelected = "";
|
|
|
|
/// <summary>
|
|
/// Toggle visualizzazione licenza
|
|
/// </summary>
|
|
/// <param name="keySel"></param>
|
|
private void SetDetail(string keySel)
|
|
{
|
|
if (string.IsNullOrEmpty(keySelected))
|
|
{
|
|
keySelected = keySel;
|
|
}
|
|
else
|
|
{
|
|
keySelected = "";
|
|
}
|
|
}
|
|
|
|
#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
|
|
|
|
/// <summary>
|
|
/// Esegue abbreviazione se supera limite tenendo inizio e fine...
|
|
/// </summary>
|
|
/// <param name="oString"></param>
|
|
/// <param name="maxChar"></param>
|
|
/// <returns></returns>
|
|
private string Abbrev(string oString, int maxChar = 20)
|
|
{
|
|
string answ = oString;
|
|
if (oString.Length > maxChar)
|
|
{
|
|
answ = $"{oString.Substring(0, (maxChar / 2))}..{oString.Substring(oString.Length - (maxChar / 2))}";
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
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
|
|
}
|
|
} |