【发布时间】:2012-03-05 16:14:56
【问题描述】:
当我正确输入帐号和提款金额时,我不断收到“输入整数”消息框。
假设我输入“12”作为帐号,“50”(或“50.0”)作为金额 - 我收到“输入整数”异常消息框。
如果我什么都不输入,我会得到正确的“输入帐号”。
如果我只输入帐号(无论帐号是否存在)但将金额留空 - 按提款按钮我什么也得不到。
如果我输入帐号和金额(错误或正确,没关系),我会收到“输入和整数”异常消息框。
我哪里做错了?
private void btnWithdraw_Click(object sender, EventArgs e)
{
if (!txtSearch.Text.Equals(""))
{
if(!txtAmount.Text.Equals(""))
{
try
{
int aN = int.Parse(txtSearch.Text);
double am = double.Parse(txtAmount.Text);
client.Withdraw(aN, am);
MessageBox.Show(String.Format("Withdrawn {0} from {1}\nBalance now: {2}", am, aN));
//if(client.Fi)
// MessageBox.Show(String.Format("Customer {0} couldn't be found", aN));
//else
// MessageBox.Show(String.Format("Customer {0}\nBalance: {1}C", aN, client.CustomerBalance(aN).ToString()));
}
catch (FormatException)
{
MessageBox.Show("Enter an integer");
}
catch (NullReferenceException)
{
MessageBox.Show("Customer cannot be found");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
else
{
MessageBox.Show("Enter account number");
}
}
【问题讨论】:
标签: c# winforms wcf exception-handling