Exemple #1
0
 private void FormOpenDental_Load(object sender, System.EventArgs e)
 {
     Splash.Dispose();
     Version versionOd=Assembly.GetAssembly(typeof(FormOpenDental)).GetName().Version;
     Version versionObBus=Assembly.GetAssembly(typeof(Db)).GetName().Version;
     if(versionOd!=versionObBus) {
         MessageBox.Show("Mismatched program file versions. Please run the Open Dental setup file again on this computer.");//No MsgBox or Lan.g() here, because we don't want to access the database if there is a version conflict.
         Application.Exit();
         return;
     }
     allNeutral();
     string odUser="";
     string odPassHash="";
     string webServiceUri="";
     YN webServiceIsEcw=YN.Unknown;
     string odPassword="";
     string serverName="";
     string databaseName="";
     string mySqlUser="";
     string mySqlPassword="";
     if(CommandLineArgs.Length!=0) {
         for(int i=0;i<CommandLineArgs.Length;i++) {
             if(CommandLineArgs[i].StartsWith("UserName=") && CommandLineArgs[i].Length>9) {
                 odUser=CommandLineArgs[i].Substring(9).Trim('"');
             }
             if(CommandLineArgs[i].StartsWith("PassHash=") && CommandLineArgs[i].Length>9) {
                 odPassHash=CommandLineArgs[i].Substring(9).Trim('"');
             }
             if(CommandLineArgs[i].StartsWith("WebServiceUri=") && CommandLineArgs[i].Length>14) {
                 webServiceUri=CommandLineArgs[i].Substring(14).Trim('"');
             }
             if(CommandLineArgs[i].StartsWith("WebServiceIsEcw=") && CommandLineArgs[i].Length>16) {
                 if(CommandLineArgs[i].Substring(16).Trim('"')=="True") {
                     webServiceIsEcw=YN.Yes;
                 }
                 else {
                     webServiceIsEcw=YN.No;
                 }
             }
             if(CommandLineArgs[i].StartsWith("OdPassword=") && CommandLineArgs[i].Length>11) {
                 odPassword=CommandLineArgs[i].Substring(11).Trim('"');
             }
             if(CommandLineArgs[i].StartsWith("ServerName=") && CommandLineArgs[i].Length>11) {
                 serverName=CommandLineArgs[i].Substring(11).Trim('"');
             }
             if(CommandLineArgs[i].StartsWith("DatabaseName=") && CommandLineArgs[i].Length>13) {
                 databaseName=CommandLineArgs[i].Substring(13).Trim('"');
             }
             if(CommandLineArgs[i].StartsWith("MySqlUser=") && CommandLineArgs[i].Length>10) {
                 mySqlUser=CommandLineArgs[i].Substring(10).Trim('"');
             }
             if(CommandLineArgs[i].StartsWith("MySqlPassword=") && CommandLineArgs[i].Length>14) {
                 mySqlPassword=CommandLineArgs[i].Substring(14).Trim('"');
             }
         }
     }
     YN noShow=YN.Unknown;
     if(webServiceUri!=""){//a web service was specified
         if(odUser!="" && odPassword!=""){//and both a username and password were specified
             noShow=YN.Yes;
         }
     }
     else if(databaseName!=""){
         noShow=YN.Yes;
     }
     FormChooseDatabase formChooseDb=new FormChooseDatabase();
     formChooseDb.OdUser=odUser;
     formChooseDb.OdPassHash=odPassHash;
     formChooseDb.WebServiceUri=webServiceUri;
     formChooseDb.WebServiceIsEcw=webServiceIsEcw;
     formChooseDb.OdPassword=odPassword;
     formChooseDb.ServerName=serverName;
     formChooseDb.DatabaseName=databaseName;
     formChooseDb.MySqlUser=mySqlUser;
     formChooseDb.MySqlPassword=mySqlPassword;
     formChooseDb.NoShow=noShow;//either unknown or yes
     formChooseDb.GetConfig();
     formChooseDb.GetCmdLine();
     while(true) {//Most users will loop through once.  If user tries to connect to a db with replication failure, they will loop through again.
         if(formChooseDb.NoShow==YN.Yes) {
             if(!formChooseDb.TryToConnect()) {
                 formChooseDb.ShowDialog();
                 if(formChooseDb.DialogResult==DialogResult.Cancel) {
                     Application.Exit();
                     return;
                 }
             }
         }
         else {
             formChooseDb.ShowDialog();
             if(formChooseDb.DialogResult==DialogResult.Cancel) {
                 Application.Exit();
                 return;
             }
         }
         Cursor=Cursors.WaitCursor;
         Splash=new FormSplash();
         if(CommandLineArgs.Length==0) {
             Splash.Show();
         }
         if(!PrefsStartup()){//looks for the AtoZ folder here, but would like to eventually move that down to after login
             Cursor=Cursors.Default;
             Splash.Dispose();
             Application.Exit();
             return;
         }
         if(ReplicationServers.Server_id!=0 && ReplicationServers.Server_id==PrefC.GetInt(PrefName.ReplicationFailureAtServer_id)) {
             MsgBox.Show(this,"This database is temporarily unavailable.  Please connect instead to your alternate database at the other location.");
             formChooseDb.NoShow=YN.No;//This ensures they will get a choose db window next time through the loop.
             ReplicationServers.Server_id=-1;
             continue;
         }
         break;
     }
     if(Programs.UsingEcwTight()) {
         Splash.Dispose();//We don't show splash screen when bridging to eCW.
     }
     //We no longer do this shotgun approach because it can slow the loading time.
     //RefreshLocalData(InvalidType.AllLocal);
     List<InvalidType> invalidTypes=new List<InvalidType>();
     invalidTypes.Add(InvalidType.Prefs);
     invalidTypes.Add(InvalidType.Defs);
     invalidTypes.Add(InvalidType.Providers);//obviously heavily used
     invalidTypes.Add(InvalidType.Programs);//already done above, but needs to be done explicitly to trigger the PostCleanup
     invalidTypes.Add(InvalidType.ToolBut);//so program buttons will show in all the toolbars
     if(Programs.UsingEcwTight()) {
         lightSignalGrid1.Visible=false;
     }
     else{
         invalidTypes.Add(InvalidType.Signals);//so when mouse moves over light buttons, it won't crash
     }
     Plugins.LoadAllPlugins(this);//moved up from right after optimizing tooth chart graphics.  New position might cause problems.
     //It was moved because RefreshLocalData()=>RefreshLocalDataPostCleanup()=>ContrChart2.InitializeLocalData()=>LayoutToolBar() has a hook.
     RefreshLocalData(invalidTypes.ToArray());
     FillSignalButtons(null);
     ContrManage2.InitializeOnStartup();//so that when a signal is received, it can handle it.
     //Lan.Refresh();//automatically skips if current culture is en-US
     //LanguageForeigns.Refresh(CultureInfo.CurrentCulture);//automatically skips if current culture is en-US
     DataValid.BecameInvalid += new OpenDental.ValidEventHandler(DataValid_BecameInvalid);
     signalLastRefreshed=MiscData.GetNowDateTime();
     if(PrefC.GetInt(PrefName.ProcessSigsIntervalInSecs)==0) {
         timerSignals.Enabled=false;
     }
     else {
         timerSignals.Interval=PrefC.GetInt(PrefName.ProcessSigsIntervalInSecs)*1000;
         timerSignals.Enabled=true;
     }
     timerTimeIndic.Enabled=true;
     myOutlookBar.Buttons[0].Caption=Lan.g(this,"Appts");
     myOutlookBar.Buttons[1].Caption=Lan.g(this,"Family");
     myOutlookBar.Buttons[2].Caption=Lan.g(this,"Account");
     myOutlookBar.Buttons[3].Caption=Lan.g(this,"Treat' Plan");
     //myOutlookBar.Buttons[4].Caption=Lan.g(this,"Chart");//??done in RefreshLocalData
     myOutlookBar.Buttons[5].Caption=Lan.g(this,"Images");
     myOutlookBar.Buttons[6].Caption=Lan.g(this,"Manage");
     foreach(MenuItem menuItem in mainMenu.MenuItems){
         TranslateMenuItem(menuItem);
     }
     if(CultureInfo.CurrentCulture.Name=="en-US"){
         //for the business layer, this functionality is duplicated in the Lan class.  Need for SL.
         CultureInfo cInfo=(CultureInfo)CultureInfo.CurrentCulture.Clone();
         cInfo.DateTimeFormat.ShortDatePattern="MM/dd/yyyy";
         Application.CurrentCulture=cInfo;
         //
         //if(CultureInfo.CurrentCulture.TwoLetterISOLanguageName=="en"){
         menuItemTranslation.Visible=false;
     }
     if(!File.Exists("Help.chm")){
         menuItemHelpWindows.Visible=false;
     }
     if(Environment.OSVersion.Platform==PlatformID.Unix){//Create A to Z unsupported on Unix for now.
         menuItemCreateAtoZFolders.Visible=false;
     }
     if(!PrefC.GetBool(PrefName.ADAdescriptionsReset)) {
         ProcedureCodes.ResetADAdescriptions();
         Prefs.UpdateBool(PrefName.ADAdescriptionsReset,true);
     }
     Splash.Dispose();
     //Choose a default DirectX format when no DirectX format has been specified and running in DirectX tooth chart mode.
     //ComputerPref localComputerPrefs=ComputerPrefs.GetForLocalComputer();
     if(ComputerPrefs.LocalComputer.GraphicsSimple==DrawingMode.DirectX && ComputerPrefs.LocalComputer.DirectXFormat=="") {
         //MessageBox.Show(Lan.g(this,"Optimizing tooth chart graphics. This may take a few minutes. You will be notified when the process is complete."));
         ComputerPrefs.LocalComputer.DirectXFormat=FormGraphics.GetPreferredDirectXFormat(this);
         if(ComputerPrefs.LocalComputer.DirectXFormat=="invalid") {
             //No valid local DirectX format could be found.
             //Simply revert to OpenGL.
             ComputerPrefs.LocalComputer.GraphicsSimple=DrawingMode.OpenGL;
         }
         ComputerPrefs.Update(ComputerPrefs.LocalComputer);
         ContrChart2.InitializeOnStartup();
         //MsgBox.Show(this,"Done optimizing tooth chart graphics.");
     }
     if(Security.CurUser==null) {//It could already be set if using web service because login from ChooseDatabase window.
         if(Programs.UsingEcwTight() && odUser!="") {//only leave it null if a user was passed in on the commandline.  If starting OD manually, it will jump into the else.
             //leave user as null
         }
         else {
             if(odUser!="" && odPassword!=""){//if a username and password were passed in
                 Userod user=Userods.GetUserByName(odUser,Programs.UsingEcwTight());
                 if(user!=null){
                     if(Userods.CheckTypedPassword(odPassword,user.Password)){//password matches
                         Security.CurUser=user.Copy();
                         if(RemotingClient.RemotingRole==RemotingRole.ClientWeb){
                             string pw=odPassword;
                             if(Programs.UsingEcwTight()) {//ecw requires hash, but non-ecw requires actual password
                                 pw=Userods.EncryptPassword(pw,true);
                             }
                             Security.PasswordTyped=pw;
                         }
                         //TasksCheckOnStartup is one thing that doesn't get done because login window wasn't used
                     }
                 }
             }
             if(Security.CurUser==null) {//normal manual log in process
                 Userod adminUser=Userods.GetAdminUser();
                 if(adminUser.Password=="") {
                     Security.CurUser=adminUser.Copy();
                 }
                 else {
                     FormLogOn_=new FormLogOn();
                     FormLogOn_.ShowDialog(this);
                     if(FormLogOn_.DialogResult==DialogResult.Cancel) {
                         Cursor=Cursors.Default;
                         Application.Exit();
                         return;
                     }
                 }
             }
         }
     }
     if(userControlTasks1.Visible) {
         userControlTasks1.InitializeOnStartup();
     }
     myOutlookBar.SelectedIndex=Security.GetModule(0);//for eCW, this fails silently.
     if(Programs.UsingEcwTight()) {
         myOutlookBar.SelectedIndex=4;//Chart module
         //ToolBarMain.Height=0;//this should force the modules further up on the screen
         //ToolBarMain.Visible=false;
         LayoutControls();
     }
     if(Programs.UsingOrion) {
         myOutlookBar.SelectedIndex=1;//Family module
     }
     myOutlookBar.Invalidate();
     LayoutToolBar();
     SetModuleSelected();
     Cursor=Cursors.Default;
     if(myOutlookBar.SelectedIndex==-1){
         MsgBox.Show(this,"You do not have permission to use any modules.");
     }
     Bridges.Trojan.StartupCheck();
     FormUAppoint.StartThreadIfEnabled();
     Bridges.ICat.StartFileWatcher();
     if(PrefC.GetBool(PrefName.DockPhonePanelShow)){
         #if !DEBUG
             if(Process.GetProcessesByName("WebCamOD").Length==0) {
                 try {
                     Process.Start("WebCamOD.exe");
                 }
                 catch { }//for example, if working from home.
             }
         #endif
     }
     #if !TRIALONLY
         if(PrefC.GetDate(PrefName.BackupReminderLastDateRun).AddMonths(1)<DateTime.Today) {
             FormBackupReminder FormBR=new FormBackupReminder();
             FormBR.ShowDialog();
             if(FormBR.DialogResult==DialogResult.OK){
                 Prefs.UpdateDateT(PrefName.BackupReminderLastDateRun,DateTime.Today);
             }
             else{
                 Application.Exit();
                 return;
             }
         }
     #endif
     FillPatientButton(0,"",false,"",0);
     ThreadCommandLine=new Thread(new ThreadStart(Listen));
     if(!IsSecondInstance) {//can't use a port that's already in use.
         //js We can't do this yet.  I tried it already, and it consumes nearly 100% CPU.  Not while testing, but later.
         //So until we really need to do it, it's easiest no just not start the thread for now.
         //ThreadCommandLine.Start();
     }
     //if(CommandLineArgs.Length>0) {
     ProcessCommandLine(CommandLineArgs);
     //}
     try {
         Computers.UpdateHeartBeat(Environment.MachineName);
     }
     catch { }
     string dllPathEHR=ODFileUtils.CombinePaths(Application.StartupPath,"EHR.dll");
     if(PrefC.GetBoolSilent(PrefName.ShowFeatureEhr,false)) {
         #if EHRTEST
             FormEHR=new FormEHR();
             ContrChart2.InitializeLocalData();//because toolbar is now missing the EHR button.  Only a problem if a db conversion is done when opening the program.
         #else
             FormEHR=null;
             AssemblyEHR=null;
             if(File.Exists(dllPathEHR)) {//EHR.dll is available, so load it up
                 AssemblyEHR=Assembly.LoadFile(dllPathEHR);
                 Type type=AssemblyEHR.GetType("EHR.FormEHR");//namespace.class
                 FormEHR=Activator.CreateInstance(type);
             }
         #endif
     }
     dateTimeLastActivity=DateTime.Now;
     timerLogoff.Enabled=true;
     timerReplicationMonitor.Enabled=true;
     Plugins.HookAddCode(this,"FormOpenDental.Load_end");
 }
		private void Tool_EHR_Click(bool onLoadShowOrders) {
			//Quarterly key check was removed from here so that any customer can use EHR tools
			//But we require a EHR subscription for them to obtain their MU reports.
			FormEHR FormE = new FormEHR();
			FormE.PatNum=PatCur.PatNum;
			FormE.PatNotCur=PatientNoteCur;
			FormE.PatFamCur=FamCur;
			FormE.ShowDialog();
			if(FormE.DialogResult!=DialogResult.OK) {
				return;
			}
			if(FormE.ResultOnClosing==EhrFormResult.PatientSelect) {
				OnPatientSelected(Patients.GetPat(FormE.PatNum));
				ModuleSelected(FormE.PatNum);
			}
		}