简体   繁体   English

如何简化我的C#代码

[英]How to simplify my C# Code

I'm developing Windows Form Application using DevExpress. 我正在使用DevExpress开发Windows窗体应用程序。 I need Simplfy my C# Code Below is the code I use: 我需要简化我的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, "", "", "");

                }

Based on your error message, it seems that your dateEdit_periodfrom variable is of the DateEdit type (not SearchLookupEdit ). 根据您的错误信息,看来你dateEdit_periodfrom变量是DateEdit型(不SearchLookupEdit)的。 DateEdit doesn't provide the DataSource property. DateEdit不提供DataSource属性。 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);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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