Beispiel #1
0
        /// <summary>Will only convert to MyISAM if default storage engine set to MyISAM.</summary>
        private void butToMyIsam_Click(object sender, EventArgs e)
        {
            if (!MsgBox.Show(this, MsgBoxButtons.OKCancel, "This will convert all tables in the database to the MyISAM storage engine.  This may take several minutes.\r\nContinue?"))
            {
                return;
            }
            if (InnoDb.GetDefaultEngine() == "InnoDB")
            {
                MsgBoxCopyPaste msgbox = new MsgBoxCopyPaste(
                    Lan.g("FormInnoDB", "You will first need to change your default storage engine to MyISAM.  Make sure that the following line is in your my.ini file: \r\n"
                          + "default-storage-engine=MyISAM.\r\n"
                          + "Then, restart the MySQL service and return here."));
                msgbox.ShowDialog();
                return;
            }
            if (!Shared.MakeABackup(BackupLocation.InnoDbTool))
            {
                return;                //A message has already shown that the backup failed.
            }
            Cursor         = Cursors.WaitCursor;
            textBox1.Text += Lans.g("FormInnoDb", "Default Storage Engine: " + InnoDb.GetDefaultEngine().ToString() + "\r\n");
            Application.DoEvents();
            int numchanged = InnoDb.ConvertTables("InnoDB", "MyISAM");

            textBox1.Text += Lan.g("FormInnoDb", "Number of tables converted to MyISAM: ") + numchanged.ToString() + "\r\n";
            Application.DoEvents();
            textBox1.Text += InnoDb.GetEngineCount();
            Application.DoEvents();
            Cursor = Cursors.Default;
        }
Beispiel #2
0
        private void FormInnoDb_Load(object sender, EventArgs e)
        {
            Cursor = Cursors.WaitCursor;
            StringBuilder strB = new StringBuilder();

            strB.Append('-', 60);
            textBox1.Text = DateTime.Now.ToString() + strB.ToString() + "\r\n";
            Application.DoEvents();
            textBox1.Text += Lans.g("FormInnoDb", "Default Storage Engine: " + InnoDb.GetDefaultEngine().ToString() + "\r\n");
            Application.DoEvents();
            textBox1.Text += InnoDb.GetEngineCount();
            Application.DoEvents();
            Cursor = Cursors.Default;
        }
Beispiel #3
0
        /// <summary>Will only convert to InnoDB if default storage engine set to InnoDB and skip-innodb is not in my.ini file, which disables InnoDB engine.</summary>
        private void butToInnoDb_Click(object sender, EventArgs e)
        {
            if (!MsgBox.Show(this, MsgBoxButtons.OKCancel, "This will convert all tables in the database to the InnoDB storage engine.  This may take several minutes.\r\nContinue?"))
            {
                return;
            }
            if (!InnoDb.IsInnodbAvail())
            {
                MsgBoxCopyPaste msgbox = new MsgBoxCopyPaste(
                    Lan.g("FormInnoDb", "InnoDB storage engine is disabled.  In order for InnoDB tables to work you must comment out the skip-innodb line in your my.ini file, like this:\r\n"
                          + "#skip-innodb\r\n"
                          + "and, if present, comment out the default-storage-engine line like this: \r\n"
                          + "#default-storage-engine=MyISAM.\r\n"
                          + "Then, restart the MySQL service and return here."));
                msgbox.ShowDialog();
                return;
            }
            if (InnoDb.GetDefaultEngine() == "MyISAM")
            {
                MsgBoxCopyPaste msgbox = new MsgBoxCopyPaste(
                    Lan.g("FormInnoDB", "You will first need to change your default storage engine to InnoDB.  In your my.ini file, comment out the default-storage-engine line like this: \r\n"
                          + "#default-storage-engine=MyISAM.\r\n"
                          + "Then, restart the MySQL service and return here."));
                msgbox.ShowDialog();
                return;
            }
            try {
                MiscData.MakeABackup();
            }
            catch (Exception ex) {
                if (ex.Message != "")
                {
                    MessageBox.Show(ex.Message);
                }
                MsgBox.Show("FormInnoDb", "Backup failed. Your database has not been altered.");
                return;
            }
            Cursor         = Cursors.WaitCursor;
            textBox1.Text += Lans.g("FormInnoDb", "Default Storage Engine: " + InnoDb.GetDefaultEngine().ToString() + "\r\n");
            Application.DoEvents();
            int numchanged = InnoDb.ConvertTables("MyISAM", "InnoDB");

            textBox1.Text += Lan.g("FormInnoDb", "Number of tables converted to InnoDB: ") + numchanged.ToString() + "\r\n";
            Application.DoEvents();
            textBox1.Text += InnoDb.GetEngineCount();
            Application.DoEvents();
            Cursor = Cursors.Default;
        }
        ///<summary>Return false to indicate exit app.  Only called when program first starts up at the beginning of FormOpenDental.PrefsStartup.</summary>
        public bool Convert(string fromVersion, string toVersion, bool isSilent, Form currentForm = null)
        {
            FromVersion = new Version(fromVersion);
            ToVersion   = new Version(toVersion);        //Application.ProductVersion);
            if (FromVersion >= new Version("3.4.0") && PrefC.GetBool(PrefName.CorruptedDatabase))
            {
                FormOpenDental.ExitCode = 201;              //Database was corrupted due to an update failure
                if (!isSilent)
                {
                    MsgBox.Show(this, "Your database is corrupted because an update failed.  Please contact us.  This database is unusable and you will need to restore from a backup.");
                }
                return(false);               //shuts program down.
            }
            if (FromVersion == ToVersion)
            {
                return(true);                         //no conversion necessary
            }
            if (FromVersion.CompareTo(ToVersion) > 0) //"Cannot convert database to an older version."
            //no longer necessary to catch it here.  It will be handled soon enough in CheckProgramVersion
            {
                return(true);
            }
            if (FromVersion < new Version("2.8.0"))
            {
                FormOpenDental.ExitCode = 130;              //Database must be upgraded to 2.8 to continue
                if (!isSilent)
                {
                    MsgBox.Show(this, "This database is too old to easily convert in one step. Please upgrade to 2.1 if necessary, then to 2.8.  Then you will be able to upgrade to this version. We apologize for the inconvenience.");
                }
                return(false);
            }
            if (FromVersion < new Version("6.6.2"))
            {
                FormOpenDental.ExitCode = 131;              //Database must be upgraded to 11.1 to continue
                if (!isSilent)
                {
                    MsgBox.Show(this, "This database is too old to easily convert in one step. Please upgrade to 11.1 first.  Then you will be able to upgrade to this version. We apologize for the inconvenience.");
                }
                return(false);
            }
            if (FromVersion < new Version("3.0.1"))
            {
                if (!isSilent)
                {
                    MsgBox.Show(this, "This is an old database.  The conversion must be done using MySQL 4.1 (not MySQL 5.0) or it will fail.");
                }
            }
            if (FromVersion.ToString() == "2.9.0.0" || FromVersion.ToString() == "3.0.0.0" || FromVersion.ToString() == "4.7.0.0")
            {
                FormOpenDental.ExitCode = 190;              //Cannot convert this database version which was only for development purposes
                if (!isSilent)
                {
                    MsgBox.Show(this, "Cannot convert this database version which was only for development purposes.");
                }
                return(false);
            }
            if (FromVersion > new Version("4.7.0") && FromVersion.Build == 0)
            {
                FormOpenDental.ExitCode = 190;              //Cannot convert this database version which was only for development purposes
                if (!isSilent)
                {
                    MsgBox.Show(this, "Cannot convert this database version which was only for development purposes.");
                }
                return(false);
            }
            if (FromVersion >= LatestVersion)
            {
                return(true);               //no conversion necessary
            }
            if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
            {
                FormOpenDental.ExitCode = 140;              //Web client cannot convert database
                if (!isSilent)
                {
                    MsgBox.Show(this, "Web client cannot convert database.  Must be using a direct connection.");
                }
                return(false);
            }
            if (ReplicationServers.ServerIsBlocked())
            {
                FormOpenDental.ExitCode = 150;              //Replication server is blocked from performing updates
                if (!isSilent)
                {
                    MsgBox.Show(this, "This replication server is blocked from performing updates.");
                }
                return(false);
            }
#if TRIALONLY
            //Trial users should never be able to update a database.
            if (PrefC.GetString(PrefName.RegistrationKey) != "") //Allow databases with no reg key to update.  Needed by our conversion department.
            {
                FormOpenDental.ExitCode = 191;                   //Trial versions cannot connect to live databases
                if (!isSilent)
                {
                    MsgBox.Show(this, "Trial versions cannot connect to live databases.  Please run the Setup.exe in the AtoZ folder to reinstall your original version.");
                }
                return(false);
            }
#endif
            if (PrefC.GetString(PrefName.WebServiceServerName) != "" &&       //using web service
                !ODEnvironment.IdIsThisComputer(PrefC.GetString(PrefName.WebServiceServerName).ToLower()))                   //and not on web server
            {
                if (isSilent)
                {
                    FormOpenDental.ExitCode = 141;   //Updates are only allowed from a designated web server
                    return(false);                   //if you are in debug mode and you really need to update the DB, you can manually clear the WebServiceServerName preference.
                }
                //This will be handled in CheckProgramVersion, giving the user option to downgrade or exit program.
                return(true);
            }
            //If MyISAM and InnoDb mix, then try to fix
            if (DataConnection.DBtype == DatabaseType.MySql)           //not for Oracle
            {
                string namesInnodb = InnoDb.GetInnodbTableNames();     //Or possibly some other format.
                int    numMyisam   = DatabaseMaintenances.GetMyisamTableCount();
                if (namesInnodb != "" && numMyisam > 0)
                {
                    if (!isSilent)
                    {
                        MessageBox.Show(Lan.g(this, "A mixture of database tables in InnoDB and MyISAM format were found.  A database backup will now be made, and then the following InnoDB tables will be converted to MyISAM format: ") + namesInnodb);
                    }
                    if (!Shared.MakeABackup(isSilent, BackupLocation.ConvertScript, false))
                    {
                        Cursor.Current          = Cursors.Default;
                        FormOpenDental.ExitCode = 101;                      //Database Backup failed
                        return(false);
                    }
                    if (!DatabaseMaintenances.ConvertTablesToMyisam())
                    {
                        FormOpenDental.ExitCode = 102;                      //Failed to convert InnoDB tables to MyISAM format
                        if (!isSilent)
                        {
                            MessageBox.Show(Lan.g(this, "Failed to convert InnoDB tables to MyISAM format. Please contact support."));
                        }
                        return(false);
                    }
                    if (!isSilent)
                    {
                        MessageBox.Show(Lan.g(this, "All tables converted to MyISAM format successfully."));
                    }
                    namesInnodb = "";
                }
                if (namesInnodb == "" && numMyisam > 0)             //if all tables are myisam
                //but default storage engine is innodb, then kick them out.
                {
                    if (DatabaseMaintenances.GetStorageEngineDefaultName().ToUpper() != "MYISAM") //Probably InnoDB but could be another format.
                    {
                        FormOpenDental.ExitCode = 103;                                            //Default database .ini setting is innoDB
                        if (!isSilent)
                        {
                            MessageBox.Show(Lan.g(this, "The database tables are in MyISAM format, but the default database engine format is InnoDB. You must change the default storage engine within the my.ini (or my.cnf) file on the database server and restart MySQL in order to fix this problem. Exiting."));
                        }
                        return(false);
                    }
                }
            }
#if DEBUG
            if (!isSilent && MessageBox.Show("You are in Debug mode.  Your database can now be converted" + "\r"
                                             + "from version" + " " + FromVersion.ToString() + "\r"
                                             + "to version" + " " + ToVersion.ToString() + "\r"
                                             + "You can click Cancel to skip conversion and attempt to run the newer code against the older database."
                                             , "", MessageBoxButtons.OKCancel) != DialogResult.OK)
            {
                return(true);               //If user clicks cancel, then do nothing
            }
#else
            if (!isSilent && MessageBox.Show(Lan.g(this, "Your database will now be converted") + "\r"
                                             + Lan.g(this, "from version") + " " + FromVersion.ToString() + "\r"
                                             + Lan.g(this, "to version") + " " + ToVersion.ToString() + "\r"
                                             + Lan.g(this, "The conversion works best if you are on the server.  Depending on the speed of your computer, it can be as fast as a few seconds, or it can take as long as 10 minutes.")
                                             , "", MessageBoxButtons.OKCancel) != DialogResult.OK)
            {
                return(false);               //If user clicks cancel, then close the program
            }
#endif
            Cursor.Current = Cursors.WaitCursor;
            Action actionCloseConvertProgress = null;
#if !DEBUG
            if (!isSilent)
            {
                if (DataConnection.DBtype != DatabaseType.MySql &&
                    !MsgBox.Show(this, true, "If you have not made a backup, please Cancel and backup before continuing.  Continue?"))
                {
                    return(false);
                }
            }
            if (DataConnection.DBtype == DatabaseType.MySql)
            {
                if (!Shared.MakeABackup(isSilent, BackupLocation.ConvertScript, false))
                {
                    Cursor.Current          = Cursors.Default;
                    FormOpenDental.ExitCode = 101;                  //Database Backup failed
                    return(false);
                }
            }
            //We've been getting an increasing number of phone calls with databases that have duplicate preferences which is impossible
            //unless a user has gotten this far and another computer in the office is in the middle of an update as well.
            //The issue is most likely due to the blocking messageboxes above which wait indefinitely for user input right before upgrading the database.
            //This means that the cache for this computer could be stale and we need to manually refresh our cache to double check
            //that the database isn't flagged as corrupt, an update isn't in progress, or that the database version hasn't changed (someone successfully updated already).
            Prefs.RefreshCache();
            //Now check the preferences that should stop this computer from executing an update.
            if (PrefC.GetBool(PrefName.CorruptedDatabase) ||
                (PrefC.GetString(PrefName.UpdateInProgressOnComputerName) != "" && PrefC.GetString(PrefName.UpdateInProgressOnComputerName) != Environment.MachineName))
            {
                //At this point, the pref "corrupted database" being true means that a computer is in the middle of running the upgrade script.
                //There will be another corrupted database check on start up which will take care of the scenario where this is truly a corrupted database.
                //Also, we need to make sure that the update in progress preference is set to this computer because we JUST set it to that value before entering this method.
                //If it has changed, we absolutely know without a doubt that another computer is trying to update at the same time.
                FormOpenDental.ExitCode = 142;              //Update is already in progress from another computer
                if (!isSilent)
                {
                    MsgBox.Show(this, "An update is already in progress from another computer.");
                }
                return(false);
            }
            //Double check that the database version has not changed.  This check is here just in case another computer has successfully updated the database already.
            Version versionDatabase = new Version(PrefC.GetString(PrefName.DataBaseVersion));
            if (FromVersion != versionDatabase)
            {
                FormOpenDental.ExitCode = 143;              //Database has already been updated from another computer
                if (!isSilent)
                {
                    MsgBox.Show(this, "The database has already been updated from another computer.");
                }
                return(false);
            }
            try {
#endif
            if (FromVersion < new Version("7.5.17"))                     //Insurance Plan schema conversion
            {
                if (isSilent)
                {
                    FormOpenDental.ExitCode = 139;                          //Update must be done manually to fix Insurance Plan Schema
                    Application.Exit();
                    return(false);
                }
                Cursor.Current = Cursors.Default;
                YN InsPlanConverstion_7_5_17_AutoMergeYN = YN.Unknown;
                if (FromVersion < new Version("7.5.1"))
                {
                    FormInsPlanConvert_7_5_17 form = new FormInsPlanConvert_7_5_17();
                    if (PrefC.GetBoolSilent(PrefName.InsurancePlansShared, true))
                    {
                        form.InsPlanConverstion_7_5_17_AutoMergeYN = YN.Yes;
                    }
                    else
                    {
                        form.InsPlanConverstion_7_5_17_AutoMergeYN = YN.No;
                    }
                    form.ShowDialog();
                    if (form.DialogResult == DialogResult.Cancel)
                    {
                        MessageBox.Show("Your database has not been altered.");
                        return(false);
                    }
                    InsPlanConverstion_7_5_17_AutoMergeYN = form.InsPlanConverstion_7_5_17_AutoMergeYN;
                }
                ConvertDatabases.Set_7_5_17_AutoMerge(InsPlanConverstion_7_5_17_AutoMergeYN);                        //does nothing if this pref is already present for some reason.
                Cursor.Current = Cursors.WaitCursor;
            }
            if (!isSilent && FromVersion > new Version("16.3.0") && FromVersion < new Version("16.3.29") && ApptReminderRules.IsReminders)
            {
                //16.3.29 is more strict about reminder rule setup. Prompt the user and allow them to exit the update if desired.
                //Get all currently enabled reminder rules.
                List <bool> listReminderFlags = ApptReminderRules.Get_16_3_29_ConversionFlags();
                if (listReminderFlags?[0] ?? false)                        //2 reminders scheduled for same day of appointment. 1 will be converted to future day reminder.
                {
                    MsgBox.Show(this, "You have multiple appointment reminders set to send on the same day of the appointment. One of these will be converted to send 1 day prior to the appointment.  Please review automated reminder rule setup after update has finished.");
                }
                if (listReminderFlags?[1] ?? false)                        //2 reminders scheduled for future day of appointment. 1 will be converted to same day reminder.
                {
                    MsgBox.Show(this, "You have multiple appointment reminders set to send 1 or more days prior to the day of the appointment. One of these will be converted to send 1 hour prior to the appointment.  Please review automated reminder rule setup after update has finished.");
                }
            }
            if (FromVersion >= new Version("17.3.1") && FromVersion < new Version("17.3.23") && DataConnection.DBtype == DatabaseType.MySql &&
                (Tasks.HasAnyLongDescripts() || TaskNotes.HasAnyLongNotes() || Commlogs.HasAnyLongNotes()))
            {
                if (isSilent)
                {
                    FormOpenDental.ExitCode = 138;                          //Update must be done manually in order to get data loss notification(s).
                    Application.Exit();
                    return(false);
                }
                if (!MsgBox.Show(this, true, "Data will be lost during this update."
                                 + "\r\nContact support in order to retrieve the data from a backup after the update."
                                 + "\r\n\r\nContinue?"))
                {
                    MessageBox.Show("Your database has not been altered.");
                    return(false);
                }
            }
            if (FromVersion >= new Version("3.4.0"))
            {
                Prefs.UpdateBool(PrefName.CorruptedDatabase, true);
            }
            ConvertDatabases.FromVersion = FromVersion;
#if !DEBUG
            //Typically the UpdateInProgressOnComputerName preference will have already been set within FormUpdate.
            //However, the user could have cancelled out of FormUpdate after successfully downloading the Setup.exe
            //OR the Setup.exe could have been manually sent to our customer (during troubleshooting with HQ).
            //For those scenarios, the preference will be empty at this point and we need to let other computers know that an update going to start.
            //Updating the string (again) here will guarantee that all computers know an update is in fact in progress from this machine.
            Prefs.UpdateString(PrefName.UpdateInProgressOnComputerName, Environment.MachineName);
#endif
            //Show a progress window that will indecate to the user that there is an active update in progress.  Currently okay to show during isSilent.
            actionCloseConvertProgress = ODProgressOld.ShowProgressStatus("ConvertDatabases", hasMinimize: false, currentForm: currentForm);
            ConvertDatabases.To2_8_2();                //begins going through the chain of conversion steps
            InvokeConvertMethods();                    //continues going through the chain of conversion steps starting at v17.1.1 via reflection.
            actionCloseConvertProgress();
            Cursor.Current = Cursors.Default;
            if (FromVersion >= new Version("3.4.0"))
            {
                //CacheL.Refresh(InvalidType.Prefs);//or it won't know it has to update in the next line.
                Prefs.UpdateBool(PrefName.CorruptedDatabase, false, true);                      //more forceful refresh in order to properly change flag
            }
            Cache.Refresh(InvalidType.Prefs);
            if (!isSilent)
            {
                MsgBox.Show(this, "Database update successful");
            }
            return(true);

#if !DEBUG
        }

        catch (System.IO.FileNotFoundException e) {
            actionCloseConvertProgress?.Invoke();
            FormOpenDental.ExitCode = 160;                  //File not found exception
            if (!isSilent)
            {
                MessageBox.Show(e.FileName + " " + Lan.g(this, "could not be found. Your database has not been altered and is still usable if you uninstall this version, then reinstall the previous version."));
            }
            if (FromVersion >= new Version("3.4.0"))
            {
                Prefs.UpdateBool(PrefName.CorruptedDatabase, false);
            }
            return(false);
        }
        catch (System.IO.DirectoryNotFoundException) {
            actionCloseConvertProgress?.Invoke();
            FormOpenDental.ExitCode = 160;                  //ConversionFiles folder could not be found
            if (!isSilent)
            {
                MessageBox.Show(Lan.g(this, "ConversionFiles folder could not be found. Your database has not been altered and is still usable if you uninstall this version, then reinstall the previous version."));
            }
            if (FromVersion >= new Version("3.4.0"))
            {
                Prefs.UpdateBool(PrefName.CorruptedDatabase, false);
            }
            return(false);
        }
        catch (Exception ex) {
            actionCloseConvertProgress?.Invoke();
            FormOpenDental.ExitCode = 201;                  //Database was corrupted due to an update failure
            if (!isSilent)
            {
                MessageBox.Show(ex.Message + "\r\n\r\n"
                                + Lan.g(this, "Conversion unsuccessful. Your database is now corrupted and you cannot use it.  Please contact us."));
            }
            //Then, application will exit, and database will remain tagged as corrupted.
            return(false);
        }
#endif
        }
Beispiel #5
0
        private void butRestore_Click(object sender, System.EventArgs e)
        {
            if (textBackupRestoreFromPath.Text != "" && !textBackupRestoreFromPath.Text.EndsWith("" + Path.DirectorySeparatorChar))
            {
                MessageBox.Show(Lan.g(this, "Paths must end with ") + Path.DirectorySeparatorChar + ".");
                return;
            }
            if (textBackupRestoreToPath.Text != "" && !textBackupRestoreToPath.Text.EndsWith("" + Path.DirectorySeparatorChar))
            {
                MessageBox.Show(Lan.g(this, "Paths must end with ") + Path.DirectorySeparatorChar + ".");
                return;
            }
            if (ShouldUseAtoZFolder())
            {
                if (textBackupRestoreAtoZToPath.Text != "" && !textBackupRestoreAtoZToPath.Text.EndsWith("" + Path.DirectorySeparatorChar))
                {
                    MessageBox.Show(Lan.g(this, "Paths must end with ") + Path.DirectorySeparatorChar + ".");
                    return;
                }
            }
            if (Environment.OSVersion.Platform != PlatformID.Unix)
            {
                //dmg This check will not work on Linux, because mapped drives exist as regular (mounted) paths. Perhaps there
                //is another way to check for this on Linux.
                if (textBackupRestoreToPath.Text != "" && textBackupRestoreToPath.Text.StartsWith("" + Path.DirectorySeparatorChar))
                {
                    MsgBox.Show(this, "The restore database TO folder must be on this computer.");
                    return;
                }
            }
            //pointless to save defaults
            string dbName = MiscData.GetCurrentDatabase();

            if (InnoDb.HasInnoDbTables(dbName))
            {
                //Database has innodb tables. Restore tool does not work on dbs with InnoDb tables.
                MsgBox.Show(this, "InnoDb tables detected. Restore tool cannot run with InnoDb tables.");
                return;
            }
            if (!Directory.Exists(ODFileUtils.CombinePaths(textBackupRestoreFromPath.Text, dbName)))           // D:\opendental
            {
                MessageBox.Show(Lan.g(this, "Restore FROM path is invalid.  Unable to find folder named ") + dbName);
                return;
            }
            if (!Directory.Exists(ODFileUtils.CombinePaths(textBackupRestoreToPath.Text, dbName)))            // C:\mysql\data\opendental
            {
                MessageBox.Show(Lan.g(this, "Restore TO path is invalid.  Unable to find folder named ") + dbName);
                return;
            }
            if (ShouldUseAtoZFolder())
            {
                if (!Directory.Exists(textBackupRestoreAtoZToPath.Text))                 // C:\OpenDentalData\
                {
                    MsgBox.Show(this, "Restore A-Z images TO path is invalid.");
                    return;
                }
                string atozFull = textBackupRestoreAtoZToPath.Text;                                         // C:\OpenDentalData\
                //remove the trailing \
                atozFull = atozFull.Substring(0, atozFull.Length - 1);                                      // C:\OpenDentalData
                string atozDir = atozFull.Substring(atozFull.LastIndexOf(Path.DirectorySeparatorChar) + 1); // OpenDentalData
                if (!Directory.Exists(ODFileUtils.CombinePaths(textBackupRestoreFromPath.Text, atozDir)))   // D:\OpenDentalData
                {
                    MsgBox.Show(this, "Restore A-Z images FROM path is invalid.");
                    return;
                }
            }
            string        fromPath = ODFileUtils.CombinePaths(new string[] { textBackupRestoreFromPath.Text, dbName, "" }); // D:\opendental\
            DirectoryInfo dirInfo  = new DirectoryInfo(fromPath);                                                           //does not check to see if dir exists

            if (MessageBox.Show(Lan.g(this, "Restore from backup created on") + "\r\n"
                                + dirInfo.LastWriteTime.ToString("dddd") + "  " + dirInfo.LastWriteTime.ToString()
                                , "", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel)
            {
                return;
            }
            Cursor = Cursors.WaitCursor;
            //stop the service--------------------------------------------------------------------------------------
            ServiceController sc = new ServiceController("MySQL");

            if (!ServicesHelper.Stop(sc))
            {
                MsgBox.Show(this, "Unable to stop MySQL service.");
                Cursor = Cursors.Default;
                return;
            }
            //rename the current database---------------------------------------------------------------------------
            //Get a name for the new directory
            string newDb = dbName + "backup_" + DateTime.Today.ToString("MM_dd_yyyy");

            if (Directory.Exists(ODFileUtils.CombinePaths(textBackupRestoreToPath.Text, newDb)))           //if the new database name already exists
            //find a unique one
            {
                int    uniqueID      = 1;
                string originalNewDb = newDb;
                do
                {
                    newDb = originalNewDb + "_" + uniqueID.ToString();
                    uniqueID++;
                }while(Directory.Exists(ODFileUtils.CombinePaths(textBackupRestoreToPath.Text, newDb)));
            }
            //move the current db (rename)
            Directory.Move(ODFileUtils.CombinePaths(textBackupRestoreToPath.Text, dbName)
                           , ODFileUtils.CombinePaths(textBackupRestoreToPath.Text, newDb));
            //Restore----------------------------------------------------------------------------------------------
            string toPath = textBackupRestoreToPath.Text;          // C:\mysql\data\

            Directory.CreateDirectory(ODFileUtils.CombinePaths(toPath, dirInfo.Name));
            FileInfo[] files = dirInfo.GetFiles();
            curVal = 0;          //curVal gets increased
            for (int i = 0; i < files.Length; i++)
            {
                File.Copy(files[i].FullName, ODFileUtils.CombinePaths(new string[] { toPath, dirInfo.Name, files[i].Name }));
            }
            //start the service--------------------------------------------------------------------------------------
            ServicesHelper.Start(sc);
            Cursor = Cursors.Default;
            //restore A-Z folder, and give user a chance to cancel it.
            if (ShouldUseAtoZFolder())
            {
                FormP        = new FormProgress();
                FormP.MaxVal = 100;              //We will be setting maxVal from worker thread.  (double)fileSize/1024;
                FormP.NumberMultiplication = 100;
                FormP.DisplayText          = ""; //We will set the text from the worker thread.
                FormP.NumberFormat         = "N1";
                //start the thread that will perform the database copy
                Thread workerThread = new Thread(new ThreadStart(InstanceMethodRestore));
                workerThread.Start();
                //display the progress dialog to the user:
                FormP.ShowDialog();
                if (FormP.DialogResult == DialogResult.Cancel)
                {
                    workerThread.Abort();
                    return;
                }
            }
            Version programVersionDb  = new Version(PrefC.GetStringNoCache(PrefName.ProgramVersion));
            Version programVersionCur = new Version(Application.ProductVersion);

            if (programVersionDb != programVersionCur)
            {
                MsgBox.Show(this, "The restored database version is different than the version installed and requires a restart.  The program will now close.");
                FormOpenDental.S_ProcessKillCommand();
                return;
            }
            else
            {
                DataValid.SetInvalid(Cache.GetAllCachedInvalidTypes().ToArray());
            }
            MsgBox.Show(this, "Done");
            Close();
            return;
        }
Beispiel #6
0
        private void butBackup_Click(object sender, System.EventArgs e)
        {
            if (!IsBackupTabValid())
            {
                return;
            }
            //Ensure that the backup from and backup to paths are different. This is to prevent the live database
            //from becoming corrupt.
            if (this.textBackupFromPath.Text.Trim().ToLower() == this.textBackupToPath.Text.Trim().ToLower())
            {
                MsgBox.Show(this, "The backup from path and backup to path must be different.");
                return;
            }
            //test saving defaults
            if (textBackupFromPath.Text != PrefC.GetString(PrefName.BackupFromPath) ||
                textBackupToPath.Text != PrefC.GetString(PrefName.BackupToPath) ||
                textBackupRestoreFromPath.Text != PrefC.GetString(PrefName.BackupRestoreFromPath) ||
                textBackupRestoreToPath.Text != PrefC.GetString(PrefName.BackupRestoreToPath) ||
                textBackupRestoreAtoZToPath.Text != PrefC.GetString(PrefName.BackupRestoreAtoZToPath))
            {
                if (MsgBox.Show(this, MsgBoxButtons.YesNo, "Set as default?") && SaveTabPrefs())
                {
                    DataValid.SetInvalid(InvalidType.Prefs);
                }
            }
            string dbName = MiscData.GetCurrentDatabase();

            if (InnoDb.HasInnoDbTables(dbName))
            {
                //Database has innodb tables. Backup tool does not work on dbs with InnoDb tables.
                MsgBox.Show(this, "InnoDb tables detected. Backup tool cannot run with InnoDb tables.");
                return;
            }
            if (!Directory.Exists(ODFileUtils.CombinePaths(textBackupFromPath.Text, dbName)))           // C:\mysql\data\opendental
            {
                MsgBox.Show(this, "Backup FROM path is invalid.");
                return;
            }
            if (!Directory.Exists(textBackupToPath.Text))            // D:\
            {
                MsgBox.Show(this, "Backup TO path is invalid.");
                return;
            }
            _errorMessage = "";
            FormP         = new FormProgress();
            FormP.MaxVal  = 100;             //We will be setting maxVal from worker thread.  (double)fileSize/1024;
            FormP.NumberMultiplication = 100;
            FormP.DisplayText          = ""; //We will set the text from the worker thread.
            FormP.NumberFormat         = "N1";
            //start the thread that will perform the database copy
            Thread workerThread = new Thread(new ThreadStart(InstanceMethodBackup));

            workerThread.Start();
            //display the progress dialog to the user:
            FormP.ShowDialog();
            if (FormP.DialogResult == DialogResult.Cancel)
            {
                workerThread.Abort();
                return;
            }
            if (_errorMessage == "")
            {
                SecurityLogs.MakeLogEntry(Permissions.Backup, 0, Lan.g(this, "Database backup created at ") + textBackupToPath.Text);
                MessageBox.Show(Lan.g(this, "Backup complete."));
            }
            else              //Backup failed for some reason.
            {
                MessageBox.Show(_errorMessage);
            }
            Close();
        }