Devexpress MessageBox自动关闭

时间:2013-01-16 07:27:41

标签: devexpress progress-bar messagebox

我有一个Devexpress表单,它有Progress bar和MessageBox。 当我单击表单上的搜索按钮时,进度条显示百分比,然后网格将与记录绑定。 当它没有返回任何记录时,会在进度条之后显示消息框,例如"没有找到记录"

但在显示未找到任何记录后,它会自动关闭而不会单击消息框上的“确定”或“取消”按钮

进度条代码

namespace DMS
{
public partial class ProgressBar : WaitForm
{
    public ProgressBar()
    {
        InitializeComponent();
    }

    #region Overrides
    public override void SetCaption(string caption)
    {
        base.SetCaption(caption);
        this.progressPanel1.Caption = caption;
    }
    public override void SetDescription(string description)
    {
        base.SetDescription(description);
        this.progressPanel1.Description = description;
    }
    public override void ProcessCommand(Enum cmd, object arg)
    {
        base.ProcessCommand(cmd, arg);
    }
    #endregion

    private void progressBarControl1_EditValueChanged(object sender, EventArgs e)
    {
        try
        {
            int i = int.Parse(Math.Floor(double.Parse(this.progressBarControl1.EditValue.ToString())).ToString());                
            if (i.ToString().EndsWith("0"))
            {
                //satya
                //i += 5;
                i += 0;
            }
            this.Opacity = 100;
            SetCaption("Please Wait...");
            SetDescription(i.ToString() + "% Completed...");
            Application.DoEvents();
        }
        catch (Exception ex)
        {
            XtraMessageBox.Show(ex.Message.ToString() + " " + ex.Source.ToString());
        }
    }
}

}

显示留言箱的代码

private void btnshow_Click(object sender, EventArgs e)
    {
        try
        {
            if (dtstartdate.DateTime.Date > dtEnddate.DateTime.Date)
            {
                XtraMessageBox.Show("Start date should be less than End date", Program.MessageBoxTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                dtstartdate.Focus();
                return;
            }
            string CommandText = "select * from DMS_View_Payments where v_Paymentdate between '" + General.DateToDatabase(this.dtstartdate.DateTime.ToShortDateString())
                + "' and '" + General.DateToDatabase(this.dtEnddate.DateTime.ToShortDateString()) + "'";
            if (ccbeForClient.EditValue.ToString() != string.Empty)
            {
                CommandText += " and v_clientid in (" + this.ccbeForClient.EditValue.ToString() + ")";
            }
            else if (Logs.UserLimitedClients != "0")
            {
                CommandText += " and v_clientid in (" + Logs.UserLimitedClients + ")";
            }
            if (ccbeForBatch.Text.Trim() != "" && ccbeForBatch.Text.Trim() != "--")
            {
                string selected_client_list = "";
                if (ccbeForBatch.Text.Trim() != "" && ccbeForBatch.Text.Trim() != "--")
                {
                    //selected_client_list = ccbe_client_list.Text.Replace(" ", "").Replace(",", "','");
                    string source = ccbeForBatch.Text;
                    string[] split = source.Split(',');
                    string changed = "";
                    for (int i = 0; i < split.Length; i++)
                    {
                        changed += "," + split[i].Trim();
                    }
                    //string output = changed.Trim(',').Replace(",", "','");
                    selected_client_list = changed.Trim(',').Replace(",", "','");
                }
                else
                {
                    selected_client_list = "";
                }
                CommandText += " and v_Batch in ('" + selected_client_list + "') ";
            }
            if (ccbeForBranch.EditValue.ToString() != string.Empty)
            {
                CommandText += " and v_BRANCH_ID in (" + ccbeForBranch.EditValue.ToString() + ")";
            }
            if (ccbeForCollector.EditValue.ToString() != string.Empty)
            {
                CommandText += " and V_CollectorId in (" + ccbeForCollector.EditValue.ToString() + ")";
            }
            else if (DevXCharts.EmpIdsForHierarchey != "")
            {
                CommandText += " and V_CollectorId in (" + DevXCharts.EmpIdsForHierarchey.ToString() + ")";
            }
            if (ccbeForAccountType.Text.Trim() != "" && ccbeForAccountType.Text.Trim() != "--")
            {
                string selected_client_list = "";
                if (ccbeForAccountType.Text.Trim() != "" && ccbeForAccountType.Text.Trim() != "--")
                {
                    //selected_client_list = ccbe_client_list.Text.Replace(" ", "").Replace(",", "','");
                    string source = ccbeForAccountType.Text;
                    string[] split = source.Split(',');
                    string changed = "";
                    for (int i = 0; i < split.Length; i++)
                    {
                        changed += "," + split[i].Trim();
                    }
                    //string output = changed.Trim(',').Replace(",", "','");
                    selected_client_list = changed.Trim(',').Replace(",", "','");
                }
                else
                {
                    selected_client_list = "";
                }
                CommandText += " and v_AccountType in ('" + selected_client_list + "') ";
            }
            if (radioPayment.SelectedIndex == 0)
            {
                CommandText += " and v_Confirmed='Y'";
            }
            else if (radioPayment.SelectedIndex == 1)
            {
                CommandText += " and v_Confirmed='N'";
            }
            if (radioCases.SelectedIndex == 0)
            {
                CommandText += " and v_flagabort='0'";
            }
            else if (radioCases.SelectedIndex == 1)
            {
                CommandText += " and v_flagabort='1'";
            }
            CommandText += " order by v_debtorname";
            Application.DoEvents();
            if (objPB != null)
            {
                objPB.Close();
                objPB = null;
            }
            objPB = new ProgressBar();
            objPB.StartPosition = FormStartPosition.CenterScreen;
            objPB.progressBarControl1.EditValue = 20;
            objPB.TopMost = true;
            objPB.ShowInTaskbar = false;
            Application.DoEvents();
            objPB.Show();
            Application.DoEvents();
            SqlDataAdapter sql_for_debtors = new SqlDataAdapter(CommandText, DBConString.ConnectionString());
            DataSet ds_for_rhb = new DataSet();
            sql_for_debtors.SelectCommand.CommandTimeout = 0;
            sql_for_debtors.Fill(ds_for_rhb, "DMS_View_Payments");
            sql_for_debtors.Dispose();
            Application.DoEvents();
            objPB.progressBarControl1.EditValue = 40;
            Application.DoEvents();
            if (ds_for_rhb.Tables["DMS_View_Payments"].Rows.Count > 0)
            {
                XrtPaymentsDevx obj_report = new XrtPaymentsDevx();
                obj_report.xrlReportHeader.Text = "Payments From " + this.dtstartdate.DateTime.ToString("dd/MM/yyyy") + " To " + this.dtEnddate.DateTime.ToString("dd/MM/yyyy");
                string SelectionCriteria = "";
                if (this.ccbeForClient.Text != "" && this.ccbeForClient.Text != "--")
                {
                    SelectionCriteria += " Client: " + this.ccbeForClient.Text + " , ";
                }
                if (this.ccbeForBatch.Text != "" && this.ccbeForBatch.Text != "--")
                {
                    SelectionCriteria += " Batch: " + this.ccbeForBatch.Text + " , ";
                }
                if (this.ccbeForBranch.Text != "" && this.ccbeForBranch.Text != "--")
                {
                    SelectionCriteria += " Branch: " + this.ccbeForBranch.Text + " , ";
                }
                if (this.ccbeForCollector.Text != "" && this.ccbeForCollector.Text != "--")
                {
                    SelectionCriteria += " Collector: " + this.ccbeForCollector.Text + " , ";
                }
                if (this.ccbeForAccountType.Text != "" && this.ccbeForAccountType.Text != "--")
                {
                    SelectionCriteria += " AccType: " + this.ccbeForAccountType.Text + " , ";
                }
                if (radioPayment.SelectedIndex == 0)
                {
                    SelectionCriteria += " Payment Confirmed='Y'" + " , ";
                }
                else if (radioPayment.SelectedIndex == 1)
                {
                    SelectionCriteria += " Payment Confirmed='N'" + " , ";
                }
                else if (radioPayment.SelectedIndex == 2)
                {
                    SelectionCriteria += " Payment Confirmed='Y' And 'N'" + " , ";
                }
                if (radioCases.SelectedIndex == 1)
                {
                    SelectionCriteria += " Abort Cases" + " , ";
                }
                else if (radioCases.SelectedIndex == 0)
                {
                    SelectionCriteria += " Active Cases" + " , ";
                }
                else if (radioCases.SelectedIndex == 2)
                {
                    SelectionCriteria += " Both Active And Abort Cases" + " , ";
                }
                obj_report.xrlSelectionCriteria.Text = SelectionCriteria;
                obj_report.DataSource = ds_for_rhb;
                obj_report.DataMember = "DMS_View_Payments";
                Application.DoEvents();
                objPB.progressBarControl1.EditValue = 60;
                Application.DoEvents();
                obj_report.CreateDataBindings();
                Application.DoEvents();
                objPB.progressBarControl1.EditValue = 80;
                Application.DoEvents();
                //obj_report.bind_data();
                obj_report.ShowPreview();
                Application.DoEvents();
                objPB.progressBarControl1.EditValue = 90;
                Application.DoEvents();
                Application.DoEvents();
                objPB.progressBarControl1.EditValue = 100;
                Application.DoEvents();
                objPB.Close();
                Application.DoEvents();
            }
            else
            {
                XtraMessageBox.Show("No Records(s) Found", Program.MessageBoxTitle, MessageBoxButtons.OK, MessageBoxIcon.Information);
                objPB.progressBarControl1.EditValue = 100;                    
                //objPB.progressBarControl1.EditValue = 100;
                Application.DoEvents();
                objPB.Close();

                //Application.DoEvents();




                //objPB.progressBarControl1.EditValue = 100;                    
                //Application.DoEvents();
                //objPB.Close();                    
                //XtraMessageBox.Show("No Records(s) Found", Program.MessageBoxTitle, MessageBoxButtons.OK, MessageBoxIcon.Information);

            }
        }
        catch (Exception ex)
        {
            XtraMessageBox.Show(ex.Message.ToString() + " " + ex.Source.ToString(), Program.MessageBoxTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
    }

1 个答案:

答案 0 :(得分:0)

问题的原因是WaitForm 实例的使用不正确 您不应该直接显示/隐藏WaitForm,而是使用SplashScreenManager API来显示/隐藏WaitForm并与之交互。
在这里,我将尝试为您提供正确的方法:

首先,使用WaitForm显示运行搜索操作的代码应如下所示:

void OnRunSearchOperation_ButtonClick(object sender, EventArgs e) {
    bool success = false;
    SplashScreenManager.ShowForm(this, typeof(ProgressWaitForm), false, false); 
    try {
        // here you can run some long time operations
        success = SearchOperation();
    }
    finally { SplashScreenManager.CloseForm(); }
    if(!success) {
        XtraMessageBox.Show(this, "No entries found");
    }
}
bool SearchOperation() {
    // THIS IS SEARCH OPERATION IMITATION 
    const int count = 70000000;
    int stepThreshold = count / 100;
    decimal dec = 1.41M;
    for(int i = 0; i < count; i++) {
        dec /= 2;
        if((i % stepThreshold) == 0) 
            SplashScreenManager.Default.SendCommand(WaitFormCommand.PerformStep, null);
    }
    return false; // result
}

以下是WaitFormCommand和'ProgressWaitForm'实现:

public enum WaitFormCommand {
    PerformStep
}
public partial class ProgressWaitForm : WaitForm {
    public ProgressWaitForm() {
        InitializeComponent();
    }
    #region Overrides
    public override void ProcessCommand(Enum cmd, object arg) {
        base.ProcessCommand(cmd, arg);
        WaitFormCommand wfCmd = (WaitFormCommand)cmd;
        if(wfCmd == WaitFormCommand.PerformStep) 
            progressBarControl1.PerformStep();
    }
    #endregion
}