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 DetailInfo { get; set; } = new Dictionary(); [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, "
")); } #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; } /// /// Chiave sel x display dettaglio /// private string keySelected = ""; /// /// Toggle visualizzazione licenza /// /// 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 ListRecord = new Dictionary(); private int numRecord = 5; private Dictionary SearchRecord = new Dictionary(); 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 /// /// Esegue abbreviazione se supera limite tenendo inizio e fine... /// /// /// /// 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 } }