0

プログレスバーとメッセージボックスを備えたDevexpressフォームがあります。フォームの検索ボタンをクリックすると、進行状況バーにパーセンテージが表示され、グリッドがレコードにバインドされます。レコードが返されない場合は、「レコードが見つかりません」のようなプログレスバーの後にメッセージボックスが表示されます

ただし、レコードが見つかりませんと表示された後、メッセージボックスの[OK]または[キャンセル]ボタンをクリックせずに自動的に閉じます

プログレスバーのコード

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

1 に答える 1

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
}
于 2013-01-17T09:01:34.753 に答える