source: Scheduling/trunk/cs/bsdx0200GUISourceCode/CustomPrinting.cs@ 1091

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