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

Last change on this file since 1468 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
RevLine 
[772]1using System;
2using System.Drawing.Printing;
3using System.Drawing;
[1110]4using System.Text;
5using System.Drawing.Drawing2D;
6using System.Linq;
[772]7using System.Data;
8
9namespace IndianHealthService.ClinicalScheduling
10{
[1112]11 public partial class Printing
[1110]12 {
[772]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>
[788]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>
[772]23 /// <remarks>beg and end have no effect on operation--they are there for documentation for user only</remarks>
[1110]24 public virtual void PrintAppointments(dsPatientApptDisplay2 ds, PrintPageEventArgs e, DateTime beg, DateTime end, int resourceToPrint, ref int apptPrinting, int pageNumber)
[772]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
[788]40 //Header
[772]41 g.DrawString("Confidential Patient Information", f8, Brushes.Black, e.PageBounds, sf);
42
[788]43 //Footer
44 sf.Alignment = StringAlignment.Center;
45 sf.LineAlignment = StringAlignment.Far;
46 g.DrawString("Page " + pageNumber, f8, Brushes.Black, e.PageBounds, sf);
47
[772]48 //Typical manipulable print area
49 Rectangle printArea = e.MarginBounds;
[1112]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
[788]72 //resource we want to print
[772]73 dsPatientApptDisplay2.BSDXResourceRow r = ds.BSDXResource[resourceToPrint];
74
[788]75 //header
[772]76 string toprint;
[1112]77 if (beg.Date == end.Date) toprint = "Appointments for " + r.RESOURCE_NAME + " on " + beg.ToLongDateString();
[772]78 else toprint = "Appointments for " + r.RESOURCE_NAME + " from " + beg.ToShortDateString() + " to "
79 + end.ToShortDateString();
80 g.DrawString(toprint, f14bold, Brushes.Black, printArea);
81
[788]82 //Move print area down
[1112]83 int titleHeight = (int)g.MeasureString(toprint, f14bold, printArea.Size).Height;
84 printArea.Height -= titleHeight;
85 printArea.Y += titleHeight;
[788]86
87 //Draw Line
[772]88 g.DrawLine(new Pen(Brushes.Black, 0), printArea.X, printArea.Y, printArea.X + printArea.Width, printArea.Y);
89
[788]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
[772]95
[788]96 StringFormat sf2 = new StringFormat(); //sf to hold tab stops
97 sf2.SetTabStops(50, new float[] { 100, 250, 25 });
[772]98
[788]99 //appt printed starts at zero
100 while (apptPrinting < appts.Length)
[772]101 {
[788]102 dsPatientApptDisplay2.PatientApptsRow a = (dsPatientApptDisplay2.PatientApptsRow)appts[apptPrinting];
103
104 StringBuilder apptPrintStr = new StringBuilder(200);
[900]105 apptPrintStr.AppendLine(a.ApptDate.ToString() + "\t" + a.Name + " (" + a.Sex + ")" + "\t" + "DOB: " + a.DOB.ToShortDateString() + "\t" + "ID: " + a.HRN);
[788]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++;
[772]137 }
[1131]138
139
140 g.Dispose();
[772]141 }
[788]142
143 /// <summary>
[1110]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,
[1159]158 Height = e.MarginBounds.Y - e.PageBounds.Y - 50,
[1110]159 Width = e.MarginBounds.Width
160 };
[1112]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 };
[1110]168
[1131]169 string s;
[1112]170
[1110]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
[1131]176 StringFormat sfCenterCenter = new StringFormat()
[1110]177 {
178 Alignment = StringAlignment.Center,
179 LineAlignment = StringAlignment.Center
180 };
181
182 // Draw Header
183 string division = CGDocumentManager.Current.ConnectInfo.DivisionName;
[1131]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
[1110]192 // Draw Title
[1131]193 StringFormat sfCenter = new StringFormat();
194 sfCenter.Alignment = StringAlignment.Center; //for title & header
[1110]195
[1131]196 s = strings.ApptReminderSlip;
197 g.DrawString(s, fTitle, Brushes.Black, printArea, sfCenter); //title
[1110]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
[1112]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);
[1110]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);
[1112]226 sb.AppendLine(strings.Name + ":" + "\t" + appt.Patient.Name);
[1110]227 sb.AppendLine();
[1112]228 sb.AppendLine(strings.ID + ":" + "\t" + appt.Patient.ID);
[1110]229 sb.AppendLine();
[1176]230 s = appt.Patient.DOB.ToString("dd") + " " + appt.Patient.DOB.ToString("MMM") + ", " + appt.Patient.DOB.Year;
231 sb.AppendLine(strings.DOB + ":" + "\t" + s);
[1110]232 sb.AppendLine();
[1112]233 sb.AppendLine(strings.Age + ":" + "\t" + appt.Patient.UserFriendlyAge);
[1110]234 sb.AppendLine();
[1112]235 s = appt.Patient.Sex == Sex.Male ? strings.Male : strings.Female;
236 sb.AppendLine(strings.Sex + ":" + "\t" + s);
237
[1110]238 // Draw them
[1112]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);
[1110]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
[1112]251 s = strings.ApptInfo;
[1110]252 // group header
[1112]253 g.DrawString(s, fGroupTitle, Brushes.Black, new Rectangle(apptInfoRectangle.X, apptInfoRectangle.Y - 20,apptInfoRectangle.Width, 20), sf3);
[1110]254
255 // Strings to write
256 sb = new StringBuilder();
[1112]257 sb.AppendLine(strings.Clinic + ":" + "\t" + appt.Resource);
[1110]258 sb.AppendLine();
[1176]259 s = appt.StartTime.ToString("dd") + " " + appt.StartTime.ToString("MMM") + ", " + appt.StartTime.Year;
260 sb.AppendLine(strings.Date + ":" + "\t" + s);
[1110]261 sb.AppendLine();
[1112]262 sb.AppendLine(strings.Day + ":" + "\t" + appt.StartTime.ToString("dddd"));
[1110]263 sb.AppendLine();
[1112]264 sb.AppendLine(strings.Time + ":" + "\t" + appt.StartTime.ToShortTimeString());
[1110]265
266 // Draw them
267 Rectangle apptInfoInnerRectangle = new Rectangle(apptInfoRectangle.X + 20, apptInfoRectangle.Y + 20, 280 - 40, 300 - 40);
268
269 // Draw them
[1112]270 g.DrawString(sb.ToString(), fBody, Brushes.Black, apptInfoInnerRectangle, sf3);
[1110]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
[1112]282 s = strings.ClinicInstructions;
[1131]283 g.DrawString(s, fTitle, Brushes.Black, printArea, sfCenter); //title
[1110]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
[1112]302 if (String.IsNullOrWhiteSpace(ltrTxt)) ltrTxt = strings.NoInstructionsProvided;
[1110]303
[1112]304 g.DrawString(ltrTxt, fBody, Brushes.Black, printArea, sf3);
[1110]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
[1112]315 s = strings.Notes;
[1131]316 g.DrawString(s, fTitle, Brushes.Black, printArea, sfCenter); // Notes title
[1110]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)
[1112]335 s = strings.Printed + ": " + DateTime.Now.ToString();
[1110]336 Font fFooter = new Font(FontFamily.GenericSerif, 7);
[1131]337 g.DrawString(s, fFooter, Brushes.Black, footerArea, sfCenterCenter);
[1110]338
[1131]339 g.Dispose();
[1110]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>
[788]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>
[1110]370 public virtual void PrintReminderLetter(dsPatientApptDisplay2.PatientApptsRow ptRow, PrintPageEventArgs e, string letter, string title)
[788]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;
[789]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
[900]400 //Text Direction
401 StringFormat sf2 = new StringFormat();
402 if (System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.IsRightToLeft)
403 sf2.FormatFlags = StringFormatFlags.DirectionRightToLeft;
404
[788]405 // write missive
[900]406 g.DrawString(letter, fBody, Brushes.Black, printArea, sf2);
[788]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);
[1131]418
419 g.Dispose();
[788]420 }
[1110]421
[788]422 /// <summary>
[789]423 /// Cancellation Letter to be given or mailed to the patient
[788]424 /// </summary>
[789]425 /// <param name="ptRow">Strongly typed PatientApptsRow to pass (just one ApptRow)</param>
[788]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>
[1110]429 public virtual void PrintCancelLetter(dsRebookAppts.PatientApptsRow ptRow, PrintPageEventArgs e, string letter, string title)
[788]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
[789]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
[900]458 //Text Direction
459 StringFormat sf2 = new StringFormat();
460 if (System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.IsRightToLeft)
461 sf2.FormatFlags = StringFormatFlags.DirectionRightToLeft;
462
[788]463 // write missive
[900]464 g.DrawString(letter, fBody, Brushes.Black, printArea, sf2);
[788]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);
[1131]476
477 g.Dispose();
[788]478 }
479
[789]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>
[1110]487 public virtual void PrintRebookLetter(dsRebookAppts.PatientApptsRow ptRow, PrintPageEventArgs e, string letter, string title)
[789]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
[900]517 //Text Direction
518 StringFormat sf2 = new StringFormat();
519 if (System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.IsRightToLeft)
520 sf2.FormatFlags = StringFormatFlags.DirectionRightToLeft;
521
[789]522 // write missive
[900]523 g.DrawString(letter, fBody, Brushes.Black, printArea, sf2);
[789]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
[1131]536 g.Dispose();
[789]537 }
538
539 /// <summary>
540 /// Print message on a page; typically that there are no appointments to be found.
[804]541 /// Or just a test message to verify that printing works.
[789]542 /// </summary>
543 /// <param name="msg">The exact string to print.</param>
544 /// <param name="e">Print Page event args</param>
[1110]545 public virtual void PrintMessage(string msg, PrintPageEventArgs e)
[788]546 {
547 e.Graphics.DrawString(msg, new Font(FontFamily.GenericSerif, 14),
548 Brushes.Black, e.MarginBounds);
[1131]549 e.Graphics.Dispose();
[788]550 }
[804]551
552 /// <summary>
553 /// Print Routing Slip
554 /// </summary>
555 /// <param name="a">Appointment Data Structure</param>
[1156]556 /// <param name="apptOrder">Order of Appointment</param>
[804]557 /// <param name="e">etc</param>
[1112]558 public virtual void PrintRoutingSlip(CGAppointment appt, int apptOrder, PrintPageEventArgs e)
[804]559 {
[1112]560 // Prep
561 Graphics g = e.Graphics;
[804]562 Rectangle printArea = e.MarginBounds;
[1112]563 Rectangle pageArea = e.PageBounds;
564 Rectangle headerArea = new Rectangle()
565 {
[1159]566 X = e.MarginBounds.X,
567 Y = e.PageBounds.Y, //0
568 Height = e.MarginBounds.Y - e.PageBounds.Y - 50, //100px - 50px
[1112]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
[1131]597 const int watermarkLength = 75;
598
599 // Move down for optional form paper
600 printArea.Y += watermarkLength;
601 printArea.Height -= watermarkLength;
602
[1112]603 // Draw Title
[804]604 StringFormat sf = new StringFormat();
[1112]605 sf.Alignment = StringAlignment.Center; //for title & header
[1131]606 string title = strings.RoutingSlip;
[804]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
[1112]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 }
[804]625
[1112]626 // group header
[1131]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);
[804]630
[1131]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
[1112]635 // inner rectangle for drawing strings:
636 Rectangle personalInfoInnerRectangle = new Rectangle(personalInfoRectangle.X + 20, personalInfoRectangle.Y + 20, personalInfoRectangle.Width - 40, personalInfoRectangle.Height - 40);
[804]637
[1112]638 // Strings to write
639 StringBuilder sb = new StringBuilder(500);
[1131]640 sb.AppendLine(strings.Name + ":" + "\t" + appt.Patient.Name);
[1112]641 sb.AppendLine();
[1131]642 sb.AppendLine(strings.ID + ":" + "\t" + appt.Patient.ID);
[1112]643 sb.AppendLine();
[1176]644 s = appt.Patient.DOB.ToString("dd") + " " + appt.Patient.DOB.ToString("MMM") + ", " + appt.Patient.DOB.Year;
645 sb.AppendLine(strings.DOB + ":" + "\t" + s);
[1112]646 sb.AppendLine();
[1131]647 sb.AppendLine(strings.Age + ":" + "\t" + appt.Patient.UserFriendlyAge);
[1125]648 //sb.AppendLine();
649 //sb.AppendLine("Sex:" + "\t" + appt.Patient.Sex.ToString());
[1112]650
651 // Draw them
[1131]652 g.DrawString(sb.ToString(), fBody, Brushes.Black, personalInfoInnerRectangle, sf4);
[1112]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
[1131]662 s = strings.ApptInfo;
663 g.DrawString(s, fGroupTitle, Brushes.Black, new Rectangle(apptInfoRectangle.X, apptInfoRectangle.Y - 20, apptInfoRectangle.Width, 20), sf3);
[1112]664
665 // Strings to write
666 sb = new StringBuilder();
[1131]667 sb.AppendLine(strings.Clinic + ":");
[1112]668 sb.AppendLine(appt.Resource);
669 sb.AppendLine();
[1131]670 sb.AppendLine(strings.AppointmentProvider + ":");
671 sb.AppendLine((appt.Provider == null) ? strings.none : appt.Provider.ToString()); //Appt Provider or (none) if null
[1112]672 sb.AppendLine();
[1131]673 sb.AppendLine(strings.PatientOrder + ":" + "\t" + apptOrder);
674 sb.AppendLine(strings.Date + ":" + "\t" + appt.StartTime.ToShortDateString() + " " + appt.StartTime.ToShortTimeString());
[1112]675 sb.AppendLine();
[1131]676 sb.AppendLine(strings.AppointmentNote + ":");
677 sb.AppendLine(String.IsNullOrWhiteSpace(appt.Note)? strings.none : appt.Note);
[1112]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
[1131]683 g.DrawString(sb.ToString(), fBody, Brushes.Black, apptInfoInnerRectangle, sf4);
[1112]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
[1131]699 s = strings.ScratchArea;
700 g.DrawString(s, fGroupTitle, Brushes.Black, printArea, sf3);
[1156]701
702 /* Per Al-Najjar, we don't want the next appointment instructions section
[1112]703 // move down
[1131]704 printArea.Y += 240;
705 printArea.Height -= 240;
[1112]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
[1131]716 s = strings.NextAppointmentInstructions;
717 g.DrawString(s, fGroupTitle, Brushes.Black, printArea, sf3);
[1156]718 */
[1112]719
720 // Draw Footer
721 //use sf0 to print the footer (center all the way)
[1131]722 s = strings.Printed + ": " + DateTime.Now.ToString();
[1112]723 Font fFooter = new Font(FontFamily.GenericSerif, 7);
724 g.DrawString(s, fFooter, Brushes.Black, footerArea, sf0);
725
726 g.Dispose();
727
[1110]728 }
[804]729
[772]730 }
[1110]731 public abstract class PrintingCreator
732 {
733 public abstract Printing PrintFactory();
734 }
735
736}
Note: See TracBrowser for help on using the repository browser.