Ignore:
Timestamp:
May 11, 2010, 1:24:18 AM (14 years ago)
Author:
Sam Habiel
Message:

Better printing in UCPatientAppts.

File:
1 edited

Legend:

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

    r753 r755  
    1414    public partial class UCPatientAppts : UserControl
    1515    {
    16         DataTable dtAppt;
    17         DataView dvAppt;
     16        DataTable dtAppt; // Main table
     17        DataView dvAppt; // Manipulated view of table
     18        int rowToPrint; // Used in printing
    1819        /// <summary>
    19         /// Ctor
     20        /// Ctor - Creates control and populates data into datagridview
    2021        /// </summary>
    2122        /// <param name="docManager">Document Manager from main context</param>
     
    4445        {
    4546            if (ShowPastAppts) dvAppt.RowFilter = "";
    46             else dvAppt.RowFilter = "ApptDate > " + "#" + DateTime.Today.ToShortDateString() + "#"; ;
     47            else dvAppt.RowFilter = "ApptDate > " + "#" + DateTime.Today.ToShortDateString() + "#";
    4748        }
    4849
     
    5657        {
    5758            Graphics g = e.Graphics;
    58             using (Font font = new Font("Lucida Console", 72))
     59            Font Serif12Bold = new Font(FontFamily.GenericSerif, 12, FontStyle.Bold);
     60            Font Serif12 = new Font(FontFamily.GenericSerif, 12);
     61            Font Serif14 = new Font(FontFamily.GenericSerif, 14);
     62            Rectangle startDrawRectangle = e.MarginBounds;
     63            int widthPerColumn = e.MarginBounds.Width/dgAppts.Columns.Count;
     64            int Serif12Height = (int)Serif12.GetHeight();
     65           
     66            //Draw Header
     67            StringFormat sf1 = new StringFormat();
     68            sf1.Alignment = StringAlignment.Center;
     69            g.DrawString("Appointment Listing", Serif14, Brushes.Black, startDrawRectangle, sf1);
     70
     71            startDrawRectangle.Y += (int)Serif14.GetHeight();
     72
     73            g.DrawString("Confidential Patient Information", Serif12, Brushes.Black, startDrawRectangle, sf1);
     74           
     75            startDrawRectangle.Y += Serif12Height * 2;
     76
     77            //Patient Name + Sex + DOB
     78            string identifier = "Patient Name: " + dtAppt.Rows[0]["Name"] + "\tSex: " + dtAppt.Rows[0]["Sex"]
     79                + "\tDate of Birth: " + dtAppt.Rows[0]["DOB"];
     80            g.DrawString(identifier, Serif12, Brushes.Black, startDrawRectangle);
     81
     82            startDrawRectangle.Y += Serif12Height * 2;
     83
     84            foreach (DataGridViewColumn col in dgAppts.Columns)
    5985            {
    60                 g.DrawString("Hello,\nPrinter", font, Brushes.Black, e.MarginBounds);
     86                g.DrawString(col.HeaderText, Serif12Bold, Brushes.Black, startDrawRectangle);
     87                startDrawRectangle.X += widthPerColumn;
    6188            }
     89            startDrawRectangle.Y += Serif12Height;
     90
     91            // rowToPrint initialized in print button handler. Helps us keep track of which row we
     92            // are on, so that, just in case we need an extra page to print, we would know where
     93            // we left off. Royal we of course.
     94            for ( ; rowToPrint<dgAppts.Rows.Count; rowToPrint++)
     95            {
     96                // Post facto statement -- This is starting to look like Mumps...
     97                // Start drawing a new page if you hit the bottom margin...
     98                // Y incremented at the bottom of the for loop; but checked here
     99                // because I need for statement stuff to happen first
     100                if (startDrawRectangle.Y > e.MarginBounds.Bottom)
     101                {
     102                    e.HasMorePages = true;
     103                    break;
     104                }
     105
     106                startDrawRectangle.X = e.MarginBounds.X;
     107
     108                foreach (DataGridViewCell cell in dgAppts.Rows[rowToPrint].Cells)
     109                {
     110                    g.DrawString(cell.Value.ToString(), Serif12, Brushes.Black, startDrawRectangle);
     111                    startDrawRectangle.X += widthPerColumn;
     112                }
     113
     114                startDrawRectangle.Y += Serif12Height;
     115
     116            }             
    62117        }
    63118
    64119        private void btnPrint_Click(object sender, EventArgs e)
    65120        {
     121            rowToPrint = 0; //reset row to print
    66122            DialogResult res = printDialog1.ShowDialog();
    67123            if (res == DialogResult.OK) this.printDialog1.Document.Print();
    68124        }
    69125
     126        private void PrintPtAppts_QueryPageSettings(object sender, System.Drawing.Printing.QueryPageSettingsEventArgs e)
     127        {
     128            e.PageSettings.Landscape = true;
     129        }
     130
    70131    }
    71132}
Note: See TracChangeset for help on using the changeset viewer.