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

Last change on this file since 1071 was 900, checked in by Sam Habiel, 14 years ago
  1. Fix bug of not showing appointments in 7 day view if arabic locale on machine.
  2. Fix printing of routing slip (add clinic and fix appointment time and HRN)
  3. Add RTL support for letters printed in Arabic Locale.
File size: 16.9 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Drawing.Printing;
6using System.Drawing;
7using System.Data;
8using System.Drawing.Drawing2D;
9
10namespace IndianHealthService.ClinicalScheduling
11{
12 /// <summary>
13 /// Class that encapsulates printing functions in Clinical Scheduling
14 /// </summary>
15 public static class Printing
16 {
17 /// <summary>
18 /// Print Appointments
19 /// </summary>
20 /// <param name="ds">Strongly Typed DataSet contains Resources and Appointments</param>
21 /// <param name="e">PrintPageEventArgs from PrintDocument Print handler</param>
22 /// <param name="beg">Begin Datetime to print appointments</param>
23 /// <param name="end">End Datetime to print appointments</param
24 /// <param name="resourceToPrint">The resouce to print</param>
25 /// <param name="apptPrinting">Current Appointment printing</param>
26 /// <param name="pageNumber">Current page number</param>
27 /// <remarks>beg and end have no effect on operation--they are there for documentation for user only</remarks>
28 public static void PrintAppointments(dsPatientApptDisplay2 ds, PrintPageEventArgs e, DateTime beg, DateTime end,
29 int resourceToPrint, ref int apptPrinting, int pageNumber)
30 {
31 Graphics g = e.Graphics;
32 //g.PageUnit = GraphicsUnit.Millimeter;
33 //SizeF szVCB = g.VisibleClipBounds.Size;
34 //PointF[] ptszVCB = {new PointF(szVCB.Width,szVCB.Height)};
35 //g.TransformPoints(CoordinateSpace.Page, CoordinateSpace.Device, ptszVCB);
36 //Create Fonts
37 Font f8 = new Font(FontFamily.GenericSerif, 8);
38 Font f10 = new Font(FontFamily.GenericSerif, 10);
39 Font f14bold = new Font(FontFamily.GenericSerif, 14, FontStyle.Bold);
40
41 //Center Alignment for some stuff
42 StringFormat sf = new StringFormat();
43 sf.Alignment = StringAlignment.Center;
44
45 //Header
46 g.DrawString("Confidential Patient Information", f8, Brushes.Black, e.PageBounds, sf);
47
48 //Footer
49 sf.Alignment = StringAlignment.Center;
50 sf.LineAlignment = StringAlignment.Far;
51 g.DrawString("Page " + pageNumber, f8, Brushes.Black, e.PageBounds, sf);
52
53 //Typical manipulable print area
54 Rectangle printArea = e.MarginBounds;
55
56 //resource we want to print
57 dsPatientApptDisplay2.BSDXResourceRow r = ds.BSDXResource[resourceToPrint];
58
59 //header
60 string toprint;
61 if (beg == end) toprint = "Appointments for " + r.RESOURCE_NAME + " on " + beg.ToLongDateString();
62 else toprint = "Appointments for " + r.RESOURCE_NAME + " from " + beg.ToShortDateString() + " to "
63 + end.ToShortDateString();
64 g.DrawString(toprint, f14bold, Brushes.Black, printArea);
65
66 //Move print area down
67 printArea.Height -= (int)f14bold.GetHeight();
68 printArea.Y += (int)f14bold.GetHeight();
69
70 //Draw Line
71 g.DrawLine(new Pen(Brushes.Black, 0), printArea.X, printArea.Y, printArea.X + printArea.Width, printArea.Y);
72
73 //Move print area down
74 printArea.Y += 5;
75 printArea.Height -= 5;
76
77 System.Data.DataRow[] appts = r.GetChildRows(ds.Relations[0]); //ds has only one relation
78
79 StringFormat sf2 = new StringFormat(); //sf to hold tab stops
80 sf2.SetTabStops(50, new float[] { 100, 250, 25 });
81
82 //appt printed starts at zero
83 while (apptPrinting < appts.Length)
84 {
85 dsPatientApptDisplay2.PatientApptsRow a = (dsPatientApptDisplay2.PatientApptsRow)appts[apptPrinting];
86
87 StringBuilder apptPrintStr = new StringBuilder(200);
88 apptPrintStr.AppendLine(a.ApptDate.ToString() + "\t" + a.Name + " (" + a.Sex + ")" + "\t" + "DOB: " + a.DOB.ToShortDateString() + "\t" + "ID: " + a.HRN);
89 apptPrintStr.AppendLine("P: " + a.HOMEPHONE + "\t" + "Address: " + a.STREET + ", " + a.CITY + ", " + a.STATE + " " + a.ZIP);
90 apptPrintStr.AppendLine("Note: " + a.NOTE);
91 apptPrintStr.AppendLine("Appointment made by " + a.APPT_MADE_BY + " on " + a.DATE_APPT_MADE);
92
93 int printedApptHeight = (int)g.MeasureString(apptPrintStr.ToString(), f10, printArea.Width).Height;
94 if (printedApptHeight > printArea.Height) // too much to print -- move to next page
95 // but don't increment the appointment to print since we haven't printed it yet.
96 // i.e. apptPrinting stays the same.
97 {
98 e.HasMorePages = true;
99 break;
100 }
101
102 //otherwise print it
103 g.DrawString(apptPrintStr.ToString(), f10, Brushes.Black, printArea, sf2);
104
105 //Move print area down
106 printArea.Y += printedApptHeight + 3;
107 printArea.Height -= printedApptHeight + 3;
108
109 //Draw a divider line
110 Point pt1 = new Point((int)(printArea.X + printArea.Width * 0.25), printArea.Y);
111 Point pt2 = new Point((int)(printArea.X + printArea.Width * 0.75), printArea.Y);
112 g.DrawLine(Pens.Gray, pt1, pt2);
113
114 //move down, again
115 printArea.Y += 3;
116 printArea.Height -= 3;
117
118 //go to the next appointment
119 apptPrinting++;
120 }
121 }
122
123 /// <summary>
124 /// Print Letter to be given or mailed to the patient
125 /// </summary>
126 /// <param name="ptrow">Strongly typed PatientApptsRow to pass (just one ApptRow)</param>
127 /// <param name="e">You know what that is</param>
128 /// <param name="letter">Contains letter string</param>
129 /// <param name="title">Title of the letter</param>
130 public static void PrintReminderLetter(dsPatientApptDisplay2.PatientApptsRow ptRow, PrintPageEventArgs e, string letter, string title)
131 {
132
133 Rectangle printArea = e.MarginBounds;
134 Graphics g = e.Graphics;
135 StringFormat sf = new StringFormat();
136 sf.Alignment = StringAlignment.Center; //for title
137 Font fTitle = new Font(FontFamily.GenericSerif, 24, FontStyle.Bold); //for title
138 Font fBody = new Font(FontFamily.GenericSerif, 12);
139 g.DrawString(title, fTitle, Brushes.Black, printArea, sf); //title
140
141 // move down
142 int titleHeight = (int)g.MeasureString(title, fTitle, printArea.Width).Height;
143 printArea.Y += titleHeight;
144 printArea.Height -= titleHeight;
145
146 // draw underline
147 g.DrawLine(Pens.Black, printArea.Location, new Point(printArea.Right, printArea.Y));
148 printArea.Y += 15;
149 printArea.Height -= 15;
150
151 // write appointment date
152 string str = "Appointment Date: " + ptRow.ApptDate + "\n\n";
153 g.DrawString(str, fBody, Brushes.Black, printArea);
154
155 // move down
156 int strHeight = (int)g.MeasureString(str, fBody, printArea.Width).Height;
157 printArea.Y += strHeight;
158 printArea.Height -= strHeight;
159
160 //Text Direction
161 StringFormat sf2 = new StringFormat();
162 if (System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.IsRightToLeft)
163 sf2.FormatFlags = StringFormatFlags.DirectionRightToLeft;
164
165 // write missive
166 g.DrawString(letter, fBody, Brushes.Black, printArea, sf2);
167
168 //print Address in lower left corner for windowed envolopes
169 printArea.Location = new Point(e.MarginBounds.X, (int)(e.PageBounds.Height * 0.66));
170 printArea.Height = (int)(e.MarginBounds.Height * 0.20);
171 sf.Alignment = StringAlignment.Near;
172 sf.LineAlignment = StringAlignment.Center;
173 StringBuilder address = new StringBuilder(100);
174 address.AppendLine(ptRow.Name);
175 address.AppendLine(ptRow.STREET);
176 address.AppendLine(ptRow.CITY + ", " + ptRow.STATE + " " + ptRow.ZIP);
177 g.DrawString(address.ToString(), fBody, Brushes.Black, printArea, sf);
178 }
179
180 /// <summary>
181 /// Cancellation Letter to be given or mailed to the patient
182 /// </summary>
183 /// <param name="ptRow">Strongly typed PatientApptsRow to pass (just one ApptRow)</param>
184 /// <param name="e">You know what that is</param>
185 /// <param name="letter">Contains letter string</param>
186 /// <param name="title">Title of the letter</param>
187 public static void PrintCancelLetter(dsRebookAppts.PatientApptsRow ptRow, PrintPageEventArgs e, string letter, string title)
188 {
189 Rectangle printArea = e.MarginBounds;
190 Graphics g = e.Graphics;
191 StringFormat sf = new StringFormat();
192 sf.Alignment = StringAlignment.Center; //for title
193 Font fTitle = new Font(FontFamily.GenericSerif, 24, FontStyle.Bold); //for title
194 Font fBody = new Font(FontFamily.GenericSerif, 12);
195 g.DrawString(title, fTitle, Brushes.Black, printArea, sf); //title
196
197 // move down
198 int titleHeight = (int)g.MeasureString(title, fTitle, printArea.Width).Height;
199 printArea.Y += titleHeight;
200 printArea.Height -= titleHeight;
201
202 // draw underline
203 g.DrawLine(Pens.Black, printArea.Location, new Point(printArea.Right, printArea.Y));
204 printArea.Y += 15;
205 printArea.Height -= 15;
206
207 // write appointment date
208 string str = "Appointment Date: " + ptRow.OldApptDate + "\n\n";
209 g.DrawString(str, fBody, Brushes.Black, printArea);
210
211 // move down
212 int strHeight = (int)g.MeasureString(str, fBody, printArea.Width).Height;
213 printArea.Y += strHeight;
214 printArea.Height -= strHeight;
215
216 //Text Direction
217 StringFormat sf2 = new StringFormat();
218 if (System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.IsRightToLeft)
219 sf2.FormatFlags = StringFormatFlags.DirectionRightToLeft;
220
221 // write missive
222 g.DrawString(letter, fBody, Brushes.Black, printArea, sf2);
223
224 //print Address in lower left corner for windowed envolopes
225 printArea.Location = new Point(e.MarginBounds.X, (int)(e.PageBounds.Height * 0.66));
226 printArea.Height = (int)(e.MarginBounds.Height * 0.20);
227 sf.Alignment = StringAlignment.Near;
228 sf.LineAlignment = StringAlignment.Center;
229 StringBuilder address = new StringBuilder(100);
230 address.AppendLine(ptRow.Name);
231 address.AppendLine(ptRow.STREET);
232 address.AppendLine(ptRow.CITY + ", " + ptRow.STATE + " " + ptRow.ZIP);
233 g.DrawString(address.ToString(), fBody, Brushes.Black, printArea, sf);
234 }
235
236 /// <summary>
237 /// Print rebook letters. Prints old and new appointments dates then the missive.
238 /// </summary>
239 /// <param name="ptRow">Strongly typed appointment row</param>
240 /// <param name="e">etc</param>
241 /// <param name="letter">Text of the letter to print</param>
242 /// <param name="title">Title to print at the top of the letter</param>
243 public static void PrintRebookLetter(dsRebookAppts.PatientApptsRow ptRow, PrintPageEventArgs e, string letter, string title)
244 {
245 Rectangle printArea = e.MarginBounds;
246 Graphics g = e.Graphics;
247 StringFormat sf = new StringFormat();
248 sf.Alignment = StringAlignment.Center; //for title
249 Font fTitle = new Font(FontFamily.GenericSerif, 24, FontStyle.Bold); //for title
250 Font fBody = new Font(FontFamily.GenericSerif, 12);
251 g.DrawString(title, fTitle, Brushes.Black, printArea, sf); //title
252
253 // move down
254 int titleHeight = (int)g.MeasureString(title, fTitle, printArea.Width).Height;
255 printArea.Y += titleHeight;
256 printArea.Height -= titleHeight;
257
258 // draw underline
259 g.DrawLine(Pens.Black, printArea.Location, new Point(printArea.Right, printArea.Y));
260 printArea.Y += 15;
261 printArea.Height -= 15;
262
263 // write old and new appointment dates
264 string str = "Old Appointment Date:\t\t" + ptRow.OldApptDate + "\n";
265 str += "New Appointment Date:\t\t" + ptRow.NewApptDate + "\n\n";
266 g.DrawString(str, fBody, Brushes.Black, printArea);
267
268 // move down
269 int strHeight = (int)g.MeasureString(str, fBody, printArea.Width).Height;
270 printArea.Y += strHeight;
271 printArea.Height -= strHeight;
272
273 //Text Direction
274 StringFormat sf2 = new StringFormat();
275 if (System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.IsRightToLeft)
276 sf2.FormatFlags = StringFormatFlags.DirectionRightToLeft;
277
278 // write missive
279 g.DrawString(letter, fBody, Brushes.Black, printArea, sf2);
280
281 //print Address in lower left corner for windowed envolopes
282 printArea.Location = new Point(e.MarginBounds.X, (int)(e.PageBounds.Height * 0.66));
283 printArea.Height = (int)(e.MarginBounds.Height * 0.20);
284 sf.Alignment = StringAlignment.Near;
285 sf.LineAlignment = StringAlignment.Center;
286 StringBuilder address = new StringBuilder(100);
287 address.AppendLine(ptRow.Name);
288 address.AppendLine(ptRow.STREET);
289 address.AppendLine(ptRow.CITY + ", " + ptRow.STATE + " " + ptRow.ZIP);
290 g.DrawString(address.ToString(), fBody, Brushes.Black, printArea, sf);
291
292 }
293
294 /// <summary>
295 /// Print message on a page; typically that there are no appointments to be found.
296 /// Or just a test message to verify that printing works.
297 /// </summary>
298 /// <param name="msg">The exact string to print.</param>
299 /// <param name="e">Print Page event args</param>
300 public static void PrintMessage(string msg, PrintPageEventArgs e)
301 {
302 e.Graphics.DrawString(msg, new Font(FontFamily.GenericSerif, 14),
303 Brushes.Black, e.MarginBounds);
304 }
305
306 /// <summary>
307 /// Print Routing Slip
308 /// </summary>
309 /// <param name="a">Appointment Data Structure</param>
310 /// <param name="title">String to print for title</param>
311 /// <param name="e">etc</param>
312 public static void PrintRoutingSlip(CGAppointment a, string title, PrintPageEventArgs e)
313 {
314 Rectangle printArea = e.MarginBounds;
315 Graphics g = e.Graphics;
316 StringFormat sf = new StringFormat();
317 sf.Alignment = StringAlignment.Center; //for title
318 Font fTitle = new Font(FontFamily.GenericSerif, 24, FontStyle.Bold); //for title
319 Font fBody = new Font(FontFamily.GenericSerif, 18);
320 Font fBodyEm = new Font(FontFamily.GenericSerif, 18, FontStyle.Bold);
321 g.DrawString(title, fTitle, Brushes.Black, printArea, sf); //title
322
323 // move down
324 int titleHeight = (int)g.MeasureString(title, fTitle, printArea.Width).Height;
325 printArea.Y += titleHeight;
326 printArea.Height -= titleHeight;
327
328 // draw underline
329 g.DrawLine(Pens.Black, printArea.Location, new Point(printArea.Right, printArea.Y));
330
331 // move down
332 printArea.Y += 15;
333 printArea.Height -= 15;
334
335 //construct what to print
336 string toprint = "Patient: " + a.PatientName + "\t" + "ID: " + a.HealthRecordNumber;
337 toprint += "\n\n";
338 toprint += "Clinic: " + a.Resource;
339 toprint += "\n\n";
340 toprint += "Appointment Time: " + a.StartTime;
341 toprint += "\n\n";
342 toprint += "Notes:\n" + a.Note;
343
344 //print
345 g.DrawString(toprint, fBody, Brushes.Black, printArea);
346
347 // Print Date Printed
348 //sf to move to bottom center
349 StringFormat sf2 = new StringFormat();
350 sf2.LineAlignment = StringAlignment.Far;
351 sf2.Alignment = StringAlignment.Center;
352
353 //Print
354 Font fFooter = new Font(FontFamily.GenericSerif, 8);
355 g.DrawString("Printed: " + DateTime.Now, fFooter, Brushes.Black, printArea, sf2);
356
357 }
358 }
359}
Note: See TracBrowser for help on using the repository browser.