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

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

Some debugging code to attach the program to the console to print messages.
Letters:

  • Cancellation letters now work.
  • Initial work on Rebook Letters.
File size: 10.3 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 missive
152 g.DrawString(letter, fBody, Brushes.Black, printArea);
153
154 //print Address in lower left corner for windowed envolopes
155 printArea.Location = new Point(e.MarginBounds.X, (int)(e.PageBounds.Height * 0.66));
156 printArea.Height = (int)(e.MarginBounds.Height * 0.20);
157 sf.Alignment = StringAlignment.Near;
158 sf.LineAlignment = StringAlignment.Center;
159 StringBuilder address = new StringBuilder(100);
160 address.AppendLine(ptRow.Name);
161 address.AppendLine(ptRow.STREET);
162 address.AppendLine(ptRow.CITY + ", " + ptRow.STATE + " " + ptRow.ZIP);
163 g.DrawString(address.ToString(), fBody, Brushes.Black, printArea, sf);
164 }
165
166 /// <summary>
167 /// Print Letter to be given or mailed to the patient
168 /// </summary>
169 /// <param name="ptrow">Strongly typed PatientApptsRow to pass (just one ApptRow)</param>
170 /// <param name="e">You know what that is</param>
171 /// <param name="letter">Contains letter string</param>
172 /// <param name="title">Title of the letter</param>
173 public static void PrintCancelLetter(dsRebookAppts.PatientApptsRow ptRow, PrintPageEventArgs e, string letter, string title)
174 {
175 Rectangle printArea = e.MarginBounds;
176 Graphics g = e.Graphics;
177 StringFormat sf = new StringFormat();
178 sf.Alignment = StringAlignment.Center; //for title
179 Font fTitle = new Font(FontFamily.GenericSerif, 24, FontStyle.Bold); //for title
180 Font fBody = new Font(FontFamily.GenericSerif, 12);
181 g.DrawString(title, fTitle, Brushes.Black, printArea, sf); //title
182
183 // move down
184 int titleHeight = (int)g.MeasureString(title, fTitle, printArea.Width).Height;
185 printArea.Y += titleHeight;
186 printArea.Height -= titleHeight;
187
188 // draw underline
189 g.DrawLine(Pens.Black, printArea.Location, new Point(printArea.Right, printArea.Y));
190 printArea.Y += 15;
191 printArea.Height -= 15;
192
193 // write missive
194 g.DrawString(letter, fBody, Brushes.Black, printArea);
195
196 //print Address in lower left corner for windowed envolopes
197 printArea.Location = new Point(e.MarginBounds.X, (int)(e.PageBounds.Height * 0.66));
198 printArea.Height = (int)(e.MarginBounds.Height * 0.20);
199 sf.Alignment = StringAlignment.Near;
200 sf.LineAlignment = StringAlignment.Center;
201 StringBuilder address = new StringBuilder(100);
202 address.AppendLine(ptRow.Name);
203 address.AppendLine(ptRow.STREET);
204 address.AppendLine(ptRow.CITY + ", " + ptRow.STATE + " " + ptRow.ZIP);
205 g.DrawString(address.ToString(), fBody, Brushes.Black, printArea, sf);
206 }
207
208 public static void PrintMessage(string msg, PrintPageEventArgs e)
209 {
210 e.Graphics.DrawString(msg, new Font(FontFamily.GenericSerif, 14),
211 Brushes.Black, e.MarginBounds);
212 }
213
214 }
215}
Note: See TracBrowser for help on using the repository browser.