183 lines
6.5 KiB
C#
183 lines
6.5 KiB
C#
using MP.Data.DatabaseModels;
|
|
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace MP.Data
|
|
{
|
|
public class Utils
|
|
{
|
|
#region Public Properties
|
|
|
|
public static string redKeyArtUsed
|
|
{
|
|
get => RedHash($"SPEC:Cache:CheckArtUsed");
|
|
}
|
|
|
|
public static string redKeyTabCheckArt
|
|
{
|
|
get => RedHash($"CACHE:TabCheckArt");
|
|
}
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Public Methods
|
|
|
|
public static string ConvMinToTime(double minutes)
|
|
{
|
|
// FIXME TODO: da rendere parametrico da appsettings.json...
|
|
var ts = TimeSpan.FromMinutes(minutes);
|
|
string answ = $"{ts.Hours:00}:{ts.Minutes:00}:{ts.Seconds:00}"; //.{ts.Milliseconds}
|
|
return answ;
|
|
}
|
|
|
|
public static string ConvMsecToTime(long milliseconds)
|
|
{
|
|
// FIXME TODO: da rendere parametrico da appsettings.json...
|
|
var ts = TimeSpan.FromMilliseconds(milliseconds);
|
|
string answ = $"{ts.Hours:00}:{ts.Minutes:00}:{ts.Seconds:00}"; //.{ts.Milliseconds}
|
|
return answ;
|
|
}
|
|
|
|
public static string FormDurata(double durataMinuti)
|
|
{
|
|
string answ = "";
|
|
TimeSpan tsDurata = TimeSpan.FromMinutes(durataMinuti);
|
|
if (tsDurata.TotalDays < 1)
|
|
{
|
|
answ = $"{tsDurata.Hours:00}h {tsDurata.Minutes:00}'";
|
|
}
|
|
else
|
|
{
|
|
answ = $"{tsDurata.Days}gg {tsDurata.Hours:00}h";
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Inizializzazione con periodo e arrotondamento
|
|
/// </summary>
|
|
/// <param name="minRound"></param>
|
|
/// <returns></returns>
|
|
public static DateTime InitDatetime(DateTime dtRif, int minRound)
|
|
{
|
|
TimeSpan DayElapsed = dtRif.Subtract(dtRif.Date);
|
|
int minDay = (int)Math.Ceiling((double)(DayElapsed.TotalMinutes / minRound)) * minRound;
|
|
DateTime endRounded = DateTime.Today.AddMinutes(minDay);
|
|
return endRounded;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Nome della variabile HASH da utilizzare (dato CodModulo / Server / DB impiegato da
|
|
/// funzionalita' DbConfig) + keyName richiesto...
|
|
/// </summary>
|
|
public static string RedHash(string keyName)
|
|
{
|
|
string answ = keyName;
|
|
try
|
|
{
|
|
answ = $"MP:Data:{keyName}";
|
|
}
|
|
catch
|
|
{ }
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Effettua salvataggio in file di un generico oggetto in formato CSV
|
|
/// </summary>
|
|
/// <typeparam name="T"></typeparam>
|
|
/// <param name="reportData"></param>
|
|
/// <param name="path"></param>
|
|
/// <param name="separator">Separatore da impiegare</param>
|
|
/// <returns></returns>
|
|
public static async Task SaveToCsv<T>(List<T> reportData, string path, char separator)
|
|
{
|
|
var lines = new List<string>();
|
|
IEnumerable<PropertyDescriptor> props = TypeDescriptor.GetProperties(typeof(T)).OfType<PropertyDescriptor>();
|
|
var header = string.Join(";", props.ToList().Select(x => x.Name));
|
|
lines.Add(header);
|
|
var valueLines = reportData.Select(row => string.Join(separator, header.Split(separator).Select(a => row.GetType().GetProperty(a).GetValue(row, null))));
|
|
//var valueLines = reportData.Select(row => string.Join(";", header.Split(';').Select(a => row.GetType().GetProperty(a).GetValue(row, null))));
|
|
lines.AddRange(valueLines);
|
|
await Task.Run(() => File.WriteAllLines(path, lines.ToArray()));
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Public Classes
|
|
|
|
public class POdlExt
|
|
{
|
|
#region Public Methods
|
|
|
|
/// <summary>
|
|
/// Clona un POdleExt, tutti i valori (compreso idxOdl)
|
|
/// </summary>
|
|
/// <param name="selRec"></param>
|
|
/// <returns></returns>
|
|
public static PODLExpModel clone(PODLExpModel selRec, bool resetOdl)
|
|
{
|
|
// creo record duplicato...
|
|
PODLExpModel newRec = new PODLExpModel()
|
|
{
|
|
Attivabile = selRec.Attivabile,
|
|
CodArticolo = selRec.CodArticolo,
|
|
CodCli = selRec.CodCli,
|
|
CodGruppo = selRec.CodGruppo,
|
|
DueDate = selRec.DueDate,
|
|
IdxMacchina = selRec.IdxMacchina,
|
|
IdxOdl = resetOdl ? 0 : selRec.IdxOdl,
|
|
IdxPromessa = 0,
|
|
InsertDate = selRec.InsertDate,
|
|
KeyBCode = selRec.KeyBCode,
|
|
KeyRichiesta = selRec.KeyRichiesta,
|
|
Note = $"DUPLICATED - {selRec.Note}",
|
|
NumPezzi = selRec.NumPezzi,
|
|
Priorita = selRec.Priorita,
|
|
PzPallet = selRec.PzPallet,
|
|
Tcassegnato = selRec.Tcassegnato
|
|
};
|
|
return newRec;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Clona un POdleExt a POdl
|
|
/// </summary>
|
|
/// <param name="selRec"></param>
|
|
/// <returns></returns>
|
|
public static PODLModel convertToPOdl(PODLExpModel selRec)
|
|
{
|
|
// creo record duplicato...
|
|
PODLModel newRec = new PODLModel()
|
|
{
|
|
Attivabile = selRec.Attivabile,
|
|
CodArticolo = selRec.CodArticolo,
|
|
CodCli = selRec.CodCli,
|
|
CodGruppo = selRec.CodGruppo,
|
|
DueDate = selRec.DueDate,
|
|
IdxMacchina = selRec.IdxMacchina,
|
|
IdxOdl = selRec.IdxOdl,
|
|
IdxPromessa = selRec.IdxPromessa,
|
|
InsertDate = selRec.InsertDate,
|
|
KeyBCode = selRec.KeyBCode,
|
|
KeyRichiesta = selRec.KeyRichiesta,
|
|
Note = selRec.Note,
|
|
NumPezzi = selRec.NumPezzi,
|
|
Priorita = selRec.Priorita,
|
|
PzPallet = selRec.PzPallet,
|
|
Tcassegnato = selRec.Tcassegnato
|
|
};
|
|
return newRec;
|
|
}
|
|
|
|
#endregion Public Methods
|
|
}
|
|
|
|
#endregion Public Classes
|
|
}
|
|
} |