-
Notifications
You must be signed in to change notification settings - Fork 0
/
Form1.cs
139 lines (108 loc) · 4.67 KB
/
Form1.cs
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
using System;
using System.Drawing;
using System.Drawing.Printing;
using System.Windows.Forms;
using DevExpress.XtraPrinting;
// ...
namespace docDynamicFooterSummaries {
public partial class Form1 : Form {
private PrintingSystem ps = new PrintingSystem();
private string[] Operation = new string[] { "Count", "Sum" };
private Brick[] sbriks = new Brick[2];
public Form1() {
InitializeComponent();
ps.BeforePagePaint += new PagePaintEventHandler(PagePainting);
}
private void PagePainting(object sender, PagePaintEventArgs e) {
double sum = 0, v;
int count = 0;
// Perform actions for all bricks on the current page.
foreach (TextBrick brick in e.Page) {
if (brick != null) {
double d;
if (!(brick.TextValue is string) || !double.TryParse((string)brick.TextValue, out d))
continue;
v = Convert.ToDouble(brick.TextValue);
// Check the brick identification and perform calculations accordingly.
switch (brick.ID) {
case "Count":
count++;
break;
case "Sum":
sum += v;
break;
}
}
}
// Assign the resulting values to the bricks,
// which represent totals in the page footer.
((TextBrick)sbriks[0]).Text = String.Format("{0:0.##}", count);
((TextBrick)sbriks[1]).Text = String.Format("{0:0.##}", sum);
}
private void button1_Click(object sender, EventArgs e) {
CreateDocument();
ps.PageSettings.Assign(new Margins(15, 15, 15, 35),
PaperKind.Custom, new Size(200, 500), true);
}
private void CreateDocument() {
Cursor currentCursor = Cursor.Current;
Cursor.Current = Cursors.WaitCursor;
CreateTableOfValues();
ps.PreviewFormEx.Show();
Cursor.Current = currentCursor;
}
private void CreateTableOfValues() {
BrickGraphics gr = ps.Graph;
ps.Begin();
double sum = 0;
int count = 0;
int h = 20;
int X = Convert.ToInt32(Math.Floor(gr.ClientPageSize.Width / 5));
gr.StringFormat = new BrickStringFormat(StringAlignment.Center,
StringAlignment.Center);
// Display column headers.
gr.Modifier = BrickModifier.DetailHeader;
for (int i = 0; i < 2; i++) {
gr.DrawString(Operation[i], Color.Black,
new RectangleF(i * X, 0, X, h), BorderSide.All);
}
// Display random values.
gr.Modifier = BrickModifier.Detail;
gr.BackColor = SystemColors.Window;
gr.Font = new Font("Arial", 8);
double v;
Random rand = new Random();
for (int j = 0; j < 10; j++) {
v = rand.NextDouble() * 100;
for (int i = 0; i < 2; i++) {
TextBrick brick = gr.DrawString(String.Format("{0:0.##}", v), Color.Black,
new RectangleF(i * X, j * h, X, h), BorderSide.All);
// Assign the column identificator.
brick.ID = Operation[i];
// Assign the value used for subsequent calculations.
brick.TextValue = v.ToString();
}
count++;
sum += v;
}
// Display the count and sum values in the ReportFooter section
// (at the end of the report).
gr.Modifier = BrickModifier.ReportFooter;
gr.BackColor = SystemColors.ControlDark;
gr.Font = new Font("Arial", 10, FontStyle.Bold);
h = gr.Font.Height;
gr.DrawString(String.Format("{0:0.##}", count), Color.White,
new RectangleF(0, 0, X, h), BorderSide.All);
gr.DrawString(String.Format("{0:0.##}", sum), Color.White,
new RectangleF(X, 0, X, h), BorderSide.All);
// Display summaries for the current page items.
gr.Modifier = BrickModifier.MarginalFooter;
gr.StringFormat = gr.StringFormat.ChangeAlignment(StringAlignment.Far);
for (int i = 0; i < 2; i++) {
sbriks[i] = gr.DrawString("", Color.Black,
new RectangleF(i * X, 0, X, h), BorderSide.All);
}
ps.End();
}
}
}