/// <summary>Outputs where Date Part function is used includes the array builder. /// <para>jparameters = JSON congifurations relating to this function</para> /// <para>jCategory = the whole configuration which is required to do the variable replace</para> /// <para>GroupID = current Group ID</para> /// <para>ItemID = current row ID</para> /// </summary> public string Output(string jparameters, List <CategoryViewModel> jCategory, int GroupID, int ItemID) { JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer(); CalculationCSharp.Areas.Configuration.Models.ConfigFunctions Config = new CalculationCSharp.Areas.Configuration.Models.ConfigFunctions(); DateFunctions DatesFunctions = new DateFunctions(); ArrayBuildingFunctions ArrayBuilder = new ArrayBuildingFunctions(); DatePart parameters = (DatePart)javaScriptSerializer.Deserialize(jparameters, typeof(DatePart)); string[] Date1parts = null; //Returns Array Date1parts = ArrayBuilder.InputArrayBuilder(parameters.Date1, jCategory, GroupID, ItemID); string Output = null; //Loop through the array to calculate each value in array foreach (string part in Date1parts) { dynamic InputA = Config.VariableReplace(jCategory, part, GroupID, ItemID); DateTime Date1; DateTime.TryParse(InputA, out Date1); int DatePart = DatesFunctions.GetDatePart(parameters.Part, Date1); Output = Output + Convert.ToString(DatePart) + "~"; } Output = Output.Remove(Output.Length - 1); return(Convert.ToString(Output)); }
public String Output(string jparameters, List <CategoryViewModel> jCategory, int GroupID, int ItemID, string MathString, bool PowOpen) { CalculationCSharp.Areas.Configuration.Models.ConfigFunctions Config = new CalculationCSharp.Areas.Configuration.Models.ConfigFunctions(); string formula = null; Maths Maths = new Maths(); Maths parameters = (Maths)javaScriptSerializer.Deserialize(jparameters, typeof(Maths)); dynamic InputA = Config.VariableReplace(jCategory, parameters.Input1, GroupID, ItemID); dynamic InputB = Config.VariableReplace(jCategory, parameters.Input2, GroupID, ItemID); string Bracket1 = Convert.ToString(parameters.Bracket1); string Input1 = Convert.ToString(InputA); string Logic = Convert.ToString(parameters.Logic); string Input2 = Convert.ToString(InputB); string Bracket2 = Convert.ToString(parameters.Bracket2); string Logic2 = Convert.ToString(parameters.Logic2); if (Logic == "Pow") { formula = Logic + '(' + Input1 + ',' + Input2 + ')'; } else { formula = Input1 + Logic + Input2; } string MathString1; if (Logic2 == "Pow") { MathString1 = string.Concat(Logic2, "(", MathString, Bracket1, formula, Bracket2, ","); } else { MathString1 = string.Concat(MathString, Bracket1, formula, Bracket2, Logic2); } if (Logic2 != "Pow" && PowOpen == true) { MathString1 = string.Concat(MathString1, ")"); } return(MathString1); }
/// <summary>Return where function is being built this is the value that should be passed back to the main calculation. /// <para>jparameters = JSON congifurations relating to this function</para> /// <para>jCategory = the whole configuration which is required to do the variable replace</para> /// <para>GroupID = current Group ID</para> /// <para>ItemID = current row ID</para> /// </summary> public string Output(string jparameters, List <CategoryViewModel> jCategory, int GroupID, int ItemID) { JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer(); CalculationCSharp.Areas.Configuration.Models.ConfigFunctions Config = new CalculationCSharp.Areas.Configuration.Models.ConfigFunctions(); ArrayBuildingFunctions ArrayBuilder = new ArrayBuildingFunctions(); Return parameters = (Return)javaScriptSerializer.Deserialize(jparameters, typeof(Return)); string[] Return1parts = null; //Returns Array Return1parts = ArrayBuilder.InputArrayBuilder(parameters.Variable, jCategory, GroupID, ItemID); string Output = null; //Loop through the array to calculate each value in array foreach (string part in Return1parts) { dynamic InputA = Config.VariableReplace(jCategory, part, GroupID, ItemID); Output = Output + Convert.ToString(InputA) + "~"; } Output = Output.Remove(Output.Length - 1); return(Convert.ToString(Output)); }
public String Output(string jparameters, List<CategoryViewModel> jCategory, int GroupID, int ItemID, string MathString, bool PowOpen) { CalculationCSharp.Areas.Configuration.Models.ConfigFunctions Config = new CalculationCSharp.Areas.Configuration.Models.ConfigFunctions(); string formula = null; Maths Maths = new Maths(); Maths parameters = (Maths)javaScriptSerializer.Deserialize(jparameters, typeof(Maths)); dynamic InputA = Config.VariableReplace(jCategory, parameters.Input1, GroupID, ItemID); dynamic InputB = Config.VariableReplace(jCategory, parameters.Input2, GroupID, ItemID); string Bracket1 = Convert.ToString(parameters.Bracket1); string Input1 = Convert.ToString(InputA); string Logic = Convert.ToString(parameters.Logic); string Input2 = Convert.ToString(InputB); string Bracket2 = Convert.ToString(parameters.Bracket2); string Logic2 = Convert.ToString(parameters.Logic2); if (Logic == "Pow") { formula = Logic + '(' + Input1 + ',' + Input2 + ')'; } else { formula = Input1 + Logic + Input2; } string MathString1; if (Logic2 == "Pow") { MathString1 = string.Concat(Logic2, "(", MathString, Bracket1, formula, Bracket2, ","); } else { MathString1 = string.Concat(MathString, Bracket1, formula, Bracket2, Logic2); } if (Logic2 != "Pow" && PowOpen == true) { MathString1 = string.Concat(MathString1, ")"); } return MathString1; }
/// <summary>Outputs where Date Part function is used includes the array builder. /// <para>jparameters = JSON congifurations relating to this function</para> /// <para>jCategory = the whole configuration which is required to do the variable replace</para> /// <para>GroupID = current Group ID</para> /// <para>ItemID = current row ID</para> /// </summary> public string Output(string jparameters, List<CategoryViewModel> jCategory, int GroupID, int ItemID) { JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer(); CalculationCSharp.Areas.Configuration.Models.ConfigFunctions Config = new CalculationCSharp.Areas.Configuration.Models.ConfigFunctions(); DateFunctions DatesFunctions = new DateFunctions(); ArrayBuildingFunctions ArrayBuilder = new ArrayBuildingFunctions(); DatePart parameters = (DatePart)javaScriptSerializer.Deserialize(jparameters, typeof(DatePart)); string[] Date1parts = null; //Returns Array Date1parts = ArrayBuilder.InputArrayBuilder(parameters.Date1, jCategory, GroupID, ItemID); string Output = null; //Loop through the array to calculate each value in array foreach (string part in Date1parts) { dynamic InputA = Config.VariableReplace(jCategory, part, GroupID, ItemID); DateTime Date1; DateTime.TryParse(InputA, out Date1); int DatePart = DatesFunctions.GetDatePart(parameters.Part, Date1); Output = Output + Convert.ToString(DatePart) + "~"; } Output = Output.Remove(Output.Length - 1); return Convert.ToString(Output); }
/// <summary>Outputs where Array Functions function is used, includes the array builder. /// <para>jparameters = JSON congifurations relating to this function</para> /// <para>jCategory = the whole configuration which is required to do the variable replace</para> /// <para>GroupID = current Group ID</para> /// <para>ItemID = current row ID</para> /// </summary> public string Output(string jparameters, List <CategoryViewModel> jCategory, int GroupID, int ItemID) { CalculationCSharp.Areas.Configuration.Models.ConfigFunctions Config = new CalculationCSharp.Areas.Configuration.Models.ConfigFunctions(); JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer(); MathematicalFunctions MathFunctions = new MathematicalFunctions(); ArrayFunctions parameters = (ArrayFunctions)javaScriptSerializer.Deserialize(jparameters, typeof(ArrayFunctions)); dynamic InputA = Config.VariableReplace(jCategory, parameters.LookupValue, GroupID, ItemID); string OutputValue = null; if (parameters.LookupType == "Decimal") { OutputValue = DecimalCalculation(parameters, InputA); } else if (parameters.LookupType == "Date") { OutputValue = DateCalculation(parameters, InputA); } else { OutputValue = Convert.ToString(0); } return(Convert.ToString(OutputValue)); }
public string Output(string jparameters, List <CategoryViewModel> jCategory, int GroupID, int ItemID, dynamic variable, string DataType) { JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer(); CalculationCSharp.Areas.Configuration.Models.ConfigFunctions Config = new CalculationCSharp.Areas.Configuration.Models.ConfigFunctions(); ArrayBuildingFunctions ArrayBuilder = new ArrayBuildingFunctions(); string[] Parts = null; //Returns Array Parts = ArrayBuilder.InputArrayBuilder(variable, jCategory, GroupID, ItemID); string Output = null; //Loop through the array to calculate each value in array foreach (string part in Parts) { dynamic InputA = Config.VariableReplace(jCategory, part, GroupID, ItemID); if (DataType == "Date") { DateTime Date1; DateTime.TryParse(InputA, out Date1); Output = Output + Convert.ToString(Date1.ToShortDateString()) + "~"; } else if (DataType == "Decimal") { Int16 Int1; Int16.TryParse(InputA, out Int1); Output = Output + Convert.ToString(Int1) + "~"; } else { Output = Output + Convert.ToString(InputA) + "~"; } } Output = Output.Remove(Output.Length - 1); return(Convert.ToString(Output)); }
/// <summary>Outputs where Array Functions function is used, includes the array builder. /// <para>jparameters = JSON congifurations relating to this function</para> /// <para>jCategory = the whole configuration which is required to do the variable replace</para> /// <para>GroupID = current Group ID</para> /// <para>ItemID = current row ID</para> /// </summary> public string Output(string jparameters, List<CategoryViewModel> jCategory, int GroupID, int ItemID) { CalculationCSharp.Areas.Configuration.Models.ConfigFunctions Config = new CalculationCSharp.Areas.Configuration.Models.ConfigFunctions(); JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer(); MathematicalFunctions MathFunctions = new MathematicalFunctions(); ArrayFunctions parameters = (ArrayFunctions)javaScriptSerializer.Deserialize(jparameters, typeof(ArrayFunctions)); dynamic InputA = Config.VariableReplace(jCategory, parameters.LookupValue, GroupID, ItemID); string OutputValue = null; if (parameters.LookupType == "Decimal") { OutputValue = DecimalCalculation(parameters, InputA); } else if(parameters.LookupType == "Date") { OutputValue = DateCalculation(parameters, InputA); } else { OutputValue = Convert.ToString(0); } return Convert.ToString(OutputValue); }
/// <summary>Outputs Date Adjustment function is used, includes the array builder. /// <para>jparameters = JSON congifurations relating to this function</para> /// <para>jCategory = the whole configuration which is required to do the variable replace</para> /// <para>GroupID = current Group ID</para> /// <para>ItemID = current row ID</para> /// </summary> public string Output(string jparameters, List<CategoryViewModel> jCategory, int GroupID, int ItemID) { JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer(); CalculationCSharp.Areas.Configuration.Models.ConfigFunctions Config = new CalculationCSharp.Areas.Configuration.Models.ConfigFunctions(); DateFunctions DatesFunctions = new DateFunctions(); ArrayBuildingFunctions ArrayBuilder = new ArrayBuildingFunctions(); Dates parameters = (Dates)javaScriptSerializer.Deserialize(jparameters, typeof(Dates)); if(parameters.Type == "Today") { return DateTime.Now.ToShortDateString(); } string[] Date1parts = null; string[] Date2parts = null; //Returns array Date1parts = ArrayBuilder.InputArrayBuilder(parameters.Date1, jCategory, GroupID, ItemID); Date2parts = ArrayBuilder.InputArrayBuilder(parameters.Date2, jCategory, GroupID, ItemID); string Output = null; int Counter = 0; //Gets Max Length of array so loops through all values int MaxLength = ArrayBuilder.GetMaxLength(Date1parts, Date2parts); //Loop through the array to calculate each value in array for (int i = 0; i < MaxLength; i++) { dynamic InputA = null; dynamic InputB = null; //Gets the current array to use in the loop InputA = ArrayBuilder.GetArrayPart(Date1parts, Counter); InputB = ArrayBuilder.GetArrayPart(Date2parts, Counter); dynamic InputC = Config.VariableReplace(jCategory, parameters.Period, GroupID, ItemID); DateTime Date1; DateTime Date2; Decimal Period; //Data output checker if (InputA != null) { DateTime.TryParse(InputA, out Date1); } else { Date1 = Convert.ToDateTime("01/01/0001"); } if (InputB != null) { DateTime.TryParse(InputB, out Date2); } else { Date2 = Convert.ToDateTime("01/01/0001"); } Decimal.TryParse(InputC, out Period); string date = DatesFunctions.DateAdjustment(parameters.Type, Convert.ToString(Date1), Convert.ToString(Date2), parameters.PeriodType, Period, parameters.Adjustment, parameters.Day, parameters.Month); Output = Output + date + "~"; Counter = Counter + 1; } if(Output != null) { Output = Output.Remove(Output.Length - 1); } return Convert.ToString(Output); }
/// <summary>Outputs Date Adjustment function is used, includes the array builder. /// <para>jparameters = JSON congifurations relating to this function</para> /// <para>jCategory = the whole configuration which is required to do the variable replace</para> /// <para>GroupID = current Group ID</para> /// <para>ItemID = current row ID</para> /// </summary> public string Output(string jparameters, List <CategoryViewModel> jCategory, int GroupID, int ItemID) { JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer(); CalculationCSharp.Areas.Configuration.Models.ConfigFunctions Config = new CalculationCSharp.Areas.Configuration.Models.ConfigFunctions(); DateFunctions DatesFunctions = new DateFunctions(); ArrayBuildingFunctions ArrayBuilder = new ArrayBuildingFunctions(); Dates parameters = (Dates)javaScriptSerializer.Deserialize(jparameters, typeof(Dates)); if (parameters.Type == "Today") { return(DateTime.Now.ToShortDateString()); } string[] Date1parts = null; string[] Date2parts = null; //Returns array Date1parts = ArrayBuilder.InputArrayBuilder(parameters.Date1, jCategory, GroupID, ItemID); Date2parts = ArrayBuilder.InputArrayBuilder(parameters.Date2, jCategory, GroupID, ItemID); string Output = null; int Counter = 0; //Gets Max Length of array so loops through all values int MaxLength = ArrayBuilder.GetMaxLength(Date1parts, Date2parts); //Loop through the array to calculate each value in array for (int i = 0; i < MaxLength; i++) { dynamic InputA = null; dynamic InputB = null; //Gets the current array to use in the loop InputA = ArrayBuilder.GetArrayPart(Date1parts, Counter); InputB = ArrayBuilder.GetArrayPart(Date2parts, Counter); dynamic InputC = Config.VariableReplace(jCategory, parameters.Period, GroupID, ItemID); DateTime Date1; DateTime Date2; Decimal Period; //Data output checker if (InputA != null) { DateTime.TryParse(InputA, out Date1); } else { Date1 = Convert.ToDateTime("01/01/0001"); } if (InputB != null) { DateTime.TryParse(InputB, out Date2); } else { Date2 = Convert.ToDateTime("01/01/0001"); } Decimal.TryParse(InputC, out Period); string date = DatesFunctions.DateAdjustment(parameters.Type, Convert.ToString(Date1), Convert.ToString(Date2), parameters.PeriodType, Period, parameters.Adjustment, parameters.Day, parameters.Month); Output = Output + date + "~"; Counter = Counter + 1; } if (Output != null) { Output = Output.Remove(Output.Length - 1); } return(Convert.ToString(Output)); }
//Calcuation Controller Action public void CalculateAction(List <CategoryViewModel> jCategory) { foreach (var group in jCategory) { foreach (var item in group.Functions) { if (item.Function == "Input") { item.Output = InputFunctions.Output(item.Type, item.Output); OutputList.Add(new OutputList { ID = Convert.ToString(item.ID), Field = item.Name, Value = item.Output, Group = group.Name }); } else { //Logic check at Column Level string colLogic = null; bool colLogicParse = true; if (group.Logic != null) { foreach (var bit in group.Logic) { var grouplastLogic = group.Logic.Last(); string grouplastLogicOperator = grouplastLogic.Operator; Logic Logic = new Logic(); colLogic = Logic.Output(jCategory, bit, group.ID, 0); Expression ex = new Expression(colLogic); try { colLogicParse = Convert.ToBoolean(ex.Evaluate()); } catch (Exception exception) { logger.Error(exception); throw new HttpException(exception.ToString()); } if (grouplastLogicOperator == "AND" && colLogicParse == false) { break; } else if (grouplastLogicOperator == "OR" && colLogicParse == true) { colLogicParse = true; break; } } } if (item.Parameter.Count > 0) { string logic = null; bool logicparse = true; string MathString = null; bool PowOpen = false; //Logic check at column level if (colLogicParse == true) { foreach (var bit in item.Logic) { var lastLogic = item.Logic.Last(); string lastLogicOperator = lastLogic.Operator; Logic Logic = new Logic(); logic = Logic.Output(jCategory, bit, group.ID, item.ID); Expression ex = new Expression(logic); try { logicparse = Convert.ToBoolean(ex.Evaluate()); } catch (Exception exception) { logger.Error(exception); throw new HttpException(exception.ToString()); } if (lastLogicOperator == "AND" && logicparse == false) { break; } else if (lastLogicOperator == "OR" && logicparse == true) { logicparse = true; break; } } } else { logicparse = false; } //Run code if logic if met at column and row level if (logicparse == true) { int paramCount = 1; foreach (var param in item.Parameter) { string jparameters = Newtonsoft.Json.JsonConvert.SerializeObject(param); logger.Debug("Column Name(" + group.ID + ") - " + group.Name + " || Row Name(" + item.ID + ") - " + item.Name); if (item.Function == "Maths") { Maths Maths = new Maths(); Maths parameters = (Maths)javaScriptSerializer.Deserialize(jparameters, typeof(Maths)); MathString = Maths.Output(jparameters, jCategory, group.ID, item.ID, MathString, PowOpen); PowOpen = Maths.PowOpen(jparameters, PowOpen); if (paramCount == item.Parameter.Count) { Expression e = new Expression(MathString); var Calculation = e.Evaluate(); bool DeciParse; decimal CalculationDeci; string Rounding; DeciParse = decimal.TryParse(Convert.ToString(Calculation), out CalculationDeci); Rounding = Convert.ToString(parameters.Rounding); if (Rounding == null || Rounding == "") { Rounding = "2"; } if (DeciParse == true) { decimal Output = CalculationDeci; MathematicalFunctions MathematicalFunctions = new MathematicalFunctions(); try { Output = MathematicalFunctions.Rounding(Convert.ToString(parameters.RoundingType), Rounding, Output); } catch (Exception ex) { logger.Error(ex); throw new HttpException(ex.ToString()); } item.Output = Convert.ToString(Output); } else { item.Output = "0"; } } paramCount = paramCount + 1; } else if (item.Function == "ErrorsWarnings") { ErrorsWarnings Errors = new ErrorsWarnings(); ErrorsWarnings parameters = (ErrorsWarnings)javaScriptSerializer.Deserialize(jparameters, typeof(ErrorsWarnings)); item.Name = parameters.Type; item.Output = parameters.String1; } else if (item.Function == "Comments") { Comments Errors = new Comments(); Comments parameters = (Comments)javaScriptSerializer.Deserialize(jparameters, typeof(Comments)); item.Output = parameters.String1; } else if (item.Function == "Period") { DateFunctions DateFunctions = new DateFunctions(); Period Periods = new Period(); try { item.Output = Periods.Output(jparameters, jCategory, group.ID, item.ID); } catch (Exception ex) { logger.Error(ex); throw new HttpException(ex.ToString()); } } else if (item.Function == "Factors") { Factors Factors = new Factors(); Factors parameters = (Factors)javaScriptSerializer.Deserialize(jparameters, typeof(Factors)); try { item.Output = Factors.Output(jparameters, jCategory, group.ID, item.ID); } catch (Exception ex) { logger.Error(ex); throw new HttpException(ex.ToString()); } item.Type = parameters.OutputType; } else if (item.Function == "DateAdjustment") { Dates Dates = new Dates(); try { item.Output = Dates.Output(jparameters, jCategory, group.ID, item.ID); } catch (Exception ex) { logger.Error(ex); throw new HttpException(ex.ToString()); } } else if (item.Function == "DatePart") { DatePart DateParts = new DatePart(); try { item.Output = DateParts.Output(jparameters, jCategory, group.ID, item.ID); } catch (Exception ex) { logger.Error(ex); throw new HttpException(ex.ToString()); } } else if (item.Function == "Return") { Return Return = new Return(); try { item.Output = Return.Output(jparameters, jCategory, group.ID, item.ID); OutputList.Add(new OutputList { ID = Convert.ToString(item.ID), Field = item.Name, Value = item.Output, Group = group.Name }); return; } catch (Exception ex) { logger.Error(ex); throw new HttpException(ex.ToString()); } } else if (item.Function == "MathsFunctions") { MathsFunctions MathsFunctions = new MathsFunctions(); try { item.Output = MathsFunctions.Output(jparameters, jCategory, group.ID, item.ID, group); } catch (Exception ex) { logger.Error(ex); throw new HttpException(ex.ToString()); } } else if (item.Function == "ArrayFunctions") { ArrayFunctions ArrayFunctions = new ArrayFunctions(); ArrayFunctions parameters = (ArrayFunctions)javaScriptSerializer.Deserialize(jparameters, typeof(ArrayFunctions)); try { item.Output = ArrayFunctions.Output(jparameters, jCategory, group.ID, item.ID); } catch (Exception ex) { logger.Error(ex); throw new HttpException(ex.ToString()); } if (parameters.Function == "Count") { item.Type = "Decimal"; } else { item.Type = parameters.LookupType; } } else if (item.Function == "StringFunctions") { StringFunctions StringFunctions = new StringFunctions(); StringFunctions parameters = (StringFunctions)javaScriptSerializer.Deserialize(jparameters, typeof(StringFunctions)); try { item.Output = StringFunctions.Output(jparameters, jCategory, group.ID, item.ID); } catch (Exception ex) { logger.Error(ex); throw new HttpException(ex.ToString()); } if (parameters.Type == "Len") { item.Type = "Decimal"; } else { item.Type = "String"; } } else if (item.Function == "Function") { Function Functions = new Function(); Function parameters = (Function)javaScriptSerializer.Deserialize(jparameters, typeof(Function)); FunctionConfiguration calcFunction = db.FunctionConfiguration.Find(Convert.ToInt32(parameters.ID)); List <CategoryViewModel> calcFunctionConfig = (List <CategoryViewModel>)javaScriptSerializer.Deserialize(calcFunction.Configuration, typeof(List <CategoryViewModel>)); //replace inputs from main configuration to function foreach (var row in calcFunctionConfig[0].Functions) { int index = parameters.Input.FindIndex(a => a.Name == row.Name); if (index >= 0) { row.Output = parameters.Input[index].Output; } else { row.Output = null; } } foreach (var input in calcFunctionConfig[0].Functions) { if (input.Output != null) { input.Output = Convert.ToString(Functions.Output(jparameters, jCategory, group.ID, item.ID, input.Output, input.Type)); } } //run the function with the new inputs Calculate Calculate = new Calculate(); calcFunctionConfig = Calculate.DebugResults(calcFunctionConfig); item.SubOutput = Calculate.OutputResults(calcFunctionConfig); foreach (var col in calcFunctionConfig) { int index = col.Functions.FindIndex(a => a.Function == "Return"); if (index >= 0) { item.Output = col.Functions[index].Output; foreach (var thing in col.Functions[index].Parameter) { foreach (var test in thing) { if (test.Key == "Datatype") { item.Type = test.Value; } } } } } } } //Expected results on the builder this sets the required ones if (item.ExpectedResult == null || item.ExpectedResult == "") { item.Pass = "******"; } else if (item.ExpectedResult == item.Output) { item.Pass = "******"; } else { item.Pass = "******"; } OutputList.Add(new OutputList { ID = Convert.ToString(item.ID), Field = item.Name, Value = item.Output, Group = group.Name, SubOutput = item.SubOutput }); } else { //Ignores the row if logic is not met dynamic LogicReplace = Config.VariableReplace(jCategory, item.Name, group.ID, item.ID); if (Convert.ToString(LogicReplace) == Convert.ToString(item.Name)) { item.Output = null; } else { item.Output = Convert.ToString(LogicReplace); } item.Pass = "******"; OutputList.Add(new OutputList { ID = Convert.ToString(item.ID), Field = item.Name, Value = item.Output, Group = group.Name, SubOutput = item.SubOutput }); } } } } } }
/// <summary>Outputs where Logic is set on the row . /// <para>jCategory = the whole configuration which is required to do the variable replace</para> /// <para>bit = the logic to set</para> /// <para>GroupID = current Group ID</para> /// <para>ItemID = current row ID</para> /// </summary> public string Output(List<CategoryViewModel> jCategory, Logic bit, int GroupID, int ItemID) { JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer(); CalculationCSharp.Areas.Configuration.Models.ConfigFunctions Config = new CalculationCSharp.Areas.Configuration.Models.ConfigFunctions(); dynamic InputA = Config.VariableReplace(jCategory, bit.Input1, GroupID, ItemID); dynamic InputB = Config.VariableReplace(jCategory, bit.Input2, GroupID, ItemID); string Logic = null; //Sets the Logic indicator if (bit.LogicInd == "NotEqual") { Logic = "<>"; } else if (bit.LogicInd == "Greater") { Logic = ">"; } else if (bit.LogicInd == "GreaterEqual") { Logic = ">="; } else if (bit.LogicInd == "Less") { Logic = "<"; } else if (bit.LogicInd == "LessEqual") { Logic = "<="; } else { Logic = bit.LogicInd; } //Parses Decimals bool InputADeciSucceeded; bool InputBDeciSucceeded; decimal InputADeci; decimal InputBDeci; InputADeciSucceeded = decimal.TryParse(InputA, out InputADeci); InputBDeciSucceeded = decimal.TryParse(InputB, out InputBDeci); //Parses Dates bool InputADateSucceeded; bool InputBDateSucceeded; DateTime InputADate; DateTime InputBDate; InputADateSucceeded = DateTime.TryParse(InputA, out InputADate); InputBDateSucceeded = DateTime.TryParse(InputB, out InputBDate); //Builds the string to calculate the logis if (InputADeciSucceeded == true && InputBDeciSucceeded == true) { return "if(" + InputADeci + Logic + InputBDeci + ",true,false)"; } else if (InputADeciSucceeded == true && InputBDeciSucceeded == false) { return "if(" + InputADeci + Logic + "'" + InputBDeci + "'" + ",true,false)"; } else if (InputADeciSucceeded == false && InputBDeciSucceeded == true) { return "if(" + "'" + InputADeci + "'" + Logic + InputBDeci + ",true,false)"; } else if (InputADateSucceeded == true && InputBDateSucceeded == true) { return "if(" + "'" + InputADate + "'" + Logic + "'" + InputBDate + "'" + ",true,false)"; } else if (InputADateSucceeded == true && InputBDateSucceeded == false) { return "if(" + InputADate + Logic + "'" + InputBDate + "'" + ",true,false)"; } else if (InputADateSucceeded == false && InputBDateSucceeded == true) { return "if(" + "'" + InputADate + "'" + Logic + InputBDate + ",true,false)"; } else { string inputA = Convert.ToString(InputA); string inputB = Convert.ToString(InputB); return "if(" + "'" + inputA + "'" + Logic + "'" + inputB + "'" + ",true,false)"; } }
/// <summary>Outputs where Logic is set on the row . /// <para>jCategory = the whole configuration which is required to do the variable replace</para> /// <para>bit = the logic to set</para> /// <para>GroupID = current Group ID</para> /// <para>ItemID = current row ID</para> /// </summary> public string Output(List <CategoryViewModel> jCategory, Logic bit, int GroupID, int ItemID) { JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer(); CalculationCSharp.Areas.Configuration.Models.ConfigFunctions Config = new CalculationCSharp.Areas.Configuration.Models.ConfigFunctions(); dynamic InputA = Config.VariableReplace(jCategory, bit.Input1, GroupID, ItemID); dynamic InputB = Config.VariableReplace(jCategory, bit.Input2, GroupID, ItemID); string Logic = null; //Sets the Logic indicator if (bit.LogicInd == "NotEqual") { Logic = "<>"; } else if (bit.LogicInd == "Greater") { Logic = ">"; } else if (bit.LogicInd == "GreaterEqual") { Logic = ">="; } else if (bit.LogicInd == "Less") { Logic = "<"; } else if (bit.LogicInd == "LessEqual") { Logic = "<="; } else { Logic = bit.LogicInd; } //Parses Decimals bool InputADeciSucceeded; bool InputBDeciSucceeded; decimal InputADeci; decimal InputBDeci; InputADeciSucceeded = decimal.TryParse(InputA, out InputADeci); InputBDeciSucceeded = decimal.TryParse(InputB, out InputBDeci); //Parses Dates bool InputADateSucceeded; bool InputBDateSucceeded; DateTime InputADate; DateTime InputBDate; InputADateSucceeded = DateTime.TryParse(InputA, out InputADate); InputBDateSucceeded = DateTime.TryParse(InputB, out InputBDate); //Builds the string to calculate the logis if (InputADeciSucceeded == true && InputBDeciSucceeded == true) { return("if(" + InputADeci + Logic + InputBDeci + ",true,false)"); } else if (InputADeciSucceeded == true && InputBDeciSucceeded == false) { return("if(" + InputADeci + Logic + "'" + InputBDeci + "'" + ",true,false)"); } else if (InputADeciSucceeded == false && InputBDeciSucceeded == true) { return("if(" + "'" + InputADeci + "'" + Logic + InputBDeci + ",true,false)"); } else if (InputADateSucceeded == true && InputBDateSucceeded == true) { return("if(" + "'" + InputADate + "'" + Logic + "'" + InputBDate + "'" + ",true,false)"); } else if (InputADateSucceeded == true && InputBDateSucceeded == false) { return("if(" + InputADate + Logic + "'" + InputBDate + "'" + ",true,false)"); } else if (InputADateSucceeded == false && InputBDateSucceeded == true) { return("if(" + "'" + InputADate + "'" + Logic + InputBDate + ",true,false)"); } else { string inputA = Convert.ToString(InputA); string inputB = Convert.ToString(InputB); return("if(" + "'" + inputA + "'" + Logic + "'" + inputB + "'" + ",true,false)"); } }