Ignore:
Timestamp:
Mar 3, 2011, 4:44:18 AM (13 years ago)
Author:
Sam Habiel
Message:

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:
1 edited

Legend:

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

    r1095 r1097  
    11using System;
    2 using System.Drawing;
    32using System.Collections;
    4 using System.ComponentModel;
     3using System.Collections.Generic;
    54using System.Windows.Forms;
    65using System.Data;
     6using System.Linq;
    77//using System.Data.OleDb;
    8 using IndianHealthService.BMXNet;
    98
    109namespace IndianHealthService.ClinicalScheduling
    1110{
    1211        /// <summary>
    13         /// Summary description for DApptSearch.
     12        /// Modal Dialog for searching for Patient Slots
    1413        /// </summary>
    1514        public class DApptSearch : System.Windows.Forms.Form
     
    1716                private System.Windows.Forms.Panel panel1;
    1817                private System.Windows.Forms.Button cmdCancel;
    19                 private System.Windows.Forms.Button cmdOK;
     18                private System.Windows.Forms.Button btnAccept;
    2019                private System.Windows.Forms.Panel pnlDescription;
    2120                private System.Windows.Forms.GroupBox grpDescription;
     
    3837                private System.Windows.Forms.RadioButton rdoPM;
    3938                private System.Windows.Forms.RadioButton rdoAM;
    40                 private System.Windows.Forms.Label label1;
    41                 private System.Windows.Forms.MonthCalendar calStartDate;
    42                 private System.Windows.Forms.GroupBox groupBox2;
    43                 private System.Windows.Forms.DataGrid grdResult;
    44                 private System.Windows.Forms.Button cmdSearch;
    45                 /// <summary>
    46                 /// Required designer variable.
    47                 /// </summary>
    48                 private System.ComponentModel.Container components = null;
     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;
    4957
    5058                public DApptSearch()
     
    6068                DataTable               m_dtTypes;
    6169                DataView                m_dvTypes;
    62 
     70        List<CGAvailability> lstResultantAvailabilities;
     71        private CGAvailability _selectedAvailability;
    6372                DateTime                m_dStart;
    6473                DateTime                m_dEnd;
    6574                ArrayList               m_alResources;
    6675                ArrayList               m_alAccessTypes;
    67                 string                  m_sWeekDays;
    68                 string                  m_sAmpm;
    69 
    70                 DataTable               m_dtResult;
    71                 DataView                m_dvResult;
    72 
    73                 string                  m_sSelectedResource;
    74                 DateTime                m_sSelectedDate;
     76                string                  m_sWeekDays; //only practical use now is for sending to server
     77                string                  m_sAmpm; // same here.
    7578
    7679                #endregion Fields
     
    110113                {
    111114
    112                         this.m_DocManager = docManager;
     115            this.Text = "Searching for Appointments in: " + string.Join(" | ", alResources.Cast<string>());
     116           
     117            this.m_DocManager = docManager;
    113118                        this.m_dsGlobal = m_DocManager.GlobalDataSet;
    114                         System.IntPtr pHandle = this.Handle;
     119                       
    115120                        LoadListBox("ALL");
    116121
     
    136141                        cboAccessTypeFilter.Refresh();
    137142
    138                         //Create DataGridTableStyle for Result grid
     143
     144            /* OLD CODE
     145            //Create DataGridTableStyle for Result grid
    139146                        DataGridTableStyle tsResult = new DataGridTableStyle();
    140147                        tsResult.MappingName = "Result";
    141148                        tsResult.ReadOnly = true;
     149
    142150                        // Add START_TIME column style.
    143151                        DataGridTextBoxColumn colStartTime = new DataGridTextBoxColumn();
    144                         colStartTime.MappingName = "START_TIME";
     152            colStartTime.MappingName = "StartTime";
    145153                        colStartTime.HeaderText = "Start Time";
    146154                        colStartTime.Width = 200;
     
    150158                        // Add END_TIME column style.
    151159                        DataGridTextBoxColumn colEndTime = new DataGridTextBoxColumn();
    152                         colEndTime.MappingName = "END_TIME";
     160            colEndTime.MappingName = "EndTime";
    153161                        colEndTime.HeaderText = "End Time";
    154162                        colEndTime.Width = 75;
     
    158166                        // Add RESOURCE column style.
    159167                        DataGridTextBoxColumn colResource = new DataGridTextBoxColumn();
    160                         colResource.MappingName = "RESOURCE";
     168            colResource.MappingName = "ResourceList";
    161169                        colResource.HeaderText = "Resource";
    162170                        colResource.Width = 200;
     
    176184                        colAccess.Width = 200;
    177185                        tsResult.GridColumnStyles.Add(colAccess);
    178                         grdResult.TableStyles.Add(tsResult);
    179 
     186                        //grdResult.TableStyles.Add(tsResult);
     187            */
     188           
    180189                        this.UpdateDialogData(true);
    181190               
     
    232241
    233242                                //Start
    234                                 this.m_dStart = this.calStartDate.SelectionStart;
     243                this.m_dStart = this.dtStart.Value;
    235244
    236245                                //End
    237                                 m_dEnd = calStartDate.SelectionEnd;
    238                                 m_dEnd = m_dEnd.AddHours(23);
    239                                 m_dEnd = m_dEnd.AddMinutes(59);
    240 
     246                                this.m_dEnd = this.dtEnd.Value;
    241247                        }               
    242248                }
     
    270276            this.cmdSearch = new System.Windows.Forms.Button();
    271277            this.cmdCancel = new System.Windows.Forms.Button();
    272             this.cmdOK = new System.Windows.Forms.Button();
     278            this.btnAccept = new System.Windows.Forms.Button();
    273279            this.pnlDescription = new System.Windows.Forms.Panel();
    274280            this.grpDescription = new System.Windows.Forms.GroupBox();
    275281            this.lblDescription = new System.Windows.Forms.Label();
    276282            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();
    277287            this.label3 = new System.Windows.Forms.Label();
    278288            this.label2 = new System.Windows.Forms.Label();
     
    292302            this.rdoAM = new System.Windows.Forms.RadioButton();
    293303            this.label1 = new System.Windows.Forms.Label();
    294             this.calStartDate = new System.Windows.Forms.MonthCalendar();
    295304            this.groupBox2 = new System.Windows.Forms.GroupBox();
    296             this.grdResult = new System.Windows.Forms.DataGrid();
     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()));
    297314            this.panel1.SuspendLayout();
    298315            this.pnlDescription.SuspendLayout();
     
    302319            this.grpTimeOfDay.SuspendLayout();
    303320            this.groupBox2.SuspendLayout();
    304             ((System.ComponentModel.ISupportInitialize)(this.grdResult)).BeginInit();
    305321            this.SuspendLayout();
    306322            //
     
    309325            this.panel1.Controls.Add(this.cmdSearch);
    310326            this.panel1.Controls.Add(this.cmdCancel);
    311             this.panel1.Controls.Add(this.cmdOK);
     327            this.panel1.Controls.Add(this.btnAccept);
    312328            this.panel1.Dock = System.Windows.Forms.DockStyle.Bottom;
    313329            this.panel1.Location = new System.Drawing.Point(0, 461);
     
    334350            this.cmdCancel.Text = "Cancel";
    335351            //
    336             // cmdOK
    337             //
    338             this.cmdOK.DialogResult = System.Windows.Forms.DialogResult.OK;
    339             this.cmdOK.Location = new System.Drawing.Point(128, 8);
    340             this.cmdOK.Name = "cmdOK";
    341             this.cmdOK.Size = new System.Drawing.Size(64, 24);
    342             this.cmdOK.TabIndex = 0;
    343             this.cmdOK.Text = "OK";
    344             this.cmdOK.Visible = false;
    345             this.cmdOK.Click += new System.EventHandler(this.cmdOK_Click);
     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);
    346361            //
    347362            // pnlDescription
     
    378393            // groupBox1
    379394            //
     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);
    380399            this.groupBox1.Controls.Add(this.label3);
    381400            this.groupBox1.Controls.Add(this.label2);
     
    385404            this.groupBox1.Controls.Add(this.grpTimeOfDay);
    386405            this.groupBox1.Controls.Add(this.label1);
    387             this.groupBox1.Controls.Add(this.calStartDate);
    388406            this.groupBox1.Dock = System.Windows.Forms.DockStyle.Top;
    389407            this.groupBox1.Location = new System.Drawing.Point(0, 0);
     
    393411            this.groupBox1.TabStop = false;
    394412            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;
    395445            //
    396446            // label3
     
    542592            //
    543593            this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
    544             this.label1.Location = new System.Drawing.Point(16, 24);
     594            this.label1.Location = new System.Drawing.Point(6, 16);
    545595            this.label1.Name = "label1";
    546596            this.label1.Size = new System.Drawing.Size(136, 16);
     
    548598            this.label1.Text = "Date Range:";
    549599            //
    550             // calStartDate
    551             //
    552             this.calStartDate.Location = new System.Drawing.Point(16, 40);
    553             this.calStartDate.MaxSelectionCount = 62;
    554             this.calStartDate.Name = "calStartDate";
    555             this.calStartDate.TabIndex = 56;
    556             //
    557600            // groupBox2
    558601            //
    559             this.groupBox2.Controls.Add(this.grdResult);
     602            this.groupBox2.Controls.Add(this.lstResults);
    560603            this.groupBox2.Dock = System.Windows.Forms.DockStyle.Fill;
    561604            this.groupBox2.Location = new System.Drawing.Point(0, 208);
     
    566609            this.groupBox2.Text = "Search Result";
    567610            //
    568             // grdResult
    569             //
    570             this.grdResult.CaptionVisible = false;
    571             this.grdResult.DataMember = "";
    572             this.grdResult.Dock = System.Windows.Forms.DockStyle.Fill;
    573             this.grdResult.HeaderForeColor = System.Drawing.SystemColors.ControlText;
    574             this.grdResult.Location = new System.Drawing.Point(3, 16);
    575             this.grdResult.Name = "grdResult";
    576             this.grdResult.ReadOnly = true;
    577             this.grdResult.Size = new System.Drawing.Size(917, 170);
    578             this.grdResult.TabIndex = 0;
    579             this.grdResult.DoubleClick += new System.EventHandler(this.grdResult_DoubleClick);
    580             this.grdResult.CurrentCellChanged += new System.EventHandler(this.grdResult_CurrentCellChanged);
     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;
    581673            //
    582674            // DApptSearch
     
    596688            this.grpDescription.ResumeLayout(false);
    597689            this.groupBox1.ResumeLayout(false);
     690            this.groupBox1.PerformLayout();
    598691            this.grpDayOfWeek.ResumeLayout(false);
    599692            this.grpTimeOfDay.ResumeLayout(false);
    600693            this.groupBox2.ResumeLayout(false);
    601             ((System.ComponentModel.ISupportInitialize)(this.grdResult)).EndInit();
    602694            this.ResumeLayout(false);
    603695
     
    606698
    607699        #region Event Handlers
    608         private void cmdOK_Click(object sender, System.EventArgs e)
    609                 {
    610 
    611                 }
    612700
    613701                private void cmdSearch_Click(object sender, System.EventArgs e)
    614702                {
    615                         //Get the control data into local vars
     703                        //Tell user we are processing
     704            this.Cursor = Cursors.WaitCursor;
     705           
     706            //Get the control data into local vars
    616707                        UpdateDialogData(false);
    617708                        //Resource array, Begin date, Access type array, MTWTF , AM PM
    618                         //Assemble |-delimited resource string
    619                         string sResources = "";
    620                         for (int j=0; j < m_alResources.Count; j++)
    621                         {
    622                                 sResources = sResources + m_alResources[j];
    623                                 if (j < (m_alResources.Count - 1))
    624                                         sResources = sResources + "|";
    625                         }
    626 
    627                         //Access Types Array
    628                         string sTypes = "";
    629                         if (m_alAccessTypes.Count > 0)
    630                         {
    631                                 for (int j=0; j < m_alAccessTypes.Count; j++)
    632                                 {
    633                                         sTypes = sTypes + (string) m_alAccessTypes[j];
    634                                         if (j < (m_alAccessTypes.Count-1))
    635                                                 sTypes = sTypes + "|";
    636                                 }
    637                         }
    638 
     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
    639712                        string sSearchInfo = "1|" + m_sAmpm + "|" + m_sWeekDays;
    640                         m_dtResult = CGSchedLib.CreateAvailabilitySchedule(m_DocManager, m_alResources, m_dStart, m_dEnd, m_alAccessTypes, ScheduleType.Resource, sSearchInfo);
    641 
    642                         if (m_dtResult.Rows.Count == 0)
    643                         {
    644                                 MessageBox.Show("No availability found.");
    645                                 return;
    646                         }
    647 
    648                         m_dtResult.TableName = "Result";
    649                         m_dtResult.Columns.Add("AMPM", System.Type.GetType("System.String") ,"Convert(START_TIME, 'System.String')" );
    650                         m_dtResult.Columns.Add("DAYOFWEEK", System.Type.GetType("System.String"));
    651                         m_dtResult.Columns.Add("ACCESSNAME", System.Type.GetType("System.String"));
    652 
    653                         DataRow drAT;
    654                         DateTime dt;
    655                         string sDOW;
    656                         int nAccessTypeID;
    657                         string sAccessType;
    658 
    659                         foreach (DataRow dr in m_dtResult.Rows)
    660                         {
    661                                 dt = (DateTime) dr["START_TIME"];
    662                                 sDOW = dt.DayOfWeek.ToString();
    663                                 dr["DAYOFWEEK"] = sDOW;
    664                                 if (dr["ACCESS_TYPE"].ToString() != "")
    665                                 {
    666                                         nAccessTypeID =Convert.ToInt16(dr["ACCESS_TYPE"].ToString());
    667                                         drAT = m_dsGlobal.Tables["AccessTypes"].Rows.Find(nAccessTypeID);
    668                                         if (drAT != null)
    669                                         {
    670                                                 sAccessType = drAT["ACCESS_TYPE_NAME"].ToString();
    671                                                 dr["ACCESSNAME"] = sAccessType;
    672                                         }
    673                                 }
    674                         }
    675 
    676 
    677                         m_dvResult = new DataView(m_dtResult);
    678 
    679                         string sFilter = "(SLOTS > 0)";
    680                         if (m_sAmpm != "")
    681                         {
    682                                 if (m_sAmpm == "AM")
    683                                         sFilter = sFilter + " AND (AMPM LIKE '*AM*')";
    684                                 if (m_sAmpm == "PM")
    685                                         sFilter = sFilter + " AND (AMPM LIKE '*PM*')";
    686                         }
    687 
    688                         bool sOr = false;
    689                         if (m_sWeekDays != "")
    690                         {
    691                                 sFilter += " AND (";
    692                                 if (chkMon.Checked == true)
    693                                 {
    694                                         sFilter = sFilter + "(DAYOFWEEK LIKE '*Monday*')";
    695                                         sOr = true;
    696                                 }
    697                                 if (chkTue.Checked == true)
    698                                 {
    699                                         sFilter = (sOr == true)?sFilter + " OR ":sFilter;
    700                                         sFilter = sFilter + "(DAYOFWEEK LIKE '*Tuesday*')";
    701                                         sOr = true;
    702                                 }
    703                                 if (chkWed.Checked == true)
    704                                 {
    705                                         sFilter = (sOr == true)?sFilter + " OR ":sFilter;
    706                                         sFilter = sFilter + "(DAYOFWEEK LIKE '*Wednesday*')";
    707                                         sOr = true;
    708                                 }
    709                                 if (chkThu.Checked == true)
    710                                 {
    711                                         sFilter = (sOr == true)?sFilter + " OR ":sFilter;
    712                                         sFilter = sFilter + "(DAYOFWEEK LIKE '*Thursday*')";
    713                                         sOr = true;
    714                                 }
    715                                 if (chkFri.Checked == true)
    716                                 {
    717                                         sFilter = (sOr == true)?sFilter + " OR ":sFilter;
    718                                         sFilter = sFilter + "(DAYOFWEEK LIKE '*Friday*')";
    719                                         sOr = true;
    720                                 }
    721                                 if (chkSat.Checked == true)
    722                                 {
    723                                         sFilter = (sOr == true)?sFilter + " OR ":sFilter;
    724                                         sFilter = sFilter + "(DAYOFWEEK LIKE '*Saturday*')";
    725                                         sOr = true;
    726                                 }
    727                                 if (chkSun.Checked == true)
    728                                 {
    729                                         sFilter = (sOr == true)?sFilter + " OR ":sFilter;
    730                                         sFilter = sFilter + "(DAYOFWEEK LIKE '*Sunday*')";
    731                                         sOr = true;
    732                                 }
    733                                 sFilter += ")";
    734                         }
    735 
    736                         if (m_alAccessTypes.Count > 0)
    737                         {
    738                                 sFilter += " AND (";
    739                                 sOr = false;
    740                                 foreach (string sType in m_alAccessTypes)
    741                                 {
    742                                         if (sOr == true)
    743                                                 sFilter += " OR ";
    744                                         sOr = true;
    745                                         sFilter += "(ACCESSNAME = '" + sType + "')";
    746                                 }
    747                                 sFilter += ")";
    748                         }       
    749 
    750                         m_dvResult.RowFilter = sFilter;
    751                         this.grdResult.DataSource = m_dvResult;
    752 
     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;
    753889                }
    754890
     
    770906                private void grdResult_DoubleClick(object sender, System.EventArgs e)
    771907                {
    772                         if (grdResult.DataSource == null)
     908                        /*
     909            if (lstResults.DataSource == null)
    773910                                return;
    774911
    775                         DataGridCell dgCell;
     912                        DataGridViewCell dgCell;
    776913                        dgCell = this.grdResult.CurrentCell;
    777                         dgCell.ColumnNumber = 2;
    778                         this.m_sSelectedResource = grdResult[dgCell.RowNumber, dgCell.ColumnNumber].ToString();
    779                         this.m_sSelectedDate = (DateTime) grdResult[dgCell.RowNumber,0];
     914            this.m_sSelectedResource = grdResult.SelectedRows[0].Cells[2].ToString();
     915            this.m_sSelectedDate = (DateTime)grdResult.SelectedRows[0].Cells[0].Value;
    780916                        this.DialogResult = DialogResult.OK;
    781917                        this.Close();
     918             */
    782919                }
    783920
    784921                private void grdResult_CurrentCellChanged(object sender, System.EventArgs e)
    785922                {
    786                         DataGridCell dgCell;
    787                         dgCell = this.grdResult.CurrentCell;
    788                         this.grdResult.Select(dgCell.RowNumber);
    789 
     923                        /*
     924            DataGridViewCell dgCell;
     925            dgCell = this.grdResult.CurrentCell;
     926             */
    790927        }
    791928
     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
    792954        #endregion  Event Handlers
    793955
    794956        #region Properties
     957
     958       
    795959        /// <summary>
    796                 /// Gets the resource selected by the user
    797                 /// </summary>
    798                 public string SelectedResource
    799                 {
    800                         get
    801                         {
    802                                 return this.m_sSelectedResource;
    803                         }
    804                 }
    805 
    806                 /// <summary>
    807                 /// Gets the date selected by the user
    808                 /// </summary>
    809                 public DateTime SelectedDate
    810                 {
    811                         get
    812                         {
    813                                 return this.m_sSelectedDate;
    814                         }
    815                 }
     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
    816967                #endregion Properties
    817 
    818         }
     968    }
    819969}
Note: See TracChangeset for help on using the changeset viewer.