source: Scheduling/branches/BMX4Support/Printing.cs@ 1436

Last change on this file since 1436 was 1194, checked in by Sam Habiel, 13 years ago

All changes to support BMX4. Now works with BMX 4.
AssemblyInfo: Bumped to 1.6 (will be 1.7 pending server changes).
Removed BMXNet23.dll and added BMXNET40.dll and BMXWIN40.dll.
Actual changes to support BMX 4 in the code:
All references to DocManager.ConnectInfo.bmxNetLib substituted with CGDocumentManager.Current.RemoteSession everywhere.
All Events use RemoteSession.EventServices APIs.
All references to DUZ use RemoteSession.User APIs.
All references to BMXNetLib.Piece changed to M.Piece.
Added RPC Logging Capability courtesy of BMX4.
Extensive changes in the Main[] class CGDocumentManager:

  • Added references to IndianHealthService.BMXNet.WinForm
  • Removed references to BMXNetLib and changed to RemoteSession
  • Singleton Instance constructor now private (overdue change).
  • Use new Event Framework part of Remote Session.
  • Login code totally rewritten to use BMXWIN40.dll.
  • RPMSDataTable references changed to TableFromCommand or TableFromSQL.

DAL:

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