Skip to content

Commit

Permalink
Added support for decimal and thousandth seperators saucepleez#177
Browse files Browse the repository at this point in the history
  • Loading branch information
saucepleez committed Jan 9, 2020
1 parent 21db3f1 commit eb5bc59
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion taskt/Core/Automation/Commands/MathCalculationCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,21 @@ public class MathCalculationCommand : ScriptCommand
[Attributes.PropertyAttributes.Remarks("You can use known numbers or variables.")]
public string v_InputValue { get; set; }

[XmlAttribute]
[Attributes.PropertyAttributes.PropertyDescription("Optional - Indicate Thousand Seperator")]
[Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)]
[Attributes.PropertyAttributes.InputSpecification("Enter the seperator used to identify decimal places")]
[Attributes.PropertyAttributes.SampleUsage("")]
[Attributes.PropertyAttributes.Remarks("Typically a comma or a decimal point (period)")]
public string v_ThousandSeperator { get; set; }

[XmlAttribute]
[Attributes.PropertyAttributes.PropertyDescription("Optional - Indicate Decimal Seperator")]
[Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)]
[Attributes.PropertyAttributes.InputSpecification("Enter the seperator used to identify decimal places")]
[Attributes.PropertyAttributes.SampleUsage("")]
[Attributes.PropertyAttributes.Remarks("Typically a comma or a decimal point (period)")]
public string v_DecimalSeperator { get; set; }

[XmlAttribute]
[Attributes.PropertyAttributes.PropertyDescription("Please select the variable to receive the math calculation")]
Expand All @@ -41,7 +56,8 @@ public MathCalculationCommand()
this.CustomRendering = true;

this.v_InputValue = "(2 + 5) * 3";

this.v_DecimalSeperator = ".";
this.v_ThousandSeperator = ",";
}

public override void RunCommand(object sender)
Expand All @@ -51,10 +67,29 @@ public override void RunCommand(object sender)

try
{
var decimalSeperator = v_DecimalSeperator.ConvertToUserVariable(sender);
var thousandSeperator = v_ThousandSeperator.ConvertToUserVariable(sender);

//remove thousandths markers
variableMath = variableMath.Replace(thousandSeperator, "");

//check decimal seperator
if (decimalSeperator != ".")
{
variableMath = variableMath.Replace(decimalSeperator, ".");
}

//perform compute
DataTable dt = new DataTable();
var result = dt.Compute(variableMath, "");

//restore decimal seperator
if (decimalSeperator != ".")
{
result = result.ToString().Replace(".", decimalSeperator);
}


//store string in variable
result.ToString().StoreInUserVariable(sender, v_applyToVariableName);
}
Expand All @@ -70,6 +105,8 @@ public override List<Control> Render(frmCommandEditor editor)

//create standard group controls
RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_InputValue", this, editor));
RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_ThousandSeperator", this, editor));
RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_DecimalSeperator", this, editor));

RenderedControls.Add(CommandControls.CreateDefaultLabelFor("v_applyToVariableName", this));
var VariableNameControl = CommandControls.CreateStandardComboboxFor("v_applyToVariableName", this).AddVariableNames(editor);
Expand Down

0 comments on commit eb5bc59

Please sign in to comment.