Beispiel #1
0
        } // выбор каталога для сохранения архива

        private void FolderArhiveBtn_Click(object sender, EventArgs e)
        {
            try
            {
                Server   srv = new Server("DESKTOP-EPNEITS");
                Database db  = default(Database);
                db = srv.Databases["Rating"];

                int recoverymod;
                recoverymod = (int)db.DatabaseOptions.RecoveryModel;

                Backup bk = new Backup();

                bk.Action = BackupActionType.Database;
                bk.BackupSetDescription = "Full backup of Rating";
                bk.BackupSetName        = "Rating Backup";
                bk.Database             = "Rating";

                BackupDeviceItem bdi = default(BackupDeviceItem);
                bdi = new BackupDeviceItem("Rating " + DateTime.Now.ToString("yyyy-MM-dd") + " Backup", DeviceType.File);

                bk.Devices.Add(bdi);
                bk.Incremental = false;

                System.DateTime backupdate = new System.DateTime();
                backupdate        = new System.DateTime(2018, 10, 5);
                bk.ExpirationDate = backupdate;

                bk.LogTruncation = BackupTruncateLogType.Truncate;

                bk.SqlBackup(srv);

                bk.Devices.Remove(bdi);

                if (string.IsNullOrEmpty(FolderNameTextBox.Text))
                {
                    MessageBox.Show("Выберете папку!", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    FolderNameTextBox.Focus();
                    return;
                }

                string pat  = "BackupDB.zip";
                string path = FolderNameTextBox.Text;

                using (ZipFile zip = new ZipFile())
                {
                    zip.CompressionLevel = Ionic.Zlib.CompressionLevel.BestCompression;
                    zip.AddDirectory(@"C:\Program Files\Microsoft SQL Server\MSSQL14.MSSQLSERVER\MSSQL\Backup");
                    zip.Save(path + " " + DateTime.Now.ToString("yyyy-MM-dd") + " " + pat);
                }

                MessageBox.Show("Архивирование данных прошло успешно!");
            }
            catch
            {
                MessageBox.Show("Во время архивации данных произошла ошибка, убедитесь в правильности указания каталога!");
            }
        } // архивация бекапа БД
        public MainWindow()
        {
            InitializeComponent();
            DeleteCheckbox.IsChecked = Settings.Default.Delete;
            Drives = DriveInfo.GetDrives().Where(drive => drive.DriveType == DriveType.Removable).ToList();
            bw     = new BackgroundWorker();
            bw.WorkerReportsProgress = true;
            bw.DoWork             += Bw_DoWork;
            bw.ProgressChanged    += Bw_ProgressChanged;
            bw.RunWorkerCompleted += Bw_RunWorkerCompleted;

            //Set Default Settings If Not Set
            if (Settings.Default.LastFolders == null)
            {
                Settings.Default.LastFolders = new System.Collections.Specialized.StringCollection();
            }
            if (Settings.Default.Path == "UNSET")
            {
                Settings.Default.Path = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
                Settings.Default.Save();
            }

            //Get Drives Only works if exactly one drive
            if (Drives.Count == 1)
            {
                SourcePath.Content      = PathShortner(Strings.StartLabelText, Drives.FirstOrDefault().Name);
                DestinationPath.Content = PathShortner(Strings.FinishLabelText, Settings.Default.Path);
                RecursiveFileCount(Drives[0].RootDirectory.FullName);
                OverallProgressBar.Maximum = FileCount;
            }
            else
            {
                if (MessageBox.Show(Strings.NoDriveSettings, Strings.NoDrive, MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                {
                    SettingsWindow settings = new SettingsWindow();
                    settings.Show();
                    this.Close();
                }
                else
                {
                    this.Close();
                }
            }

            //For Textbox
            FolderNameTextBox.Focus();
            LastFoldersList.ItemsSource = Settings.Default.LastFolders;

            var desktopWorkingArea = System.Windows.SystemParameters.WorkArea;

            this.Left = desktopWorkingArea.Right - this.Width;
            this.Top  = desktopWorkingArea.Bottom - this.Height;
        }
 private void Window_Loaded(object sender, RoutedEventArgs e)
 {
     FolderNameTextBox.Focus();
 }