如何解决如果语句/校验值?
| 我已经用谷歌浏览了一下,我知道这里的代码不是很容易接受,但是我非常感谢您的帮助: 必须选中此复选框,然后检查选项按钮的值(布尔值)。 根据该值显示不同的消息,如果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);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。