private void Search()
        {
            if (pnlResults.InvokeRequired)
            {
                EmptyDelegate ed = new EmptyDelegate(Search);
                Invoke(ed);
            }
            else
            {
                eligibility_data ed       = new eligibility_data();
                DataTable        matches  = ed.Search(BuildSQL());
                DateTime?        lastDate = new DateTime(1900, 1, 1);
                numAppointmentsFound = matches.Rows.Count;

                pnlResults.SuspendLayout();
                pnlResults.Controls.Clear();

                foreach (DataRow aRow in matches.Rows)
                {
                    ed = new eligibility_data();
                    ed.Load(aRow);
                    AddAppointment(ed, lastDate);
                    lastDate = ed.appt_date;
                }
                pnlResults.ResumeLayout();
                UpdateLastLabelSafe(lastDateLabel, numAppointmentsCurrentDate);
                UpdateBinCounts();
            }
        }
 private void UpdateBinCounts()
 {
     if (btnTomorrow.InvokeRequired)
     {
         EmptyDelegate ed = new EmptyDelegate(UpdateBinCounts);
         Invoke(ed);
     }
     else
     {
         eligibility_data ed = new eligibility_data();
         UpdateBinCount(ed.Search(BuildSQL(true, FormSearchMode.Unsent)).Rows[0][0].ToString(),
                        btnUnverified, "Unsent", _searchMode == FormSearchMode.Unsent);
         UpdateBinCount(ed.Search(BuildSQL(true, FormSearchMode.Rejected)).Rows[0][0].ToString(),
                        btnRejected, "Rejected", _searchMode == FormSearchMode.Rejected);
         UpdateBinCount(ed.Search(BuildSQL(true, FormSearchMode.Tomorrow)).Rows[0][0].ToString(),
                        btnTomorrow, "Tomorrow", _searchMode == FormSearchMode.Tomorrow);
         UpdateBinCount(ed.Search(BuildSQL(true, FormSearchMode.AllUpcoming)).Rows[0][0].ToString(),
                        btnUpcoming, "All Upcoming", _searchMode == FormSearchMode.AllUpcoming);
         UpdateBinCount(ed.Search(BuildSQL(true, FormSearchMode.Sent)).Rows[0][0].ToString(),
                        btnSent, "Sent", _searchMode == FormSearchMode.Sent);
     }
 }
        /// <summary>
        /// Checks to see if a given record exists in our system. If so, updates it. If not, creates it.
        /// </summary>
        /// <param name="aRow"></param>
        /// <returns></returns>
        private void CheckCreateEligibility(DataRow aRow)
        {
            eligibility_data egd = new eligibility_data();

            egd.dentrix_id = Convert.ToInt32(aRow["APPTID"].ToString());
            egd.dentrix_db = Convert.ToInt32(aRow["APPTDB"].ToString());
            DataTable matches = egd.Search();

            if (matches.Rows.Count > 0)
            {
                // We have a copy of this stored locally
                egd.Load(matches.Rows[0]);
            }

            // appt_date PatName, ApptLen, Time_Hour, Time_Minute, ApptReason
            egd.patient_name = aRow["PatName"].ToString();
            egd.appt_length  = Convert.ToInt32(aRow["ApptLen"]);
            DateTime apptDay = Convert.ToDateTime(aRow["apptdate"].ToString());

            egd.appt_date      = new DateTime(apptDay.Year, apptDay.Month, apptDay.Day, Convert.ToInt32(aRow["Time_Hour"]), Convert.ToInt32(aRow["Time_Minute"]), 0);
            egd.procedure_info = aRow["apptReason"].ToString();

            egd.Save();
        }