Ignore:
Timestamp:
Jun 4, 2010, 10:19:48 PM (14 years ago)
Author:
Sam Habiel
Message:

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

  • Cancellation letters now work.
  • Initial work on Rebook Letters.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Scheduling/trunk/cs/bsdx0200GUISourceCode/Printing.cs

    r772 r788  
    2121        /// <param name="e">PrintPageEventArgs from PrintDocument Print handler</param>
    2222        /// <param name="beg">Begin Datetime to print appointments</param>
    23         /// <param name="end">End 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>
    2427        /// <remarks>beg and end have no effect on operation--they are there for documentation for user only</remarks>
    2528        public static void PrintAppointments(dsPatientApptDisplay2 ds, PrintPageEventArgs e, DateTime beg, DateTime end,
    26             int resourceToPrint, ref int apptPrinted)
     29            int resourceToPrint, ref int apptPrinting, int pageNumber)
    2730        {
    2831            Graphics g = e.Graphics;
     
    4043            sf.Alignment = StringAlignment.Center;
    4144           
     45            //Header
    4246            g.DrawString("Confidential Patient Information", f8, Brushes.Black, e.PageBounds, sf);
    4347           
     48            //Footer
     49            sf.Alignment = StringAlignment.Center;
     50            sf.LineAlignment = StringAlignment.Far;
     51            g.DrawString("Page " + pageNumber, f8, Brushes.Black, e.PageBounds, sf);
     52
    4453            //Typical manipulable print area
    4554            Rectangle printArea = e.MarginBounds;
    4655           
     56            //resource we want to print
    4757            dsPatientApptDisplay2.BSDXResourceRow r = ds.BSDXResource[resourceToPrint];
    4858           
     59            //header
    4960            string toprint;
    5061            if (beg == end) toprint = "Appointments for " + r.RESOURCE_NAME + " on " + beg.ToLongDateString();
     
    5364            g.DrawString(toprint, f14bold, Brushes.Black, printArea);
    5465           
     66            //Move print area down
     67            printArea.Height -= (int)f14bold.GetHeight();
    5568            printArea.Y += (int)f14bold.GetHeight();
     69
     70            //Draw Line
    5671            g.DrawLine(new Pen(Brushes.Black, 0), printArea.X, printArea.Y, printArea.X + printArea.Width, printArea.Y);
    57             printArea.Y += 5;
    58            
    59             System.Data.DataRow[] appts = r.GetChildRows(ds.Relations[0]); //only one relation
    60 
    61             toprint = "";
    62             StringFormat sf2 = new StringFormat();
    63             sf2.SetTabStops(50, new float[] { 100, 200, 200 });
    64 
    65             foreach (dsPatientApptDisplay2.PatientApptsRow a in appts)
     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)
    6684            {
    67                 toprint += a.ApptDate.ToString() + "\t" + a.Name +"(" + a.Sex + ")" + "\t" + "DOB: " + a.DOB.ToString("dd-MMM-yyyy") + "\t" + "ID: " + a.HRN;
    68                 toprint += "\n";
    69                 toprint += "Home Phone: " + a.HOMEPHONE + "\t" + "Address: " + a.STREET + ", " + a.CITY + ", " + a.STATE + " " + a.ZIP;
    70                 toprint += "\n";
    71                 toprint += "Note: " + a.NOTE;
    72                 toprint += "\n";
    73                 toprint += "Appointment made by " + a.APPT_MADE_BY + " on " + a.DATE_APPT_MADE;
    74                 toprint += "\n\n";
     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++;
    75120            }
    76             g.DrawString(toprint, f10, Brushes.Black, printArea, sf2);
    77         }
     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       
    78214    }
    79215}
Note: See TracChangeset for help on using the changeset viewer.