Aggiunta preliminare componente selezione filtro
This commit is contained in:
@@ -0,0 +1,119 @@
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.AspNetCore.Components.Forms;
|
||||
using Microsoft.AspNetCore.Components.Rendering;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MP.Stats.Components
|
||||
{
|
||||
public class InputDateTime<TValue> : InputDate<TValue>
|
||||
{
|
||||
#region Private Fields
|
||||
|
||||
private const string DateFormat = "yyyy-MM-ddTHH:mm";
|
||||
|
||||
#endregion Private Fields
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private static bool TryParseDateTime(string value, out TValue result)
|
||||
{
|
||||
var success = BindConverter.TryConvertToDateTime(value, CultureInfo.InvariantCulture, DateFormat, out var parsedValue);
|
||||
if (success)
|
||||
{
|
||||
result = (TValue)(object)parsedValue;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = default;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool TryParseDateTimeOffset(string value, out TValue result)
|
||||
{
|
||||
var success = BindConverter.TryConvertToDateTimeOffset(value, CultureInfo.InvariantCulture, DateFormat, out var parsedValue);
|
||||
if (success)
|
||||
{
|
||||
result = (TValue)(object)parsedValue;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = default;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Private Methods
|
||||
|
||||
#region Protected Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void BuildRenderTree(RenderTreeBuilder builder)
|
||||
{
|
||||
builder.OpenElement(0, "input");
|
||||
builder.AddMultipleAttributes(1, AdditionalAttributes);
|
||||
builder.AddAttribute(2, "type", "datetime-local");
|
||||
builder.AddAttribute(3, "class", CssClass);
|
||||
builder.AddAttribute(4, "value", BindConverter.FormatValue(CurrentValueAsString));
|
||||
builder.AddAttribute(5, "onchange", EventCallback.Factory.CreateBinder<string>(this, __value => CurrentValueAsString = __value, CurrentValueAsString));
|
||||
builder.CloseElement();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override string FormatValueAsString(TValue value)
|
||||
{
|
||||
switch (value)
|
||||
{
|
||||
case DateTime dateTimeValue:
|
||||
return BindConverter.FormatValue(dateTimeValue, DateFormat, CultureInfo.InvariantCulture);
|
||||
|
||||
case DateTimeOffset dateTimeOffsetValue:
|
||||
return BindConverter.FormatValue(dateTimeOffsetValue, DateFormat, CultureInfo.InvariantCulture);
|
||||
|
||||
default:
|
||||
return string.Empty; // Handles null for Nullable<DateTime>, etc.
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override bool TryParseValueFromString(string value, out TValue result, out string validationErrorMessage)
|
||||
{
|
||||
// Unwrap nullable types. We don't have to deal with receiving empty values for nullable
|
||||
// types here, because the underlying InputBase already covers that.
|
||||
var targetType = Nullable.GetUnderlyingType(typeof(TValue)) ?? typeof(TValue);
|
||||
|
||||
bool success;
|
||||
if (targetType == typeof(DateTime))
|
||||
{
|
||||
success = TryParseDateTime(value, out result);
|
||||
}
|
||||
else if (targetType == typeof(DateTimeOffset))
|
||||
{
|
||||
success = TryParseDateTimeOffset(value, out result);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InvalidOperationException($"The type '{targetType}' is not a supported date type.");
|
||||
}
|
||||
|
||||
if (success)
|
||||
{
|
||||
validationErrorMessage = null;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
validationErrorMessage = string.Format(ParsingErrorMessage, FieldIdentifier.FieldName);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Protected Methods
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
@using MP.Stats.Components
|
||||
@using MP.Stats.Data
|
||||
|
||||
<EditForm Model="@SelFilter">
|
||||
<div class="row">
|
||||
<div class="col-3">
|
||||
<div class="form-group">
|
||||
<label for="dtInizio" class="small">inizio:</label>
|
||||
<InputDateTime id="dtInizio" class="form-control form-control-sm" @bind-Value="@DateStart"></InputDateTime>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-3">
|
||||
<div class="form-group">
|
||||
<label for="dtFine" class="small">fine:</label>
|
||||
<InputDateTime id="dtFine" class="form-control form-control-sm" @bind-Value="@DateEnd"></InputDateTime>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-2">
|
||||
<div class="form-group">
|
||||
<label for="idxMacc" class="small">macchina:</label>
|
||||
<input id="idxMacc" class="form-control form-control-sm" @bind="@IdxMacchina" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-2">
|
||||
<div class="form-group">
|
||||
<label for="idxODL" class="small">ODL:</label>
|
||||
<InputNumber id="idxODL" class="form-control form-control-sm" @bind-Value="@IdxODL"></InputNumber>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-2">
|
||||
|
||||
<div class="form-group">
|
||||
<label for="CodArt" class="small">articolo:</label>
|
||||
<input id="CodArt" class="form-control form-control-sm" @bind="@CodArticolo" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</EditForm>
|
||||
|
||||
@code {
|
||||
|
||||
protected DateTime DateStart
|
||||
{
|
||||
get
|
||||
{
|
||||
return SelFilter.DateStart;
|
||||
}
|
||||
set
|
||||
{
|
||||
bool doReport = (!SelFilter.DateStart.Equals(value));
|
||||
SelFilter.DateStart = value;
|
||||
if (doReport)
|
||||
{
|
||||
reportChange();
|
||||
}
|
||||
}
|
||||
}
|
||||
protected DateTime DateEnd
|
||||
{
|
||||
get
|
||||
{
|
||||
return SelFilter.DateEnd;
|
||||
}
|
||||
set
|
||||
{
|
||||
bool doReport = (!SelFilter.DateEnd.Equals(value));
|
||||
SelFilter.DateEnd = value;
|
||||
if (doReport)
|
||||
{
|
||||
reportChange();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected string IdxMacchina
|
||||
{
|
||||
get
|
||||
{
|
||||
return SelFilter.IdxMacchina;
|
||||
}
|
||||
set
|
||||
{
|
||||
bool doReport = (!SelFilter.IdxMacchina.Equals(value));
|
||||
SelFilter.IdxMacchina = value;
|
||||
if (doReport)
|
||||
{
|
||||
reportChange();
|
||||
}
|
||||
}
|
||||
}
|
||||
protected int IdxODL
|
||||
{
|
||||
get
|
||||
{
|
||||
return SelFilter.IdxOdl;
|
||||
}
|
||||
set
|
||||
{
|
||||
bool doReport = (!SelFilter.IdxOdl.Equals(value));
|
||||
SelFilter.IdxOdl = value;
|
||||
if (doReport)
|
||||
{
|
||||
reportChange();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected string CodArticolo
|
||||
{
|
||||
get
|
||||
{
|
||||
return SelFilter.CodArticolo;
|
||||
}
|
||||
set
|
||||
{
|
||||
bool doReport = (!SelFilter.CodArticolo.Equals(value));
|
||||
SelFilter.CodArticolo = value;
|
||||
if (doReport)
|
||||
{
|
||||
reportChange();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Parameter]
|
||||
public SelectData SelFilter { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public EventCallback<SelectData> filterChanged { get; set; }
|
||||
|
||||
private void reportChange()
|
||||
{
|
||||
filterChanged.InvokeAsync(SelFilter);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
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);
|
||||
public string IdxMacchina { get; set; } = "*";
|
||||
public int IdxOdl { get; set; } = -999;
|
||||
public string KeyRichiesta { get; set; } = "*";
|
||||
|
||||
#endregion Public Properties
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (!(obj is SelectData item))
|
||||
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;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return base.GetHashCode();
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user