当我搜索任何记录时,点击打印按钮后,它会给我一个错误,比如请选择行

本文关键字:一个 请选择 错误 记录 任何 搜索 按钮 打印 | 更新日期: 2023-09-27 18:20:40

在这里,我使用OLEDB(Access)数据库和rdlc报告开发了WPF应用程序。这里,我在Datagrid中遇到了问题。这个应用程序运行得很好,但当我搜索任何记录时,它会给我错误"请选择要打印的记录!!"。当我调试这个应用程序时,我知道它。当我搜索任何记录时,时间复选框值会自动设置为false。这就是问题所在。所以请建议我该怎么做?我可以更改搜索代码吗?如果我更改了它,请推荐我任何好的方法。提前感谢。请查看我的删除按钮代码,因为当我点击删除时,它会产生这个问题。

以下代码用于搜索支票名称:-

   private void txtChequeName_TextChanged(object sender, TextChangedEventArgs e)
    {           
       System.Windows.Controls.TextBox t = (System.Windows.Controls.TextBox)sender;
        string filter = t.Text.ToUpper();
        ICollectionView cv = CollectionViewSource.GetDefaultView(dgDataArea.ItemsSource);
        if (filter == "")
            cv.Filter = null;
        else
        {
            cv.Filter = o =>
            {
                BankMaster p = o as BankMaster;
                //if (t.Name == "txtFirstName")
                //return (p.FirstName == filter);
                return (p.ChequeName.ToUpper().StartsWith(filter));
            };
        }
    }

以下代码用于打印数据:-

       private void ImgPrint_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
        try
        {
            List<BankMaster> bmlist = dgDataArea.ItemsSource as List<BankMaster>;
            if (bmlist != null)
            {
                foreach (var item in bmlist)
                {
                    if (item.CheckAll == false)
                    {
                        MessageBox.Show("Please select the record which you want to print !!!", "Error In Selecting Record", MessageBoxButton.OK, MessageBoxImage.Error);
                        break;
                    }
                    else
                    {
                        ChequePrintReport chreport = new ChequePrintReport();
                        B_SQUARE_System.Core.Utility.GeneralDeclaration.isGridSelectionChange = true;
                        chreport.ChequeInfo__OnSaved += adddata_BankInfo_OnSaved;
                        chreport.isEditMode = true;
                        chreport.currentSelectedItem = bmlist;
                        chreport.ShowDialog();
                        break;
                    }
                }
            }
       }

                   private void Imgdelete_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
        try
        {
            List<BankMaster> bmlist = dgDataArea.ItemsSource as List<BankMaster>;
            String msg = "Are you sure you want to delete selected rows ? ";
            int count = 0;
            if (bmlist != null)
            {
                foreach (var item in bmlist)
                {
                    if (item.CheckAll == false)
                    {
                        MessageBox.Show("Please select the record which you want to delete !!!", "Error In Selecting Record", MessageBoxButton.OK, MessageBoxImage.Error);
                        break;
                    }
                    else
                    {
                        if (MessageBox.Show(msg, "Delete Cheque Data", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes)
                        {
                            foreach (var items in bmlist)
                            {
                                if (items.CheckAll == true)
                                {
                                    bmservices.deleteBankMasterInfo(items.Bank_ID);
                                    count++;
                                }
                            }
                            System.Windows.MessageBox.Show("You deleted " + " " + count + " " + "rows.", "Total Deleted Row", MessageBoxButton.OK, MessageBoxImage.Information);
                            BankMaster_Loaded(sender, e);
                        }
                        break;
                    }
                    break;
                }
            }   

应用程序输出

当我搜索任何记录时,点击打印按钮后,它会给我一个错误,比如请选择行

问题出在您的物品上。检查循环中的所有条件。您不应该在这里使用else语句,因为大多数项目都没有被检查,所以else代码将为某些项目运行。

更改foreach循环中的代码如下:

            bool printed = false;    
            foreach (var item in bmlist)
            {
                if (item.CheckAll)
                {
                //Place the Printing code here
                    printed=true;                        
                }
                if (printed == false)
                {
                   //Place the Error message here
                }
            }            

以类似方式更改删除代码。。。