2013-01-16 79 views
0

我有一個Devexpress表單,它具有進度條和MessageBox。 當我單擊我的表單上的搜索按鈕時,進度條顯示百分比,然後網格將與記錄綁定。 當它返回任何記錄,會像Devexpress 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); 
     } 
    } 
+0

您是否檢查過程序中的任何異常?在懷疑錯誤的地方提供代碼... –

+0

由於缺乏信息,很難確定此問題的原因。請提供確切的代碼... – DmitryG

+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 
}