Index: Scheduling/trunk/cs/bsdx0200GUISourceCode/CGView.cs
===================================================================
--- Scheduling/trunk/cs/bsdx0200GUISourceCode/CGView.cs	(revision 1075)
+++ Scheduling/trunk/cs/bsdx0200GUISourceCode/CGView.cs	(revision 1083)
@@ -617,5 +617,5 @@
             this.tvSchedules.Location = new System.Drawing.Point(0, 0);
             this.tvSchedules.Name = "tvSchedules";
-            this.tvSchedules.Size = new System.Drawing.Size(128, 332);
+            this.tvSchedules.Size = new System.Drawing.Size(128, 290);
             this.tvSchedules.Sorted = true;
             this.tvSchedules.TabIndex = 1;
@@ -664,5 +664,5 @@
             this.panelRight.Location = new System.Drawing.Point(941, 0);
             this.panelRight.Name = "panelRight";
-            this.panelRight.Size = new System.Drawing.Size(128, 332);
+            this.panelRight.Size = new System.Drawing.Size(128, 290);
             this.panelRight.TabIndex = 3;
             this.panelRight.Visible = false;
@@ -762,5 +762,5 @@
             this.panelCenter.Location = new System.Drawing.Point(136, 24);
             this.panelCenter.Name = "panelCenter";
-            this.panelCenter.Size = new System.Drawing.Size(802, 284);
+            this.panelCenter.Size = new System.Drawing.Size(802, 242);
             this.panelCenter.TabIndex = 7;
             // 
@@ -848,5 +848,5 @@
             this.panelBottom.Controls.Add(this.statusBar1);
             this.panelBottom.Dock = System.Windows.Forms.DockStyle.Bottom;
-            this.panelBottom.Location = new System.Drawing.Point(136, 308);
+            this.panelBottom.Location = new System.Drawing.Point(136, 266);
             this.panelBottom.Name = "panelBottom";
             this.panelBottom.Size = new System.Drawing.Size(802, 24);
@@ -866,5 +866,5 @@
             this.splitter1.Location = new System.Drawing.Point(128, 24);
             this.splitter1.Name = "splitter1";
-            this.splitter1.Size = new System.Drawing.Size(8, 308);
+            this.splitter1.Size = new System.Drawing.Size(8, 266);
             this.splitter1.TabIndex = 9;
             this.splitter1.TabStop = false;
@@ -875,5 +875,5 @@
             this.splitter2.Location = new System.Drawing.Point(938, 24);
             this.splitter2.Name = "splitter2";
-            this.splitter2.Size = new System.Drawing.Size(3, 308);
+            this.splitter2.Size = new System.Drawing.Size(3, 266);
             this.splitter2.TabIndex = 10;
             this.splitter2.TabStop = false;
@@ -903,5 +903,5 @@
             this.calendarGrid1.Resources = ((System.Collections.ArrayList)(resources.GetObject("calendarGrid1.Resources")));
             this.calendarGrid1.SelectedAppointment = 0;
-            this.calendarGrid1.Size = new System.Drawing.Size(802, 284);
+            this.calendarGrid1.Size = new System.Drawing.Size(802, 242);
             this.calendarGrid1.StartDate = new System.DateTime(2003, 1, 27, 0, 0, 0, 0);
             this.calendarGrid1.TabIndex = 0;
@@ -916,5 +916,5 @@
             // 
             this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
-            this.ClientSize = new System.Drawing.Size(1069, 332);
+            this.ClientSize = new System.Drawing.Size(1069, 290);
             this.Controls.Add(this.panelCenter);
             this.Controls.Add(this.panelBottom);
@@ -1923,6 +1923,7 @@
 			Debug.Assert(nApptID != 0);
 
-			CGAppointment a = (CGAppointment) this.Appointments.AppointmentTable[nApptID];
-
+            //smh
+			//CGAppointment a = (CGAppointment) this.Appointments.AppointmentTable[nApptID];
+            CGAppointment a = (CGAppointment)this.Document.Appointments.AppointmentTable[nApptID];
 			try
 			{
@@ -1980,5 +1981,10 @@
 				DateTime dtCheckIn = dlgCheckin.CheckInTime;
 
-				this.Document.CheckInAppointment(nApptID, dtCheckIn);
+				//Save to Database
+                this.Document.CheckInAppointment(nApptID, dtCheckIn);
+
+                //Tell appointment that it is checked in--smh cancel that!
+                //a.CheckInTime = DateTime.Now;
+
                 //smh new code
                 if (dlgCheckin.PrintRouteSlip)
@@ -1986,4 +1992,5 @@
                 // end new code
 
+                //redraw grid (would this work???)
 				this.calendarGrid1.Invalidate();
 			}
@@ -2034,5 +2041,6 @@
 				 * 8-10-05 Added overbook prompt for walkin
 				*/
-				this.Document.RefreshDocument();
+                //SMH: Takes too long to do.
+				//this.Document.RefreshDocument();
 				string sAccessType = "";
 				string sAvailabilityMessage = "";
@@ -2067,5 +2075,6 @@
 				appt.HealthRecordNumber = dPat.HealthRecordNumber;
 
-				this.Document.RefreshDocument();
+                //smh: Takes too long
+				//this.Document.RefreshDocument();
 
 				//Call Document to add a walkin appointment
@@ -2074,23 +2083,37 @@
 				//Now check them in.
 				calendarGrid1.SelectedAppointment = nApptID;
-
 				AppointmentCheckIn();
 
-				try
-				{
-					RaiseRPMSEvent("BSDX SCHEDULE" , m_Document.DocName);
-				}
-				catch (Exception ex)
-				{
-					Debug.Write(ex.Message);
-				}
+                //Show the new set of appointments by calling UpdateArrays. Fetches Document's CGAppointments
+                this.UpdateArrays();
+
+                //Get the appointments and availabilities, async, from Server. Callback updates this thread's controls.
+                OnUpdateScheduleDelegate ousd = new OnUpdateScheduleDelegate(OnUpdateSchedule);
+                ousd.BeginInvoke(OnUpdateScheduleCallback, null);
+
+
+			}
+			catch (Exception ex)
+			{
+                string msg;
+                if (BMXNetLib.Piece(ex.Message, "~", 1) == "-10") // -10 means that BSDXAPI reported an error.
+                    msg = BMXNetLib.Piece(ex.Message, "~", 4);
+                else
+                    msg = ex.Message;
+
+                MessageBox.Show("VISTA says: \r\n" + msg, "Unable to Make Walk-in Appointment");
+                return;
+			}
+
+            try
+            {
+                RaiseRPMSEvent("BSDX SCHEDULE", m_Document.DocName);
+            }
+            catch (Exception ex)
+            {
+                Debug.Write(ex.Message);
+            }
 			
-			}
-			catch (Exception ex)
-			{
-				MessageBox.Show("Unable to add walk-in appointment  " +  ex.Message, "Clinical Scheduling");
-				return;
-
-			}
+
 		}
 
@@ -2133,5 +2156,7 @@
 				Debug.Assert(nDuration > 0);
 
-				this.Document.RefreshDocument();
+
+                //Sam: takes too long. Remove this call; deal with the issue of concurrent appointments another way.
+                //this.Document.RefreshDocument();
 				string sAccessType = "";
 				string sAvailabilityMessage = "";
@@ -2180,15 +2205,26 @@
 				appt.AccessTypeID = nAccessTypeID;
 
-				//Call Document to add a new appointment
+				//Call Document to add a new appointment. Document adds appointment to CGAppointments array.
 				this.Document.CreateAppointment(appt);
-                this.Document.RefreshDocument();
-
+
+                //Show the new set of appointments by calling UpdateArrays. Fetches Document's CGAppointments
+                this.UpdateArrays();
+                
+                //Get the appointments and availabilities, async, from Server. Callback updates this thread's controls.
+                OnUpdateScheduleDelegate ousd = new OnUpdateScheduleDelegate(OnUpdateSchedule);
+                ousd.BeginInvoke(OnUpdateScheduleCallback, null);
 			}
 			catch (Exception ex)
-			{
-				MessageBox.Show("Unable to add new appointment  " +  ex.Message, "Clinical Scheduling");
+			{   
+                string msg;
+                if (BMXNetLib.Piece(ex.Message, "~", 1) == "-10") // -10 means that BSDXAPI reported an error.
+                    msg = BMXNetLib.Piece(ex.Message, "~", 4);
+                else
+                    msg = ex.Message;
+
+				MessageBox.Show("VISTA says: \r\n" + msg, "Unable to Make Appointment");
 				return;
-
-			}
+			}
+
 			try
 			{
@@ -2320,10 +2356,16 @@
 			Debug.Assert(this.InvokeRequired == false,"CGView.UpdateArrays InvokeRequired");
             // This is where you set how the grid will look
+
+            //Create Deep copy of Availability Array
+            ArrayList availArrayCopy = new ArrayList();
+            foreach (CGAvailability av in this.m_Document.AvailabilityArray)
+                availArrayCopy.Add(av);
+
 			try 
 			{
                 //Tell the grid about Avails, Appts, and Resources.
-                this.calendarGrid1.AvailabilityArray = this.m_Document.AvailabilityArray;
+                this.calendarGrid1.AvailabilityArray = availArrayCopy;
                 //Appts are cloned b/c if we tie into  the class directly, we shoot off errors when we manipulate it.
-                this.calendarGrid1.Appointments = (CGAppointments)this.m_Document.Appointments.Clone(); //smh new line again
+                this.calendarGrid1.Appointments = (CGAppointments)this.m_Document.Appointments.Clone();
 				this.calendarGrid1.Resources = this.m_Document.Resources;
                 //Redraw the calendar grid
@@ -3135,5 +3177,9 @@
 
         
-
+        /// <summary>
+        /// Update Selection of date if user does not pick a date/time
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
         private void dateTimePicker1_Leave(object sender, EventArgs e)
         {
@@ -3142,4 +3188,9 @@
         }
 
+        /// <summary>
+        /// Handle Selection of Date via mouse from datetimepicker dropdown
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
         private void dateTimePicker1_CloseUp(object sender, EventArgs e)
         {
@@ -3148,4 +3199,9 @@
         }
 
+        /// <summary>
+        /// Handle Enter and Escape key on dateTimePicker
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
         private void dateTimePicker1_KeyPress(object sender, KeyPressEventArgs e)
         {
