FastReport

Форк
0
/
ReportPage.cs 
1278 строк · 43.8 Кб
1
using System;
2
using System.Drawing;
3
using System.Collections.Generic;
4
using System.ComponentModel;
5
using FastReport.Utils;
6
using System.Drawing.Design;
7
using System.Drawing.Printing;
8

9
namespace FastReport
10
{
11
    /// <summary>
12
    /// Represents a report page.
13
    /// </summary>
14
    /// <remarks>
15
    /// To get/set a paper size and orientation, use the <see cref="PaperWidth"/>, <see cref="PaperHeight"/>
16
    /// and <see cref="Landscape"/> properties. Note that paper size is measured in millimeters.
17
    /// <para/>Report page can contain one or several bands with report objects. Use the <see cref="ReportTitle"/>, 
18
    /// <see cref="ReportSummary"/>, <see cref="PageHeader"/>, <see cref="PageFooter"/>, 
19
    /// <see cref="ColumnHeader"/>, <see cref="ColumnFooter"/>, <see cref="Overlay"/> properties
20
    /// to get/set the page bands. The <see cref="Bands"/> property holds the list of data bands or groups. 
21
    /// Thus you may add several databands to this property to create master-master reports, for example.
22
    /// <note type="caution">
23
    /// Report page can contain bands only. You cannot place report objects such as <b>TextObject</b> on a page.
24
    /// </note>
25
    /// </remarks>
26
    /// <example>
27
    /// This example shows how to create a page with one <b>ReportTitleBand</b> and <b>DataBand</b> bands and add
28
    /// it to the report.
29
    /// <code>
30
    /// ReportPage page = new ReportPage();
31
    /// // set the paper in millimeters
32
    /// page.PaperWidth = 210;
33
    /// page.PaperHeight = 297;
34
    /// // create report title
35
    /// page.ReportTitle = new ReportTitleBand();
36
    /// page.ReportTitle.Name = "ReportTitle1";
37
    /// page.ReportTitle.Height = Units.Millimeters * 10;
38
    /// // create data band
39
    /// DataBand data = new DataBand();
40
    /// data.Name = "Data1";
41
    /// data.Height = Units.Millimeters * 10;
42
    /// // add data band to the page
43
    /// page.Bands.Add(data);
44
    /// // add page to the report
45
    /// report.Pages.Add(page);
46
    /// </code>
47
    /// </example>
48
    public partial class ReportPage : PageBase, IParent
49
    {
50
        #region Constants
51

52
        private const float MAX_PAPER_SIZE_MM = 2000000000;
53

54
        #endregion // Constants
55

56
        #region Fields
57
        private string exportAlias;
58
        private float paperWidth;
59
        private float paperHeight;
60
        private int rawPaperSize;
61
        private bool landscape;
62
        private float leftMargin;
63
        private float topMargin;
64
        private float rightMargin;
65
        private float bottomMargin;
66
        private bool mirrorMargins;
67
        private PageColumns columns;
68
        private FloatCollection guides;
69
        private Border border;
70
        private FillBase fill;
71
        private Watermark watermark;
72
        private bool titleBeforeHeader;
73
        private string outlineExpression;
74
        private bool printOnPreviousPage;
75
        private bool resetPageNumber;
76
        private bool extraDesignWidth;
77
        private bool startOnOddPage;
78
        private bool backPage;
79
        private SubreportObject subreport;
80
        private PageHeaderBand pageHeader;
81
        private ReportTitleBand reportTitle;
82
        private ColumnHeaderBand columnHeader;
83
        private BandCollection bands;
84
        private ReportSummaryBand reportSummary;
85
        private ColumnFooterBand columnFooter;
86
        private PageFooterBand pageFooter;
87
        private OverlayBand overlay;
88
        private string createPageEvent;
89
        private string startPageEvent;
90
        private string finishPageEvent;
91
        private string manualBuildEvent;
92
        private int firstPageSource;
93
        private int otherPagesSource;
94
        private int lastPageSource;
95
        private Duplex duplex;
96

97
        private bool unlimitedHeight;
98
        private bool printOnRollPaper;
99
        private bool unlimitedWidth;
100
        private float unlimitedHeightValue;
101
        private float unlimitedWidthValue;
102

103
        #endregion
104

105
        #region Properties
106

107
        /// <summary>
108
        /// This event occurs when the report engine create new page. On this stage can be modified page properties.
109
        /// </summary>
110
        public event EventHandler CreatePage;
111
        /// <summary>
112
        /// This event occurs when the report engine starts this page.
113
        /// </summary>
114
        public event EventHandler StartPage;
115

116
        /// <summary>
117
        /// This event occurs when the report engine finished this page.
118
        /// </summary>
119
        public event EventHandler FinishPage;
120

121
        /// <summary>
122
        /// This event occurs when the report engine is about to print databands in this page.
123
        /// </summary>
124
        public event EventHandler ManualBuild;
125

126
        /// <summary>
127
        /// Gets or sets a width of the paper, in millimeters.
128
        /// </summary>
129
        [Category("Paper")]
130
        [TypeConverter("FastReport.TypeConverters.PaperConverter, FastReport")]
131
        public float PaperWidth
132
        {
133
            get { return paperWidth; }
134
            set { paperWidth = value; }
135
        }
136

137
        /// <summary>
138
        /// Gets or sets the page name on export
139
        /// </summary>
140
        [Category("Paper")]
141
        public string ExportAlias
142
        {
143
            get { return exportAlias; }
144
            set { exportAlias = value; }
145
        }
146

147
        /// <summary>
148
        /// Gets or sets a height of the paper, in millimeters.
149
        /// </summary>
150
        [Category("Paper")]
151
        [TypeConverter("FastReport.TypeConverters.PaperConverter, FastReport")]
152
        public float PaperHeight
153
        {
154
            get { return paperHeight; }
155
            set { paperHeight = value; }
156
        }
157

158
        /// <summary>
159
        /// Gets or sets the raw index of a paper size.
160
        /// </summary>
161
        /// <remarks>
162
        /// This property stores the RawKind value of a selected papersize. It is used to distinguish
163
        /// between several papers with the same size (for ex. "A3" and "A3 with no margins") used in some
164
        /// printer drivers. 
165
        /// <para/>It is not obligatory to set this property. FastReport will select the
166
        /// necessary paper using the <b>PaperWidth</b> and <b>PaperHeight</b> values.
167
        /// </remarks>
168
        [Category("Paper")]
169
        [DefaultValue(0)]
170
        public int RawPaperSize
171
        {
172
            get { return rawPaperSize; }
173
            set { rawPaperSize = value; }
174
        }
175

176
        /// <summary>
177
        /// Gets or sets a value indicating whether the page has unlimited height.
178
        /// </summary>
179
        [DefaultValue(false)]
180
        [Category("Paper")]
181
        public bool UnlimitedHeight
182
        {
183
            get { return unlimitedHeight; }
184
            set
185
            {
186
                unlimitedHeight = value;
187
                if (!unlimitedHeight)
188
                    printOnRollPaper = false;
189
            }
190
        }
191

192
        /// <summary>
193
        /// Gets or sets the value indicating whether the unlimited page should be printed on roll paper.
194
        /// </summary>
195
        [DefaultValue(false)]
196
        [Category("Paper")]
197
        public bool PrintOnRollPaper
198
        {
199
            get { return printOnRollPaper; }
200
            set
201
            {
202
                if (unlimitedHeight)
203
                    printOnRollPaper = value;
204
            }
205
        }
206

207
        /// <summary>
208
        /// Gets or sets a value indicating whether the page has unlimited width.
209
        /// </summary>
210
        [DefaultValue(false)]
211
        [Category("Paper")]
212
        public bool UnlimitedWidth
213
        {
214
            get { return unlimitedWidth; }
215
            set { unlimitedWidth = value; }
216
        }
217

218
        /// <summary>
219
        /// Get or set the current height of unlimited page.
220
        /// </summary>
221
        [Browsable(false)]
222
        public float UnlimitedHeightValue
223
        {
224
            get { return unlimitedHeightValue; }
225
            set
226
            {
227
                unlimitedHeightValue = value;
228
                if (printOnRollPaper)
229
                    PaperHeight = unlimitedHeightValue / Units.Millimeters;
230
            }
231
        }
232

233
        /// <summary>
234
        /// Get or set the current width of unlimited page.
235
        /// </summary>
236
        [Browsable(false)]
237
        public float UnlimitedWidthValue
238
        {
239
            get { return unlimitedWidthValue; }
240
            set { unlimitedWidthValue = value; }
241
        }
242

243
        /// <summary>
244
        /// Gets the current page height in pixels.
245
        /// </summary>
246
        [Browsable(false)]
247
        public float HeightInPixels
248
        {
249
            get
250
            {
251
                return UnlimitedHeight ? UnlimitedHeightValue : PaperHeight * Units.Millimeters;
252
            }
253
        }
254

255
        /// <summary>
256
        /// Gets the current page width in pixels.
257
        /// </summary>
258
        [Browsable(false)]
259
        public float WidthInPixels
260
        {
261
            get
262
            {
263
                if (UnlimitedWidth)
264
                {
265
                    if (!IsDesigning)
266
                    {
267
                        return UnlimitedWidthValue;
268
                    }
269
                }
270
                return PaperWidth * Units.Millimeters;
271

272
            }
273
        }
274

275
        /// <summary>
276
        /// Gets or sets a value indicating that page should be in landscape orientation.
277
        /// </summary>
278
        /// <remarks>
279
        /// When you change this property, it will automatically swap paper width and height, as well as paper margins.
280
        /// </remarks>
281
        [DefaultValue(false)]
282
        [Category("Paper")]
283
        public bool Landscape
284
        {
285
            get { return landscape; }
286
            set
287
            {
288
                if (landscape != value)
289
                {
290
                    landscape = value;
291
                    if (IsDeserializing)
292
                    {
293
                        return;
294
                    }
295

296
                    float e = paperWidth;
297
                    paperWidth = paperHeight;
298
                    paperHeight = e;
299

300
                    float m1 = leftMargin;   //     m3
301
                    float m2 = rightMargin;  //  m1    m2
302
                    float m3 = topMargin;    //     m4
303
                    float m4 = bottomMargin; //
304

305
                    if (value)
306
                    {
307
                        leftMargin = m3;       // rotate counter-clockwise
308
                        rightMargin = m4;
309
                        topMargin = m2;
310
                        bottomMargin = m1;
311
                    }
312
                    else
313
                    {
314
                        leftMargin = m4;       // rotate clockwise
315
                        rightMargin = m3;
316
                        topMargin = m1;
317
                        bottomMargin = m2;
318
                    }
319
                }
320
            }
321
        }
322

323
        /// <summary>
324
        /// Gets or sets the left page margin, in millimeters.
325
        /// </summary>
326
        [Category("Paper")]
327
        [TypeConverter("FastReport.TypeConverters.PaperConverter, FastReport")]
328
        public float LeftMargin
329
        {
330
            get { return leftMargin; }
331
            set { leftMargin = value; }
332
        }
333

334
        /// <summary>
335
        /// Gets or sets the top page margin, in millimeters.
336
        /// </summary>
337
        [Category("Paper")]
338
        [TypeConverter("FastReport.TypeConverters.PaperConverter, FastReport")]
339
        public float TopMargin
340
        {
341
            get { return topMargin; }
342
            set { topMargin = value; }
343
        }
344

345
        /// <summary>
346
        /// Gets or sets the right page margin, in millimeters.
347
        /// </summary>
348
        [Category("Paper")]
349
        [TypeConverter("FastReport.TypeConverters.PaperConverter, FastReport")]
350
        public float RightMargin
351
        {
352
            get { return rightMargin; }
353
            set { rightMargin = value; }
354
        }
355

356
        /// <summary>
357
        /// Gets or sets the bottom page margin, in millimeters.
358
        /// </summary>
359
        [Category("Paper")]
360
        [TypeConverter("FastReport.TypeConverters.PaperConverter, FastReport")]
361
        public float BottomMargin
362
        {
363
            get { return bottomMargin; }
364
            set { bottomMargin = value; }
365
        }
366

367
        /// <summary>
368
        /// Gets or sets a value indicating that even pages should swap its left and right margins when
369
        /// previewed or printed.
370
        /// </summary>
371
        [DefaultValue(false)]
372
        [Category("Behavior")]
373
        public bool MirrorMargins
374
        {
375
            get { return mirrorMargins; }
376
            set { mirrorMargins = value; }
377
        }
378

379
        /// <summary>
380
        /// Gets the page columns settings.
381
        /// </summary>
382
        [Category("Appearance")]
383
        public PageColumns Columns
384
        {
385
            get { return columns; }
386
        }
387

388
        /// <summary>
389
        /// Gets or sets the page border that will be printed inside the page printing area.
390
        /// </summary>
391
        [Category("Appearance")]
392
        public Border Border
393
        {
394
            get { return border; }
395
            set { border = value; }
396
        }
397

398

399
        /// <summary>
400
        /// Gets or sets the page background fill.
401
        /// </summary>
402
        [Category("Appearance")]
403
        [Editor("FastReport.TypeEditors.FillEditor, FastReport", typeof(UITypeEditor))]
404
        public FillBase Fill
405
        {
406
            get { return fill; }
407
            set
408
            {
409
                if (value == null)
410
                    throw new ArgumentNullException("Fill");
411
                fill = value;
412
            }
413
        }
414

415
        /// <summary>
416
        /// Gets or sets the page watermark.
417
        /// </summary>
418
        /// <remarks>
419
        /// To enabled watermark, set its <b>Enabled</b> property to <b>true</b>.
420
        /// </remarks>
421
        [Category("Appearance")]
422
        public Watermark Watermark
423
        {
424
            get { return watermark; }
425
            set
426
            {
427
                if (watermark != value)
428
                    if (watermark != null)
429
                        watermark.Dispose();
430
                watermark = value;
431
            }
432
        }
433

434
        /// <summary>
435
        /// Gets or sets a value indicating that <b>ReportTitle</b> band should be printed before the 
436
        /// <b>PageHeader</b> band.
437
        /// </summary>
438
        [DefaultValue(true)]
439
        [Category("Behavior")]
440
        public bool TitleBeforeHeader
441
        {
442
            get { return titleBeforeHeader; }
443
            set { titleBeforeHeader = value; }
444
        }
445

446
        /// <summary>
447
        /// Gets or sets an outline expression.
448
        /// </summary>
449
        /// <remarks>
450
        /// For more information, see <see cref="BandBase.OutlineExpression"/> property.
451
        /// </remarks>
452
        [Category("Data")]
453
        [Editor("FastReport.TypeEditors.ExpressionEditor, FastReport", typeof(UITypeEditor))]
454
        public string OutlineExpression
455
        {
456
            get { return outlineExpression; }
457
            set { outlineExpression = value; }
458
        }
459

460
        /// <summary>
461
        /// Gets or sets a value indicating whether to start to print this page on a free space of the previous page.
462
        /// </summary>
463
        /// <remarks>
464
        /// This property can be used if you have two or more pages in the report template.
465
        /// </remarks>
466
        [DefaultValue(false)]
467
        [Category("Behavior")]
468
        public bool PrintOnPreviousPage
469
        {
470
            get { return printOnPreviousPage; }
471
            set { printOnPreviousPage = value; }
472
        }
473

474
        /// <summary>
475
        /// Gets or sets a value indicating that FastReport engine must reset page numbers before printing this page.
476
        /// </summary>
477
        /// <remarks>
478
        /// This property can be used if you have two or more pages in the report template.
479
        /// </remarks>
480
        [DefaultValue(false)]
481
        [Category("Behavior")]
482
        public bool ResetPageNumber
483
        {
484
            get { return resetPageNumber; }
485
            set { resetPageNumber = value; }
486
        }
487

488
        /// <summary>
489
        /// Gets or sets a value indicating whether the page has extra width in the report designer.
490
        /// </summary>
491
        /// <remarks>
492
        /// This property may be useful if you work with such objects as Matrix and Table.
493
        /// </remarks>
494
        [DefaultValue(false)]
495
        [Category("Design")]
496
        public bool ExtraDesignWidth
497
        {
498
            get { return extraDesignWidth; }
499
            set { extraDesignWidth = value; }
500
        }
501

502
        /// <summary>
503
        /// Gets or sets a value indicating whether this page will start on an odd page only.
504
        /// </summary>
505
        /// <remarks>
506
        /// This property is useful to print booklet-type reports. Setting this property to <b>true</b>
507
        /// means that this page will start to print on an odd page only. If necessary, an empty page
508
        /// will be added to the prepared report before this page will be printed.
509
        /// </remarks>
510
        [DefaultValue(false)]
511
        [Category("Behavior")]
512
        public bool StartOnOddPage
513
        {
514
            get { return startOnOddPage; }
515
            set { startOnOddPage = value; }
516
        }
517

518
        /// <summary>
519
        /// Uses this page as a back page for previously printed pages.
520
        /// </summary>
521
        [DefaultValue(false)]
522
        [Category("Behavior")]
523
        public bool BackPage
524
        {
525
            get { return backPage; }
526
            set { backPage = value; }
527
        }
528

529
        /// <summary>
530
        /// Gets or sets a report title band.
531
        /// </summary>
532
        [Browsable(false)]
533
        public ReportTitleBand ReportTitle
534
        {
535
            get { return reportTitle; }
536
            set
537
            {
538
                SetProp(reportTitle, value);
539
                reportTitle = value;
540
            }
541
        }
542

543
        /// <summary>
544
        /// Gets or sets a report summary band.
545
        /// </summary>
546
        [Browsable(false)]
547
        public ReportSummaryBand ReportSummary
548
        {
549
            get { return reportSummary; }
550
            set
551
            {
552
                SetProp(reportSummary, value);
553
                reportSummary = value;
554
            }
555
        }
556

557
        /// <summary>
558
        /// Gets or sets a page header band.
559
        /// </summary>
560
        [Browsable(false)]
561
        public PageHeaderBand PageHeader
562
        {
563
            get { return pageHeader; }
564
            set
565
            {
566
                SetProp(pageHeader, value);
567
                pageHeader = value;
568
            }
569
        }
570

571
        /// <summary>
572
        /// Gets or sets a page footer band.
573
        /// </summary>
574
        [Browsable(false)]
575
        public PageFooterBand PageFooter
576
        {
577
            get { return pageFooter; }
578
            set
579
            {
580
                SetProp(pageFooter, value);
581
                pageFooter = value;
582
            }
583
        }
584

585
        /// <summary>
586
        /// Gets or sets a column header band.
587
        /// </summary>
588
        [Browsable(false)]
589
        public ColumnHeaderBand ColumnHeader
590
        {
591
            get { return columnHeader; }
592
            set
593
            {
594
                SetProp(columnHeader, value);
595
                columnHeader = value;
596
            }
597
        }
598

599
        /// <summary>
600
        /// Gets or sets a column footer band.
601
        /// </summary>
602
        [Browsable(false)]
603
        public ColumnFooterBand ColumnFooter
604
        {
605
            get { return columnFooter; }
606
            set
607
            {
608
                SetProp(columnFooter, value);
609
                columnFooter = value;
610
            }
611
        }
612

613
        /// <summary>
614
        /// Gets or sets an overlay band.
615
        /// </summary>
616
        [Browsable(false)]
617
        public OverlayBand Overlay
618
        {
619
            get { return overlay; }
620
            set
621
            {
622
                SetProp(overlay, value);
623
                overlay = value;
624
            }
625
        }
626

627
        /// <summary>
628
        /// Gets the collection of data bands or group header bands.
629
        /// </summary>
630
        /// <remarks>
631
        /// The <b>Bands</b> property holds the list of data bands or group headers. 
632
        /// Thus you may add several databands to this property to create master-master reports, for example.
633
        /// </remarks>
634
        [Browsable(false)]
635
        public BandCollection Bands
636
        {
637
            get { return bands; }
638
        }
639

640
        /// <summary>
641
        /// Gets or sets the page guidelines.
642
        /// </summary>
643
        /// <remarks>
644
        /// This property hold all vertical guidelines. The horizontal guidelines are owned by the bands (see
645
        /// <see cref="BandBase.Guides"/> property).
646
        /// </remarks>
647
        [Browsable(false)]
648
        public FloatCollection Guides
649
        {
650
            get { return guides; }
651
            set { guides = value; }
652
        }
653

654
        /// <summary>
655
        /// Gets or sets the reference to a parent <b>SubreportObject</b> that owns this page.
656
        /// </summary>
657
        /// <remarks>
658
        /// This property is <b>null</b> for regular report pages. See the <see cref="SubreportObject"/> for details.
659
        /// </remarks>
660
        [Browsable(false)]
661
        public SubreportObject Subreport
662
        {
663
            get { return subreport; }
664
            set { subreport = value; }
665
        }
666

667
        /// <summary>
668
        /// Gets or sets a script event name that will be fired when the report engine create new page.
669
        /// On this stage can be modified page properties.
670
        /// </summary>
671
        [Category("Build")]
672
        public string CreatePageEvent
673
        {
674
            get { return createPageEvent; }
675
            set { createPageEvent = value; }
676
        }
677

678
        /// <summary>
679
        /// Gets or sets a script event name that will be fired when the report engine starts this page.
680
        /// </summary>
681
        [Category("Build")]
682
        public string StartPageEvent
683
        {
684
            get { return startPageEvent; }
685
            set { startPageEvent = value; }
686
        }
687

688
        /// <summary>
689
        /// Gets or sets a script event name that will be fired when the report engine finished this page.
690
        /// </summary>
691
        [Category("Build")]
692
        public string FinishPageEvent
693
        {
694
            get { return finishPageEvent; }
695
            set { finishPageEvent = value; }
696
        }
697

698
        /// <summary>
699
        /// Gets or sets a script event name that will be fired when the report engine is about 
700
        /// to print databands in this page.
701
        /// </summary>
702
        [Category("Build")]
703
        public string ManualBuildEvent
704
        {
705
            get { return manualBuildEvent; }
706
            set { manualBuildEvent = value; }
707
        }
708

709
        /// <summary>
710
        /// Gets or sets the paper source for the first printed page.
711
        /// </summary>
712
        /// <remarks>
713
        /// <para>
714
        /// This property represents the paper source (printer tray) that will be used when printing
715
        /// the first page. To set the source for other pages, use
716
        /// <see cref="LastPageSource"/> and <see cref="OtherPagesSource"/> properties.
717
        /// </para>
718
        /// <para>
719
        /// Note: This property uses the <b>raw</b> number of the paper source.
720
        /// </para>
721
        /// </remarks>
722
        [DefaultValue(7)]
723
        [Category("Print")]
724
        public int FirstPageSource
725
        {
726
            get { return firstPageSource; }
727
            set { firstPageSource = value; }
728
        }
729

730
        /// <summary>
731
        /// Gets or sets the paper source for all printed pages except the first one.
732
        /// </summary>
733
        /// <remarks>
734
        /// <para>
735
        /// This property represents the paper source (printer tray) that will be used when printing
736
        /// all pages except the first one and the last one. To set source for first and last pages, use 
737
        /// <see cref="FirstPageSource"/> and <see cref="LastPageSource"/> properties.
738
        /// </para>
739
        /// <para>
740
        /// Note: This property uses the <b>raw</b> number of the paper source.
741
        /// </para>
742
        /// </remarks>
743
        [DefaultValue(7)]
744
        [Category("Print")]
745
        public int OtherPagesSource
746
        {
747
            get { return otherPagesSource; }
748
            set { otherPagesSource = value; }
749
        }
750

751
        /// <summary>
752
        /// Gets or sets the paper source for the last printed page.
753
        /// </summary>
754
        /// <remarks>
755
        /// <para>
756
        /// This property represents the paper source (printer tray) that will be used when printing
757
        /// the last page. To set the source for other pages, use
758
        /// <see cref="FirstPageSource"/> and <see cref="OtherPagesSource"/> properties.
759
        /// </para>
760
        /// <para>
761
        /// Note: This property uses the <b>raw</b> number of the paper source.
762
        /// </para>
763
        /// </remarks>
764
        [DefaultValue(7)]
765
        [Category("Print")]
766
        public int LastPageSource
767
        {
768
            get { return lastPageSource; }
769
            set { lastPageSource = value; }
770
        }
771

772
        /// <summary>
773
        /// Gets or sets the printer duplex mode that will be used when printing this page.
774
        /// </summary>
775
        [DefaultValue(Duplex.Default)]
776
        [Category("Print")]
777
        public Duplex Duplex
778
        {
779
            get { return duplex; }
780
            set { duplex = value; }
781
        }
782

783
        internal bool IsManualBuild
784
        {
785
            get { return !String.IsNullOrEmpty(manualBuildEvent) || ManualBuild != null; }
786
        }
787
        #endregion
788

789
        #region Private Methods
790
        private void DrawBackground(FRPaintEventArgs e, RectangleF rect)
791
        {
792
            rect.Width *= e.ScaleX;
793
            rect.Height *= e.ScaleY;
794
            Brush brush = null;
795
            if (Fill is SolidFill)
796
                brush = e.Cache.GetBrush((Fill as SolidFill).Color);
797
            else
798
                brush = Fill.CreateBrush(rect, e.ScaleX, e.ScaleY);
799

800
            e.Graphics.FillRectangle(brush, rect.Left, rect.Top, rect.Width, rect.Height);
801
            if (!(Fill is SolidFill))
802
                brush.Dispose();
803
        }
804
        #endregion
805

806
        #region Protected Methods
807

808
        /// <inheritdoc/>
809
        protected override void Dispose(bool disposing)
810
        {
811
            if (disposing)
812
            {
813
                if (Subreport != null)
814
                {
815
                    Subreport.ReportPage = null;
816
                }
817
                if (Watermark != null)
818
                {
819
                    Watermark.Dispose();
820
                    Watermark = null;
821
                }
822
            }
823
            base.Dispose(disposing);
824
        }
825

826
        #endregion
827

828
        #region IParent
829
        /// <inheritdoc/>
830
        public virtual void GetChildObjects(ObjectCollection list)
831
        {
832
            if (TitleBeforeHeader)
833
            {
834
                list.Add(reportTitle);
835
                list.Add(pageHeader);
836
            }
837
            else
838
            {
839
                list.Add(pageHeader);
840
                list.Add(reportTitle);
841
            }
842
            list.Add(columnHeader);
843
            foreach (BandBase band in bands)
844
            {
845
                list.Add(band);
846
            }
847
            list.Add(reportSummary);
848
            list.Add(columnFooter);
849
            list.Add(pageFooter);
850
            list.Add(overlay);
851
        }
852

853
        /// <inheritdoc/>
854
        public virtual bool CanContain(Base child)
855
        {
856
            if (IsRunning)
857
                return child is BandBase;
858
            return (child is PageHeaderBand || child is ReportTitleBand || child is ColumnHeaderBand ||
859
              child is DataBand || child is GroupHeaderBand || child is ColumnFooterBand ||
860
              child is ReportSummaryBand || child is PageFooterBand || child is OverlayBand);
861
        }
862

863
        /// <inheritdoc/>
864
        public virtual void AddChild(Base child)
865
        {
866
            if (IsRunning)
867
            {
868
                bands.Add(child as BandBase);
869
                return;
870
            }
871
            if (child is PageHeaderBand)
872
                PageHeader = child as PageHeaderBand;
873
            if (child is ReportTitleBand)
874
                ReportTitle = child as ReportTitleBand;
875
            if (child is ColumnHeaderBand)
876
                ColumnHeader = child as ColumnHeaderBand;
877
            if (child is DataBand || child is GroupHeaderBand)
878
                bands.Add(child as BandBase);
879
            if (child is ReportSummaryBand)
880
                ReportSummary = child as ReportSummaryBand;
881
            if (child is ColumnFooterBand)
882
                ColumnFooter = child as ColumnFooterBand;
883
            if (child is PageFooterBand)
884
                PageFooter = child as PageFooterBand;
885
            if (child is OverlayBand)
886
                Overlay = child as OverlayBand;
887
        }
888

889
        /// <inheritdoc/>
890
        public virtual void RemoveChild(Base child)
891
        {
892
            if (IsRunning)
893
            {
894
                bands.Remove(child as BandBase);
895
                return;
896
            }
897
            if (child is PageHeaderBand && pageHeader == child as PageHeaderBand)
898
                PageHeader = null;
899
            if (child is ReportTitleBand && reportTitle == child as ReportTitleBand)
900
                ReportTitle = null;
901
            if (child is ColumnHeaderBand && columnHeader == child as ColumnHeaderBand)
902
                ColumnHeader = null;
903
            if (child is DataBand || child is GroupHeaderBand)
904
                bands.Remove(child as BandBase);
905
            if (child is ReportSummaryBand && reportSummary == child as ReportSummaryBand)
906
                ReportSummary = null;
907
            if (child is ColumnFooterBand && columnFooter == child as ColumnFooterBand)
908
                ColumnFooter = null;
909
            if (child is PageFooterBand && pageFooter == child as PageFooterBand)
910
                PageFooter = null;
911
            if (child is OverlayBand && overlay == child as OverlayBand)
912
                Overlay = null;
913
        }
914

915
        /// <inheritdoc/>
916
        public virtual int GetChildOrder(Base child)
917
        {
918
            return bands.IndexOf(child as BandBase);
919
        }
920

921
        /// <inheritdoc/>
922
        public virtual void SetChildOrder(Base child, int order)
923
        {
924
            if (order > bands.Count)
925
                order = bands.Count;
926
            int oldOrder = child.ZOrder;
927
            if (oldOrder != -1 && order != -1 && oldOrder != order)
928
            {
929
                if (oldOrder <= order)
930
                    order--;
931
                bands.Remove(child as BandBase);
932
                bands.Insert(order, child as BandBase);
933
            }
934
        }
935

936
        /// <inheritdoc/>
937
        public virtual void UpdateLayout(float dx, float dy)
938
        {
939
            // do nothing
940
        }
941
        #endregion
942

943
        #region Public Methods
944
        /// <inheritdoc/>
945
        public override void Assign(Base source)
946
        {
947
            base.Assign(source);
948

949
            ReportPage src = source as ReportPage;
950
            ExportAlias = src.ExportAlias;
951
            Landscape = src.Landscape;
952
            PaperWidth = src.PaperWidth;
953
            PaperHeight = src.PaperHeight;
954
            RawPaperSize = src.RawPaperSize;
955
            LeftMargin = src.LeftMargin;
956
            TopMargin = src.TopMargin;
957
            RightMargin = src.RightMargin;
958
            BottomMargin = src.BottomMargin;
959
            MirrorMargins = src.MirrorMargins;
960
            FirstPageSource = src.FirstPageSource;
961
            OtherPagesSource = src.OtherPagesSource;
962
            LastPageSource = src.LastPageSource;
963
            Duplex = src.Duplex;
964
            Columns.Assign(src.Columns);
965
            Guides.Assign(src.Guides);
966
            Border = src.Border.Clone();
967
            Fill = src.Fill.Clone();
968
            Watermark.Assign(src.Watermark);
969
            TitleBeforeHeader = src.TitleBeforeHeader;
970
            OutlineExpression = src.OutlineExpression;
971
            PrintOnPreviousPage = src.PrintOnPreviousPage;
972
            ResetPageNumber = src.ResetPageNumber;
973
            ExtraDesignWidth = src.ExtraDesignWidth;
974
            BackPage = src.BackPage;
975
            CreatePageEvent = src.CreatePageEvent;
976
            StartOnOddPage = src.StartOnOddPage;
977
            StartPageEvent = src.StartPageEvent;
978
            FinishPageEvent = src.FinishPageEvent;
979
            ManualBuildEvent = src.ManualBuildEvent;
980
            UnlimitedHeight = src.UnlimitedHeight;
981
            PrintOnRollPaper = src.PrintOnRollPaper;
982
            UnlimitedWidth = src.UnlimitedWidth;
983
            UnlimitedHeightValue = src.UnlimitedHeightValue;
984
            UnlimitedWidthValue = src.UnlimitedWidthValue;
985
        }
986

987
        /// <inheritdoc/>
988
        public override void Serialize(FRWriter writer)
989
        {
990
            ReportPage c = writer.DiffObject as ReportPage;
991
            base.Serialize(writer);
992
            if (ExportAlias != c.ExportAlias)
993
                writer.WriteStr("ExportAlias", ExportAlias);
994
            if (Landscape != c.Landscape)
995
                writer.WriteBool("Landscape", Landscape);
996
            if (FloatDiff(PaperWidth, c.PaperWidth) || Landscape != c.Landscape)
997
                writer.WriteFloat("PaperWidth", PaperWidth);
998
            if (FloatDiff(PaperHeight, c.PaperHeight) || Landscape != c.Landscape)
999
                writer.WriteFloat("PaperHeight", PaperHeight);
1000
            if (RawPaperSize != c.RawPaperSize)
1001
                writer.WriteInt("RawPaperSize", RawPaperSize);
1002
            if (FloatDiff(LeftMargin, c.LeftMargin))
1003
                writer.WriteFloat("LeftMargin", LeftMargin);
1004
            if (FloatDiff(TopMargin, c.TopMargin))
1005
                writer.WriteFloat("TopMargin", TopMargin);
1006
            if (FloatDiff(RightMargin, c.RightMargin))
1007
                writer.WriteFloat("RightMargin", RightMargin);
1008
            if (FloatDiff(BottomMargin, c.BottomMargin))
1009
                writer.WriteFloat("BottomMargin", BottomMargin);
1010
            if (MirrorMargins != c.MirrorMargins)
1011
                writer.WriteBool("MirrorMargins", MirrorMargins);
1012
            Columns.Serialize(writer, c.Columns);
1013
            if (Guides.Count > 0)
1014
                writer.WriteValue("Guides", Guides);
1015
            Border.Serialize(writer, "Border", c.Border);
1016
            Fill.Serialize(writer, "Fill", c.Fill);
1017
            Watermark.Serialize(writer, "Watermark", c.Watermark);
1018
            if (TitleBeforeHeader != c.TitleBeforeHeader)
1019
                writer.WriteBool("TitleBeforeHeader", TitleBeforeHeader);
1020
            if (OutlineExpression != c.OutlineExpression)
1021
                writer.WriteStr("OutlineExpression", OutlineExpression);
1022
            if (PrintOnPreviousPage != c.PrintOnPreviousPage)
1023
                writer.WriteBool("PrintOnPreviousPage", PrintOnPreviousPage);
1024
            if (ResetPageNumber != c.ResetPageNumber)
1025
                writer.WriteBool("ResetPageNumber", ResetPageNumber);
1026
            if (ExtraDesignWidth != c.ExtraDesignWidth)
1027
                writer.WriteBool("ExtraDesignWidth", ExtraDesignWidth);
1028
            if (StartOnOddPage != c.StartOnOddPage)
1029
                writer.WriteBool("StartOnOddPage", StartOnOddPage);
1030
            if (BackPage != c.BackPage)
1031
                writer.WriteBool("BackPage", BackPage);
1032
            if (CreatePageEvent != c.CreatePageEvent)
1033
                writer.WriteStr("CreatePageEvent", CreatePageEvent);
1034
            if (StartPageEvent != c.StartPageEvent)
1035
                writer.WriteStr("StartPageEvent", StartPageEvent);
1036
            if (FinishPageEvent != c.FinishPageEvent)
1037
                writer.WriteStr("FinishPageEvent", FinishPageEvent);
1038
            if (ManualBuildEvent != c.ManualBuildEvent)
1039
                writer.WriteStr("ManualBuildEvent", ManualBuildEvent);
1040
            if (UnlimitedHeight != c.UnlimitedHeight)
1041
                writer.WriteBool("UnlimitedHeight", UnlimitedHeight);
1042
            if (PrintOnRollPaper != c.PrintOnRollPaper)
1043
                writer.WriteBool("PrintOnRollPaper", PrintOnRollPaper);
1044
            if (UnlimitedWidth != c.UnlimitedWidth)
1045
                writer.WriteBool("UnlimitedWidth", UnlimitedWidth);
1046
            if (FloatDiff(UnlimitedHeightValue, c.UnlimitedHeightValue))
1047
                writer.WriteFloat("UnlimitedHeightValue", UnlimitedHeightValue);
1048
            if (FloatDiff(UnlimitedWidthValue, c.UnlimitedWidthValue))
1049
                writer.WriteFloat("UnlimitedWidthValue", UnlimitedWidthValue);
1050
            if (FloatDiff(LastPageSource, c.LastPageSource))
1051
                writer.WriteFloat("LastPageSource", LastPageSource);
1052
            if (FloatDiff(FirstPageSource, c.FirstPageSource))
1053
                writer.WriteFloat("FirstPageSource", FirstPageSource);
1054
            if (FloatDiff(OtherPagesSource, c.OtherPagesSource))
1055
                writer.WriteFloat("OtherPageSource", OtherPagesSource);
1056
            if (Duplex.ToString() != c.Duplex.ToString())
1057
                writer.WriteStr("Duplex", Duplex.ToString());
1058
        }
1059

1060
        /// <inheritdoc/>
1061
        public override void Draw(FRPaintEventArgs e)
1062
        {
1063
            if (IsDesigning)
1064
                return;
1065

1066
            IGraphics g = e.Graphics;
1067
            RectangleF pageRect = new RectangleF(0, 0,
1068
              WidthInPixels - 1 / e.ScaleX, HeightInPixels - 1 / e.ScaleY);
1069
            RectangleF printableRect = new RectangleF(
1070
              LeftMargin * Units.Millimeters,
1071
              TopMargin * Units.Millimeters,
1072
              (PaperWidth - LeftMargin - RightMargin) * Units.Millimeters,
1073
              (PaperHeight - TopMargin - BottomMargin) * Units.Millimeters);
1074

1075
            // Fix System.OverflowException when drawing unlimited page without preparing.
1076
            if ((UnlimitedHeight || UnlimitedWidth) && !(IsRunning || IsPrinting))
1077
            {
1078
                pageRect = printableRect;
1079
            }
1080

1081
            DrawBackground(e, pageRect);
1082

1083
            if (UnlimitedHeight || UnlimitedWidth)
1084
            {
1085
                printableRect = new RectangleF(pageRect.Left + LeftMargin * Units.Millimeters,
1086
                    pageRect.Top + TopMargin * Units.Millimeters,
1087
                    pageRect.Width - (LeftMargin + RightMargin) * Units.Millimeters,
1088
                    pageRect.Height - (TopMargin + BottomMargin) * Units.Millimeters);
1089
            }
1090
            IGraphicsState state = g.Save();
1091
            e.Graphics.SetClip(new RectangleF(pageRect.X * e.ScaleX, pageRect.Y * e.ScaleY, pageRect.Width * e.ScaleX, pageRect.Height * e.ScaleY));
1092

1093
            Border.Draw(e, printableRect);
1094
            if (Watermark.Enabled)
1095
            {
1096
                if (!Watermark.ShowImageOnTop)
1097
                    Watermark.DrawImage(e, pageRect, Report, IsPrinting);
1098
                if (!Watermark.ShowTextOnTop)
1099
                    Watermark.DrawText(e, pageRect, Report, IsPrinting);
1100
            }
1101

1102
            float leftMargin = (int)Math.Round(LeftMargin * Units.Millimeters * e.ScaleX);
1103
            float topMargin = (int)Math.Round(TopMargin * Units.Millimeters * e.ScaleY);
1104
            g.TranslateTransform(leftMargin, topMargin);
1105

1106
            try
1107
            {
1108
                foreach (Base c in AllObjects)
1109
                {
1110
                    if (c is ReportComponentBase && c.HasFlag(Flags.CanDraw))
1111
                    {
1112
                        ReportComponentBase obj = c as ReportComponentBase;
1113
                        if (!IsPrinting)
1114
                        {
1115
#if !MONO || (WPF || AVALONIA)
1116
                            if (!obj.IsVisible(e))
1117
                                continue;
1118
#endif
1119
                        }
1120
                        else
1121
                        {
1122
                            if (!obj.Printable)
1123
                                continue;
1124
                            else if (obj.Parent is BandBase && !(obj.Parent as BandBase).Printable)
1125
                                continue;
1126
                        }
1127
                        obj.SetDesigning(false);
1128
                        obj.SetPrinting(IsPrinting);
1129
                        obj.Draw(e);
1130
                        obj.SetPrinting(false);
1131
                    }
1132
                }
1133
            }
1134
            finally
1135
            {
1136
                g.TranslateTransform(-leftMargin, -topMargin);
1137
            }
1138

1139
            if (Watermark.Enabled)
1140
            {
1141
                if (Watermark.ShowImageOnTop)
1142
                    Watermark.DrawImage(e, pageRect, Report, IsPrinting);
1143
                if (Watermark.ShowTextOnTop)
1144
                    Watermark.DrawText(e, pageRect, Report, IsPrinting);
1145
            }
1146
            g.Restore(state);
1147
        }
1148

1149
        internal void InitializeComponents()
1150
        {
1151
            ObjectCollection allObjects = AllObjects;
1152
            foreach (Base obj in allObjects)
1153
            {
1154
                if (obj is ReportComponentBase)
1155
                    (obj as ReportComponentBase).InitializeComponent();
1156
            }
1157
        }
1158

1159
        internal void FinalizeComponents()
1160
        {
1161
            ObjectCollection allObjects = AllObjects;
1162
            foreach (Base obj in allObjects)
1163
            {
1164
                if (obj is ReportComponentBase)
1165
                    (obj as ReportComponentBase).FinalizeComponent();
1166
            }
1167
        }
1168

1169
        /// <inheritdoc/>
1170
        public override string[] GetExpressions()
1171
        {
1172
            List<string> expressions = new List<string>();
1173

1174
            if (!String.IsNullOrEmpty(OutlineExpression))
1175
                expressions.Add(OutlineExpression);
1176

1177
            return expressions.ToArray();
1178
        }
1179

1180
        /// <inheritdoc/>
1181
        public override void ExtractMacros()
1182
        {
1183
            Watermark.Text = ExtractDefaultMacros(Watermark.Text);
1184
        }
1185

1186
        /// <summary>
1187
        /// This method fires the <b>CreatePage</b> event and the script code connected to the <b>CreatePageEvent</b>.
1188
        /// </summary>
1189
        public void OnCreatePage(EventArgs e)
1190
        {
1191
            if (CreatePage != null)
1192
                CreatePage(this, e);
1193
            InvokeEvent(CreatePageEvent, e);
1194
        }
1195

1196
        /// <summary>
1197
        /// This method fires the <b>StartPage</b> event and the script code connected to the <b>StartPageEvent</b>.
1198
        /// </summary>
1199
        public void OnStartPage(EventArgs e)
1200
        {
1201
            if (StartPage != null)
1202
                StartPage(this, e);
1203
            InvokeEvent(StartPageEvent, e);
1204
        }
1205

1206
        /// <summary>
1207
        /// This method fires the <b>FinishPage</b> event and the script code connected to the <b>FinishPageEvent</b>.
1208
        /// </summary>
1209
        public void OnFinishPage(EventArgs e)
1210
        {
1211
            if (FinishPage != null)
1212
                FinishPage(this, e);
1213
            InvokeEvent(FinishPageEvent, e);
1214
        }
1215

1216
        /// <summary>
1217
        /// This method fires the <b>ManualBuild</b> event and the script code connected to the <b>ManualBuildEvent</b>.
1218
        /// </summary>
1219
        public void OnManualBuild(EventArgs e)
1220
        {
1221
            if (ManualBuild != null)
1222
                ManualBuild(this, e);
1223
            InvokeEvent(ManualBuildEvent, e);
1224
        }
1225

1226
        /// <summary>
1227
        /// Updates width of all bands on this page according to page's paper settings.
1228
        /// </summary>
1229
        public void UpdateBandsWidth()
1230
        {
1231
            float pageWidth = (PaperWidth - LeftMargin - RightMargin) * Units.Millimeters;
1232
            float columnWidth = Columns.Width * Units.Millimeters;
1233

1234
            foreach (Base c in AllObjects)
1235
            {
1236
                BandBase b = c as BandBase;
1237
                if (b != null)
1238
                {
1239
                    if (Columns.Count > 1 && b.IsColumnDependentBand)
1240
                        b.Width = columnWidth;
1241
                    else
1242
                        b.Width = pageWidth;
1243
                }
1244
            }
1245
        }
1246
        #endregion
1247

1248
        /// <summary>
1249
        /// Initializes a new instance of the <see cref="ReportPage"/> class with default settings.
1250
        /// </summary>
1251
        public ReportPage()
1252
        {
1253
            paperWidth = 210;
1254
            paperHeight = 297;
1255
            leftMargin = 10;
1256
            topMargin = 10;
1257
            rightMargin = 10;
1258
            bottomMargin = 10;
1259
            InitPreview();
1260
            bands = new BandCollection(this);
1261
            guides = new FloatCollection();
1262
            columns = new PageColumns(this);
1263
            border = new Border();
1264
            fill = new SolidFill(Color.White);
1265
            watermark = new Watermark();
1266
            titleBeforeHeader = true;
1267
            startPageEvent = "";
1268
            finishPageEvent = "";
1269
            manualBuildEvent = "";
1270
            BaseName = "Page";
1271
            unlimitedHeight = false;
1272
            printOnRollPaper = false;
1273
            unlimitedWidth = false;
1274
            unlimitedHeightValue = MAX_PAPER_SIZE_MM * Units.Millimeters;
1275
            unlimitedWidthValue = MAX_PAPER_SIZE_MM * Units.Millimeters;
1276
        }
1277
    }
1278
}

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.