处理规则引擎C#中的MAX,NULL值 [英] Handle MAX, NULL values in rule engine C#

查看:79
本文介绍了处理规则引擎C#中的MAX,NULL值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在规则引擎中处理MAX,NULL值。

假设我的第一个xml元素值为null及其整数,我如何将xml元素与非null值进行比较?



我尝试了什么:



i尝试转换,但没有回复

解决方案

< blockquote>你可以这样做:

 public void ExecuteTaxRules()
{
XmlDocument rules = new XmlDocument();

string directory = AppDomain.CurrentDomain.BaseDirectory + @\ TaxCalculator.xml;

rules.Load(directory);
XmlDocument model = new XmlDocument();

model.LoadXml(@< Employee>< GrossSalary> 900001< / GrossSalary>
< HRA> 50000< / HRA>< Tax>< / Tax>< ; NetSalary>
< / NetSalary>< / Employee>);

ROM rom = Compiler.Compile(rules);
rom.AddModel(员工,型号);

int max = 900000;
string grossSalary = model [Employee] [GrossSalary]。InnerText;

int grossInt;
int.TryParse(grossSalary,out grossInt);

if(string.IsNullOrEmpty(grossSalary))
{
Console.WriteLine(Error:GrossSalary为null或为空!);
}
else if(grossInt> max)
{
Console.WriteLine(错误:超出GrossSalary!);
}
其他
{
rom.Evaluate();
var tax = model [Employee] [Tax]。InnerText;
var NetSalary = model [Employee] [NetSalary]。InnerText;
var message = string.Format(Tax:{0}和Net take home salary:{1},tax,NetSalary);
Console.Write(message);
}

Console.Read();
}


How to handle MAX, NULL values in rule engine.
Suppose if my First xml element value is null and its integer, how can i compare the xml element with a non null value?

What I have tried:

i tried converting which gave me no response

解决方案

You could do it like this:

public void ExecuteTaxRules()
{
    XmlDocument rules = new XmlDocument();

    string directory = AppDomain.CurrentDomain.BaseDirectory + @"\TaxCalculator.xml";

    rules.Load(directory);
    XmlDocument model = new XmlDocument();

    model.LoadXml(@"<Employee><GrossSalary>900001</GrossSalary>
    <HRA>50000</HRA><Tax></Tax><NetSalary>
    </NetSalary></Employee>");

    ROM rom = Compiler.Compile(rules);
    rom.AddModel("Employee", model);

    int max = 900000;
    string grossSalary = model["Employee"]["GrossSalary"].InnerText;

    int grossInt;
    int.TryParse(grossSalary, out grossInt);

    if (string.IsNullOrEmpty(grossSalary))
    {
        Console.WriteLine("Error: GrossSalary is null or empty !");
    }
    else if (grossInt > max)
    {
        Console.WriteLine("Error: GrossSalary maximum exceeded !");
    }
    else
    {
        rom.Evaluate();
        var tax = model["Employee"]["Tax"].InnerText;
        var NetSalary = model["Employee"]["NetSalary"].InnerText;
        var message = string.Format("Tax: {0} and Net take home salary :{1}", tax, NetSalary);
        Console.Write(message);
    }

    Console.Read();
}


这篇关于处理规则引擎C#中的MAX,NULL值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆