예제 #1
0
        private void btnPrint_Click(object sender, RoutedEventArgs e)
        {
            if (_report.IsBusy)
            {
                return;
            }

            string selectedReport = cbReport.SelectedItem as string;

            if (string.IsNullOrEmpty(selectedReport))
            {
                return;
            }
            PrintInfo pi = cbPrinter.SelectedItem as PrintInfo;

            if (pi == null)
            {
                return;
            }

            // load report
            try
            {
                // load from resource stream
                Assembly asm = Assembly.GetExecutingAssembly();
                using (Stream stream = asm.GetManifestResourceStream("FlexReportSamples.Resources.FlexCommonTasks_XML.flxr"))
                    _report.Load(stream, selectedReport);
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format("Failed to load report [{0}], exception:\r\n{1}", selectedReport, ex.Message), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            // render and print report
            try
            {
                _report.Render();
                C1PrintOptions po = new C1PrintOptions();
                po.PrintQueue = pi.PrintQueue;
                _report.Print(po);
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format("Failed to print report [{0}], exception:\r\n{1}", selectedReport, ex.Message), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }