[1194] | 1 | /* Main Class...:
|
---|
| 2 | * Original Author: Horace Whitt
|
---|
| 3 | * Current Author and Maintainer: Sam Habiel
|
---|
| 4 | * License: LGPL. http://www.gnu.org/licenses/lgpl-2.1.html
|
---|
| 5 | */
|
---|
| 6 |
|
---|
[614] | 7 | using System;
|
---|
| 8 | using System.Windows.Forms;
|
---|
| 9 | using System.Collections;
|
---|
| 10 | using System.Data;
|
---|
| 11 | using System.Diagnostics;
|
---|
[1050] | 12 | using System.Threading;
|
---|
[614] | 13 | using IndianHealthService.BMXNet;
|
---|
[1194] | 14 | using IndianHealthService.BMXNet.WinForm;
|
---|
| 15 | using IndianHealthService.BMXNet.WinForm.Configuration; //grrrr... too many namespaces here...
|
---|
[772] | 16 | using Mono.Options;
|
---|
[788] | 17 | using System.Runtime.InteropServices;
|
---|
[1112] | 18 | using System.Globalization;
|
---|
[614] | 19 |
|
---|
| 20 | namespace IndianHealthService.ClinicalScheduling
|
---|
| 21 | {
|
---|
| 22 | /// <summary>
|
---|
[1050] | 23 | /// Main Worker. Handles sub-forms.
|
---|
[614] | 24 | /// </summary>
|
---|
[1050] | 25 | public class CGDocumentManager //: System.Windows.Forms.Form
|
---|
[614] | 26 | {
|
---|
| 27 | #region Member Variables
|
---|
| 28 |
|
---|
| 29 | private static CGDocumentManager _current;
|
---|
[1050] | 30 | private Hashtable _views = new Hashtable(); //Returns the list of currently opened documents
|
---|
| 31 | private Hashtable m_AVViews = new Hashtable(); // List of currently opened CGAVViews
|
---|
[620] | 32 | private string m_sWindowText = "Clinical Scheduling"; //Default Window Text
|
---|
[1050] | 33 | private bool m_bSchedManager = false; // Do you have the XUPROGMODE or BSDXZMGR?
|
---|
| 34 | private bool m_bExitOK = true; // Okay to exit program? Used to control Re-logins. Default true.
|
---|
| 35 | public string m_sHandle = "0"; // Not Used
|
---|
[824] | 36 |
|
---|
[1050] | 37 | //Connection variables (tied to command line parameters /a /v /s /p /e)
|
---|
[772] | 38 | private string m_AccessCode="";
|
---|
| 39 | private string m_VerifyCode="";
|
---|
| 40 | private string m_Server="";
|
---|
| 41 | private int m_Port=0;
|
---|
[1050] | 42 | private string m_Encoding=""; //Encoding is "" by default;
|
---|
[614] | 43 |
|
---|
[1112] | 44 | //Globalization Object (tied to command line parameter /culture)
|
---|
| 45 | private string m_CultureName = "";
|
---|
| 46 |
|
---|
[843] | 47 | //Data Access Layer
|
---|
| 48 | private DAL _dal = null;
|
---|
| 49 |
|
---|
[614] | 50 | //M Connection member variables
|
---|
[1050] | 51 | private DataSet m_dsGlobal = null; // Holds all user data
|
---|
[614] | 52 |
|
---|
[1091] | 53 | //Custom Printing
|
---|
[1110] | 54 | private Printing m_PrintingObject = null;
|
---|
[614] | 55 | #endregion
|
---|
| 56 |
|
---|
[1050] | 57 | #region Properties
|
---|
| 58 |
|
---|
[1194] | 59 | public WinFramework WinFramework { get; private set; } // Login Manager
|
---|
| 60 | public RemoteSession RemoteSession { get; private set; } // Data Sesssion against the RPMS/VISTA server
|
---|
| 61 | public RPCLogger RPCLogger { get; private set; } // Logger for RPCs
|
---|
[1050] | 62 |
|
---|
| 63 | /// <summary>
|
---|
| 64 | /// True if the current user holds the BSDXZMGR or XUPROGMODE keys in RPMS
|
---|
| 65 | /// </summary>
|
---|
| 66 | public bool ScheduleManager
|
---|
| 67 | {
|
---|
| 68 | get
|
---|
| 69 | {
|
---|
| 70 | return m_bSchedManager;
|
---|
| 71 | }
|
---|
| 72 | }
|
---|
| 73 |
|
---|
| 74 | /// <summary>
|
---|
| 75 | /// Holds the user and division
|
---|
| 76 | /// </summary>
|
---|
| 77 | public string WindowText
|
---|
| 78 | {
|
---|
| 79 | get
|
---|
| 80 | {
|
---|
| 81 | return m_sWindowText;
|
---|
| 82 | }
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 | /// <summary>
|
---|
| 86 | /// This dataset contains tables used by the entire application
|
---|
| 87 | /// </summary>
|
---|
| 88 | public DataSet GlobalDataSet
|
---|
| 89 | {
|
---|
| 90 | get
|
---|
| 91 | {
|
---|
| 92 | return m_dsGlobal;
|
---|
| 93 | }
|
---|
| 94 | set
|
---|
| 95 | {
|
---|
| 96 | m_dsGlobal = value;
|
---|
| 97 | }
|
---|
| 98 | }
|
---|
[1111] | 99 |
|
---|
| 100 | /// <summary>
|
---|
[1112] | 101 | /// User Preferences Auto Property
|
---|
[1111] | 102 | /// </summary>
|
---|
| 103 | public UserPreferences UserPreferences { get; private set; }
|
---|
[1050] | 104 |
|
---|
| 105 | /// <summary>
|
---|
| 106 | /// Returns the single CGDocumentManager object
|
---|
| 107 | /// </summary>
|
---|
| 108 | public static CGDocumentManager Current
|
---|
| 109 | {
|
---|
| 110 | get
|
---|
| 111 | {
|
---|
| 112 | return _current;
|
---|
| 113 | }
|
---|
| 114 | }
|
---|
| 115 |
|
---|
| 116 |
|
---|
| 117 | /// <summary>
|
---|
| 118 | /// Returns the list of currently opened documents
|
---|
| 119 | /// </summary>
|
---|
| 120 | public Hashtable Views
|
---|
| 121 | {
|
---|
| 122 | get
|
---|
| 123 | {
|
---|
| 124 | return _views;
|
---|
| 125 | }
|
---|
| 126 | }
|
---|
| 127 |
|
---|
| 128 | /// <summary>
|
---|
| 129 | /// Returns the list of currently opened CGAVViews
|
---|
| 130 | /// </summary>
|
---|
| 131 | public Hashtable AvailabilityViews
|
---|
| 132 | {
|
---|
| 133 | get
|
---|
| 134 | {
|
---|
| 135 | return this.m_AVViews;
|
---|
| 136 | }
|
---|
| 137 | }
|
---|
| 138 |
|
---|
| 139 | public DAL DAL
|
---|
| 140 | {
|
---|
| 141 | get { return this._dal; }
|
---|
| 142 | }
|
---|
| 143 |
|
---|
[1110] | 144 | public Printing PrintingObject
|
---|
[1091] | 145 | {
|
---|
| 146 | get
|
---|
| 147 | {
|
---|
| 148 | return this.m_PrintingObject;
|
---|
| 149 | }
|
---|
| 150 | }
|
---|
[1050] | 151 | #endregion
|
---|
| 152 |
|
---|
| 153 | /// <summary>
|
---|
[1194] | 154 | /// Private constructor for singleton instance.
|
---|
[1050] | 155 | /// </summary>
|
---|
[1194] | 156 | private CGDocumentManager()
|
---|
[614] | 157 | {
|
---|
| 158 | }
|
---|
| 159 |
|
---|
[1050] | 160 |
|
---|
| 161 | #if DEBUG
|
---|
| 162 | //To write to the console
|
---|
| 163 | [DllImport("kernel32.dll")]
|
---|
| 164 | static extern bool AttachConsole(int dwProcessId);
|
---|
| 165 | private const int ATTACH_PARENT_PROCESS = -1;
|
---|
| 166 | #endif
|
---|
| 167 | /// <summary>
|
---|
| 168 | /// Main Entry Point
|
---|
| 169 | /// </summary>
|
---|
| 170 | /// <param name="args">We accept the following Arguments:
|
---|
| 171 | /// /s or -s = Server ip address or name
|
---|
| 172 | /// /p or -p = port number (must be numeric)
|
---|
| 173 | /// /a or -a = Access Code
|
---|
| 174 | /// /v or -v = Verify Code
|
---|
| 175 | /// /e or -e = Encoding (name of encoding as known to windows, such as windows-1256)
|
---|
[1112] | 176 | /// /culture or -culture = Culture Name for UI Culture if you wish to override the Windows Culture
|
---|
[1050] | 177 | /// </param>
|
---|
| 178 | /// <remarks>
|
---|
| 179 | /// Encoding decision is complex. This is the order of priority:
|
---|
| 180 | /// - If the M DB runs in UTF-8, that's what we are going to use.
|
---|
[1095] | 181 | /// - If that's not so, /e sets the default encoding. If /e is a non-existent encoding, move to next step.
|
---|
[1050] | 182 | /// - If /e is not supplied or is not recognized, the default encoding is the Windows default Encoding for the user.
|
---|
| 183 | /// </remarks>
|
---|
| 184 | [STAThread()]
|
---|
| 185 | static void Main(string[] args)
|
---|
| 186 | {
|
---|
[1122] | 187 | //Application wide error handler for unhandled errors (later I figure out that's only for WinForm ex'es)
|
---|
| 188 | Application.SetUnhandledExceptionMode(UnhandledExceptionMode.ThrowException);
|
---|
| 189 | Application.ThreadException += new ThreadExceptionEventHandler(App_ThreadException);
|
---|
| 190 |
|
---|
| 191 | // Add the event handler for handling non-UI thread exceptions to the event.
|
---|
| 192 | AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(App_DomainException);
|
---|
| 193 |
|
---|
[1050] | 194 | #if DEBUG
|
---|
| 195 | // Print console messages to console if launched from console
|
---|
| 196 | // Note: Imported From kernel32.dll
|
---|
| 197 | AttachConsole(ATTACH_PARENT_PROCESS);
|
---|
| 198 | #endif
|
---|
[1065] | 199 |
|
---|
| 200 | #if TRACE
|
---|
| 201 | DateTime startLoadTime = DateTime.Now;
|
---|
| 202 | #endif
|
---|
| 203 |
|
---|
[1050] | 204 | //Store a class instance of manager. Actual constructor does nothing.
|
---|
| 205 | _current = new CGDocumentManager();
|
---|
| 206 |
|
---|
[1071] | 207 | //Get command line options; store in private class wide variables
|
---|
[1050] | 208 | var opset = new OptionSet() {
|
---|
| 209 | { "s=", s => _current.m_Server = s },
|
---|
| 210 | { "p=", p => _current.m_Port = int.Parse(p) },
|
---|
| 211 | { "a=", a => _current.m_AccessCode = a },
|
---|
| 212 | { "v=", v => _current.m_VerifyCode = v },
|
---|
[1112] | 213 | { "e=", e => _current.m_Encoding = e},
|
---|
| 214 | { "culture=", culture => _current.m_CultureName = culture }
|
---|
[1050] | 215 | };
|
---|
| 216 |
|
---|
| 217 | opset.Parse(args);
|
---|
| 218 |
|
---|
[1197] | 219 | //Init app. Catch Login Exceptions if they happen.
|
---|
| 220 | bool isEverythingOkay = false;
|
---|
| 221 | try
|
---|
| 222 | {
|
---|
| 223 | isEverythingOkay = _current.InitializeApp();
|
---|
| 224 | }
|
---|
| 225 | catch (Exception ex)
|
---|
| 226 | {
|
---|
[1050] | 227 |
|
---|
[1197] | 228 | MessageBox.Show("Booboo: An Error Happened: " + ex.Message);
|
---|
| 229 | return; // exit application
|
---|
| 230 | }
|
---|
| 231 |
|
---|
| 232 |
|
---|
| 233 | //if something yucky happened, break out.
|
---|
[1051] | 234 | if (!isEverythingOkay) return;
|
---|
| 235 |
|
---|
[1050] | 236 | //Create the first empty document
|
---|
[1071] | 237 | //A document holds the resources, appointments, and availabilites
|
---|
[1070] | 238 | //SAM: Good place for break point
|
---|
[1050] | 239 | CGDocument doc = new CGDocument();
|
---|
| 240 | doc.DocManager = _current;
|
---|
[1071] | 241 |
|
---|
| 242 | //Create new View
|
---|
| 243 | //A view is a specific arrangement of appointments and availabilites that constitute a document
|
---|
| 244 | CGView view = new CGView();
|
---|
[1073] | 245 | view.InitializeDocView(doc, _current, doc.StartDate, _current.WindowText);
|
---|
[1071] | 246 |
|
---|
[1197] | 247 | //Handle Message Queue
|
---|
[1050] | 248 | Application.DoEvents();
|
---|
[1071] | 249 |
|
---|
[1122] | 250 | //test
|
---|
| 251 | //doc.ThrowException();
|
---|
| 252 | //test
|
---|
[1071] | 253 |
|
---|
[1065] | 254 | #if TRACE
|
---|
| 255 | DateTime EndLoadTime = DateTime.Now;
|
---|
| 256 | TimeSpan LoadTime = EndLoadTime - startLoadTime;
|
---|
| 257 | Debug.Write("Load Time for GUI is " + LoadTime.Seconds + " s & " + LoadTime.Milliseconds + " ms\n");
|
---|
| 258 | #endif
|
---|
[1071] | 259 |
|
---|
| 260 | view.Show();
|
---|
| 261 | view.Activate();
|
---|
| 262 |
|
---|
[1050] | 263 | Application.Run();
|
---|
| 264 | }
|
---|
| 265 |
|
---|
[1065] | 266 | /// <summary>
|
---|
[1122] | 267 | /// Exception handler for application errors. Only for WinForm Errors.
|
---|
[1065] | 268 | /// </summary>
|
---|
[1122] | 269 | /// <remarks>Never tested. I can't get an error to go here!</remarks>
|
---|
[1065] | 270 | /// <param name="sender"></param>
|
---|
| 271 | /// <param name="e"></param>
|
---|
| 272 | static void App_ThreadException(object sender, ThreadExceptionEventArgs e)
|
---|
| 273 | {
|
---|
| 274 | string msg = "A problem has occured in this applicaton. \r\n\r\n" +
|
---|
| 275 | "\t" + e.Exception.Message + "\r\n\r\n" +
|
---|
| 276 | "Would you like to continue the application?";
|
---|
| 277 |
|
---|
| 278 | DialogResult res = MessageBox.Show(msg, "Unexpected Error", MessageBoxButtons.YesNo);
|
---|
| 279 |
|
---|
| 280 | if (res == DialogResult.Yes) return;
|
---|
| 281 | else Application.Exit();
|
---|
| 282 | }
|
---|
| 283 |
|
---|
[1122] | 284 | /// <summary>
|
---|
| 285 | /// If we are here, we are dead meat.
|
---|
| 286 | /// </summary>
|
---|
| 287 | /// <param name="sender"></param>
|
---|
| 288 | /// <param name="e"></param>
|
---|
| 289 | static void App_DomainException(object sender, UnhandledExceptionEventArgs e)
|
---|
| 290 | {
|
---|
| 291 | if (e.ExceptionObject is System.Net.Sockets.SocketException)
|
---|
| 292 | {
|
---|
| 293 | MessageBox.Show("Looks like we lost our connection with the server\nClick OK to terminate the application.");
|
---|
| 294 | }
|
---|
| 295 | else
|
---|
| 296 | {
|
---|
| 297 | Exception ex = e.ExceptionObject as Exception;
|
---|
[1065] | 298 |
|
---|
[1122] | 299 | string msg = "A problem has occured in this applicaton. \r\n\r\n" +
|
---|
| 300 | "\t" + ex.InnerException.Message;
|
---|
| 301 |
|
---|
| 302 | MessageBox.Show(msg, "Unexpected Error");
|
---|
| 303 | }
|
---|
| 304 | }// here application terminates
|
---|
| 305 |
|
---|
[614] | 306 | #region BMXNet Event Handler
|
---|
[1194] | 307 | private void CDocMgrEventHandler(Object obj, RemoteEventArgs e)
|
---|
[614] | 308 | {
|
---|
[1194] | 309 | if (e.EventType == "BSDX CALL WORKSTATIONS")
|
---|
[614] | 310 | {
|
---|
| 311 | string sParam = "";
|
---|
| 312 | string sDelim="~";
|
---|
[1194] | 313 | sParam += this.RemoteSession.User.Name + sDelim;
|
---|
[614] | 314 | sParam += this.m_sHandle + sDelim;
|
---|
| 315 | sParam += Application.ProductVersion + sDelim;
|
---|
| 316 | sParam += this._views.Count.ToString();
|
---|
[1194] | 317 | _current.RemoteSession.EventServices.TriggerEvent("BSDX WORKSTATION REPORT", sParam, true);
|
---|
[614] | 318 | }
|
---|
[1194] | 319 | if (e.EventType == "BSDX ADMIN MESSAGE")
|
---|
[614] | 320 | {
|
---|
[1194] | 321 | string sMsg = e.EventType;
|
---|
[614] | 322 | ShowAdminMsgDelegate samd = new ShowAdminMsgDelegate(ShowAdminMsg);
|
---|
[1050] | 323 | samd.Invoke(sMsg);
|
---|
[614] | 324 | }
|
---|
[1194] | 325 | if (e.EventType == "BSDX ADMIN SHUTDOWN")
|
---|
[614] | 326 | {
|
---|
[1194] | 327 | string sMsg = e.Details;
|
---|
[614] | 328 | CloseAllDelegate cad = new CloseAllDelegate(CloseAll);
|
---|
[1050] | 329 | cad.Invoke(sMsg);
|
---|
[614] | 330 | }
|
---|
| 331 | }
|
---|
| 332 |
|
---|
| 333 | delegate void ShowAdminMsgDelegate(string sMsg);
|
---|
| 334 |
|
---|
| 335 | private void ShowAdminMsg(string sMsg)
|
---|
| 336 | {
|
---|
| 337 | MessageBox.Show(sMsg, "Message from Scheduling Administrator", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
---|
| 338 | }
|
---|
| 339 |
|
---|
| 340 | #endregion BMXNet Event Handler
|
---|
| 341 |
|
---|
| 342 |
|
---|
| 343 | #region Methods & Events
|
---|
| 344 |
|
---|
[1050] | 345 | /// <summary>
|
---|
| 346 | /// See InitializeApp(bool) below
|
---|
| 347 | /// </summary>
|
---|
[1051] | 348 | private bool InitializeApp()
|
---|
[614] | 349 | {
|
---|
[1051] | 350 | return InitializeApp(false);
|
---|
[614] | 351 | }
|
---|
| 352 |
|
---|
[1050] | 353 | /// <summary>
|
---|
| 354 | /// Does a million things:
|
---|
| 355 | /// 1. Starts Connection and displays log-in dialogs
|
---|
| 356 | /// 2. Starts Splash screen
|
---|
| 357 | /// 3. Loads data tables
|
---|
| 358 | /// </summary>
|
---|
| 359 | /// <param name="bReLogin">Is the User logging in again from a currently running instance?
|
---|
| 360 | /// If so, display a dialog to collect access and verify codes.</param>
|
---|
[1051] | 361 | private bool InitializeApp(bool bReLogin)
|
---|
[614] | 362 | {
|
---|
[1194] | 363 | //Note: There are 2 splashes -- one for being the parent of the log in forms
|
---|
| 364 | // the next is invoked async and updated async while the GUI is loading
|
---|
| 365 | // The reason is b/c an async form cannot be the parent of another that lies on the main thread
|
---|
| 366 |
|
---|
| 367 | RPCLogger = new RPCLogger();
|
---|
| 368 |
|
---|
| 369 | DSplash firstSplash = new DSplash();
|
---|
| 370 |
|
---|
| 371 | firstSplash.Show();
|
---|
[1050] | 372 |
|
---|
[1194] | 373 | /* IMPORTANT NOTE
|
---|
| 374 | * LOGIN CODE IS COPIED ALMOST VERBATIM FROM THE SCHEMABUILDER APPLICAITON;
|
---|
| 375 | * THE ONLY ONE I CAN FIND WHICH RELIES ON BMX 4 NEW WAYS WHICH I CAN'T FIGURE OUT
|
---|
| 376 | */
|
---|
| 377 | LoginProcess login;
|
---|
| 378 | this.WinFramework = WinFramework.CreateWithNetworkBroker(true, RPCLogger);
|
---|
| 379 |
|
---|
| 380 | if (bReLogin) // if logging in again...
|
---|
| 381 | {
|
---|
| 382 | this.WinFramework.LoadConnectionSpecs(LocalPersistentStore.CreateDefaultStorage(true), "BSDX");
|
---|
| 383 | login = this.WinFramework.CreateLoginProcess();
|
---|
| 384 | login.AttemptUserInputLogin("Clincal Scheduling Log-in", 3, true, firstSplash);
|
---|
| 385 | goto DoneTrying;
|
---|
| 386 | }
|
---|
| 387 |
|
---|
| 388 | // If server,port,ac,vc are supplied on command line, then try to connect...
|
---|
| 389 | else if (!String.IsNullOrEmpty(m_Server) && m_Port != 0 && !String.IsNullOrEmpty(m_AccessCode) && !String.IsNullOrEmpty(m_VerifyCode))
|
---|
| 390 | {
|
---|
| 391 | RpmsConnectionSpec spec = new RpmsConnectionSpec();
|
---|
| 392 | spec.IsDefault = true;
|
---|
| 393 | spec.Name = "Command Line Server";
|
---|
| 394 | spec.Port = m_Port;
|
---|
| 395 | spec.Server = m_Server;
|
---|
| 396 | spec.UseWindowsAuthentication = false; //for now
|
---|
| 397 | spec.UseDefaultNamespace = true; //for now
|
---|
| 398 | login = this.WinFramework.CreateLoginProcess();
|
---|
| 399 | login.AutoSetDivisionToLastLookup = false;
|
---|
| 400 | login.AttemptAccessVerifyLogin(spec, m_AccessCode, m_VerifyCode);
|
---|
| 401 | goto DoneTrying;
|
---|
| 402 | }
|
---|
| 403 |
|
---|
| 404 | // if only server, port is supplied, then use these instead
|
---|
| 405 | else if (!String.IsNullOrEmpty(m_Server) && m_Port != 0)
|
---|
| 406 | {
|
---|
| 407 | RpmsConnectionSpec spec = new RpmsConnectionSpec();
|
---|
| 408 | spec.IsDefault = true;
|
---|
| 409 | spec.Name = "Command Line Server";
|
---|
| 410 | spec.Port = m_Port;
|
---|
| 411 | spec.Server = m_Server;
|
---|
| 412 | spec.UseWindowsAuthentication = false; //for now
|
---|
| 413 | spec.UseDefaultNamespace = true; //for now
|
---|
| 414 |
|
---|
| 415 | RpmsConnectionSettings cxnSettings = new RpmsConnectionSettings
|
---|
| 416 | {
|
---|
| 417 | CommandLineConnectionSpec = spec
|
---|
| 418 | };
|
---|
| 419 |
|
---|
| 420 | this.WinFramework.ConnectionSettings = cxnSettings;
|
---|
| 421 |
|
---|
| 422 | login = this.WinFramework.CreateLoginProcess();
|
---|
| 423 | login.AutoSetDivisionToLastLookup = false;
|
---|
[1197] | 424 | //test
|
---|
| 425 | //spec.UseWindowsAuthentication = true;
|
---|
[1194] | 426 | login.AttemptUserInputLogin("Clinical Scheduling Log-in", 3, false, firstSplash);
|
---|
[1197] | 427 | //login.AttemptWindowsAuthLogin();
|
---|
| 428 | //test
|
---|
[1194] | 429 | goto DoneTrying;
|
---|
| 430 | }
|
---|
| 431 |
|
---|
| 432 | // if nothing is supplied, fall back on the original dialog
|
---|
| 433 | else
|
---|
| 434 | {
|
---|
| 435 | this.WinFramework.LoadConnectionSpecs(LocalPersistentStore.CreateDefaultStorage(true), "BSDX");
|
---|
| 436 | login = this.WinFramework.CreateLoginProcess();
|
---|
| 437 | login.AutoSetDivisionToLastLookup = false;
|
---|
| 438 | login.AttemptUserInputLogin("Clincal Scheduling Log-in", 3, true, firstSplash);
|
---|
| 439 |
|
---|
| 440 | goto DoneTrying;
|
---|
| 441 | }
|
---|
| 442 |
|
---|
| 443 | DoneTrying:
|
---|
| 444 | if (!login.WasSuccessful)
|
---|
| 445 | {
|
---|
| 446 | return false;
|
---|
| 447 | }
|
---|
| 448 |
|
---|
| 449 | LocalSession local = this.WinFramework.LocalSession;
|
---|
| 450 |
|
---|
| 451 | if ((this.WinFramework.Context.User.Division == null) && !this.WinFramework.AttemptUserInputSetDivision("Set Initial Division", firstSplash))
|
---|
| 452 | {
|
---|
| 453 | return false;
|
---|
| 454 | }
|
---|
| 455 |
|
---|
| 456 |
|
---|
| 457 |
|
---|
| 458 | this.RemoteSession = this.WinFramework.PrimaryRemoteSession;
|
---|
| 459 |
|
---|
[1050] | 460 | //Tie delegate to Events generated by BMX.
|
---|
[1194] | 461 | this.RemoteSession.EventServices.RpmsEvent += this.CDocMgrEventHandler;
|
---|
| 462 | //Disable polling
|
---|
| 463 | this.RemoteSession.EventServices.IsEventPollingEnabled = false;
|
---|
[824] | 464 |
|
---|
[1194] | 465 | //Second splash screens
|
---|
[1051] | 466 | //Show a splash screen while initializing; define delegates to remote thread
|
---|
[1194] | 467 | DSplash secondSplash = new DSplash();
|
---|
| 468 | DSplash.dSetStatus setStatusDelegate = new DSplash.dSetStatus(secondSplash.SetStatus);
|
---|
| 469 | DSplash.dAny closeSplashDelegate = new DSplash.dAny(secondSplash.RemoteClose);
|
---|
| 470 | DSplash.dProgressBarSet setMaxProgressDelegate = new DSplash.dProgressBarSet(secondSplash.RemoteProgressBarMaxSet);
|
---|
| 471 | DSplash.dProgressBarSet setProgressDelegate = new DSplash.dProgressBarSet(secondSplash.RemoteProgressBarValueSet);
|
---|
[794] | 472 |
|
---|
[1051] | 473 | //Start new thread for the Splash screen.
|
---|
[1070] | 474 | Thread threadSplash = new Thread(new ParameterizedThreadStart(frm => ((DSplash)frm).ShowDialog()));
|
---|
[1051] | 475 | threadSplash.IsBackground = true; //expendable thread -- exit even if still running.
|
---|
| 476 | threadSplash.Name = "Splash Thread";
|
---|
[1194] | 477 | threadSplash.Start(secondSplash);
|
---|
[794] | 478 |
|
---|
[1194] | 479 | firstSplash.Close(); // close temporary splash now that the new one is up and running
|
---|
| 480 |
|
---|
[1117] | 481 | //There are 21 steps to load the application. That's max for the progress bar.
|
---|
| 482 | setMaxProgressDelegate(21);
|
---|
[1194] | 483 |
|
---|
[1051] | 484 | // smh--not used: System.Configuration.ConfigurationManager.GetSection("appSettings");
|
---|
[1050] | 485 | setStatusDelegate("Connecting to VISTA");
|
---|
[1194] | 486 |
|
---|
[1051] | 487 |
|
---|
[1194] | 488 | /*
|
---|
[1050] | 489 | //Try to connect using supplied values for Server and Port
|
---|
| 490 | //Why am I doing this? The library BMX net uses prompts for access and verify code
|
---|
| 491 | //whether you can connect or not. Not good. So I test first whether
|
---|
| 492 | //we can connect at all by doing a simple connection and disconnect.
|
---|
[1051] | 493 | //TODO: Make this more robust by sending a TCPConnect message and seeing if you get a response
|
---|
[1050] | 494 | if (m_Server != "" && m_Port != 0)
|
---|
| 495 | {
|
---|
| 496 | System.Net.Sockets.TcpClient tcpClient = new System.Net.Sockets.TcpClient();
|
---|
| 497 | try
|
---|
[794] | 498 | {
|
---|
[1050] | 499 | tcpClient.Connect(m_Server, m_Port); // open it
|
---|
| 500 | tcpClient.Close(); // then close it
|
---|
| 501 | }
|
---|
[1051] | 502 | catch (System.Net.Sockets.SocketException)
|
---|
[1050] | 503 | {
|
---|
[1143] | 504 | m_ds.RemoteMsgBox("Can't connect to server! Network Error");
|
---|
[1051] | 505 | return false;
|
---|
[1050] | 506 | }
|
---|
| 507 | }
|
---|
| 508 |
|
---|
[1062] | 509 |
|
---|
| 510 | bool bRetry = true;
|
---|
| 511 |
|
---|
[1051] | 512 | // Do block is Log-in logic
|
---|
| 513 | do
|
---|
[1050] | 514 | {
|
---|
| 515 | // login crap
|
---|
| 516 | try
|
---|
| 517 | {
|
---|
| 518 | // Not my code
|
---|
| 519 | if (bReLogin == true)
|
---|
[794] | 520 | {
|
---|
[1050] | 521 | //Prompt for Access and Verify codes
|
---|
| 522 | _current.m_ConnectInfo.LoadConnectInfo("", "");
|
---|
[794] | 523 | }
|
---|
[1050] | 524 | // My code -- buts looks so ugly!
|
---|
[1071] | 525 | // Checks the passed parameters stored in the class variables
|
---|
[1050] | 526 | else
|
---|
[794] | 527 | {
|
---|
[1050] | 528 | if (m_Server != String.Empty && m_Port != 0 && m_AccessCode != String.Empty
|
---|
| 529 | && m_VerifyCode != String.Empty)
|
---|
[794] | 530 | {
|
---|
[1050] | 531 | m_ConnectInfo.LoadConnectInfo(m_Server, m_Port, m_AccessCode, m_VerifyCode);
|
---|
[794] | 532 | }
|
---|
[1050] | 533 | else if (m_Server != String.Empty && m_Port != 0)
|
---|
| 534 | m_ConnectInfo.LoadConnectInfo(m_Server, m_Port, "", "");
|
---|
[794] | 535 | else
|
---|
[1050] | 536 | m_ConnectInfo.LoadConnectInfo();
|
---|
[794] | 537 | }
|
---|
[1050] | 538 | bRetry = false;
|
---|
| 539 | }
|
---|
| 540 | catch (System.Net.Sockets.SocketException)
|
---|
| 541 | {
|
---|
[1143] | 542 | m_ds.RemoteMsgBox("Cannot connect to VistA. Network Error");
|
---|
[1050] | 543 | }
|
---|
[1051] | 544 | catch (BMXNetException ex)
|
---|
[1050] | 545 | {
|
---|
[1143] | 546 | if (m_ds.RemoteMsgBox("Unable to connect to VistA. " + ex.Message, "Clinical Scheduling", MessageBoxButtons.RetryCancel) == DialogResult.Retry)
|
---|
[794] | 547 | {
|
---|
[1050] | 548 | bRetry = true;
|
---|
[1106] | 549 | //I hate this, but this is how the library is designed. It throws an error if the user cancels. XXX: Won't fix library until BMX 4.0 port.
|
---|
| 550 | try { _current.m_ConnectInfo.ChangeServerInfo(); }
|
---|
| 551 | catch (Exception)
|
---|
| 552 | {
|
---|
| 553 | closeSplashDelegate();
|
---|
| 554 | bRetry = false;
|
---|
| 555 | return false; //tell main that it's a no go.
|
---|
| 556 | }
|
---|
[794] | 557 | }
|
---|
[1050] | 558 | else
|
---|
[794] | 559 | {
|
---|
[1050] | 560 | closeSplashDelegate();
|
---|
| 561 | bRetry = false;
|
---|
[1051] | 562 | return false; //tell main that it's a no go.
|
---|
[794] | 563 | }
|
---|
[1050] | 564 | }
|
---|
| 565 | }while (bRetry == true);
|
---|
[1194] | 566 | */
|
---|
[1091] | 567 |
|
---|
[1194] | 568 | //Printing Custom DLL. Perfect place for code injection!!!
|
---|
| 569 | //*************************************************
|
---|
[1098] | 570 | string DllLocation = string.Empty;
|
---|
[1091] | 571 | System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(Application.StartupPath + @"\Printing\");
|
---|
[1098] | 572 | if (di.Exists)
|
---|
[1091] | 573 | {
|
---|
[1098] | 574 | System.IO.FileInfo[] rgFiles = di.GetFiles("*.dll");
|
---|
| 575 |
|
---|
| 576 | foreach (System.IO.FileInfo fi in rgFiles)
|
---|
| 577 | {
|
---|
| 578 | DllLocation = fi.FullName;
|
---|
| 579 | }
|
---|
[1091] | 580 | }
|
---|
| 581 |
|
---|
| 582 | PrintingCreator Creator = null;
|
---|
| 583 | if (DllLocation == string.Empty)
|
---|
| 584 | {
|
---|
[1110] | 585 | this.m_PrintingObject = new Printing();
|
---|
[1091] | 586 | }
|
---|
| 587 | else
|
---|
| 588 | {
|
---|
| 589 | System.Reflection.Assembly assembly = System.Reflection.Assembly.LoadFrom(DllLocation);
|
---|
| 590 | foreach (Type type in assembly.GetTypes())
|
---|
| 591 | {
|
---|
| 592 | if (type.IsClass == true & type.BaseType == typeof(PrintingCreator))
|
---|
| 593 | {
|
---|
| 594 | Creator = (PrintingCreator)Activator.CreateInstance(type);
|
---|
| 595 | break;
|
---|
| 596 | }
|
---|
| 597 | }
|
---|
| 598 | this.m_PrintingObject = Creator.PrintFactory();
|
---|
| 599 | }
|
---|
[1194] | 600 | //************************************************
|
---|
[1117] | 601 |
|
---|
[1112] | 602 | //User Interface Culture (m_CultureName is set from the command line flag /culture)
|
---|
[1131] | 603 | //
|
---|
| 604 | //If passed, set that try that culture; fail over to Invariant Culture
|
---|
| 605 | if (m_CultureName != String.Empty)
|
---|
| 606 | {
|
---|
| 607 | try { Thread.CurrentThread.CurrentUICulture = new CultureInfo(m_CultureName); }
|
---|
| 608 | catch (CultureNotFoundException) { Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture; }
|
---|
| 609 | }
|
---|
| 610 | //otherwise, use the Current Computer Culture, EVEN IF (!!) the UI Culture is different.
|
---|
| 611 | //this allows localization even if Windows still displays messages in English.
|
---|
| 612 | else
|
---|
| 613 | {
|
---|
| 614 | Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture;
|
---|
| 615 | }
|
---|
[1112] | 616 |
|
---|
[1194] | 617 | _dal = new DAL(RemoteSession); // Data access layer
|
---|
| 618 |
|
---|
[1050] | 619 | //Create global dataset
|
---|
| 620 | _current.m_dsGlobal = new DataSet("GlobalDataSet");
|
---|
[614] | 621 |
|
---|
[1050] | 622 | //Version info
|
---|
[1051] | 623 | // Table #1
|
---|
| 624 | setProgressDelegate(1);
|
---|
[1050] | 625 | setStatusDelegate("Getting Version Info from Server...");
|
---|
[614] | 626 |
|
---|
[1050] | 627 | DataTable ver = _dal.GetVersion("BSDX");
|
---|
| 628 | ver.TableName = "VersionInfo";
|
---|
| 629 | m_dsGlobal.Tables.Add(ver);
|
---|
[1039] | 630 |
|
---|
[1050] | 631 | //How to extract the version numbers:
|
---|
| 632 | DataTable dtVersion = m_dsGlobal.Tables["VersionInfo"];
|
---|
| 633 | Debug.Assert(dtVersion.Rows.Count == 1);
|
---|
| 634 | DataRow rVersion = dtVersion.Rows[0];
|
---|
| 635 | string sMajor = rVersion["MAJOR_VERSION"].ToString();
|
---|
| 636 | string sMinor = rVersion["MINOR_VERSION"].ToString();
|
---|
| 637 | string sBuild = rVersion["BUILD"].ToString();
|
---|
| 638 | decimal fBuild = Convert.ToDecimal(sBuild);
|
---|
[614] | 639 |
|
---|
[1050] | 640 | //Make sure that the server is running the same version the client is.
|
---|
| 641 | Version x = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
|
---|
[1039] | 642 |
|
---|
[1050] | 643 | //if version numbers mismatch, don't continue.
|
---|
[1121] | 644 | if (!(x.Major.ToString() == sMajor && x.Minor.ToString() == sMinor))
|
---|
[1050] | 645 | {
|
---|
| 646 | MessageBox.Show(
|
---|
| 647 | "Server runs version " + sMajor + "." + sMinor + "\r\n" +
|
---|
| 648 | "You are running " + x.ToString() + "\r\n\r\n" +
|
---|
| 649 | "Major, Minor and Build versions must match",
|
---|
| 650 | "Version Mismatch");
|
---|
[1121] | 651 | closeSplashDelegate();
|
---|
| 652 | return false;
|
---|
[1050] | 653 | }
|
---|
[1039] | 654 |
|
---|
| 655 |
|
---|
[1050] | 656 | //Change encoding
|
---|
[1051] | 657 | // Call #2
|
---|
| 658 | setProgressDelegate(2);
|
---|
[1050] | 659 | setStatusDelegate("Setting encoding...");
|
---|
[1194] | 660 | //PORT TODO: Set encoding
|
---|
[1050] | 661 | if (m_Encoding == String.Empty)
|
---|
| 662 | {
|
---|
[1194] | 663 | string utf8_server_support = RemoteSession.TransmitRPC("BMX UTF-8", "");
|
---|
| 664 |
|
---|
[1050] | 665 | if (utf8_server_support == "1")
|
---|
[1194] | 666 | RemoteSession.ConnectionEncoding = System.Text.UTF8Encoding.UTF8;
|
---|
| 667 |
|
---|
[1050] | 668 | }
|
---|
[1051] | 669 |
|
---|
| 670 | //Set application context
|
---|
| 671 | // Call #3
|
---|
| 672 | setProgressDelegate(3);
|
---|
[1050] | 673 | setStatusDelegate("Setting Application Context to BSDXRPC...");
|
---|
[1194] | 674 | RemoteSession.AppContext = "BSDXRPC";
|
---|
[1117] | 675 |
|
---|
| 676 | //User Preferences Object
|
---|
| 677 | setProgressDelegate(4); //next number is 6 b/c two calls
|
---|
| 678 | setStatusDelegate("Getting User Preferences from the Server...");
|
---|
| 679 |
|
---|
[1194] | 680 | _current.UserPreferences = new UserPreferences(); // Constructor Does the calling to do that...
|
---|
[1117] | 681 |
|
---|
| 682 | //Load global recordsets
|
---|
[1050] | 683 | string statusConst = "Loading VistA data tables...";
|
---|
| 684 | setStatusDelegate(statusConst);
|
---|
[614] | 685 |
|
---|
[1050] | 686 | string sCommandText;
|
---|
[614] | 687 |
|
---|
[1051] | 688 | //Schedule User Info
|
---|
| 689 | // Table #4
|
---|
[1117] | 690 | setProgressDelegate(6);
|
---|
[1050] | 691 | setStatusDelegate(statusConst + " Schedule User");
|
---|
[1194] | 692 | DataTable dtUser = _dal.GetUserInfo(RemoteSession.User.Duz);
|
---|
[1050] | 693 | dtUser.TableName = "SchedulingUser";
|
---|
| 694 | m_dsGlobal.Tables.Add(dtUser);
|
---|
| 695 | Debug.Assert(dtUser.Rows.Count == 1);
|
---|
[614] | 696 |
|
---|
[1050] | 697 | // Only one row and one column named "MANAGER". Set local var m_bSchedManager to true if Manager.
|
---|
| 698 | DataRow rUser = dtUser.Rows[0];
|
---|
| 699 | Object oUser = rUser["MANAGER"];
|
---|
| 700 | string sUser = oUser.ToString();
|
---|
| 701 | m_bSchedManager = (sUser == "YES") ? true : false;
|
---|
[614] | 702 |
|
---|
[1051] | 703 | //Get Access Types
|
---|
| 704 | // Table #5
|
---|
[1117] | 705 | setProgressDelegate(7);
|
---|
[1050] | 706 | setStatusDelegate(statusConst + " Access Types");
|
---|
[1194] | 707 | DataTable dtAccessTypes = _dal.GetAccessTypes(m_dsGlobal, "AccessTypes");
|
---|
[614] | 708 |
|
---|
[1051] | 709 | //Get Access Groups
|
---|
| 710 | // Table #6
|
---|
[1117] | 711 | setProgressDelegate(8);
|
---|
[1050] | 712 | setStatusDelegate(statusConst + " Access Groups");
|
---|
| 713 | LoadAccessGroupsTable();
|
---|
[788] | 714 |
|
---|
[1050] | 715 | //Build Primary Key for AccessGroup table
|
---|
| 716 | DataTable dtGroups = m_dsGlobal.Tables["AccessGroup"];
|
---|
| 717 | DataColumn dcKey = dtGroups.Columns["ACCESS_GROUP"];
|
---|
| 718 | DataColumn[] dcKeys = new DataColumn[1];
|
---|
| 719 | dcKeys[0] = dcKey;
|
---|
| 720 | dtGroups.PrimaryKey = dcKeys;
|
---|
| 721 |
|
---|
[1062] | 722 | //Get Access Group Types (Combines Access Types and Groups)
|
---|
| 723 | //Optimization Note: Can eliminate Access type and Access Group Table
|
---|
| 724 | // But they are heavily referenced throughout the code.
|
---|
[1051] | 725 | // Table #7
|
---|
[1117] | 726 | setProgressDelegate(9);
|
---|
[1050] | 727 | setStatusDelegate(statusConst + " Access Group Types");
|
---|
| 728 | LoadAccessGroupTypesTable();
|
---|
| 729 |
|
---|
| 730 | //Build Primary Key for AccessGroupType table
|
---|
| 731 | DataTable dtAGTypes = m_dsGlobal.Tables["AccessGroupType"];
|
---|
| 732 | DataColumn dcGTKey = dtAGTypes.Columns["ACCESS_GROUP_TYPEID"];
|
---|
| 733 | DataColumn[] dcGTKeys = new DataColumn[1];
|
---|
| 734 | dcGTKeys[0] = dcGTKey;
|
---|
| 735 | dtAGTypes.PrimaryKey = dcGTKeys;
|
---|
| 736 |
|
---|
| 737 | //Build Data Relationship between AccessGroupType and AccessTypes tables
|
---|
| 738 | DataRelation dr = new DataRelation("AccessGroupType", //Relation Name
|
---|
| 739 | m_dsGlobal.Tables["AccessGroup"].Columns["BMXIEN"], //Parent
|
---|
| 740 | m_dsGlobal.Tables["AccessGroupType"].Columns["ACCESS_GROUP_ID"]); //Child
|
---|
| 741 | m_dsGlobal.Relations.Add(dr);
|
---|
| 742 |
|
---|
[1051] | 743 | //ResourceGroup Table (Resource Groups by User)
|
---|
| 744 | // Table #8
|
---|
[1062] | 745 | // What shows up on the tree. The groups the user has access to.
|
---|
[1117] | 746 | setProgressDelegate(10);
|
---|
[1050] | 747 | setStatusDelegate(statusConst + " Resource Groups By User");
|
---|
| 748 | LoadResourceGroupTable();
|
---|
| 749 |
|
---|
[1051] | 750 | //Resources by user
|
---|
| 751 | // Table #9
|
---|
[1062] | 752 | // Individual Resources
|
---|
[1117] | 753 | setProgressDelegate(11);
|
---|
[1050] | 754 | setStatusDelegate(statusConst + " Resources By User");
|
---|
| 755 | LoadBSDXResourcesTable();
|
---|
| 756 |
|
---|
| 757 | //Build Primary Key for Resources table
|
---|
| 758 | DataColumn[] dc = new DataColumn[1];
|
---|
| 759 | dc[0] = m_dsGlobal.Tables["Resources"].Columns["RESOURCEID"];
|
---|
| 760 | m_dsGlobal.Tables["Resources"].PrimaryKey = dc;
|
---|
| 761 |
|
---|
[1051] | 762 | //GroupResources table
|
---|
| 763 | // Table #10
|
---|
[1062] | 764 | // Resource Groups and Indivdual Resources together
|
---|
[1117] | 765 | setProgressDelegate(12);
|
---|
[1050] | 766 | setStatusDelegate(statusConst + " Group Resources");
|
---|
| 767 | LoadGroupResourcesTable();
|
---|
| 768 |
|
---|
| 769 | //Build Primary Key for ResourceGroup table
|
---|
| 770 | dc = new DataColumn[1];
|
---|
| 771 | dc[0] = m_dsGlobal.Tables["ResourceGroup"].Columns["RESOURCE_GROUP"];
|
---|
| 772 | m_dsGlobal.Tables["ResourceGroup"].PrimaryKey = dc;
|
---|
| 773 |
|
---|
| 774 | //Build Data Relationships between ResourceGroup and GroupResources tables
|
---|
| 775 | dr = new DataRelation("GroupResource", //Relation Name
|
---|
| 776 | m_dsGlobal.Tables["ResourceGroup"].Columns["RESOURCE_GROUP"], //Parent
|
---|
| 777 | m_dsGlobal.Tables["GroupResources"].Columns["RESOURCE_GROUP"]); //Child
|
---|
[1095] | 778 |
|
---|
[1050] | 779 | m_dsGlobal.Relations.Add(dr);
|
---|
| 780 |
|
---|
[1051] | 781 | //HospitalLocation table
|
---|
| 782 | //Table #11
|
---|
[1117] | 783 | setProgressDelegate(13);
|
---|
[1050] | 784 | setStatusDelegate(statusConst + " Clinics");
|
---|
| 785 | //cmd.CommandText = "SELECT BMXIEN 'HOSPITAL_LOCATION_ID', NAME 'HOSPITAL_LOCATION', DEFAULT_PROVIDER, STOP_CODE_NUMBER, INACTIVATE_DATE, REACTIVATE_DATE FROM HOSPITAL_LOCATION";
|
---|
| 786 | sCommandText = "BSDX HOSPITAL LOCATION";
|
---|
[1194] | 787 | RemoteSession.TableFromCommand(sCommandText, m_dsGlobal, "HospitalLocation");
|
---|
[1050] | 788 | Debug.Write("LoadGlobalRecordsets -- HospitalLocation loaded\n");
|
---|
| 789 |
|
---|
| 790 | //Build Primary Key for HospitalLocation table
|
---|
| 791 | dc = new DataColumn[1];
|
---|
| 792 | DataTable dtTemp = m_dsGlobal.Tables["HospitalLocation"];
|
---|
| 793 | dc[0] = dtTemp.Columns["HOSPITAL_LOCATION_ID"];
|
---|
| 794 | m_dsGlobal.Tables["HospitalLocation"].PrimaryKey = dc;
|
---|
| 795 |
|
---|
| 796 | //Build Data Relationships between Resources and HospitalLocation tables
|
---|
| 797 | dr = new DataRelation("HospitalLocationResource", //Relation Name
|
---|
| 798 | m_dsGlobal.Tables["HospitalLocation"].Columns["HOSPITAL_LOCATION_ID"], //Parent
|
---|
| 799 | m_dsGlobal.Tables["Resources"].Columns["HOSPITAL_LOCATION_ID"], false); //Child
|
---|
| 800 | m_dsGlobal.Relations.Add(dr);
|
---|
| 801 |
|
---|
[1051] | 802 | //Build ScheduleUser table
|
---|
| 803 | //Table #12
|
---|
[1117] | 804 | setProgressDelegate(14);
|
---|
[1050] | 805 | setStatusDelegate(statusConst + " Schedule User");
|
---|
| 806 | this.LoadScheduleUserTable();
|
---|
| 807 |
|
---|
| 808 | //Build Primary Key for ScheduleUser table
|
---|
| 809 | dc = new DataColumn[1];
|
---|
| 810 | dtTemp = m_dsGlobal.Tables["ScheduleUser"];
|
---|
| 811 | dc[0] = dtTemp.Columns["USERID"];
|
---|
| 812 | m_dsGlobal.Tables["ScheduleUser"].PrimaryKey = dc;
|
---|
| 813 |
|
---|
[1051] | 814 | //Build ResourceUser table
|
---|
| 815 | //Table #13
|
---|
[1062] | 816 | //Acess to Resources by [this] User
|
---|
[1117] | 817 | setProgressDelegate(15);
|
---|
[1050] | 818 | setStatusDelegate(statusConst + " Resource User");
|
---|
| 819 | this.LoadResourceUserTable();
|
---|
| 820 |
|
---|
| 821 | //Build Primary Key for ResourceUser table
|
---|
| 822 | dc = new DataColumn[1];
|
---|
| 823 | dtTemp = m_dsGlobal.Tables["ResourceUser"];
|
---|
| 824 | dc[0] = dtTemp.Columns["RESOURCEUSER_ID"];
|
---|
| 825 | m_dsGlobal.Tables["ResourceUser"].PrimaryKey = dc;
|
---|
| 826 |
|
---|
| 827 | //Create relation between BSDX Resource and BSDX Resource User tables
|
---|
| 828 | dr = new DataRelation("ResourceUser", //Relation Name
|
---|
| 829 | m_dsGlobal.Tables["Resources"].Columns["RESOURCEID"], //Parent
|
---|
| 830 | m_dsGlobal.Tables["ResourceUser"].Columns["RESOURCEID"]); //Child
|
---|
| 831 | m_dsGlobal.Relations.Add(dr);
|
---|
| 832 |
|
---|
[1051] | 833 | //Build active provider table
|
---|
| 834 | //Table #14
|
---|
[1062] | 835 | //TODO: Lazy load the provider table; no need to load in advance.
|
---|
[1117] | 836 | setProgressDelegate(16);
|
---|
[1050] | 837 | setStatusDelegate(statusConst + " Providers");
|
---|
| 838 | sCommandText = "SELECT BMXIEN, NAME FROM NEW_PERSON WHERE INACTIVE_DATE = '' AND BMXIEN > 1";
|
---|
[1194] | 839 | RemoteSession.TableFromSQL(sCommandText, m_dsGlobal, "Provider");
|
---|
[1050] | 840 | Debug.Write("LoadGlobalRecordsets -- Provider loaded\n");
|
---|
| 841 |
|
---|
[1062] | 842 | //Build the HOLIDAY table
|
---|
[1051] | 843 | //Table #15
|
---|
[1117] | 844 | setProgressDelegate(17);
|
---|
[1050] | 845 | setStatusDelegate(statusConst + " Holiday");
|
---|
[1104] | 846 | sCommandText = "SELECT NAME, DATE FROM HOLIDAY WHERE INTERNAL[DATE] > '" + FMDateTime.Create(DateTime.Today).DateOnly.FMDateString + "'";
|
---|
[1194] | 847 | RemoteSession.TableFromSQL(sCommandText, m_dsGlobal, "HOLIDAY");
|
---|
[1050] | 848 | Debug.Write("LoadingGlobalRecordsets -- Holidays loaded\n");
|
---|
| 849 |
|
---|
| 850 |
|
---|
| 851 | //Save the xml schema
|
---|
| 852 | //m_dsGlobal.WriteXmlSchema(@"..\..\csSchema20060526.xsd");
|
---|
| 853 | //----------------------------------------------
|
---|
| 854 |
|
---|
[1051] | 855 | setStatusDelegate("Setting Receive Timeout");
|
---|
[1194] | 856 | _current.RemoteSession.ReceiveTimeout = 30000; //30-second timeout
|
---|
[1050] | 857 |
|
---|
[788] | 858 | #if DEBUG
|
---|
[1194] | 859 | _current.RemoteSession.ReceiveTimeout = 600000; //longer timeout for debugging
|
---|
[1050] | 860 | #endif
|
---|
[1051] | 861 | // Event Subsriptions
|
---|
| 862 | setStatusDelegate("Subscribing to Server Events");
|
---|
[1062] | 863 | //Table #16
|
---|
[1117] | 864 | setProgressDelegate(18);
|
---|
[1194] | 865 | _current.RemoteSession.EventServices.Subscribe("BSDX SCHEDULE");
|
---|
[1062] | 866 | //Table #17
|
---|
[1117] | 867 | setProgressDelegate(19);
|
---|
[1194] | 868 | _current.RemoteSession.EventServices.Subscribe("BSDX CALL WORKSTATIONS");
|
---|
[1051] | 869 | //Table #18
|
---|
[1117] | 870 | setProgressDelegate(20);
|
---|
[1194] | 871 | _current.RemoteSession.EventServices.Subscribe("BSDX ADMIN MESSAGE");
|
---|
[1051] | 872 | //Table #19
|
---|
[1117] | 873 | setProgressDelegate(21);
|
---|
[1194] | 874 | _current.RemoteSession.EventServices.Subscribe("BSDX ADMIN SHUTDOWN");
|
---|
[614] | 875 |
|
---|
[1194] | 876 | _current.RemoteSession.EventServices.EventPollingInterval = 5000; //in milliseconds
|
---|
| 877 | _current.RemoteSession.EventServices.IsEventPollingEnabled = true;
|
---|
| 878 |
|
---|
| 879 | //PORT TODO: No Autofire in BMX 4.0
|
---|
| 880 | //_current.RemoteSession.EventServices. = 12; //AutoFire every 12*5 seconds
|
---|
[614] | 881 |
|
---|
[1050] | 882 | //Close Splash Screen
|
---|
| 883 | closeSplashDelegate();
|
---|
[1051] | 884 |
|
---|
| 885 | return true;
|
---|
[1050] | 886 |
|
---|
[614] | 887 | }
|
---|
| 888 |
|
---|
| 889 |
|
---|
[1050] | 890 |
|
---|
[614] | 891 | public void LoadAccessGroupsTable()
|
---|
| 892 | {
|
---|
| 893 | string sCommandText = "SELECT * FROM BSDX_ACCESS_GROUP";
|
---|
[1194] | 894 | RemoteSession.TableFromSQL(sCommandText, m_dsGlobal, "AccessGroup");
|
---|
[614] | 895 | Debug.Write("LoadGlobalRecordsets -- AccessGroups loaded\n");
|
---|
| 896 | }
|
---|
| 897 |
|
---|
| 898 | public void LoadAccessGroupTypesTable()
|
---|
| 899 | {
|
---|
| 900 | string sCommandText = "BSDX GET ACCESS GROUP TYPES";
|
---|
[1194] | 901 | RemoteSession.TableFromCommand(sCommandText, m_dsGlobal, "AccessGroupType");
|
---|
[614] | 902 | Debug.Write("LoadGlobalRecordsets -- AccessGroupTypes loaded\n");
|
---|
| 903 | }
|
---|
| 904 |
|
---|
| 905 | public void LoadBSDXResourcesTable()
|
---|
| 906 | {
|
---|
[1194] | 907 | string sCommandText = "BSDX RESOURCES^" + RemoteSession.User.Duz;
|
---|
| 908 | RemoteSession.TableFromCommand(sCommandText, m_dsGlobal, "Resources");
|
---|
[614] | 909 | Debug.Write("LoadGlobalRecordsets -- Resources loaded\n");
|
---|
| 910 | }
|
---|
| 911 |
|
---|
| 912 | public void LoadResourceGroupTable()
|
---|
| 913 | {
|
---|
| 914 | //ResourceGroup Table (Resource Groups by User)
|
---|
| 915 | //Table "ResourceGroup" contains all resource group names
|
---|
| 916 | //to which user has access
|
---|
| 917 | //Fields are: RESOURCE_GROUPID, RESOURCE_GROUP
|
---|
[1194] | 918 | string sCommandText = "BSDX RESOURCE GROUPS BY USER^" + RemoteSession.User.Duz;
|
---|
| 919 | RemoteSession.TableFromCommand(sCommandText, m_dsGlobal, "ResourceGroup");
|
---|
[614] | 920 | Debug.Write("LoadGlobalRecordsets -- ResourceGroup loaded\n");
|
---|
| 921 | }
|
---|
| 922 |
|
---|
| 923 | public void LoadGroupResourcesTable()
|
---|
| 924 | {
|
---|
| 925 | //Table "GroupResources" contains all active GROUP/RESOURCE combinations
|
---|
| 926 | //to which user has access based on entries in BSDX RESOURCE USER file
|
---|
| 927 | //If user has BSDXZMGR or XUPROGMODE keys, then ALL Group/Resource combinstions
|
---|
| 928 | //are returned.
|
---|
| 929 | //Fields are: RESOURCE_GROUPID, RESOURCE_GROUP, RESOURCE_GROUP_ITEMID, RESOURCE_NAME, RESOURCE_ID
|
---|
[1194] | 930 | string sCommandText = "BSDX GROUP RESOURCE^" + RemoteSession.User.Duz;
|
---|
| 931 | RemoteSession.TableFromCommand(sCommandText, m_dsGlobal, "GroupResources");
|
---|
[614] | 932 | Debug.Write("LoadGlobalRecordsets -- GroupResources loaded\n");
|
---|
| 933 | }
|
---|
| 934 |
|
---|
| 935 | public void LoadScheduleUserTable()
|
---|
| 936 | {
|
---|
| 937 | //Table "ScheduleUser" contains an entry for each user in File 200 (NEW PERSON)
|
---|
| 938 | //who possesses the BSDXZMENU security key.
|
---|
| 939 | string sCommandText = "BSDX SCHEDULE USER";
|
---|
[1194] | 940 | RemoteSession.TableFromCommand(sCommandText, m_dsGlobal, "ScheduleUser");
|
---|
[614] | 941 | Debug.Write("LoadGlobalRecordsets -- ScheduleUser loaded\n");
|
---|
| 942 | }
|
---|
| 943 |
|
---|
| 944 | public void LoadResourceUserTable()
|
---|
| 945 | {
|
---|
| 946 | //Table "ResourceUser" duplicates the BSDX RESOURCE USER File.
|
---|
| 947 | //NOTE: Column names are RESOURCEUSER_ID, RESOURCEID,
|
---|
| 948 | // OVERBOOK, MODIFY_SCHEDULE, USERID, USERID1
|
---|
| 949 | //string sCommandText = "SELECT BMXIEN RESOURCEUSER_ID, INTERNAL[RESOURCENAME] RESOURCEID, OVERBOOK, MODIFY_SCHEDULE, USERNAME USERID, INTERNAL[USERNAME] FROM BSDX_RESOURCE_USER";
|
---|
| 950 | LoadResourceUserTable(false);
|
---|
| 951 | }
|
---|
| 952 |
|
---|
| 953 | public void LoadResourceUserTable(bool bAllUsers)
|
---|
| 954 | {
|
---|
[1050] | 955 | string sCommandText = @"SELECT BMXIEN RESOURCEUSER_ID, RESOURCENAME, INTERNAL[RESOURCENAME] RESOURCEID, OVERBOOK, MODIFY_SCHEDULE, MODIFY_APPOINTMENTS, USERNAME, INTERNAL[USERNAME] USERID FROM BSDX_RESOURCE_USER"; // WHERE INTERNAL[INSTITUTION]=" + m_ConnectInfo.DUZ2;
|
---|
| 956 |
|
---|
| 957 | if (!bAllUsers)
|
---|
| 958 | {
|
---|
[1194] | 959 | sCommandText += String.Format(" WHERE INTERNAL[USERNAME] = {0}", RemoteSession.User.Duz);
|
---|
[1050] | 960 | }
|
---|
| 961 |
|
---|
[1194] | 962 | RemoteSession.TableFromSQL(sCommandText, m_dsGlobal, "ResourceUser");
|
---|
[614] | 963 | Debug.Write("LoadGlobalRecordsets -- ResourceUser loaded\n");
|
---|
| 964 | }
|
---|
| 965 |
|
---|
| 966 |
|
---|
| 967 | public void RegisterDocumentView(CGDocument doc, CGView view)
|
---|
| 968 | {
|
---|
| 969 | //Store the view in the list of views
|
---|
| 970 | this.Views.Add(view, doc);
|
---|
| 971 |
|
---|
| 972 | //Hook into the view's 'closed' event
|
---|
| 973 | view.Closed += new EventHandler(ViewClosed);
|
---|
| 974 |
|
---|
| 975 | //Hook into the view's mnuRPMSServer.Click event
|
---|
| 976 | view.mnuRPMSServer.Click += new EventHandler(mnuRPMSServer_Click);
|
---|
| 977 |
|
---|
| 978 | //Hook into the view's mnuRPMSLogin.Click event
|
---|
| 979 | view.mnuRPMSLogin.Click += new EventHandler(mnuRPMSLogin_Click);
|
---|
| 980 |
|
---|
| 981 | }
|
---|
| 982 |
|
---|
| 983 | public void RegisterAVDocumentView(CGAVDocument doc, CGAVView view)
|
---|
| 984 | {
|
---|
| 985 | //Store the view in the list of views
|
---|
| 986 | this.AvailabilityViews.Add(view, doc);
|
---|
| 987 |
|
---|
| 988 | //Hook into the view's 'closed' event
|
---|
| 989 | view.Closed += new EventHandler(AVViewClosed);
|
---|
| 990 | }
|
---|
| 991 |
|
---|
| 992 | public CGAVView GetAVViewByResource(ArrayList sResourceArray)
|
---|
| 993 | {
|
---|
| 994 | if (sResourceArray == null)
|
---|
| 995 | return null;
|
---|
| 996 |
|
---|
| 997 | bool bEqual = true;
|
---|
| 998 | foreach (CGAVView v in m_AVViews.Keys)
|
---|
| 999 | {
|
---|
| 1000 | CGAVDocument d = v.Document;
|
---|
| 1001 |
|
---|
| 1002 | bEqual = false;
|
---|
| 1003 | if (d.Resources.Count == sResourceArray.Count)
|
---|
| 1004 | {
|
---|
| 1005 | bEqual = true;
|
---|
| 1006 | for (int j = 0; j < sResourceArray.Count; j++)
|
---|
| 1007 | {
|
---|
| 1008 | if (sResourceArray.Contains(d.Resources[j]) == false)
|
---|
| 1009 | {
|
---|
| 1010 | bEqual = false;
|
---|
| 1011 | break;
|
---|
| 1012 | }
|
---|
| 1013 | if (d.Resources.Contains(sResourceArray[j]) == false)
|
---|
| 1014 | {
|
---|
| 1015 | bEqual = false;
|
---|
| 1016 | break;
|
---|
| 1017 | }
|
---|
| 1018 | }
|
---|
| 1019 | if (bEqual == true)
|
---|
| 1020 | return v;
|
---|
| 1021 | }
|
---|
| 1022 | }
|
---|
| 1023 | return null;
|
---|
| 1024 | }
|
---|
| 1025 | /// <summary>
|
---|
| 1026 | /// Return the first view having a resource array matching sResourceArray
|
---|
| 1027 | /// </summary>
|
---|
| 1028 | /// <param name="sResourceArray"></param>
|
---|
| 1029 | /// <returns></returns>
|
---|
| 1030 | public CGView GetViewByResource(ArrayList sResourceArray)
|
---|
| 1031 | {
|
---|
| 1032 | if (sResourceArray == null)
|
---|
| 1033 | return null;
|
---|
| 1034 |
|
---|
| 1035 | bool bEqual = true;
|
---|
| 1036 | foreach (CGView v in _views.Keys)
|
---|
| 1037 | {
|
---|
| 1038 | CGDocument d = v.Document;
|
---|
| 1039 |
|
---|
| 1040 | bEqual = false;
|
---|
| 1041 | if (d.Resources.Count == sResourceArray.Count)
|
---|
| 1042 | {
|
---|
| 1043 | bEqual = true;
|
---|
| 1044 | for (int j = 0; j < sResourceArray.Count; j++)
|
---|
| 1045 | {
|
---|
| 1046 | if (sResourceArray.Contains(d.Resources[j]) == false)
|
---|
| 1047 | {
|
---|
| 1048 | bEqual = false;
|
---|
| 1049 | break;
|
---|
| 1050 | }
|
---|
| 1051 | if (d.Resources.Contains(sResourceArray[j]) == false)
|
---|
| 1052 | {
|
---|
| 1053 | bEqual = false;
|
---|
| 1054 | break;
|
---|
| 1055 | }
|
---|
| 1056 | }
|
---|
| 1057 | if (bEqual == true)
|
---|
| 1058 | return v;
|
---|
| 1059 | }
|
---|
| 1060 | }
|
---|
| 1061 | return null;
|
---|
| 1062 | }
|
---|
| 1063 |
|
---|
[1050] | 1064 | /// <summary>
|
---|
| 1065 | /// Removes view and Handles Disconnection from Database if no views are left.
|
---|
| 1066 | /// </summary>
|
---|
| 1067 | /// <param name="sender"></param>
|
---|
| 1068 | /// <param name="e"></param>
|
---|
[614] | 1069 | private void ViewClosed(object sender, EventArgs e)
|
---|
| 1070 | {
|
---|
| 1071 | //Remove the sender from our document list
|
---|
| 1072 | Views.Remove(sender);
|
---|
| 1073 |
|
---|
| 1074 | //If no documents left, then close RPMS connection & exit the application
|
---|
| 1075 | if ((Views.Count == 0)&&(this.AvailabilityViews.Count == 0)&&(m_bExitOK == true))
|
---|
| 1076 | {
|
---|
[1194] | 1077 | RemoteSession.EventServices.IsEventPollingEnabled = false;
|
---|
| 1078 | RemoteSession.EventServices.Unsubscribe("BSDX SCHEDULE");
|
---|
| 1079 | RemoteSession.Close();
|
---|
[614] | 1080 | Application.Exit();
|
---|
| 1081 | }
|
---|
| 1082 | }
|
---|
| 1083 |
|
---|
| 1084 | private void AVViewClosed(object sender, EventArgs e)
|
---|
| 1085 | {
|
---|
| 1086 | //Remove the sender from our document list
|
---|
| 1087 | this.AvailabilityViews.Remove(sender);
|
---|
| 1088 |
|
---|
| 1089 | //If no documents left, then close RPMS connection & exit the application
|
---|
| 1090 | if ((Views.Count == 0)&&(this.AvailabilityViews.Count == 0)&&(m_bExitOK == true))
|
---|
| 1091 | {
|
---|
[1194] | 1092 | RemoteSession.Close();
|
---|
[614] | 1093 | Application.Exit();
|
---|
| 1094 | }
|
---|
| 1095 | }
|
---|
| 1096 |
|
---|
[1098] | 1097 | /// <summary>
|
---|
| 1098 | /// Not used
|
---|
| 1099 | /// </summary>
|
---|
[614] | 1100 | private void KeepAlive()
|
---|
| 1101 | {
|
---|
| 1102 | foreach (CGView v in _views.Keys)
|
---|
| 1103 | {
|
---|
| 1104 | CGDocument d = v.Document;
|
---|
| 1105 | DateTime dNow = DateTime.Now;
|
---|
| 1106 | DateTime dLast = d.LastRefreshed;
|
---|
| 1107 | TimeSpan tsDiff = dNow - dLast;
|
---|
| 1108 | if (tsDiff.Seconds > 180)
|
---|
| 1109 | {
|
---|
| 1110 | for (int j = 0; j < d.Resources.Count; j++)
|
---|
| 1111 | {
|
---|
| 1112 | v.RaiseRPMSEvent("SCHEDULE-" + d.Resources[j].ToString(), "");
|
---|
| 1113 | }
|
---|
| 1114 |
|
---|
| 1115 | break;
|
---|
| 1116 | }
|
---|
| 1117 | }
|
---|
| 1118 | }
|
---|
| 1119 |
|
---|
| 1120 | /// <summary>
|
---|
| 1121 | /// Propogate availability updates to all sRresource's doc/views
|
---|
| 1122 | /// </summary>
|
---|
| 1123 | public void UpdateViews(string sResource, string sOldResource)
|
---|
| 1124 | {
|
---|
| 1125 | if (sResource == null)
|
---|
| 1126 | return;
|
---|
| 1127 | foreach (CGView v in _views.Keys)
|
---|
| 1128 | {
|
---|
| 1129 | CGDocument d = v.Document;
|
---|
| 1130 | for (int j = 0; j < d.Resources.Count; j++)
|
---|
| 1131 | {
|
---|
| 1132 | if ((sResource == "") || (sResource == ((string) d.Resources[j])) || (sOldResource == ((string) d.Resources[j])))
|
---|
| 1133 | {
|
---|
| 1134 | d.RefreshDocument();
|
---|
| 1135 | break;
|
---|
| 1136 | }
|
---|
| 1137 | }
|
---|
| 1138 | v.UpdateTree();
|
---|
| 1139 | }
|
---|
| 1140 | }
|
---|
| 1141 |
|
---|
| 1142 | /// <summary>
|
---|
| 1143 | /// Propogate availability updates to all doc/views
|
---|
| 1144 | /// </summary>
|
---|
| 1145 | public void UpdateViews()
|
---|
| 1146 | {
|
---|
| 1147 | UpdateViews("","");
|
---|
| 1148 | foreach (CGView v in _views.Keys)
|
---|
| 1149 | {
|
---|
| 1150 | v.UpdateTree();
|
---|
| 1151 | }
|
---|
| 1152 | }
|
---|
| 1153 |
|
---|
| 1154 | /// <summary>
|
---|
| 1155 | /// Calls each view associated with document Doc and closes it.
|
---|
| 1156 | /// </summary>
|
---|
| 1157 | public void CloseAllViews(CGDocument doc)
|
---|
| 1158 | {
|
---|
| 1159 | //iterate through all views and call update.
|
---|
| 1160 | Hashtable h = CGDocumentManager.Current.Views;
|
---|
| 1161 |
|
---|
| 1162 | CGDocument d;
|
---|
| 1163 | int nTempCount = h.Count;
|
---|
| 1164 | do
|
---|
| 1165 | {
|
---|
| 1166 | nTempCount = h.Count;
|
---|
| 1167 | foreach (CGView v in h.Keys)
|
---|
| 1168 | {
|
---|
| 1169 | d = (CGDocument) h[v];
|
---|
| 1170 | if (d == doc)
|
---|
| 1171 | {
|
---|
| 1172 | v.Close();
|
---|
| 1173 | break;
|
---|
| 1174 | }
|
---|
| 1175 | }
|
---|
| 1176 | } while ((h.Count > 0) && (nTempCount != h.Count));
|
---|
| 1177 | }
|
---|
| 1178 |
|
---|
| 1179 | /// <summary>
|
---|
| 1180 | /// Calls each view associated with Availability Doc and closes it.
|
---|
| 1181 | /// </summary>
|
---|
| 1182 | public void CloseAllViews(CGAVDocument doc)
|
---|
| 1183 | {
|
---|
| 1184 | //iterate through all views and call update.
|
---|
| 1185 | Hashtable h = CGDocumentManager.Current.AvailabilityViews;
|
---|
| 1186 |
|
---|
| 1187 | CGAVDocument d;
|
---|
| 1188 | int nTempCount = h.Count;
|
---|
| 1189 | do
|
---|
| 1190 | {
|
---|
| 1191 | nTempCount = h.Count;
|
---|
| 1192 | foreach (CGAVView v in h.Keys)
|
---|
| 1193 | {
|
---|
| 1194 | d = (CGAVDocument) h[v];
|
---|
| 1195 | if (d == doc)
|
---|
| 1196 | {
|
---|
| 1197 | v.Close();
|
---|
| 1198 | break;
|
---|
| 1199 | }
|
---|
| 1200 | }
|
---|
| 1201 | } while ((h.Count > 0) && (nTempCount != h.Count));
|
---|
| 1202 |
|
---|
| 1203 |
|
---|
| 1204 | }
|
---|
| 1205 |
|
---|
[1071] | 1206 | /// <summary>
|
---|
| 1207 | /// Accomplishes Changing the Server to which you connect
|
---|
| 1208 | /// </summary>
|
---|
| 1209 | /// <remarks>
|
---|
| 1210 | /// Parameter relog-in for InitializeApp forces initialize app to use
|
---|
| 1211 | /// 1. The server the user just picked and then BMX saved off to User Preferences
|
---|
| 1212 | /// 2. A new access and verify code pair
|
---|
| 1213 | /// </remarks>
|
---|
| 1214 | /// <param name="sender">unused</param>
|
---|
| 1215 | /// <param name="e">unused</param>
|
---|
[614] | 1216 | private void mnuRPMSServer_Click(object sender, EventArgs e)
|
---|
| 1217 | {
|
---|
| 1218 | //Warn that changing servers will close all schedules
|
---|
[627] | 1219 | if (MessageBox.Show("Are you sure you want to close all schedules and connect to a different VistA server?", "Clinical Scheduling", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) != DialogResult.OK)
|
---|
[614] | 1220 | return;
|
---|
| 1221 |
|
---|
| 1222 | //Reconnect to RPMS and recreate all global recordsets
|
---|
| 1223 | try
|
---|
| 1224 | {
|
---|
[1071] | 1225 | // Close All, but tell the Close All method not to call Applicaiton.Exit since we still plan to continue.
|
---|
| 1226 | // Close All does not call Application.Exit, but CGView_Close handler does
|
---|
[614] | 1227 | m_bExitOK = false;
|
---|
[1071] | 1228 | CloseAll();
|
---|
| 1229 | m_bExitOK = true;
|
---|
| 1230 |
|
---|
| 1231 | //Used in Do loop
|
---|
[1194] | 1232 | //bool bRetry = true;
|
---|
[1071] | 1233 |
|
---|
[1194] | 1234 | /*// Do Loop to deal with changing the server and the vagaries of user choices.
|
---|
[614] | 1235 | do
|
---|
| 1236 | {
|
---|
| 1237 | try
|
---|
| 1238 | {
|
---|
[1071] | 1239 | //ChangeServerInfo does not re-login the user
|
---|
| 1240 | //It only changes the saved server information in the %APPDATA% folder
|
---|
| 1241 | //so it can be re-used when BMX tries to log in again.
|
---|
| 1242 | //Access and Verify code are prompted for in InitializeApp
|
---|
[1194] | 1243 | LoginProcess login = this.WinFramework.CreateLoginProcess();
|
---|
| 1244 | login.AttemptUserInputLogin("ReLog-in", 3, true, null);
|
---|
[614] | 1245 | bRetry = false;
|
---|
| 1246 | }
|
---|
| 1247 | catch (Exception ex)
|
---|
| 1248 | {
|
---|
| 1249 | if (ex.Message == "User cancelled.")
|
---|
| 1250 | {
|
---|
| 1251 | bRetry = false;
|
---|
[1071] | 1252 | Application.Exit();
|
---|
[614] | 1253 | return;
|
---|
| 1254 | }
|
---|
[627] | 1255 | if (MessageBox.Show("Unable to connect to VistA. " + ex.Message , "Clinical Scheduling", MessageBoxButtons.RetryCancel) == DialogResult.Retry)
|
---|
[614] | 1256 | {
|
---|
| 1257 | bRetry = true;
|
---|
| 1258 | }
|
---|
| 1259 | else
|
---|
| 1260 | {
|
---|
| 1261 | bRetry = false;
|
---|
[1071] | 1262 | Application.Exit();
|
---|
[614] | 1263 | return;
|
---|
| 1264 | }
|
---|
| 1265 | }
|
---|
| 1266 | } while (bRetry == true);
|
---|
[1194] | 1267 | */
|
---|
| 1268 |
|
---|
[1071] | 1269 | //Parameter for initialize app tells it that this is a re-login and forces a new access and verify code.
|
---|
| 1270 | bool isEverythingOkay = this.InitializeApp(true);
|
---|
[614] | 1271 |
|
---|
[1071] | 1272 | //if an error occurred, break out. This time we need to call Application.Exit since it's already running.
|
---|
| 1273 | if (!isEverythingOkay)
|
---|
| 1274 | {
|
---|
| 1275 | Application.Exit();
|
---|
| 1276 | return;
|
---|
| 1277 | }
|
---|
[614] | 1278 |
|
---|
[1071] | 1279 | //Otherwise, everything is okay. So open document and view, then show and activate view.
|
---|
| 1280 | CGDocument doc = new CGDocument();
|
---|
| 1281 | doc.DocManager = _current;
|
---|
[614] | 1282 |
|
---|
[1071] | 1283 | CGView view = new CGView();
|
---|
[1073] | 1284 | view.InitializeDocView(doc, _current, doc.StartDate, _current.WindowText);
|
---|
[1071] | 1285 |
|
---|
| 1286 | view.Show();
|
---|
| 1287 | view.Activate();
|
---|
| 1288 |
|
---|
| 1289 | //Application.Run need not be called b/c it is already running.
|
---|
[614] | 1290 | }
|
---|
| 1291 | catch (Exception ex)
|
---|
| 1292 | {
|
---|
| 1293 | throw ex;
|
---|
| 1294 | }
|
---|
| 1295 |
|
---|
| 1296 | }
|
---|
| 1297 |
|
---|
[1071] | 1298 | /// <summary>
|
---|
| 1299 | /// Accomplishes Re-login into RPMS/VISTA. Now all logic is in this event handler.
|
---|
| 1300 | /// </summary>
|
---|
| 1301 | /// <param name="sender">not used</param>
|
---|
| 1302 | /// <param name="e">not used</param>
|
---|
[614] | 1303 | private void mnuRPMSLogin_Click(object sender, EventArgs e)
|
---|
| 1304 | {
|
---|
[1194] | 1305 | mnuRPMSServer_Click(sender, e);
|
---|
| 1306 |
|
---|
| 1307 | /* v 1.7 to support BMX 4 -- commented out -- smh
|
---|
| 1308 | //Warn that changing login will close all schedules
|
---|
[627] | 1309 | if (MessageBox.Show("Are you sure you want to close all schedules and login to VistA?", "Clinical Scheduling", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) != DialogResult.OK)
|
---|
[614] | 1310 | return;
|
---|
| 1311 |
|
---|
| 1312 | //Reconnect to RPMS and recreate all global recordsets
|
---|
| 1313 | try
|
---|
| 1314 | {
|
---|
[1071] | 1315 | // Close All, but tell the Close All method not to call Applicaiton.Exit since we still plan to continue.
|
---|
| 1316 | // Close All does not call Application.Exit, but CGView_Close handler does
|
---|
[614] | 1317 | m_bExitOK = false;
|
---|
| 1318 | CloseAll();
|
---|
| 1319 | m_bExitOK = true;
|
---|
[1071] | 1320 |
|
---|
[1194] | 1321 | LoginProcess login = this.WinFramework.CreateLoginProcess();
|
---|
| 1322 | login.AttemptUserInputLogin("Clincal Scheduling", 3, true, null);
|
---|
| 1323 | //m_ConnectInfo.bmxNetLib.StartLog(); //This line turns on logging of messages
|
---|
| 1324 |
|
---|
| 1325 | if (!login.WasSuccessful)
|
---|
| 1326 | {
|
---|
| 1327 | return;
|
---|
| 1328 | }
|
---|
| 1329 |
|
---|
| 1330 | LocalSession local = this.WinFramework.LocalSession;
|
---|
| 1331 |
|
---|
| 1332 | if ((this.WinFramework.Context.User.Division == null) && !this.WinFramework.AttemptUserInputSetDivision("Set Initial Division", null))
|
---|
| 1333 | {
|
---|
| 1334 | return;
|
---|
| 1335 | }
|
---|
| 1336 |
|
---|
| 1337 | this.RemoteSession = this.WinFramework.PrimaryRemoteSession;
|
---|
| 1338 |
|
---|
[1071] | 1339 | //Parameter for initialize app tells it that this is a re-login and forces a new access and verify code.
|
---|
| 1340 | bool isEverythingOkay = this.InitializeApp(true);
|
---|
| 1341 |
|
---|
| 1342 | //if an error occurred, break out. This time we need to call Application.Exit since it's already running.
|
---|
| 1343 | if (!isEverythingOkay)
|
---|
| 1344 | {
|
---|
| 1345 | Application.Exit();
|
---|
| 1346 | return;
|
---|
| 1347 | }
|
---|
| 1348 |
|
---|
| 1349 | //Otherwise, everything is okay. So open document and view, then show and activate view.
|
---|
| 1350 | CGDocument doc = new CGDocument();
|
---|
| 1351 | doc.DocManager = _current;
|
---|
| 1352 |
|
---|
| 1353 | CGView view = new CGView();
|
---|
[1073] | 1354 | view.InitializeDocView(doc, _current, doc.StartDate, _current.WindowText);
|
---|
[1071] | 1355 |
|
---|
| 1356 | view.Show();
|
---|
| 1357 | view.Activate();
|
---|
| 1358 |
|
---|
| 1359 | //Application.Run need not be called b/c it is already running.
|
---|
[614] | 1360 | }
|
---|
| 1361 | catch (Exception ex)
|
---|
| 1362 | {
|
---|
| 1363 | throw ex;
|
---|
| 1364 | }
|
---|
[1194] | 1365 | */
|
---|
[614] | 1366 | }
|
---|
| 1367 |
|
---|
| 1368 | delegate void CloseAllDelegate(string sMsg);
|
---|
| 1369 |
|
---|
| 1370 | private void CloseAll(string sMsg)
|
---|
| 1371 | {
|
---|
| 1372 | if (sMsg == "")
|
---|
| 1373 | {
|
---|
| 1374 | sMsg = "Scheduling System Shutting Down Immediately for Maintenance.";
|
---|
| 1375 | }
|
---|
| 1376 |
|
---|
[620] | 1377 | MessageBox.Show(sMsg, "Clinical Scheduling Administrator -- System Shutdown Notification", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
---|
[614] | 1378 |
|
---|
| 1379 | CloseAll();
|
---|
| 1380 | }
|
---|
| 1381 |
|
---|
| 1382 | private void CloseAll()
|
---|
| 1383 | {
|
---|
| 1384 | //Close all documents, views and connections
|
---|
| 1385 | Hashtable h = CGDocumentManager.Current.Views;
|
---|
| 1386 | int nTempCount = h.Count;
|
---|
| 1387 | do
|
---|
| 1388 | {
|
---|
| 1389 | nTempCount = h.Count;
|
---|
| 1390 | foreach (CGView v in h.Keys)
|
---|
| 1391 | {
|
---|
| 1392 | v.Close();
|
---|
| 1393 | break;
|
---|
| 1394 | }
|
---|
| 1395 | } while ((h.Count > 0) && (nTempCount != h.Count));
|
---|
| 1396 |
|
---|
| 1397 | h = CGDocumentManager.Current.AvailabilityViews;
|
---|
| 1398 | nTempCount = h.Count;
|
---|
| 1399 | do
|
---|
| 1400 | {
|
---|
| 1401 | nTempCount = h.Count;
|
---|
| 1402 | foreach (CGAVView v in h.Keys)
|
---|
| 1403 | {
|
---|
| 1404 | v.Close();
|
---|
| 1405 | break;
|
---|
| 1406 | }
|
---|
| 1407 | } while ((h.Count > 0) && (nTempCount != h.Count));
|
---|
| 1408 |
|
---|
| 1409 | }
|
---|
| 1410 |
|
---|
[1011] | 1411 | public delegate DataTable RPMSDataTableDelegate(string CommandString, string TableName);
|
---|
[614] | 1412 |
|
---|
| 1413 | public DataTable RPMSDataTable(string sSQL, string sTableName)
|
---|
| 1414 | {
|
---|
| 1415 | //Retrieves a recordset from RPMS
|
---|
| 1416 | string sErrorMessage = "";
|
---|
[843] | 1417 | DataTable dtOut;
|
---|
| 1418 |
|
---|
[614] | 1419 | try
|
---|
| 1420 | {
|
---|
[1011] | 1421 | //System.IntPtr pHandle = this.Handle;
|
---|
[1194] | 1422 | RPMSDataTableDelegate rdtd = new RPMSDataTableDelegate(RemoteSession.TableFromCommand);
|
---|
[1050] | 1423 | //dtOut = (DataTable) this.Invoke(rdtd, new object[] {sSQL, sTableName});
|
---|
[1194] | 1424 | dtOut = RemoteSession.TableFromCommand(sSQL);
|
---|
| 1425 | dtOut.TableName = sTableName;
|
---|
| 1426 |
|
---|
[614] | 1427 | }
|
---|
[843] | 1428 |
|
---|
[614] | 1429 | catch (Exception ex)
|
---|
| 1430 | {
|
---|
| 1431 | sErrorMessage = "CGDocumentManager.RPMSDataTable error: " + ex.Message;
|
---|
| 1432 | throw ex;
|
---|
| 1433 | }
|
---|
[843] | 1434 |
|
---|
| 1435 | return dtOut;
|
---|
| 1436 |
|
---|
[614] | 1437 | }
|
---|
| 1438 |
|
---|
| 1439 | public void ChangeDivision(System.Windows.Forms.Form frmCaller)
|
---|
| 1440 | {
|
---|
[1194] | 1441 | WinFramework.AttemptUserInputSetDivision("Change Division", frmCaller);
|
---|
| 1442 |
|
---|
| 1443 | RemoteSession = WinFramework.PrimaryRemoteSession;
|
---|
| 1444 |
|
---|
[614] | 1445 | foreach (CGView v in _views.Keys)
|
---|
| 1446 | {
|
---|
| 1447 | v.InitializeDocView(v.Document.DocName);
|
---|
| 1448 | v.Document.RefreshDocument();
|
---|
| 1449 | }
|
---|
| 1450 | }
|
---|
| 1451 |
|
---|
| 1452 | public void ViewRefresh()
|
---|
| 1453 | {
|
---|
| 1454 | foreach (CGView v in _views.Keys)
|
---|
| 1455 | {
|
---|
| 1456 | try
|
---|
| 1457 | {
|
---|
| 1458 | v.Document.RefreshDocument();
|
---|
| 1459 | }
|
---|
| 1460 | catch (Exception ex)
|
---|
| 1461 | {
|
---|
| 1462 | Debug.Write("CGDocumentManager.ViewRefresh Exception: " + ex.Message + "\n");
|
---|
| 1463 | }
|
---|
| 1464 | finally
|
---|
| 1465 | {
|
---|
| 1466 | }
|
---|
| 1467 | }
|
---|
| 1468 | Debug.Write("DocManager refreshed all views.\n");
|
---|
| 1469 | }
|
---|
| 1470 |
|
---|
| 1471 | #endregion Methods & Events
|
---|
| 1472 |
|
---|
| 1473 | }
|
---|
| 1474 | }
|
---|