private void replaceInDynamicFormula(DynamicFormula dynamicFormula) { if (dynamicFormula == null) { return; } dynamicFormula.Criteria.Each(ReplaceIn); }
private double computeData(string GCN, string Currency) { string sqlStmnt = clsDBValues.getFormula + "GCNNo = '" + GCN + "' and Curr ='" + Currency + "'"; string expression = _TravData.getDataTrav(sqlStmnt, "Formula").Tables["Formula"].Rows[0]["formula"].ToString(); //"cost * item / 100" (IT MUST BE SEPARATED WITH SPACES!) string variable1 = "airfare="; //"item=10" string variable2 = "OtherFee="; //"cost=2.5" string variable3 = "BCDFee="; double rslt; if (tabDataInput.SelectedTab.Text == "GDS") { variable1 = variable1 + txtAirFare.Text; //"item=10" variable2 = variable2 + txtOtherFee.Text; //"cost=2.5" variable3 = variable3 + txtBCDFee.Text; } else { variable1 = variable1 + txtAirFareMan.Text; //"item=10" variable2 = variable2 + txtOtherFeeMan.Text; //"cost=2.5" variable3 = variable3 + txtBCDFeeMan.Text; } //if (variable1 == "") // variable1 = "airfare=0.00"; //if (variable2 == "") // variable2 = "OtherFee=0.00"; //if (variable3 == "") // variable3 = "BCDFee=0.00"; DynamicFormula math = new DynamicFormula(); math.Expression = expression; //Let's define the expression math.AddVariable(variable1); math.AddVariable(variable2); math.AddVariable(variable3); try { rslt = math.CalculateResult(); //In this scenario the result is 0,25... cost * item / 100 = (2.5 * 10 / 100) = 0,25 //Console.WriteLine("Success: " + result); } catch (Exception ex) { rslt = 0; } return(Math.Round(rslt, 2)); }
private void replaceInDynamicFormula(DynamicFormula dynamicFormula) { dynamicFormula?.Criteria.Each(ReplaceIn); }