如何简化我的C#代码

如何简化我的C#代码,c#,winforms,devexpress,C#,Winforms,Devexpress,我正在使用DevExpress开发Windows窗体应用程序。我需要简化我的C代码 下面是我使用的代码: if (srch_lookup_chequebookno.Text == "Auto") { MessageBox.Show("ChequeBook No : "+chequebookno+ " Saved Successfully.", MessageBoxButtons.OK, MessageBoxIcon.Inf

我正在使用DevExpress开发Windows窗体应用程序。我需要简化我的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, "", "", "");

                }

根据错误消息,您的dateEdit\u periodfrom变量似乎属于dateEdit类型(而不是SearchLookupEditDateEdit不提供数据源属性。确保使用正确的变量来完成任务

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

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

我使用了您的代码,但出现了类似错误1的错误。无法将“System.Windows.Forms.MessageBoxButtons”转换为“string”和“2”。与“System.Windows.Forms.MessageBox.Show(string,string,System.Windows.Forms.MessageBoxButtons)”匹配的最佳重载方法有一些无效参数Hanks NoobProgger我找到了解决方案