Index: /Scheduling/trunk/cs/bsdx0200GUISourceCode/AssemblyInfo.cs
===================================================================
--- /Scheduling/trunk/cs/bsdx0200GUISourceCode/AssemblyInfo.cs	(revision 1010)
+++ /Scheduling/trunk/cs/bsdx0200GUISourceCode/AssemblyInfo.cs	(revision 1011)
@@ -28,5 +28,5 @@
 // by using the '*' as shown below:
 
-[assembly: AssemblyVersion("1.4.1.*")]
+[assembly: AssemblyVersion("1.4.2.*")]
 
 //
@@ -58,4 +58,4 @@
 [assembly: AssemblyKeyFile("")]
 [assembly: AssemblyKeyName("")]
-[assembly: AssemblyFileVersionAttribute("1.4.1.0")]
+[assembly: AssemblyFileVersionAttribute("1.4.2.0")]
 [assembly: ComVisibleAttribute(false)]
Index: /Scheduling/trunk/cs/bsdx0200GUISourceCode/CGAVView.cs
===================================================================
--- /Scheduling/trunk/cs/bsdx0200GUISourceCode/CGAVView.cs	(revision 1010)
+++ /Scheduling/trunk/cs/bsdx0200GUISourceCode/CGAVView.cs	(revision 1011)
@@ -68,4 +68,5 @@
             this.mnuLoadTemplate = new System.Windows.Forms.MenuItem();
             this.mnuSaveTemplate = new System.Windows.Forms.MenuItem();
+            this.mnuDeleteAllAppointments = new System.Windows.Forms.MenuItem();
             this.menuItem6 = new System.Windows.Forms.MenuItem();
             this.mnuSchedulingManagment = new System.Windows.Forms.MenuItem();
@@ -90,4 +91,5 @@
             this.mnuHelpAbout = new System.Windows.Forms.MenuItem();
             this.splitter1 = new System.Windows.Forms.Splitter();
+            this.saveAccessBlocksWorker = new System.ComponentModel.BackgroundWorker();
             this.calendarGrid1 = new IndianHealthService.ClinicalScheduling.CalendarGrid();
             this.panelRight.SuspendLayout();
@@ -104,5 +106,5 @@
             this.panelRight.Location = new System.Drawing.Point(728, 0);
             this.panelRight.Name = "panelRight";
-            this.panelRight.Size = new System.Drawing.Size(120, 412);
+            this.panelRight.Size = new System.Drawing.Size(120, 393);
             this.panelRight.TabIndex = 1;
             // 
@@ -125,10 +127,10 @@
             this.lstClip.Location = new System.Drawing.Point(0, 32);
             this.lstClip.Name = "lstClip";
-            this.lstClip.Size = new System.Drawing.Size(120, 407);
+            this.lstClip.Size = new System.Drawing.Size(120, 416);
             this.lstClip.TabIndex = 0;
             this.lstClip.DragDrop += new System.Windows.Forms.DragEventHandler(this.lstClip_DragDrop);
+            this.lstClip.DragEnter += new System.Windows.Forms.DragEventHandler(this.lstClip_DragEnter);
+            this.lstClip.MouseDown += new System.Windows.Forms.MouseEventHandler(this.lstClip_MouseDown);
             this.lstClip.MouseMove += new System.Windows.Forms.MouseEventHandler(this.lstClip_MouseMove);
-            this.lstClip.MouseDown += new System.Windows.Forms.MouseEventHandler(this.lstClip_MouseDown);
-            this.lstClip.DragEnter += new System.Windows.Forms.DragEventHandler(this.lstClip_DragEnter);
             // 
             // ctxApptClipMenu
@@ -165,5 +167,5 @@
             this.panelBottom.Controls.Add(this.statusBar1);
             this.panelBottom.Dock = System.Windows.Forms.DockStyle.Bottom;
-            this.panelBottom.Location = new System.Drawing.Point(8, 388);
+            this.panelBottom.Location = new System.Drawing.Point(8, 369);
             this.panelBottom.Name = "panelBottom";
             this.panelBottom.Size = new System.Drawing.Size(720, 24);
@@ -217,5 +219,5 @@
             this.panelCenter.Location = new System.Drawing.Point(8, 24);
             this.panelCenter.Name = "panelCenter";
-            this.panelCenter.Size = new System.Drawing.Size(712, 364);
+            this.panelCenter.Size = new System.Drawing.Size(712, 345);
             this.panelCenter.TabIndex = 4;
             // 
@@ -253,5 +255,5 @@
             this.tvSchedules.Location = new System.Drawing.Point(0, 0);
             this.tvSchedules.Name = "tvSchedules";
-            this.tvSchedules.Size = new System.Drawing.Size(8, 412);
+            this.tvSchedules.Size = new System.Drawing.Size(8, 393);
             this.tvSchedules.Sorted = true;
             this.tvSchedules.TabIndex = 5;
@@ -271,4 +273,5 @@
             this.mnuLoadTemplate,
             this.mnuSaveTemplate,
+            this.mnuDeleteAllAppointments,
             this.menuItem6,
             this.mnuSchedulingManagment,
@@ -291,12 +294,20 @@
             this.mnuSaveTemplate.Click += new System.EventHandler(this.mnuSaveTemplate_Click);
             // 
+            // mnuDeleteAllAppointments
+            // 
+            this.mnuDeleteAllAppointments.Enabled = false;
+            this.mnuDeleteAllAppointments.Index = 2;
+            this.mnuDeleteAllAppointments.Shortcut = System.Windows.Forms.Shortcut.CtrlD;
+            this.mnuDeleteAllAppointments.Text = "&Delete All Appointments";
+            this.mnuDeleteAllAppointments.Click += new System.EventHandler(this.mnuDeleteAllAppointments_Click);
+            // 
             // menuItem6
             // 
-            this.menuItem6.Index = 2;
+            this.menuItem6.Index = 3;
             this.menuItem6.Text = "-";
             // 
             // mnuSchedulingManagment
             // 
-            this.mnuSchedulingManagment.Index = 3;
+            this.mnuSchedulingManagment.Index = 4;
             this.mnuSchedulingManagment.Shortcut = System.Windows.Forms.Shortcut.CtrlShiftM;
             this.mnuSchedulingManagment.Text = "Scheduling &Management";
@@ -305,10 +316,10 @@
             // menuItem5
             // 
-            this.menuItem5.Index = 4;
+            this.menuItem5.Index = 5;
             this.menuItem5.Text = "-";
             // 
             // mnuClose
             // 
-            this.mnuClose.Index = 5;
+            this.mnuClose.Index = 6;
             this.mnuClose.Shortcut = System.Windows.Forms.Shortcut.CtrlW;
             this.mnuClose.Text = "&Close";
@@ -446,7 +457,14 @@
             this.splitter1.Location = new System.Drawing.Point(720, 24);
             this.splitter1.Name = "splitter1";
-            this.splitter1.Size = new System.Drawing.Size(8, 364);
+            this.splitter1.Size = new System.Drawing.Size(8, 345);
             this.splitter1.TabIndex = 6;
             this.splitter1.TabStop = false;
+            // 
+            // saveAccessBlocksWorker
+            // 
+            this.saveAccessBlocksWorker.WorkerReportsProgress = true;
+            this.saveAccessBlocksWorker.DoWork += new System.ComponentModel.DoWorkEventHandler(this.saveAccessBlocksWorker_DoWork);
+            this.saveAccessBlocksWorker.ProgressChanged += new System.ComponentModel.ProgressChangedEventHandler(this.saveAccessBlocksWorker_ProgressChanged);
+            this.saveAccessBlocksWorker.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(this.saveAccessBlocksWorker_RunWorkerCompleted);
             // 
             // calendarGrid1
@@ -469,17 +487,17 @@
             this.calendarGrid1.Resources = ((System.Collections.ArrayList)(resources.GetObject("calendarGrid1.Resources")));
             this.calendarGrid1.SelectedAppointment = 0;
-            this.calendarGrid1.Size = new System.Drawing.Size(712, 364);
+            this.calendarGrid1.Size = new System.Drawing.Size(712, 345);
             this.calendarGrid1.StartDate = new System.DateTime(2003, 1, 27, 0, 0, 0, 0);
             this.calendarGrid1.TabIndex = 2;
             this.calendarGrid1.TimeScale = 20;
+            this.calendarGrid1.CGAppointmentAdded += new IndianHealthService.ClinicalScheduling.CGAppointmentChangedHandler(this.calendarGrid1_CGAppointmentAdded);
+            this.calendarGrid1.CGAppointmentChanged += new IndianHealthService.ClinicalScheduling.CGAppointmentChangedHandler(this.calendarGrid1_CGAppointmentChanged);
+            this.calendarGrid1.CGSelectionChanged += new IndianHealthService.ClinicalScheduling.CGSelectionChangedHandler(this.calendarGrid1_CGSelectionChanged);
             this.calendarGrid1.DoubleClick += new System.EventHandler(this.calendarGrid1_DoubleClick);
-            this.calendarGrid1.CGSelectionChanged += new IndianHealthService.ClinicalScheduling.CGSelectionChangedHandler(this.calendarGrid1_CGSelectionChanged);
-            this.calendarGrid1.CGAppointmentChanged += new IndianHealthService.ClinicalScheduling.CGAppointmentChangedHandler(this.calendarGrid1_CGAppointmentChanged);
-            this.calendarGrid1.CGAppointmentAdded += new IndianHealthService.ClinicalScheduling.CGAppointmentChangedHandler(this.calendarGrid1_CGAppointmentAdded);
             // 
             // CGAVView
             // 
             this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
-            this.ClientSize = new System.Drawing.Size(848, 412);
+            this.ClientSize = new System.Drawing.Size(848, 393);
             this.Controls.Add(this.panelCenter);
             this.Controls.Add(this.splitter1);
@@ -492,6 +510,6 @@
             this.Name = "CGAVView";
             this.Text = "CGAVView";
+            this.Closing += new System.ComponentModel.CancelEventHandler(this.CGAVView_Closing);
             this.Load += new System.EventHandler(this.CGAVView_Load);
-            this.Closing += new System.ComponentModel.CancelEventHandler(this.CGAVView_Closing);
             this.panelRight.ResumeLayout(false);
             this.panelClip.ResumeLayout(false);
@@ -556,4 +574,6 @@
 		private System.Windows.Forms.MenuItem ctxCalGridEdit;
 		private System.Windows.Forms.MenuItem ctxCalGridDelete;
+        private BackgroundWorker saveAccessBlocksWorker;
+        private MenuItem mnuDeleteAllAppointments;
 		private bool				m_bDragDropStart = false;
 
@@ -749,4 +769,32 @@
 		}//End AvailabilityAddNew
 
+        private void MassAppointmentDelete()
+        {
+            DialogResult msgResult = MessageBox.Show("Delete all Access Slots?", "Delete Slots?",MessageBoxButtons.YesNo);
+            if (msgResult != DialogResult.Yes) return;
+
+            CGAppointments appointments = new CGAppointments();
+            appointments = this.Document.AVBlocks;
+
+            foreach (CGAppointment a in appointments.AppointmentTable.Values)
+            {
+                int nApptID = a.AppointmentKey;
+                Debug.Assert(nApptID != 0);
+                try
+                {
+                    Document.DeleteAvailability(nApptID);
+                }
+                catch (Exception ex)
+                {
+                    MessageBox.Show("Unable to delete access block" + ex.Message, "Clinical Scheduling");
+                }
+
+            }
+
+            this.m_DocManager.UpdateViews((string)this.m_Document.Resources[0], "");
+            RaiseRPMSEvent("BSDX SCHEDULE", m_Document.DocName);
+            this.calendarGrid1.Invalidate();
+        }
+
 		private void AppointmentDelete() 
 		{
@@ -756,9 +804,4 @@
 				sMsg = " these access blocks?";
 
-			if (MessageBox.Show("Are you sure you want to delete" + sMsg, "Clinical Scheduling",  MessageBoxButtons.YesNo) != DialogResult.Yes)
-			{
-				calendarGrid1.CGToolTip.Active = true;
-				return;
-			}
 			calendarGrid1.CGToolTip.Active = true;
 
@@ -907,7 +950,4 @@
 			{
 //				this.DocManager.EnableAutoRefresh(false);
-
-				if (MessageBox.Show("Are you sure you want to move this access block?", "Clinical Scheduling",  MessageBoxButtons.YesNo) != DialogResult.Yes)
-					return;
 
 				m_Document.ChangeAppointmentTime(e.Appointment, e.StartTime, e.EndTime, e.Resource);
@@ -1010,69 +1050,71 @@
 			try
 			{
-				OpenFileDialog openFileDialog1 = dlg.FileDialog;
-				Stream streamFile;
-				if((streamFile = openFileDialog1.OpenFile())== null)
-				{
-					MessageBox.Show("Unable to open template file.");
-					return;
-				}
-
-				BinaryFormatter formatter = new BinaryFormatter();
-				CGAppointments cgaTemp = (CGAppointments) formatter.Deserialize(streamFile);
-				streamFile.Close();
-
-				DateTime dtStart = dlg.StartDate;
-                DateTime newStartDate, newEndDate;
-                this.Document.WeekNeedsRefresh(1,dtStart, out newStartDate, out newEndDate);
-                dtStart = newStartDate;
-				int nWeeksToApply = dlg.WeeksToApply;
-				DateTime dtEnd = dtStart.AddDays(6); // or 7?
-
-				string sResourceID = this.m_Document.ResourceID.ToString();
-				DataTable dt;
-
-				for (int j=1; j < nWeeksToApply + 1; j++)
-				{
-					//Convert start and end to string
-					//string sStart = dtStart.ToString("M/d/yyyy");
-					//string sEnd = dtEnd.ToString("M/d/yyyy");
-                    //i18n
-                    string sStart = FMDateTime.Create(dtStart).DateOnly.FMDateString;
-                    string sEnd = FMDateTime.Create(dtEnd).DateOnly.FMDateString;
-					//Cancel all existing access blocks in the date range
-					string sSql = "BSDX CANCEL AV BY DATE^" + sResourceID + "^" + sStart + "^" + sEnd;
-					dt = this.m_DocManager.RPMSDataTable(sSql, "Cancelled");
-
-					//for each CGAppointment in AVBlocks, call AddNew
-					string sResource = "";
-					sResource = (string) this.Document.Resources[0];
-					foreach (CGAppointment a in cgaTemp.AppointmentTable.Values)
-					{
-						//Change the resource to the current one
-						a.Resource = sResource;
-
-						//Change the date to correspond to the GridColumn member
-						int col = a.GridColumn;
-						col--;
-						DateTime dBuildDate = dtStart.Date;
-						dBuildDate = dBuildDate.AddDays(col);
-						dBuildDate = dBuildDate.AddHours(a.StartTime.Hour);
-						dBuildDate = dBuildDate.AddMinutes(a.StartTime.Minute);
-						a.StartTime = dBuildDate;
-						dBuildDate = dtStart.Date;
-						dBuildDate = dBuildDate.AddDays(col);
-						dBuildDate = dBuildDate.AddHours(a.EndTime.Hour);
-						dBuildDate = dBuildDate.AddMinutes(a.EndTime.Minute);
-						a.EndTime = dBuildDate;
-
-						//Call Document to add a new appointment
-						this.Document.CreateAppointmentAuto(a);
-					}
-
-					//Increment start and end
-					dtStart = dtStart.AddDays(7);
-					dtEnd = dtStart.AddDays(6);
-
-				}//end for
+                this.saveAccessBlocksWorker.RunWorkerAsync(dlg);
+                //OpenFileDialog openFileDialog1 = dlg.FileDialog;
+                //openFileDialog1.RestoreDirectory = false; // go back to our dir
+                //Stream streamFile;
+                //if((streamFile = openFileDialog1.OpenFile())== null)
+                //{
+                //    MessageBox.Show("Unable to open template file.");
+                //    return;
+                //}
+
+                //BinaryFormatter formatter = new BinaryFormatter();
+                //CGAppointments cgaTemp = (CGAppointments) formatter.Deserialize(streamFile);
+                //streamFile.Close();
+
+                //DateTime dtStart = dlg.StartDate;
+                //DateTime newStartDate, newEndDate;
+                //this.Document.WeekNeedsRefresh(1,dtStart, out newStartDate, out newEndDate);
+                //dtStart = newStartDate;
+                //int nWeeksToApply = dlg.WeeksToApply;
+                //DateTime dtEnd = dtStart.AddDays(6); // or 7?
+
+                //string sResourceID = this.m_Document.ResourceID.ToString();
+                //DataTable dt;
+
+                //for (int j=1; j < nWeeksToApply + 1; j++)
+                //{
+                //    //Convert start and end to string
+                //    //string sStart = dtStart.ToString("M/d/yyyy");
+                //    //string sEnd = dtEnd.ToString("M/d/yyyy");
+                //    //i18n
+                //    string sStart = FMDateTime.Create(dtStart).DateOnly.FMDateString;
+                //    string sEnd = FMDateTime.Create(dtEnd).DateOnly.FMDateString;
+                //    //Cancel all existing access blocks in the date range
+                //    string sSql = "BSDX CANCEL AV BY DATE^" + sResourceID + "^" + sStart + "^" + sEnd;
+                //    dt = this.m_DocManager.RPMSDataTable(sSql, "Cancelled");
+
+                //    //for each CGAppointment in AVBlocks, call AddNew
+                //    string sResource = "";
+                //    sResource = (string) this.Document.Resources[0];
+                //    foreach (CGAppointment a in cgaTemp.AppointmentTable.Values)
+                //    {
+                //        //Change the resource to the current one
+                //        a.Resource = sResource;
+
+                //        //Change the date to correspond to the GridColumn member
+                //        int col = a.GridColumn;
+                //        col--;
+                //        DateTime dBuildDate = dtStart.Date;
+                //        dBuildDate = dBuildDate.AddDays(col);
+                //        dBuildDate = dBuildDate.AddHours(a.StartTime.Hour);
+                //        dBuildDate = dBuildDate.AddMinutes(a.StartTime.Minute);
+                //        a.StartTime = dBuildDate;
+                //        dBuildDate = dtStart.Date;
+                //        dBuildDate = dBuildDate.AddDays(col);
+                //        dBuildDate = dBuildDate.AddHours(a.EndTime.Hour);
+                //        dBuildDate = dBuildDate.AddMinutes(a.EndTime.Minute);
+                //        a.EndTime = dBuildDate;
+
+                //        //Call Document to add a new appointment
+                //        this.Document.CreateAppointmentAuto(a);
+                //    }
+
+                //    //Increment start and end
+                //    dtStart = dtStart.AddDays(7);
+                //    dtEnd = dtStart.AddDays(6);
+
+				// }//end for
 				try
 				{
@@ -1424,4 +1466,99 @@
 			cg.Invalidate();
 		}
+
+
+
+        private void saveAccessBlocksWorker_DoWork(object sender, DoWorkEventArgs e)
+        {
+            BackgroundWorker worker = (BackgroundWorker)sender;
+            DAccessTemplate dlg = (DAccessTemplate)e.Argument;
+
+            OpenFileDialog openFileDialog1 = dlg.FileDialog;
+            openFileDialog1.RestoreDirectory = false; // go back to our dir
+            Stream streamFile;
+            if ((streamFile = openFileDialog1.OpenFile()) == null)
+            {
+                MessageBox.Show("Unable to open template file.");
+                return;
+            }
+
+            BinaryFormatter formatter = new BinaryFormatter();
+            CGAppointments cgaTemp = (CGAppointments)formatter.Deserialize(streamFile);
+            streamFile.Close();
+
+            DateTime dtStart = dlg.StartDate;
+            DateTime newStartDate, newEndDate;
+            this.Document.WeekNeedsRefresh(1, dtStart, out newStartDate, out newEndDate);
+            dtStart = newStartDate;
+            int nWeeksToApply = dlg.WeeksToApply;
+            DateTime dtEnd = dtStart.AddDays(6); // or 7?
+
+            string sResourceID = this.m_Document.ResourceID.ToString();
+            DataTable dt;
+
+            for (int j = 1; j < nWeeksToApply + 1; j++)
+            {
+                float fProgressPercentage = ((float)j / (float)nWeeksToApply) * 100;
+                int iProgressPercentage = (int)fProgressPercentage;
+                worker.ReportProgress(iProgressPercentage);
+                //Convert start and end to string
+                //string sStart = dtStart.ToString("M/d/yyyy");
+                //string sEnd = dtEnd.ToString("M/d/yyyy");
+                //i18n
+                string sStart = FMDateTime.Create(dtStart).DateOnly.FMDateString;
+                string sEnd = FMDateTime.Create(dtEnd).DateOnly.FMDateString;
+                //Cancel all existing access blocks in the date range
+                string sSql = "BSDX CANCEL AV BY DATE^" + sResourceID + "^" + sStart + "^" + sEnd;
+                CGDocumentManager.RPMSDataTableDelegate d = new CGDocumentManager.RPMSDataTableDelegate(m_DocManager.RPMSDataTable);
+                //dt = this.m_DocManager.RPMSDataTable(sSql, "Cancelled");
+                dt = d(sSql, "Cancelled");
+                //for each CGAppointment in AVBlocks, call AddNew
+                string sResource = "";
+                sResource = (string)this.Document.Resources[0];
+                foreach (CGAppointment a in cgaTemp.AppointmentTable.Values)
+                {
+                    //Change the resource to the current one
+                    a.Resource = sResource;
+
+                    //Change the date to correspond to the GridColumn member
+                    int col = a.GridColumn;
+                    col--;
+                    DateTime dBuildDate = dtStart.Date;
+                    dBuildDate = dBuildDate.AddDays(col);
+                    dBuildDate = dBuildDate.AddHours(a.StartTime.Hour);
+                    dBuildDate = dBuildDate.AddMinutes(a.StartTime.Minute);
+                    a.StartTime = dBuildDate;
+                    dBuildDate = dtStart.Date;
+                    dBuildDate = dBuildDate.AddDays(col);
+                    dBuildDate = dBuildDate.AddHours(a.EndTime.Hour);
+                    dBuildDate = dBuildDate.AddMinutes(a.EndTime.Minute);
+                    a.EndTime = dBuildDate;
+
+                    //Call Document to add a new appointment
+                    this.Document.CreateAppointmentAuto(a);
+                }
+
+                //Increment start and end
+                dtStart = dtStart.AddDays(7);
+                dtEnd = dtStart.AddDays(6);
+
+            }
+
+        }
+
+        private void saveAccessBlocksWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
+        {
+            this.statusBar1.Text = "Done saving access blocks.";
+        }
+
+        private void saveAccessBlocksWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
+        {
+            this.statusBar1.Text = "Saving Data to VISTA. Progress: " + e.ProgressPercentage + " %";
+        }
+
+        private void mnuDeleteAllAppointments_Click(object sender, EventArgs e)
+        {
+            MassAppointmentDelete();
+        }
 	}
 }
Index: /Scheduling/trunk/cs/bsdx0200GUISourceCode/CGAVView.resx
===================================================================
--- /Scheduling/trunk/cs/bsdx0200GUISourceCode/CGAVView.resx	(revision 1010)
+++ /Scheduling/trunk/cs/bsdx0200GUISourceCode/CGAVView.resx	(revision 1011)
@@ -133,4 +133,7 @@
     <value>281, 17</value>
   </metadata>
+  <metadata name="saveAccessBlocksWorker.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+    <value>398, 17</value>
+  </metadata>
   <assembly alias="System.Drawing" name="System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
   <data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
Index: /Scheduling/trunk/cs/bsdx0200GUISourceCode/CGDocumentManager.cs
===================================================================
--- /Scheduling/trunk/cs/bsdx0200GUISourceCode/CGDocumentManager.cs	(revision 1010)
+++ /Scheduling/trunk/cs/bsdx0200GUISourceCode/CGDocumentManager.cs	(revision 1011)
@@ -1035,5 +1035,5 @@
 		}
 
-		delegate DataTable RPMSDataTableDelegate(string CommandString, string TableName);
+		public delegate DataTable RPMSDataTableDelegate(string CommandString, string TableName);
 
 		public DataTable RPMSDataTable(string sSQL, string sTableName)
@@ -1048,5 +1048,5 @@
 			try
 			{
-				System.IntPtr pHandle = this.Handle;
+				//System.IntPtr pHandle = this.Handle;
 				RPMSDataTableDelegate rdtd = new RPMSDataTableDelegate(ConnectInfo.RPMSDataTable);
 				dtOut = (DataTable) this.Invoke(rdtd, new object[] {sSQL, sTableName});
Index: /Scheduling/trunk/cs/bsdx0200GUISourceCode/CGSchedLib.cs
===================================================================
--- /Scheduling/trunk/cs/bsdx0200GUISourceCode/CGSchedLib.cs	(revision 1010)
+++ /Scheduling/trunk/cs/bsdx0200GUISourceCode/CGSchedLib.cs	(revision 1011)
@@ -95,15 +95,18 @@
 			
 			string sResName;
+            // for each resource
 			for (int i = 0; i < nSize; i++) 
 			{
 				sResName = saryResourceNames[i].ToString();
-
+                //Gets all the slots (or Availabities, if you like)
 				rsSlotSchedule = CGSchedLib.CreateAssignedSlotSchedule(docManager, sResName, StartTime, EndTime, saryApptTypes,/**/ stType, sSearchInfo);
 				OutputArray(rsSlotSchedule, "rsSlotSchedule");
-
+                //if we have slots
 				if (rsSlotSchedule.Rows.Count > 0 ) 
 				{
+                    // Get appointment count to substract from the slots
 					rsApptSchedule = CGSchedLib.CreateAppointmentSlotSchedule(docManager, sResName, StartTime, EndTime, stType);
 					OutputArray(rsApptSchedule, "rsApptSchedule");
+                    // Perform the substraction
 					rsTemp1 = CGSchedLib.SubtractSlotsRS2(rsSlotSchedule, rsApptSchedule, sResName);
 					OutputArray(rsTemp1, "rsTemp1");
@@ -114,4 +117,5 @@
 					OutputArray(rsTemp1, "rsTemp1");
 				}
+                // if only one resource was passed in, its availablility is what we want
 				if (i == 0) 
 				{
@@ -586,4 +590,11 @@
 		}
 
+        /// <summary>
+        /// My guess is that this calculates remaining slots
+        /// </summary>
+        /// <param name="rsBlocks1"></param>
+        /// <param name="rsBlocks2"></param>
+        /// <param name="sResource"></param>
+        /// <returns></returns>
 		public static DataTable SubtractSlotsRS2(DataTable rsBlocks1, DataTable rsBlocks2, string sResource)
 		{
@@ -770,5 +781,9 @@
 		}//end IntersectBlocks
 
-
+        /// <summary>
+        /// Number of minutes since Jan 1 1980
+        /// </summary>
+        /// <param name="d">Date to compare</param>
+        /// <returns>Minutes as integer</returns>
 		public static int MinSince80(DateTime d)
 		{
@@ -878,4 +893,5 @@
 			rect1.Height = CGSchedLib.MinSince80(dEnd1) - rect1.Y;
 
+            //for each row in the availability schedule
 			foreach (DataRow r in rsBlock.Rows) 
 			{
Index: /Scheduling/trunk/cs/bsdx0200GUISourceCode/CalendarGrid.cs
===================================================================
--- /Scheduling/trunk/cs/bsdx0200GUISourceCode/CalendarGrid.cs	(revision 1010)
+++ /Scheduling/trunk/cs/bsdx0200GUISourceCode/CalendarGrid.cs	(revision 1011)
@@ -677,4 +677,6 @@
             else
             {
+                //columnToPutAppt = (startTime - this.m_dtStart).Days + 1;
+                //test sam
                 columnToPutAppt = (startTime - this.m_dtStart).Days + 1;
             }
Index: /Scheduling/trunk/cs/bsdx0200GUISourceCode/ClinicalScheduling.csproj.user
===================================================================
--- /Scheduling/trunk/cs/bsdx0200GUISourceCode/ClinicalScheduling.csproj.user	(revision 1010)
+++ /Scheduling/trunk/cs/bsdx0200GUISourceCode/ClinicalScheduling.csproj.user	(revision 1011)
@@ -37,5 +37,5 @@
     </RemoteDebugMachine>
     <StartAction>Project</StartAction>
-    <StartArguments>/s=172.16.17.51 /p=9260 /a=shabiel12 /v=abc,123!</StartArguments>
+    <StartArguments>/s=192.168.56.101 /p=9260 /a=shabiel12 /v=catdog.66</StartArguments>
     <StartPage>
     </StartPage>
Index: /Scheduling/trunk/cs/bsdx0200GUISourceCode/DAccessTemplate.cs
===================================================================
--- /Scheduling/trunk/cs/bsdx0200GUISourceCode/DAccessTemplate.cs	(revision 1010)
+++ /Scheduling/trunk/cs/bsdx0200GUISourceCode/DAccessTemplate.cs	(revision 1011)
@@ -36,5 +36,5 @@
 
 			UpdateDialogData(true);
-
+            //this.cmdSelectTemplate.Focus(); // Focus on first button on form
 		}
 
@@ -113,9 +113,4 @@
 			m_bSelectedFile = false;
 			OpenFileDialog openFileDialog1 = new OpenFileDialog();
-			string sPath = "";
-			sPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
-
-			openFileDialog1.InitialDirectory = @"c:\" ;
-			openFileDialog1.InitialDirectory = sPath ;
 			openFileDialog1.Filter = "Schedule Template Files (*.bsdxa)|*.bsdxa|All files (*.*)|*.*" ;
 			openFileDialog1.FilterIndex = 0 ;
@@ -185,5 +180,5 @@
             this.cmdCancel.Name = "cmdCancel";
             this.cmdCancel.Size = new System.Drawing.Size(56, 24);
-            this.cmdCancel.TabIndex = 2;
+            this.cmdCancel.TabIndex = 5;
             this.cmdCancel.Text = "Cancel";
             // 
@@ -194,5 +189,5 @@
             this.cmdOK.Name = "cmdOK";
             this.cmdOK.Size = new System.Drawing.Size(64, 24);
-            this.cmdOK.TabIndex = 1;
+            this.cmdOK.TabIndex = 4;
             this.cmdOK.Text = "OK";
             this.cmdOK.Click += new System.EventHandler(this.cmdOK_Click);
@@ -234,5 +229,5 @@
             this.cmdSelectTemplate.Name = "cmdSelectTemplate";
             this.cmdSelectTemplate.Size = new System.Drawing.Size(136, 32);
-            this.cmdSelectTemplate.TabIndex = 9;
+            this.cmdSelectTemplate.TabIndex = 1;
             this.cmdSelectTemplate.Text = "Select Access Template";
             this.cmdSelectTemplate.Click += new System.EventHandler(this.cmdSelectTemplate_Click);
@@ -254,5 +249,5 @@
             this.dtpStartDate.Name = "dtpStartDate";
             this.dtpStartDate.Size = new System.Drawing.Size(184, 20);
-            this.dtpStartDate.TabIndex = 11;
+            this.dtpStartDate.TabIndex = 2;
             // 
             // udWeeksToApply
@@ -271,5 +266,5 @@
             this.udWeeksToApply.Name = "udWeeksToApply";
             this.udWeeksToApply.Size = new System.Drawing.Size(96, 20);
-            this.udWeeksToApply.TabIndex = 12;
+            this.udWeeksToApply.TabIndex = 3;
             this.udWeeksToApply.Value = new decimal(new int[] {
             1,
Index: /Scheduling/trunk/cs/bsdx0200GUISourceCode/UCPatientAppts.cs
===================================================================
--- /Scheduling/trunk/cs/bsdx0200GUISourceCode/UCPatientAppts.cs	(revision 1010)
+++ /Scheduling/trunk/cs/bsdx0200GUISourceCode/UCPatientAppts.cs	(revision 1011)
@@ -119,4 +119,11 @@
         private void btnPrint_Click(object sender, EventArgs e)
         {
+            //Fixes bug reported by EHS. Don't print if there are no appointments as this causes null ref
+            if (dtAppt.Rows.Count == 0)
+            {
+                MessageBox.Show("No Appointments to Print", "Nothing to Print");
+                return;
+            }
+
             rowToPrint = 0; //reset row to print
             DialogResult res = printDialog1.ShowDialog();
@@ -124,4 +131,7 @@
         }
 
+        /// <summary>
+        /// Sets default page orientation to landscape.
+        /// </summary>
         private void PrintPtAppts_QueryPageSettings(object sender, System.Drawing.Printing.QueryPageSettingsEventArgs e)
         {
