|
|
@ -1,13 +1,25 @@
|
|
|
|
using Connected.Models;
|
|
|
|
using Connected.Models;
|
|
|
|
|
|
|
|
using Connected.Utilities;
|
|
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
using System.Numerics;
|
|
|
|
using System.Numerics;
|
|
|
|
|
|
|
|
using static Connected.Colors;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Connected.Components;
|
|
|
|
namespace Connected.Components;
|
|
|
|
public partial class InputNumber<NumberType>:InputBase where NumberType : INumber<NumberType>
|
|
|
|
public partial class InputNumber<NumberType>:InputBase where NumberType : INumber<NumberType>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
private double _step;
|
|
|
|
[Parameter]
|
|
|
|
[Parameter]
|
|
|
|
public double Step { get; set; }
|
|
|
|
public double Step {
|
|
|
|
|
|
|
|
get
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return _step;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
set
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_step = value;
|
|
|
|
|
|
|
|
AdjustStep();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
[Parameter]
|
|
|
|
public NumberType Value { get; set; }
|
|
|
|
public NumberType Value { get; set; }
|
|
|
@ -23,18 +35,56 @@ public partial class InputNumber<NumberType>:InputBase where NumberType : INumbe
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (args.Value is not null)
|
|
|
|
if (args.Value is not null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
NumberType originalValue = (NumberType)Convert.ChangeType(args.Value, typeof(NumberType));
|
|
|
|
if (args.Value.ToString().Length > 0)
|
|
|
|
NumberType value = originalValue;
|
|
|
|
|
|
|
|
if (value.ToString().Length > 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
await ValueChanged.InvokeAsync((NumberType)Convert.ChangeType(args.Value, typeof(NumberType)));
|
|
|
|
|
|
|
|
|
|
|
|
value = AdjustDecimalPlaces(value);
|
|
|
|
|
|
|
|
//await ValueChanged.InvokeAsync((NumberType)Convert.ChangeType(value, typeof(NumberType)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
await ValueChanged.InvokeAsync((NumberType)Convert.ChangeType(0, typeof(NumberType)));
|
|
|
|
value = (NumberType)Convert.ChangeType(0, typeof(NumberType));
|
|
|
|
|
|
|
|
//await ValueChanged.InvokeAsync((NumberType)Convert.ChangeType(0, typeof(NumberType)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Value = value;
|
|
|
|
|
|
|
|
await ValueChanged.InvokeAsync((NumberType)Convert.ChangeType(Value, typeof(NumberType)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void AdjustStep()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (DecimalPlaces > 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var StepDecmalPlaces = Helper.GetDecimalPlaces(_step);
|
|
|
|
|
|
|
|
if (StepDecmalPlaces > DecimalPlaces)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
double MinStep = 1;
|
|
|
|
|
|
|
|
for (int i = 0; i < DecimalPlaces; i++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
MinStep = MinStep / 10;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
_step = MinStep;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private NumberType AdjustDecimalPlaces(NumberType value)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
NumberType result = value;
|
|
|
|
|
|
|
|
if (Helper.NumberHasDecimalPlaces(value))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (DecimalPlaces > 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
decimal rounded = (decimal)Convert.ChangeType(value, typeof(decimal));
|
|
|
|
|
|
|
|
rounded = Math.Round(rounded, DecimalPlaces);
|
|
|
|
|
|
|
|
result = (NumberType)Convert.ChangeType(rounded, typeof(NumberType));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private async Task Clear()
|
|
|
|
private async Task Clear()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
await ValueChanged.InvokeAsync((NumberType)Convert.ChangeType(0, typeof(NumberType)));
|
|
|
|
await ValueChanged.InvokeAsync((NumberType)Convert.ChangeType(0, typeof(NumberType)));
|
|
|
@ -42,14 +92,23 @@ public partial class InputNumber<NumberType>:InputBase where NumberType : INumbe
|
|
|
|
|
|
|
|
|
|
|
|
#region Lifecycle
|
|
|
|
#region Lifecycle
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (DecimalPlaces > 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Value = AdjustDecimalPlaces(Value);
|
|
|
|
|
|
|
|
await ValueChanged.InvokeAsync(Value);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
AdjustStep();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override async Task OnParametersSetAsync()
|
|
|
|
protected override async Task OnParametersSetAsync()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (typeof(NumberType).Name.ToLower().Contains("int"))
|
|
|
|
if (typeof(NumberType).Name.ToLower().Contains("int"))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (Step-(int)Step>0) Step= (int)Step;
|
|
|
|
if (Step - (int)Step > 0) Step = (int)Step;
|
|
|
|
if (Step < 1) Step = 1;
|
|
|
|
if (Step < 1) Step = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
await base.OnParametersSetAsync();
|
|
|
|
await base.OnParametersSetAsync();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|