コード例 #1
0
        private void btnDownLoad_Click(object sender, RoutedEventArgs e)
        {
            PacerImportTransaction _transaction = new PacerImportTransaction()
            {
                DischargedCases = (bool)rdoDischarged.IsChecked, StartDate = (DateTime)rdpStartDate.SelectedDate, EndDate = (DateTime)rdpEndDate.SelectedDate, CourtID = _court.ID, PacerFileFormatID = _court.PacerFileFormatID
            };

            Mouse.OverrideCursor = Cursors.Wait;

            if (_transaction.QueryNewCases() == true)
            {
                if (MessageBox.Show("Do you wish to download and pay for " + _transaction.BillablePages.ToString() + " billable pages for " + _transaction.Cost.ToString("C"), "Continue?", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                {
                    if (_transaction.DownloadNewCases(true) == true)
                    {
                        Mouse.OverrideCursor = Cursors.Arrow;
                        MessageBox.Show(_transaction.ImportMessage);
                        this.DialogResult = true;
                        this.Close();
                    }
                    else
                    {
                        Mouse.OverrideCursor = Cursors.Arrow;
                        MessageBox.Show(_transaction.ImportMessage);
                    }
                }
                Mouse.OverrideCursor = Cursors.Arrow;
            }
            else
            {
                Mouse.OverrideCursor = Cursors.Arrow;
                MessageBox.Show(_transaction.ImportMessage);
            }
        }
コード例 #2
0
        private void bwAsync_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                // The Sender is the BackgroundWorker object we need it to
                // report progress and check for cancellation.
                BackgroundWorker   bwAsync = sender as BackgroundWorker;
                MutipleProcessSpec _spec   = (MutipleProcessSpec)e.Argument;

                int    i      = 0;
                string _state = "Checking ECF Versions...";
                bwAsync.ReportProgress(0, _state);

                _state = CourtService.CheckECFVersions();
                bwAsync.ReportProgress(0, _state);
                Thread.Sleep(1000);

                foreach (object _court in _spec.Courts)
                {
                    i++;

                    //refresh court from ID to get version that may have been updated
                    CourtService.Refresh((Court)_court);

                    if ((_spec.FiledOnly == true && (((Court)_court).LastPacerLoadFileDate == DateTime.Parse(DateTime.Now.AddDays(-1).ToShortDateString()))) ||
                        (_spec.FiledOnly == false && (((Court)_court).LastPacerLoadDischargeDate == DateTime.Parse(DateTime.Now.AddDays(-1).ToShortDateString()))))
                    {
                        //do nothing
                    }
                    else
                    {
                        // Periodically report progress to the main thread so that it can
                        // update the UI.
                        _state = "Downloading cases for  " + ((Court)_court).CourtName + "...";
                        bwAsync.ReportProgress(Convert.ToInt32(i * (100.0 / _courts.Count)), _state);
                        PacerImportTransaction _transaction = new PacerImportTransaction();

                        _transaction.CourtID         = ((Court)_court).ID;
                        _transaction.CourtName       = ((Court)_court).CourtName;
                        _transaction.DischargedCases = !_spec.FiledOnly;

                        if (_spec.StartDate != null)
                        {
                            _transaction.StartDate = (DateTime)_spec.StartDate;
                        }
                        //filed only cases use the LastPacerLoadFileDate
                        else if (_spec.FiledOnly == true)
                        {
                            if (((DateTime)((Court)_court).LastPacerLoadFileDate) > DateTime.MinValue)
                            {
                                _transaction.StartDate = ((DateTime)((Court)_court).LastPacerLoadFileDate).AddDays(1);
                            }
                            else
                            {
                                _transaction.StartDate = DateTime.Now.AddMonths(-1);
                            }
                        }
                        //discharged cases use the LastPacerLoadFileDate
                        else if (_spec.FiledOnly == false)
                        {
                            if (((DateTime)((Court)_court).LastPacerLoadDischargeDate) > DateTime.MinValue)
                            {
                                _transaction.StartDate = ((DateTime)((Court)_court).LastPacerLoadDischargeDate).AddDays(1);
                            }
                            else
                            {
                                _transaction.StartDate = DateTime.Now.AddMonths(-1);
                            }
                        }

                        if (_spec.EndDate != null)
                        {
                            _transaction.EndDate = (DateTime)_spec.EndDate;
                        }
                        else
                        {
                            _transaction.EndDate = DateTime.Parse(DateTime.Now.AddDays(-1).ToShortDateString());
                        }

                        _transaction.PacerFileFormatID = ((Court)_court).PacerFileFormatID;

                        //check if the transaction overlaps prior periods to avoid extra chanrges, if so throw an error
                        _transaction.CheckForPriorOverlappingDownloads();

                        _transaction.DownloadNewCases(_spec.GeocodeAddresses);

                        _multipleTransactions.Add(_transaction);

                        // Periodically check if a Cancellation request is pending.  If the user
                        // clicks cancel the line _asyncWorker.CancelAsync();
                        if (bwAsync.CancellationPending)
                        {
                            // Pause for bit to demonstrate that there is time between
                            // "Cancelling..." and "Canceled".
                            // Thread.Sleep(1200);

                            // Set the e.Cancel flag so that the WorkerCompleted event
                            // knows that the process was canceled.
                            e.Cancel = true;
                            return;
                        }
                    }
                }
                bwAsync.ReportProgress(100);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }