source: Scheduling/trunk/cs/bsdx0200GUISourceCode/Printing.cs@ 1125

Last change on this file since 1125 was 1125, checked in by Sam Habiel, 14 years ago

CGView: Appointment Object now has Patient subobject created for routing slip information.
DPatientLookup: Now returns DOB as well.
Routing Slip doesn't print Sex anymore.
Updated Release Exes.

File size: 31.9 KB
Line 
1using System;
2using System.Drawing.Printing;
3using System.Drawing;
4using System.Text;
5using System.Drawing.Drawing2D;
6using System.Linq;
7using System.Data;
8
9namespace IndianHealthService.ClinicalScheduling
10{
11 public partial class Printing
12 {
13 /// <summary>
14 /// Print Appointments
15 /// </summary>
16 /// <param name="ds">Strongly Typed DataSet contains Resources and Appointments</param>
17 /// <param name="e">PrintPageEventArgs from PrintDocument Print handler</param>
18 /// <param name="beg">Begin Datetime to print appointments</param>
19 /// <param name="end">End Datetime to print appointments</param
20 /// <param name="resourceToPrint">The resouce to print</param>
21 /// <param name="apptPrinting">Current Appointment printing</param>
22 /// <param name="pageNumber">Current page number</param>
23 /// <remarks>beg and end have no effect on operation--they are there for documentation for user only</remarks>
24 public virtual void PrintAppointments(dsPatientApptDisplay2 ds, PrintPageEventArgs e, DateTime beg, DateTime end, int resourceToPrint, ref int apptPrinting, int pageNumber)
25 {
26 Graphics g = e.Graphics;
27 //g.PageUnit = GraphicsUnit.Millimeter;
28 //SizeF szVCB = g.VisibleClipBounds.Size;
29 //PointF[] ptszVCB = {new PointF(szVCB.Width,szVCB.Height)};
30 //g.TransformPoints(CoordinateSpace.Page, CoordinateSpace.Device, ptszVCB);
31 //Create Fonts
32 Font f8 = new Font(FontFamily.GenericSerif, 8);
33 Font f10 = new Font(FontFamily.GenericSerif, 10);
34 Font f14bold = new Font(FontFamily.GenericSerif, 14, FontStyle.Bold);
35
36 //Center Alignment for some stuff
37 StringFormat sf = new StringFormat();
38 sf.Alignment = StringAlignment.Center;
39
40 //Header
41 g.DrawString("Confidential Patient Information", f8, Brushes.Black, e.PageBounds, sf);
42
43 //Footer
44 sf.Alignment = StringAlignment.Center;
45 sf.LineAlignment = StringAlignment.Far;
46 g.DrawString("Page " + pageNumber, f8, Brushes.Black, e.PageBounds, sf);
47
48 //Typical manipulable print area
49 Rectangle printArea = e.MarginBounds;
50 Rectangle pageArea = e.PageBounds;
51 Rectangle headerArea = new Rectangle()
52 {
53 X = e.MarginBounds.X,
54 Y = e.PageBounds.Y,
55 Height = e.MarginBounds.Y - e.PageBounds.Y,
56 Width = e.MarginBounds.Width
57 };
58 Rectangle footerArea = new Rectangle()
59 {
60 X = e.MarginBounds.X,
61 Y = e.MarginBounds.Height + headerArea.Height,
62 Width = e.MarginBounds.Width,
63 Height = pageArea.Height - (e.MarginBounds.Height + headerArea.Height)
64 };
65
66 //print footer
67 StringFormat sfFooter = new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center };
68 string s = strings.Printed + ": " + DateTime.Now.ToString();
69 Font fFooter = new Font(FontFamily.GenericSerif, 7);
70 g.DrawString(s, fFooter, Brushes.Black, footerArea, sfFooter);
71
72 //resource we want to print
73 dsPatientApptDisplay2.BSDXResourceRow r = ds.BSDXResource[resourceToPrint];
74
75 //header
76 string toprint;
77 if (beg.Date == end.Date) toprint = "Appointments for " + r.RESOURCE_NAME + " on " + beg.ToLongDateString();
78 else toprint = "Appointments for " + r.RESOURCE_NAME + " from " + beg.ToShortDateString() + " to "
79 + end.ToShortDateString();
80 g.DrawString(toprint, f14bold, Brushes.Black, printArea);
81
82 //Move print area down
83 int titleHeight = (int)g.MeasureString(toprint, f14bold, printArea.Size).Height;
84 printArea.Height -= titleHeight;
85 printArea.Y += titleHeight;
86
87 //Draw Line
88 g.DrawLine(new Pen(Brushes.Black, 0), printArea.X, printArea.Y, printArea.X + printArea.Width, printArea.Y);
89
90 //Move print area down
91 printArea.Y += 5;
92 printArea.Height -= 5;
93
94 System.Data.DataRow[] appts = r.GetChildRows(ds.Relations[0]); //ds has only one relation
95
96 StringFormat sf2 = new StringFormat(); //sf to hold tab stops
97 sf2.SetTabStops(50, new float[] { 100, 250, 25 });
98
99 //appt printed starts at zero
100 while (apptPrinting < appts.Length)
101 {
102 dsPatientApptDisplay2.PatientApptsRow a = (dsPatientApptDisplay2.PatientApptsRow)appts[apptPrinting];
103
104 StringBuilder apptPrintStr = new StringBuilder(200);
105 apptPrintStr.AppendLine(a.ApptDate.ToString() + "\t" + a.Name + " (" + a.Sex + ")" + "\t" + "DOB: " + a.DOB.ToShortDateString() + "\t" + "ID: " + a.HRN);
106 apptPrintStr.AppendLine("P: " + a.HOMEPHONE + "\t" + "Address: " + a.STREET + ", " + a.CITY + ", " + a.STATE + " " + a.ZIP);
107 apptPrintStr.AppendLine("Note: " + a.NOTE);
108 apptPrintStr.AppendLine("Appointment made by " + a.APPT_MADE_BY + " on " + a.DATE_APPT_MADE);
109
110 int printedApptHeight = (int)g.MeasureString(apptPrintStr.ToString(), f10, printArea.Width).Height;
111 if (printedApptHeight > printArea.Height) // too much to print -- move to next page
112 // but don't increment the appointment to print since we haven't printed it yet.
113 // i.e. apptPrinting stays the same.
114 {
115 e.HasMorePages = true;
116 break;
117 }
118
119 //otherwise print it
120 g.DrawString(apptPrintStr.ToString(), f10, Brushes.Black, printArea, sf2);
121
122 //Move print area down
123 printArea.Y += printedApptHeight + 3;
124 printArea.Height -= printedApptHeight + 3;
125
126 //Draw a divider line
127 Point pt1 = new Point((int)(printArea.X + printArea.Width * 0.25), printArea.Y);
128 Point pt2 = new Point((int)(printArea.X + printArea.Width * 0.75), printArea.Y);
129 g.DrawLine(Pens.Gray, pt1, pt2);
130
131 //move down, again
132 printArea.Y += 3;
133 printArea.Height -= 3;
134
135 //go to the next appointment
136 apptPrinting++;
137 }
138 }
139
140 /// <summary>
141 /// Prints a single appointment slip to give to the patient
142 /// </summary>
143 /// <param name="appt">The Appointment to print</param>
144 /// <param name="e">PrintPageEventArgs from PrintDocument Print handler</param>
145 public virtual void PrintAppointmentSlip(CGAppointment appt, PrintPageEventArgs e)
146 {
147 // Prep
148 Graphics g = e.Graphics;
149 Rectangle printArea = e.MarginBounds;
150 Rectangle pageArea = e.PageBounds;
151 Rectangle headerArea = new Rectangle()
152 {
153 X = e.MarginBounds.X,
154 Y = e.PageBounds.Y,
155 Height = e.MarginBounds.Y - e.PageBounds.Y,
156 Width = e.MarginBounds.Width
157 };
158 Rectangle footerArea = new Rectangle()
159 {
160 X = e.MarginBounds.X,
161 Y = e.MarginBounds.Height + headerArea.Height,
162 Width = e.MarginBounds.Width,
163 Height = pageArea.Height - (e.MarginBounds.Height + headerArea.Height)
164 };
165
166
167 // A few fonts
168 Font fTitle = new Font(FontFamily.GenericSerif, 24, FontStyle.Bold); //for title
169 Font fBody = new Font(FontFamily.GenericSerif, 12);
170 Font fGroupTitle = new Font(FontFamily.GenericSansSerif, 10, FontStyle.Bold);
171
172 StringFormat sf0 = new StringFormat()
173 {
174 Alignment = StringAlignment.Center,
175 LineAlignment = StringAlignment.Center
176 };
177
178 // Draw Header
179 string division = CGDocumentManager.Current.ConnectInfo.DivisionName;
180 g.DrawString(division, fBody, Brushes.Black, headerArea, sf0);
181
182 // Draw Title
183 StringFormat sf = new StringFormat();
184 sf.Alignment = StringAlignment.Center; //for title & header
185
186 //string s = "Appointment Reminder Slip";
187 string s = strings.ApptRoutingSlip;
188 g.DrawString(s, fTitle, Brushes.Black, printArea, sf); //title
189
190 // move down
191 int titleHeight = (int)g.MeasureString(s, fTitle, printArea.Width).Height;
192 printArea.Y += titleHeight;
193 printArea.Height -= titleHeight;
194
195 // draw underline
196 g.DrawLine(Pens.Black, printArea.Location, new Point(printArea.Right, printArea.Y));
197 printArea.Y += 15;
198 printArea.Height -= 15;
199
200 // draw curved rectangle.
201 Rectangle personalInfoRectangle = new Rectangle(e.MarginBounds.X, printArea.Y + 30, 280, 300);
202 using (GraphicsPath path = GetRoundedRectPath(personalInfoRectangle, 10))
203 {
204 g.DrawPath(Pens.Black, path);
205 }
206
207 // group header
208 s = strings.PtInfo;
209 StringFormat sf3 = new StringFormat(System.Threading.Thread.CurrentThread.CurrentUICulture.TextInfo.IsRightToLeft ? StringFormatFlags.DirectionRightToLeft : 0);
210 g.DrawString(s, fGroupTitle, Brushes.Black, new Rectangle(personalInfoRectangle.X, personalInfoRectangle.Y - 20,personalInfoRectangle.Width, 20),sf3);
211
212 // inner rectangle for drawing strings:
213 Rectangle personalInfoInnerRectangle = new Rectangle(personalInfoRectangle.X + 20, personalInfoRectangle.Y + 20, 280 - 40, 300 - 40);
214
215 // Strings to write
216 StringBuilder sb = new StringBuilder(500);
217 sb.AppendLine(strings.Name + ":" + "\t" + appt.Patient.Name);
218 sb.AppendLine();
219 sb.AppendLine(strings.ID + ":" + "\t" + appt.Patient.ID);
220 sb.AppendLine();
221 sb.AppendLine(strings.DOB + ":" + "\t" + appt.Patient.DOB.ToShortDateString());
222 sb.AppendLine();
223 sb.AppendLine(strings.Age + ":" + "\t" + appt.Patient.UserFriendlyAge);
224 sb.AppendLine();
225 s = appt.Patient.Sex == Sex.Male ? strings.Male : strings.Female;
226 sb.AppendLine(strings.Sex + ":" + "\t" + s);
227
228 // Draw them
229 sf3 = new StringFormat(System.Threading.Thread.CurrentThread.CurrentUICulture.TextInfo.IsRightToLeft ? StringFormatFlags.DirectionRightToLeft : 0);
230 sf3.SetTabStops(0, new float[] {75} );
231 sf3.SetDigitSubstitution(System.Threading.Thread.CurrentThread.CurrentUICulture.LCID, StringDigitSubstitute.Traditional);
232 g.DrawString(sb.ToString(), fBody, Brushes.Black, personalInfoInnerRectangle, sf3);
233
234 // draw curved rectangle
235 Rectangle apptInfoRectangle = new Rectangle(e.MarginBounds.X + e.MarginBounds.Width - 280, printArea.Y + 30, 280, 300);
236 using (GraphicsPath path = GetRoundedRectPath(apptInfoRectangle, 10))
237 {
238 g.DrawPath(Pens.Black, path);
239 }
240
241 s = strings.ApptInfo;
242 // group header
243 g.DrawString(s, fGroupTitle, Brushes.Black, new Rectangle(apptInfoRectangle.X, apptInfoRectangle.Y - 20,apptInfoRectangle.Width, 20), sf3);
244
245 // Strings to write
246 sb = new StringBuilder();
247 sb.AppendLine(strings.Clinic + ":" + "\t" + appt.Resource);
248 sb.AppendLine();
249 sb.AppendLine(strings.Date + ":" + "\t" + appt.StartTime.ToShortDateString());
250 sb.AppendLine();
251 sb.AppendLine(strings.Day + ":" + "\t" + appt.StartTime.ToString("dddd"));
252 sb.AppendLine();
253 sb.AppendLine(strings.Time + ":" + "\t" + appt.StartTime.ToShortTimeString());
254
255 // Draw them
256 Rectangle apptInfoInnerRectangle = new Rectangle(apptInfoRectangle.X + 20, apptInfoRectangle.Y + 20, 280 - 40, 300 - 40);
257
258 // Draw them
259 g.DrawString(sb.ToString(), fBody, Brushes.Black, apptInfoInnerRectangle, sf3);
260
261 // Move Drawing Rectangle Down
262 printArea.Y += 300 + 30 + 20;
263 printArea.Height -= 300 + 30 + 20;
264
265 // Draw New Line
266 g.DrawLine(Pens.Black, printArea.Location, new Point(printArea.Right, printArea.Y));
267 printArea.Y += 5;
268 printArea.Height -= 5;
269
270 // Draw new Title
271 s = strings.ClinicInstructions;
272 g.DrawString(s, fTitle, Brushes.Black, printArea, sf); //title
273
274 // move down
275 titleHeight = (int)g.MeasureString(s, fTitle, printArea.Width).Height;
276 printArea.Y += titleHeight;
277 printArea.Height -= titleHeight;
278
279 // Draw New Line
280 g.DrawLine(Pens.Black, printArea.Location, new Point(printArea.Right, printArea.Y));
281 printArea.Y += 15;
282 printArea.Height -= 15;
283
284 // Get Resource Clinic Appointment Letter Text
285 DataTable resources = CGDocumentManager.Current.GlobalDataSet.Tables["Resources"];
286
287 string ltrTxt = (from resource in resources.AsEnumerable()
288 where resource.Field<string>("RESOURCE_NAME") == appt.Resource
289 select resource.Field<string>("LETTER_TEXT")).SingleOrDefault<string>();
290
291 if (String.IsNullOrWhiteSpace(ltrTxt)) ltrTxt = strings.NoInstructionsProvided;
292
293 g.DrawString(ltrTxt, fBody, Brushes.Black, printArea, sf3);
294
295 int ltrTxtHeight = (int)g.MeasureString(ltrTxt, fBody).Height;
296
297 printArea.Y += ltrTxtHeight + 15;
298 printArea.Height -= ltrTxtHeight + 15;
299
300 g.DrawLine(Pens.Black, printArea.Location, new Point(printArea.Right, printArea.Y));
301 printArea.Y += 5;
302 printArea.Height -= 5;
303
304 s = strings.Notes;
305 g.DrawString(s, fTitle, Brushes.Black, printArea, sf); // Notes title
306
307 // move down
308 titleHeight = (int)g.MeasureString(s, fTitle, printArea.Width).Height;
309 printArea.Y += titleHeight;
310 printArea.Height -= titleHeight;
311
312 // Draw New Line
313 g.DrawLine(Pens.Black, printArea.Location, new Point(printArea.Right, printArea.Y));
314 printArea.Y += 15;
315 printArea.Height -= 15;
316
317 // Draw Notes Area
318 using (GraphicsPath path = GetRoundedRectPath(printArea, 15))
319 {
320 g.DrawPath(Pens.Black, path);
321 }
322
323 //use sf0 to print the footer (center all the way)
324 s = strings.Printed + ": " + DateTime.Now.ToString();
325 Font fFooter = new Font(FontFamily.GenericSerif, 7);
326 g.DrawString(s, fFooter, Brushes.Black, footerArea, sf0);
327
328 }
329
330
331 private GraphicsPath GetRoundedRectPath(Rectangle rect, int radius)
332 {
333 int diameter = 2 * radius;
334
335 Rectangle arcRect = new Rectangle(rect.Location, new Size(diameter, diameter));
336 GraphicsPath path = new GraphicsPath();
337
338 path.AddArc(arcRect, 180, 90); //top left
339 arcRect.X = rect.Right - diameter;
340 path.AddArc(arcRect, 270, 90); // top right
341 arcRect.Y = rect.Bottom - diameter;
342 path.AddArc(arcRect, 0, 90); // bottom right
343 arcRect.X = rect.Left;
344 path.AddArc(arcRect, 90, 90); // bottom left
345
346 path.CloseFigure();
347
348 return path;
349 }
350
351 /// <summary>
352 /// Print Letter to be given or mailed to the patient
353 /// </summary>
354 /// <param name="ptrow">Strongly typed PatientApptsRow to pass (just one ApptRow)</param>
355 /// <param name="e">You know what that is</param>
356 /// <param name="letter">Contains letter string</param>
357 /// <param name="title">Title of the letter</param>
358 public virtual void PrintReminderLetter(dsPatientApptDisplay2.PatientApptsRow ptRow, PrintPageEventArgs e, string letter, string title)
359 {
360
361 Rectangle printArea = e.MarginBounds;
362 Graphics g = e.Graphics;
363 StringFormat sf = new StringFormat();
364 sf.Alignment = StringAlignment.Center; //for title
365 Font fTitle = new Font(FontFamily.GenericSerif, 24, FontStyle.Bold); //for title
366 Font fBody = new Font(FontFamily.GenericSerif, 12);
367 g.DrawString(title, fTitle, Brushes.Black, printArea, sf); //title
368
369 // move down
370 int titleHeight = (int)g.MeasureString(title, fTitle, printArea.Width).Height;
371 printArea.Y += titleHeight;
372 printArea.Height -= titleHeight;
373
374 // draw underline
375 g.DrawLine(Pens.Black, printArea.Location, new Point(printArea.Right, printArea.Y));
376 printArea.Y += 15;
377 printArea.Height -= 15;
378
379 // write appointment date
380 string str = "Appointment Date: " + ptRow.ApptDate + "\n\n";
381 g.DrawString(str, fBody, Brushes.Black, printArea);
382
383 // move down
384 int strHeight = (int)g.MeasureString(str, fBody, printArea.Width).Height;
385 printArea.Y += strHeight;
386 printArea.Height -= strHeight;
387
388 //Text Direction
389 StringFormat sf2 = new StringFormat();
390 if (System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.IsRightToLeft)
391 sf2.FormatFlags = StringFormatFlags.DirectionRightToLeft;
392
393 // write missive
394 g.DrawString(letter, fBody, Brushes.Black, printArea, sf2);
395
396 //print Address in lower left corner for windowed envolopes
397 printArea.Location = new Point(e.MarginBounds.X, (int)(e.PageBounds.Height * 0.66));
398 printArea.Height = (int)(e.MarginBounds.Height * 0.20);
399 sf.Alignment = StringAlignment.Near;
400 sf.LineAlignment = StringAlignment.Center;
401 StringBuilder address = new StringBuilder(100);
402 address.AppendLine(ptRow.Name);
403 address.AppendLine(ptRow.STREET);
404 address.AppendLine(ptRow.CITY + ", " + ptRow.STATE + " " + ptRow.ZIP);
405 g.DrawString(address.ToString(), fBody, Brushes.Black, printArea, sf);
406 }
407
408 /// <summary>
409 /// Cancellation Letter to be given or mailed to the patient
410 /// </summary>
411 /// <param name="ptRow">Strongly typed PatientApptsRow to pass (just one ApptRow)</param>
412 /// <param name="e">You know what that is</param>
413 /// <param name="letter">Contains letter string</param>
414 /// <param name="title">Title of the letter</param>
415 public virtual void PrintCancelLetter(dsRebookAppts.PatientApptsRow ptRow, PrintPageEventArgs e, string letter, string title)
416 {
417 Rectangle printArea = e.MarginBounds;
418 Graphics g = e.Graphics;
419 StringFormat sf = new StringFormat();
420 sf.Alignment = StringAlignment.Center; //for title
421 Font fTitle = new Font(FontFamily.GenericSerif, 24, FontStyle.Bold); //for title
422 Font fBody = new Font(FontFamily.GenericSerif, 12);
423 g.DrawString(title, fTitle, Brushes.Black, printArea, sf); //title
424
425 // move down
426 int titleHeight = (int)g.MeasureString(title, fTitle, printArea.Width).Height;
427 printArea.Y += titleHeight;
428 printArea.Height -= titleHeight;
429
430 // draw underline
431 g.DrawLine(Pens.Black, printArea.Location, new Point(printArea.Right, printArea.Y));
432 printArea.Y += 15;
433 printArea.Height -= 15;
434
435 // write appointment date
436 string str = "Appointment Date: " + ptRow.OldApptDate + "\n\n";
437 g.DrawString(str, fBody, Brushes.Black, printArea);
438
439 // move down
440 int strHeight = (int)g.MeasureString(str, fBody, printArea.Width).Height;
441 printArea.Y += strHeight;
442 printArea.Height -= strHeight;
443
444 //Text Direction
445 StringFormat sf2 = new StringFormat();
446 if (System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.IsRightToLeft)
447 sf2.FormatFlags = StringFormatFlags.DirectionRightToLeft;
448
449 // write missive
450 g.DrawString(letter, fBody, Brushes.Black, printArea, sf2);
451
452 //print Address in lower left corner for windowed envolopes
453 printArea.Location = new Point(e.MarginBounds.X, (int)(e.PageBounds.Height * 0.66));
454 printArea.Height = (int)(e.MarginBounds.Height * 0.20);
455 sf.Alignment = StringAlignment.Near;
456 sf.LineAlignment = StringAlignment.Center;
457 StringBuilder address = new StringBuilder(100);
458 address.AppendLine(ptRow.Name);
459 address.AppendLine(ptRow.STREET);
460 address.AppendLine(ptRow.CITY + ", " + ptRow.STATE + " " + ptRow.ZIP);
461 g.DrawString(address.ToString(), fBody, Brushes.Black, printArea, sf);
462 }
463
464 /// <summary>
465 /// Print rebook letters. Prints old and new appointments dates then the missive.
466 /// </summary>
467 /// <param name="ptRow">Strongly typed appointment row</param>
468 /// <param name="e">etc</param>
469 /// <param name="letter">Text of the letter to print</param>
470 /// <param name="title">Title to print at the top of the letter</param>
471 public virtual void PrintRebookLetter(dsRebookAppts.PatientApptsRow ptRow, PrintPageEventArgs e, string letter, string title)
472 {
473 Rectangle printArea = e.MarginBounds;
474 Graphics g = e.Graphics;
475 StringFormat sf = new StringFormat();
476 sf.Alignment = StringAlignment.Center; //for title
477 Font fTitle = new Font(FontFamily.GenericSerif, 24, FontStyle.Bold); //for title
478 Font fBody = new Font(FontFamily.GenericSerif, 12);
479 g.DrawString(title, fTitle, Brushes.Black, printArea, sf); //title
480
481 // move down
482 int titleHeight = (int)g.MeasureString(title, fTitle, printArea.Width).Height;
483 printArea.Y += titleHeight;
484 printArea.Height -= titleHeight;
485
486 // draw underline
487 g.DrawLine(Pens.Black, printArea.Location, new Point(printArea.Right, printArea.Y));
488 printArea.Y += 15;
489 printArea.Height -= 15;
490
491 // write old and new appointment dates
492 string str = "Old Appointment Date:\t\t" + ptRow.OldApptDate + "\n";
493 str += "New Appointment Date:\t\t" + ptRow.NewApptDate + "\n\n";
494 g.DrawString(str, fBody, Brushes.Black, printArea);
495
496 // move down
497 int strHeight = (int)g.MeasureString(str, fBody, printArea.Width).Height;
498 printArea.Y += strHeight;
499 printArea.Height -= strHeight;
500
501 //Text Direction
502 StringFormat sf2 = new StringFormat();
503 if (System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.IsRightToLeft)
504 sf2.FormatFlags = StringFormatFlags.DirectionRightToLeft;
505
506 // write missive
507 g.DrawString(letter, fBody, Brushes.Black, printArea, sf2);
508
509 //print Address in lower left corner for windowed envolopes
510 printArea.Location = new Point(e.MarginBounds.X, (int)(e.PageBounds.Height * 0.66));
511 printArea.Height = (int)(e.MarginBounds.Height * 0.20);
512 sf.Alignment = StringAlignment.Near;
513 sf.LineAlignment = StringAlignment.Center;
514 StringBuilder address = new StringBuilder(100);
515 address.AppendLine(ptRow.Name);
516 address.AppendLine(ptRow.STREET);
517 address.AppendLine(ptRow.CITY + ", " + ptRow.STATE + " " + ptRow.ZIP);
518 g.DrawString(address.ToString(), fBody, Brushes.Black, printArea, sf);
519
520 }
521
522 /// <summary>
523 /// Print message on a page; typically that there are no appointments to be found.
524 /// Or just a test message to verify that printing works.
525 /// </summary>
526 /// <param name="msg">The exact string to print.</param>
527 /// <param name="e">Print Page event args</param>
528 public virtual void PrintMessage(string msg, PrintPageEventArgs e)
529 {
530 e.Graphics.DrawString(msg, new Font(FontFamily.GenericSerif, 14),
531 Brushes.Black, e.MarginBounds);
532 }
533
534 /// <summary>
535 /// Print Routing Slip
536 /// </summary>
537 /// <param name="a">Appointment Data Structure</param>
538 /// <param name="title">String to print for title</param>
539 /// <param name="e">etc</param>
540 public virtual void PrintRoutingSlip(CGAppointment appt, int apptOrder, PrintPageEventArgs e)
541 {
542 // Prep
543 Graphics g = e.Graphics;
544 Rectangle printArea = e.MarginBounds;
545 Rectangle pageArea = e.PageBounds;
546 Rectangle headerArea = new Rectangle()
547 {
548 X = e.MarginBounds.X,
549 Y = e.PageBounds.Y,
550 Height = e.MarginBounds.Y - e.PageBounds.Y,
551 Width = e.MarginBounds.Width
552 };
553 Rectangle footerArea = new Rectangle()
554 {
555 X = e.MarginBounds.X,
556 Y = e.MarginBounds.Height + headerArea.Height,
557 Width = e.MarginBounds.Width,
558 Height = pageArea.Height - (e.MarginBounds.Height + headerArea.Height)
559 };
560
561 const int part1Height = 400;
562 string s;
563
564 // A few fonts
565 Font fTitle = new Font(FontFamily.GenericSerif, 24, FontStyle.Bold); //for title
566 Font fBody = new Font(FontFamily.GenericSerif, 12);
567 Font fGroupTitle = new Font(FontFamily.GenericSansSerif, 10, FontStyle.Bold);
568
569 StringFormat sf0 = new StringFormat()
570 {
571 Alignment = StringAlignment.Center,
572 LineAlignment = StringAlignment.Center
573 };
574
575 // Draw Header
576 string division = CGDocumentManager.Current.ConnectInfo.DivisionName;
577 g.DrawString(division, fBody, Brushes.Black, headerArea, sf0);
578
579 // Draw Title
580 StringFormat sf = new StringFormat();
581 sf.Alignment = StringAlignment.Center; //for title & header
582 string title = "Routing Slip";
583 g.DrawString(title, fTitle, Brushes.Black, printArea, sf); //title
584
585 // move down
586 int titleHeight = (int)g.MeasureString(title, fTitle, printArea.Width).Height;
587 printArea.Y += titleHeight;
588 printArea.Height -= titleHeight;
589
590 // draw underline
591 g.DrawLine(Pens.Black, printArea.Location, new Point(printArea.Right, printArea.Y));
592 printArea.Y += 15;
593 printArea.Height -= 15;
594
595 // draw curved rectangle.
596 Rectangle personalInfoRectangle = new Rectangle(e.MarginBounds.X, printArea.Y + 30, 280, part1Height);
597 using (GraphicsPath path = GetRoundedRectPath(personalInfoRectangle, 10))
598 {
599 g.DrawPath(Pens.Black, path);
600 }
601
602 // group header
603 g.DrawString("Patient Information", fGroupTitle, Brushes.Black, new Point(personalInfoRectangle.X, personalInfoRectangle.Y - 20));
604
605 // inner rectangle for drawing strings:
606 Rectangle personalInfoInnerRectangle = new Rectangle(personalInfoRectangle.X + 20, personalInfoRectangle.Y + 20, personalInfoRectangle.Width - 40, personalInfoRectangle.Height - 40);
607
608 // Strings to write
609 StringBuilder sb = new StringBuilder(500);
610 sb.AppendLine("Name:" + "\t" + appt.Patient.Name);
611 sb.AppendLine();
612 sb.AppendLine("ID#:" + "\t" + appt.Patient.ID);
613 sb.AppendLine();
614 sb.AppendLine("DOB:" + "\t" + appt.Patient.DOB.ToShortDateString());
615 sb.AppendLine();
616 sb.AppendLine("Age:" + "\t" + appt.Patient.UserFriendlyAge);
617 //sb.AppendLine();
618 //sb.AppendLine("Sex:" + "\t" + appt.Patient.Sex.ToString());
619
620 // Draw them
621 g.DrawString(sb.ToString(), fBody, Brushes.Black, personalInfoInnerRectangle);
622
623 // draw curved rectangle
624 Rectangle apptInfoRectangle = new Rectangle(e.MarginBounds.X + e.MarginBounds.Width - 280, printArea.Y + 30, 280, part1Height);
625 using (GraphicsPath path = GetRoundedRectPath(apptInfoRectangle, 10))
626 {
627 g.DrawPath(Pens.Black, path);
628 }
629
630 // group header
631 g.DrawString("Appointment Information", fGroupTitle, Brushes.Black, new Point(apptInfoRectangle.X, apptInfoRectangle.Y - 20));
632
633 // Strings to write
634 sb = new StringBuilder();
635 sb.AppendLine("Clinic:");
636 sb.AppendLine(appt.Resource);
637 sb.AppendLine();
638 sb.AppendLine("Appointment Provider:");
639 sb.AppendLine((appt.Provider == null) ? "(none)" : appt.Provider.ToString()); //Appt Provider or (none) if null
640 sb.AppendLine();
641 sb.AppendLine("Patient Order:" + "\t" + apptOrder);
642 sb.AppendLine("Date: " + "\t" + appt.StartTime.ToShortDateString() + " " + appt.StartTime.ToShortTimeString());
643 sb.AppendLine();
644 sb.AppendLine("Appointment Note: ");
645 sb.AppendLine(String.IsNullOrWhiteSpace(appt.Note)? "(none)" : appt.Note);
646
647 // Draw them
648 Rectangle apptInfoInnerRectangle = new Rectangle(apptInfoRectangle.X + 20, apptInfoRectangle.Y + 20, apptInfoRectangle.Width - 40, apptInfoRectangle.Height - 40);
649
650 // Draw them
651 g.DrawString(sb.ToString(), fBody, Brushes.Black, apptInfoInnerRectangle);
652
653 // Move Drawing Rectangle Down
654 printArea.Y += apptInfoRectangle.Height + 30 + 20;
655 printArea.Height -= apptInfoRectangle.Height + 30 + 20;
656
657 // Draw New Line
658 using (Pen dashpen = new Pen(Color.Black))
659 {
660 dashpen.DashStyle = DashStyle.Dash;
661 g.DrawLine(dashpen, printArea.Location, new Point(printArea.Right, printArea.Y));
662 }
663
664 printArea.Y += 5;
665 printArea.Height -= 5;
666
667 s = "Scratch Area";
668 g.DrawString(s, fGroupTitle, Brushes.Black, printArea);
669
670 // move down
671 printArea.Y += 300;
672 printArea.Height -= 300;
673
674 //TODO: Put Next Appointment Area
675 using (Pen dashpen = new Pen(Color.Black))
676 {
677 dashpen.DashStyle = DashStyle.Dot;
678 g.DrawLine(dashpen, printArea.Location, new Point(printArea.Right, printArea.Y));
679 }
680
681 printArea.Y += 5;
682 printArea.Height -= 5;
683
684 s = "Next Appointment Instructions";
685 g.DrawString(s, fGroupTitle, Brushes.Black, printArea);
686
687 // Draw Footer
688 //use sf0 to print the footer (center all the way)
689 s = "Printed: " + DateTime.Now.ToString();
690 Font fFooter = new Font(FontFamily.GenericSerif, 7);
691 g.DrawString(s, fFooter, Brushes.Black, footerArea, sf0);
692
693 g.Dispose();
694
695 }
696
697 }
698 public abstract class PrintingCreator
699 {
700 public abstract Printing PrintFactory();
701 }
702
703}
Note: See TracBrowser for help on using the repository browser.