简体   繁体   中英

How to simplify my C# Code

I'm developing Windows Form Application using DevExpress. I need Simplfy my C# Code Below is the code I use:

 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, "", "", "");

                }

Based on your error message, it seems that your dateEdit_periodfrom variable is of the DateEdit type (not SearchLookupEdit ). DateEdit doesn't provide the DataSource property. Make sure you are using a correct variable to accomplish your task.

you must always put the success message box after the process finishes to make sure no exception will be triggered after the success message is shown. And to make it more readable, I added another line of codes

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);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM