コード例 #1
0
        private void btnExportClickHandler(object sender, RoutedEventArgs e)
        {
            var filePrefix = m_customer.GetFullName().Replace(" ", "_");
            var f = new AskExportSettingsWindow(this, m_album, filePrefix) { Owner = this };
            f.ShowDialog();
            if (f.GetResult() != AskExportSettingsWindow.Result.Ok) return;

            var bg = new BackgroundWorker {WorkerReportsProgress = true, WorkerSupportsCancellation = true};
            bg.DoWork += (o, args) =>
                {
                    var worker = args.Argument as ExportFormatterBase;
                    worker.ExportCustomerOrders(m_customer);
                    args.Result = worker;
                };
            bg.RunWorkerCompleted += (o, args) =>
                {
                    tbTotal.Text = m_statusBackup;
                    Cursor = m_cursorBackup;

                    if (args.Error != null)
                    {
                        this.ShowError(args.Error.Message);
                    }
                    else
                    {
                        var worker = args.Result as ExportFormatterBase;
                        if (worker is IFileExporter)
                        {
                            if (this.ShowQuestion("Экспорт выполнен успешно. Открыть файл?"))
                            {
                                Process.Start(new ProcessStartInfo(((IFileExporter)worker).Filename) { Verb = "open" });
                            }
                        }
                        else if (worker is IReportExporter)
                        {
                            // open report in viewer
                            var f1 = new ReportsViewerWindow(((IReportExporter)worker).GetDocument()) { Owner = this };
                            f1.ShowDialog();
                        }
                    }
                };

            m_statusBackup = tbTotal.Text;
            tbTotal.Text = "Выполняется экспорт...";
            m_cursorBackup = Cursor;
            Cursor = Cursors.Wait;
            bg.RunWorkerAsync(f.GetSelectedFormatter());
        }
コード例 #2
0
        private void cmdPrintDeliveryListClickEventHandler(object sender, RoutedEventArgs e)
        {
            if (SelectedAlbum == null)
            {
                this.ShowMessage("Для выполнения операции выберите альбом.");
                return;
            }

            var f = new AskExportSettingsWindow(this, SelectedAlbum, @"ЛистДоставки");
            f.ShowDialog();

            if (f.GetResult() != AskExportSettingsWindow.Result.Ok) return;

            var formatter = f.GetSelectedFormatter();
            var bg = new BackgroundWorker {WorkerReportsProgress = true};
            bg.ProgressChanged += (o, args) =>
                {
                    if (m_waitingWindow != null)
                    {
                        m_waitingWindow.SetState(args.UserState);
                    }
                };
            bg.DoWork += (o, args) =>
                {
                    var worker = (BackgroundWorker) o;

                    worker.ReportProgress(0, "Выполняется экспорт");
                    var formObj = (ExportFormatterBase) args.Argument;
                    formObj.ExportDeliveryList();
                    args.Result = formObj;
                };
            bg.RunWorkerCompleted += (o, args) =>
                {
                    if (m_waitingWindow != null)
                    {
                        m_waitingWindow.Close();
                        m_waitingWindow = null;
                    }

                    if (args.Cancelled) return;
                    if (args.Error != null)
                    {
                        this.ShowError(args.Error.Message);
                        return;
                    }

                    var exporter = (ExportFormatterBase) args.Result;
                    if (exporter is IFileExporter)
                    {
                        if (this.ShowQuestion("Экспорт выполнен успешно. Открыть файл?"))
                        {
                            Process.Start(new ProcessStartInfo(((IFileExporter)exporter).Filename) { Verb = "open" });
                        }
                    }
                    else if (exporter is IReportExporter)
                    {
                        // open report in viewer
                        var f1 = new ReportsViewerWindow(((IReportExporter) exporter).GetDocument()){Owner = this};
                        f1.ShowDialog();
                    }

                };
            bg.RunWorkerAsync(formatter);

            m_waitingWindow = new WaitingWindow(this);
            m_waitingWindow.ShowDialog();
        }
コード例 #3
0
        private void btnExportCurrent_Click(object sender, RoutedEventArgs e)
        {
            if (SelectedAlbum == null || m_selectedView == ServiceTreeNodes.None)
            {
                this.ShowMessage("Для выполнения операции выберите альбом и категорию.");
                return;
            }

            var f = new AskExportSettingsWindow(this, SelectedAlbum, m_selectedView.ToString()) { Owner = this };
            f.ShowDialog();

            if (f.GetResult() != AskExportSettingsWindow.Result.Ok) return;

            var selectedFormatter = f.GetSelectedFormatter();
            selectedFormatter.ProgressChanged += (o, args) => SetStatus(args.StateMessage);

            var bg = new BackgroundWorker {WorkerReportsProgress = true};
            bg.ProgressChanged += (o, args) =>
                {
                    if (m_waitingWindow != null)
                    {
                        m_waitingWindow.SetState(args.UserState.ToString());
                    }
                };
            bg.DoWork += (o, args) =>
                {
                    var worker = (BackgroundWorker) o;
                    var formatter = (ExportFormatterBase) args.Argument;

                    worker.ReportProgress(0, "Формирование отчета...");
                    if (m_selectedView == ServiceTreeNodes.AlbumProducts)
                    {
                        formatter.ExportProductsSummary();
                    }
                    else if (m_selectedView == ServiceTreeNodes.AlbumCustomers)
                    {
                        formatter.ExportCustomersSummary();
                    }
                    else if (m_selectedView == ServiceTreeNodes.AlbumPaymets)
                    {
                        formatter.ExportPaymentsSummary();
                    }
                    else
                    {
                        throw new BgWorkerException("Не найдены отчеты для выбранного представления!");
                    }

                    args.Result = formatter;
                };
            bg.RunWorkerCompleted += (o, args) =>
                {
                    var worker = o as BackgroundWorker;
                    if (worker != null)
                    {
                        lock (m_workersPool)
                        {
                            m_workersPool.Remove(worker);
                        }
                    }

                    if (m_waitingWindow != null)
                    {
                        m_waitingWindow.Close();
                        m_waitingWindow = null;
                    }

                    if (args.Cancelled) return;
                    if (args.Error != null)
                    {
                        this.ShowError(args.Error.Message);
                        return;
                    }

                    var formatter = (ExportFormatterBase)args.Result;
                    if (formatter is IFileExporter)
                    {
                        if (this.ShowQuestion("Экспорт выполнен успешно. Открыть файл?"))
                        {
                            Process.Start(new ProcessStartInfo(((IFileExporter)formatter).Filename) { Verb = "open" });
                        }
                    }
                    else if (formatter is IReportExporter)
                    {
                        var doc = ((IReportExporter)formatter).GetDocument();
                        var f1 = new ReportsViewerWindow(doc) { Owner = this };
                        f1.Show();
                    }
                };

            lock (m_workersPool)
            {
                m_workersPool.Add(bg);
            }

            bg.RunWorkerAsync(selectedFormatter);
            m_waitingWindow = new WaitingWindow(this);
            m_waitingWindow.ShowDialog();
        }