Changeset 1469 for Scheduling/trunk/cs
- Timestamp:
- Jul 6, 2012, 12:23:58 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Scheduling/trunk/cs/bsdx0200GUISourceCode/Printing.cs
r1176 r1469 10 10 { 11 11 public partial class Printing 12 { 12 { 13 13 /// <summary> 14 14 /// Print Appointments … … 33 33 Font f10 = new Font(FontFamily.GenericSerif, 10); 34 34 Font f14bold = new Font(FontFamily.GenericSerif, 14, FontStyle.Bold); 35 35 36 36 //Center Alignment for some stuff 37 37 StringFormat sf = new StringFormat(); 38 38 sf.Alignment = StringAlignment.Center; 39 39 40 40 //Header 41 41 g.DrawString("Confidential Patient Information", f8, Brushes.Black, e.PageBounds, sf); 42 42 43 43 //Footer 44 44 sf.Alignment = StringAlignment.Center; … … 72 72 //resource we want to print 73 73 dsPatientApptDisplay2.BSDXResourceRow r = ds.BSDXResource[resourceToPrint]; 74 74 75 75 //header 76 76 string toprint; … … 79 79 + end.ToShortDateString(); 80 80 g.DrawString(toprint, f14bold, Brushes.Black, printArea); 81 81 82 82 //Move print area down 83 83 int titleHeight = (int)g.MeasureString(toprint, f14bold, printArea.Size).Height; … … 87 87 //Draw Line 88 88 g.DrawLine(new Pen(Brushes.Black, 0), printArea.X, printArea.Y, printArea.X + printArea.Width, printArea.Y); 89 89 90 90 //Move print area down 91 printArea.Y += 5; 91 printArea.Y += 5; 92 92 printArea.Height -= 5; 93 93 94 94 System.Data.DataRow[] appts = r.GetChildRows(ds.Relations[0]); //ds has only one relation 95 95 96 96 StringFormat sf2 = new StringFormat(); //sf to hold tab stops 97 sf2.SetTabStops(50, new float[] { 100, 250, 25 }); 97 sf2.SetTabStops(50, new float[] { 100, 250, 25 }); 98 98 99 99 //appt printed starts at zero … … 101 101 { 102 102 dsPatientApptDisplay2.PatientApptsRow a = (dsPatientApptDisplay2.PatientApptsRow)appts[apptPrinting]; 103 104 StringBuilder apptPrintStr = new StringBuilder(200); 103 104 StringBuilder apptPrintStr = new StringBuilder(200); 105 105 apptPrintStr.AppendLine(a.ApptDate.ToString() + "\t" + a.Name + " (" + a.Sex + ")" + "\t" + "DOB: " + a.DOB.ToShortDateString() + "\t" + "ID: " + a.HRN); 106 106 apptPrintStr.AppendLine("P: " + a.HOMEPHONE + "\t" + "Address: " + a.STREET + ", " + a.CITY + ", " + a.STATE + " " + a.ZIP); … … 110 110 int printedApptHeight = (int)g.MeasureString(apptPrintStr.ToString(), f10, printArea.Width).Height; 111 111 if (printedApptHeight > printArea.Height) // too much to print -- move to next page 112 113 112 // but don't increment the appointment to print since we haven't printed it yet. 113 // i.e. apptPrinting stays the same. 114 114 { 115 115 e.HasMorePages = true; 116 116 break; 117 117 } 118 118 119 119 //otherwise print it 120 120 g.DrawString(apptPrintStr.ToString(), f10, Brushes.Black, printArea, sf2); 121 121 122 122 //Move print area down 123 123 printArea.Y += printedApptHeight + 3; … … 148 148 public virtual void PrintAppointmentSlip(CGAppointment appt, PrintPageEventArgs e) 149 149 { 150 // Prep 150 // setting the reference values for calculating the needed ratio of the coming page. 151 //referrenceHeight and referrenceWidth for A6 size. 152 double referrenceHeight = 383; 153 double referrenceWidth = 213; 154 155 //check if the paper is landscape or portrait. if it is landscape then new ratio need to be calculated. 156 if (e.MarginBounds.Width > e.MarginBounds.Height) 157 { 158 //landscape = true; 159 referrenceHeight = 213; 160 referrenceWidth = 383; 161 //fontRatio = ((e.MarginBounds.Height) / referrenceHeight); 162 } 163 164 //setting the font,width and height ratios 165 double fontRatio = (e.MarginBounds.Height / referrenceHeight); 166 if (fontRatio > 1.0) 167 { 168 fontRatio = fontRatio * 0.75; 169 } 170 double widthRatio = ((e.MarginBounds.Width) / referrenceWidth); 171 double heightRatio = ((e.MarginBounds.Height) / referrenceHeight); 172 151 173 Graphics g = e.Graphics; 152 Rectangle printArea = e.MarginBounds; 153 Rectangle pageArea = e.PageBounds; 174 //this is the string which is used to fill with the data and to be print on the screen. 175 string stringData; 176 177 //in portrait we used fonts that fits with the A6 paper and changed depending on the page ratio,but in the land scape we used fonts fits with the A5 paper and counted the other pages depening on the ratios. 178 Font fontTitle = new Font(FontFamily.GenericSerif, (int)(13 * fontRatio), FontStyle.Bold); //for title 179 Font fontBody = new Font(FontFamily.GenericSerif, (int)(13 * fontRatio)); 180 Font fontGroupTitle = new Font(FontFamily.GenericSansSerif, (int)(13 * fontRatio), FontStyle.Bold); 181 Font fFooter = new Font(FontFamily.GenericSerif, (int)(7 * fontRatio)); 182 183 StringFormat sfCenterNear = new StringFormat() 184 { 185 Alignment = StringAlignment.Near, 186 LineAlignment = StringAlignment.Near 187 }; 188 189 StringFormat sfCenterCenter = new StringFormat() 190 { 191 Alignment = StringAlignment.Center, 192 LineAlignment = StringAlignment.Center 193 }; 194 195 StringFormat sfCenterFar = new StringFormat() 196 { 197 Alignment = StringAlignment.Far, 198 LineAlignment = StringAlignment.Near 199 }; 200 201 StringFormat sf3 = new StringFormat(System.Threading.Thread.CurrentThread.CurrentUICulture.TextInfo.IsRightToLeft ? StringFormatFlags.DirectionRightToLeft : 0); 202 sf3.SetDigitSubstitution(System.Threading.Thread.CurrentThread.CurrentUICulture.LCID, StringDigitSubstitute.Traditional); 203 204 205 //set the hard margin which different for each printer and multiplied with 2 206 int HardMarginX = 0; 207 if ((int)(e.PageSettings.HardMarginX) > 0) 208 { 209 HardMarginX=((int)(e.PageSettings.HardMarginX) *2); 210 } 211 int HardMarginY = 0; 212 if ((int)(e.PageSettings.HardMarginY) > 0) 213 { 214 HardMarginY = ((int)(e.PageSettings.HardMarginY) * 2); 215 } 216 217 // Draw Header 218 219 string division = CGDocumentManager.Current.ConnectInfo.DivisionName; 220 int divisionStringHeight = (int)g.MeasureString(division.ToString(), fontBody, e.PageBounds.Width - (int)(10 * widthRatio) - HardMarginX).Height; 221 154 222 Rectangle headerArea = new Rectangle() 155 223 { 156 X = e.MarginBounds.X, 157 Y = e.PageBounds.Y, 158 Height = e.MarginBounds.Y - e.PageBounds.Y - 50, 159 Width = e.MarginBounds.Width 160 }; 224 X = (int)(5 * widthRatio), 225 Y = (int)(5 * heightRatio), 226 Height = divisionStringHeight + (int)(5 * heightRatio), 227 Width = e.PageBounds.Width - (int)(10 * widthRatio) - HardMarginX 228 }; 229 g.DrawString(division, fontBody, Brushes.Black, headerArea, sfCenterNear); 230 231 //use stringData to print the footer (center all the way) 232 stringData = strings.Printed + ": " + DateTime.Now.ToString(); 233 int stringDataStringHeight = (int)g.MeasureString(stringData.ToString(), fFooter, e.MarginBounds.Width).Height; 161 234 Rectangle footerArea = new Rectangle() 162 235 { 163 X = e.MarginBounds.X, 164 Y = e.MarginBounds.Height + headerArea.Height, 165 Width = e.MarginBounds.Width, 166 Height = pageArea.Height - (e.MarginBounds.Height + headerArea.Height) 167 }; 168 169 string s; 170 171 // A few fonts 172 Font fTitle = new Font(FontFamily.GenericSerif, 24, FontStyle.Bold); //for title 173 Font fBody = new Font(FontFamily.GenericSerif, 12); 174 Font fGroupTitle = new Font(FontFamily.GenericSansSerif, 10, FontStyle.Bold); 175 176 StringFormat sfCenterCenter = new StringFormat() 177 { 178 Alignment = StringAlignment.Center, 179 LineAlignment = StringAlignment.Center 180 }; 181 182 // Draw Header 183 string division = CGDocumentManager.Current.ConnectInfo.DivisionName; 184 g.DrawString(division, fBody, Brushes.Black, headerArea, sfCenterCenter); 185 186 const int watermarkLength = 75; 236 X = headerArea.X, 237 Y = e.PageBounds.Height - stringDataStringHeight - HardMarginY - (int)(5 * heightRatio), 238 Width = headerArea.Width, 239 Height = stringDataStringHeight 240 }; 241 g.DrawString(stringData, fFooter, Brushes.Black, footerArea, sfCenterCenter); 242 243 //setting the printing area bigger than the margin bounds to use more printing space on the paper. 244 Rectangle printArea = new Rectangle() 245 { 246 X = headerArea.X, 247 Y = headerArea.Y+headerArea.Height, 248 Height = footerArea.Y-(headerArea.Y+headerArea.Height) - (int)(5 * heightRatio), 249 Width = headerArea.Width 250 }; 251 252 // if there is a need for the watermark use the following code. 253 //const int watermarkLength = 75*heightratio; 187 254 188 255 // Move down for optional form paper 189 printArea.Y += watermarkLength; 190 printArea.Height -= watermarkLength; 191 192 // Draw Title 193 StringFormat sfCenter = new StringFormat(); 194 sfCenter.Alignment = StringAlignment.Center; //for title & header 195 196 s = strings.ApptReminderSlip; 197 g.DrawString(s, fTitle, Brushes.Black, printArea, sfCenter); //title 198 199 // move down 200 int titleHeight = (int)g.MeasureString(s, fTitle, printArea.Width).Height; 256 //printArea.Y += watermarkLength; 257 //printArea.Height -= watermarkLength; 258 259 //// Draw Title 260 //StringFormat sfCenter = new StringFormat(); 261 //sfCenter.Alignment = StringAlignment.Center; //for title & header 262 263 //string data for the appointment slip title 264 stringData = strings.ApptReminderSlip; 265 g.DrawString(stringData, fontTitle, Brushes.Black, printArea, sfCenterFar); //title 266 267 //// move down 268 int titleHeight = (int)g.MeasureString(stringData, fontTitle, printArea.Width).Height; 201 269 printArea.Y += titleHeight; 202 270 printArea.Height -= titleHeight; … … 204 272 // draw underline 205 273 g.DrawLine(Pens.Black, printArea.Location, new Point(printArea.Right, printArea.Y)); 206 printArea.Y += 15; 207 printArea.Height -= 15; 208 209 // draw curved rectangle. 210 Rectangle personalInfoRectangle = new Rectangle(e.MarginBounds.X, printArea.Y + 30, 280, 300); 211 using (GraphicsPath path = GetRoundedRectPath(personalInfoRectangle, 10)) 274 printArea.Y += (int)(10 * heightRatio); 275 printArea.Height -= (int)(10 * heightRatio); 276 277 // building the string of the person information to write 278 StringBuilder personInformationString = new StringBuilder(500); 279 personInformationString.AppendLine(strings.Name + ":" + "\t" + appt.Patient.Name); 280 //personInformationString.AppendLine(); 281 stringData = appt.Patient.Sex == Sex.Male ? strings.Male : strings.Female; 282 personInformationString.AppendLine(strings.ID + ":" + "\t" + appt.Patient.ID + "\t" + "( " + stringData + " )"); 283 //personInformationString.AppendLine(); 284 stringData = appt.Patient.DOB.ToString("dd") + " " + appt.Patient.DOB.ToString("MMM") + ", " + appt.Patient.DOB.Year; 285 personInformationString.AppendLine(strings.DOB + ":" + "\t" + stringData); 286 //personInformationString.AppendLine(); 287 //personInformationString.AppendLine(strings.Age + ":" + "\t" + appt.Patient.UserFriendlyAge); 288 289 290 // building the string of the appointment information to write 291 StringBuilder appointmentInformationString = new StringBuilder(500); 292 appointmentInformationString = new StringBuilder(); 293 appointmentInformationString.AppendLine(strings.Clinic + ":" + "\t" + appt.Resource); 294 //appointmentInformationString.AppendLine(); 295 stringData = appt.StartTime.ToString("dddd") + " " + appt.StartTime.ToString("dd") + " " + appt.StartTime.ToString("MMM") + ", " + appt.StartTime.Year; 296 appointmentInformationString.AppendLine(strings.Date + ":" + "\t" + stringData); 297 //sb.AppendLine(); 298 //appointmentInformationString.AppendLine(strings.Day + ":" + "\t" + appt.StartTime.ToString("dddd")); 299 //sb.AppendLine(); 300 appointmentInformationString.AppendLine(strings.Time + ":" + "\t" + appt.StartTime.ToShortTimeString()); 301 302 303 //counting the width and hieght of the information inner aera for the person and appointment rectangels. 304 int InfoInnerRectangleWidth = (printArea.Width / 2 - printArea.X / 2) - (int)(10 * widthRatio); 305 306 //Counting the height of the two strings (PersontInformationStringappointment & InformationStringto)to be allocated to the InfoInnerRectangleHeight later. 307 int PersonInformationStringHeight = (int)g.MeasureString(personInformationString.ToString(), fontBody, InfoInnerRectangleWidth).Height; 308 int appointmentInformationStringHeight = (int)g.MeasureString(appointmentInformationString.ToString(), fontBody, InfoInnerRectangleWidth).Height; 309 310 int InfoInnerRectangleHeight = PersonInformationStringHeight; 311 if (appointmentInformationStringHeight > PersonInformationStringHeight) 312 { 313 InfoInnerRectangleHeight = appointmentInformationStringHeight; 314 } 315 316 // draw curved rectangle for the person informations. 317 Rectangle personalInfoRectangle = new Rectangle(printArea.X, printArea.Y, InfoInnerRectangleWidth + (int)(10 * widthRatio), InfoInnerRectangleHeight + (int)(10 * heightRatio)); 318 using (GraphicsPath path = GetRoundedRectPath(personalInfoRectangle, 5)) 212 319 { 213 320 g.DrawPath(Pens.Black, path); 214 321 } 215 216 // group header217 s = strings.PtInfo;218 StringFormat sf3 = new StringFormat(System.Threading.Thread.CurrentThread.CurrentUICulture.TextInfo.IsRightToLeft ? StringFormatFlags.DirectionRightToLeft : 0);219 g.DrawString(s, fGroupTitle, Brushes.Black, new Rectangle(personalInfoRectangle.X, personalInfoRectangle.Y - 20,personalInfoRectangle.Width, 20),sf3);220 322 221 323 // inner rectangle for drawing strings: 222 Rectangle personalInfoInnerRectangle = new Rectangle(personalInfoRectangle.X + 20, personalInfoRectangle.Y + 20, 280 - 40, 300 - 40); 223 224 // Strings to write 225 StringBuilder sb = new StringBuilder(500); 226 sb.AppendLine(strings.Name + ":" + "\t" + appt.Patient.Name); 227 sb.AppendLine(); 228 sb.AppendLine(strings.ID + ":" + "\t" + appt.Patient.ID); 229 sb.AppendLine(); 230 s = appt.Patient.DOB.ToString("dd") + " " + appt.Patient.DOB.ToString("MMM") + ", " + appt.Patient.DOB.Year; 231 sb.AppendLine(strings.DOB + ":" + "\t" + s); 232 sb.AppendLine(); 233 sb.AppendLine(strings.Age + ":" + "\t" + appt.Patient.UserFriendlyAge); 234 sb.AppendLine(); 235 s = appt.Patient.Sex == Sex.Male ? strings.Male : strings.Female; 236 sb.AppendLine(strings.Sex + ":" + "\t" + s); 237 238 // Draw them 239 sf3 = new StringFormat(System.Threading.Thread.CurrentThread.CurrentUICulture.TextInfo.IsRightToLeft ? StringFormatFlags.DirectionRightToLeft : 0); 240 sf3.SetTabStops(0, new float[] {75} ); 241 sf3.SetDigitSubstitution(System.Threading.Thread.CurrentThread.CurrentUICulture.LCID, StringDigitSubstitute.Traditional); 242 g.DrawString(sb.ToString(), fBody, Brushes.Black, personalInfoInnerRectangle, sf3); 243 244 // draw curved rectangle 245 Rectangle apptInfoRectangle = new Rectangle(e.MarginBounds.X + e.MarginBounds.Width - 280, printArea.Y + 30, 280, 300); 246 using (GraphicsPath path = GetRoundedRectPath(apptInfoRectangle, 10)) 324 Rectangle personalInfoInnerRectangle = new Rectangle(personalInfoRectangle.X + (int)(5 * widthRatio), personalInfoRectangle.Y + (int)(5 * heightRatio), InfoInnerRectangleWidth, InfoInnerRectangleHeight); 325 326 // Draw the preson informations. 327 //sf3.SetTabStops(0, new float[] {75} ); 328 329 g.DrawString(personInformationString.ToString(), fontBody, Brushes.Black, personalInfoInnerRectangle, sf3); 330 331 // draw curved rectangle for the appointment informations. 332 Rectangle apptInfoRectangle = new Rectangle((int)(printArea.X + personalInfoRectangle.Width + printArea.X), personalInfoRectangle.Y, personalInfoRectangle.Width, personalInfoRectangle.Height); 333 using (GraphicsPath path = GetRoundedRectPath(apptInfoRectangle, 5)) 247 334 { 248 335 g.DrawPath(Pens.Black, path); 249 336 } 250 337 251 s = strings.ApptInfo; 252 // group header 253 g.DrawString(s, fGroupTitle, Brushes.Black, new Rectangle(apptInfoRectangle.X, apptInfoRectangle.Y - 20,apptInfoRectangle.Width, 20), sf3); 254 255 // Strings to write 256 sb = new StringBuilder(); 257 sb.AppendLine(strings.Clinic + ":" + "\t" + appt.Resource); 258 sb.AppendLine(); 259 s = appt.StartTime.ToString("dd") + " " + appt.StartTime.ToString("MMM") + ", " + appt.StartTime.Year; 260 sb.AppendLine(strings.Date + ":" + "\t" + s); 261 sb.AppendLine(); 262 sb.AppendLine(strings.Day + ":" + "\t" + appt.StartTime.ToString("dddd")); 263 sb.AppendLine(); 264 sb.AppendLine(strings.Time + ":" + "\t" + appt.StartTime.ToShortTimeString()); 265 266 // Draw them 267 Rectangle apptInfoInnerRectangle = new Rectangle(apptInfoRectangle.X + 20, apptInfoRectangle.Y + 20, 280 - 40, 300 - 40); 268 269 // Draw them 270 g.DrawString(sb.ToString(), fBody, Brushes.Black, apptInfoInnerRectangle, sf3); 338 339 // Draw appointment informations in the inner rectangle. 340 Rectangle apptInfoInnerRectangle = new Rectangle(apptInfoRectangle.X + (int)(5 * widthRatio), apptInfoRectangle.Y + (int)(5 * heightRatio), InfoInnerRectangleWidth, InfoInnerRectangleHeight); 341 g.DrawString(appointmentInformationString.ToString(), fontBody, Brushes.Black, apptInfoInnerRectangle, sf3); 271 342 272 343 // Move Drawing Rectangle Down 273 printArea.Y += 300 + 30 + 20;274 printArea.Height -= 300 + 30 + 20;344 printArea.Y += personalInfoRectangle.Height + (int)(5 * heightRatio); 345 printArea.Height -= personalInfoRectangle.Height + (int)(5 * heightRatio); 275 346 276 347 // Draw New Line 277 348 g.DrawLine(Pens.Black, printArea.Location, new Point(printArea.Right, printArea.Y)); 278 printArea.Y += 5;279 printArea.Height -= 5;349 printArea.Y += (int)(5 * heightRatio); 350 printArea.Height -= (int)(5 * heightRatio); 280 351 281 352 // Draw new Title 282 s = strings.ClinicInstructions;283 g.DrawString(s, fTitle, Brushes.Black, printArea, sfCenter); //title284 353 stringData = strings.ClinicInstructions; 354 titleHeight = (int)g.MeasureString(stringData, fontTitle, printArea.Width).Height; 355 g.DrawString(stringData, fontTitle, Brushes.Black, printArea, sf3); //title 285 356 // move down 286 titleHeight = (int)g.MeasureString(s, fTitle, printArea.Width).Height;287 357 printArea.Y += titleHeight; 288 358 printArea.Height -= titleHeight; 289 290 // Draw New Line291 g.DrawLine(Pens.Black, printArea.Location, new Point(printArea.Right, printArea.Y));292 printArea.Y += 15;293 printArea.Height -= 15;294 359 295 360 // Get Resource Clinic Appointment Letter Text … … 301 366 302 367 if (String.IsNullOrWhiteSpace(ltrTxt)) ltrTxt = strings.NoInstructionsProvided; 303 304 g.DrawString(ltrTxt, fBody, Brushes.Black, printArea, sf3); 305 306 int ltrTxtHeight = (int)g.MeasureString(ltrTxt, fBody).Height; 307 308 printArea.Y += ltrTxtHeight + 15; 309 printArea.Height -= ltrTxtHeight + 15; 310 311 g.DrawLine(Pens.Black, printArea.Location, new Point(printArea.Right, printArea.Y)); 312 printArea.Y += 5; 313 printArea.Height -= 5; 314 315 s = strings.Notes; 316 g.DrawString(s, fTitle, Brushes.Black, printArea, sfCenter); // Notes title 317 318 // move down 319 titleHeight = (int)g.MeasureString(s, fTitle, printArea.Width).Height; 320 printArea.Y += titleHeight; 321 printArea.Height -= titleHeight; 322 323 // Draw New Line 324 g.DrawLine(Pens.Black, printArea.Location, new Point(printArea.Right, printArea.Y)); 325 printArea.Y += 15; 326 printArea.Height -= 15; 327 328 // Draw Notes Area 329 using (GraphicsPath path = GetRoundedRectPath(printArea, 15)) 330 { 331 g.DrawPath(Pens.Black, path); 332 } 333 334 //use sf0 to print the footer (center all the way) 335 s = strings.Printed + ": " + DateTime.Now.ToString(); 336 Font fFooter = new Font(FontFamily.GenericSerif, 7); 337 g.DrawString(s, fFooter, Brushes.Black, footerArea, sfCenterCenter); 338 368 int ltrTxtHeight = (int)g.MeasureString(ltrTxt, fontBody,printArea.Width).Height; 369 //setting the instructions area smaller than the printing area. 370 int instructionsAreaHeight = ltrTxtHeight; 371 //missingString true if there are no more printing area for the instructions and will use it to print a statement for it. 372 bool missingString = false; 373 string missingStringStatement = ""; 374 int missingStringStatementHeight = 0; 375 if (ltrTxtHeight > printArea.Height) 376 { 377 missingStringStatement = "etc..."; 378 missingStringStatementHeight = (int)g.MeasureString(missingStringStatement, fFooter, printArea.Width).Height; 379 instructionsAreaHeight = printArea.Height -missingStringStatementHeight- (int)(5 * heightRatio); 380 missingString = true; 381 } 382 Rectangle instructionsArea = new Rectangle() 383 { 384 X = printArea.X, 385 Y = printArea.Y, 386 Height = instructionsAreaHeight, 387 Width = printArea.Width 388 }; 389 g.DrawString(ltrTxt, fontBody, Brushes.Black, instructionsArea, sf3); 390 391 //moving down 392 printArea.Y += instructionsAreaHeight + (int)(5 * heightRatio); 393 printArea.Height -= instructionsAreaHeight + (int)(5 * heightRatio); 394 395 if (missingString) 396 { 397 g.DrawString(missingStringStatement, fFooter, Brushes.Black, printArea, sf3); //title 398 printArea.Y += missingStringStatementHeight; 399 printArea.Height -= missingStringStatementHeight; 400 } 401 //Draing new line 402 if (printArea.Height > 0) 403 { 404 g.DrawLine(Pens.Black, printArea.Location, new Point(printArea.Right, printArea.Y)); 405 printArea.Y += (int)(5 * heightRatio); 406 printArea.Height -= (int)(5 * heightRatio); 407 408 string noteStringData = strings.Notes; 409 int noteTitleHeight = (int)g.MeasureString(noteStringData, fontTitle, printArea.Width).Height; 410 411 //check if the remaining area height enugh for the notes 412 if (printArea.Height > ((int)(noteTitleHeight))) 413 { 414 //draw the note title. 415 g.DrawString(noteStringData, fontTitle, Brushes.Black, printArea, sf3); // Notes title 416 } 417 418 419 } 339 420 g.Dispose(); 340 421 } … … 344 425 { 345 426 int diameter = 2 * radius; 346 427 347 428 Rectangle arcRect = new Rectangle(rect.Location, new Size(diameter, diameter)); 348 429 GraphicsPath path = new GraphicsPath(); 349 430 350 431 path.AddArc(arcRect, 180, 90); //top left 351 432 arcRect.X = rect.Right - diameter; … … 383 464 printArea.Y += titleHeight; 384 465 printArea.Height -= titleHeight; 385 466 386 467 // draw underline 387 468 g.DrawLine(Pens.Black, printArea.Location, new Point(printArea.Right, printArea.Y)); … … 419 500 g.Dispose(); 420 501 } 421 502 422 503 /// <summary> 423 504 /// Cancellation Letter to be given or mailed to the patient … … 460 541 if (System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.IsRightToLeft) 461 542 sf2.FormatFlags = StringFormatFlags.DirectionRightToLeft; 462 543 463 544 // write missive 464 545 g.DrawString(letter, fBody, Brushes.Black, printArea, sf2); … … 558 639 public virtual void PrintRoutingSlip(CGAppointment appt, int apptOrder, PrintPageEventArgs e) 559 640 { 560 // Prep 641 // setting the reference values for calculating the needed ratio of the coming page. 642 //referrenceHeight and referrenceWidth for A6 size. 643 double referrenceHeight = 383; 644 double referrenceWidth = 213; 645 646 //check if the paper is landscape or portrait. if it is landscape then new ratio need to be calculated. 647 if (e.MarginBounds.Width > e.MarginBounds.Height) 648 { 649 //landscape = true; 650 referrenceHeight = 213; 651 referrenceWidth = 383; 652 //fontRatio = ((e.MarginBounds.Height) / referrenceHeight); 653 } 654 655 //setting the font,width and height ratios 656 double fontRatio = (e.MarginBounds.Height / referrenceHeight); 657 if (fontRatio > 1.0) 658 { 659 fontRatio = fontRatio * 0.75; 660 } 661 double widthRatio = ((e.MarginBounds.Width) / referrenceWidth); 662 double heightRatio = ((e.MarginBounds.Height) / referrenceHeight); 663 561 664 Graphics g = e.Graphics; 562 Rectangle printArea = e.MarginBounds; 563 Rectangle pageArea = e.PageBounds; 564 Rectangle headerArea = new Rectangle() 565 { 566 X = e.MarginBounds.X, 567 Y = e.PageBounds.Y, //0 568 Height = e.MarginBounds.Y - e.PageBounds.Y - 50, //100px - 50px 569 Width = e.MarginBounds.Width 570 }; 571 Rectangle footerArea = new Rectangle() 572 { 573 X = e.MarginBounds.X, 574 Y = e.MarginBounds.Height + headerArea.Height, 575 Width = e.MarginBounds.Width, 576 Height = pageArea.Height - (e.MarginBounds.Height + headerArea.Height) 577 }; 578 579 const int part1Height = 400; 580 string s; 581 582 // A few fonts 583 Font fTitle = new Font(FontFamily.GenericSerif, 24, FontStyle.Bold); //for title 584 Font fBody = new Font(FontFamily.GenericSerif, 12); 585 Font fGroupTitle = new Font(FontFamily.GenericSansSerif, 10, FontStyle.Bold); 586 587 StringFormat sf0 = new StringFormat() 665 //this is the string which is used to fill with the data and to be print on the screen. 666 string stringData; 667 668 //in portrait we used fonts that fits with the A6 paper and changed depending on the page ratio,but in the land scape we used fonts fits with the A5 paper and counted the other pages depening on the ratios. 669 Font fontTitle = new Font(FontFamily.GenericSerif, (int)(13 * fontRatio), FontStyle.Bold); //for title 670 Font fontBody = new Font(FontFamily.GenericSerif, (int)(13 * fontRatio)); 671 Font fontGroupTitle = new Font(FontFamily.GenericSansSerif, (int)(13 * fontRatio), FontStyle.Bold); 672 Font fFooter = new Font(FontFamily.GenericSerif, (int)(7 * fontRatio)); 673 674 StringFormat sfCenterCenter = new StringFormat() 588 675 { 589 676 Alignment = StringAlignment.Center, … … 591 678 }; 592 679 680 //set the hard margin which different for each printer and multiplied with 2 681 int HardMarginX = 0; 682 if ((int)(e.PageSettings.HardMarginX) > 0) 683 { 684 HardMarginX = ((int)(e.PageSettings.HardMarginX) * 2); 685 } 686 int HardMarginY = 0; 687 if ((int)(e.PageSettings.HardMarginY) > 0) 688 { 689 HardMarginY = ((int)(e.PageSettings.HardMarginY) * 2); 690 } 691 593 692 // Draw Header 594 693 string division = CGDocumentManager.Current.ConnectInfo.DivisionName; 595 g.DrawString(division, fBody, Brushes.Black, headerArea, sf0); 596 597 const int watermarkLength = 75; 694 int divisionStringHeight = (int)g.MeasureString(division.ToString(), fontBody, e.MarginBounds.Width).Height; 695 Rectangle headerArea = new Rectangle() 696 { 697 X = (int)(5 * widthRatio), 698 Y = (int)(5 * heightRatio), 699 Height = divisionStringHeight + (int)(5 * heightRatio), 700 Width = e.PageBounds.Width - (int)(10 * widthRatio) - HardMarginX 701 }; 702 g.DrawString(division, fontBody, Brushes.Black, headerArea, sfCenterCenter); 703 704 705 //use stringData to print the footer (center all the way) 706 stringData = strings.Printed + ": " + DateTime.Now.ToString(); 707 int stringDataStringHeight = (int)g.MeasureString(stringData.ToString(), fFooter, e.MarginBounds.Width).Height; 708 Rectangle footerArea = new Rectangle() 709 { 710 X = headerArea.X, 711 Y = e.PageBounds.Height - stringDataStringHeight - HardMarginY - (int)(5 * heightRatio), 712 Width = headerArea.Width, 713 Height = stringDataStringHeight 714 }; 715 g.DrawString(stringData, fFooter, Brushes.Black, footerArea, sfCenterCenter); 716 717 718 719 //setting the printing area bigger than the margin bounds to use more printing space on the paper. 720 Rectangle printArea = new Rectangle() 721 { 722 X = headerArea.X, 723 Y = headerArea.Y + headerArea.Height, 724 Height = footerArea.Y - (headerArea.Y + headerArea.Height) - (int)(5 * heightRatio), 725 Width = headerArea.Width 726 }; 727 728 729 // if there is a need for the watermark use the following code. 730 //const int watermarkLength = 75*heightratio; 598 731 599 732 // Move down for optional form paper 600 printArea.Y += watermarkLength;601 printArea.Height -= watermarkLength;733 //printArea.Y += watermarkLength; 734 //printArea.Height -= watermarkLength; 602 735 603 736 // Draw Title 604 StringFormat sf = new StringFormat();605 sf .Alignment = StringAlignment.Center; //for title & header737 StringFormat sfCenter = new StringFormat(); 738 sfCenter.Alignment = StringAlignment.Center; //for title & header 606 739 string title = strings.RoutingSlip; 607 g.DrawString(title, f Title, Brushes.Black, printArea, sf); //title740 g.DrawString(title, fontTitle, Brushes.Black, printArea, sfCenter); //title 608 741 609 742 // move down 610 int titleHeight = (int)g.MeasureString(title, f Title, printArea.Width).Height;743 int titleHeight = (int)g.MeasureString(title, fontTitle, printArea.Width).Height; 611 744 printArea.Y += titleHeight; 612 745 printArea.Height -= titleHeight; … … 614 747 // draw underline 615 748 g.DrawLine(Pens.Black, printArea.Location, new Point(printArea.Right, printArea.Y)); 616 printArea.Y += 15; 617 printArea.Height -= 15; 618 619 // draw curved rectangle. 620 Rectangle personalInfoRectangle = new Rectangle(e.MarginBounds.X, printArea.Y + 30, 280, part1Height); 621 using (GraphicsPath path = GetRoundedRectPath(personalInfoRectangle, 10)) 749 printArea.Y += (int)(5 * heightRatio); 750 printArea.Height -= (int)(5 * heightRatio); 751 752 // Strings to write 753 754 StringBuilder personInformationString = new StringBuilder(500); 755 personInformationString.AppendLine(strings.Name + ":" + "\t" + appt.Patient.Name); 756 //personInformationString.AppendLine(); 757 personInformationString.AppendLine(strings.ID + ":" + "\t" + appt.Patient.ID); 758 //personInformationString.AppendLine(); 759 stringData = appt.Patient.DOB.ToString("dd") + " " + appt.Patient.DOB.ToString("MMM") + ", " + appt.Patient.DOB.Year; 760 personInformationString.AppendLine(strings.DOB + ":" + "\t" + stringData); 761 //personInformationString.AppendLine(); 762 personInformationString.AppendLine(strings.Age + ":" + "\t" + appt.Patient.UserFriendlyAge); 763 //personInformationString.AppendLine(); 764 //personInformationString.AppendLine("Sex:" + "\t" + appt.Patient.Sex.ToString()); 765 766 // Strings to write 767 StringBuilder appointmentInformationString = new StringBuilder(); 768 appointmentInformationString.AppendLine(strings.Clinic + ":"); 769 appointmentInformationString.AppendLine(appt.Resource); 770 //appointmentInformationString.AppendLine(); 771 appointmentInformationString.AppendLine(strings.AppointmentProvider + ":"); 772 appointmentInformationString.AppendLine((appt.Provider == null) ? strings.none : appt.Provider.ToString()); //Appt Provider or (none) if null 773 //appointmentInformationString.AppendLine(); 774 appointmentInformationString.AppendLine(strings.PatientOrder + ":" + "\t" + apptOrder); 775 appointmentInformationString.AppendLine(strings.Date + ":" + "\t" + appt.StartTime.ToShortDateString() + " " + appt.StartTime.ToShortTimeString()); 776 //appointmentInformationString.AppendLine(); 777 appointmentInformationString.AppendLine(strings.AppointmentNote + ":"); 778 appointmentInformationString.AppendLine(String.IsNullOrWhiteSpace(appt.Note) ? strings.none : appt.Note); 779 780 //counting the width and hieght of the information inner aera for the person and appointment rectangels. 781 int InfoInnerRectangleWidth = (printArea.Width / 2 - printArea.X / 2) - (int)(10 * widthRatio); 782 783 //Counting the height of the two strings (PersontInformationStringappointment & InformationStringto)to be allocated to the InfoInnerRectangleHeight later. 784 int PersonInformationStringHeight = (int)g.MeasureString(personInformationString.ToString(), fontBody, InfoInnerRectangleWidth).Height; 785 int appointmentInformationStringHeight = (int)g.MeasureString(appointmentInformationString.ToString(), fontBody, InfoInnerRectangleWidth).Height; 786 787 int InfoInnerRectangleHeight = PersonInformationStringHeight; 788 if (appointmentInformationStringHeight > PersonInformationStringHeight) 789 { 790 InfoInnerRectangleHeight = appointmentInformationStringHeight; 791 } 792 793 // group header for the person informations. 794 stringData = strings.PtInfo; 795 StringFormat sf3 = new StringFormat(System.Threading.Thread.CurrentThread.CurrentUICulture.TextInfo.IsRightToLeft ? StringFormatFlags.DirectionRightToLeft : 0); 796 stringDataStringHeight = (int)g.MeasureString(stringData.ToString(), fontGroupTitle, InfoInnerRectangleWidth).Height; 797 g.DrawString(stringData, fontGroupTitle, Brushes.Black, new Rectangle(printArea.X, printArea.Y, InfoInnerRectangleWidth, stringDataStringHeight), sf3); 798 799 // group header for the appointment information 800 stringData = strings.ApptInfo; 801 g.DrawString(stringData, fontGroupTitle, Brushes.Black, new Rectangle((int)(printArea.X + (InfoInnerRectangleWidth + (int)(10 * widthRatio)) + printArea.X), printArea.Y, InfoInnerRectangleWidth, stringDataStringHeight), sf3); 802 803 //moving down 804 printArea.Y += stringDataStringHeight + (int)(5 * heightRatio); 805 printArea.Height -= stringDataStringHeight + (int)(5 * heightRatio); 806 807 // draw curved rectangle for the person informations. 808 Rectangle personalInfoRectangle = new Rectangle(printArea.X, printArea.Y, InfoInnerRectangleWidth + (int)(10 * widthRatio), InfoInnerRectangleHeight + (int)(10 * heightRatio)); 809 using (GraphicsPath path = GetRoundedRectPath(personalInfoRectangle, 5)) 622 810 { 623 811 g.DrawPath(Pens.Black, path); 624 812 } 625 813 626 // group header627 s = strings.PtInfo;628 StringFormat sf3 = new StringFormat(System.Threading.Thread.CurrentThread.CurrentUICulture.TextInfo.IsRightToLeft ? StringFormatFlags.DirectionRightToLeft : 0);629 g.DrawString(s, fGroupTitle, Brushes.Black, new Rectangle(personalInfoRectangle.X, personalInfoRectangle.Y - 20, personalInfoRectangle.Width, 20), sf3);630 631 StringFormat sf4 = new StringFormat(System.Threading.Thread.CurrentThread.CurrentUICulture.TextInfo.IsRightToLeft ? StringFormatFlags.DirectionRightToLeft : 0);632 sf4.SetTabStops(0, new float[] { 75 });633 sf4.SetDigitSubstitution(System.Threading.Thread.CurrentThread.CurrentUICulture.LCID, StringDigitSubstitute.Traditional);634 635 814 // inner rectangle for drawing strings: 636 Rectangle personalInfoInnerRectangle = new Rectangle(personalInfoRectangle.X + 20, personalInfoRectangle.Y + 20, personalInfoRectangle.Width - 40, personalInfoRectangle.Height - 40); 637 638 // Strings to write 639 StringBuilder sb = new StringBuilder(500); 640 sb.AppendLine(strings.Name + ":" + "\t" + appt.Patient.Name); 641 sb.AppendLine(); 642 sb.AppendLine(strings.ID + ":" + "\t" + appt.Patient.ID); 643 sb.AppendLine(); 644 s = appt.Patient.DOB.ToString("dd") + " " + appt.Patient.DOB.ToString("MMM") + ", " + appt.Patient.DOB.Year; 645 sb.AppendLine(strings.DOB + ":" + "\t" + s); 646 sb.AppendLine(); 647 sb.AppendLine(strings.Age + ":" + "\t" + appt.Patient.UserFriendlyAge); 648 //sb.AppendLine(); 649 //sb.AppendLine("Sex:" + "\t" + appt.Patient.Sex.ToString()); 650 651 // Draw them 652 g.DrawString(sb.ToString(), fBody, Brushes.Black, personalInfoInnerRectangle, sf4); 653 654 // draw curved rectangle 655 Rectangle apptInfoRectangle = new Rectangle(e.MarginBounds.X + e.MarginBounds.Width - 280, printArea.Y + 30, 280, part1Height); 656 using (GraphicsPath path = GetRoundedRectPath(apptInfoRectangle, 10)) 815 Rectangle personalInfoInnerRectangle = new Rectangle(personalInfoRectangle.X + (int)(5 * widthRatio), personalInfoRectangle.Y + (int)(5 * heightRatio), InfoInnerRectangleWidth, InfoInnerRectangleHeight); 816 817 // Draw the preson informations. 818 sf3 = new StringFormat(System.Threading.Thread.CurrentThread.CurrentUICulture.TextInfo.IsRightToLeft ? StringFormatFlags.DirectionRightToLeft : 0); 819 //sf3.SetTabStops(0, new float[] {75} ); 820 sf3.SetDigitSubstitution(System.Threading.Thread.CurrentThread.CurrentUICulture.LCID, StringDigitSubstitute.Traditional); 821 g.DrawString(personInformationString.ToString(), fontBody, Brushes.Black, personalInfoInnerRectangle, sf3); 822 823 // draw curved rectangle for the appointment informations. 824 Rectangle apptInfoRectangle = new Rectangle((int)(printArea.X + personalInfoRectangle.Width + printArea.X), personalInfoRectangle.Y, personalInfoRectangle.Width, personalInfoRectangle.Height); 825 using (GraphicsPath path = GetRoundedRectPath(apptInfoRectangle, 5)) 657 826 { 658 827 g.DrawPath(Pens.Black, path); 659 828 } 660 829 661 // group header 662 s = strings.ApptInfo; 663 g.DrawString(s, fGroupTitle, Brushes.Black, new Rectangle(apptInfoRectangle.X, apptInfoRectangle.Y - 20, apptInfoRectangle.Width, 20), sf3); 664 665 // Strings to write 666 sb = new StringBuilder(); 667 sb.AppendLine(strings.Clinic + ":"); 668 sb.AppendLine(appt.Resource); 669 sb.AppendLine(); 670 sb.AppendLine(strings.AppointmentProvider + ":"); 671 sb.AppendLine((appt.Provider == null) ? strings.none : appt.Provider.ToString()); //Appt Provider or (none) if null 672 sb.AppendLine(); 673 sb.AppendLine(strings.PatientOrder + ":" + "\t" + apptOrder); 674 sb.AppendLine(strings.Date + ":" + "\t" + appt.StartTime.ToShortDateString() + " " + appt.StartTime.ToShortTimeString()); 675 sb.AppendLine(); 676 sb.AppendLine(strings.AppointmentNote + ":"); 677 sb.AppendLine(String.IsNullOrWhiteSpace(appt.Note)? strings.none : appt.Note); 678 679 // Draw them 680 Rectangle apptInfoInnerRectangle = new Rectangle(apptInfoRectangle.X + 20, apptInfoRectangle.Y + 20, apptInfoRectangle.Width - 40, apptInfoRectangle.Height - 40); 681 682 // Draw them 683 g.DrawString(sb.ToString(), fBody, Brushes.Black, apptInfoInnerRectangle, sf4); 684 830 // Draw appointment informations in the inner rectangle. 831 Rectangle apptInfoInnerRectangle = new Rectangle(apptInfoRectangle.X + (int)(5 * widthRatio), apptInfoRectangle.Y + (int)(5 * heightRatio), InfoInnerRectangleWidth, InfoInnerRectangleHeight); 832 g.DrawString(appointmentInformationString.ToString(), fontBody, Brushes.Black, apptInfoInnerRectangle, sf3); 833 685 834 // Move Drawing Rectangle Down 686 printArea.Y += apptInfoRectangle.Height + 30 + 20;687 printArea.Height -= apptInfoRectangle.Height + 30 + 20;835 printArea.Y += personalInfoRectangle.Height + (int)(5 * heightRatio); 836 printArea.Height -= personalInfoRectangle.Height + (int)(5 * heightRatio); 688 837 689 838 // Draw New Line … … 694 843 } 695 844 696 printArea.Y += 5;697 printArea.Height -= 5;698 699 s = strings.ScratchArea;700 g.DrawString(s , fGroupTitle, Brushes.Black, printArea, sf3);701 845 printArea.Y += (int)(5 * heightRatio); 846 printArea.Height -= (int)(5 * heightRatio); 847 848 stringData = strings.ScratchArea; 849 g.DrawString(stringData, fontGroupTitle, Brushes.Black, printArea, sf3); 850 702 851 /* Per Al-Najjar, we don't want the next appointment instructions section 703 852 // move down … … 714 863 printArea.Height -= 5; 715 864 716 s = strings.NextAppointmentInstructions;717 g.DrawString(s , fGroupTitle, Brushes.Black, printArea, sf3);865 stringData = strings.NextAppointmentInstructions; 866 g.DrawString(stringData, fontGroupTitle, Brushes.Black, printArea, sf3); 718 867 */ 719 720 // Draw Footer721 //use sf0 to print the footer (center all the way)722 s = strings.Printed + ": " + DateTime.Now.ToString();723 Font fFooter = new Font(FontFamily.GenericSerif, 7);724 g.DrawString(s, fFooter, Brushes.Black, footerArea, sf0);725 868 726 869 g.Dispose();
Note:
See TracChangeset
for help on using the changeset viewer.