Index: /Scheduling/branches/BMX4Support/AssemblyInfo.cs
===================================================================
--- /Scheduling/branches/BMX4Support/AssemblyInfo.cs	(revision 1193)
+++ /Scheduling/branches/BMX4Support/AssemblyInfo.cs	(revision 1194)
@@ -28,5 +28,5 @@
 // by using the '*' as shown below:
 
-[assembly: AssemblyVersion("1.5.1.*")]
+[assembly: AssemblyVersion("1.6.0.*")]
 
 //
@@ -58,4 +58,4 @@
 [assembly: AssemblyKeyFile("")]
 [assembly: AssemblyKeyName("")]
-[assembly: AssemblyFileVersionAttribute("1.5.1.0")]
+[assembly: AssemblyFileVersionAttribute("1.6.0.0")]
 [assembly: ComVisibleAttribute(false)]
Index: /Scheduling/branches/BMX4Support/CGAVView.cs
===================================================================
--- /Scheduling/branches/BMX4Support/CGAVView.cs	(revision 1193)
+++ /Scheduling/branches/BMX4Support/CGAVView.cs	(revision 1194)
@@ -654,5 +654,5 @@
 //				sSql = "BSDX RAISE EVENT^" + sEvent + "^" + sParams + "^^";
 //				DataTable dtAppt =m_DocManager.RPMSDataTable(sSql, "RaiseEvent");
-				this.m_DocManager.ConnectInfo.RaiseEvent(sEvent, sParams, true);
+				CGDocumentManager.Current.RemoteSession.EventServices.TriggerEvent(sEvent, sParams, true);
 			}
 			catch (Exception ex)
@@ -809,5 +809,5 @@
 		{
 			calendarGrid1.CGToolTip.Active = false;
-			string sMsg = " this access block?";
+			string sMsg;
 			if (calendarGrid1.SelectedAppointments.AppointmentTable.Count > 1)
 				sMsg = " these access blocks?";
@@ -859,5 +859,5 @@
 			try
 			{
-				bool bLock = DocManager.ConnectInfo.bmxNetLib.Lock("^BSDXMGR", "+");
+				bool bLock = CGDocumentManager.Current.RemoteSession.Lock("^BSDXMGR", "+");
 				if (bLock == false)
 				{
@@ -872,5 +872,5 @@
 					return;
 				}
-				bLock = DocManager.ConnectInfo.bmxNetLib.Lock("^BSDXMGR", "-");
+                bLock = CGDocumentManager.Current.RemoteSession.Lock("^BSDXMGR", "-");
 			}
 			catch (Exception ex)
@@ -947,5 +947,5 @@
 		{
 			this.calendarGrid1.CloseGrid();
-			DocManager.ConnectInfo.bmxNetLib.Lock("^BSDXRES(" + Document.ResourceID.ToString() + ")", "-");
+            CGDocumentManager.Current.RemoteSession.Lock("^BSDXRES(" + Document.ResourceID.ToString() + ")", "-");
 		}
 
Index: /Scheduling/branches/BMX4Support/CGDocumentManager.cs
===================================================================
--- /Scheduling/branches/BMX4Support/CGDocumentManager.cs	(revision 1193)
+++ /Scheduling/branches/BMX4Support/CGDocumentManager.cs	(revision 1194)
@@ -1,2 +1,8 @@
+/* Main Class...:
+ * Original Author: Horace Whitt
+ * Current Author and Maintainer: Sam Habiel
+ * License: LGPL. http://www.gnu.org/licenses/lgpl-2.1.html
+*/
+
 using System;
 using System.Windows.Forms;
@@ -6,4 +12,6 @@
 using System.Threading;
 using IndianHealthService.BMXNet;
+using IndianHealthService.BMXNet.WinForm;
+using IndianHealthService.BMXNet.WinForm.Configuration; //grrrr... too many namespaces here...
 using Mono.Options;
 using System.Runtime.InteropServices;
@@ -42,6 +50,4 @@
 		//M Connection member variables
 		private DataSet									m_dsGlobal = null;      // Holds all user data
-		private BMXNetConnectInfo						m_ConnectInfo = null;   // Connection to VISTA object
-        private BMXNetConnectInfo.BMXNetEventDelegate CDocMgrEventDelegate;     // Delegate to respond to messages from VISTA. Responds to event: BMXNetConnectInfo.BMXNetEvent
 
         //Custom Printing
@@ -51,14 +57,7 @@
         #region Properties
 
-        /// <summary>
-        /// Returns the document manager's BMXNetConnectInfo member
-        /// </summary>
-        public BMXNetConnectInfo ConnectInfo
-        {
-            get
-            {
-                return m_ConnectInfo;
-            }
-        }
+        public WinFramework WinFramework { get; private set; }  // Login Manager
+        public RemoteSession RemoteSession { get; private set; } // Data Sesssion against the RPMS/VISTA server
+        public RPCLogger RPCLogger { get; private set; }         // Logger for RPCs
 
         /// <summary>
@@ -153,7 +152,7 @@
 
         /// <summary>
-        /// Constructor. Does absolutely nothing at this point.
+        /// Private constructor for singleton instance.
         /// </summary>
-		public CGDocumentManager()
+		private CGDocumentManager()
 		{
         }
@@ -295,28 +294,26 @@
 
         #region BMXNet Event Handler
-        private void CDocMgrEventHandler(Object obj, BMXNet.BMXNetEventArgs e)
-		{
-			if (e.BMXEvent == "BSDX CALL WORKSTATIONS")
+        private void CDocMgrEventHandler(Object obj, RemoteEventArgs e)
+		{
+			if (e.EventType == "BSDX CALL WORKSTATIONS")
 			{
 				string sParam = "";
 				string sDelim="~";
-				sParam += this.m_ConnectInfo.UserName + sDelim;
+				sParam += this.RemoteSession.User.Name + sDelim;
 				sParam += this.m_sHandle + sDelim;
 				sParam += Application.ProductVersion + sDelim;
 				sParam += this._views.Count.ToString();
-				_current.m_ConnectInfo.RaiseEvent("BSDX WORKSTATION REPORT", sParam, true);
-			}
-			if (e.BMXEvent == "BSDX ADMIN MESSAGE")
-			{
-				string sMsg = e.BMXParam;
+				_current.RemoteSession.EventServices.TriggerEvent("BSDX WORKSTATION REPORT", sParam, true);
+			}
+			if (e.EventType == "BSDX ADMIN MESSAGE")
+			{
+				string sMsg = e.EventType;
 				ShowAdminMsgDelegate samd = new ShowAdminMsgDelegate(ShowAdminMsg);
-				//this.Invoke(samd, new object [] {sMsg});
                 samd.Invoke(sMsg);
 			}
-			if (e.BMXEvent == "BSDX ADMIN SHUTDOWN")
-			{
-				string sMsg = e.BMXParam;
+			if (e.EventType == "BSDX ADMIN SHUTDOWN")
+			{
+				string sMsg = e.Details;
 				CloseAllDelegate cad = new CloseAllDelegate(CloseAll);
-				//this.Invoke(cad, new object [] {sMsg});
                 cad.Invoke(sMsg);
 			}
@@ -353,22 +350,109 @@
         private bool InitializeApp(bool bReLogin)
 		{
-            //Set M connection info
-            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
+            //Note: There are 2 splashes -- one for being the parent of the log in forms
+            // the next is invoked async and updated async while the GUI is loading
+            // The reason is b/c an async form cannot be the parent of another that lies on the main thread
+
+            RPCLogger = new RPCLogger();
+
+            DSplash firstSplash = new DSplash();
+
+            firstSplash.Show();
             
-            //Create a delegate to process events raised by BMX.
-            CDocMgrEventDelegate = new BMXNetConnectInfo.BMXNetEventDelegate(CDocMgrEventHandler);
+            /* IMPORTANT NOTE
+             * LOGIN CODE IS COPIED ALMOST VERBATIM FROM THE SCHEMABUILDER APPLICAITON;
+             * THE ONLY ONE I CAN FIND WHICH RELIES ON BMX 4 NEW WAYS WHICH I CAN'T FIGURE OUT
+             */
+            LoginProcess login;
+            this.WinFramework = WinFramework.CreateWithNetworkBroker(true, RPCLogger);
+            
+            if (bReLogin) // if logging in again...
+            {
+                this.WinFramework.LoadConnectionSpecs(LocalPersistentStore.CreateDefaultStorage(true), "BSDX");
+                login = this.WinFramework.CreateLoginProcess();
+                login.AttemptUserInputLogin("Clincal Scheduling Log-in", 3, true, firstSplash);
+                goto DoneTrying;
+            }
+
+            // If server,port,ac,vc are supplied on command line, then try to connect...
+            else if (!String.IsNullOrEmpty(m_Server) && m_Port != 0 && !String.IsNullOrEmpty(m_AccessCode) && !String.IsNullOrEmpty(m_VerifyCode))
+            {
+                RpmsConnectionSpec spec = new RpmsConnectionSpec();
+                spec.IsDefault = true;
+                spec.Name = "Command Line Server";
+                spec.Port = m_Port;
+                spec.Server = m_Server;
+                spec.UseWindowsAuthentication = false; //for now
+                spec.UseDefaultNamespace = true; //for now
+                login = this.WinFramework.CreateLoginProcess();
+                login.AutoSetDivisionToLastLookup = false;
+                login.AttemptAccessVerifyLogin(spec, m_AccessCode, m_VerifyCode);
+                goto DoneTrying;
+            }
+            
+            // if only server, port is supplied, then use these instead
+            else if (!String.IsNullOrEmpty(m_Server) && m_Port != 0)
+            {
+                RpmsConnectionSpec spec = new RpmsConnectionSpec();
+                spec.IsDefault = true;
+                spec.Name = "Command Line Server";
+                spec.Port = m_Port;
+                spec.Server = m_Server;
+                spec.UseWindowsAuthentication = false; //for now
+                spec.UseDefaultNamespace = true; //for now
+
+                RpmsConnectionSettings cxnSettings = new RpmsConnectionSettings
+                {
+                    CommandLineConnectionSpec = spec
+                };
+
+                this.WinFramework.ConnectionSettings = cxnSettings;
+
+                login = this.WinFramework.CreateLoginProcess();
+                login.AutoSetDivisionToLastLookup = false;
+                login.AttemptUserInputLogin("Clinical Scheduling Log-in", 3, false, firstSplash);
+                goto DoneTrying;
+            }
+
+            // if nothing is supplied, fall back on the original dialog
+            else
+            {
+                this.WinFramework.LoadConnectionSpecs(LocalPersistentStore.CreateDefaultStorage(true), "BSDX");
+                login = this.WinFramework.CreateLoginProcess();
+                login.AutoSetDivisionToLastLookup = false;
+                login.AttemptUserInputLogin("Clincal Scheduling Log-in", 3, true, firstSplash);
+
+                goto DoneTrying;
+            }
+
+DoneTrying:
+            if (!login.WasSuccessful)
+            {
+                return false;
+            }
+
+            LocalSession local = this.WinFramework.LocalSession;
+
+            if ((this.WinFramework.Context.User.Division == null) && !this.WinFramework.AttemptUserInputSetDivision("Set Initial Division", firstSplash))
+            {
+                return false;
+            }
+
+            
+
+            this.RemoteSession = this.WinFramework.PrimaryRemoteSession;
+
             //Tie delegate to Events generated by BMX.
-            m_ConnectInfo.BMXNetEvent += CDocMgrEventDelegate;
-            //Disable polling (But does this really work???? I don't see how it gets disabled)
-            m_ConnectInfo.EventPollingEnabled = false;
-
+            this.RemoteSession.EventServices.RpmsEvent += this.CDocMgrEventHandler;
+            //Disable polling
+            this.RemoteSession.EventServices.IsEventPollingEnabled = false;
+
+            //Second splash screens
             //Show a splash screen while initializing; define delegates to remote thread
-            DSplash m_ds = new DSplash();
-            DSplash.dSetStatus setStatusDelegate = new DSplash.dSetStatus(m_ds.SetStatus);
-            DSplash.dAny closeSplashDelegate = new DSplash.dAny(m_ds.RemoteClose);
-            DSplash.dProgressBarSet setMaxProgressDelegate = new DSplash.dProgressBarSet(m_ds.RemoteProgressBarMaxSet);
-            DSplash.dProgressBarSet setProgressDelegate = new DSplash.dProgressBarSet(m_ds.RemoteProgressBarValueSet);
+            DSplash secondSplash = new DSplash();
+            DSplash.dSetStatus setStatusDelegate = new DSplash.dSetStatus(secondSplash.SetStatus);
+            DSplash.dAny closeSplashDelegate = new DSplash.dAny(secondSplash.RemoteClose);
+            DSplash.dProgressBarSet setMaxProgressDelegate = new DSplash.dProgressBarSet(secondSplash.RemoteProgressBarMaxSet);
+            DSplash.dProgressBarSet setProgressDelegate = new DSplash.dProgressBarSet(secondSplash.RemoteProgressBarValueSet);
 
             //Start new thread for the Splash screen.
@@ -376,13 +460,16 @@
             threadSplash.IsBackground = true; //expendable thread -- exit even if still running.
             threadSplash.Name = "Splash Thread";
-            threadSplash.Start(m_ds); // pass form as parameter.
+            threadSplash.Start(secondSplash);
+
+            firstSplash.Close(); // close temporary splash now that the new one is up and running
 
             //There are 21 steps to load the application. That's max for the progress bar.
             setMaxProgressDelegate(21);
+
+            // smh--not used: System.Configuration.ConfigurationManager.GetSection("appSettings");
+            setStatusDelegate("Connecting to VISTA");
+
             
-            // smh--not used: System.Configuration.ConfigurationManager.GetSection("appSettings");
-            
-            setStatusDelegate("Connecting to VISTA");
-            
+            /*
             //Try to connect using supplied values for Server and Port
             //Why am I doing this? The library BMX net uses prompts for access and verify code
@@ -462,7 +549,8 @@
                 }
 			}while (bRetry == true);
-            
-            //Printing
-
+            */
+
+            //Printing Custom DLL. Perfect place for code injection!!!
+            //*************************************************
             string DllLocation = string.Empty;
             System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(Application.StartupPath + @"\Printing\");
@@ -495,5 +583,5 @@
                 this.m_PrintingObject = Creator.PrintFactory();
             }
-           
+           //************************************************
             
             //User Interface Culture (m_CultureName is set from the command line flag /culture)
@@ -512,4 +600,6 @@
             }
 
+            _dal = new DAL(RemoteSession);   // Data access layer
+            
             //Create global dataset
 			_current.m_dsGlobal = new DataSet("GlobalDataSet");
@@ -553,10 +643,12 @@
             setProgressDelegate(2);
             setStatusDelegate("Setting encoding...");
-
+            //PORT TODO: Set encoding
             if (m_Encoding == String.Empty)
             {
-                string utf8_server_support = m_ConnectInfo.bmxNetLib.TransmitRPC("BMX UTF-8", "");
+                string utf8_server_support = RemoteSession.TransmitRPC("BMX UTF-8", "");
+                
                 if (utf8_server_support == "1")
-                    m_ConnectInfo.bmxNetLib.Encoder = System.Text.UTF8Encoding.UTF8;
+                    RemoteSession.ConnectionEncoding = System.Text.UTF8Encoding.UTF8;
+                
             }
 			
@@ -565,5 +657,5 @@
             setProgressDelegate(3);
 			setStatusDelegate("Setting Application Context to BSDXRPC...");
-			m_ConnectInfo.AppContext = "BSDXRPC";
+			RemoteSession.AppContext = "BSDXRPC";
 
             //User Preferences Object
@@ -571,5 +663,5 @@
             setStatusDelegate("Getting User Preferences from the Server...");
 
-            _current.UserPreferences = new UserPreferences(); // Does the calling to do that...
+            _current.UserPreferences = new UserPreferences(); // Constructor Does the calling to do that...
             
             //Load global recordsets
@@ -583,5 +675,5 @@
             setProgressDelegate(6);
             setStatusDelegate(statusConst + " Schedule User");
-            DataTable dtUser = _dal.GetUserInfo(m_ConnectInfo.DUZ);
+            DataTable dtUser = _dal.GetUserInfo(RemoteSession.User.Duz);
             dtUser.TableName = "SchedulingUser";
             m_dsGlobal.Tables.Add(dtUser);
@@ -598,7 +690,5 @@
             setProgressDelegate(7);
             setStatusDelegate(statusConst + " Access Types");
-            DataTable dtAccessTypes = _dal.GetAccessTypes();
-            dtAccessTypes.TableName = "AccessTypes";
-            m_dsGlobal.Tables.Add(dtAccessTypes);
+            DataTable dtAccessTypes = _dal.GetAccessTypes(m_dsGlobal, "AccessTypes");
 
             //Get Access Groups
@@ -680,5 +770,5 @@
             //cmd.CommandText = "SELECT BMXIEN 'HOSPITAL_LOCATION_ID', NAME 'HOSPITAL_LOCATION', DEFAULT_PROVIDER, STOP_CODE_NUMBER, INACTIVATE_DATE, REACTIVATE_DATE FROM HOSPITAL_LOCATION";
             sCommandText = "BSDX HOSPITAL LOCATION";
-            ConnectInfo.RPMSDataTable(sCommandText, "HospitalLocation", m_dsGlobal);
+            RemoteSession.TableFromCommand(sCommandText, m_dsGlobal, "HospitalLocation");
             Debug.Write("LoadGlobalRecordsets -- HospitalLocation loaded\n");
 
@@ -732,5 +822,5 @@
             setStatusDelegate(statusConst + " Providers");
             sCommandText = "SELECT BMXIEN, NAME FROM NEW_PERSON WHERE INACTIVE_DATE = '' AND BMXIEN > 1";
-            ConnectInfo.RPMSDataTable(sCommandText, "Provider", m_dsGlobal);
+            RemoteSession.TableFromSQL(sCommandText, m_dsGlobal, "Provider");
             Debug.Write("LoadGlobalRecordsets -- Provider loaded\n");
 
@@ -740,5 +830,5 @@
             setStatusDelegate(statusConst + " Holiday");
             sCommandText = "SELECT NAME, DATE FROM HOLIDAY WHERE INTERNAL[DATE] > '" + FMDateTime.Create(DateTime.Today).DateOnly.FMDateString + "'";
-            ConnectInfo.RPMSDataTable(sCommandText, "HOLIDAY", m_dsGlobal);
+            RemoteSession.TableFromSQL(sCommandText, m_dsGlobal, "HOLIDAY");
             Debug.Write("LoadingGlobalRecordsets -- Holidays loaded\n");
 
@@ -749,8 +839,8 @@
 
             setStatusDelegate("Setting Receive Timeout");
-            _current.m_ConnectInfo.ReceiveTimeout = 30000; //30-second timeout
+            _current.RemoteSession.ReceiveTimeout = 30000; //30-second timeout
 
 #if DEBUG
-            _current.m_ConnectInfo.ReceiveTimeout = 600000; //longer timeout for debugging
+            _current.RemoteSession.ReceiveTimeout = 600000; //longer timeout for debugging
 #endif 
 			// Event Subsriptions
@@ -758,18 +848,20 @@
             //Table #16
             setProgressDelegate(18);
-            _current.m_ConnectInfo.SubscribeEvent("BSDX SCHEDULE");
+            _current.RemoteSession.EventServices.Subscribe("BSDX SCHEDULE");
 			//Table #17
             setProgressDelegate(19);
-            _current.m_ConnectInfo.SubscribeEvent("BSDX CALL WORKSTATIONS");
+            _current.RemoteSession.EventServices.Subscribe("BSDX CALL WORKSTATIONS");
 			//Table #18
             setProgressDelegate(20);
-            _current.m_ConnectInfo.SubscribeEvent("BSDX ADMIN MESSAGE");
+            _current.RemoteSession.EventServices.Subscribe("BSDX ADMIN MESSAGE");
 			//Table #19
             setProgressDelegate(21);
-            _current.m_ConnectInfo.SubscribeEvent("BSDX ADMIN SHUTDOWN");
-
-			_current.m_ConnectInfo.EventPollingInterval = 5000; //in milliseconds
-			_current.m_ConnectInfo.EventPollingEnabled = true;
-			_current.m_ConnectInfo.AutoFire = 12; //AutoFire every 12*5 seconds
+            _current.RemoteSession.EventServices.Subscribe("BSDX ADMIN SHUTDOWN");
+
+			_current.RemoteSession.EventServices.EventPollingInterval = 5000; //in milliseconds
+			_current.RemoteSession.EventServices.IsEventPollingEnabled = true;
+			
+            //PORT TODO: No Autofire in BMX 4.0
+            //_current.RemoteSession.EventServices. = 12; //AutoFire every 12*5 seconds
 
             //Close Splash Screen
@@ -785,5 +877,5 @@
 		{
 			string sCommandText = "SELECT * FROM BSDX_ACCESS_GROUP";
-			ConnectInfo.RPMSDataTable(sCommandText, "AccessGroup", m_dsGlobal);
+			RemoteSession.TableFromSQL(sCommandText, m_dsGlobal, "AccessGroup");
 			Debug.Write("LoadGlobalRecordsets -- AccessGroups loaded\n");
 		}
@@ -792,5 +884,5 @@
 		{
 			string sCommandText = "BSDX GET ACCESS GROUP TYPES";
-			ConnectInfo.RPMSDataTable(sCommandText, "AccessGroupType", m_dsGlobal);
+            RemoteSession.TableFromCommand(sCommandText, m_dsGlobal, "AccessGroupType");
 			Debug.Write("LoadGlobalRecordsets -- AccessGroupTypes loaded\n");
 		}
@@ -798,6 +890,6 @@
 		public void LoadBSDXResourcesTable()
 		{
-			string sCommandText = "BSDX RESOURCES^" + m_ConnectInfo.DUZ;
-			ConnectInfo.RPMSDataTable(sCommandText, "Resources", m_dsGlobal);
+			string sCommandText = "BSDX RESOURCES^" + RemoteSession.User.Duz;
+            RemoteSession.TableFromCommand(sCommandText, m_dsGlobal, "Resources");
 			Debug.Write("LoadGlobalRecordsets -- Resources loaded\n");
 		}
@@ -809,6 +901,6 @@
 			//to which user has access
 			//Fields are: RESOURCE_GROUPID, RESOURCE_GROUP
-			string sCommandText = "BSDX RESOURCE GROUPS BY USER^" + m_ConnectInfo.DUZ;
-			ConnectInfo.RPMSDataTable(sCommandText, "ResourceGroup", m_dsGlobal);
+			string sCommandText = "BSDX RESOURCE GROUPS BY USER^" + RemoteSession.User.Duz;
+            RemoteSession.TableFromCommand(sCommandText, m_dsGlobal, "ResourceGroup");
 			Debug.Write("LoadGlobalRecordsets -- ResourceGroup loaded\n");
 		}
@@ -821,6 +913,6 @@
 			//are returned.
 			//Fields are: RESOURCE_GROUPID, RESOURCE_GROUP, RESOURCE_GROUP_ITEMID, RESOURCE_NAME, RESOURCE_ID
-			string sCommandText = "BSDX GROUP RESOURCE^" + m_ConnectInfo.DUZ;
-			ConnectInfo.RPMSDataTable(sCommandText, "GroupResources", m_dsGlobal);
+			string sCommandText = "BSDX GROUP RESOURCE^" + RemoteSession.User.Duz;
+            RemoteSession.TableFromCommand(sCommandText, m_dsGlobal, "GroupResources");
 			Debug.Write("LoadGlobalRecordsets -- GroupResources loaded\n");
 		}
@@ -831,5 +923,5 @@
 			//who possesses the BSDXZMENU security key.
 			string sCommandText = "BSDX SCHEDULE USER";
-			ConnectInfo.RPMSDataTable(sCommandText, "ScheduleUser", m_dsGlobal);
+            RemoteSession.TableFromCommand(sCommandText, m_dsGlobal, "ScheduleUser");
 			Debug.Write("LoadGlobalRecordsets -- ScheduleUser loaded\n");
 		}
@@ -850,8 +942,8 @@
             if (!bAllUsers)
             {
-                sCommandText += String.Format(" WHERE INTERNAL[USERNAME] = {0}", m_ConnectInfo.DUZ);
-            }
-
-			ConnectInfo.RPMSDataTable(sCommandText, "ResourceUser", m_dsGlobal);
+                sCommandText += String.Format(" WHERE INTERNAL[USERNAME] = {0}", RemoteSession.User.Duz);
+            }
+
+            RemoteSession.TableFromSQL(sCommandText, m_dsGlobal, "ResourceUser");
 			Debug.Write("LoadGlobalRecordsets -- ResourceUser loaded\n");
 		}
@@ -968,7 +1060,7 @@
 			if ((Views.Count == 0)&&(this.AvailabilityViews.Count == 0)&&(m_bExitOK == true))
 			{
-				m_ConnectInfo.EventPollingEnabled = false;
-				m_ConnectInfo.UnSubscribeEvent("BSDX SCHEDULE");
-				m_ConnectInfo.CloseConnection();
+				RemoteSession.EventServices.IsEventPollingEnabled = false;
+				RemoteSession.EventServices.Unsubscribe("BSDX SCHEDULE");
+                RemoteSession.Close();
 				Application.Exit();
 			}
@@ -983,5 +1075,5 @@
 			if ((Views.Count == 0)&&(this.AvailabilityViews.Count == 0)&&(m_bExitOK == true))
 			{
-				m_ConnectInfo.bmxNetLib.CloseConnection();
+                RemoteSession.Close();
 				Application.Exit();
 			}
@@ -1123,7 +1215,7 @@
                 
                 //Used in Do loop
-                bool bRetry = true;
+                //bool bRetry = true;
 				
-                // Do Loop to deal with changing the server and the vagaries of user choices.
+                /*// Do Loop to deal with changing the server and the vagaries of user choices.
 				do
 				{
@@ -1134,5 +1226,6 @@
                         //so it can be re-used when BMX tries to log in again.
                         //Access and Verify code are prompted for in InitializeApp
-						m_ConnectInfo.ChangeServerInfo();
+                        LoginProcess login = this.WinFramework.CreateLoginProcess();
+                        login.AttemptUserInputLogin("ReLog-in", 3, true, null);
 						bRetry = false;
 					}
@@ -1157,5 +1250,6 @@
 					}
 				} while (bRetry == true);
-
+                */
+                
                 //Parameter for initialize app tells it that this is a re-login and forces a new access and verify code.
                 bool isEverythingOkay = this.InitializeApp(true);
@@ -1194,5 +1288,8 @@
 		private void mnuRPMSLogin_Click(object sender, EventArgs e)
 		{
-			//Warn that changing login will close all schedules
+            mnuRPMSServer_Click(sender, e);
+            
+            /* v 1.7 to support BMX 4 -- commented out -- smh
+            //Warn that changing login will close all schedules
 			if (MessageBox.Show("Are you sure you want to close all schedules and login to VistA?", "Clinical Scheduling", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) != DialogResult.OK)
 				return;
@@ -1206,4 +1303,22 @@
 				CloseAll();
 				m_bExitOK = true;
+
+                LoginProcess login = this.WinFramework.CreateLoginProcess();
+                login.AttemptUserInputLogin("Clincal Scheduling", 3, true, null);
+                //m_ConnectInfo.bmxNetLib.StartLog();    //This line turns on logging of messages
+
+                if (!login.WasSuccessful)
+                {
+                    return;
+                }
+
+                LocalSession local = this.WinFramework.LocalSession;
+
+                if ((this.WinFramework.Context.User.Division == null) && !this.WinFramework.AttemptUserInputSetDivision("Set Initial Division", null))
+                {
+                    return;
+                }
+
+                this.RemoteSession = this.WinFramework.PrimaryRemoteSession;
 
                 //Parameter for initialize app tells it that this is a re-login and forces a new access and verify code.
@@ -1233,5 +1348,5 @@
 				throw ex;
 			}
-	
+	        */
 		}
 
@@ -1290,7 +1405,9 @@
 			{
 				//System.IntPtr pHandle = this.Handle;
-				RPMSDataTableDelegate rdtd = new RPMSDataTableDelegate(ConnectInfo.RPMSDataTable);
+				RPMSDataTableDelegate rdtd = new RPMSDataTableDelegate(RemoteSession.TableFromCommand);
 				//dtOut = (DataTable) this.Invoke(rdtd, new object[] {sSQL, sTableName});
-                dtOut = rdtd.Invoke(sSQL, sTableName);
+                dtOut = RemoteSession.TableFromCommand(sSQL);
+                dtOut.TableName = sTableName;
+
 			}
 
@@ -1307,5 +1424,8 @@
 		public void ChangeDivision(System.Windows.Forms.Form frmCaller)
 		{
-			this.ConnectInfo.ChangeDivision(frmCaller);
+            WinFramework.AttemptUserInputSetDivision("Change Division", frmCaller);
+
+            RemoteSession = WinFramework.PrimaryRemoteSession;
+
 			foreach (CGView v in _views.Keys)
 			{
Index: /Scheduling/branches/BMX4Support/CGView.cs
===================================================================
--- /Scheduling/branches/BMX4Support/CGView.cs	(revision 1193)
+++ /Scheduling/branches/BMX4Support/CGView.cs	(revision 1194)
@@ -114,4 +114,5 @@
         private MenuItem sepApptMenu3;
         private MenuItem mnuReprintApptSlip;
+        private MenuItem mnuViewBrokerLog;
         private IContainer components;
 
@@ -132,9 +133,9 @@
 		public void InitializeDocView(string sText)
 		{
-			this.Text = this.DocManager.ConnectInfo.UserName;
+            this.Text = CGDocumentManager.Current.RemoteSession.User.Name;
 			if (sText != null)
 				this.Text += " - " + sText;
-			if (DocManager.ConnectInfo.DivisionName != null)
-				this.Text += " - " + DocManager.ConnectInfo.DivisionName;
+            if (CGDocumentManager.Current.RemoteSession.User.Division.Name != null)
+                this.Text += " - " + CGDocumentManager.Current.RemoteSession.User.Division.Name;
 		}
 
@@ -157,16 +158,12 @@
 
             // Set username and division up top
-            this.Text = this.DocManager.ConnectInfo.UserName;
+            this.Text = CGDocumentManager.Current.RemoteSession.User.Name;
 			if (sText != null)
 				this.Text += " - " + sText;
-			if (DocManager.ConnectInfo.DivisionName != null)
-				this.Text += " - " + DocManager.ConnectInfo.DivisionName;
-
-			this.m_ConnectInfo = m_DocManager.ConnectInfo;
-			m_bmxDelegate = new BMXNetConnectInfo.BMXNetEventDelegate(BMXNetEventHandler);
-			m_ConnectInfo.BMXNetEvent += m_bmxDelegate;
-		}
-
-		private BMXNetConnectInfo.BMXNetEventDelegate m_bmxDelegate;
+			if (CGDocumentManager.Current.RemoteSession.User.Division.Name != null)
+                this.Text += " - " + CGDocumentManager.Current.RemoteSession.User.Division.Name;
+
+            CGDocumentManager.Current.RemoteSession.EventServices.RpmsEvent += BMXNetEventHandler;
+		}
 		
 
@@ -235,4 +232,5 @@
             this.mnuHelp = new System.Windows.Forms.MenuItem();
             this.mnuHelpAbout = new System.Windows.Forms.MenuItem();
+            this.mnuViewBrokerLog = new System.Windows.Forms.MenuItem();
             this.mnuTest = new System.Windows.Forms.MenuItem();
             this.mnuTest1 = new System.Windows.Forms.MenuItem();
@@ -680,5 +678,6 @@
             this.mnuHelp.Index = 3;
             this.mnuHelp.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
-            this.mnuHelpAbout});
+            this.mnuHelpAbout,
+            this.mnuViewBrokerLog});
             this.mnuHelp.Text = "&Help";
             // 
@@ -688,4 +687,10 @@
             this.mnuHelpAbout.Text = "&About";
             this.mnuHelpAbout.Click += new System.EventHandler(this.mnuHelpAbout_Click);
+            // 
+            // mnuViewBrokerLog
+            // 
+            this.mnuViewBrokerLog.Index = 1;
+            this.mnuViewBrokerLog.Text = "&View Broker Log";
+            this.mnuViewBrokerLog.Click += new System.EventHandler(this.mnuViewBrokerLog_Click);
             // 
             // mnuTest
@@ -702,5 +707,4 @@
             this.mnuTest1.Index = 0;
             this.mnuTest1.Text = "Test1";
-            this.mnuTest1.Click += new System.EventHandler(this.mnuTest1_Click);
             // 
             // tvSchedules
@@ -712,5 +716,5 @@
             this.tvSchedules.Location = new System.Drawing.Point(0, 0);
             this.tvSchedules.Name = "tvSchedules";
-            this.tvSchedules.Size = new System.Drawing.Size(128, 392);
+            this.tvSchedules.Size = new System.Drawing.Size(128, 389);
             this.tvSchedules.Sorted = true;
             this.tvSchedules.TabIndex = 1;
@@ -781,5 +785,5 @@
             this.panelRight.Location = new System.Drawing.Point(996, 0);
             this.panelRight.Name = "panelRight";
-            this.panelRight.Size = new System.Drawing.Size(128, 392);
+            this.panelRight.Size = new System.Drawing.Size(128, 389);
             this.panelRight.TabIndex = 3;
             this.panelRight.Visible = false;
@@ -877,5 +881,5 @@
             this.panelCenter.Location = new System.Drawing.Point(136, 24);
             this.panelCenter.Name = "panelCenter";
-            this.panelCenter.Size = new System.Drawing.Size(857, 344);
+            this.panelCenter.Size = new System.Drawing.Size(857, 341);
             this.panelCenter.TabIndex = 7;
             // 
@@ -984,5 +988,5 @@
             this.panelBottom.Controls.Add(this.statusBar1);
             this.panelBottom.Dock = System.Windows.Forms.DockStyle.Bottom;
-            this.panelBottom.Location = new System.Drawing.Point(136, 368);
+            this.panelBottom.Location = new System.Drawing.Point(136, 365);
             this.panelBottom.Name = "panelBottom";
             this.panelBottom.Size = new System.Drawing.Size(857, 24);
@@ -1002,5 +1006,5 @@
             this.splitter1.Location = new System.Drawing.Point(128, 24);
             this.splitter1.Name = "splitter1";
-            this.splitter1.Size = new System.Drawing.Size(8, 368);
+            this.splitter1.Size = new System.Drawing.Size(8, 365);
             this.splitter1.TabIndex = 9;
             this.splitter1.TabStop = false;
@@ -1011,5 +1015,5 @@
             this.splitter2.Location = new System.Drawing.Point(993, 24);
             this.splitter2.Name = "splitter2";
-            this.splitter2.Size = new System.Drawing.Size(3, 368);
+            this.splitter2.Size = new System.Drawing.Size(3, 365);
             this.splitter2.TabIndex = 10;
             this.splitter2.TabStop = false;
@@ -1034,5 +1038,5 @@
             this.calendarGrid1.Resources = ((System.Collections.ArrayList)(resources.GetObject("calendarGrid1.Resources")));
             this.calendarGrid1.SelectedAppointment = 0;
-            this.calendarGrid1.Size = new System.Drawing.Size(857, 344);
+            this.calendarGrid1.Size = new System.Drawing.Size(857, 341);
             this.calendarGrid1.StartDate = new System.DateTime(2003, 1, 27, 0, 0, 0, 0);
             this.calendarGrid1.TabIndex = 0;
@@ -1047,5 +1051,5 @@
             // 
             this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
-            this.ClientSize = new System.Drawing.Size(1124, 392);
+            this.ClientSize = new System.Drawing.Size(1124, 389);
             this.Controls.Add(this.panelCenter);
             this.Controls.Add(this.panelBottom);
@@ -1086,6 +1090,4 @@
 		private Hashtable			m_htModifySchedule;
 		private Hashtable			m_htChangeAppts;
-		private BMXNetConnectInfo	m_ConnectInfo = null;
-		public BMXNetConnectInfo.BMXNetEventDelegate	BMXNetEvent;
 
 		#endregion Fields
@@ -1308,5 +1310,5 @@
 			DataTable dt = this.DocManager.GlobalDataSet.Tables["ResourceUser"];
 			DataView dv = new DataView(dt, "", "RESOURCENAME ASC", DataViewRowState.OriginalRows);
-			string sDuz = this.DocManager.ConnectInfo.DUZ;
+            string sDuz = CGDocumentManager.Current.RemoteSession.User.Duz;
 			bool bModSchedule = false;
 			DataRowView[] drvA = dv.FindRows(sResource);
@@ -1756,5 +1758,5 @@
 					doc.ResourceID = Convert.ToInt32(sResourceID);
 
-					bool bLock = DocManager.ConnectInfo.bmxNetLib.Lock("^BSDXRES(" + sResourceID + ")", "+");
+                    bool bLock = CGDocumentManager.Current.RemoteSession.Lock("^BSDXRES(" + sResourceID + ")", "+");
 					if (bLock == false)
 					{
@@ -1929,5 +1931,5 @@
 			dt = this.DocManager.GlobalDataSet.Tables["ResourceUser"];
 			dv = new DataView(dt, "", "RESOURCENAME ASC", DataViewRowState.OriginalRows);
-			dv.RowFilter = "USERNAME = '" + this.DocManager.ConnectInfo.UserName + "'";
+            dv.RowFilter = "USERNAME = '" + CGDocumentManager.Current.RemoteSession.User.Name + "'";
 			for (int j=0; j < dv.Count; j++)
 			{
@@ -2504,6 +2506,6 @@
 			{
                 string msg;
-                if (BMXNetLib.Piece(ex.Message, "~", 1) == "-10") // -10 means that BSDXAPI reported an error.
-                    msg = BMXNetLib.Piece(ex.Message, "~", 4);
+                if (M.Piece(ex.Message, "~", 1) == "-10") // -10 means that BSDXAPI reported an error.
+                    msg = M.Piece(ex.Message, "~", 4);
                 else
                     msg = ex.Message;
@@ -2615,6 +2617,6 @@
 			{   
                 string msg;
-                if (BMXNetLib.Piece(ex.Message, "~", 1) == "-10") // -10 means that BSDXAPI reported an error.
-                    msg = BMXNetLib.Piece(ex.Message, "~", 4);
+                if (M.Piece(ex.Message, "~", 1) == "-10") // -10 means that BSDXAPI reported an error.
+                    msg = M.Piece(ex.Message, "~", 4);
                 else
                     msg = ex.Message;
@@ -2716,5 +2718,5 @@
         /// <param name="e">BMXEvent Args: 
         /// e.BMXEvent is free text for Event Type; e.BMXParam is free text for Event Arguments</param>
-        private void BMXNetEventHandler(Object obj, BMXNet.BMXNetEventArgs e)
+        private void BMXNetEventHandler(Object obj, RemoteEventArgs e)
         {
             try
@@ -2724,5 +2726,5 @@
 
                 // if event is Autofire event
-                if (e.BMXEvent == "BMXNet AutoFire")
+                if (e.EventType == "BMXNet AutoFire")
                 {
                     Debug.Write("CGView caught AutoFire event.\n");
@@ -2737,5 +2739,5 @@
 
                 // if event is BSDX SCHEDULE
-                else if (e.BMXEvent == "BSDX SCHEDULE")
+                else if (e.EventType == "BSDX SCHEDULE")
                 {
                     //See if any of the resources in the event argument matches BSDX Schedule.
@@ -2745,5 +2747,5 @@
                     {
                         sResourceName = m_Document.m_sResourcesArray[j].ToString();
-                        if (e.BMXParam == sResourceName)
+                        if (e.Details == sResourceName)
                         {
                             Debug.Write("CGView caught BSDX SCHEDULE event.\n");
@@ -2813,5 +2815,5 @@
             {
                 //Signal RPMS to raise an event
-                m_ConnectInfo.RaiseEvent(sEvent, sParams, false);
+                CGDocumentManager.Current.RemoteSession.EventServices.TriggerEvent(sEvent, sParams, false);
             }
             catch (Exception ex)
@@ -2859,5 +2861,5 @@
             try
             {
-                bool bLock = DocManager.ConnectInfo.Lock("^BSDXMGR", "+", "");
+                bool bLock = CGDocumentManager.Current.RemoteSession.Lock("^BSDXMGR", "+");
                 if (bLock == false)
                 {
@@ -2874,5 +2876,5 @@
                 m_DocManager.GlobalDataSet.Tables["ResourceUser"].Clear();
                 m_DocManager.LoadResourceUserTable(false);
-                bLock = DocManager.ConnectInfo.bmxNetLib.Lock("^BSDXMGR", "-");
+                bLock = CGDocumentManager.Current.RemoteSession.Lock("^BSDXMGR", "-");
             }
             catch (ApplicationException aex)
@@ -3140,47 +3142,9 @@
         }
 
-        /// <summary>
-        /// Useless code now... Good place to test something.
-        /// </summary>
-        /// <param name="sender"></param>
-        /// <param name="e"></param>
-		private void mnuTest1_Click(object sender, System.EventArgs e)
-		{
-			ReaderWriterLock m_rwl = this.DocManager.ConnectInfo.bmxNetLib.BMXRWL;
+		private void CGView_Closing(object sender, System.ComponentModel.CancelEventArgs e)
+		{
 			try
 			{
-				m_rwl.AcquireWriterLock(50);
-				Debug.Write("\nTest Button 1 Acquired first lock\n");
-				m_rwl.AcquireWriterLock(50);
-				Debug.Write("Test Button 1 Acquired second lock\n");
-				this.DocManager.ViewRefresh();
-				Thread.Sleep(5000);
-				try
-				{
-				}
-				catch
-				{
-				}
-				finally
-				{
-					m_rwl.ReleaseWriterLock();
-					Debug.Write ("Test Button 1 released first lock.\n");
-					m_rwl.ReleaseWriterLock();
-					Debug.Write ("Test Button 1 released second lock.\n");
-				}
-
-				return;
-			}
-			catch (Exception ex)
-			{
-				Debug.Write("Test Button 1 exception: " + ex.Message + "\n");
-			}
-		}
-
-		private void CGView_Closing(object sender, System.ComponentModel.CancelEventArgs e)
-		{
-			try
-			{
-				m_ConnectInfo.BMXNetEvent -= m_bmxDelegate;
+				CGDocumentManager.Current.RemoteSession.EventServices.RpmsEvent -= BMXNetEventHandler;
 				this.calendarGrid1.CloseGrid();
 			}
@@ -3904,4 +3868,10 @@
         }
 
+        private void mnuViewBrokerLog_Click(object sender, EventArgs e)
+        {
+            var view = new RPCLoggerView();
+            view.Show();
+        }
+
 
     }//End class
Index: /Scheduling/branches/BMX4Support/ClinicalScheduling.csproj
===================================================================
--- /Scheduling/branches/BMX4Support/ClinicalScheduling.csproj	(revision 1193)
+++ /Scheduling/branches/BMX4Support/ClinicalScheduling.csproj	(revision 1194)
@@ -148,4 +148,11 @@
     <Compile Include="Provider.cs" />
     <Compile Include="RadiologyExam.cs" />
+    <Compile Include="RPCLogger.cs" />
+    <Compile Include="RPCLoggerView.cs">
+      <SubType>Form</SubType>
+    </Compile>
+    <Compile Include="RPCLoggerView.Designer.cs">
+      <DependentUpon>RPCLoggerView.cs</DependentUpon>
+    </Compile>
     <Compile Include="strings.ar.Designer.cs">
       <AutoGen>True</AutoGen>
@@ -431,4 +438,7 @@
     <EmbeddedResource Include="LoadingSplash.resx">
       <DependentUpon>LoadingSplash.cs</DependentUpon>
+    </EmbeddedResource>
+    <EmbeddedResource Include="RPCLoggerView.resx">
+      <DependentUpon>RPCLoggerView.cs</DependentUpon>
     </EmbeddedResource>
     <EmbeddedResource Include="strings.ar.resx">
@@ -479,7 +489,11 @@
   </ItemGroup>
   <ItemGroup>
-    <ProjectReference Include="..\bmx\BMXNet\BMXNet.csproj">
+    <ProjectReference Include="..\BMX4\IHS BMX Framework\IndianHealthService.BMXNet.WinForm\IndianHealthService.BMXNet.WinForm.csproj">
+      <Project>{3B9011B5-59F4-4F6B-ADC7-54ADC6948F4D}</Project>
+      <Name>IndianHealthService.BMXNet.WinForm</Name>
+    </ProjectReference>
+    <ProjectReference Include="..\BMX4\IHS BMX Framework\IndianHealthService.BMXNet\IndianHealthService.BMXNet.csproj">
       <Project>{DE8E4CC9-4F3A-4E32-8DFE-EE5692E8FC45}</Project>
-      <Name>BMXNet</Name>
+      <Name>IndianHealthService.BMXNet</Name>
     </ProjectReference>
   </ItemGroup>
Index: /Scheduling/branches/BMX4Support/ClinicalScheduling.csproj.user
===================================================================
--- /Scheduling/branches/BMX4Support/ClinicalScheduling.csproj.user	(revision 1193)
+++ /Scheduling/branches/BMX4Support/ClinicalScheduling.csproj.user	(revision 1194)
@@ -37,5 +37,5 @@
     </RemoteDebugMachine>
     <StartAction>Project</StartAction>
-    <StartArguments>/s=172.16.16.108 /p=9250 /a=s.habiel /v=catdog.77</StartArguments>
+    <StartArguments>/s=172.16.16.142 /p=9260 /a=shabiel12 /v=catdog.77</StartArguments>
     <StartPage>
     </StartPage>
Index: /Scheduling/branches/BMX4Support/ClinicalScheduling.sln
===================================================================
--- /Scheduling/branches/BMX4Support/ClinicalScheduling.sln	(revision 1193)
+++ /Scheduling/branches/BMX4Support/ClinicalScheduling.sln	(revision 1194)
@@ -3,5 +3,7 @@
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClinicalScheduling", "ClinicalScheduling.csproj", "{8C05C4F7-FE81-479F-87A0-44E04C7F6E0F}"
 EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BMXNet", "..\bmx\BMXNet\BMXNet.csproj", "{DE8E4CC9-4F3A-4E32-8DFE-EE5692E8FC45}"
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IndianHealthService.BMXNet", "..\BMX4\IHS BMX Framework\IndianHealthService.BMXNet\IndianHealthService.BMXNet.csproj", "{DE8E4CC9-4F3A-4E32-8DFE-EE5692E8FC45}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IndianHealthService.BMXNet.WinForm", "..\BMX4\IHS BMX Framework\IndianHealthService.BMXNet.WinForm\IndianHealthService.BMXNet.WinForm.csproj", "{3B9011B5-59F4-4F6B-ADC7-54ADC6948F4D}"
 EndProject
 Global
@@ -19,4 +21,8 @@
 		{DE8E4CC9-4F3A-4E32-8DFE-EE5692E8FC45}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{DE8E4CC9-4F3A-4E32-8DFE-EE5692E8FC45}.Release|Any CPU.Build.0 = Release|Any CPU
+		{3B9011B5-59F4-4F6B-ADC7-54ADC6948F4D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{3B9011B5-59F4-4F6B-ADC7-54ADC6948F4D}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{3B9011B5-59F4-4F6B-ADC7-54ADC6948F4D}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{3B9011B5-59F4-4F6B-ADC7-54ADC6948F4D}.Release|Any CPU.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
Index: /Scheduling/branches/BMX4Support/DAL.cs
===================================================================
--- /Scheduling/branches/BMX4Support/DAL.cs	(revision 1193)
+++ /Scheduling/branches/BMX4Support/DAL.cs	(revision 1194)
@@ -16,5 +16,5 @@
     public class DAL
     {
-        private BMXNetConnectInfo _thisConnection; // set in constructor
+        private RemoteSession _thisConnection; // set in constructor
         
         delegate DataTable RPMSDataTableDelegate(string CommandString, string TableName); // for use in calling (Sync and Async)
@@ -25,5 +25,5 @@
         /// </summary>
         /// <param name="conn">The current connection to use</param>
-        public DAL(BMXNetConnectInfo conn)
+        public DAL(RemoteSession conn)
         {
             this._thisConnection = conn;
@@ -39,5 +39,5 @@
         {
             string cmd = String.Format("BMX VERSION INFO^{0}", nmsp);
-            return RPMSDataTable(cmd, "");
+            return _thisConnection.TableFromCommand(cmd);
         }
 
@@ -50,5 +50,5 @@
         {
             string cmd = String.Format("BSDX SCHEDULING USER INFO^{0}", DUZ);
-            return RPMSDataTable(cmd, "");
+            return _thisConnection.TableFromCommand(cmd);
         }
 
@@ -65,8 +65,8 @@
         /// BLUE (NJ3,0), [0;7]
         ///</returns>
-        public DataTable GetAccessTypes()
+        public DataTable GetAccessTypes(DataSet dataSetToTakeTable, string tablename)
         {
             string sCommandText = "SELECT * FROM BSDX_ACCESS_TYPE";
-            DataTable table = RPMSDataTable(sCommandText, "");
+            DataTable table = _thisConnection.TableFromSQL(sCommandText, dataSetToTakeTable, tablename);
             DataColumn dcKey = table.Columns["BMXIEN"];
             DataColumn[] dcKeys = new DataColumn[1];
@@ -93,5 +93,5 @@
             string sEnd = FMDateTime.Create(EndDate).DateOnly.FMDateString;
             string cmd = String.Format("BSDX CLINIC LETTERS^{0}^{1}^{2}", sClinicList, sBegin, sEnd);
-            return RPMSDataTable(cmd, "");
+            return _thisConnection.TableFromCommand(cmd);
         }
 
@@ -107,5 +107,5 @@
         {
             string cmd = String.Format("BSDX RESOURCE LETTERS^{0}", sClinicList);
-            return RPMSDataTable(cmd, "");
+            return _thisConnection.TableFromCommand(cmd);
         }
 
@@ -126,5 +126,5 @@
             string sEnd = FMDateTime.Create(EndDate).DateOnly.FMDateString;
             string cmd = String.Format("BSDX REBOOK CLINIC LIST^{0}^{1}^{2}", sClinicList, sBegin, sEnd);
-            return RPMSDataTable(cmd, "");
+            return _thisConnection.TableFromCommand(cmd);
         }
 
@@ -139,5 +139,5 @@
         {
             string cmd = String.Format("BSDX REBOOK LIST^{0}", sApptList);
-            return RPMSDataTable(cmd, "");
+            return _thisConnection.TableFromCommand(cmd);
         }
 
@@ -157,5 +157,5 @@
             string sEnd = FMDateTime.Create(EndDate).DateOnly.FMDateString;
             string cmd = String.Format("BSDX CANCEL CLINIC LIST^{0}^{1}^{2}", sClinicList, sBegin, sEnd);
-            return RPMSDataTable(cmd, "");
+            return _thisConnection.TableFromCommand(cmd);
         }
 
@@ -173,5 +173,5 @@
             string sEnd = FMDateTime.Create(EndDate).DateOnly.FMDateString;
             string cmd = String.Format("BSDX CANCEL AV BY DATE^{0}^{1}^{2}", sResourceID, sBegin, sEnd);
-            return RPMSDataTable(cmd, "Cancelled");
+            return _thisConnection.TableFromCommand(cmd);
         }
 
@@ -185,5 +185,5 @@
         {
             string cmd = string.Format("BSDX REMOVE CHECK-IN^{0}", ApptID);
-            return RPMSDataTable(cmd, "");
+            return _thisConnection.TableFromCommand(cmd);
         }
 
@@ -197,5 +197,5 @@
         {
             string cmd = string.Format("BSDX GET RAD EXAM FOR PT^{0}^{1}", DFN, SCIEN);
-            DataTable tbl = RPMSDataTable(cmd, "");
+            DataTable tbl = _thisConnection.TableFromCommand(cmd);
             return (from row in tbl.AsEnumerable()
                     select new RadiologyExam
@@ -218,5 +218,5 @@
         {
             string fmStartDate = FMDateTime.Create(dStart).FMDateString;
-            string result = _thisConnection.bmxNetLib.TransmitRPC("BSDX SCHEDULE RAD EXAM", string.Format("{0}^{1}^{2}", DFN, examIEN, fmStartDate));
+            string result = _thisConnection.TransmitRPC("BSDX SCHEDULE RAD EXAM", string.Format("{0}^{1}^{2}", DFN, examIEN, fmStartDate));
             return result == "1" ? true : false;
         }
@@ -230,5 +230,5 @@
         public bool CancelRadiologyExam(int DFN, int examIEN)
         {
-            string result = _thisConnection.bmxNetLib.TransmitRPC("BSDX HOLD RAD EXAM", string.Format("{0}^{1}", DFN, examIEN));
+            string result = _thisConnection.TransmitRPC("BSDX HOLD RAD EXAM", string.Format("{0}^{1}", DFN, examIEN));
             return result == "1" ? true : false;
         }
@@ -245,10 +245,10 @@
             get
             {
-                string val = _thisConnection.bmxNetLib.TransmitRPC("BSDX GET PARAM", "BSDX AUTO PRINT RS");  //1 = true; 0 = false; "" = not set
+                string val = _thisConnection.TransmitRPC("BSDX GET PARAM", "BSDX AUTO PRINT RS");  //1 = true; 0 = false; "" = not set
                 return val == "1" ? true : false;
             }
             set
             {
-                TransmitRPCAsync _asyncTransmitter = new TransmitRPCAsync(_thisConnection.bmxNetLib.TransmitRPC);
+                TransmitRPCAsync _asyncTransmitter = new TransmitRPCAsync(_thisConnection.TransmitRPC);
                 // 0 = success; anything else is wrong. Not being tested here as its success is not critical to application use.
                 _asyncTransmitter.BeginInvoke("BSDX SET PARAM", String.Format("{0}^{1}", "BSDX AUTO PRINT RS", value ? "1" : "0"), null, null);
@@ -267,10 +267,10 @@
             get
             {
-                string val = _thisConnection.bmxNetLib.TransmitRPC("BSDX GET PARAM", "BSDX AUTO PRINT AS");  //1 = true; 0 = false; "" = not set
+                string val = _thisConnection.TransmitRPC("BSDX GET PARAM", "BSDX AUTO PRINT AS");  //1 = true; 0 = false; "" = not set
                 return val == "1" ? true : false;
             }
             set
             {
-                TransmitRPCAsync _asyncTransmitter = new TransmitRPCAsync(_thisConnection.bmxNetLib.TransmitRPC);
+                TransmitRPCAsync _asyncTransmitter = new TransmitRPCAsync(_thisConnection.TransmitRPC);
                 // 0 = success; anything else is wrong. Not being tested here as its success is not critical to application use.
                 _asyncTransmitter.BeginInvoke("BSDX SET PARAM", String.Format("{0}^{1}", "BSDX AUTO PRINT AS", value ? "1" : "0"), null, null);
@@ -292,10 +292,7 @@
             DataTable dtOut;
 
-#if TRACE
-            DateTime sendTime = DateTime.Now;
-#endif
             try
             {
-                RPMSDataTableDelegate rdtd = new RPMSDataTableDelegate(_thisConnection.RPMSDataTable);
+                RPMSDataTableDelegate rdtd = new RPMSDataTableDelegate(_thisConnection.TableFromSQL);
                 dtOut = (DataTable)rdtd.Invoke(sSQL, sTableName);
             }
@@ -306,10 +303,4 @@
                 throw ex;
             }
-
-#if TRACE
-            DateTime receiveTime = DateTime.Now;
-            TimeSpan executionTime = receiveTime - sendTime;
-            Debug.Write("RPMSDataTable Execution Time: " + executionTime.Milliseconds + " ms.\n");
-#endif
 
             return dtOut;
Index: /Scheduling/branches/BMX4Support/DManagement.cs
===================================================================
--- /Scheduling/branches/BMX4Support/DManagement.cs	(revision 1193)
+++ /Scheduling/branches/BMX4Support/DManagement.cs	(revision 1194)
@@ -140,7 +140,6 @@
 			this.m_dsGlobal = m_DocManager.GlobalDataSet;
 
-			MgrEventDelegate = new BMXNetConnectInfo.BMXNetEventDelegate(MgrEventHandler);
-			m_DocManager.ConnectInfo.BMXNetEvent += MgrEventDelegate;
-			m_DocManager.ConnectInfo.SubscribeEvent("BSDX WORKSTATION REPORT");
+            m_DocManager.RemoteSession.EventServices.RpmsEvent += MgrEventHandler;
+			m_DocManager.RemoteSession.EventServices.Subscribe("BSDX WORKSTATION REPORT");
 			m_dtWSGrid = new DataTable("WSGrid");
 			m_dtWSGrid.Columns.Add("UserName", typeof(System.String));
@@ -1899,7 +1898,8 @@
             m_dsGlobal.Tables["AccessTypes"].Clear();
             m_dsGlobal.Tables["AccessGroupType"].Clear();
-            DataTable dt1 = m_DocManager.DAL.GetAccessTypes();
-            m_dsGlobal.Tables["AccessTypes"].Merge(dt1);
-            m_dsGlobal.Tables.Add(dt1);
+            //PORT TODO: This may fail.
+            DataTable dt1 = m_DocManager.DAL.GetAccessTypes(m_dsGlobal, "AccessTypes");
+            //m_dsGlobal.Tables["AccessTypes"].Merge(dt1); //smh -commented out for BMX4
+            //m_dsGlobal.Tables.Add(dt1);                  //smh -commented out for BMX4
             //Fix Groups
             //m_DocManager.LoadAccessTypesTable();
@@ -2329,15 +2329,14 @@
 		{
 			this.m_dtWSGrid.Clear();
-			this.m_DocManager.ConnectInfo.RaiseEvent("BSDX CALL WORKSTATIONS", "A", true);
-		}
-
-		private BMXNetConnectInfo.BMXNetEventDelegate	MgrEventDelegate;
+			this.m_DocManager.RemoteSession.EventServices.TriggerEvent("BSDX CALL WORKSTATIONS", "A", true);
+		}
+
 		delegate void UpdateWorkstationGridDelegate(string sParam);
 
-		private void MgrEventHandler(Object obj, BMXNet.BMXNetEventArgs e)
+		private void MgrEventHandler(Object obj, RemoteEventArgs e)
 		{
 			try
 			{
-				if (e.BMXEvent == "BSDX WORKSTATION REPORT")
+				if (e.EventType == "BSDX WORKSTATION REPORT")
 				{
 					Debug.Write("DManagement Got Workstation Report\n");
@@ -2345,9 +2344,9 @@
                     if (this.InvokeRequired == true) //ensures that handle is created
                     {
-                        this.Invoke(uWSGd, new object[] { e.BMXParam });
+                        this.Invoke(uWSGd, new object[] { e.Details });
                     }
                     else
                     {
-                        UpdateWorkstationGrid(e.BMXParam);
+                        UpdateWorkstationGrid(e.Details);
                     }
 				}
@@ -2363,8 +2362,8 @@
 			string sDelim = "~";
 			DataRow dr = this.m_dtWSGrid.NewRow();
-			dr["UserName"] = BMXNetLib.Piece(sParam,sDelim,1);
-			dr["Handle"] = BMXNetLib.Piece(sParam,sDelim,2);
-			dr["Version"] = BMXNetLib.Piece(sParam,sDelim,3);		
-			dr["Views"] = BMXNetLib.Piece(sParam,sDelim,4);
+			dr["UserName"] = M.Piece(sParam,sDelim,1);
+			dr["Handle"] = M.Piece(sParam,sDelim,2);
+			dr["Version"] = M.Piece(sParam,sDelim,3);		
+			dr["Views"] = M.Piece(sParam,sDelim,4);
 			m_dtWSGrid.Rows.Add(dr);
 		}
@@ -2372,5 +2371,5 @@
 		private void DManagement_Closing(object sender, System.ComponentModel.CancelEventArgs e)
 		{
-			m_DocManager.ConnectInfo.UnSubscribeEvent("BSDX WORKSTATION REPORT");
+			CGDocumentManager.Current.RemoteSession.EventServices.Unsubscribe("BSDX WORKSTATION REPORT");
 		}
 
@@ -2389,5 +2388,5 @@
 				return;
 
-			this.m_DocManager.ConnectInfo.RaiseEvent("BSDX ADMIN MESSAGE", sMessage, false);
+            this.m_DocManager.RemoteSession.EventServices.TriggerEvent("BSDX ADMIN MESSAGE", sMessage, false);
 		}
 
@@ -2398,5 +2397,5 @@
 				return;
 			}
-			this.m_DocManager.ConnectInfo.RaiseEvent("BSDX ADMIN SHUTDOWN", txtSendMessage.Text, false);
+            this.m_DocManager.RemoteSession.EventServices.TriggerEvent("BSDX ADMIN SHUTDOWN", txtSendMessage.Text, false);
         }
         #endregion Workstations
Index: /Scheduling/branches/BMX4Support/Printing.cs
===================================================================
--- /Scheduling/branches/BMX4Support/Printing.cs	(revision 1193)
+++ /Scheduling/branches/BMX4Support/Printing.cs	(revision 1194)
@@ -181,5 +181,5 @@
             
             // Draw Header
-            string division = CGDocumentManager.Current.ConnectInfo.DivisionName;
+            string division = CGDocumentManager.Current.RemoteSession.User.Division.Name;
             g.DrawString(division, fBody, Brushes.Black, headerArea, sfCenterCenter);
 
@@ -591,5 +591,5 @@
 
             // Draw Header
-            string division = CGDocumentManager.Current.ConnectInfo.DivisionName;
+            string division = CGDocumentManager.Current.RemoteSession.User.Division.Name;
             g.DrawString(division, fBody, Brushes.Black, headerArea, sf0);
 
