source: Scheduling/branches/BMX4Support/CGDocumentManager.cs@ 1368

Last change on this file since 1368 was 1197, checked in by Sam Habiel, 13 years ago

CGDocumentManager updated with tiny tests and a try/catch.

Updated exes, and dlls.

File size: 53.7 KB
Line 
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
7using System;
8using System.Windows.Forms;
9using System.Collections;
10using System.Data;
11using System.Diagnostics;
12using System.Threading;
13using IndianHealthService.BMXNet;
14using IndianHealthService.BMXNet.WinForm;
15using IndianHealthService.BMXNet.WinForm.Configuration; //grrrr... too many namespaces here...
16using Mono.Options;
17using System.Runtime.InteropServices;
18using System.Globalization;
19
20namespace IndianHealthService.ClinicalScheduling
21{
22 /// <summary>
23 /// Main Worker. Handles sub-forms.
24 /// </summary>
25 public class CGDocumentManager //: System.Windows.Forms.Form
26 {
27 #region Member Variables
28
29 private static CGDocumentManager _current;
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
32 private string m_sWindowText = "Clinical Scheduling"; //Default Window Text
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
36
37 //Connection variables (tied to command line parameters /a /v /s /p /e)
38 private string m_AccessCode="";
39 private string m_VerifyCode="";
40 private string m_Server="";
41 private int m_Port=0;
42 private string m_Encoding=""; //Encoding is "" by default;
43
44 //Globalization Object (tied to command line parameter /culture)
45 private string m_CultureName = "";
46
47 //Data Access Layer
48 private DAL _dal = null;
49
50 //M Connection member variables
51 private DataSet m_dsGlobal = null; // Holds all user data
52
53 //Custom Printing
54 private Printing m_PrintingObject = null;
55 #endregion
56
57 #region Properties
58
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
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 }
99
100 /// <summary>
101 /// User Preferences Auto Property
102 /// </summary>
103 public UserPreferences UserPreferences { get; private set; }
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
144 public Printing PrintingObject
145 {
146 get
147 {
148 return this.m_PrintingObject;
149 }
150 }
151 #endregion
152
153 /// <summary>
154 /// Private constructor for singleton instance.
155 /// </summary>
156 private CGDocumentManager()
157 {
158 }
159
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)
176 /// /culture or -culture = Culture Name for UI Culture if you wish to override the Windows Culture
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.
181 /// - If that's not so, /e sets the default encoding. If /e is a non-existent encoding, move to next step.
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 {
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
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
199
200#if TRACE
201 DateTime startLoadTime = DateTime.Now;
202#endif
203
204 //Store a class instance of manager. Actual constructor does nothing.
205 _current = new CGDocumentManager();
206
207 //Get command line options; store in private class wide variables
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 },
213 { "e=", e => _current.m_Encoding = e},
214 { "culture=", culture => _current.m_CultureName = culture }
215 };
216
217 opset.Parse(args);
218
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 {
227
228 MessageBox.Show("Booboo: An Error Happened: " + ex.Message);
229 return; // exit application
230 }
231
232
233 //if something yucky happened, break out.
234 if (!isEverythingOkay) return;
235
236 //Create the first empty document
237 //A document holds the resources, appointments, and availabilites
238 //SAM: Good place for break point
239 CGDocument doc = new CGDocument();
240 doc.DocManager = _current;
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();
245 view.InitializeDocView(doc, _current, doc.StartDate, _current.WindowText);
246
247 //Handle Message Queue
248 Application.DoEvents();
249
250 //test
251 //doc.ThrowException();
252 //test
253
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
259
260 view.Show();
261 view.Activate();
262
263 Application.Run();
264 }
265
266 /// <summary>
267 /// Exception handler for application errors. Only for WinForm Errors.
268 /// </summary>
269 /// <remarks>Never tested. I can't get an error to go here!</remarks>
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
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;
298
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
306 #region BMXNet Event Handler
307 private void CDocMgrEventHandler(Object obj, RemoteEventArgs e)
308 {
309 if (e.EventType == "BSDX CALL WORKSTATIONS")
310 {
311 string sParam = "";
312 string sDelim="~";
313 sParam += this.RemoteSession.User.Name + sDelim;
314 sParam += this.m_sHandle + sDelim;
315 sParam += Application.ProductVersion + sDelim;
316 sParam += this._views.Count.ToString();
317 _current.RemoteSession.EventServices.TriggerEvent("BSDX WORKSTATION REPORT", sParam, true);
318 }
319 if (e.EventType == "BSDX ADMIN MESSAGE")
320 {
321 string sMsg = e.EventType;
322 ShowAdminMsgDelegate samd = new ShowAdminMsgDelegate(ShowAdminMsg);
323 samd.Invoke(sMsg);
324 }
325 if (e.EventType == "BSDX ADMIN SHUTDOWN")
326 {
327 string sMsg = e.Details;
328 CloseAllDelegate cad = new CloseAllDelegate(CloseAll);
329 cad.Invoke(sMsg);
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
345 /// <summary>
346 /// See InitializeApp(bool) below
347 /// </summary>
348 private bool InitializeApp()
349 {
350 return InitializeApp(false);
351 }
352
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>
361 private bool InitializeApp(bool bReLogin)
362 {
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();
372
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;
424 //test
425 //spec.UseWindowsAuthentication = true;
426 login.AttemptUserInputLogin("Clinical Scheduling Log-in", 3, false, firstSplash);
427 //login.AttemptWindowsAuthLogin();
428 //test
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
443DoneTrying:
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
460 //Tie delegate to Events generated by BMX.
461 this.RemoteSession.EventServices.RpmsEvent += this.CDocMgrEventHandler;
462 //Disable polling
463 this.RemoteSession.EventServices.IsEventPollingEnabled = false;
464
465 //Second splash screens
466 //Show a splash screen while initializing; define delegates to remote thread
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);
472
473 //Start new thread for the Splash screen.
474 Thread threadSplash = new Thread(new ParameterizedThreadStart(frm => ((DSplash)frm).ShowDialog()));
475 threadSplash.IsBackground = true; //expendable thread -- exit even if still running.
476 threadSplash.Name = "Splash Thread";
477 threadSplash.Start(secondSplash);
478
479 firstSplash.Close(); // close temporary splash now that the new one is up and running
480
481 //There are 21 steps to load the application. That's max for the progress bar.
482 setMaxProgressDelegate(21);
483
484 // smh--not used: System.Configuration.ConfigurationManager.GetSection("appSettings");
485 setStatusDelegate("Connecting to VISTA");
486
487
488 /*
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.
493 //TODO: Make this more robust by sending a TCPConnect message and seeing if you get a response
494 if (m_Server != "" && m_Port != 0)
495 {
496 System.Net.Sockets.TcpClient tcpClient = new System.Net.Sockets.TcpClient();
497 try
498 {
499 tcpClient.Connect(m_Server, m_Port); // open it
500 tcpClient.Close(); // then close it
501 }
502 catch (System.Net.Sockets.SocketException)
503 {
504 m_ds.RemoteMsgBox("Can't connect to server! Network Error");
505 return false;
506 }
507 }
508
509
510 bool bRetry = true;
511
512 // Do block is Log-in logic
513 do
514 {
515 // login crap
516 try
517 {
518 // Not my code
519 if (bReLogin == true)
520 {
521 //Prompt for Access and Verify codes
522 _current.m_ConnectInfo.LoadConnectInfo("", "");
523 }
524 // My code -- buts looks so ugly!
525 // Checks the passed parameters stored in the class variables
526 else
527 {
528 if (m_Server != String.Empty && m_Port != 0 && m_AccessCode != String.Empty
529 && m_VerifyCode != String.Empty)
530 {
531 m_ConnectInfo.LoadConnectInfo(m_Server, m_Port, m_AccessCode, m_VerifyCode);
532 }
533 else if (m_Server != String.Empty && m_Port != 0)
534 m_ConnectInfo.LoadConnectInfo(m_Server, m_Port, "", "");
535 else
536 m_ConnectInfo.LoadConnectInfo();
537 }
538 bRetry = false;
539 }
540 catch (System.Net.Sockets.SocketException)
541 {
542 m_ds.RemoteMsgBox("Cannot connect to VistA. Network Error");
543 }
544 catch (BMXNetException ex)
545 {
546 if (m_ds.RemoteMsgBox("Unable to connect to VistA. " + ex.Message, "Clinical Scheduling", MessageBoxButtons.RetryCancel) == DialogResult.Retry)
547 {
548 bRetry = true;
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 }
557 }
558 else
559 {
560 closeSplashDelegate();
561 bRetry = false;
562 return false; //tell main that it's a no go.
563 }
564 }
565 }while (bRetry == true);
566 */
567
568 //Printing Custom DLL. Perfect place for code injection!!!
569 //*************************************************
570 string DllLocation = string.Empty;
571 System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(Application.StartupPath + @"\Printing\");
572 if (di.Exists)
573 {
574 System.IO.FileInfo[] rgFiles = di.GetFiles("*.dll");
575
576 foreach (System.IO.FileInfo fi in rgFiles)
577 {
578 DllLocation = fi.FullName;
579 }
580 }
581
582 PrintingCreator Creator = null;
583 if (DllLocation == string.Empty)
584 {
585 this.m_PrintingObject = new Printing();
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 }
600 //************************************************
601
602 //User Interface Culture (m_CultureName is set from the command line flag /culture)
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 }
616
617 _dal = new DAL(RemoteSession); // Data access layer
618
619 //Create global dataset
620 _current.m_dsGlobal = new DataSet("GlobalDataSet");
621
622 //Version info
623 // Table #1
624 setProgressDelegate(1);
625 setStatusDelegate("Getting Version Info from Server...");
626
627 DataTable ver = _dal.GetVersion("BSDX");
628 ver.TableName = "VersionInfo";
629 m_dsGlobal.Tables.Add(ver);
630
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);
639
640 //Make sure that the server is running the same version the client is.
641 Version x = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
642
643 //if version numbers mismatch, don't continue.
644 if (!(x.Major.ToString() == sMajor && x.Minor.ToString() == sMinor))
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");
651 closeSplashDelegate();
652 return false;
653 }
654
655
656 //Change encoding
657 // Call #2
658 setProgressDelegate(2);
659 setStatusDelegate("Setting encoding...");
660 //PORT TODO: Set encoding
661 if (m_Encoding == String.Empty)
662 {
663 string utf8_server_support = RemoteSession.TransmitRPC("BMX UTF-8", "");
664
665 if (utf8_server_support == "1")
666 RemoteSession.ConnectionEncoding = System.Text.UTF8Encoding.UTF8;
667
668 }
669
670 //Set application context
671 // Call #3
672 setProgressDelegate(3);
673 setStatusDelegate("Setting Application Context to BSDXRPC...");
674 RemoteSession.AppContext = "BSDXRPC";
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
680 _current.UserPreferences = new UserPreferences(); // Constructor Does the calling to do that...
681
682 //Load global recordsets
683 string statusConst = "Loading VistA data tables...";
684 setStatusDelegate(statusConst);
685
686 string sCommandText;
687
688 //Schedule User Info
689 // Table #4
690 setProgressDelegate(6);
691 setStatusDelegate(statusConst + " Schedule User");
692 DataTable dtUser = _dal.GetUserInfo(RemoteSession.User.Duz);
693 dtUser.TableName = "SchedulingUser";
694 m_dsGlobal.Tables.Add(dtUser);
695 Debug.Assert(dtUser.Rows.Count == 1);
696
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;
702
703 //Get Access Types
704 // Table #5
705 setProgressDelegate(7);
706 setStatusDelegate(statusConst + " Access Types");
707 DataTable dtAccessTypes = _dal.GetAccessTypes(m_dsGlobal, "AccessTypes");
708
709 //Get Access Groups
710 // Table #6
711 setProgressDelegate(8);
712 setStatusDelegate(statusConst + " Access Groups");
713 LoadAccessGroupsTable();
714
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
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.
725 // Table #7
726 setProgressDelegate(9);
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
743 //ResourceGroup Table (Resource Groups by User)
744 // Table #8
745 // What shows up on the tree. The groups the user has access to.
746 setProgressDelegate(10);
747 setStatusDelegate(statusConst + " Resource Groups By User");
748 LoadResourceGroupTable();
749
750 //Resources by user
751 // Table #9
752 // Individual Resources
753 setProgressDelegate(11);
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
762 //GroupResources table
763 // Table #10
764 // Resource Groups and Indivdual Resources together
765 setProgressDelegate(12);
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
778
779 m_dsGlobal.Relations.Add(dr);
780
781 //HospitalLocation table
782 //Table #11
783 setProgressDelegate(13);
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";
787 RemoteSession.TableFromCommand(sCommandText, m_dsGlobal, "HospitalLocation");
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
802 //Build ScheduleUser table
803 //Table #12
804 setProgressDelegate(14);
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
814 //Build ResourceUser table
815 //Table #13
816 //Acess to Resources by [this] User
817 setProgressDelegate(15);
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
833 //Build active provider table
834 //Table #14
835 //TODO: Lazy load the provider table; no need to load in advance.
836 setProgressDelegate(16);
837 setStatusDelegate(statusConst + " Providers");
838 sCommandText = "SELECT BMXIEN, NAME FROM NEW_PERSON WHERE INACTIVE_DATE = '' AND BMXIEN > 1";
839 RemoteSession.TableFromSQL(sCommandText, m_dsGlobal, "Provider");
840 Debug.Write("LoadGlobalRecordsets -- Provider loaded\n");
841
842 //Build the HOLIDAY table
843 //Table #15
844 setProgressDelegate(17);
845 setStatusDelegate(statusConst + " Holiday");
846 sCommandText = "SELECT NAME, DATE FROM HOLIDAY WHERE INTERNAL[DATE] > '" + FMDateTime.Create(DateTime.Today).DateOnly.FMDateString + "'";
847 RemoteSession.TableFromSQL(sCommandText, m_dsGlobal, "HOLIDAY");
848 Debug.Write("LoadingGlobalRecordsets -- Holidays loaded\n");
849
850
851 //Save the xml schema
852 //m_dsGlobal.WriteXmlSchema(@"..\..\csSchema20060526.xsd");
853 //----------------------------------------------
854
855 setStatusDelegate("Setting Receive Timeout");
856 _current.RemoteSession.ReceiveTimeout = 30000; //30-second timeout
857
858#if DEBUG
859 _current.RemoteSession.ReceiveTimeout = 600000; //longer timeout for debugging
860#endif
861 // Event Subsriptions
862 setStatusDelegate("Subscribing to Server Events");
863 //Table #16
864 setProgressDelegate(18);
865 _current.RemoteSession.EventServices.Subscribe("BSDX SCHEDULE");
866 //Table #17
867 setProgressDelegate(19);
868 _current.RemoteSession.EventServices.Subscribe("BSDX CALL WORKSTATIONS");
869 //Table #18
870 setProgressDelegate(20);
871 _current.RemoteSession.EventServices.Subscribe("BSDX ADMIN MESSAGE");
872 //Table #19
873 setProgressDelegate(21);
874 _current.RemoteSession.EventServices.Subscribe("BSDX ADMIN SHUTDOWN");
875
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
881
882 //Close Splash Screen
883 closeSplashDelegate();
884
885 return true;
886
887 }
888
889
890
891 public void LoadAccessGroupsTable()
892 {
893 string sCommandText = "SELECT * FROM BSDX_ACCESS_GROUP";
894 RemoteSession.TableFromSQL(sCommandText, m_dsGlobal, "AccessGroup");
895 Debug.Write("LoadGlobalRecordsets -- AccessGroups loaded\n");
896 }
897
898 public void LoadAccessGroupTypesTable()
899 {
900 string sCommandText = "BSDX GET ACCESS GROUP TYPES";
901 RemoteSession.TableFromCommand(sCommandText, m_dsGlobal, "AccessGroupType");
902 Debug.Write("LoadGlobalRecordsets -- AccessGroupTypes loaded\n");
903 }
904
905 public void LoadBSDXResourcesTable()
906 {
907 string sCommandText = "BSDX RESOURCES^" + RemoteSession.User.Duz;
908 RemoteSession.TableFromCommand(sCommandText, m_dsGlobal, "Resources");
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
918 string sCommandText = "BSDX RESOURCE GROUPS BY USER^" + RemoteSession.User.Duz;
919 RemoteSession.TableFromCommand(sCommandText, m_dsGlobal, "ResourceGroup");
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
930 string sCommandText = "BSDX GROUP RESOURCE^" + RemoteSession.User.Duz;
931 RemoteSession.TableFromCommand(sCommandText, m_dsGlobal, "GroupResources");
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";
940 RemoteSession.TableFromCommand(sCommandText, m_dsGlobal, "ScheduleUser");
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 {
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 {
959 sCommandText += String.Format(" WHERE INTERNAL[USERNAME] = {0}", RemoteSession.User.Duz);
960 }
961
962 RemoteSession.TableFromSQL(sCommandText, m_dsGlobal, "ResourceUser");
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
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>
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 {
1077 RemoteSession.EventServices.IsEventPollingEnabled = false;
1078 RemoteSession.EventServices.Unsubscribe("BSDX SCHEDULE");
1079 RemoteSession.Close();
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 {
1092 RemoteSession.Close();
1093 Application.Exit();
1094 }
1095 }
1096
1097 /// <summary>
1098 /// Not used
1099 /// </summary>
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
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>
1216 private void mnuRPMSServer_Click(object sender, EventArgs e)
1217 {
1218 //Warn that changing servers will close all schedules
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)
1220 return;
1221
1222 //Reconnect to RPMS and recreate all global recordsets
1223 try
1224 {
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
1227 m_bExitOK = false;
1228 CloseAll();
1229 m_bExitOK = true;
1230
1231 //Used in Do loop
1232 //bool bRetry = true;
1233
1234 /*// Do Loop to deal with changing the server and the vagaries of user choices.
1235 do
1236 {
1237 try
1238 {
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
1243 LoginProcess login = this.WinFramework.CreateLoginProcess();
1244 login.AttemptUserInputLogin("ReLog-in", 3, true, null);
1245 bRetry = false;
1246 }
1247 catch (Exception ex)
1248 {
1249 if (ex.Message == "User cancelled.")
1250 {
1251 bRetry = false;
1252 Application.Exit();
1253 return;
1254 }
1255 if (MessageBox.Show("Unable to connect to VistA. " + ex.Message , "Clinical Scheduling", MessageBoxButtons.RetryCancel) == DialogResult.Retry)
1256 {
1257 bRetry = true;
1258 }
1259 else
1260 {
1261 bRetry = false;
1262 Application.Exit();
1263 return;
1264 }
1265 }
1266 } while (bRetry == true);
1267 */
1268
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);
1271
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 }
1278
1279 //Otherwise, everything is okay. So open document and view, then show and activate view.
1280 CGDocument doc = new CGDocument();
1281 doc.DocManager = _current;
1282
1283 CGView view = new CGView();
1284 view.InitializeDocView(doc, _current, doc.StartDate, _current.WindowText);
1285
1286 view.Show();
1287 view.Activate();
1288
1289 //Application.Run need not be called b/c it is already running.
1290 }
1291 catch (Exception ex)
1292 {
1293 throw ex;
1294 }
1295
1296 }
1297
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>
1303 private void mnuRPMSLogin_Click(object sender, EventArgs e)
1304 {
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
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)
1310 return;
1311
1312 //Reconnect to RPMS and recreate all global recordsets
1313 try
1314 {
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
1317 m_bExitOK = false;
1318 CloseAll();
1319 m_bExitOK = true;
1320
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
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();
1354 view.InitializeDocView(doc, _current, doc.StartDate, _current.WindowText);
1355
1356 view.Show();
1357 view.Activate();
1358
1359 //Application.Run need not be called b/c it is already running.
1360 }
1361 catch (Exception ex)
1362 {
1363 throw ex;
1364 }
1365 */
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
1377 MessageBox.Show(sMsg, "Clinical Scheduling Administrator -- System Shutdown Notification", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
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
1411 public delegate DataTable RPMSDataTableDelegate(string CommandString, string TableName);
1412
1413 public DataTable RPMSDataTable(string sSQL, string sTableName)
1414 {
1415 //Retrieves a recordset from RPMS
1416 string sErrorMessage = "";
1417 DataTable dtOut;
1418
1419 try
1420 {
1421 //System.IntPtr pHandle = this.Handle;
1422 RPMSDataTableDelegate rdtd = new RPMSDataTableDelegate(RemoteSession.TableFromCommand);
1423 //dtOut = (DataTable) this.Invoke(rdtd, new object[] {sSQL, sTableName});
1424 dtOut = RemoteSession.TableFromCommand(sSQL);
1425 dtOut.TableName = sTableName;
1426
1427 }
1428
1429 catch (Exception ex)
1430 {
1431 sErrorMessage = "CGDocumentManager.RPMSDataTable error: " + ex.Message;
1432 throw ex;
1433 }
1434
1435 return dtOut;
1436
1437 }
1438
1439 public void ChangeDivision(System.Windows.Forms.Form frmCaller)
1440 {
1441 WinFramework.AttemptUserInputSetDivision("Change Division", frmCaller);
1442
1443 RemoteSession = WinFramework.PrimaryRemoteSession;
1444
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}
Note: See TracBrowser for help on using the repository browser.