出现错误后不应显示表格 [英] Form should not be shown after raising an error
本文介绍了出现错误后不应显示表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,我已经写了以下代码
Hi all i have written the following code
private void btnEntry_Click(object sender, EventArgs e)
{
if (cmbServiceClassCode.SelectedIndex == -1 || txtCompname.Text == string.Empty || txtCompidentification.Text == string.Empty
|| cmbStandardentryclasscode.SelectedIndex == -1 || txtOrgstatuscode.Text == string.Empty || txtODFIidentification.Text == string.Empty
|| txtBatchno.Text == string.Empty)
{
MessageBox.Show("Insufficient Data to Proceed");
if (Convert.ToBoolean(DialogResult.OK))
{
this.Show();
}
}
string s = cmbStandardentryclasscode.SelectedItem.ToString();
try
{
if (s == "CCD")
{
frmEntryDetails frmentry = new frmEntryDetails(s);
frmentry.ShowDialog(this);
}
else
{
frmEntryDetails frmentry = new frmEntryDetails(s);
frmentry.ShowDialog(this);
}
}
catch (Exception ex)
{
}
}
但是,如果我选择某个值 cmbStandardentryclasscode ,则会显示错误消息,但会执行其余代码.
But if i select some value cmbStandardentryclasscode the error message is displayed but executing the remaining code. So can any one please help me.
推荐答案
然后,您是否不想要以下结构(即添加其他);
Do you not want the following structure then (i.e.add an else);
private void btnEntry_Click(object sender, EventArgs e)
{
if ( //the condition checks)
{
MessageBox.Show("Insufficient Data to Proceed");
if (Convert.ToBoolean(DialogResult.OK))
{
this.Show();
}
}
else
{
string s = cmbStandardentryclasscode.SelectedItem.ToString();
try
{
//code as per existing try
}
catch (Exception ex)
{
}
}
}
好,我得到了答案
编辑代码如下
Ok i got the answer
Edited the code as follows
private void btnEntry_Click(object sender, EventArgs e)
{
if (cmbServiceClassCode.SelectedIndex == -1 || txtCompname.Text == string.Empty || txtCompidentification.Text == string.Empty
|| cmbStandardentryclasscode.SelectedIndex == -1 || txtOrgstatuscode.Text == string.Empty || txtODFIidentification.Text == string.Empty
|| txtBatchno.Text == string.Empty)
{
MessageBox.Show("Insufficient Data to Proceed");
}
try
{
string s = cmbStandardentryclasscode.SelectedItem.ToString();
if (s != null && cmbServiceClassCode.SelectedIndex == -1 || txtCompname.Text == string.Empty
|| txtCompidentification.Text == string.Empty || txtOrgstatuscode.Text == string.Empty || txtODFIidentification.Text == string.Empty)
{
this.Show();
}
else
{
if (s == "CCD")
{
frmEntryDetails frmentry = new frmEntryDetails(s);
frmentry.ShowDialog(this);
}
else
{
frmEntryDetails frmentry = new frmEntryDetails(s);
frmentry.ShowDialog(this);
}
}
}
catch (Exception ex)
{
}
}
这篇关于出现错误后不应显示表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文