public void CanDetermineTableLookupValueFromQuestion() { var controller = new YamlScriptController(); var result = controller.Parse(YamlTestFileLoader.Load(@"TableTests.yaml")); Assert.False(result.IsError); var parameters = new ParametersCollection() as IParametersCollection; controller.QuestionCallback = (FormulaExpressionContext sender, QuestionArgs args) => { Assert.True(args.Parameters[0].Name == "woonland"); Assert.True(args.Parameters[0].Type == TypeInference.InferenceResult.TypeEnum.List); // This list can be used to do a selection of a valid woonland Assert.True(((List <object>)args.Parameters[0].Value).Count > 0); // Provide an anwser by selecting an item: Finland from the list parameters.Add(new ClientParameter(args.Parameters[0].Name, ((List <object>)args.Parameters[0].Value)[1], TypeInference.InferenceResult.TypeEnum.List, "Dummy")); }; var executionResult = new ExecutionResult(ref parameters) as IExecutionResult; try { var workflow = controller.ExecuteWorkflow(ref parameters, ref executionResult); } catch (UnresolvedException) { // The server lookup needs to be evaluated again to get the resulting woonlandfactor. // In this case the client will not need to have to answer another question. // Maybe this can be put in core, in order to make the client logic simpler. var evaluateAgain = controller.ExecuteWorkflow(ref parameters, ref executionResult); } Assert.True(parameters[0].Name == "woonland"); Assert.True((string)parameters[0].Value == "Finland"); Assert.True(parameters[1].Name == "woonlandfactor"); Assert.True((double)parameters[1].Value == 0.7161); Assert.True(parameters[2].Name == "recht"); Assert.True((bool)parameters[2].Value == true); // Quick Hack to see if recht is false by selecting woonland: Anders parameters.Clear(); parameters.Add(new ClientParameter("woonland", "Anders", TypeInference.InferenceResult.TypeEnum.List, "Dummy")); var recalculate = controller.ExecuteWorkflow(ref parameters, ref executionResult); Assert.True(parameters[0].Name == "woonland"); Assert.True((string)parameters[0].Value == "Anders"); Assert.True(parameters[1].Name == "woonlandfactor"); Assert.True((double)parameters[1].Value == 0); Assert.True(parameters[2].Name == "recht"); Assert.True((bool)parameters[2].Value == false); Assert.NotNull(recalculate.Stacktrace.FindLast(p => p.IsStopExecution == true)); }
public override bool RecalcPrice(int parCodeReceipt = 0) { ParametersCollection varParameters = new ParametersCollection();; varParameters.Add("parIdWorkplace", GlobalVar.varIdWorkPlace, DbType.Int32); varParameters.Add("parCodePeriod", Global.GetCodePeriod(), DbType.Int32); varParameters.Add("parDefaultCodeDealer", GlobalVar.varDefaultCodeDealer[0], DbType.Int32); varParameters.Add("parCodeReceipt", parCodeReceipt, DbType.Int32); DataTable varDT = this.db.Execute(this.varSqlListPS, varParameters); for (int i = 0; i < varDT.Rows.Count; i++) { //wr.code_wares, wr.code_unit, w.vat, w.vat_operation, ps.code_ps, ps.priority, psd.type_discount, psd.data, pd.price_dealer, pdd.price_dealer default_price_dealer, int varCodeWares = Convert.ToInt32(varDT.Rows[i]["code_wares"]); int varCodeUnit = Convert.ToInt32(varDT.Rows[i]["code_unit"]); int varCodePS = Convert.ToInt32(varDT.Rows[i]["code_ps"]); varParameters.Clear(); varParameters.Add("parIdWorkplace", GlobalVar.varIdWorkPlace, DbType.Int32); varParameters.Add("parCodePeriod", Global.GetCodePeriod(), DbType.Int32); varParameters.Add("parCodeReceipt", parCodeReceipt, DbType.Int32); varParameters.Add("parCodeWares", varCodeWares, DbType.Int32); varParameters.Add("parCodeUnit", varCodeUnit, DbType.Int32); varParameters.Add("parCodePS", varCodePS, DbType.Int32); //varParameters.Add("parTypeDiscount",varTypeDiscount,DbType.Int32); varWares.SetWares(varDT.Rows[i]); varParameters.Add("parVatOperation", varWares.varTypeVat, DbType.Int32); varParameters.Add("parSum", (varWares.varPrice * varWares.varQuantity) * (1 + varWares.varPercentVat) * varWares.varCoefficient, DbType.Decimal); varParameters.Add("parSumVat", varWares.varPrice * varWares.varQuantity * varWares.varPercentVat * varWares.varCoefficient, DbType.Decimal); this.db.ExecuteNonQuery(this.varSqlUpdatePrice, varParameters); RecalcHeadReceipt(varParameters); } return(true); }