/// <summary>Runs the Array Decimal calculation. /// <para>parameters = JSON congifurations relating to this function</para> /// <para>InputA = value to be passed into the calculation</para> /// </summary> public string DecimalCalculation(ArrayFunctions parameters, dynamic InputA) { MathematicalFunctions MathFunctions = new MathematicalFunctions(); //Sums up all values in the array if (parameters.Function == "Sum") { string[] Deci1parts = null; Deci1parts = InputA.Split('~'); decimal Sum = 0; foreach (string output in Deci1parts) { decimal InputADeci = 0; decimal.TryParse(output, out InputADeci); Sum = decimal.Add(Sum, InputADeci); } return Convert.ToString(Sum); } //Multiplies all values in the array else if (parameters.Function == "Product") { string[] Deci1parts = null; Deci1parts = InputA.Split('~'); decimal Sum = 0; int counter = 0; foreach (string output in Deci1parts) { decimal InputADeci = 0; decimal.TryParse(output, out InputADeci); if (counter == 0) { Sum = InputADeci; } else { Sum = decimal.Multiply(Sum, InputADeci); } counter = counter + 1; } return Convert.ToString(Sum); } //Gets the first number in the array else if (parameters.Function == "FirstNumber") { string[] Deci1parts = null; Deci1parts = InputA.Split('~'); return Convert.ToString(Deci1parts[0]); } //Gets the last number in the array else if (parameters.Function == "LastNumber") { string[] Deci1parts = null; Deci1parts = InputA.Split('~'); return Convert.ToString(Deci1parts[Deci1parts.GetUpperBound(0)]); } //Calculates Total Period in the array else if (parameters.Function == "TotalPeriod") { string[] Deci1parts = null; Deci1parts = InputA.Split('~'); decimal Sum = 0; int counter = 0; bool firstpass = false; foreach (string output in Deci1parts) { if(firstpass == false) { if(Deci1parts.Length > 1) { Sum = MathFunctions.AddPeriod(Convert.ToDecimal(output), Convert.ToDecimal(Deci1parts[counter + 1]), parameters.PeriodType); } else { Sum = Convert.ToDecimal(output); } firstpass = true; } else if (Deci1parts.Length > 2 && counter >= 2) { Sum = MathFunctions.AddPeriod(Sum, Convert.ToDecimal(output), parameters.PeriodType); } counter = counter + 1; } if(parameters.PeriodType == "YearsDays") { return MathFunctions.RoundingDecimalPlaces("3", Sum); } else { return MathFunctions.RoundingDecimalPlaces("2", Sum); } } //Counts the number or values in the array else if (parameters.Function == "Count") { string[] Deci1parts = null; Deci1parts = InputA.Split('~'); return Convert.ToString(Deci1parts.Length); } else { return Convert.ToString(0); } }
/// <summary>Runs the Maths Functions calculation. /// <para>parameters = JSON congifurations relating to this function</para> /// <para>InputADeci = value to be passed into the calculation</para> /// <para>InputBDeci = value to be passed into the calculation</para> /// </summary> public decimal Calculate(MathsFunctions parameters, dynamic InputADeci, dynamic InputBDeci, int ItemID, CategoryViewModel group) { MathematicalFunctions MathFunctions = new MathematicalFunctions(); Decimal Output = 0; Rounding = Convert.ToString(parameters.Rounding); if (Rounding == null || Rounding == "") { Rounding = "2"; } //Absolute if (parameters.Type == "Abs") { Output = MathFunctions.Abs(InputADeci); } //Add else if (parameters.Type == "Add") { Output = MathFunctions.Add(InputADeci, InputBDeci); } //Add Period else if (parameters.Type == "AddPeriod") { Output = MathFunctions.AddPeriod(InputADeci, InputBDeci, parameters.PeriodType); Rounding = "2"; if (parameters.PeriodType == "YearsDays") { Rounding = "3"; } } //Ceiling else if (parameters.Type == "Ceiling") { Output = MathFunctions.Ceiling(InputADeci); } //Get decimal part only else if (parameters.Type == "DecimalPart") { Output = MathFunctions.DecimalPart(InputADeci); } //Divide else if (parameters.Type == "Divide") { Output = MathFunctions.Divide(InputADeci, InputBDeci); } //Floor to lowest integer else if (parameters.Type == "Floor") { Output = MathFunctions.Floor(InputADeci); } //Max of two values else if (parameters.Type == "Max") { Output = MathFunctions.Max(InputADeci, InputBDeci); } //Min of two values else if (parameters.Type == "Min") { Output = MathFunctions.Min(InputADeci, InputBDeci); } //Multiply of two values else if (parameters.Type == "Multiply") { Output = MathFunctions.Multiply(InputADeci, InputBDeci); } //Power of two value else if (parameters.Type == "Power") { Output = MathFunctions.Power(InputADeci, InputBDeci); } //Subtract two value else if (parameters.Type == "Subtract") { Output = MathFunctions.Subtract(InputADeci, InputBDeci); } //Subtract two value else if (parameters.Type == "SumDecimalAbove") { var filterList = group.Functions.Where((l, index) => index >= (ItemID - InputADeci) && index < ItemID); Output = 0; foreach (var row in filterList) { if (row.Type == "Decimal" && row.Pass != "miss") { Output = Output + Convert.ToDecimal(row.Output); } } } //Subtract two period value else if (parameters.Type == "SubtractPeriod") { Output = MathFunctions.SubtractPeriod(InputADeci, InputBDeci, parameters.PeriodType); Rounding = "2"; if (parameters.PeriodType == "YearsDays") { Rounding = "3"; } } //Truncate else if (parameters.Type == "Truncate") { Output = MathFunctions.Truncate(InputADeci); } return(MathFunctions.Rounding(parameters.RoundingType, Rounding, Output)); }
/// <summary>Runs the Maths Functions calculation. /// <para>parameters = JSON congifurations relating to this function</para> /// <para>InputADeci = value to be passed into the calculation</para> /// <para>InputBDeci = value to be passed into the calculation</para> /// </summary> public decimal Calculate(MathsFunctions parameters, dynamic InputADeci, dynamic InputBDeci) { MathematicalFunctions MathFunctions = new MathematicalFunctions(); Decimal Output = 0; Rounding = Convert.ToString(parameters.Rounding); if (Rounding == null || Rounding == "") { Rounding = "2"; } //Absolute if (parameters.Type == "Abs") { Output = MathFunctions.Abs(InputADeci); } //Add else if (parameters.Type == "Add") { Output = MathFunctions.Add(InputADeci, InputBDeci); } //Add Period else if (parameters.Type == "AddPeriod") { Output = MathFunctions.AddPeriod(InputADeci, InputBDeci, parameters.PeriodType); Rounding = "2"; if (parameters.PeriodType == "YearsDays") { Rounding = "3"; } } //Ceiling else if (parameters.Type == "Ceiling") { Output = MathFunctions.Ceiling(InputADeci); } //Get decimal part only else if (parameters.Type == "DecimalPart") { Output = MathFunctions.DecimalPart(InputADeci); } //Divide else if (parameters.Type == "Divide") { Output = MathFunctions.Divide(InputADeci, InputBDeci); } //Floor to lowest integer else if (parameters.Type == "Floor") { Output = MathFunctions.Floor(InputADeci); } //Max of two values else if (parameters.Type == "Max") { Output = MathFunctions.Max(InputADeci, InputBDeci); } //Min of two values else if (parameters.Type == "Min") { Output = MathFunctions.Min(InputADeci, InputBDeci); } //Multiply of two values else if (parameters.Type == "Multiply") { Output = MathFunctions.Multiply(InputADeci, InputBDeci); } //Power of two value else if (parameters.Type == "Power") { Output = MathFunctions.Power(InputADeci, InputBDeci); } //Subtract two value else if (parameters.Type == "Subtract") { Output = MathFunctions.Subtract(InputADeci, InputBDeci); } //Subtract two period value else if (parameters.Type == "SubtractPeriod") { Output = MathFunctions.SubtractPeriod(InputADeci, InputBDeci, parameters.PeriodType); Rounding = "2"; if (parameters.PeriodType == "YearsDays") { Rounding = "3"; } } //Truncate else if (parameters.Type == "Truncate") { Output = MathFunctions.Truncate(InputADeci); } return MathFunctions.Rounding(parameters.RoundingType, Rounding, Output); }
/// <summary>Runs the Array Decimal calculation. /// <para>parameters = JSON congifurations relating to this function</para> /// <para>InputA = value to be passed into the calculation</para> /// </summary> public string DecimalCalculation(ArrayFunctions parameters, dynamic InputA) { MathematicalFunctions MathFunctions = new MathematicalFunctions(); //Sums up all values in the array if (parameters.Function == "Sum") { string[] Deci1parts = null; Deci1parts = InputA.Split('~'); decimal Sum = 0; foreach (string output in Deci1parts) { decimal InputADeci = 0; decimal.TryParse(output, out InputADeci); Sum = decimal.Add(Sum, InputADeci); } return(Convert.ToString(Sum)); } //Multiplies all values in the array else if (parameters.Function == "Product") { string[] Deci1parts = null; Deci1parts = InputA.Split('~'); decimal Sum = 0; int counter = 0; foreach (string output in Deci1parts) { decimal InputADeci = 0; decimal.TryParse(output, out InputADeci); if (counter == 0) { Sum = InputADeci; } else { Sum = decimal.Multiply(Sum, InputADeci); } counter = counter + 1; } return(Convert.ToString(Sum)); } //Gets the first number in the array else if (parameters.Function == "FirstNumber") { string[] Deci1parts = null; Deci1parts = InputA.Split('~'); return(Convert.ToString(Deci1parts[0])); } //Gets the last number in the array else if (parameters.Function == "LastNumber") { string[] Deci1parts = null; Deci1parts = InputA.Split('~'); return(Convert.ToString(Deci1parts[Deci1parts.GetUpperBound(0)])); } //Calculates Total Period in the array else if (parameters.Function == "TotalPeriod") { string[] Deci1parts = null; Deci1parts = InputA.Split('~'); decimal Sum = 0; int counter = 0; bool firstpass = false; foreach (string output in Deci1parts) { if (firstpass == false) { if (Deci1parts.Length > 1) { Sum = MathFunctions.AddPeriod(Convert.ToDecimal(output), Convert.ToDecimal(Deci1parts[counter + 1]), parameters.PeriodType); } else { Sum = Convert.ToDecimal(output); } firstpass = true; } else if (Deci1parts.Length > 2 && counter >= 2) { Sum = MathFunctions.AddPeriod(Sum, Convert.ToDecimal(output), parameters.PeriodType); } counter = counter + 1; } if (parameters.PeriodType == "YearsDays") { return(MathFunctions.RoundingDecimalPlaces("3", Sum)); } else { return(MathFunctions.RoundingDecimalPlaces("2", Sum)); } } //Counts the number or values in the array else if (parameters.Function == "Count") { string[] Deci1parts = null; Deci1parts = InputA.Split('~'); return(Convert.ToString(Deci1parts.Length)); } else { return(Convert.ToString(0)); } }