如果语句/校验值?

| 我已经用谷歌浏览了一下,我知道这里的代码不是很容易接受,但是我非常感谢您的帮助: 必须选中此复选框,然后检查选项按钮的值(布尔值)。 根据该值显示不同的消息,如果True,则在邮件中包括多余的一行,但这是另一个问题。 任何帮助将不胜感激。我真的需要摆脱这个C#的困扰。
public void field42_Changed(object sender, XmlEventArgs e)
{
    // checking Gsm checkbox(IOgsm@parzs.be)
    if (e.NewValue.Equals(\"true\"))
    {
        XPathNavigator xnMyForm = this.CreateNavigator();
        XmlNamespaceManager ns = this.NamespaceManager;
        xnMyForm.SelectSingleNode(\"/my:myFields/my:txtGSM\", ns).SetValue(\"P.Bab@gmail.Com\");
        //string MobielInternet = xnMyForm.SelectSingleNode(\"/my:myFields/my:GsmMobileInternet\", ns).Value;
        if MobielInternet e.NewValue.Equals(\"true\")
            MessageBox.Show(\"An e-mail for GSM with Mobile internet will be sent\");
        if (e.NewValue.Equals(\"false\"))
            MessageBox.Show(\"An email for the GSM will be sent\");
        if (e.NewValue.Equals(\"\"))
            MessageBox.Show (\" The Mobile Internet option has to been filled out \");
    }
    else if (e.NewValue.Equals(\"false\"))
    {
        XPathNavigator xnMyForm = this.CreateNavigator();
        XmlNamespaceManager ns = this.NamespaceManager;
        xnMyForm.SelectSingleNode(\"/my:myFields/my:txtGSM\", ns).SetValue(\"\");
    }
}
    
已邀请:
这是我对更干净代码的建议。我希望我不会错过这里要讲的内容,但是您实际上并没有在比较mobielinternet值,而是在再次比较EventArgs值。 尝试这个。
XPathNavigator xnMyForm = this.CreateNavigator();
XmlNamespaceManager ns = this.NamespaceManager;
var emailAddress = \"\";
var message = \"\";

if (e.NewValue.Equals(\"true\"))
{
    emailAddress = \"P.Bab@gmail.Com\";
    string MobielInternet = xnMyForm.SelectSingleNode(\"/my:myFields/my:GsmMobileInternet\", ns).Value;

    if (string.IsNullorEmpty(MobielInternet))
        message = \"The Mobile Internet option has to been filled out\";

    if (bool.Parse(MobielInternet))
        message = \"An e-mail for GSM with Mobile internet will be sent\";
    else
        message = \"An email for the GSM will be sent\";

    MessageBox.Show(message);
}
else if (e.NewValue.Equals(\"false\"))
{
    XPathNavigator xnMyForm = this.CreateNavigator();
    XmlNamespaceManager ns = this.NamespaceManager;
    xnMyForm.SelectSingleNode(\"/my:myFields/my:txtGSM\", ns).SetValue(\"\");
}


xnMyForm.SelectSingleNode(\"/my:myFields/my:txtGSM\", ns).SetValue(emailAddress);
    

要回复问题请先登录注册