Files
limanapp/LiMan.UI/Components/InstAppPareto.razor.cs
T
2025-01-16 19:52:27 +01:00

187 lines
5.5 KiB
C#

using EgwCoreLib.Razor.Data;
using LiMan.DB.DTO;
using LiMan.UI.Data;
using Microsoft.AspNetCore.Components;
using Org.BouncyCastle.Ocsp;
using System;
using System.Collections.Generic;
using System.Linq;
namespace LiMan.UI.Components
{
public partial class InstAppPareto
{
#region Public Properties
[Parameter]
public AppStatusDTO CurrRecord { get; set; } = null!;
#endregion Public Properties
#region Protected Properties
protected List<AppRelStatusDTO> ListRecord { get; set; } = new List<AppRelStatusDTO>();
[Inject]
protected MessageService MServ { get; set; } = null!;
protected List<AppRelStatusDTO> SearchRecord { get; set; } = new List<AppRelStatusDTO>();
#endregion Protected Properties
#region Protected Methods
protected override void OnParametersSet()
{
ReloadData();
ReloadCharts();
}
/// <summary>
/// Imposta dati x filtrare analisi su impianto selezionato x applicazioni e info accessorie...
/// </summary>
/// <param name="currRec"></param>
protected void SetCodImp(AppRelStatusDTO currRec)
{
// salvo nelle preferenze i valori CodImp e PcInst
MServ.UsrParamSet("Cliente", currRec.Cliente);
MServ.UsrParamSet("CodImp", currRec.CodImp);
MServ.UsrParamSet("PcInst", currRec.PcInst);
// Richiedo azione x gestione dettaglio info
MServ.ReportReqInstDetail();
}
protected void setNumPage(int newNum)
{
currPage = newNum;
ReloadData();
isLoading = false;
}
protected void setNumRec(int newNum)
{
numRecord = newNum;
ReloadData();
isLoading = false;
}
#endregion Protected Methods
#region Private Fields
private List<DoughnutStyling> ChartColor = new List<DoughnutStyling>();
private double[] ChartData = new double[1];
private string[] ChartLabels = new string[1];
private int currPage = 1;
private bool isLoading = false;
private int numRecord = 25;
private int totalCount = 0;
#endregion Private Fields
#region Private Methods
private string cssVers(AppRelStatusDTO rec)
{
string answ = "";
switch (rec.UpToDateStatus)
{
case 4:
answ = "text-success fw-bold";
break;
case 3:
answ = "text-success";
break;
case 2:
answ = "text-warning";
break;
case 1:
answ = "text-danger";
break;
case 0:
answ = "text-danger fw-bold";
break;
default:
break;
}
return answ;
}
private void ReloadCharts()
{
// sistemo info x grafico... se ho impieghi uso quello, altrimenti istanze...
if (CurrRecord.NumImp > 0)
{
ChartData = SearchRecord
.GroupBy(x => x.VersNumInstall)
.Select(g => (double)g.Sum(x => x.NumImp))
.ToArray();
}
else
{
ChartData = SearchRecord
.GroupBy(x => x.VersNumInstall)
.Select(g => (double)g.Count())
.ToArray();
}
ChartLabels = SearchRecord
.GroupBy(x => x.VersNumInstall)
.Select(g => g.Key)
.ToArray();
ChartColor.Clear();
var listStatus = SearchRecord
.GroupBy(x => x.VersNumInstall)
.Select(g => g.First().UpToDateStatus)
.ToList();
foreach (var item in listStatus)
{
switch (item)
{
case 4:
ChartColor.Add(new DoughnutStyling("#12FF06", "#006900"));
break;
case 3:
ChartColor.Add(new DoughnutStyling("#ABFF69", "#11AA11"));
break;
case 2:
ChartColor.Add(new DoughnutStyling("#FFE493", "#AAFF00"));
break;
case 1:
ChartColor.Add(new DoughnutStyling("#FF6900", "#953500"));
break;
case 0:
ChartColor.Add(new DoughnutStyling("#AA3600", "#AA0000"));
break;
default:
break;
}
}
}
private void ReloadData()
{
SearchRecord = CurrRecord.DetailInstalled
.OrderByDescending(x => x.VersNumInstall)
.ToList();
totalCount = SearchRecord.Count;
// sistemo tabella
ListRecord = SearchRecord
.Skip((currPage - 1) * numRecord)
.Take(numRecord)
.ToList();
}
#endregion Private Methods
}
}