source: Scheduling/branches/GUI1.2/Printing.cs@ 1071

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

Support for Routing Slip printing.
Version change from 1.1 to 1.2 in preparation for release.
Printing.cs: Addition of PrintRoutingSlip method.
CGView.cs: Handling of printing of routing slip if chosen in DCheckIn.cs
CGView.cs: New context option to re-print routing slip
DCheckIn.cs: toolTip1 to explain that routing slip will print on the default printer.

File size: 16.1 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.ToString("dd-MMM-yyyy") + "\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 // write missive
161 g.DrawString(letter, fBody, Brushes.Black, printArea);
162
163 //print Address in lower left corner for windowed envolopes
164 printArea.Location = new Point(e.MarginBounds.X, (int)(e.PageBounds.Height * 0.66));
165 printArea.Height = (int)(e.MarginBounds.Height * 0.20);
166 sf.Alignment = StringAlignment.Near;
167 sf.LineAlignment = StringAlignment.Center;
168 StringBuilder address = new StringBuilder(100);
169 address.AppendLine(ptRow.Name);
170 address.AppendLine(ptRow.STREET);
171 address.AppendLine(ptRow.CITY + ", " + ptRow.STATE + " " + ptRow.ZIP);
172 g.DrawString(address.ToString(), fBody, Brushes.Black, printArea, sf);
173 }
174
175 /// <summary>
176 /// Cancellation Letter to be given or mailed to the patient
177 /// </summary>
178 /// <param name="ptRow">Strongly typed PatientApptsRow to pass (just one ApptRow)</param>
179 /// <param name="e">You know what that is</param>
180 /// <param name="letter">Contains letter string</param>
181 /// <param name="title">Title of the letter</param>
182 public static void PrintCancelLetter(dsRebookAppts.PatientApptsRow ptRow, PrintPageEventArgs e, string letter, string title)
183 {
184 Rectangle printArea = e.MarginBounds;
185 Graphics g = e.Graphics;
186 StringFormat sf = new StringFormat();
187 sf.Alignment = StringAlignment.Center; //for title
188 Font fTitle = new Font(FontFamily.GenericSerif, 24, FontStyle.Bold); //for title
189 Font fBody = new Font(FontFamily.GenericSerif, 12);
190 g.DrawString(title, fTitle, Brushes.Black, printArea, sf); //title
191
192 // move down
193 int titleHeight = (int)g.MeasureString(title, fTitle, printArea.Width).Height;
194 printArea.Y += titleHeight;
195 printArea.Height -= titleHeight;
196
197 // draw underline
198 g.DrawLine(Pens.Black, printArea.Location, new Point(printArea.Right, printArea.Y));
199 printArea.Y += 15;
200 printArea.Height -= 15;
201
202 // write appointment date
203 string str = "Appointment Date: " + ptRow.OldApptDate + "\n\n";
204 g.DrawString(str, fBody, Brushes.Black, printArea);
205
206 // move down
207 int strHeight = (int)g.MeasureString(str, fBody, printArea.Width).Height;
208 printArea.Y += strHeight;
209 printArea.Height -= strHeight;
210
211 // write missive
212 g.DrawString(letter, fBody, Brushes.Black, printArea);
213
214 //print Address in lower left corner for windowed envolopes
215 printArea.Location = new Point(e.MarginBounds.X, (int)(e.PageBounds.Height * 0.66));
216 printArea.Height = (int)(e.MarginBounds.Height * 0.20);
217 sf.Alignment = StringAlignment.Near;
218 sf.LineAlignment = StringAlignment.Center;
219 StringBuilder address = new StringBuilder(100);
220 address.AppendLine(ptRow.Name);
221 address.AppendLine(ptRow.STREET);
222 address.AppendLine(ptRow.CITY + ", " + ptRow.STATE + " " + ptRow.ZIP);
223 g.DrawString(address.ToString(), fBody, Brushes.Black, printArea, sf);
224 }
225
226 /// <summary>
227 /// Print rebook letters. Prints old and new appointments dates then the missive.
228 /// </summary>
229 /// <param name="ptRow">Strongly typed appointment row</param>
230 /// <param name="e">etc</param>
231 /// <param name="letter">Text of the letter to print</param>
232 /// <param name="title">Title to print at the top of the letter</param>
233 public static void PrintRebookLetter(dsRebookAppts.PatientApptsRow ptRow, PrintPageEventArgs e, string letter, string title)
234 {
235 Rectangle printArea = e.MarginBounds;
236 Graphics g = e.Graphics;
237 StringFormat sf = new StringFormat();
238 sf.Alignment = StringAlignment.Center; //for title
239 Font fTitle = new Font(FontFamily.GenericSerif, 24, FontStyle.Bold); //for title
240 Font fBody = new Font(FontFamily.GenericSerif, 12);
241 g.DrawString(title, fTitle, Brushes.Black, printArea, sf); //title
242
243 // move down
244 int titleHeight = (int)g.MeasureString(title, fTitle, printArea.Width).Height;
245 printArea.Y += titleHeight;
246 printArea.Height -= titleHeight;
247
248 // draw underline
249 g.DrawLine(Pens.Black, printArea.Location, new Point(printArea.Right, printArea.Y));
250 printArea.Y += 15;
251 printArea.Height -= 15;
252
253 // write old and new appointment dates
254 string str = "Old Appointment Date:\t\t" + ptRow.OldApptDate + "\n";
255 str += "New Appointment Date:\t\t" + ptRow.NewApptDate + "\n\n";
256 g.DrawString(str, fBody, Brushes.Black, printArea);
257
258 // move down
259 int strHeight = (int)g.MeasureString(str, fBody, printArea.Width).Height;
260 printArea.Y += strHeight;
261 printArea.Height -= strHeight;
262
263 // write missive
264 g.DrawString(letter, fBody, Brushes.Black, printArea);
265
266 //print Address in lower left corner for windowed envolopes
267 printArea.Location = new Point(e.MarginBounds.X, (int)(e.PageBounds.Height * 0.66));
268 printArea.Height = (int)(e.MarginBounds.Height * 0.20);
269 sf.Alignment = StringAlignment.Near;
270 sf.LineAlignment = StringAlignment.Center;
271 StringBuilder address = new StringBuilder(100);
272 address.AppendLine(ptRow.Name);
273 address.AppendLine(ptRow.STREET);
274 address.AppendLine(ptRow.CITY + ", " + ptRow.STATE + " " + ptRow.ZIP);
275 g.DrawString(address.ToString(), fBody, Brushes.Black, printArea, sf);
276
277 }
278
279 /// <summary>
280 /// Print message on a page; typically that there are no appointments to be found.
281 /// Or just a test message to verify that printing works.
282 /// </summary>
283 /// <param name="msg">The exact string to print.</param>
284 /// <param name="e">Print Page event args</param>
285 public static void PrintMessage(string msg, PrintPageEventArgs e)
286 {
287 e.Graphics.DrawString(msg, new Font(FontFamily.GenericSerif, 14),
288 Brushes.Black, e.MarginBounds);
289 }
290
291 /// <summary>
292 /// Print Routing Slip
293 /// </summary>
294 /// <param name="a">Appointment Data Structure</param>
295 /// <param name="title">String to print for title</param>
296 /// <param name="e">etc</param>
297 public static void PrintRoutingSlip(CGAppointment a, string title, PrintPageEventArgs e)
298 {
299 Rectangle printArea = e.MarginBounds;
300 Graphics g = e.Graphics;
301 StringFormat sf = new StringFormat();
302 sf.Alignment = StringAlignment.Center; //for title
303 Font fTitle = new Font(FontFamily.GenericSerif, 24, FontStyle.Bold); //for title
304 Font fBody = new Font(FontFamily.GenericSerif, 18);
305 Font fBodyEm = new Font(FontFamily.GenericSerif, 18, FontStyle.Bold);
306 g.DrawString(title, fTitle, Brushes.Black, printArea, sf); //title
307
308 // move down
309 int titleHeight = (int)g.MeasureString(title, fTitle, printArea.Width).Height;
310 printArea.Y += titleHeight;
311 printArea.Height -= titleHeight;
312
313 // draw underline
314 g.DrawLine(Pens.Black, printArea.Location, new Point(printArea.Right, printArea.Y));
315 printArea.Y += 15;
316 printArea.Height -= 15;
317
318 //construct what to print
319 string toprint = "Patient: " + a.PatientName + "\t" + "ID: " + a.PatientID;
320 toprint += "\n\n";
321 toprint += "Appointment Time: " + a.StartTime.ToLongDateString() + " " + a.StartTime.ToLongTimeString();
322 toprint += "\n\n";
323 toprint += "Notes:\n" + a.Note;
324
325 //print
326 g.DrawString(toprint, fBody, Brushes.Black, printArea);
327
328 // Print Date Printed
329 //sf to move to bottom center
330 StringFormat sf2 = new StringFormat();
331 sf2.LineAlignment = StringAlignment.Far;
332 sf2.Alignment = StringAlignment.Center;
333
334 //Print
335 Font fFooter = new Font(FontFamily.GenericSerif, 8);
336 g.DrawString("Printed: " + DateTime.Now, fFooter, Brushes.Black, printArea, sf2);
337
338 }
339 }
340}
Note: See TracBrowser for help on using the repository browser.