/// <summary> /// open existing database /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OpenToolStripMenuItem_Click(object sender, EventArgs e) { //close opened database this.CloseToolStripMenuItem.PerformClick(); string filename = ""; //get database location using (OpenFileDialog dialog = new OpenFileDialog()) { dialog.Title = "Open database"; dialog.InitialDirectory = Application.StartupPath; dialog.Filter = "SQLite database | *.db"; dialog.ShowDialog(this); if (dialog.FileName.Trim() != "") { filename = dialog.FileName.Trim(); } } //open database if (filename.Trim() != "") { this._Database = new Database.SQLiteDatabase(filename); //check master password bool MasterPassword = false; while (true) { using (MasterPasswordForm master = new MasterPasswordForm(this._Database)) { master.ShowDialog(this); if (master.DialogResult == DialogResult.OK) { if (master.IsValid() == true) { this._MasterPassword = master.GetMasterPassword(); MasterPassword = true; break; } } else { break; } } } //if master password true, show all account if (MasterPassword == true) { //this.AccountTable.DataSource = this._Database.LoadAccount(); this._Database.LoadAccount(ref this.AccountTable); } } }
/// <summary> /// create new database /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void NewToolStripMenuItem_Click(object sender, EventArgs e) { //close opened database this.CloseToolStripMenuItem.PerformClick(); bool new_database = false; using (MasterPasswordForm master = new MasterPasswordForm()) { while (true) { master.ShowDialog(this); if (master.DialogResult == DialogResult.OK) { if (master.PasswordRequiment() == true) { this._MasterPassword = master.GetMasterPassword(); new_database = true; break; } } else { break; } } } string filename = ""; if (new_database == true) { //create new database using (SaveFileDialog dialog = new SaveFileDialog()) { dialog.Title = "Save database"; dialog.InitialDirectory = Application.StartupPath; dialog.Filter = "SQLite database | *.db"; dialog.ShowDialog(this); if (dialog.FileName.Trim() != "") { filename = dialog.FileName.Trim(); } } } if (filename != "") { try { if (System.IO.File.Exists(filename)) { System.IO.File.Delete(filename); } } catch { MessageBox.Show("Can't replace the file."); return; } //Database.SQLiteDatabase.CreateDatabase(dialog.FileName); this._Database = new Database.SQLiteDatabase(); this._Database.CreateDatabase(filename); this._Database = new Database.SQLiteDatabase(filename); this._Database.CreateQPassDatabase(this._MasterPassword); //show account list this._Database.LoadAccount(ref this.AccountTable); } }