using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace MP.Stats.Data
{
public class SelectData
{
#region Public Properties
public string CodArticolo { get; set; } = "*";
public DateTime DateEnd { get; set; } = DateTime.Now.AddMinutes(1);
public DateTime DateStart { get; set; } = DateTime.Now.AddDays(-7);
///
/// Primo record x selezione paginata, tipicamente primo della "decina" della pagina corrente
///
public int FirstRecord
{
get
{
int primaPag = PageNum % 10;
int decina = PageNum - primaPag;
return PageSize * decina + 1;
}
}
public string IdxMacchina { get; set; } = "*";
public List ListIdxMaccSel { get; set; } = new List();
public int IdxOdl { get; set; } = -999;
public string KeyRichiesta { get; set; } = "*";
public string Azione { get; set; } = "*";
///
/// Numero record da recuperare, tipicamente la decina della pag corrente (10 * PageSize)
///
public int NumRecord
{
get
{
return PageSize * 10;
}
}
public bool MaccSelValid
{
get => ListIdxMaccSel != null && ListIdxMaccSel.Count > 0;
}
public int PageNum { get; set; } = 1;
public int PageSize { get; set; } = 10;
#endregion Public Properties
#region Public Methods
///
/// Inizializzazione con periodo e arrotondamento
///
///
///
///
public static SelectData Init(int minRound, int numDayPrev)
{
TimeSpan DayElapsed = DateTime.Now.Subtract(DateTime.Today);
int minDay = (int)(DayElapsed.TotalMinutes / minRound) * minRound;
DateTime endRounded = DateTime.Today.AddMinutes(minDay);
SelectData answ = new SelectData()
{
DateEnd = endRounded,
DateStart = endRounded.AddDays(-numDayPrev)
};
return answ;
}
public override bool Equals(object obj)
{
if (!(obj is SelectData item))
return false;
if (PageSize != item.PageSize)
return false;
if (PageNum != item.PageNum)
return false;
if (CodArticolo != item.CodArticolo)
return false;
if (DateEnd != item.DateEnd)
return false;
if (DateStart != item.DateStart)
return false;
if (IdxMacchina != item.IdxMacchina)
return false;
if (IdxOdl != item.IdxOdl)
return false;
if (KeyRichiesta != item.KeyRichiesta)
return false;
if (Azione != item.Azione)
return false;
return true;
}
public override int GetHashCode()
{
return base.GetHashCode();
}
#endregion Public Methods
}
}