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

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

V 1.6 Beta Release

AssemblyInfo.cs: version bumped up to 1.6
CGView:

  1. Changed Popup calendar menu enable/disable code for specific menu items (simplification)
  2. Bug fixed in AddAppointmentEnabled(): Checks to see if there are any slots using the new algorithm introduced in v 1.5
  3. Resequence order of Saving/Canceling Radiology Package Call with Saving/Cancelling Appointment. Saving Cancelling appointment comes first because it may fail and thus cancel the whole transaction.
  4. BMX Events will now be raised after making/cancelling a radiology appointment.
  5. Better exception handling for making Radiology Appointments in AppointmentAddNewRadiology().

strings.ar.resx:
Fixed a mispelling.

Printing:
Improved the display of dates for Appointment Slips.

File size: 33.6 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 g.Dispose();
141 }
142
143 /// <summary>
144 /// Prints a single appointment slip to give to the patient
145 /// </summary>
146 /// <param name="appt">The Appointment to print</param>
147 /// <param name="e">PrintPageEventArgs from PrintDocument Print handler</param>
148 public virtual void PrintAppointmentSlip(CGAppointment appt, PrintPageEventArgs e)
149 {
150 // Prep
151 Graphics g = e.Graphics;
152 Rectangle printArea = e.MarginBounds;
153 Rectangle pageArea = e.PageBounds;
154 Rectangle headerArea = new Rectangle()
155 {
156 X = e.MarginBounds.X,
157 Y = e.PageBounds.Y,
158 Height = e.MarginBounds.Y - e.PageBounds.Y - 50,
159 Width = e.MarginBounds.Width
160 };
161 Rectangle footerArea = new Rectangle()
162 {
163 X = e.MarginBounds.X,
164 Y = e.MarginBounds.Height + headerArea.Height,
165 Width = e.MarginBounds.Width,
166 Height = pageArea.Height - (e.MarginBounds.Height + headerArea.Height)
167 };
168
169 string s;
170
171 // A few fonts
172 Font fTitle = new Font(FontFamily.GenericSerif, 24, FontStyle.Bold); //for title
173 Font fBody = new Font(FontFamily.GenericSerif, 12);
174 Font fGroupTitle = new Font(FontFamily.GenericSansSerif, 10, FontStyle.Bold);
175
176 StringFormat sfCenterCenter = new StringFormat()
177 {
178 Alignment = StringAlignment.Center,
179 LineAlignment = StringAlignment.Center
180 };
181
182 // Draw Header
183 string division = CGDocumentManager.Current.ConnectInfo.DivisionName;
184 g.DrawString(division, fBody, Brushes.Black, headerArea, sfCenterCenter);
185
186 const int watermarkLength = 75;
187
188 // Move down for optional form paper
189 printArea.Y += watermarkLength;
190 printArea.Height -= watermarkLength;
191
192 // Draw Title
193 StringFormat sfCenter = new StringFormat();
194 sfCenter.Alignment = StringAlignment.Center; //for title & header
195
196 s = strings.ApptReminderSlip;
197 g.DrawString(s, fTitle, Brushes.Black, printArea, sfCenter); //title
198
199 // move down
200 int titleHeight = (int)g.MeasureString(s, fTitle, printArea.Width).Height;
201 printArea.Y += titleHeight;
202 printArea.Height -= titleHeight;
203
204 // draw underline
205 g.DrawLine(Pens.Black, printArea.Location, new Point(printArea.Right, printArea.Y));
206 printArea.Y += 15;
207 printArea.Height -= 15;
208
209 // draw curved rectangle.
210 Rectangle personalInfoRectangle = new Rectangle(e.MarginBounds.X, printArea.Y + 30, 280, 300);
211 using (GraphicsPath path = GetRoundedRectPath(personalInfoRectangle, 10))
212 {
213 g.DrawPath(Pens.Black, path);
214 }
215
216 // group header
217 s = strings.PtInfo;
218 StringFormat sf3 = new StringFormat(System.Threading.Thread.CurrentThread.CurrentUICulture.TextInfo.IsRightToLeft ? StringFormatFlags.DirectionRightToLeft : 0);
219 g.DrawString(s, fGroupTitle, Brushes.Black, new Rectangle(personalInfoRectangle.X, personalInfoRectangle.Y - 20,personalInfoRectangle.Width, 20),sf3);
220
221 // inner rectangle for drawing strings:
222 Rectangle personalInfoInnerRectangle = new Rectangle(personalInfoRectangle.X + 20, personalInfoRectangle.Y + 20, 280 - 40, 300 - 40);
223
224 // Strings to write
225 StringBuilder sb = new StringBuilder(500);
226 sb.AppendLine(strings.Name + ":" + "\t" + appt.Patient.Name);
227 sb.AppendLine();
228 sb.AppendLine(strings.ID + ":" + "\t" + appt.Patient.ID);
229 sb.AppendLine();
230 s = appt.Patient.DOB.ToString("dd") + " " + appt.Patient.DOB.ToString("MMM") + ", " + appt.Patient.DOB.Year;
231 sb.AppendLine(strings.DOB + ":" + "\t" + s);
232 sb.AppendLine();
233 sb.AppendLine(strings.Age + ":" + "\t" + appt.Patient.UserFriendlyAge);
234 sb.AppendLine();
235 s = appt.Patient.Sex == Sex.Male ? strings.Male : strings.Female;
236 sb.AppendLine(strings.Sex + ":" + "\t" + s);
237
238 // Draw them
239 sf3 = new StringFormat(System.Threading.Thread.CurrentThread.CurrentUICulture.TextInfo.IsRightToLeft ? StringFormatFlags.DirectionRightToLeft : 0);
240 sf3.SetTabStops(0, new float[] {75} );
241 sf3.SetDigitSubstitution(System.Threading.Thread.CurrentThread.CurrentUICulture.LCID, StringDigitSubstitute.Traditional);
242 g.DrawString(sb.ToString(), fBody, Brushes.Black, personalInfoInnerRectangle, sf3);
243
244 // draw curved rectangle
245 Rectangle apptInfoRectangle = new Rectangle(e.MarginBounds.X + e.MarginBounds.Width - 280, printArea.Y + 30, 280, 300);
246 using (GraphicsPath path = GetRoundedRectPath(apptInfoRectangle, 10))
247 {
248 g.DrawPath(Pens.Black, path);
249 }
250
251 s = strings.ApptInfo;
252 // group header
253 g.DrawString(s, fGroupTitle, Brushes.Black, new Rectangle(apptInfoRectangle.X, apptInfoRectangle.Y - 20,apptInfoRectangle.Width, 20), sf3);
254
255 // Strings to write
256 sb = new StringBuilder();
257 sb.AppendLine(strings.Clinic + ":" + "\t" + appt.Resource);
258 sb.AppendLine();
259 s = appt.StartTime.ToString("dd") + " " + appt.StartTime.ToString("MMM") + ", " + appt.StartTime.Year;
260 sb.AppendLine(strings.Date + ":" + "\t" + s);
261 sb.AppendLine();
262 sb.AppendLine(strings.Day + ":" + "\t" + appt.StartTime.ToString("dddd"));
263 sb.AppendLine();
264 sb.AppendLine(strings.Time + ":" + "\t" + appt.StartTime.ToShortTimeString());
265
266 // Draw them
267 Rectangle apptInfoInnerRectangle = new Rectangle(apptInfoRectangle.X + 20, apptInfoRectangle.Y + 20, 280 - 40, 300 - 40);
268
269 // Draw them
270 g.DrawString(sb.ToString(), fBody, Brushes.Black, apptInfoInnerRectangle, sf3);
271
272 // Move Drawing Rectangle Down
273 printArea.Y += 300 + 30 + 20;
274 printArea.Height -= 300 + 30 + 20;
275
276 // Draw New Line
277 g.DrawLine(Pens.Black, printArea.Location, new Point(printArea.Right, printArea.Y));
278 printArea.Y += 5;
279 printArea.Height -= 5;
280
281 // Draw new Title
282 s = strings.ClinicInstructions;
283 g.DrawString(s, fTitle, Brushes.Black, printArea, sfCenter); //title
284
285 // move down
286 titleHeight = (int)g.MeasureString(s, fTitle, printArea.Width).Height;
287 printArea.Y += titleHeight;
288 printArea.Height -= titleHeight;
289
290 // Draw New Line
291 g.DrawLine(Pens.Black, printArea.Location, new Point(printArea.Right, printArea.Y));
292 printArea.Y += 15;
293 printArea.Height -= 15;
294
295 // Get Resource Clinic Appointment Letter Text
296 DataTable resources = CGDocumentManager.Current.GlobalDataSet.Tables["Resources"];
297
298 string ltrTxt = (from resource in resources.AsEnumerable()
299 where resource.Field<string>("RESOURCE_NAME") == appt.Resource
300 select resource.Field<string>("LETTER_TEXT")).SingleOrDefault<string>();
301
302 if (String.IsNullOrWhiteSpace(ltrTxt)) ltrTxt = strings.NoInstructionsProvided;
303
304 g.DrawString(ltrTxt, fBody, Brushes.Black, printArea, sf3);
305
306 int ltrTxtHeight = (int)g.MeasureString(ltrTxt, fBody).Height;
307
308 printArea.Y += ltrTxtHeight + 15;
309 printArea.Height -= ltrTxtHeight + 15;
310
311 g.DrawLine(Pens.Black, printArea.Location, new Point(printArea.Right, printArea.Y));
312 printArea.Y += 5;
313 printArea.Height -= 5;
314
315 s = strings.Notes;
316 g.DrawString(s, fTitle, Brushes.Black, printArea, sfCenter); // Notes title
317
318 // move down
319 titleHeight = (int)g.MeasureString(s, fTitle, printArea.Width).Height;
320 printArea.Y += titleHeight;
321 printArea.Height -= titleHeight;
322
323 // Draw New Line
324 g.DrawLine(Pens.Black, printArea.Location, new Point(printArea.Right, printArea.Y));
325 printArea.Y += 15;
326 printArea.Height -= 15;
327
328 // Draw Notes Area
329 using (GraphicsPath path = GetRoundedRectPath(printArea, 15))
330 {
331 g.DrawPath(Pens.Black, path);
332 }
333
334 //use sf0 to print the footer (center all the way)
335 s = strings.Printed + ": " + DateTime.Now.ToString();
336 Font fFooter = new Font(FontFamily.GenericSerif, 7);
337 g.DrawString(s, fFooter, Brushes.Black, footerArea, sfCenterCenter);
338
339 g.Dispose();
340 }
341
342
343 private GraphicsPath GetRoundedRectPath(Rectangle rect, int radius)
344 {
345 int diameter = 2 * radius;
346
347 Rectangle arcRect = new Rectangle(rect.Location, new Size(diameter, diameter));
348 GraphicsPath path = new GraphicsPath();
349
350 path.AddArc(arcRect, 180, 90); //top left
351 arcRect.X = rect.Right - diameter;
352 path.AddArc(arcRect, 270, 90); // top right
353 arcRect.Y = rect.Bottom - diameter;
354 path.AddArc(arcRect, 0, 90); // bottom right
355 arcRect.X = rect.Left;
356 path.AddArc(arcRect, 90, 90); // bottom left
357
358 path.CloseFigure();
359
360 return path;
361 }
362
363 /// <summary>
364 /// Print Letter to be given or mailed to the patient
365 /// </summary>
366 /// <param name="ptrow">Strongly typed PatientApptsRow to pass (just one ApptRow)</param>
367 /// <param name="e">You know what that is</param>
368 /// <param name="letter">Contains letter string</param>
369 /// <param name="title">Title of the letter</param>
370 public virtual void PrintReminderLetter(dsPatientApptDisplay2.PatientApptsRow ptRow, PrintPageEventArgs e, string letter, string title)
371 {
372
373 Rectangle printArea = e.MarginBounds;
374 Graphics g = e.Graphics;
375 StringFormat sf = new StringFormat();
376 sf.Alignment = StringAlignment.Center; //for title
377 Font fTitle = new Font(FontFamily.GenericSerif, 24, FontStyle.Bold); //for title
378 Font fBody = new Font(FontFamily.GenericSerif, 12);
379 g.DrawString(title, fTitle, Brushes.Black, printArea, sf); //title
380
381 // move down
382 int titleHeight = (int)g.MeasureString(title, fTitle, printArea.Width).Height;
383 printArea.Y += titleHeight;
384 printArea.Height -= titleHeight;
385
386 // draw underline
387 g.DrawLine(Pens.Black, printArea.Location, new Point(printArea.Right, printArea.Y));
388 printArea.Y += 15;
389 printArea.Height -= 15;
390
391 // write appointment date
392 string str = "Appointment Date: " + ptRow.ApptDate + "\n\n";
393 g.DrawString(str, fBody, Brushes.Black, printArea);
394
395 // move down
396 int strHeight = (int)g.MeasureString(str, fBody, printArea.Width).Height;
397 printArea.Y += strHeight;
398 printArea.Height -= strHeight;
399
400 //Text Direction
401 StringFormat sf2 = new StringFormat();
402 if (System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.IsRightToLeft)
403 sf2.FormatFlags = StringFormatFlags.DirectionRightToLeft;
404
405 // write missive
406 g.DrawString(letter, fBody, Brushes.Black, printArea, sf2);
407
408 //print Address in lower left corner for windowed envolopes
409 printArea.Location = new Point(e.MarginBounds.X, (int)(e.PageBounds.Height * 0.66));
410 printArea.Height = (int)(e.MarginBounds.Height * 0.20);
411 sf.Alignment = StringAlignment.Near;
412 sf.LineAlignment = StringAlignment.Center;
413 StringBuilder address = new StringBuilder(100);
414 address.AppendLine(ptRow.Name);
415 address.AppendLine(ptRow.STREET);
416 address.AppendLine(ptRow.CITY + ", " + ptRow.STATE + " " + ptRow.ZIP);
417 g.DrawString(address.ToString(), fBody, Brushes.Black, printArea, sf);
418
419 g.Dispose();
420 }
421
422 /// <summary>
423 /// Cancellation Letter to be given or mailed to the patient
424 /// </summary>
425 /// <param name="ptRow">Strongly typed PatientApptsRow to pass (just one ApptRow)</param>
426 /// <param name="e">You know what that is</param>
427 /// <param name="letter">Contains letter string</param>
428 /// <param name="title">Title of the letter</param>
429 public virtual void PrintCancelLetter(dsRebookAppts.PatientApptsRow ptRow, PrintPageEventArgs e, string letter, string title)
430 {
431 Rectangle printArea = e.MarginBounds;
432 Graphics g = e.Graphics;
433 StringFormat sf = new StringFormat();
434 sf.Alignment = StringAlignment.Center; //for title
435 Font fTitle = new Font(FontFamily.GenericSerif, 24, FontStyle.Bold); //for title
436 Font fBody = new Font(FontFamily.GenericSerif, 12);
437 g.DrawString(title, fTitle, Brushes.Black, printArea, sf); //title
438
439 // move down
440 int titleHeight = (int)g.MeasureString(title, fTitle, printArea.Width).Height;
441 printArea.Y += titleHeight;
442 printArea.Height -= titleHeight;
443
444 // draw underline
445 g.DrawLine(Pens.Black, printArea.Location, new Point(printArea.Right, printArea.Y));
446 printArea.Y += 15;
447 printArea.Height -= 15;
448
449 // write appointment date
450 string str = "Appointment Date: " + ptRow.OldApptDate + "\n\n";
451 g.DrawString(str, fBody, Brushes.Black, printArea);
452
453 // move down
454 int strHeight = (int)g.MeasureString(str, fBody, printArea.Width).Height;
455 printArea.Y += strHeight;
456 printArea.Height -= strHeight;
457
458 //Text Direction
459 StringFormat sf2 = new StringFormat();
460 if (System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.IsRightToLeft)
461 sf2.FormatFlags = StringFormatFlags.DirectionRightToLeft;
462
463 // write missive
464 g.DrawString(letter, fBody, Brushes.Black, printArea, sf2);
465
466 //print Address in lower left corner for windowed envolopes
467 printArea.Location = new Point(e.MarginBounds.X, (int)(e.PageBounds.Height * 0.66));
468 printArea.Height = (int)(e.MarginBounds.Height * 0.20);
469 sf.Alignment = StringAlignment.Near;
470 sf.LineAlignment = StringAlignment.Center;
471 StringBuilder address = new StringBuilder(100);
472 address.AppendLine(ptRow.Name);
473 address.AppendLine(ptRow.STREET);
474 address.AppendLine(ptRow.CITY + ", " + ptRow.STATE + " " + ptRow.ZIP);
475 g.DrawString(address.ToString(), fBody, Brushes.Black, printArea, sf);
476
477 g.Dispose();
478 }
479
480 /// <summary>
481 /// Print rebook letters. Prints old and new appointments dates then the missive.
482 /// </summary>
483 /// <param name="ptRow">Strongly typed appointment row</param>
484 /// <param name="e">etc</param>
485 /// <param name="letter">Text of the letter to print</param>
486 /// <param name="title">Title to print at the top of the letter</param>
487 public virtual void PrintRebookLetter(dsRebookAppts.PatientApptsRow ptRow, PrintPageEventArgs e, string letter, string title)
488 {
489 Rectangle printArea = e.MarginBounds;
490 Graphics g = e.Graphics;
491 StringFormat sf = new StringFormat();
492 sf.Alignment = StringAlignment.Center; //for title
493 Font fTitle = new Font(FontFamily.GenericSerif, 24, FontStyle.Bold); //for title
494 Font fBody = new Font(FontFamily.GenericSerif, 12);
495 g.DrawString(title, fTitle, Brushes.Black, printArea, sf); //title
496
497 // move down
498 int titleHeight = (int)g.MeasureString(title, fTitle, printArea.Width).Height;
499 printArea.Y += titleHeight;
500 printArea.Height -= titleHeight;
501
502 // draw underline
503 g.DrawLine(Pens.Black, printArea.Location, new Point(printArea.Right, printArea.Y));
504 printArea.Y += 15;
505 printArea.Height -= 15;
506
507 // write old and new appointment dates
508 string str = "Old Appointment Date:\t\t" + ptRow.OldApptDate + "\n";
509 str += "New Appointment Date:\t\t" + ptRow.NewApptDate + "\n\n";
510 g.DrawString(str, fBody, Brushes.Black, printArea);
511
512 // move down
513 int strHeight = (int)g.MeasureString(str, fBody, printArea.Width).Height;
514 printArea.Y += strHeight;
515 printArea.Height -= strHeight;
516
517 //Text Direction
518 StringFormat sf2 = new StringFormat();
519 if (System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.IsRightToLeft)
520 sf2.FormatFlags = StringFormatFlags.DirectionRightToLeft;
521
522 // write missive
523 g.DrawString(letter, fBody, Brushes.Black, printArea, sf2);
524
525 //print Address in lower left corner for windowed envolopes
526 printArea.Location = new Point(e.MarginBounds.X, (int)(e.PageBounds.Height * 0.66));
527 printArea.Height = (int)(e.MarginBounds.Height * 0.20);
528 sf.Alignment = StringAlignment.Near;
529 sf.LineAlignment = StringAlignment.Center;
530 StringBuilder address = new StringBuilder(100);
531 address.AppendLine(ptRow.Name);
532 address.AppendLine(ptRow.STREET);
533 address.AppendLine(ptRow.CITY + ", " + ptRow.STATE + " " + ptRow.ZIP);
534 g.DrawString(address.ToString(), fBody, Brushes.Black, printArea, sf);
535
536 g.Dispose();
537 }
538
539 /// <summary>
540 /// Print message on a page; typically that there are no appointments to be found.
541 /// Or just a test message to verify that printing works.
542 /// </summary>
543 /// <param name="msg">The exact string to print.</param>
544 /// <param name="e">Print Page event args</param>
545 public virtual void PrintMessage(string msg, PrintPageEventArgs e)
546 {
547 e.Graphics.DrawString(msg, new Font(FontFamily.GenericSerif, 14),
548 Brushes.Black, e.MarginBounds);
549 e.Graphics.Dispose();
550 }
551
552 /// <summary>
553 /// Print Routing Slip
554 /// </summary>
555 /// <param name="a">Appointment Data Structure</param>
556 /// <param name="apptOrder">Order of Appointment</param>
557 /// <param name="e">etc</param>
558 public virtual void PrintRoutingSlip(CGAppointment appt, int apptOrder, PrintPageEventArgs e)
559 {
560 // Prep
561 Graphics g = e.Graphics;
562 Rectangle printArea = e.MarginBounds;
563 Rectangle pageArea = e.PageBounds;
564 Rectangle headerArea = new Rectangle()
565 {
566 X = e.MarginBounds.X,
567 Y = e.PageBounds.Y, //0
568 Height = e.MarginBounds.Y - e.PageBounds.Y - 50, //100px - 50px
569 Width = e.MarginBounds.Width
570 };
571 Rectangle footerArea = new Rectangle()
572 {
573 X = e.MarginBounds.X,
574 Y = e.MarginBounds.Height + headerArea.Height,
575 Width = e.MarginBounds.Width,
576 Height = pageArea.Height - (e.MarginBounds.Height + headerArea.Height)
577 };
578
579 const int part1Height = 400;
580 string s;
581
582 // A few fonts
583 Font fTitle = new Font(FontFamily.GenericSerif, 24, FontStyle.Bold); //for title
584 Font fBody = new Font(FontFamily.GenericSerif, 12);
585 Font fGroupTitle = new Font(FontFamily.GenericSansSerif, 10, FontStyle.Bold);
586
587 StringFormat sf0 = new StringFormat()
588 {
589 Alignment = StringAlignment.Center,
590 LineAlignment = StringAlignment.Center
591 };
592
593 // Draw Header
594 string division = CGDocumentManager.Current.ConnectInfo.DivisionName;
595 g.DrawString(division, fBody, Brushes.Black, headerArea, sf0);
596
597 const int watermarkLength = 75;
598
599 // Move down for optional form paper
600 printArea.Y += watermarkLength;
601 printArea.Height -= watermarkLength;
602
603 // Draw Title
604 StringFormat sf = new StringFormat();
605 sf.Alignment = StringAlignment.Center; //for title & header
606 string title = strings.RoutingSlip;
607 g.DrawString(title, fTitle, Brushes.Black, printArea, sf); //title
608
609 // move down
610 int titleHeight = (int)g.MeasureString(title, fTitle, printArea.Width).Height;
611 printArea.Y += titleHeight;
612 printArea.Height -= titleHeight;
613
614 // draw underline
615 g.DrawLine(Pens.Black, printArea.Location, new Point(printArea.Right, printArea.Y));
616 printArea.Y += 15;
617 printArea.Height -= 15;
618
619 // draw curved rectangle.
620 Rectangle personalInfoRectangle = new Rectangle(e.MarginBounds.X, printArea.Y + 30, 280, part1Height);
621 using (GraphicsPath path = GetRoundedRectPath(personalInfoRectangle, 10))
622 {
623 g.DrawPath(Pens.Black, path);
624 }
625
626 // group header
627 s = strings.PtInfo;
628 StringFormat sf3 = new StringFormat(System.Threading.Thread.CurrentThread.CurrentUICulture.TextInfo.IsRightToLeft ? StringFormatFlags.DirectionRightToLeft : 0);
629 g.DrawString(s, fGroupTitle, Brushes.Black, new Rectangle(personalInfoRectangle.X, personalInfoRectangle.Y - 20, personalInfoRectangle.Width, 20), sf3);
630
631 StringFormat sf4 = new StringFormat(System.Threading.Thread.CurrentThread.CurrentUICulture.TextInfo.IsRightToLeft ? StringFormatFlags.DirectionRightToLeft : 0);
632 sf4.SetTabStops(0, new float[] { 75 });
633 sf4.SetDigitSubstitution(System.Threading.Thread.CurrentThread.CurrentUICulture.LCID, StringDigitSubstitute.Traditional);
634
635 // inner rectangle for drawing strings:
636 Rectangle personalInfoInnerRectangle = new Rectangle(personalInfoRectangle.X + 20, personalInfoRectangle.Y + 20, personalInfoRectangle.Width - 40, personalInfoRectangle.Height - 40);
637
638 // Strings to write
639 StringBuilder sb = new StringBuilder(500);
640 sb.AppendLine(strings.Name + ":" + "\t" + appt.Patient.Name);
641 sb.AppendLine();
642 sb.AppendLine(strings.ID + ":" + "\t" + appt.Patient.ID);
643 sb.AppendLine();
644 s = appt.Patient.DOB.ToString("dd") + " " + appt.Patient.DOB.ToString("MMM") + ", " + appt.Patient.DOB.Year;
645 sb.AppendLine(strings.DOB + ":" + "\t" + s);
646 sb.AppendLine();
647 sb.AppendLine(strings.Age + ":" + "\t" + appt.Patient.UserFriendlyAge);
648 //sb.AppendLine();
649 //sb.AppendLine("Sex:" + "\t" + appt.Patient.Sex.ToString());
650
651 // Draw them
652 g.DrawString(sb.ToString(), fBody, Brushes.Black, personalInfoInnerRectangle, sf4);
653
654 // draw curved rectangle
655 Rectangle apptInfoRectangle = new Rectangle(e.MarginBounds.X + e.MarginBounds.Width - 280, printArea.Y + 30, 280, part1Height);
656 using (GraphicsPath path = GetRoundedRectPath(apptInfoRectangle, 10))
657 {
658 g.DrawPath(Pens.Black, path);
659 }
660
661 // group header
662 s = strings.ApptInfo;
663 g.DrawString(s, fGroupTitle, Brushes.Black, new Rectangle(apptInfoRectangle.X, apptInfoRectangle.Y - 20, apptInfoRectangle.Width, 20), sf3);
664
665 // Strings to write
666 sb = new StringBuilder();
667 sb.AppendLine(strings.Clinic + ":");
668 sb.AppendLine(appt.Resource);
669 sb.AppendLine();
670 sb.AppendLine(strings.AppointmentProvider + ":");
671 sb.AppendLine((appt.Provider == null) ? strings.none : appt.Provider.ToString()); //Appt Provider or (none) if null
672 sb.AppendLine();
673 sb.AppendLine(strings.PatientOrder + ":" + "\t" + apptOrder);
674 sb.AppendLine(strings.Date + ":" + "\t" + appt.StartTime.ToShortDateString() + " " + appt.StartTime.ToShortTimeString());
675 sb.AppendLine();
676 sb.AppendLine(strings.AppointmentNote + ":");
677 sb.AppendLine(String.IsNullOrWhiteSpace(appt.Note)? strings.none : appt.Note);
678
679 // Draw them
680 Rectangle apptInfoInnerRectangle = new Rectangle(apptInfoRectangle.X + 20, apptInfoRectangle.Y + 20, apptInfoRectangle.Width - 40, apptInfoRectangle.Height - 40);
681
682 // Draw them
683 g.DrawString(sb.ToString(), fBody, Brushes.Black, apptInfoInnerRectangle, sf4);
684
685 // Move Drawing Rectangle Down
686 printArea.Y += apptInfoRectangle.Height + 30 + 20;
687 printArea.Height -= apptInfoRectangle.Height + 30 + 20;
688
689 // Draw New Line
690 using (Pen dashpen = new Pen(Color.Black))
691 {
692 dashpen.DashStyle = DashStyle.Dash;
693 g.DrawLine(dashpen, printArea.Location, new Point(printArea.Right, printArea.Y));
694 }
695
696 printArea.Y += 5;
697 printArea.Height -= 5;
698
699 s = strings.ScratchArea;
700 g.DrawString(s, fGroupTitle, Brushes.Black, printArea, sf3);
701
702 /* Per Al-Najjar, we don't want the next appointment instructions section
703 // move down
704 printArea.Y += 240;
705 printArea.Height -= 240;
706
707 using (Pen dashpen = new Pen(Color.Black))
708 {
709 dashpen.DashStyle = DashStyle.Dot;
710 g.DrawLine(dashpen, printArea.Location, new Point(printArea.Right, printArea.Y));
711 }
712
713 printArea.Y += 5;
714 printArea.Height -= 5;
715
716 s = strings.NextAppointmentInstructions;
717 g.DrawString(s, fGroupTitle, Brushes.Black, printArea, sf3);
718 */
719
720 // Draw Footer
721 //use sf0 to print the footer (center all the way)
722 s = strings.Printed + ": " + DateTime.Now.ToString();
723 Font fFooter = new Font(FontFamily.GenericSerif, 7);
724 g.DrawString(s, fFooter, Brushes.Black, footerArea, sf0);
725
726 g.Dispose();
727
728 }
729
730 }
731 public abstract class PrintingCreator
732 {
733 public abstract Printing PrintFactory();
734 }
735
736}
Note: See TracBrowser for help on using the repository browser.