Index: Scheduling/trunk/cs/bsdx0200GUISourceCode/CGDocumentManager.cs
===================================================================
--- Scheduling/trunk/cs/bsdx0200GUISourceCode/CGDocumentManager.cs	(revision 824)
+++ Scheduling/trunk/cs/bsdx0200GUISourceCode/CGDocumentManager.cs	(revision 843)
@@ -34,4 +34,7 @@
         private string                      m_Encoding="";
 
+        //Data Access Layer
+        private DAL                         _dal = null;
+
 		//M Connection member variables
 		private DataSet									m_dsGlobal = null;
@@ -177,4 +180,9 @@
 		}
 
+        public DAL DAL
+        {
+            get { return this._dal; }
+        }
+
 
 		#endregion
@@ -206,11 +214,4 @@
 		private void InitializeComponent()
 		{
-			// 
-			// CGDocumentManager
-			// 
-			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
-			this.ClientSize = new System.Drawing.Size(292, 266);
-			this.Name = "CGDocumentManager";
-
 		}
 
@@ -231,4 +232,5 @@
 		{
             m_ConnectInfo = new BMXNetConnectInfo(m_Encoding); // Encoding is "" unless passed in command line
+            _dal = new DAL(m_ConnectInfo);   // Data access layer
             //m_ConnectInfo.bmxNetLib.StartLog();    //This line turns on logging of messages
             CDocMgrEventDelegate = new BMXNetConnectInfo.BMXNetEventDelegate(CDocMgrEventHandler);
@@ -321,8 +323,10 @@
 				m_ds.SetStatus("Getting Version Info...");
                 m_ds.Refresh();
-                String sCmd = "BMX VERSION INFO^BSDX^";
-                this.m_ConnectInfo.RPMSDataTable(sCmd, "VersionInfo", m_dsGlobal);
-
-				//Keep the following commented code for future use:
+
+                DataTable ver = _dal.GetVersion("BSDX"); //sCmd, "VersionInfo", m_dsGlobal);
+                ver.TableName = "VersionInfo";
+                m_dsGlobal.Tables.Add(ver);
+
+                //Keep the following commented code for future use:
 				//How to extract the version numbers:
                 //DataTable dtVersion = m_dsGlobal.Tables["VersionInfo"];
@@ -435,10 +439,4 @@
 		}
 
-		public void LoadAccessTypesTable()
-		{
-			string sCommandText = "SELECT * FROM BSDX_ACCESS_TYPE";
-			ConnectInfo.RPMSDataTable(sCommandText, "AccessTypes", m_dsGlobal);
-			Debug.Write("LoadGlobalRecordsets -- AccessTypes loaded\n");
-		}
 
 		public void LoadAccessGroupsTable()
@@ -455,12 +453,4 @@
 			Debug.Write("LoadGlobalRecordsets -- AccessGroupTypes loaded\n");
 		}
-
-        //TODO:REMOVE THIS
-		/*public void LoadClinicSetupTable()
-		{
-			string sCommandText = "BSDX CLINIC SETUP";
-			ConnectInfo.RPMSDataTable(sCommandText, "ClinicSetupParameters", m_dsGlobal);
-			Debug.Write("LoadGlobalRecordsets -- ClinicSetupParameters loaded\n");
-		}*/
 
 		public void LoadBSDXResourcesTable()
@@ -521,9 +511,14 @@
 		private bool LoadGlobalRecordsets() 
 		{
-			//Schedule User Info
-			string sCommandText = "BSDX SCHEDULING USER INFO^" + m_ConnectInfo.DUZ;
-			DataTable dtUser = ConnectInfo.RPMSDataTable(sCommandText, "SchedulingUser", m_dsGlobal);
-
+			
+            string sCommandText;
+
+            //Schedule User Info
+			DataTable dtUser = _dal.GetUserInfo(m_ConnectInfo.DUZ);
+            dtUser.TableName = "SchedulingUser";
+            m_dsGlobal.Tables.Add(dtUser);
 			Debug.Assert(dtUser.Rows.Count == 1);
+
+            // Only one row and one column named "MANAGER". Set local var m_bSchedManager to true if Manager.
 			DataRow rUser = dtUser.Rows[0];
 			Object oUser = rUser["MANAGER"];
@@ -531,13 +526,8 @@
 			m_bSchedManager = (sUser == "YES")?true:false;
 
-			//AccessTypes
-			LoadAccessTypesTable();
-
-			//Build Primary Key for AccessTypes table
-			DataTable dtTypes = m_dsGlobal.Tables["AccessTypes"];
-			DataColumn dcKey = dtTypes.Columns["BMXIEN"];
-			DataColumn[] dcKeys = new DataColumn[1];
-			dcKeys[0] = dcKey;
-			dtTypes.PrimaryKey = dcKeys;
+            //Get Access Types
+            DataTable dtAccessTypes = _dal.GetAccessTypes();
+            dtAccessTypes.TableName = "AccessTypes";
+            m_dsGlobal.Tables.Add(dtAccessTypes);
 
 			//AccessGroups
@@ -546,6 +536,6 @@
 			//Build Primary Key for AccessGroup table
 			DataTable dtGroups = m_dsGlobal.Tables["AccessGroup"];
-			dcKey = dtGroups.Columns["ACCESS_GROUP"];
-			dcKeys = new DataColumn[1];
+            DataColumn dcKey = dtGroups.Columns["ACCESS_GROUP"];
+            DataColumn[] dcKeys = new DataColumn[1];
 			dcKeys[0] = dcKey;
 			dtGroups.PrimaryKey = dcKeys;
@@ -1044,13 +1034,16 @@
 			//Retrieves a recordset from RPMS
 			string			sErrorMessage = "";
+            DataTable dtOut;
+
+#if TRACE
+            DateTime sendTime = DateTime.Now;
+#endif
 			try
 			{
 				System.IntPtr pHandle = this.Handle;
-				DataTable dtOut;
 				RPMSDataTableDelegate rdtd = new RPMSDataTableDelegate(ConnectInfo.RPMSDataTable);
-				//dtOut = (DataTable) this.Invoke(rdtd, new object[] {sSQL, sTableName});
-                dtOut = ConnectInfo.RPMSDataTable(sSQL, sTableName);
-				return dtOut;
-			}
+				dtOut = (DataTable) this.Invoke(rdtd, new object[] {sSQL, sTableName});
+			}
+
 			catch (Exception ex)
 			{
@@ -1058,4 +1051,13 @@
 				throw ex;
 			}
+
+#if TRACE
+            DateTime receiveTime = DateTime.Now;
+            TimeSpan executionTime = receiveTime - sendTime;
+            Debug.Write("CGDocumentManager::RPMSDataTable Execution Time: " + executionTime.Milliseconds + " ms.\n");
+#endif
+
+            return dtOut;
+
 		}
 
