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

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

UCPatientAppts: Now uses LINQ. Mumps side fixes deal with other bugs.
calendarGrid: Fixes 1 day drawing bug showing yesterday's appointments
CGAVView: Cosmetic changes so far
CGDocument: Documentation change due to change in return values from Mumps.

File size: 6.6 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 SetPastFilter(false);
35
36 // dgAppts.DataSource = dvAppt;
37 }
38 /// <summary>
39 /// Sets the filter for the DataView on whether to show past appointments or not
40 /// Uses LINQ. Must use .Net 3.5 or above. Hope the LINQ is self-explanatory.
41 /// </summary>
42 /// <param name="ShowPastAppts">boolean - self explanatory</param>
43 void SetPastFilter(bool ShowPastAppts)
44 {
45 if (ShowPastAppts)
46 {
47 var uncancelledAppts = from appt in dtAppt.AsEnumerable()
48 orderby appt.Field<DateTime>("ApptDate")
49 select appt;
50
51 dvAppt = uncancelledAppts.AsDataView();
52 }
53 else
54 {
55 var uncancelledAppts = from appt in dtAppt.AsEnumerable()
56 where appt.Field<DateTime>("ApptDate") > DateTime.Today
57 orderby appt.Field<DateTime>("ApptDate")
58 select appt;
59
60 dvAppt = uncancelledAppts.AsDataView();
61 }
62
63 // It's strange that I have to bind it here; but look like dvAppt points to a new memory
64 // location when reassigned up above in the LINQ statement, so we have to rebind it.
65 dgAppts.DataSource = dvAppt;
66 }
67
68 private void chkPastAppts_CheckedChanged(object sender, EventArgs e)
69 {
70 if (chkPastAppts.Checked) SetPastFilter(true);
71 else SetPastFilter(false);
72 }
73
74 private void PrintPtAppts_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
75 {
76 Graphics g = e.Graphics;
77 Font Serif12Bold = new Font(FontFamily.GenericSerif, 12, FontStyle.Bold);
78 Font Serif12 = new Font(FontFamily.GenericSerif, 12);
79 Font Serif14 = new Font(FontFamily.GenericSerif, 14);
80 Rectangle startDrawRectangle = e.MarginBounds;
81 int widthPerColumn = e.MarginBounds.Width/dgAppts.Columns.Count;
82 int Serif12Height = (int)Serif12.GetHeight();
83
84 //Draw Header
85 StringFormat sf1 = new StringFormat();
86 sf1.Alignment = StringAlignment.Center;
87 g.DrawString("Appointment Listing", Serif14, Brushes.Black, startDrawRectangle, sf1);
88
89 startDrawRectangle.Y += (int)Serif14.GetHeight();
90
91 g.DrawString("Confidential Patient Information", Serif12, Brushes.Black, startDrawRectangle, sf1);
92
93 startDrawRectangle.Y += Serif12Height * 2;
94
95 //Patient Name + Sex + DOB
96 string identifier = "Patient Name: " + dtAppt.Rows[0]["Name"] + "\tSex: " + dtAppt.Rows[0]["Sex"]
97 + "\tDate of Birth: " + dtAppt.Rows[0]["DOB"];
98 g.DrawString(identifier, Serif12, Brushes.Black, startDrawRectangle);
99
100 startDrawRectangle.Y += Serif12Height * 2;
101
102 foreach (DataGridViewColumn col in dgAppts.Columns)
103 {
104 g.DrawString(col.HeaderText, Serif12Bold, Brushes.Black, startDrawRectangle);
105 startDrawRectangle.X += widthPerColumn;
106 }
107 startDrawRectangle.Y += Serif12Height;
108
109 // rowToPrint initialized in print button handler. Helps us keep track of which row we
110 // are on, so that, just in case we need an extra page to print, we would know where
111 // we left off. Royal we of course.
112 for ( ; rowToPrint<dgAppts.Rows.Count; rowToPrint++)
113 {
114 // Post facto statement -- This is starting to look like Mumps...
115 // Start drawing a new page if you hit the bottom margin...
116 // Y incremented at the bottom of the for loop; but checked here
117 // because I need for statement stuff to happen first
118 if (startDrawRectangle.Y > e.MarginBounds.Bottom)
119 {
120 e.HasMorePages = true;
121 break;
122 }
123
124 startDrawRectangle.X = e.MarginBounds.X;
125
126 foreach (DataGridViewCell cell in dgAppts.Rows[rowToPrint].Cells)
127 {
128 g.DrawString(cell.Value.ToString(), Serif12, Brushes.Black, startDrawRectangle);
129 startDrawRectangle.X += widthPerColumn;
130 }
131
132 startDrawRectangle.Y += Serif12Height;
133
134 }
135 }
136
137 private void btnPrint_Click(object sender, EventArgs e)
138 {
139 //Fixes bug reported by EHS. Don't print if there are no appointments as this causes null ref
140 if (dtAppt.Rows.Count == 0)
141 {
142 MessageBox.Show("No Appointments to Print", "Nothing to Print");
143 return;
144 }
145
146 rowToPrint = 0; //reset row to print
147 DialogResult res = printDialog1.ShowDialog();
148 if (res == DialogResult.OK) this.printDialog1.Document.Print();
149 }
150
151 /// <summary>
152 /// Sets default page orientation to landscape.
153 /// </summary>
154 private void PrintPtAppts_QueryPageSettings(object sender, System.Drawing.Printing.QueryPageSettingsEventArgs e)
155 {
156 e.PageSettings.Landscape = true;
157 }
158
159 }
160}
Note: See TracBrowser for help on using the repository browser.