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

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

CalendarGrid:

  • Support for Autoscrolling corrected.
  • A little optimization: Grid is only drawn once now when starting, not twice (don't know why original code did that).

CGAppointment:

  • Added member Patient (new Class)

CGDocument:

  • OnOpenDocument now accepts input of DateTime to decide where to open document.
  • SlotsAvailable algorithm now includes code for scaling according to timescale and code to merge Blocks if they are adjacent.

CGDocumentManager:

  • Fix bug having to do with canceling log-in after first retry. BMX lib threw an exception which was not caught.

CGView: Many changes:

  • SlotsAvailable signature changed in CGDocument. All references to it had to be changed.
  • Opening a node in the tvSchedules by clicking on the plus sign did not select it. Code changes to make it select it.
  • UpdateStatusBar now uses a string builder; and shows a more comprehensive message on the availability in the Status Bar.
  • Focus issues on various controls.
  • Support for printing a slip after an appointment is made automatically has been added.

CustomPrinting:

  • now includes a method to print a single appointment slip

DAppointPage:

  • Checkbox to decide whether to print appt slip added.
  • New readonly property to get the appointment that has been made (of type CGAppointment).

DApptSearch:

  • StartDate and EndDate now autoadjust based on each other.
  • lblMessage added to show user message if no appointments are found.
File size: 18.0 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 /// Prints a single appointment slip to give to the patient
117 /// </summary>
118 /// <param name="appt">The Appointment to print</param>
119 /// <param name="e">PrintPageEventArgs from PrintDocument Print handler</param>
120 public virtual void PrintAppointmentSlip(CGAppointment appt, PrintPageEventArgs e)
121 {
122 Rectangle printArea = e.MarginBounds;
123 Graphics g = e.Graphics;
124 StringFormat sf = new StringFormat();
125 sf.Alignment = StringAlignment.Center; //for title
126 Font fTitle = new Font(FontFamily.GenericSerif, 24, FontStyle.Bold); //for title
127 Font fBody = new Font(FontFamily.GenericSerif, 12);
128 string s = "Appointment Reminder Slip";
129 g.DrawString(s, fTitle, Brushes.Black, printArea, sf); //title
130
131 // move down
132 int titleHeight = (int)g.MeasureString(s, fTitle, printArea.Width).Height;
133 printArea.Y += titleHeight;
134 printArea.Height -= titleHeight;
135
136 // draw underline
137 g.DrawLine(Pens.Black, printArea.Location, new Point(printArea.Right, printArea.Y));
138 printArea.Y += 15;
139 printArea.Height -= 15;
140
141
142
143 }
144
145
146 /// <summary>
147 /// Print Letter to be given or mailed to the patient
148 /// </summary>
149 /// <param name="ptrow">Strongly typed PatientApptsRow to pass (just one ApptRow)</param>
150 /// <param name="e">You know what that is</param>
151 /// <param name="letter">Contains letter string</param>
152 /// <param name="title">Title of the letter</param>
153 public virtual void PrintReminderLetter(dsPatientApptDisplay2.PatientApptsRow ptRow, PrintPageEventArgs e, string letter, string title)
154 {
155
156 Rectangle printArea = e.MarginBounds;
157 Graphics g = e.Graphics;
158 StringFormat sf = new StringFormat();
159 sf.Alignment = StringAlignment.Center; //for title
160 Font fTitle = new Font(FontFamily.GenericSerif, 24, FontStyle.Bold); //for title
161 Font fBody = new Font(FontFamily.GenericSerif, 12);
162 g.DrawString(title, fTitle, Brushes.Black, printArea, sf); //title
163
164 // move down
165 int titleHeight = (int)g.MeasureString(title, fTitle, printArea.Width).Height;
166 printArea.Y += titleHeight;
167 printArea.Height -= titleHeight;
168
169 // draw underline
170 g.DrawLine(Pens.Black, printArea.Location, new Point(printArea.Right, printArea.Y));
171 printArea.Y += 15;
172 printArea.Height -= 15;
173
174 // write appointment date
175 string str = "Appointment Date: " + ptRow.ApptDate + "\n\n";
176 g.DrawString(str, fBody, Brushes.Black, printArea);
177
178 // move down
179 int strHeight = (int)g.MeasureString(str, fBody, printArea.Width).Height;
180 printArea.Y += strHeight;
181 printArea.Height -= strHeight;
182
183 //Text Direction
184 StringFormat sf2 = new StringFormat();
185 if (System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.IsRightToLeft)
186 sf2.FormatFlags = StringFormatFlags.DirectionRightToLeft;
187
188 // write missive
189 g.DrawString(letter, fBody, Brushes.Black, printArea, sf2);
190
191 //print Address in lower left corner for windowed envolopes
192 printArea.Location = new Point(e.MarginBounds.X, (int)(e.PageBounds.Height * 0.66));
193 printArea.Height = (int)(e.MarginBounds.Height * 0.20);
194 sf.Alignment = StringAlignment.Near;
195 sf.LineAlignment = StringAlignment.Center;
196 StringBuilder address = new StringBuilder(100);
197 address.AppendLine(ptRow.Name);
198 address.AppendLine(ptRow.STREET);
199 address.AppendLine(ptRow.CITY + ", " + ptRow.STATE + " " + ptRow.ZIP);
200 g.DrawString(address.ToString(), fBody, Brushes.Black, printArea, sf);
201 }
202
203 /// <summary>
204 /// Cancellation Letter to be given or mailed to the patient
205 /// </summary>
206 /// <param name="ptRow">Strongly typed PatientApptsRow to pass (just one ApptRow)</param>
207 /// <param name="e">You know what that is</param>
208 /// <param name="letter">Contains letter string</param>
209 /// <param name="title">Title of the letter</param>
210 public virtual void PrintCancelLetter(dsRebookAppts.PatientApptsRow ptRow, PrintPageEventArgs e, string letter, string title)
211 {
212 Rectangle printArea = e.MarginBounds;
213 Graphics g = e.Graphics;
214 StringFormat sf = new StringFormat();
215 sf.Alignment = StringAlignment.Center; //for title
216 Font fTitle = new Font(FontFamily.GenericSerif, 24, FontStyle.Bold); //for title
217 Font fBody = new Font(FontFamily.GenericSerif, 12);
218 g.DrawString(title, fTitle, Brushes.Black, printArea, sf); //title
219
220 // move down
221 int titleHeight = (int)g.MeasureString(title, fTitle, printArea.Width).Height;
222 printArea.Y += titleHeight;
223 printArea.Height -= titleHeight;
224
225 // draw underline
226 g.DrawLine(Pens.Black, printArea.Location, new Point(printArea.Right, printArea.Y));
227 printArea.Y += 15;
228 printArea.Height -= 15;
229
230 // write appointment date
231 string str = "Appointment Date: " + ptRow.OldApptDate + "\n\n";
232 g.DrawString(str, fBody, Brushes.Black, printArea);
233
234 // move down
235 int strHeight = (int)g.MeasureString(str, fBody, printArea.Width).Height;
236 printArea.Y += strHeight;
237 printArea.Height -= strHeight;
238
239 //Text Direction
240 StringFormat sf2 = new StringFormat();
241 if (System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.IsRightToLeft)
242 sf2.FormatFlags = StringFormatFlags.DirectionRightToLeft;
243
244 // write missive
245 g.DrawString(letter, fBody, Brushes.Black, printArea, sf2);
246
247 //print Address in lower left corner for windowed envolopes
248 printArea.Location = new Point(e.MarginBounds.X, (int)(e.PageBounds.Height * 0.66));
249 printArea.Height = (int)(e.MarginBounds.Height * 0.20);
250 sf.Alignment = StringAlignment.Near;
251 sf.LineAlignment = StringAlignment.Center;
252 StringBuilder address = new StringBuilder(100);
253 address.AppendLine(ptRow.Name);
254 address.AppendLine(ptRow.STREET);
255 address.AppendLine(ptRow.CITY + ", " + ptRow.STATE + " " + ptRow.ZIP);
256 g.DrawString(address.ToString(), fBody, Brushes.Black, printArea, sf);
257 }
258
259 /// <summary>
260 /// Print rebook letters. Prints old and new appointments dates then the missive.
261 /// </summary>
262 /// <param name="ptRow">Strongly typed appointment row</param>
263 /// <param name="e">etc</param>
264 /// <param name="letter">Text of the letter to print</param>
265 /// <param name="title">Title to print at the top of the letter</param>
266 public virtual void PrintRebookLetter(dsRebookAppts.PatientApptsRow ptRow, PrintPageEventArgs e, string letter, string title)
267 {
268 Rectangle printArea = e.MarginBounds;
269 Graphics g = e.Graphics;
270 StringFormat sf = new StringFormat();
271 sf.Alignment = StringAlignment.Center; //for title
272 Font fTitle = new Font(FontFamily.GenericSerif, 24, FontStyle.Bold); //for title
273 Font fBody = new Font(FontFamily.GenericSerif, 12);
274 g.DrawString(title, fTitle, Brushes.Black, printArea, sf); //title
275
276 // move down
277 int titleHeight = (int)g.MeasureString(title, fTitle, printArea.Width).Height;
278 printArea.Y += titleHeight;
279 printArea.Height -= titleHeight;
280
281 // draw underline
282 g.DrawLine(Pens.Black, printArea.Location, new Point(printArea.Right, printArea.Y));
283 printArea.Y += 15;
284 printArea.Height -= 15;
285
286 // write old and new appointment dates
287 string str = "Old Appointment Date:\t\t" + ptRow.OldApptDate + "\n";
288 str += "New Appointment Date:\t\t" + ptRow.NewApptDate + "\n\n";
289 g.DrawString(str, fBody, Brushes.Black, printArea);
290
291 // move down
292 int strHeight = (int)g.MeasureString(str, fBody, printArea.Width).Height;
293 printArea.Y += strHeight;
294 printArea.Height -= strHeight;
295
296 //Text Direction
297 StringFormat sf2 = new StringFormat();
298 if (System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.IsRightToLeft)
299 sf2.FormatFlags = StringFormatFlags.DirectionRightToLeft;
300
301 // write missive
302 g.DrawString(letter, fBody, Brushes.Black, printArea, sf2);
303
304 //print Address in lower left corner for windowed envolopes
305 printArea.Location = new Point(e.MarginBounds.X, (int)(e.PageBounds.Height * 0.66));
306 printArea.Height = (int)(e.MarginBounds.Height * 0.20);
307 sf.Alignment = StringAlignment.Near;
308 sf.LineAlignment = StringAlignment.Center;
309 StringBuilder address = new StringBuilder(100);
310 address.AppendLine(ptRow.Name);
311 address.AppendLine(ptRow.STREET);
312 address.AppendLine(ptRow.CITY + ", " + ptRow.STATE + " " + ptRow.ZIP);
313 g.DrawString(address.ToString(), fBody, Brushes.Black, printArea, sf);
314
315 }
316
317 /// <summary>
318 /// Print message on a page; typically that there are no appointments to be found.
319 /// Or just a test message to verify that printing works.
320 /// </summary>
321 /// <param name="msg">The exact string to print.</param>
322 /// <param name="e">Print Page event args</param>
323 public virtual void PrintMessage(string msg, PrintPageEventArgs e)
324 {
325 e.Graphics.DrawString(msg, new Font(FontFamily.GenericSerif, 14),
326 Brushes.Black, e.MarginBounds);
327 }
328
329 /// <summary>
330 /// Print Routing Slip
331 /// </summary>
332 /// <param name="a">Appointment Data Structure</param>
333 /// <param name="title">String to print for title</param>
334 /// <param name="e">etc</param>
335 public virtual void PrintRoutingSlip(CGAppointment a, string title, PrintPageEventArgs e)
336 {
337 Rectangle printArea = e.MarginBounds;
338 Graphics g = e.Graphics;
339 StringFormat sf = new StringFormat();
340 sf.Alignment = StringAlignment.Center; //for title
341 Font fTitle = new Font(FontFamily.GenericSerif, 24, FontStyle.Bold); //for title
342 Font fBody = new Font(FontFamily.GenericSerif, 18);
343 Font fBodyEm = new Font(FontFamily.GenericSerif, 18, FontStyle.Bold);
344 g.DrawString(title, fTitle, Brushes.Black, printArea, sf); //title
345
346 // move down
347 int titleHeight = (int)g.MeasureString(title, fTitle, printArea.Width).Height;
348 printArea.Y += titleHeight;
349 printArea.Height -= titleHeight;
350
351 // draw underline
352 g.DrawLine(Pens.Black, printArea.Location, new Point(printArea.Right, printArea.Y));
353
354 // move down
355 printArea.Y += 15;
356 printArea.Height -= 15;
357
358 //construct what to print
359 string toprint = "Patient: " + a.PatientName + "\t" + "ID: " + a.HealthRecordNumber;
360 toprint += "\n\n";
361 toprint += "Clinic: " + a.Resource;
362 toprint += "\n\n";
363 toprint += "Appointment Time: " + a.StartTime;
364 toprint += "\n\n";
365 toprint += "Notes:\n" + a.Note;
366
367 //print
368 g.DrawString(toprint, fBody, Brushes.Black, printArea);
369
370 // Print Date Printed
371 //sf to move to bottom center
372 StringFormat sf2 = new StringFormat();
373 sf2.LineAlignment = StringAlignment.Far;
374 sf2.Alignment = StringAlignment.Center;
375
376 //Print
377 Font fFooter = new Font(FontFamily.GenericSerif, 8);
378 g.DrawString("Printed: " + DateTime.Now, fFooter, Brushes.Black, printArea, sf2);
379 }
380
381 }
382 public abstract class PrintingCreator
383 {
384 public abstract CustomPrinting PrintFactory();
385 }
386
387}
Note: See TracBrowser for help on using the repository browser.