Esempio n. 1
0
        public void LoadAll()
        {
            try
            {
                string folder = GestionParametre.Instance.RestoreFolder;
                lblBackupPath.Text = folder;

                if (!Directory.Exists(folder))
                {
                    MessageBox.Show(@"Dossier de sauvegarde introuvable", @"Sauvegarde/Restauration", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    btnRestaurer.Enabled = false;
                    btnRestaurer.Enabled = false;
                    btnDelete.Enabled = false;
                    return;
                }

                var files = new List<DataBaseFile>();

                foreach (var file in Directory.EnumerateFiles(folder))
                {
                    var filepath = Path.Combine(folder, file);
                    var extension = Path.GetExtension(filepath);
                    if (!string.IsNullOrEmpty(extension) && extension.CompareTo(".db") == 0)
                    {
                        var dateTime = File.GetCreationTime(filepath);
                        var dbfile = new DataBaseFile() { CreationDate = dateTime, FileName = Path.GetFileName(file), FullPathName = file };
                        int nbrBackupRaison;
                        if (!Int32.TryParse(dbfile.FileName[0].ToString(), out nbrBackupRaison))
                            nbrBackupRaison = 3;
                        dbfile.BackupRaison = (BackupRaison)nbrBackupRaison;
                        files.Add(dbfile);
                    }
                }

                files = files.OrderBy(f => f.CreationDate).Reverse().ToList();

                dgvdbFiles.DataSource = files;

                btnRestaurer.Enabled = dgvdbFiles.RowCount > 0;
                btnDelete.Enabled = dgvdbFiles.RowCount > 0;

            }
            catch (Exception exception)
            {
                GestionException.TraiterException(exception, "Sauvegarde/Restauration");
            }
        }
Esempio n. 2
0
        public void RestaurerBase(DataBaseFile selectedFile)
        {
            var fileToCopy = Path.Combine(GestionParametre.Instance.RestoreFolder, selectedFile.FileName);

            File.Copy(fileToCopy, GestionParametre.Instance.DataBaseFilePath, true);
        }