进度栏不断循环

时间:2018-09-09 10:16:43

标签: c# winforms

我有一个进度条崩溃了,我正在使用coutner基于value ++方法增加其值,但是在更改代码后,进度条只会循环播放,而不会按预期方式将结果显示到网格中。

invoiceRecord = (SageDataObject240.InvoiceRecord)_workSpace.CreateObject(Resources.InvoiceRecord);


pnlProgress.Visible = true;
progBarSelectInvoices.Value = 0;
progBarSelectInvoices.Maximum = invoiceRecord.Count;

List<EdiInvoice> selectedInvoices = new List<EdiInvoice>();
EdiInvoice invoice;

DateTime fromDate = chkEnableFromDatePicker.Checked ? dtpFrom.Value.Date : DateTime.MinValue;
DateTime toDate = chkEnableToDatePicker.Checked ? dtpTo.Value.Date : DateTime.MaxValue;
int count = 0;
while (invoiceRecord.MoveLast())
{
    progBarSelectInvoices.Value++;
    bool isPosted = (SDOHelper.Read<sbyte>(invoiceRecord, Resources.POSTED_CODE) == 1);

    if (isPosted)
    {
        int invoiceNo = SDOHelper.Read<int>(invoiceRecord, Resources.INVOICE_NUMBER);
        string invoiceCustomerReference = SDOHelper.Read<string>(invoiceRecord, Resources.ACCOUNT_REF);
        bool isValidCustomerReference = (invoiceCustomerReference == _selectedCustomer.Reference || _selectedCustomer.IncludeBranchInvoices && _selectedCustomer.BranchCodes.ContainsKey(invoiceCustomerReference));

        sbyte invoiceTypeCode = SDOHelper.Read<sbyte>(invoiceRecord, Resources.INVOICE_TYPE_CODE);
        bool isValidType = invoiceTypeCode >= 0 && invoiceTypeCode <= 5;

        string notes1 = SDOHelper.Read<string>(invoiceRecord, "NOTES_1");
        bool isExported = notes1.Length > 2 && notes1.Substring(0, 3).Equals("EDI", StringComparison.CurrentCultureIgnoreCase);

        DateTime invoiceDate = SDOHelper.Read<DateTime>(invoiceRecord, "INVOICE_DATE");
        bool isInDateRange = invoiceDate >= fromDate && invoiceDate <= toDate;

        if (isValidCustomerReference && isValidType && (!isExported || chkIncludeAlreadyExportedInvoices.Checked) && isInDateRange)
        {
            invoice = new EdiInvoice();
            invoice.Customer = string.Format("({0}), {1}", invoiceCustomerReference, SDOHelper.Read<string>(invoiceRecord, Resources.NAME));
            invoice.InvoiceNumber = invoiceNo;
            invoice.Date = SDOHelper.Read<DateTime>(invoiceRecord, "INVOICE_DATE").ToString("dd/MM/yyyy");
            invoice.Type = GetInvoiceOrCredit(invoiceTypeCode);
            invoice.DeliveryAddress = SDOHelper.Read<string>(invoiceRecord, Resources.DEL_ADDRESS_1);
            invoice.Nett = SDOHelper.Read<double>(invoiceRecord, Resources.BASE_TOT_NET) + SDOHelper.Read<double>(invoiceRecord, Resources.BASE_CARR_NET);
            invoice.Vat = SDOHelper.Read<double>(invoiceRecord, Resources.BASE_TOT_TAX) + SDOHelper.Read<double>(invoiceRecord, Resources.BASE_CARR_TAX);

            selectedInvoices.Add(invoice);
        }
    }






    Application.DoEvents();
}  

我不明白为什么进度条会一直停在这里。

0 个答案:

没有答案