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();
        }
Ejemplo n.º 2
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());
        }