source: Scheduling/trunk/cs/bsdx0200GUISourceCode/UCPatientAppts.cs@ 899

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

Support for different encodings besides ASCII.
Minor bug fixes dealing with internationalization of dates.

File size: 5.4 KB
Line 
1using System;
2using System.ComponentModel;
3using System.Drawing;
4using System.Data;
5using System.Text;
6using System.Windows.Forms;
7using IndianHealthService.BMXNet;
8
9namespace IndianHealthService.ClinicalScheduling
10{
11 /// <summary>
12 /// User Control that shows patient's appointments and allows printing
13 /// </summary>
14 public partial class UCPatientAppts : UserControl
15 {
16 DataTable dtAppt; // Main table
17 DataView dvAppt; // Manipulated view of table
18 int rowToPrint; // Used in printing
19 /// <summary>
20 /// Ctor - Creates control and populates data into datagridview
21 /// </summary>
22 /// <param name="docManager">Document Manager from main context</param>
23 /// <param name="nPatientID">Patient IEN</param>
24 public UCPatientAppts(CGDocumentManager docManager, int nPatientID)
25 {
26 InitializeComponent();
27 try
28 {
29 string sSql = "BSDX PATIENT APPT DISPLAY^" + nPatientID.ToString();
30 dtAppt = docManager.RPMSDataTable(sSql, "PatientAppts");
31 }
32 catch (Exception ex) { MessageBox.Show(ex.Message); }
33
34 dvAppt = new DataView(dtAppt);
35 dvAppt.Sort = "ApptDate ASC";
36 SetPastFilter(false);
37 dgAppts.DataSource = dvAppt;
38
39 }
40 /// <summary>
41 /// Sets the filter for the DataView on whether to show past appointments or not
42 /// </summary>
43 /// <param name="ShowPastAppts">boolean - self explanatory</param>
44 void SetPastFilter(bool ShowPastAppts)
45 {
46 if (ShowPastAppts) dvAppt.RowFilter = "";
47 else dvAppt.RowFilter = "ApptDate > " + "'" + DateTime.Today.ToShortDateString() + "'";
48 }
49
50 private void chkPastAppts_CheckedChanged(object sender, EventArgs e)
51 {
52 if (chkPastAppts.Checked) SetPastFilter(true);
53 else SetPastFilter(false);
54 }
55
56 private void PrintPtAppts_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
57 {
58 Graphics g = e.Graphics;
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)
85 {
86 g.DrawString(col.HeaderText, Serif12Bold, Brushes.Black, startDrawRectangle);
87 startDrawRectangle.X += widthPerColumn;
88 }
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 }
117 }
118
119 private void btnPrint_Click(object sender, EventArgs e)
120 {
121 rowToPrint = 0; //reset row to print
122 DialogResult res = printDialog1.ShowDialog();
123 if (res == DialogResult.OK) this.printDialog1.Document.Print();
124 }
125
126 private void PrintPtAppts_QueryPageSettings(object sender, System.Drawing.Printing.QueryPageSettingsEventArgs e)
127 {
128 e.PageSettings.Landscape = true;
129 }
130
131 }
132}
Note: See TracBrowser for help on using the repository browser.