public void CreateDatabase(string path)
        {
            //The file that was just created does not have a schema, so SQLite won't touch it.
            //The file must have a schema or not exist for use with SQLite, so we'll delete
            //it and install a schema

            try
            {
                FileEx.SafeDelete(path);
            }
            catch (IOException x)
            {
                MessageDlg.ShowException(this, x);
                return;
            }

            //Create file, initialize db
            try
            {
                OptimizationDb.CreateOptimizationDb(path);

                textDatabase.Text = path;
            }
            catch (Exception x)
            {
                var message = TextUtil.LineSeparate(string.Format(Resources.EditOptimizationLibraryDlg_CreateDatabase_The_file__0__could_not_be_created_, path),
                                                    x.Message);
                MessageDlg.ShowWithException(this, message, x);
            }
        }
        public void OkDialog()
        {
            if (string.IsNullOrEmpty(textName.Text))
            {
                MessageDlg.Show(this, Resources.EditOptimizationLibraryDlg_OkDialog_Please_enter_a_name_for_the_optimization_library_);
                textName.Focus();
                return;
            }

            if (_existing != null)
            {
                foreach (var existing in _existing)
                {
                    if (Equals(existing.Name, textName.Text) && !Equals(existing.Name, _editingName))
                    {
                        if (MessageBox.Show(this, string.Format(Resources.EditOptimizationLibraryDlg_OkDialog_A_library_with_the_name__0__already_exists__Do_you_want_to_overwrite_it_,
                                                                textName.Text),
                                            Program.Name, MessageBoxButtons.YesNo) != DialogResult.Yes)
                        {
                            textName.Focus();
                            return;
                        }
                    }
                }
            }

            string message;

            if (string.IsNullOrEmpty(textDatabase.Text))
            {
                message = TextUtil.LineSeparate(Resources.EditOptimizationLibraryDlg_OkDialog_Please_choose_a_library_file_for_the_optimization_library_,
                                                Resources.EditOptimizationLibraryDlg_OkDialog_Click_the_Create_button_to_create_a_new_library_or_the_Open_button_to_open_an_existing_library_file_);
                MessageDlg.Show(this, message);
                textDatabase.Focus();
                return;
            }
            string path = Path.GetFullPath(textDatabase.Text);

            if (!Equals(path, textDatabase.Text))
            {
                message = TextUtil.LineSeparate(Resources.EditOptimizationLibraryDlg_OkDialog_Please_use_a_full_path_to_a_library_file_for_the_optimization_library_,
                                                Resources.EditOptimizationLibraryDlg_OkDialog_Click_the_Create_button_to_create_a_new_library_or_the_Open_button_to_open_an_existing_library_file_);
                MessageDlg.Show(this, message);
                textDatabase.Focus();
                return;
            }
            if (!string.Equals(Path.GetExtension(path), OptimizationDb.EXT))
            {
                path += OptimizationDb.EXT;
            }

            if (!ValidateOptimizationList(LibraryOptimizations, Resources.EditOptimizationLibraryDlg_OkDialog_library))
            {
                gridViewLibrary.Focus();
                return;
            }

            try
            {
                var library = new OptimizationLibrary(textName.Text, path);

                OptimizationDb db = File.Exists(path)
                               ? OptimizationDb.GetOptimizationDb(path, null, _document)
                               : OptimizationDb.CreateOptimizationDb(path);

                db = db.UpdateOptimizations(LibraryOptimizations.ToArray(), _original ?? new DbOptimization[0]);

                Library = library.ChangeDatabase(db);
            }
            catch (OptimizationsOpeningException x)
            {
                MessageDlg.ShowException(this, x);
                textDatabase.Focus();
                return;
            }
            catch (StaleStateException)
            {
                // CONSIDER: Not sure if this is the right thing to do.  It would
                //           be nice to solve whatever is causing this, but this is
                //           better than showing an unexpected error form with stack trace.
                MessageDlg.Show(this, Resources.EditOptimizationLibraryDlg_OkDialog_Failure_updating_optimizations_in_the_optimization_library__The_database_may_be_out_of_synch_);
                return;
            }

            DialogResult = DialogResult.OK;
        }