protected void OnBtnDatabaseClicked(object sender, EventArgs e) { SaveFileDialog dlgFile = new SaveFileDialog { Title = "Choose database to open/create", Directory = new Uri(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)), CheckFileExists = false, FileName = "osrepodbmgr.db" }; if (dlgFile.ShowDialog(this) != DialogResult.Ok) { return; } if (File.Exists(dlgFile.FileName)) { DbCore dbCore = new SQLite(); bool notDb = false; try { notDb |= !dbCore.OpenDb(dlgFile.FileName, null, null, null); } catch { notDb = true; } if (notDb) { MessageBox.Show("Cannot open specified file as a database, please choose another.", MessageBoxType.Error); return; } dbCore.CloseDb(); } else { DbCore dbCore = new SQLite(); bool notDb = false; try { notDb |= !dbCore.CreateDb(dlgFile.FileName, null, null, null); } catch { notDb = true; } if (notDb) { MessageBox.Show("Cannot create a database in the specified file as a database.", MessageBoxType.Error); return; } dbCore.CloseDb(); } txtDatabase.Text = dlgFile.FileName; }
protected void OnBtnDatabaseClicked(object sender, EventArgs e) { FileChooserDialog dlgFile = new FileChooserDialog("Choose database to open/create", this, FileChooserAction.Save, "Cancel", ResponseType.Cancel, "Choose", ResponseType.Accept) { SelectMultiple = false }; dlgFile.SetCurrentFolder(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)); dlgFile.SetFilename("Core.db"); if (dlgFile.Run() == (int)ResponseType.Accept) { if (File.Exists(dlgFile.Filename)) { DbCore dbCore = new SQLite(); bool notDb = false; try { notDb |= !dbCore.OpenDb(dlgFile.Filename, null, null, null); } catch { notDb = true; } if (notDb) { MessageDialog dlgMsg = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, "Cannot open specified file as a database, please choose another."); dlgMsg.Run(); dlgMsg.Destroy(); dlgFile.Destroy(); return; } dbCore.CloseDb(); } else { DbCore dbCore = new SQLite(); bool notDb = false; try { notDb |= !dbCore.CreateDb(dlgFile.Filename, null, null, null); } catch { notDb = true; } if (notDb) { MessageDialog dlgMsg = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, "Cannot create a database in the specified file as a database."); dlgMsg.Run(); dlgMsg.Destroy(); dlgFile.Destroy(); return; } dbCore.CloseDb(); } txtDatabase.Text = dlgFile.Filename; } dlgFile.Destroy(); }