Esempio n. 1
0
        /// <summary>
        /// Формирует отчет согласно заданным критериям
        /// </summary>
        /// <param name="sender"> Владелец окна отчета</param>
        /// <param name="Title">Надпись окна отчета</param>
        /// <param name="path">Путь к основном отчету</param>
        /// <param name="subreports">Подотчеты</param>
        /// <param name="tables">Таблицы данных отчета</param>
        /// <param name="r">Параметры отчета</param>
        /// <param name="duplex">Режим печати отчета</param>
        /// <param name="PreviewPrint">Показывать ли предварительный просмотр</param>
        /// <param name="EnabledExport">Доступные параметры для экспорта</param>
        public static void ShowReport(DependencyObject sender, string Title, string path, IEnumerable <SubReport> subreports, IEnumerable <DataTable> tables, IEnumerable <ReportParameter> r, SPrint.Duplex duplex = SPrint.Duplex.Simplex,
                                      bool PreviewPrint = true, DateTime?YearVersion = null, string[] EnabledExport = null)
        {
            if (!ExistsReport(path, YearVersion))
            {
                System.Windows.MessageBox.Show(Window.GetWindow(sender), "Ошибка формирования. Макет отчета не найден в заданной директории", "Зарплата предприятия");
                return;
            }
            ViewReportWindow f = new ViewReportWindow(EnabledExport);

            f.repViewer.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(LocalReport_SubreportProcessing);
            f.repViewer.LocalReport.LoadReportDefinition(File.OpenRead(string.Format(@"{0}\Reports\{1}{2}", AppLocalPath.CurrentAppPath, YearVersion.HasValue ? YearVersion.Value.Year.ToString() + @"\" : string.Empty, path)));

            if (subreports != null)
            {
                CurrentSubReports = subreports;
                foreach (SubReport st in subreports)
                {
                    f.repViewer.LocalReport.LoadSubreportDefinition(st.ReportName, File.OpenRead(string.Format(@"{0}\Reports\{1}{2}", AppLocalPath.CurrentAppPath, YearVersion.HasValue ? YearVersion.Value.Year.ToString() + @"\" : string.Empty, st.ReportPath)));
                }
            }
            else
            {
                CurrentSubReports = null;
            }
            f.repViewer.PrinterSettings.Duplex = duplex;
            f.repViewer.ZoomPercent            = 110;
            f.repViewer.LocalReport.DataSources.Clear();
            if (tables != null)
            {
                int i = 1;
                foreach (DataTable t in tables)
                {
                    f.repViewer.LocalReport.DataSources.Add(new ReportDataSource(string.Format("DataSet{0}", i++), t));
                }
            }
            if (r != null)
            {
                f.repViewer.LocalReport.SetParameters(r);
            }
            f.repViewer.RefreshReport();
            if (PreviewPrint)
            {
                f.repViewer.SetDisplayMode(DisplayMode.PrintLayout);
            }
            if (sender != null)
            {
                f.Owner = Window.GetWindow(sender);
            }
            f.Title += "    " + Title;
            f.Show();
        }
Esempio n. 2
0
        public static Window ShowReport(string Title, string path, IEnumerable <DataTable> tables, IEnumerable <ReportParameter> r)
        {
            ViewReportWindow f = new ViewReportWindow();

            f.repViewer.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(LocalReport_SubreportProcessing);
            f.repViewer.LocalReport.LoadReportDefinition(File.OpenRead(string.Format(@"{0}\Reports\{1}{2}", AppLocalPath.CurrentAppPath, string.Empty, path)));

            /*if (subreports != null)
             * {
             *  CurrentSubReports = subreports;
             *  foreach (SubReport st in subreports)
             *  {
             *      f.repViewer.LocalReport.LoadSubreportDefinition(st.ReportName, File.OpenRead(string.Format(@"{0}\Reports\{1}{2}", Connect.CurrentAppPath, string.Empty, st.ReportPath)));
             *  }
             * }
             * else*/
            CurrentSubReports       = null;
            f.repViewer.ZoomPercent = 100;
            f.repViewer.LocalReport.DataSources.Clear();
            if (tables != null)
            {
                int i = 1;
                foreach (DataTable t in tables)
                {
                    f.repViewer.LocalReport.DataSources.Add(new ReportDataSource(string.Format("DataSet{0}", i++), t));
                }
            }
            if (r != null)
            {
                f.repViewer.LocalReport.SetParameters(r);
            }
            f.repViewer.RefreshReport();
            f.repViewer.SetDisplayMode(DisplayMode.PrintLayout);
            f.Title += "    " + Title;
            f.Show();
            return(f);
        }