-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClass_Cell.cs
420 lines (328 loc) · 11.6 KB
/
Class_Cell.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
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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
using System.Drawing.Printing;
using System.Windows.Forms;
// Author: Fabrice GARCIA (20290 BORGO, Haute-Corse, France. November 1, 2021)
// You are free to include this code in your programs.
// It is provided to you freely and free of charge without any liability on my part.
// I only ask you to respect my copyright by keeping my name
// You can also send me a thank you email to fab2bprog@outlook.fr that will make me happy.
namespace CellPrintReport
{
public abstract class CommonCell
{
public float XCoord;
public float YCoord;
public float Height;
public float Width;
public float Zone_YCoord = 0;
public float Zone_Height = 0;
public float MarginTop = 0;
public float MarginRight = 0;
public float MarginLeft = 0;
public float MarginBottom = 0;
private float BorderTop = 1;
private float BorderRight = 1;
private float BorderLeft = 1;
private float BorderBottom = 1;
public float PaddingTop = 0;
public float PaddingRight = 0;
public float PaddingLeft = 0;
public float PaddingBottom = 0;
/// <summary>
/// Police et taille de la police du texte :
/// </summary>
public Font CtArea_FontCell = new Font("Courier New", 8);
/// <summary>
/// Couleur de la police du texte :
/// </summary>
public Brush CtArea_Brush = Brushes.Black;
/// <summary>
/// Crayon utilisé pour dessiner la bordure de la cellule.
/// </summary>
public Pen Border_LinePen= new Pen(Color.Black, 0.2F);
public PrintPageEventArgs pg;
//-----------------------------------------------------
public bool Border_LineTop
{
get
{
if (this.BorderTop > 1) { return true; } else { return false; };
}
set
{
if (value == true) { this.BorderTop = 1; } else { this.BorderTop = 0; }
}
}
public bool Border_LineRight
{
get
{
if (this.BorderRight > 1) { return true; } else { return false; };
}
set
{
if (value == true) { this.BorderRight = 1; } else { this.BorderRight = 0; }
}
}
public bool Border_LineLeft
{
get
{
if (this.BorderLeft > 1) { return true; } else { return false; };
}
set
{
if (value == true) { this.BorderLeft = 1; } else { this.BorderLeft= 0; }
}
}
public bool Border_LineBottom
{
get
{
if (this.BorderBottom > 1) { return true; } else { return false; };
}
set
{
if (value == true) { this.BorderBottom = 1; } else { this.BorderBottom= 0; }
}
}
public float Margin_LeftX()
{
return XCoord;
}
public float Margin_RightX()
{
float result = XCoord + Margin_Width();
return result;
}
public float Margin_TopY()
{
return YCoord + Zone_YCoord;
}
public float Margin_BottomY()
{
float result = YCoord + Zone_YCoord + Margin_Height();
return result;
}
public float Margin_Width()
{
return Width;
}
public float Margin_Height()
{
return Height;
}
//-----------------------------------------------------
//-----------------------------------------------------
public float Border_LeftX()
{
float result = XCoord + MarginLeft;
return result;
}
public float Border_RightX()
{
float result = Border_LeftX() + Border_Width();
return result;
}
public float Border_TopY()
{
float result = YCoord + Zone_YCoord + MarginTop;
return result;
}
public float Border_BottomY()
{
float result = Border_TopY() + Border_Height();
return result;
}
public float Border_Width()
{
float result = Width - MarginLeft - MarginRight;
return result;
}
public float Border_Height()
{
float result = Height - MarginTop - MarginBottom;
return result;
}
//-----------------------------------------------------
//-----------------------------------------------------
public float Padding_LeftX()
{
float result = XCoord + MarginLeft + BorderLeft;
return result;
}
public float Padding_RightX()
{
float result = Border_LeftX() + Padding_Width();
return result;
}
public float Padding_TopY()
{
float result = YCoord + Zone_YCoord + MarginTop + BorderTop;
return result;
}
public float Padding_BottomY()
{
float result = Border_TopY() + Padding_Height();
return result;
}
public float Padding_Width()
{
float result = Width - (MarginLeft + BorderLeft) - (MarginRight + BorderRight);
return result;
}
public float Padding_Height()
{
float result = Height - (MarginTop + BorderTop) - (MarginBottom + BorderBottom);
return result;
}
//-----------------------------------------------------
public float CtArea_LeftX()
{
float result = XCoord + MarginLeft + BorderLeft + PaddingLeft;
return result;
}
public float CtArea_RightX()
{
float result = CtArea_LeftX() + CtArea_Width();
return result;
}
public float CtArea_TopY()
{
float result = YCoord + Zone_YCoord + MarginTop + BorderTop + PaddingTop;
return result;
}
public float CtArea_BottomY()
{
float result = CtArea_TopY() + CtArea_Height();
return result;
}
public float CtArea_Width()
{
float result = Width - (MarginLeft + BorderLeft + PaddingLeft) - (MarginRight + BorderRight + PaddingRight);
return result;
}
public float CtArea_Height()
{
float result = Height - (MarginTop + BorderTop + PaddingTop) - (MarginBottom + BorderBottom + PaddingBottom);
return result;
}
public bool Draw_Border()
{
if (BorderTop > 0) { pg.Graphics.DrawLine(Border_LinePen, Border_LeftX(), Border_TopY(), Border_RightX(), Border_TopY()); };
if (BorderRight > 0) { pg.Graphics.DrawLine(Border_LinePen, Border_RightX(), Border_TopY(), Border_RightX(), Border_BottomY()); };
if (BorderLeft > 0) { pg.Graphics.DrawLine(Border_LinePen, Border_LeftX(), Border_TopY(), Border_LeftX(), Border_BottomY()); };
if (BorderBottom > 0) { pg.Graphics.DrawLine(Border_LinePen, Border_LeftX(), Border_BottomY(), Border_RightX(), Border_BottomY()); };
return true;
}
}
public class TextCell : CommonCell
{
/// <summary>
/// Defini l'alignement horizontal du texte :
/// left = 0, center = 1, right = 2
/// </summary>
public int CtArea_HorizAlign = 0; // left = 0, center = 1, right = 2
/// <summary>
/// Defini l'alignement vertical du texte :
/// Top = 0, center = 1, Bottom = 2
/// </summary>
public int CtArea_VertiAlign = 0; // top = 0 , center = 1, bottom = 2
public string CtArea_Data = string.Empty;
public bool Draw_Cell()
{
Draw_Border();
Draw_CtArea_Data(CtArea_Data, CtArea_LeftX(), CtArea_TopY());
return true;
}
private bool Draw_CtArea_Data(string txt, float x, float y)
{
SizeF sf_string = pg.Graphics.MeasureString(txt, CtArea_FontCell);
float CxLayout=0;
float CyLayout=0;
// Alignement horizontal a gauche du texte
if (CtArea_HorizAlign == 0)
{
CxLayout = x;
}
// Alignement vertical en haut
if (CtArea_VertiAlign == 0)
{
CyLayout = y;
}
// Alignement horizontal au centre du texte
if (CtArea_HorizAlign==1) {
CxLayout = x + ((CtArea_Width() / 2) - (sf_string.Width / 2));
}
// Alignement vertical au centre du texte
if (CtArea_VertiAlign == 1)
{
CyLayout = y + ((CtArea_Height() / 2) - (sf_string.Height / 2));
}
// Alignement horizontal a droite du texte
if (CtArea_HorizAlign == 2)
{
CxLayout = x + (CtArea_Width() - sf_string.Width);
}
// Alignement vertical en bas de la cellule
if (CtArea_VertiAlign == 2)
{
CyLayout = y + (CtArea_Height() - sf_string.Height);
}
pg.Graphics.DrawString(txt, CtArea_FontCell, CtArea_Brush, CxLayout, CyLayout);
return true;
}
}
public class NumericCell : CommonCell
{
public int DecimalNum;
public float CtArea_Data = 0;
public bool Draw_Cell()
{
Draw_Border();
Draw_CtArea_Data(CtArea_Data, CtArea_RightX(), CtArea_TopY());
return true;
}
private bool Draw_CtArea_Data(float number, float x, float y)
{
string cdecim = String.Empty;
string txt = number.ToString();
for (int i = 0; i < DecimalNum; i++)
{
cdecim = cdecim + "0";
}
SizeF sf_decim = pg.Graphics.MeasureString(cdecim, CtArea_FontCell);
SizeF sf_string = pg.Graphics.MeasureString(txt, CtArea_FontCell);
float.TryParse(txt, out float result);
SizeF sf_IntPart = pg.Graphics.MeasureString(Math.Truncate(result).ToString(), CtArea_FontCell);
pg.Graphics.DrawString(txt, CtArea_FontCell, CtArea_Brush, x - sf_IntPart.Width - sf_decim.Width, y);
return true;
}
}
public class MoneyCell : CommonCell
{
public decimal CtArea_Data = 0;
public bool Draw_Cell()
{
Draw_Border();
Draw_CtArea_Data(CtArea_Data, CtArea_RightX(), CtArea_TopY());
return true;
}
private bool Draw_CtArea_Data(decimal number, float x, float y)
{
string txt = number.ToString("C");
string textIntPart = Math.Truncate(number).ToString("N");
textIntPart = textIntPart.Substring(0, textIntPart.Length - 3);
SizeF sf_decim = pg.Graphics.MeasureString("00 €", CtArea_FontCell);
SizeF sf_txt = pg.Graphics.MeasureString(txt, CtArea_FontCell);
SizeF sf_textIntPart = pg.Graphics.MeasureString(textIntPart, CtArea_FontCell);
pg.Graphics.DrawString(txt, CtArea_FontCell, CtArea_Brush, x - sf_textIntPart.Width - sf_decim.Width, y);
return true;
}
}
}