如何简化我的C#代码

时间:2017-10-03 07:29:40

标签: c# winforms devexpress

我正在使用DevExpress开发Windows Form Application。我需要Simplfy我的C#代码 以下是我使用的代码:

 if (srch_lookup_chequebookno.Text == "Auto")
                {
                    MessageBox.Show("ChequeBook No : "+chequebookno+ " Saved Successfully.", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    dtgridview = iCubeERP.Accounts.FinanceTransactions.BOChequeBook.getchequedetails("GridValue", chequebookno, "", "", "");

                }
                else
                {
                    MessageBox.Show("ChequeBook No : " + srch_lookup_chequebookno.Text + " Updated Successfully.",  MessageBoxButtons.OK, MessageBoxIcon.Information);
                    dtgridview = iCubeERP.Accounts.FinanceTransactions.BOChequeBook.getchequedetails("GridValue", srch_lookup_chequebookno.Text, "", "", "");

                }

2 个答案:

答案 0 :(得分:1)

根据您的错误消息,您的 dateEdit_periodfrom 变量似乎属于 DateEdit 类型(不是 SearchLookupEdit )。 DateEdit 不提供 DataSource 属性。确保使用正确的变量来完成任务。

答案 1 :(得分:0)

在进程完成后,您必须始终放置成功消息框,以确保在显示成功消息后不会触发任何异常。为了使其更具可读性,我添加了另一行代码

if (srch_lookup_chequebookno.Text == "Auto")
{

    dtgridview = iCubeERP.Accounts.FinanceTransactions.BOChequeBook.getchequedetails("GridValue", chequebookno, "", "", "");
    string msg = string.Format("ChequeBook No: {0} Saved Successfully", chequebookno);
    MessageBox.Show(msg, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{

    dtgridview = iCubeERP.Accounts.FinanceTransactions.BOChequeBook.getchequedetails("GridValue", srch_lookup_chequebookno.Text, "", "", "");
    string msg = string.Format("ChequeBook No: {0} Updated Successfully", srch_lookup_chequebookno);
    MessageBox.Show(msg, MessageBoxButtons.OK, MessageBoxIcon.Information);
}