jt
2021-06-10 5d0d028456874576560552f5a5c4e8b801786f11
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using GrapeCity.ActiveReports.Export.Html.Page;
using GrapeCity.ActiveReports.Export.Text.Page;
using GrapeCity.ActiveReports.Extensibility.Rendering.IO;
using GrapeCity.ActiveReports.Rendering.IO;
using System.IO;
using GrapeCity.ActiveReports.Export.Image.Page;
using GrapeCity.ActiveReports.Export.Pdf.Page;
using GrapeCity.ActiveReports.Export.Rdf;
using GrapeCity.ActiveReports.Export.Word.Page;
using GrapeCity.ActiveReports.Export.Xml.Page;
using GrapeCity.ActiveReports.Export.Excel.Page;
using GrapeCity.ActiveReports.Design;
using GrapeCity.ActiveReports.Export.Excel.Section;
using System.Xml;
using GrapeCity.ActiveReports.Viewer.Win;
using GrapeCity.ActiveReports;
namespace HH.WMS.Client
{
    public partial class ExportForm : Form
    {
        readonly DesignerReportType _reportType;
        readonly object _report;
        private readonly Viewer _reportViewer;
        readonly SectionReport _sectionReport = new SectionReport();
        public ExportForm(DesignerReportType reportType, object report, Viewer reportViewer)
        {
            _reportType = reportType;
            _report = report;
            _reportViewer = reportViewer;
            InitializeComponent();
        }
        void AddPageReportExportTypes()
        {
            List<PageExport> pageExports = new List<PageExport>();
            bool isFpl = _reportType == DesignerReportType.Page;
            var imageRenderingExtension = new ImageRenderingExtension();
            var wordRenderingExtension = new WordRenderingExtension();
            var htmlRenderingExtension = new HtmlRenderingExtension();
            var pdfRenderingExtension = new PdfRenderingExtension();
            var xmlRenderingExtension = new XmlRenderingExtension();
            var excelRenderingExtension = new ExcelRenderingExtension();
            var csvRenderingExtension = new CsvRenderingExtension();
            pageExports.Add(new PageExport
            {
                DisplayName = Properties.Resources.PageCsvString,
                DefaultFileName = Properties.Resources.CsvFileName,
                Settings = csvRenderingExtension.GetSupportedSettings(isFpl),
                Filter = Properties.Resources.CsvFilter,
                RenderingExtension = csvRenderingExtension,
            });
            pageExports.Add(new PageExport
            {
                DisplayName = Properties.Resources.PageImageString,
                DefaultFileName = Properties.Resources.ImageFileName,
                Settings = imageRenderingExtension.GetSupportedSettings(isFpl),
                Filter = Properties.Resources.ImageFilter,
                RenderingExtension = imageRenderingExtension,
            });
            pageExports.Add(new PageExport
            {
                DisplayName = Properties.Resources.PageWordString,
                DefaultFileName = Properties.Resources.WordFileName,
                Settings = wordRenderingExtension.GetSupportedSettings(isFpl),
                Filter = Properties.Resources.WordFilter,
                RenderingExtension = wordRenderingExtension,
            });
            pageExports.Add(new PageExport
            {
                DisplayName = Properties.Resources.PageHTMLString,
                DefaultFileName = Properties.Resources.HTMLFileName,
                Settings = htmlRenderingExtension.GetSupportedSettings(isFpl),
                Filter = Properties.Resources.HTMLFilter,
                RenderingExtension = htmlRenderingExtension,
            });
            pageExports.Add(new PageExport
            {
                DisplayName = Properties.Resources.PagePDFString,
                DefaultFileName = Properties.Resources.PDFFileName,
                Settings = pdfRenderingExtension.GetSupportedSettings(isFpl),
                Filter = Properties.Resources.PDFFilter,
                RenderingExtension = pdfRenderingExtension,
            });
            pageExports.Add(new PageExport
            {
                DisplayName = Properties.Resources.PageRDFString,
                DefaultFileName = Properties.Resources.RDFFileName,
                Settings = new GrapeCity.ActiveReports.Export.Rdf.Settings(),
                Filter = Properties.Resources.RdfFilter,
                RenderingExtension = new RdfRenderingExtension(),
            });
            pageExports.Add(new PageExport
            {
                DisplayName = Properties.Resources.PageXMLString,
                DefaultFileName = Properties.Resources.XMLFileName,
                Settings = xmlRenderingExtension.GetSupportedSettings(isFpl),
                Filter = Properties.Resources.XmlFilter,
                RenderingExtension = xmlRenderingExtension,
            });
            pageExports.Add(new PageExport
            {
                DisplayName = (_reportType == DesignerReportType.Rdl) ? Properties.Resources.PageExcelRE : Properties.Resources.PageExcelString,
                DefaultFileName = Properties.Resources.ExcelFileName,
                Settings = excelRenderingExtension.GetSupportedSettings(isFpl),
                Filter = Properties.Resources.ExcelFilter,
                RenderingExtension = excelRenderingExtension,
            });
            cmbExportFormat.DataSource = pageExports;
            cmbExportFormat.DisplayMember = "DisplayName";
            cmbExportFormat.SelectedIndex = 0;
        }
        void AddSectionReportExportTypes()
        {
            List<SectionExport> sectionExports = new List<SectionExport>();
            sectionExports.Add(new SectionExport
            {
                DisplayName = Properties.Resources.SectionHTMLString,
                Filter = Properties.Resources.HTMLFilter,
                DefaultFileName = Properties.Resources.HTMLFileName,
                Settings = new GrapeCity.ActiveReports.Export.Html.Section.HtmlExport()
            });
            sectionExports.Add(new SectionExport
            {
                DisplayName = Properties.Resources.SectionPDFString,
                Filter = Properties.Resources.PDFFilter,
                DefaultFileName = Properties.Resources.PDFFileName,
                Settings = new GrapeCity.ActiveReports.Export.Pdf.Section.PdfExport()
            });
            sectionExports.Add(new SectionExport
            {
                DisplayName = Properties.Resources.SectionRTFString,
                Filter = Properties.Resources.RtfFilter,
                DefaultFileName = Properties.Resources.RtfFileName,
                Settings = new GrapeCity.ActiveReports.Export.Word.Section.RtfExport()
            });
            sectionExports.Add(new SectionExport
            {
                DisplayName = Properties.Resources.SectionTIFFString,
                Filter = Properties.Resources.TiffFilter,
                DefaultFileName = Properties.Resources.TiffFileName,
                Settings = new GrapeCity.ActiveReports.Export.Image.Tiff.Section.TiffExport()
            });
            sectionExports.Add(new SectionExport
            {
                DisplayName = Properties.Resources.SectionPlainTextString,
                Filter = Properties.Resources.TextFilter,
                DefaultFileName = Properties.Resources.TextFileName,
                Settings = new GrapeCity.ActiveReports.Export.Xml.Section.TextExport()
            });
            sectionExports.Add(new SectionExport
            {
                DisplayName = Properties.Resources.SectionExcelString,
                Filter = Properties.Resources.ExcelFilter,
                DefaultFileName = Properties.Resources.ExcelFileName,
                Settings = new XlsExport()
            });
            cmbExportFormat.DataSource = sectionExports;
            cmbExportFormat.DisplayMember = "DisplayName";
            cmbExportFormat.SelectedIndex = 0;
        }
        private void ExportForm_Load(object sender, EventArgs e)
        {
            if (_reportType == DesignerReportType.Section)
            {
                AddSectionReportExportTypes();
            }
            if ((_reportType == DesignerReportType.Page) || (_reportType == DesignerReportType.Rdl))
            {
                AddPageReportExportTypes();
            }
        }
        private void cmbExportFormat_SelectedIndexChanged(object sender, EventArgs e)
        {
            if ((_reportType == DesignerReportType.Page) || (_reportType == DesignerReportType.Rdl))
            {
                exportPropertyGrid.SelectedObject = ((PageExport)cmbExportFormat.SelectedItem).Settings;
            }
            if (_reportType == DesignerReportType.Section)
            {
                exportPropertyGrid.SelectedObject = ((SectionExport)cmbExportFormat.SelectedItem).Settings;
            }
        }
        private void btnCancel_Click(object sender, EventArgs e)
        {
            Hide();
        }
        private void btnOk_Click(object sender, EventArgs e)
        {
            switch (_reportType)
            {
                case DesignerReportType.Section:
                    exportSaveFileDialog.Filter = ((SectionExport)cmbExportFormat.SelectedItem).Filter;
                    exportSaveFileDialog.FileName = ((SectionExport)cmbExportFormat.SelectedItem).DefaultFileName;
                    if (exportPropertyGrid.SelectedObject is XlsExport)
                    {
                        switch (((XlsExport)exportPropertyGrid.SelectedObject).FileFormat)
                        {
                            case GrapeCity.ActiveReports.Export.Excel.Section.FileFormat.Xlsx:
                                exportSaveFileDialog.FileName = Properties.Resources.Excel2007FileName;
                                exportSaveFileDialog.Filter = Properties.Resources.Excel2007Filter;
                                break;
                        }
                    }
                    if (exportSaveFileDialog.ShowDialog() == DialogResult.OK)
                    {
                        RunSectionReport();
                        if (File.Exists(exportSaveFileDialog.FileName))
                        {
                            File.Delete(exportSaveFileDialog.FileName);
                        }
                        ((SectionExport)cmbExportFormat.SelectedItem).Export(_sectionReport.Document, exportSaveFileDialog.FileName);
                        MessageBox.Show(((SectionExport)cmbExportFormat.SelectedItem).DisplayName + " " + Properties.Resources.ExportCompleteString);
                        Hide();
                    }
                    break;
                case DesignerReportType.Page:
                case DesignerReportType.Rdl:
                    exportSaveFileDialog.AddExtension = false;
                    exportSaveFileDialog.Filter = ((PageExport)cmbExportFormat.SelectedItem).Filter;
                    exportSaveFileDialog.FileName = ((PageExport)cmbExportFormat.SelectedItem).DefaultFileName;
                    if (exportPropertyGrid.SelectedObject is GrapeCity.ActiveReports.Export.Image.Page.Settings)
                    {
                        GrapeCity.ActiveReports.Export.Image.Page.Settings _settings = (GrapeCity.ActiveReports.Export.Image.Page.Settings)exportPropertyGrid.SelectedObject;
                        exportSaveFileDialog.FileName = ((PageExport)cmbExportFormat.SelectedItem).DefaultFileName + "." + _settings.ImageType.ToString().ToLower();
                    }
                    if (exportPropertyGrid.SelectedObject is GrapeCity.ActiveReports.Export.Word.Page.Settings &&
                        ((GrapeCity.ActiveReports.Export.Word.Page.Settings)exportPropertyGrid.SelectedObject).FileFormat ==
                            GrapeCity.ActiveReports.Export.Word.Page.FileFormat.OOXML)
                    {
                        exportSaveFileDialog.FileName = Properties.Resources.Word2007FileName;
                        exportSaveFileDialog.Filter = Properties.Resources.Word2007Filter;
                    }
                    if (exportPropertyGrid.SelectedObject is ExcelRenderingExtensionSettings &&
                        ((ExcelRenderingExtensionSettings) exportPropertyGrid.SelectedObject).FileFormat ==
                            GrapeCity.ActiveReports.Export.Excel.Page.FileFormat.Xlsx)
                    {
                        exportSaveFileDialog.FileName = Properties.Resources.Excel2007FileName;
                        exportSaveFileDialog.Filter = Properties.Resources.Excel2007Filter;
                    }
                    if (exportSaveFileDialog.ShowDialog() == DialogResult.OK)
                    {
                        if (File.Exists(exportSaveFileDialog.FileName))
                        {
                            File.Delete(exportSaveFileDialog.FileName);
                        }
                        PageExport tempQualifier = ((PageExport)cmbExportFormat.SelectedItem);
                        string filePath = exportSaveFileDialog.FileName;
                        StreamProvider StreamProvider = new FileStreamProvider(new DirectoryInfo(Path.GetDirectoryName(filePath)), Path.GetFileNameWithoutExtension(filePath));
                        _reportViewer.Render(tempQualifier.RenderingExtension, StreamProvider, tempQualifier.Settings.GetSettings());
                        MessageBox.Show(((PageExport)cmbExportFormat.SelectedItem).DisplayName + " " + Properties.Resources.ExportCompleteString);
                        Hide();
                    }
                    break;
            }
        }
        void RunSectionReport()
        {
            MemoryStream memoryStream = new MemoryStream();
            memoryStream.Position = 0;
            using (XmlWriter writer = XmlWriter.Create(memoryStream))
            {
                ((SectionReport)_report).SaveLayout(writer);
            }
            memoryStream.Position = 0;
            using (XmlReader reader = XmlReader.Create(memoryStream))
            {
                _sectionReport.LoadLayout(reader);
            }
            _sectionReport.Run();
        }
    }
}