source: Scheduling/trunk/cs/bsdx0200GUISourceCode/DApptSearch.cs@ 1131

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

Several Fixes found in my own testing:

  • CalendarGrid needs to have StartDate as 12:00:00, otherwise a subtraction to calculate the column number of each availability doesn't work properly
  • CGDocument needs to have SelectedDate set otherwise when it refreshes, it uses the selected date and makes the screen suddenly blank.
  • DApptSearch needs to make date/times proper to send over to DB. CGSchedLib.CreateAvailabilitySchedule needs the startDate to be the beginning of the day and end date to be the end of the day. Now this is done.
  • Updated exes.
File size: 43.1 KB
Line 
1using System;
2using System.Collections;
3using System.Collections.Generic;
4using System.Windows.Forms;
5using System.Data;
6using System.Linq;
7//using System.Data.OleDb;
8
9namespace IndianHealthService.ClinicalScheduling
10{
11 /// <summary>
12 /// Modal Dialog for searching for Patient Slots
13 /// </summary>
14 public class DApptSearch : System.Windows.Forms.Form
15 {
16 private System.Windows.Forms.Panel panel1;
17 private System.Windows.Forms.Button cmdCancel;
18 private System.Windows.Forms.Button btnAccept;
19 private System.Windows.Forms.Panel pnlDescription;
20 private System.Windows.Forms.GroupBox grpDescription;
21 private System.Windows.Forms.Label lblDescription;
22 private System.Windows.Forms.GroupBox groupBox1;
23 private System.Windows.Forms.Label label3;
24 private System.Windows.Forms.Label label2;
25 private System.Windows.Forms.CheckedListBox lstAccessTypes;
26 private System.Windows.Forms.ComboBox cboAccessTypeFilter;
27 private System.Windows.Forms.GroupBox grpDayOfWeek;
28 private System.Windows.Forms.CheckBox chkSun;
29 private System.Windows.Forms.CheckBox chkSat;
30 private System.Windows.Forms.CheckBox chkFri;
31 private System.Windows.Forms.CheckBox chkThu;
32 private System.Windows.Forms.CheckBox chkWed;
33 private System.Windows.Forms.CheckBox chkTue;
34 private System.Windows.Forms.CheckBox chkMon;
35 private System.Windows.Forms.GroupBox grpTimeOfDay;
36 private System.Windows.Forms.RadioButton rdoBoth;
37 private System.Windows.Forms.RadioButton rdoPM;
38 private System.Windows.Forms.RadioButton rdoAM;
39 private System.Windows.Forms.Label label1;
40 private System.Windows.Forms.GroupBox groupBox2;
41 private System.Windows.Forms.Button cmdSearch;
42 private ListView lstResults;
43 private ColumnHeader colStartTime;
44 private ColumnHeader colEndTime;
45 private ColumnHeader colResource;
46 private ColumnHeader colSlots;
47 private ColumnHeader colAccessType;
48 private ColumnHeader colDate;
49 private Label lblEnd;
50 private Label lblStart;
51 private DateTimePicker dtEnd;
52 private DateTimePicker dtStart;
53 private ColumnHeader colDOW;
54 private ColumnHeader colID;
55 private Label lblMessage;
56
57 private System.ComponentModel.IContainer components;
58
59 public DApptSearch()
60 {
61 InitializeComponent();
62 }
63
64 #region Fields
65
66 private CGDocumentManager m_DocManager;
67
68 private DataSet m_dsGlobal;
69 DataTable m_dtTypes;
70 DataView m_dvTypes;
71 List<CGAvailability> lstResultantAvailabilities;
72 private CGAvailability _selectedAvailability;
73 DateTime m_dStart;
74 DateTime m_dEnd;
75 ArrayList m_alResources;
76 ArrayList m_alAccessTypes;
77 string m_sWeekDays; //only practical use now is for sending to server
78 string m_sAmpm; // same here.
79
80 #endregion Fields
81
82 #region Methods
83
84 public void LoadListBox(string sGroup)
85 {
86 if (sGroup == "ALL")
87 {
88 //Load the Access Type list box with ALL access types
89 m_dtTypes = m_dsGlobal.Tables["AccessTypes"];
90 m_dvTypes = new DataView(m_dtTypes);
91 lstAccessTypes.DataSource = m_dvTypes;
92 lstAccessTypes.DisplayMember = "ACCESS_TYPE_NAME";
93 lstAccessTypes.Tag = 1; //This holds the column index of the ACCESS_TYPE_NAME column
94 lstAccessTypes.ValueMember = "BMXIEN";
95 }
96 else
97 {
98 //Load the Access Type list box with active access types belonging
99 //to group sGroup
100
101 //Build AccessGroup table containing *active* AccessTypes and their Groups
102 m_dtTypes = m_dsGlobal.Tables["AccessGroupType"];
103 //Create a view that is filterable on Access Group
104 m_dvTypes = new DataView(m_dtTypes);
105 m_dvTypes.RowFilter = "ACCESS_GROUP = '" + this.cboAccessTypeFilter.Text + "'";
106 lstAccessTypes.DataSource = m_dvTypes;
107 lstAccessTypes.DisplayMember = "ACCESS_TYPE";
108 lstAccessTypes.ValueMember = "ACCESS_TYPE_ID";
109 lstAccessTypes.Tag = 4; //This holds the column index of the ACCESS_TYPE column
110 }
111 }
112
113 public void InitializePage(ArrayList alResources, CGDocumentManager docManager)
114 {
115
116 this.Text = "Searching for Appointments in: " + string.Join(" | ", alResources.Cast<string>());
117
118 this.m_DocManager = docManager;
119 this.m_dsGlobal = m_DocManager.GlobalDataSet;
120
121 LoadListBox("ALL");
122
123 m_dStart = DateTime.Today;
124 m_dEnd = new DateTime(9999);
125 this.m_alResources = alResources;
126 this.m_alAccessTypes = new ArrayList();
127 this.m_sAmpm="both";
128 this.m_sWeekDays = "";
129
130 //Load filter combo with list of access type groups
131 DataTable dtGroup = m_dsGlobal.Tables["AccessGroup"];
132 DataSet dsTemp = new DataSet("dsTemp");
133 dsTemp.Tables.Add(dtGroup.Copy());
134 DataTable dtTemp = dsTemp.Tables["AccessGroup"];
135 DataView dvGroup = new DataView(dtTemp);
136 DataRowView drv = dvGroup.AddNew();
137 drv["ACCESS_GROUP"]="<Show All Access Types>";
138 cboAccessTypeFilter.DataSource = dvGroup;
139 cboAccessTypeFilter.DisplayMember = "ACCESS_GROUP";
140 cboAccessTypeFilter.SelectedText = "<Show All Access Types>";
141 cboAccessTypeFilter.SelectedIndex = cboAccessTypeFilter.Items.Count - 1;
142 cboAccessTypeFilter.Refresh();
143
144
145 /* OLD CODE
146 //Create DataGridTableStyle for Result grid
147 DataGridTableStyle tsResult = new DataGridTableStyle();
148 tsResult.MappingName = "Result";
149 tsResult.ReadOnly = true;
150
151 // Add START_TIME column style.
152 DataGridTextBoxColumn colStartTime = new DataGridTextBoxColumn();
153 colStartTime.MappingName = "StartTime";
154 colStartTime.HeaderText = "Start Time";
155 colStartTime.Width = 200;
156 colStartTime.Format = "f";
157 tsResult.GridColumnStyles.Add(colStartTime);
158
159 // Add END_TIME column style.
160 DataGridTextBoxColumn colEndTime = new DataGridTextBoxColumn();
161 colEndTime.MappingName = "EndTime";
162 colEndTime.HeaderText = "End Time";
163 colEndTime.Width = 75;
164 colEndTime.Format = "h:mm tt";
165 tsResult.GridColumnStyles.Add(colEndTime);
166
167 // Add RESOURCE column style.
168 DataGridTextBoxColumn colResource = new DataGridTextBoxColumn();
169 colResource.MappingName = "ResourceList";
170 colResource.HeaderText = "Resource";
171 colResource.Width = 200;
172 tsResult.GridColumnStyles.Add(colResource);
173
174 // Add SLOTS column style.
175 DataGridTextBoxColumn colSlots = new DataGridTextBoxColumn();
176 colSlots.MappingName = "SLOTS";
177 colSlots.HeaderText = "Slots";
178 colSlots.Width = 50;
179 tsResult.GridColumnStyles.Add(colSlots);
180
181 // Add AMPM column style.
182 DataGridTextBoxColumn colAccess = new DataGridTextBoxColumn();
183 colAccess.MappingName = "ACCESSNAME";
184 colAccess.HeaderText = "Access Type";
185 colAccess.Width = 200;
186 tsResult.GridColumnStyles.Add(colAccess);
187 //grdResult.TableStyles.Add(tsResult);
188 */
189
190 this.UpdateDialogData(true);
191
192 }
193
194 /// <summary>
195 /// If b is true, moves member vars into control data
196 /// otherwise, moves control data into member vars
197 /// </summary>
198 /// <param name="b"></param>
199 private void UpdateDialogData(bool b)
200 {
201 if (b == true) //move member vars into controls
202 {
203
204 }
205 else //move control data into member vars
206 {
207
208 //Build AccessType list
209
210 this.m_alAccessTypes.Clear();
211
212 for (int j = 0; j < this.lstAccessTypes.CheckedItems.Count; j++)
213 {
214 DataRowView drv = (DataRowView) lstAccessTypes.CheckedItems[j];
215 int nIndex = (int) lstAccessTypes.Tag;
216 string sItem = drv.Row.ItemArray[nIndex].ToString();
217 m_alAccessTypes.Add(sItem);
218 }
219
220 //AM/PM
221 this.m_sAmpm = (this.rdoAM.Checked == true) ? "AM":"BOTH";
222 if (this.m_sAmpm != "AM")
223 this.m_sAmpm = (this.rdoPM.Checked == true) ? "PM":"BOTH";
224
225
226 //Weekday
227 this.m_sWeekDays = ""; //any
228 if (chkMon.Checked == true)
229 m_sWeekDays += "Monday";
230 if (chkTue.Checked == true)
231 m_sWeekDays += "Tuesday";
232 if (chkWed.Checked == true)
233 m_sWeekDays += "Wednesday";
234 if (chkThu.Checked == true)
235 m_sWeekDays += "Thursday";
236 if (chkFri.Checked == true)
237 m_sWeekDays += "Friday";
238 if (chkSat.Checked == true)
239 m_sWeekDays += "Saturday";
240 if (chkSun.Checked == true)
241 m_sWeekDays += "Sunday";
242
243 //Start
244 this.m_dStart = this.dtStart.Value;
245
246 //End
247 this.m_dEnd = this.dtEnd.Value;
248 }
249 }
250
251
252 /// <summary>
253 /// Clean up any resources being used.
254 /// </summary>
255 protected override void Dispose( bool disposing )
256 {
257 if( disposing )
258 {
259 if(components != null)
260 {
261 components.Dispose();
262 }
263 }
264 base.Dispose( disposing );
265 }
266
267 #endregion Methods
268
269 #region Windows Form Designer generated code
270 /// <summary>
271 /// Required method for Designer support - do not modify
272 /// the contents of this method with the code editor.
273 /// </summary>
274 private void InitializeComponent()
275 {
276 this.panel1 = new System.Windows.Forms.Panel();
277 this.cmdSearch = new System.Windows.Forms.Button();
278 this.cmdCancel = new System.Windows.Forms.Button();
279 this.btnAccept = new System.Windows.Forms.Button();
280 this.pnlDescription = new System.Windows.Forms.Panel();
281 this.grpDescription = new System.Windows.Forms.GroupBox();
282 this.lblDescription = new System.Windows.Forms.Label();
283 this.groupBox1 = new System.Windows.Forms.GroupBox();
284 this.lblEnd = new System.Windows.Forms.Label();
285 this.lblStart = new System.Windows.Forms.Label();
286 this.dtEnd = new System.Windows.Forms.DateTimePicker();
287 this.dtStart = new System.Windows.Forms.DateTimePicker();
288 this.label3 = new System.Windows.Forms.Label();
289 this.label2 = new System.Windows.Forms.Label();
290 this.lstAccessTypes = new System.Windows.Forms.CheckedListBox();
291 this.cboAccessTypeFilter = new System.Windows.Forms.ComboBox();
292 this.grpDayOfWeek = new System.Windows.Forms.GroupBox();
293 this.chkSun = new System.Windows.Forms.CheckBox();
294 this.chkSat = new System.Windows.Forms.CheckBox();
295 this.chkFri = new System.Windows.Forms.CheckBox();
296 this.chkThu = new System.Windows.Forms.CheckBox();
297 this.chkWed = new System.Windows.Forms.CheckBox();
298 this.chkTue = new System.Windows.Forms.CheckBox();
299 this.chkMon = new System.Windows.Forms.CheckBox();
300 this.grpTimeOfDay = new System.Windows.Forms.GroupBox();
301 this.rdoBoth = new System.Windows.Forms.RadioButton();
302 this.rdoPM = new System.Windows.Forms.RadioButton();
303 this.rdoAM = new System.Windows.Forms.RadioButton();
304 this.label1 = new System.Windows.Forms.Label();
305 this.groupBox2 = new System.Windows.Forms.GroupBox();
306 this.lstResults = new System.Windows.Forms.ListView();
307 this.colID = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
308 this.colDate = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
309 this.colDOW = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
310 this.colStartTime = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
311 this.colEndTime = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
312 this.colResource = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
313 this.colSlots = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
314 this.colAccessType = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
315 this.lblMessage = new System.Windows.Forms.Label();
316 this.panel1.SuspendLayout();
317 this.pnlDescription.SuspendLayout();
318 this.grpDescription.SuspendLayout();
319 this.groupBox1.SuspendLayout();
320 this.grpDayOfWeek.SuspendLayout();
321 this.grpTimeOfDay.SuspendLayout();
322 this.groupBox2.SuspendLayout();
323 this.SuspendLayout();
324 //
325 // panel1
326 //
327 this.panel1.Controls.Add(this.lblMessage);
328 this.panel1.Controls.Add(this.cmdSearch);
329 this.panel1.Controls.Add(this.cmdCancel);
330 this.panel1.Controls.Add(this.btnAccept);
331 this.panel1.Dock = System.Windows.Forms.DockStyle.Bottom;
332 this.panel1.Location = new System.Drawing.Point(0, 461);
333 this.panel1.Name = "panel1";
334 this.panel1.Size = new System.Drawing.Size(923, 40);
335 this.panel1.TabIndex = 4;
336 //
337 // cmdSearch
338 //
339 this.cmdSearch.Location = new System.Drawing.Point(33, 6);
340 this.cmdSearch.Name = "cmdSearch";
341 this.cmdSearch.Size = new System.Drawing.Size(72, 24);
342 this.cmdSearch.TabIndex = 2;
343 this.cmdSearch.Text = "Search";
344 this.cmdSearch.Click += new System.EventHandler(this.cmdSearch_Click);
345 //
346 // cmdCancel
347 //
348 this.cmdCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
349 this.cmdCancel.Location = new System.Drawing.Point(828, 8);
350 this.cmdCancel.Name = "cmdCancel";
351 this.cmdCancel.Size = new System.Drawing.Size(64, 24);
352 this.cmdCancel.TabIndex = 1;
353 this.cmdCancel.Text = "Cancel";
354 //
355 // btnAccept
356 //
357 this.btnAccept.DialogResult = System.Windows.Forms.DialogResult.OK;
358 this.btnAccept.Location = new System.Drawing.Point(135, 8);
359 this.btnAccept.Name = "btnAccept";
360 this.btnAccept.Size = new System.Drawing.Size(176, 24);
361 this.btnAccept.TabIndex = 0;
362 this.btnAccept.Text = "Select Slot for Appointment";
363 this.btnAccept.Click += new System.EventHandler(this.btnAccept_Click);
364 //
365 // pnlDescription
366 //
367 this.pnlDescription.Controls.Add(this.grpDescription);
368 this.pnlDescription.Dock = System.Windows.Forms.DockStyle.Bottom;
369 this.pnlDescription.Location = new System.Drawing.Point(0, 397);
370 this.pnlDescription.Name = "pnlDescription";
371 this.pnlDescription.Size = new System.Drawing.Size(923, 64);
372 this.pnlDescription.TabIndex = 47;
373 //
374 // grpDescription
375 //
376 this.grpDescription.Controls.Add(this.lblDescription);
377 this.grpDescription.Dock = System.Windows.Forms.DockStyle.Fill;
378 this.grpDescription.Location = new System.Drawing.Point(0, 0);
379 this.grpDescription.Name = "grpDescription";
380 this.grpDescription.Size = new System.Drawing.Size(923, 64);
381 this.grpDescription.TabIndex = 0;
382 this.grpDescription.TabStop = false;
383 this.grpDescription.Text = "Description";
384 //
385 // lblDescription
386 //
387 this.lblDescription.Dock = System.Windows.Forms.DockStyle.Fill;
388 this.lblDescription.Location = new System.Drawing.Point(3, 16);
389 this.lblDescription.Name = "lblDescription";
390 this.lblDescription.Size = new System.Drawing.Size(917, 45);
391 this.lblDescription.TabIndex = 1;
392 this.lblDescription.Text = "Search for available appointment times using this panel. You may narrow your sea" +
393 "rch by selecting an access type or by selecting specific days of the week or tim" +
394 "es of day.";
395 //
396 // groupBox1
397 //
398 this.groupBox1.Controls.Add(this.lblEnd);
399 this.groupBox1.Controls.Add(this.lblStart);
400 this.groupBox1.Controls.Add(this.dtEnd);
401 this.groupBox1.Controls.Add(this.dtStart);
402 this.groupBox1.Controls.Add(this.label3);
403 this.groupBox1.Controls.Add(this.label2);
404 this.groupBox1.Controls.Add(this.lstAccessTypes);
405 this.groupBox1.Controls.Add(this.cboAccessTypeFilter);
406 this.groupBox1.Controls.Add(this.grpDayOfWeek);
407 this.groupBox1.Controls.Add(this.grpTimeOfDay);
408 this.groupBox1.Controls.Add(this.label1);
409 this.groupBox1.Dock = System.Windows.Forms.DockStyle.Top;
410 this.groupBox1.Location = new System.Drawing.Point(0, 0);
411 this.groupBox1.Name = "groupBox1";
412 this.groupBox1.Size = new System.Drawing.Size(923, 208);
413 this.groupBox1.TabIndex = 56;
414 this.groupBox1.TabStop = false;
415 this.groupBox1.Text = "Search Parameters";
416 //
417 // lblEnd
418 //
419 this.lblEnd.AutoSize = true;
420 this.lblEnd.Location = new System.Drawing.Point(12, 124);
421 this.lblEnd.Name = "lblEnd";
422 this.lblEnd.Size = new System.Drawing.Size(153, 13);
423 this.lblEnd.TabIndex = 67;
424 this.lblEnd.Text = "End Date to Search (Inclusive)";
425 //
426 // lblStart
427 //
428 this.lblStart.AutoSize = true;
429 this.lblStart.Location = new System.Drawing.Point(12, 35);
430 this.lblStart.Name = "lblStart";
431 this.lblStart.Size = new System.Drawing.Size(159, 13);
432 this.lblStart.TabIndex = 66;
433 this.lblStart.Text = "Start Date to Search (Inclusive)";
434 //
435 // dtEnd
436 //
437 this.dtEnd.Location = new System.Drawing.Point(12, 141);
438 this.dtEnd.Name = "dtEnd";
439 this.dtEnd.Size = new System.Drawing.Size(200, 20);
440 this.dtEnd.TabIndex = 65;
441 this.dtEnd.ValueChanged += new System.EventHandler(this.dtEnd_ValueChanged);
442 //
443 // dtStart
444 //
445 this.dtStart.Location = new System.Drawing.Point(12, 54);
446 this.dtStart.Name = "dtStart";
447 this.dtStart.Size = new System.Drawing.Size(200, 20);
448 this.dtStart.TabIndex = 64;
449 this.dtStart.ValueChanged += new System.EventHandler(this.dtStart_ValueChanged);
450 //
451 // label3
452 //
453 this.label3.Location = new System.Drawing.Point(684, 64);
454 this.label3.Name = "label3";
455 this.label3.Size = new System.Drawing.Size(80, 16);
456 this.label3.TabIndex = 63;
457 this.label3.Text = "Access Type:";
458 //
459 // label2
460 //
461 this.label2.Location = new System.Drawing.Point(684, 21);
462 this.label2.Name = "label2";
463 this.label2.Size = new System.Drawing.Size(104, 16);
464 this.label2.TabIndex = 62;
465 this.label2.Text = "Access Group:";
466 //
467 // lstAccessTypes
468 //
469 this.lstAccessTypes.CheckOnClick = true;
470 this.lstAccessTypes.HorizontalScrollbar = true;
471 this.lstAccessTypes.Location = new System.Drawing.Point(661, 88);
472 this.lstAccessTypes.MultiColumn = true;
473 this.lstAccessTypes.Name = "lstAccessTypes";
474 this.lstAccessTypes.Size = new System.Drawing.Size(250, 109);
475 this.lstAccessTypes.TabIndex = 61;
476 //
477 // cboAccessTypeFilter
478 //
479 this.cboAccessTypeFilter.Location = new System.Drawing.Point(661, 40);
480 this.cboAccessTypeFilter.Name = "cboAccessTypeFilter";
481 this.cboAccessTypeFilter.Size = new System.Drawing.Size(250, 21);
482 this.cboAccessTypeFilter.TabIndex = 60;
483 this.cboAccessTypeFilter.Text = "cboAccessTypeFilter";
484 this.cboAccessTypeFilter.SelectionChangeCommitted += new System.EventHandler(this.cboAccessTypeFilter_SelectionChangeCommitted);
485 //
486 // grpDayOfWeek
487 //
488 this.grpDayOfWeek.Controls.Add(this.chkSun);
489 this.grpDayOfWeek.Controls.Add(this.chkSat);
490 this.grpDayOfWeek.Controls.Add(this.chkFri);
491 this.grpDayOfWeek.Controls.Add(this.chkThu);
492 this.grpDayOfWeek.Controls.Add(this.chkWed);
493 this.grpDayOfWeek.Controls.Add(this.chkTue);
494 this.grpDayOfWeek.Controls.Add(this.chkMon);
495 this.grpDayOfWeek.Location = new System.Drawing.Point(311, 94);
496 this.grpDayOfWeek.Name = "grpDayOfWeek";
497 this.grpDayOfWeek.Size = new System.Drawing.Size(240, 101);
498 this.grpDayOfWeek.TabIndex = 59;
499 this.grpDayOfWeek.TabStop = false;
500 this.grpDayOfWeek.Text = "Day of the Week";
501 //
502 // chkSun
503 //
504 this.chkSun.Location = new System.Drawing.Point(176, 64);
505 this.chkSun.Name = "chkSun";
506 this.chkSun.Size = new System.Drawing.Size(48, 16);
507 this.chkSun.TabIndex = 6;
508 this.chkSun.Text = "Sun";
509 //
510 // chkSat
511 //
512 this.chkSat.Location = new System.Drawing.Point(128, 64);
513 this.chkSat.Name = "chkSat";
514 this.chkSat.Size = new System.Drawing.Size(48, 16);
515 this.chkSat.TabIndex = 5;
516 this.chkSat.Text = "Sat";
517 //
518 // chkFri
519 //
520 this.chkFri.Location = new System.Drawing.Point(72, 64);
521 this.chkFri.Name = "chkFri";
522 this.chkFri.Size = new System.Drawing.Size(48, 16);
523 this.chkFri.TabIndex = 4;
524 this.chkFri.Text = "Fri";
525 //
526 // chkThu
527 //
528 this.chkThu.Location = new System.Drawing.Point(16, 64);
529 this.chkThu.Name = "chkThu";
530 this.chkThu.Size = new System.Drawing.Size(48, 16);
531 this.chkThu.TabIndex = 3;
532 this.chkThu.Text = "Thu";
533 //
534 // chkWed
535 //
536 this.chkWed.Location = new System.Drawing.Point(128, 32);
537 this.chkWed.Name = "chkWed";
538 this.chkWed.Size = new System.Drawing.Size(48, 16);
539 this.chkWed.TabIndex = 2;
540 this.chkWed.Text = "Wed";
541 //
542 // chkTue
543 //
544 this.chkTue.Location = new System.Drawing.Point(72, 32);
545 this.chkTue.Name = "chkTue";
546 this.chkTue.Size = new System.Drawing.Size(48, 16);
547 this.chkTue.TabIndex = 1;
548 this.chkTue.Text = "Tue";
549 //
550 // chkMon
551 //
552 this.chkMon.Location = new System.Drawing.Point(16, 32);
553 this.chkMon.Name = "chkMon";
554 this.chkMon.Size = new System.Drawing.Size(48, 16);
555 this.chkMon.TabIndex = 0;
556 this.chkMon.Text = "Mon";
557 //
558 // grpTimeOfDay
559 //
560 this.grpTimeOfDay.Controls.Add(this.rdoBoth);
561 this.grpTimeOfDay.Controls.Add(this.rdoPM);
562 this.grpTimeOfDay.Controls.Add(this.rdoAM);
563 this.grpTimeOfDay.Location = new System.Drawing.Point(311, 32);
564 this.grpTimeOfDay.Name = "grpTimeOfDay";
565 this.grpTimeOfDay.Size = new System.Drawing.Size(240, 48);
566 this.grpTimeOfDay.TabIndex = 58;
567 this.grpTimeOfDay.TabStop = false;
568 this.grpTimeOfDay.Text = "Time of Day";
569 //
570 // rdoBoth
571 //
572 this.rdoBoth.Checked = true;
573 this.rdoBoth.Location = new System.Drawing.Point(176, 24);
574 this.rdoBoth.Name = "rdoBoth";
575 this.rdoBoth.Size = new System.Drawing.Size(48, 16);
576 this.rdoBoth.TabIndex = 2;
577 this.rdoBoth.TabStop = true;
578 this.rdoBoth.Text = "Both";
579 //
580 // rdoPM
581 //
582 this.rdoPM.Location = new System.Drawing.Point(96, 24);
583 this.rdoPM.Name = "rdoPM";
584 this.rdoPM.Size = new System.Drawing.Size(72, 16);
585 this.rdoPM.TabIndex = 1;
586 this.rdoPM.Text = "PM Only";
587 //
588 // rdoAM
589 //
590 this.rdoAM.Location = new System.Drawing.Point(16, 24);
591 this.rdoAM.Name = "rdoAM";
592 this.rdoAM.Size = new System.Drawing.Size(72, 16);
593 this.rdoAM.TabIndex = 0;
594 this.rdoAM.Text = "AM Only";
595 //
596 // label1
597 //
598 this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
599 this.label1.Location = new System.Drawing.Point(6, 16);
600 this.label1.Name = "label1";
601 this.label1.Size = new System.Drawing.Size(136, 16);
602 this.label1.TabIndex = 57;
603 this.label1.Text = "Date Range:";
604 //
605 // groupBox2
606 //
607 this.groupBox2.Controls.Add(this.lstResults);
608 this.groupBox2.Dock = System.Windows.Forms.DockStyle.Fill;
609 this.groupBox2.Location = new System.Drawing.Point(0, 208);
610 this.groupBox2.Name = "groupBox2";
611 this.groupBox2.Size = new System.Drawing.Size(923, 189);
612 this.groupBox2.TabIndex = 57;
613 this.groupBox2.TabStop = false;
614 this.groupBox2.Text = "Search Result";
615 //
616 // lstResults
617 //
618 this.lstResults.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
619 this.colID,
620 this.colDate,
621 this.colDOW,
622 this.colStartTime,
623 this.colEndTime,
624 this.colResource,
625 this.colSlots,
626 this.colAccessType});
627 this.lstResults.Dock = System.Windows.Forms.DockStyle.Fill;
628 this.lstResults.FullRowSelect = true;
629 this.lstResults.GridLines = true;
630 this.lstResults.Location = new System.Drawing.Point(3, 16);
631 this.lstResults.MultiSelect = false;
632 this.lstResults.Name = "lstResults";
633 this.lstResults.Size = new System.Drawing.Size(917, 170);
634 this.lstResults.TabIndex = 0;
635 this.lstResults.UseCompatibleStateImageBehavior = false;
636 this.lstResults.View = System.Windows.Forms.View.Details;
637 this.lstResults.DoubleClick += new System.EventHandler(this.lstResults_DoubleClick);
638 //
639 // colID
640 //
641 this.colID.Text = "ID";
642 this.colID.Width = 0;
643 //
644 // colDate
645 //
646 this.colDate.Text = "Date";
647 this.colDate.Width = 91;
648 //
649 // colDOW
650 //
651 this.colDOW.Text = "Day of Week";
652 this.colDOW.Width = 80;
653 //
654 // colStartTime
655 //
656 this.colStartTime.Text = "Start Time";
657 this.colStartTime.Width = 87;
658 //
659 // colEndTime
660 //
661 this.colEndTime.Text = "End Time";
662 this.colEndTime.Width = 116;
663 //
664 // colResource
665 //
666 this.colResource.Text = "Resource";
667 this.colResource.Width = 370;
668 //
669 // colSlots
670 //
671 this.colSlots.Text = "Slots";
672 this.colSlots.Width = 47;
673 //
674 // colAccessType
675 //
676 this.colAccessType.Text = "Access Type";
677 this.colAccessType.Width = 101;
678 //
679 // lblMessage
680 //
681 this.lblMessage.AutoSize = true;
682 this.lblMessage.Font = new System.Drawing.Font("Tahoma", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
683 this.lblMessage.ForeColor = System.Drawing.Color.Red;
684 this.lblMessage.Location = new System.Drawing.Point(337, 16);
685 this.lblMessage.Name = "lblMessage";
686 this.lblMessage.Size = new System.Drawing.Size(0, 16);
687 this.lblMessage.TabIndex = 3;
688 //
689 // DApptSearch
690 //
691 this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
692 this.CancelButton = this.cmdCancel;
693 this.ClientSize = new System.Drawing.Size(923, 501);
694 this.Controls.Add(this.groupBox2);
695 this.Controls.Add(this.groupBox1);
696 this.Controls.Add(this.pnlDescription);
697 this.Controls.Add(this.panel1);
698 this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
699 this.Name = "DApptSearch";
700 this.Text = "Find Clinic Availability";
701 this.panel1.ResumeLayout(false);
702 this.panel1.PerformLayout();
703 this.pnlDescription.ResumeLayout(false);
704 this.grpDescription.ResumeLayout(false);
705 this.groupBox1.ResumeLayout(false);
706 this.groupBox1.PerformLayout();
707 this.grpDayOfWeek.ResumeLayout(false);
708 this.grpTimeOfDay.ResumeLayout(false);
709 this.groupBox2.ResumeLayout(false);
710 this.ResumeLayout(false);
711
712 }
713 #endregion
714
715 #region Event Handlers
716
717 private void cmdSearch_Click(object sender, System.EventArgs e)
718 {
719 //Tell user we are processing
720 this.Cursor = Cursors.WaitCursor;
721 this.lblMessage.Text = String.Empty;
722
723 //Get the control data into local vars
724 UpdateDialogData(false);
725 //Resource array, Begin date, Access type array, MTWTF , AM PM
726
727 //Get Availabilities and Appointments from the DB
728 //NB: m_sAmpm and m_sWeekDays don't have an effect on the M side side right now
729 m_dStart = m_dStart.Date; // move to 1200
730 m_dEnd = m_dEnd.Date.AddHours(23).AddMinutes(59).AddSeconds(59); //move to 235959
731 string sSearchInfo = "1|" + m_sAmpm + "|" + m_sWeekDays;
732 DataTable m_availTable = CGSchedLib.CreateAvailabilitySchedule(m_DocManager, m_alResources, m_dStart, m_dEnd, m_alAccessTypes, ScheduleType.Resource, sSearchInfo);
733 DataTable m_apptTable = CGSchedLib.CreateAppointmentSchedule(m_DocManager, m_alResources, m_dStart, m_dEnd);
734
735#if DEBUG
736 System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
737 stopwatch.Start();
738#endif
739 lstResultantAvailabilities = (from rowAV in m_availTable.AsEnumerable()
740
741 // Calculate the number of slots consumed in this availability by appointments
742 let slotsConsumed = (from appt in m_apptTable.AsEnumerable()
743 //If the resource is the same and the user selection overlaps, then...
744 where (rowAV.Field<string>("RESOURCE") == appt.Field<string>("RESOURCENAME")
745 && CalendarGrid.TimesOverlap(rowAV.Field<DateTime>("START_TIME"), rowAV.Field<DateTime>("END_TIME"), appt.Field<DateTime>("START_TIME"), appt.Field<DateTime>("END_TIME")))
746 // if appt starttime is before avail start time, only count against the avail starting from the availability start time
747 let startTimeToCountAgainstBlock = appt.Field<DateTime>("START_TIME") < rowAV.Field<DateTime>("START_TIME") ? rowAV.Field<DateTime>("START_TIME") : appt.Field<DateTime>("START_TIME")
748 // if appt endtime is after the avail ends, only count against the avail up to where the avail ends
749 let endTimeToCountAgainstBlock = appt.Field<DateTime>("END_TIME") > rowAV.Field<DateTime>("END_TIME") ? rowAV.Field<DateTime>("END_TIME") : appt.Field<DateTime>("END_TIME")
750 // theoretical minutes per slot for the availability
751 let minPerSlot = (rowAV.Field<DateTime>("END_TIME") - rowAV.Field<DateTime>("START_TIME")).TotalMinutes / rowAV.Field<int>("SLOTS")
752 // how many minutes does this appointment take away from the slot
753 let minPerAppt = (endTimeToCountAgainstBlock - startTimeToCountAgainstBlock).TotalMinutes
754 // how many slots the appointment takes up using this availability's scale
755 let slotsConsumed = minPerAppt / minPerSlot
756 select slotsConsumed).Sum()
757
758 // Subtract the number consumed from the original ones
759 let slotsLeft = (float)rowAV.Field<int>("SLOTS") - slotsConsumed
760 // filter by that value if it is at least one slot
761 where slotsLeft >= 1
762 // Sort by Start Time, then by Resource Name
763 orderby rowAV.Field<DateTime>("START_TIME"), rowAV.Field<string>("RESOURCE")
764 //return as a CGAvailability
765 select new CGAvailability
766 {
767 ResourceList = rowAV.Field<string>("RESOURCE"),
768 StartTime = rowAV.Field<DateTime>("START_TIME"),
769 EndTime = rowAV.Field<DateTime>("END_TIME"),
770 Slots = (int)slotsLeft,
771 // AccessTypeName is grabbed from the Access Type Table using a psuedojoin syntax.
772 // "ACCESS_TYPE" is the IEN of the AcceesType.
773 // Single or default is b/c we are expecting one result.
774 AccessTypeName = (from at in m_dsGlobal.Tables["AccessTypes"].AsEnumerable()
775 where at.Field<int>("BMXIEN")==Int32.Parse(rowAV.Field<string>("ACCESS_TYPE"))
776 select at.Field<string>("ACCESS_TYPE_NAME")).SingleOrDefault<string>(),
777 AvailabilityType = rowAV.Field<int>("AVAILABILITYID")
778 })
779 // convert to Generic List
780 .ToList<CGAvailability>();
781
782 // if specific access types are chosen, filter the results based on a join against them.
783 if (m_alAccessTypes.Count > 0)
784 lstResultantAvailabilities = (from av in lstResultantAvailabilities
785 join at in m_alAccessTypes.Cast<string>() on av.AccessTypeName equals at
786 select av).ToList<CGAvailability>();
787
788 // if user chose AM radio button, get morning appointments
789 // TimeSpan.FromHours(12) gets the number of ticks since Midnight
790 if (rdoAM.Checked) // less than 12 pm
791 {
792 lstResultantAvailabilities = (from av in lstResultantAvailabilities
793 where av.StartTime.TimeOfDay < TimeSpan.FromHours(12)
794 select av).ToList<CGAvailability>();
795 }
796 // if user chose PM radio button, get morning appointments
797 if (rdoPM.Checked) // after or equal to 12 pm
798 {
799 lstResultantAvailabilities = (from av in lstResultantAvailabilities
800 where av.StartTime.TimeOfDay >= TimeSpan.FromHours(12)
801 select av).ToList<CGAvailability>();
802 }
803
804 // if any of the days of week are checked, create a new list based on them
805 // and clear the original list, and join the new lists together
806 if (chkMon.Checked || chkTue.Checked || chkWed.Checked || chkThu.Checked || chkFri.Checked || chkSat.Checked || chkSun.Checked)
807 {
808
809 var lstMonday = new List<CGAvailability>();
810 var lstTuesday = new List<CGAvailability>();
811 var lstWednesday = new List<CGAvailability>();
812 var lstThursday = new List<CGAvailability>();
813 var lstFriday = new List<CGAvailability>();
814 var lstSaturday = new List<CGAvailability>();
815 var lstSunday = new List<CGAvailability>();
816
817 if (chkMon.Checked == true)
818 {
819 lstMonday = (from av in lstResultantAvailabilities
820 where av.StartTime.DayOfWeek == DayOfWeek.Monday
821 select av).ToList<CGAvailability>();
822 }
823
824 if (chkTue.Checked == true)
825 {
826 lstTuesday = (from av in lstResultantAvailabilities
827 where av.StartTime.DayOfWeek == DayOfWeek.Tuesday
828 select av).ToList<CGAvailability>();
829 }
830
831 if (chkWed.Checked == true)
832 {
833 lstWednesday = (from av in lstResultantAvailabilities
834 where av.StartTime.DayOfWeek == DayOfWeek.Wednesday
835 select av).ToList<CGAvailability>();
836
837 }
838
839 if (chkThu.Checked == true)
840 {
841 lstThursday = (from av in lstResultantAvailabilities
842 where av.StartTime.DayOfWeek == DayOfWeek.Thursday
843 select av).ToList<CGAvailability>();
844
845 }
846
847 if (chkFri.Checked == true)
848 {
849 lstFriday = (from av in lstResultantAvailabilities
850 where av.StartTime.DayOfWeek == DayOfWeek.Friday
851 select av).ToList<CGAvailability>();
852 }
853
854 if (chkSat.Checked == true)
855 {
856 lstSaturday = (from av in lstResultantAvailabilities
857 where av.StartTime.DayOfWeek == DayOfWeek.Saturday
858 select av).ToList<CGAvailability>();
859
860 }
861
862 if (chkSun.Checked == true)
863 {
864 lstSunday = (from av in lstResultantAvailabilities
865 where av.StartTime.DayOfWeek == DayOfWeek.Sunday
866 select av).ToList<CGAvailability>();
867
868 }
869
870
871 lstResultantAvailabilities.Clear();
872 lstResultantAvailabilities.AddRange(lstMonday);
873 lstResultantAvailabilities.AddRange(lstTuesday);
874 lstResultantAvailabilities.AddRange(lstWednesday);
875 lstResultantAvailabilities.AddRange(lstThursday);
876 lstResultantAvailabilities.AddRange(lstFriday);
877 lstResultantAvailabilities.AddRange(lstSaturday);
878 lstResultantAvailabilities.AddRange(lstSunday);
879
880 lstResultantAvailabilities.OrderBy(av => av.StartTime).ThenBy(av => av.ResourceList);
881 }
882
883
884
885#if DEBUG
886 System.Diagnostics.Debug.Write("LINQ took this long: " + stopwatch.ElapsedMilliseconds + "\n");
887 stopwatch = null;
888#endif
889
890 //Then, convert the availabilities to ListViewItems
891 var items = (from item in lstResultantAvailabilities
892 let s = new string[] {item.AvailabilityType.ToString(), item.StartTime.ToShortDateString(), item.StartTime.DayOfWeek.ToString(),item.StartTime.ToShortTimeString() ,item.EndTime.ToShortTimeString() ,item.ResourceList,item.Slots.ToString(),item.AccessTypeName}
893 let lvItem = new ListViewItem(s)
894 select lvItem).ToArray<ListViewItem>();
895
896 //--Updating Listview
897 lstResults.BeginUpdate(); //tell listview to suspend drawing for now
898 lstResults.Items.Clear(); //empty it from old data
899
900 if (items.Length > 0) lstResults.Items.AddRange(items); // add new data
901 else this.lblMessage.Text = "No available Appointment Slots Found!";
902
903 lstResults.EndUpdate(); // ok done adding items, draw now.
904 //--End Update Listview
905
906 //We are done
907 this.Cursor = Cursors.Default;
908 }
909
910 private void cboAccessTypeFilter_SelectionChangeCommitted(object sender, System.EventArgs e)
911 {
912 //Load Access Types listbox & filter
913 string sGroup = cboAccessTypeFilter.Text;
914 if (sGroup == "<Show All Access Types>")
915 {
916 LoadListBox("ALL");
917 }
918 else
919 {
920 LoadListBox("SELECTED");
921 }
922
923 }
924
925
926 private void lstResults_DoubleClick(object sender, EventArgs e)
927 {
928 ProcessChoice(sender, e);
929 }
930
931 private void btnAccept_Click(object sender, EventArgs e)
932 {
933 ProcessChoice(sender, e);
934 }
935
936 /// <summary>
937 /// Shared method to process a user's choice
938 /// </summary>
939 /// <param name="s">sender</param>
940 /// <param name="e">EventArgs</param>
941 private void ProcessChoice(object s, EventArgs e)
942 {
943 if (lstResults.SelectedIndices.Count == 0)
944 {
945 this.DialogResult = DialogResult.None;
946 lblMessage.Text = "No Appointment Slot selected!";
947 return;
948 }
949
950 long availabilityKey = long.Parse(lstResults.SelectedItems[0].SubItems[0].Text);
951 _selectedAvailability = (from av in lstResultantAvailabilities
952 where av.AvailabilityType == availabilityKey
953 select av).Single<CGAvailability>();
954 this.DialogResult = DialogResult.OK;
955 }
956
957 /// <summary>
958 /// Adjust start date based on end date.
959 /// </summary>
960 /// <param name="sender"></param>
961 /// <param name="e"></param>
962 private void dtStart_ValueChanged(object sender, EventArgs e)
963 {
964 if (dtEnd.Value < dtStart.Value) dtEnd.Value = dtStart.Value;
965 }
966
967 /// <summary>
968 /// Adjust end date based on start date.
969 /// </summary>
970 /// <param name="sender"></param>
971 /// <param name="e"></param>
972 private void dtEnd_ValueChanged(object sender, EventArgs e)
973 {
974 if (dtStart.Value > dtEnd.Value) dtStart.Value = dtEnd.Value;
975 }
976
977 #endregion Event Handlers
978
979 #region Properties
980
981 /// <summary>
982 /// Gets the Availability Selected by the User in which to put an appointment
983 /// </summary>
984 public CGAvailability SelectedAvailability
985 {
986 get { return this._selectedAvailability; }
987 }
988
989 #endregion Properties
990
991
992 }
993}
Note: See TracBrowser for help on using the repository browser.