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

Last change on this file since 1097 was 1097, checked in by Sam Habiel, 13 years ago

DPatientLookup.cs: Usings Cleanup
DApptSearch: Extensive refactoring. Now uses new algorithm to find appointments. Now outputs CGAvailability
CGView: Appointments checked in now set the Checkin time on the appointment structure; changes to support DApptSearch modified output.
CGSchedLib: Extensive refactoring; only 2 methods remain: CreateAppointmentSchedule and CreateAvailabilitySchedule
CGDocument: SlotsAvailable uses a new algorithm
CGAVView: Uses CalendarGrid.TimesOverlap instead of the removed one in CGSchedLib
CGAVDocument: Uses CalendarGrid.TimesOverlap instead of the removed one in CGSchedLib; CreateAssignedSlotSchedule reassigned to CreateAvailabilitySchedule

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