Index: Scheduling/trunk/cs/bsdx0200GUISourceCode/CGDocument.cs
===================================================================
--- Scheduling/trunk/cs/bsdx0200GUISourceCode/CGDocument.cs	(revision 1084)
+++ Scheduling/trunk/cs/bsdx0200GUISourceCode/CGDocument.cs	(revision 1095)
@@ -173,4 +173,5 @@
         /// <summary>
         /// Update schedule based on info in RPMS
+        /// <returns>Clears and repopluates m_appointments</returns>
         /// </summary>
         private bool RefreshDaysSchedule()
@@ -200,4 +201,5 @@
                 m_dLastRefresh = DateTime.Now;
 
+                //Clear appointments associated with this document
                 this.m_appointments.ClearAllAppointments();
 
@@ -205,8 +207,5 @@
                 rAppointmentSchedule = CGSchedLib.CreateAppointmentSchedule(m_DocManager, m_sResourcesArray, this.m_dStartDate, this.m_dEndDate);
 
-                // Datatable dumper into Debug Log (nice to know that this exists)
-                CGSchedLib.OutputArray(rAppointmentSchedule, "rAppointmentSchedule");
-
-
+                // loop through datatable: Create CGAppointment and add to CGAppointments
                 foreach (DataRow r in rAppointmentSchedule.Rows)
                 {
@@ -422,17 +421,46 @@
             try
             {
-                if (this.m_DocManager.ConnectInfo.Connected == false)
-                {
-                    m_DocManager.ConnectInfo.LoadConnectInfo();
-                }
-
                 ArrayList saryApptTypes = new ArrayList();
-                int nApptTypeID = 0;
-
+                
                 //Refresh Availability schedules
                 DataTable rAvailabilitySchedule;
                 rAvailabilitySchedule = CGSchedLib.CreateAvailabilitySchedule(m_DocManager, m_sResourcesArray, this.m_dStartDate, this.m_dEndDate, saryApptTypes,/**/ m_ScheduleType, "0");
-                CGSchedLib.OutputArray(rAvailabilitySchedule, "rAvailabilitySchedule");
-
+
+                ////NEW
+                //NOTE: This lock makes sure that availabilities aren't queried for slots when the array is an intermediate
+                //state. The other place that has this lock is SlotsAvailable function.
+                lock (this.m_pAvArray)
+                {
+                    m_pAvArray.Clear();
+                    foreach (DataRow rTemp in rAvailabilitySchedule.Rows)
+                    {
+                        DateTime dStart = (DateTime)rTemp["START_TIME"];
+                        DateTime dEnd = (DateTime)rTemp["END_TIME"];
+
+                        //TODO: Fix this slots datatype problem
+                        string sSlots = rTemp["SLOTS"].ToString();
+                        int nSlots = Convert.ToInt16(sSlots);
+
+                        string sResourceList = rTemp["RESOURCE"].ToString();
+                        string sAccessRuleList = rTemp["ACCESS_TYPE"].ToString();
+                        string sNote = rTemp["NOTE"].ToString();
+
+                        int nApptTypeID;
+
+                        if ((nSlots < -1000) || (sAccessRuleList == ""))
+                        {
+                            nApptTypeID = 0;
+                        }
+                        else
+                        {
+                            nApptTypeID = Int32.Parse(rTemp["ACCESS_TYPE"].ToString());
+                        }
+
+                        AddAvailability(dStart, dEnd, nApptTypeID, nSlots, sResourceList, sAccessRuleList, sNote);
+                    }
+                }
+                return true;
+                
+                /* NOT USED
                 //Refresh Type Schedule
                 string sResourceName = "";
@@ -442,5 +470,5 @@
                     sResourceName = m_sResourcesArray[j].ToString();
                     DataTable dtTemp = CGSchedLib.CreateAssignedTypeSchedule(m_DocManager, sResourceName, this.m_dStartDate, this.m_dEndDate, m_ScheduleType);
-                    CGSchedLib.OutputArray(dtTemp, "dtTemp");
+
                     if (j == 0)
                     {
@@ -452,5 +480,4 @@
                     }
                 }
-                CGSchedLib.OutputArray(rTypeSchedule, "rTypeSchedule");
 
                 DateTime dStart;
@@ -523,8 +550,9 @@
 
 
-                        AddAvailability(dStart, dEnd, nApptTypeID, nSlots, false, sResourceList, sAccessRuleList, sNote);
+                        //AddAvailability(dStart, dEnd, nApptTypeID, nSlots, sResourceList, sAccessRuleList, sNote);
                     }//end foreach datarow rTemp
                 }//end lock
                 return true;
+             */
             }
             catch (Exception ex)
@@ -552,5 +580,5 @@
         /// <param name="sNote"></param>
         /// <returns></returns>
-        public int AddAvailability(DateTime StartTime, DateTime EndTime, int nType, int nSlots, bool UpdateView, string sResourceList, string sAccessRuleList, string sNote)
+        public int AddAvailability(DateTime StartTime, DateTime EndTime, int nType, int nSlots, string sResourceList, string sAccessRuleList, string sNote)
         {
             //adds it to the object array
@@ -588,8 +616,5 @@
             int nIndex = 0;
             nIndex = m_pAvArray.Add(pNewAv);
-            if (UpdateView == true)
-            {
-                this.UpdateAllViews();
-            }
+
             return nIndex;
         }
