Exemplo n.º 1
0
        /// <summary>
        /// Click event for the File->Close Database menu item
        /// </summary>
        private void menu_FileCloseDatabaseMenuItem_Click(object sender, EventArgs e)
        {
            Mydb.CloseDB();
            GuiPrefs.OpenDBName = "";
            GuiPrefs.OpenDBLoc = "";
            GuiPrefs.OpenDBPath = "";
            lb_Add_CurrentOpenDB.Text = "No Database Loaded";
            lb_S_CurrentOpenDB.Text = "No Database Loaded";
            lb_V_CurrentOpenDB.Text = "No Database Loaded";
            lb_D_CurrentOpenDB.Text = "No Database Loaded";
            lb_R_CurrentOpenDB.Text = "No Database Loaded";

            Enable_AllControls(true);
            Enable_MenuItems(false);
            timer_AutoBackup.Stop();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Click event for the File->Restore menu item
        /// </summary>
        private void menu_FileRestoreMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.InitialDirectory = GuiPrefs.DefaultBackupDir;
            ofd.Filter = "Second Sight Database Files (*.ssd, *.ssb)|*.ssd;*.ssb|All files (*.*)|*.*";
            ofd.Title = "Restore the current database from a backup.";
            ofd.Multiselect = false;
            ofd.CheckFileExists = true;
            ofd.CheckPathExists = true;

            if (!Mydb.IsOpen())
            {
                MessageBox.Show("No database is currently loaded.  Please load a database " +
                                "before attempting to restore a database from a backup.",
                                "No Loaded Database", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            { //If no database is loaded
                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    if (MessageBox.Show("The current database will be permanently replaced with the backup you selected.  Are you sure you want to continue?",
                        "Confirm Restore", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk) == DialogResult.Yes)
                    {
                        string currentdbpath = GuiPrefs.OpenDBPath;
                        try
                        {

                            Mydb.CloseDB();
                            File.Copy(ofd.FileName, currentdbpath, true);
                            Mydb.OpenDB(currentdbpath);
                            MessageBox.Show("The database was successfully restored.",
                                "Restore Successful", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        catch
                        {
                            MessageBox.Show("The database could not be restored.  Make sure you have permission to write to the destination folder.",
                                "Restore Unsuccessful", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        finally
                        {
                            Mydb.OpenDB(currentdbpath);
                            UpdateAfterOpenDB();
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        //Closed event for the main form - Writes the current prefs to the prefs.txt file
        private void MainForm_FormClosed(object sender, EventArgs e)
        {
            string tp = prefspath; //String.Format("{0}\\prefs.txt", mydocspath); //installpath);

            //Make an auto backup on exit if pref is set
            try
            {
                if (GuiPrefs.AutoBackup)
                {
                    PerformAutoBackup();
                }
            }
            catch { }

            using (StreamWriter sw = new StreamWriter(tp, false))
            {
                //File description and warning
                sw.WriteLine("//This is the SecondSight preferences file, prefs.txt.  If these values are modified, the program " +
                             "may crash or behave unexpectedly.  Do not manually modify this file unless you know what you're doing." +
                             Environment.NewLine + "//The file can be safely deleted in the case of problems, as the program will generate a " +
                             "new one if prefs.txt cannot be found.");
                //Automatic prefs (program state)
                sw.WriteLine(Environment.NewLine + "//Automatic Prefs: These items are generated automatically and represent information about the" +
                             Environment.NewLine + "//  state the program was in when it was last closed." +
                             Environment.NewLine + "//Width\t\t- The width of the program window" +
                             Environment.NewLine + "//Height\t- The height of the program window" +
                             Environment.NewLine + "//Maximized\t- Whether the program was maximized when it was last closed" +
                             Environment.NewLine + "//OpenDBName\t- The name of the last open database" +
                             Environment.NewLine + "//OpenDBLoc\t- The physical location of the last open database (not the file path)" +
                             Environment.NewLine + "//OpenDBPath\t- The file path to the last open database file");
                sw.WriteLine(String.Format("Width={0}", GuiPrefs.Width));
                sw.WriteLine(String.Format("Height={0}", GuiPrefs.Height));
                if (WindowState == FormWindowState.Maximized)
                {
                    sw.WriteLine("Maximized=1");
                }
                else
                {
                    sw.WriteLine("Maximized=0");
                }

                sw.WriteLine(String.Format("OpenDBName={0}", GuiPrefs.OpenDBName));
                sw.WriteLine(String.Format("OpenDBLoc={0}", GuiPrefs.OpenDBLoc));
                sw.WriteLine(String.Format("OpenDBPath={0}", GuiPrefs.OpenDBPath));

                //General prefs
                sw.WriteLine(Environment.NewLine + "//General Prefs: These are general user-defined preferences" +
                             Environment.NewLine + "//OpenMostRecentDB\t- Whether to open the most recently open database when the program starts" +
                             Environment.NewLine + "//ODColumnColor\t\t- The color of the OD Rx columns in the database grid views" +
                             Environment.NewLine + "//OSColumnColor\t\t- The color of the OS Rx columns in the database grid views");
                sw.WriteLine(String.Format("OpenMostRecentDB={0}", GuiPrefs.OpenMostRecentDB));
                //	            sw.WriteLine(String.Format("ODColumnColor={0}", GuiPrefs.ODColumnColor.ToArgb()));
                //	            sw.WriteLine(String.Format("OSColumnColor={0}", GuiPrefs.OSColumnColor.ToArgb()));

                //Database prefs
                sw.WriteLine(Environment.NewLine + "//Database prefs: these define database file locations and automatic backup preferences." +
                             Environment.NewLine + "//DefaultDBDir\t\t- The path to the folder where SecondSight will first look for database files." +
                             Environment.NewLine + "//DefaultBackupDir\t- The path to the folder where SecondSight will first look for backup files." +
                             Environment.NewLine + "//AutoBackup\t\t- Perform automatic backups? 0 = No, nonzero = Yes" +
                             Environment.NewLine + "//ABAfterTime\t\t- Backup current database after a set period of time? 0 = No, nonzero = Yes" +
                             Environment.NewLine + "//ABTime\t\t- Time interval for automatic backup, in minutes (ignored if ABAfterTime is 0)" +
                             Environment.NewLine + "//ABAfterOps\t\t\t- Backup current database after a number of operations (Add/Delete/Dispense)? 0 = No, nonzero = Yes" +
                             Environment.NewLine + "//ABOps\t\t- Number of operations between automatic backups (ignored if ABAfterOps is 0)" +
                             Environment.NewLine + "//ABNumberKept\t\t- Number of the most recent backup files kept on disk.");
                sw.WriteLine(String.Format("DefaultDBDir={0}", GuiPrefs.DefaultDBDir));
                sw.WriteLine(String.Format("DefaultBackupDir={0}", GuiPrefs.DefaultBackupDir));
                sw.WriteLine(String.Format("AutoBackup={0}", GuiPrefs.AutoBackup));
                sw.WriteLine(String.Format("ABAfterTime={0}", GuiPrefs.ABAfterTime));
                sw.WriteLine(String.Format("ABTime={0}", GuiPrefs.ABTime));
                sw.WriteLine(String.Format("ABAfterOps={0}", GuiPrefs.ABAfterOps));
                sw.WriteLine(String.Format("ABOps={0}", GuiPrefs.ABOps));
                sw.WriteLine(String.Format("ABNumberKept={0}", GuiPrefs.ABNumberKept));

                Mydb.CloseDB();
            }
        }