private void restoreBackupToolStripMenuItem_Click(object sender, EventArgs e) { var dialog = new OpenFileDialog { InitialDirectory = BackupsFolderPath, Filter = "Zip File (*.zip) | *.zip" }; var result = dialog.ShowDialog(); if (result == DialogResult.OK) { var tempFolder = $"{Path.GetTempPath()}\\excelRestoreFolder"; string tempFile = $"{tempFolder}\\{DB_NAME}"; Directory.CreateDirectory(tempFolder); ZipFile.ExtractToDirectory(dialog.FileName, tempFolder); File.Copy(tempFile, DbPath, true); File.Delete(tempFile); Directory.Delete(tempFolder); excelGrid.DataSource = ExcelHandler.GetDataTable(DbPath); createBackupToolStripMenuItem.Enabled = true; MessageBox.Show("Restore Successful"); } }
/// <summary> /// Loads Db to Datagrid If it exists and /// Enables Excel Menu Item /// </summary> private void InitDb() { importExcelToolStripMenuItem.Enabled = true; restoreBackupToolStripMenuItem.Enabled = true; if (DbExists) { excelGrid.DataSource = ExcelHandler.GetDataTable(DbPath); createBackupToolStripMenuItem.Enabled = true; } else { excelGrid.DataSource = new DataTable(); createBackupToolStripMenuItem.Enabled = false; } }
private void OpenImportExcelDialog() { var dialog = new OpenFileDialog { InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop), Filter = "Excel (*.xlsx) | *.xlsx" }; var result = dialog.ShowDialog(); if (result == DialogResult.OK) { File.Copy(dialog.FileName, DbPath, true); excelGrid.DataSource = ExcelHandler.GetDataTable(DbPath); createBackupToolStripMenuItem.Enabled = true; } }