|
@@ -106,21 +106,21 @@ namespace Comal.Classes
|
|
|
{
|
|
|
|
|
|
if (unitid.IsEqualTo(name))
|
|
|
- Calculate(Quantity, Length, Width, Height, Weight, Unit.Formula, Unit.Format);
|
|
|
+ (this as IDimensions).Calculate(Quantity, Length, Width, Height, Weight, Unit.Formula, Unit.Format);
|
|
|
else if (quantity.IsEqualTo(name))
|
|
|
- Calculate(after, Length, Width, Height, Weight, Unit.Formula, Unit.Format);
|
|
|
+ (this as IDimensions).Calculate(after, Length, Width, Height, Weight, Unit.Formula, Unit.Format);
|
|
|
else if (length.IsEqualTo(name))
|
|
|
- Calculate(Quantity, after, Width, Height, Weight, Unit.Formula, Unit.Format);
|
|
|
+ (this as IDimensions).Calculate(Quantity, after, Width, Height, Weight, Unit.Formula, Unit.Format);
|
|
|
else if (width.IsEqualTo(name))
|
|
|
- Calculate(Quantity, Length, after, Height, Weight, Unit.Formula, Unit.Format);
|
|
|
+ (this as IDimensions).Calculate(Quantity, Length, after, Height, Weight, Unit.Formula, Unit.Format);
|
|
|
else if (height.IsEqualTo(name))
|
|
|
- Calculate(Quantity, Length, Width, after, Weight, Unit.Formula, Unit.Format);
|
|
|
+ (this as IDimensions).Calculate(Quantity, Length, Width, after, Weight, Unit.Formula, Unit.Format);
|
|
|
else if (weight.IsEqualTo(name))
|
|
|
- Calculate(Quantity, Length, Width, Height, after, Unit.Formula, Unit.Format);
|
|
|
+ (this as IDimensions).Calculate(Quantity, Length, Width, Height, after, Unit.Formula, Unit.Format);
|
|
|
else if (sizeformula.IsEqualTo(name))
|
|
|
- Calculate(Quantity, Length, Width, Height, Weight, after as string, Unit.Format);
|
|
|
+ (this as IDimensions).Calculate(Quantity, Length, Width, Height, Weight, after as string, Unit.Format);
|
|
|
else if (sizeformat.IsEqualTo(name))
|
|
|
- Calculate(Quantity, Length, Width, Height, Weight, Unit.Formula, after as string);
|
|
|
+ (this as IDimensions).Calculate(Quantity, Length, Width, Height, Weight, Unit.Formula, after as string);
|
|
|
}
|
|
|
finally
|
|
|
{
|
|
@@ -148,7 +148,7 @@ namespace Comal.Classes
|
|
|
Width = width;
|
|
|
Height = height;
|
|
|
Weight = weight;
|
|
|
- Calculate(quantity, length, width, height, weight, unit.Formula, unit.Format);
|
|
|
+ (this as IDimensions).Calculate(quantity, length, width, height, weight, unit.Formula, unit.Format);
|
|
|
}
|
|
|
finally
|
|
|
{
|
|
@@ -158,47 +158,7 @@ namespace Comal.Classes
|
|
|
|
|
|
public void CalculateValueAndUnitSize()
|
|
|
{
|
|
|
- Calculate(Quantity, Length, Width, Height, Weight, Unit.Formula, Unit.Format);
|
|
|
- }
|
|
|
-
|
|
|
- private void Calculate(object? quantity, object? length, object? width, object? height, object? weight, string? formula, string? format)
|
|
|
- {
|
|
|
- if (Evaluate<double>(formula, quantity, length, width, height, weight, out double value))
|
|
|
- Value = value;
|
|
|
- if (Evaluate<String>(format, quantity, length, width, height, weight, out string unitsize))
|
|
|
- UnitSize = unitsize;
|
|
|
- }
|
|
|
-
|
|
|
- private bool Evaluate<T>(string? formula, object? quantity, object? length, object? width, object? height, object? weight, out T result)
|
|
|
- {
|
|
|
-
|
|
|
- if (!String.IsNullOrWhiteSpace(formula))
|
|
|
- {
|
|
|
- var variables = new Dictionary<string, object?>()
|
|
|
- {
|
|
|
- { "Quantity", Convert.ToDouble(quantity) },
|
|
|
- { "Length", Convert.ToDouble(length) },
|
|
|
- { "Width", Convert.ToDouble(width) },
|
|
|
- { "Height", Convert.ToDouble(height) },
|
|
|
- { "Weight", Convert.ToDouble(weight) }
|
|
|
- };
|
|
|
- try
|
|
|
- {
|
|
|
- var expr = new CoreExpression(formula);
|
|
|
- var eval = expr.Evaluate(variables);
|
|
|
- result = (T)CoreUtils.ChangeType(eval, typeof(T));
|
|
|
- return true;
|
|
|
- }
|
|
|
- catch (Exception e)
|
|
|
- {
|
|
|
- Logger.Send(LogType.Information, "", String.Format("Error in Formula: [{0}] ({1})", formula, e.Message));
|
|
|
- result = default(T);
|
|
|
- return false;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- result = default(T);
|
|
|
- return true;
|
|
|
+ (this as IDimensions).Calculate(Quantity, Length, Width, Height, Weight, Unit.Formula, Unit.Format);
|
|
|
}
|
|
|
|
|
|
public void CopyFrom(IDimensions source, bool observing = false)
|
|
@@ -259,12 +219,15 @@ namespace Comal.Classes
|
|
|
public static class Dimensions
|
|
|
{
|
|
|
|
|
|
- private static readonly Column<IDimensions> unitid = new Column<IDimensions>(x => x.Unit.ID);
|
|
|
- private static readonly Column<IDimensions> quantity = new Column<IDimensions>(x => x.Quantity);
|
|
|
- private static readonly Column<IDimensions> length = new Column<IDimensions>(x => x.Length);
|
|
|
- private static readonly Column<IDimensions> width = new Column<IDimensions>(x => x.Width);
|
|
|
- private static readonly Column<IDimensions> height = new Column<IDimensions>(x => x.Height);
|
|
|
- private static readonly Column<IDimensions> weight = new Column<IDimensions>(x => x.Weight);
|
|
|
+ public static readonly Column<IDimensions> unitid = new Column<IDimensions>(x => x.Unit.ID);
|
|
|
+ public static readonly Column<IDimensions> quantity = new Column<IDimensions>(x => x.Quantity);
|
|
|
+ public static readonly Column<IDimensions> length = new Column<IDimensions>(x => x.Length);
|
|
|
+ public static readonly Column<IDimensions> width = new Column<IDimensions>(x => x.Width);
|
|
|
+ public static readonly Column<IDimensions> height = new Column<IDimensions>(x => x.Height);
|
|
|
+ public static readonly Column<IDimensions> weight = new Column<IDimensions>(x => x.Weight);
|
|
|
+
|
|
|
+ public static readonly Column<IDimensions> unitSize = new Column<IDimensions>(x => x.UnitSize);
|
|
|
+ public static readonly Column<IDimensions> value = new Column<IDimensions>(x => x.Value);
|
|
|
|
|
|
public static IEnumerable<Column<IDimensions>> GetFilterColumns()
|
|
|
{
|
|
@@ -457,5 +420,37 @@ namespace Comal.Classes
|
|
|
_ => LocalColumns<TDim>()
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
+ public static bool Evaluate<T>(string? formula, object? quantity, object? length, object? width, object? height, object? weight, out T result)
|
|
|
+ {
|
|
|
+
|
|
|
+ if (!String.IsNullOrWhiteSpace(formula))
|
|
|
+ {
|
|
|
+ var variables = new Dictionary<string, object?>()
|
|
|
+ {
|
|
|
+ { "Quantity", Convert.ToDouble(quantity) },
|
|
|
+ { "Length", Convert.ToDouble(length) },
|
|
|
+ { "Width", Convert.ToDouble(width) },
|
|
|
+ { "Height", Convert.ToDouble(height) },
|
|
|
+ { "Weight", Convert.ToDouble(weight) }
|
|
|
+ };
|
|
|
+ try
|
|
|
+ {
|
|
|
+ var expr = new CoreExpression(formula);
|
|
|
+ var eval = expr.Evaluate(variables);
|
|
|
+ result = (T)CoreUtils.ChangeType(eval, typeof(T));
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ Logger.Send(LogType.Information, "", String.Format("Error in Formula: [{0}] ({1})", formula, e.Message));
|
|
|
+ result = default(T);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ result = default(T);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
}
|
|
|
}
|