private void DeleteBackupButton_Click(object sender, System.Windows.RoutedEventArgs e) { ViewModels.DatabaseBackupViewModel selectedBackup = BackupsGridControl.SelectedItem as ViewModels.DatabaseBackupViewModel; System.IO.DirectoryInfo oDirectoryInfo = new System.IO.DirectoryInfo(Utility.DatabaseBackupPath); System.IO.FileInfo oFile = oDirectoryInfo.GetFiles() .Where(current => current.Name == selectedBackup.BackupFileName) .Where(current => current.CreationTime == selectedBackup.BackupDateTime) .FirstOrDefault(); if (oFile != null) { System.Windows.MessageBoxResult oResult = Infrastructure.MessageBox.Show ( text: "آیا مطمئن به حذف نسخه پشتیبان هستید؟", caption: Infrastructure.MessageBox.Caption.Question ); if (oResult == System.Windows.MessageBoxResult.Yes) { oFile.Delete(); Infrastructure.MessageBox.Show ( text: "نسخه پشتیبان با موفقیت حذف گردید", caption: Infrastructure.MessageBox.Caption.Information ); } LoadGridControl(); } }
private void LoadGridControl() { string _defaultPath = Utility.DatabaseBackupPath; System.IO.DirectoryInfo oDirectoryInfo = new System.IO.DirectoryInfo(path: _defaultPath); System.Collections.Generic.List <ViewModels.DatabaseBackupViewModel> Backups = new System.Collections.Generic.List <ViewModels.DatabaseBackupViewModel>(); if (oDirectoryInfo.Exists == true) { foreach (System.IO.FileInfo oFileInfo in oDirectoryInfo.GetFiles()) { if ((string.Compare(oFileInfo.Extension, ".bkdb", true) == 0) == true) { ViewModels.DatabaseBackupViewModel oViewModel = new ViewModels.DatabaseBackupViewModel(); oViewModel.BackupFileName = oFileInfo.Name; oViewModel.BackupDateTime = oFileInfo.CreationTime; oViewModel.PersianBackupDateTime = FarsiLibrary.Utils.PersianDateConverter.ToPersianDate(oViewModel.BackupDateTime).ToString(); Backups.Add(oViewModel); } } } BackupsGridControl.ItemsSource = Backups .OrderBy(current => current.BackupDateTime) .ToList(); if (Backups.Count == 0) { DeleteAllBackupButton.IsEnabled = false; DeleteBackupButton.IsEnabled = false; RestoreBackupButton.IsEnabled = false; } else { DeleteAllBackupButton.IsEnabled = true; DeleteBackupButton.IsEnabled = true; RestoreBackupButton.IsEnabled = true; } }
private void RestoreBackupButton_Click(object sender, System.Windows.RoutedEventArgs e) { ViewModels.DatabaseBackupViewModel selectedBackup = BackupsGridControl.SelectedItem as ViewModels.DatabaseBackupViewModel; System.IO.DirectoryInfo oDirectoryInfo = new System.IO.DirectoryInfo(Utility.DatabaseBackupPath); System.IO.FileInfo oFile = oDirectoryInfo.GetFiles() .Where(current => current.Name == selectedBackup.BackupFileName) .Where(current => current.CreationTime == selectedBackup.BackupDateTime) .FirstOrDefault(); if (oFile != null) { System.Windows.MessageBoxResult oResult = Infrastructure.MessageBox.Show ( text: "آیا مطمئن به بازیابی نسخه پشتیبان هستید؟", caption: Infrastructure.MessageBox.Caption.Question ); if (oResult == System.Windows.MessageBoxResult.Yes) { string destinationFileName = System.Environment.CurrentDirectory + "\\Database\\FundDatabase.sdf"; oFile.CopyTo(destFileName: destinationFileName, overwrite: true); Infrastructure.MessageBox.Show ( text: "نسخه پشتیبان با موفقیت بازیابی گردید" + System.Environment.NewLine + "برنامه با پایگاه جدید بازیابی شده مجددا راه اندازی خواهد شد", caption: Infrastructure.MessageBox.Caption.Information ); System.Diagnostics.Process.Start(System.Windows.Application.ResourceAssembly.Location); System.Windows.Application.Current.Shutdown(); } } }