void Worker_DoWork(object sender, DoWorkEventArgs e) { foreach (var server in SQLFunctions.GetServers()) { if (!HostCoBox.Items.Contains(server)) { if (this.HostCoBox.InvokeRequired) { HostCoBox.BeginInvoke((MethodInvoker) delegate() { HostCoBox.Items.Add(server); }); } else { HostCoBox.Items.Add(server); } } } }
private void SaveBackup_Click(object sender, EventArgs e) { var BackupName = BackupNameTxt.Text.Trim(); #region Save Validation int index = ((MyBackup)MyParentPanel.Tag).MyIndex; if (BackupName.Length == 0) { MessageBox.Show("Please write a valid Backup Name!", "", MessageBoxButtons.OK, MessageBoxIcon.Error); BackupNameTxt.Focus(); return; } else if (MyBackup.MyBackups.Exists(x => x.BackupName.ToLower() == BackupName.ToLower() && x.MyIndex != index)) { MessageBox.Show("Backup Name is already exists!", "", MessageBoxButtons.OK, MessageBoxIcon.Error); BackupNameTxt.Focus(); return; } else if (!SQLFunctions.TestConnection(false, HostCoBox.Text, DBCoBox.Text, AuthCoBox.SelectedIndex == 1, AuthCoBox.SelectedIndex == 0 ? UsernameTxt.Text : string.Empty, AuthCoBox.SelectedIndex == 0 ? PassTxt.Text : string.Empty, out _, out string ExcMessage)) { MessageBox.Show(ExcMessage, "SQL ConnectionString Error", MessageBoxButtons.OK, MessageBoxIcon.Error); HostCoBox.Focus(); return; } else if (BackupPathTxt.Text.Length == 0 || !Directory.Exists(BackupPathTxt.Text)) { MessageBox.Show("Please select a valid Backup Path!", "", MessageBoxButtons.OK, MessageBoxIcon.Error); BackupPathTxt.Focus(); return; } else if (!RepeatRadio.Checked && !SpecificRadio.Checked) { MessageBox.Show("Please select a valid Backup Schedule!", "", MessageBoxButtons.OK, MessageBoxIcon.Error); RepeatRadio.Focus(); return; } else if (RepeatRadio.Checked) { if (!SatBox.Checked && !SunBox.Checked && !MonBox.Checked && !TueBox.Checked && !WedBox.Checked && !ThuBox.Checked && !FriBox.Checked) { MessageBox.Show("Please select one day schedule at least!", "", MessageBoxButtons.OK, MessageBoxIcon.Error); SatBox.Focus(); return; } } else if (SpecificRadio.Checked) { if (!MinutesRadio.Checked && !HoursRadio.Checked && !DaysRadio.Checked && !WeeksRadio.Checked && !MonthsRadio.Checked)//YearsRadio { MessageBox.Show("Please select a schedule type!", "", MessageBoxButtons.OK, MessageBoxIcon.Error); MinutesRadio.Focus(); return; } } #endregion var backup = (MyBackup)MyParentPanel.Tag; //Backup Options backup.IsEnabled = IsEnabledBox.Checked; backup.BackupName = BackupName; //SQL Connection string host; if (HostCoBox.SelectedItem != null) { host = HostCoBox.SelectedItem.ToString(); } else { host = HostCoBox.SelectedText; } backup.Host = host; string db; if (DBCoBox.SelectedItem != null) { db = DBCoBox.SelectedItem.ToString(); } else { db = DBCoBox.SelectedText; } backup.Database = db; backup.Authentication = AuthCoBox.SelectedIndex == 1; backup.Username = UsernameTxt.Text; backup.Password = PassTxt.Text; backup.SavePassword = SaveCkBox.Checked; //Backup Path backup.BackupPath = BackupPathTxt.Text; //Backup Repeat Datetime backup.Repeat = RepeatRadio.Checked; backup.Time = new TimeSpan(TimePicker.Value.Hour, TimePicker.Value.Minute, 0).Ticks;//new TimeSpan(TimePicker.Value.Hour == 0 ? 1 : 0, TimePicker.Value.Hour, TimePicker.Value.Minute, 0).Ticks; backup.Sat = SatBox.Checked; backup.Sun = SunBox.Checked; backup.Mon = MonBox.Checked; backup.Tue = TueBox.Checked; backup.Wed = WedBox.Checked; backup.Thu = ThuBox.Checked; backup.Fri = FriBox.Checked; //Backup Specific Datetime backup.Specific = SpecificRadio.Checked; backup.Every = SpecificNum.Value; if (MinutesRadio.Checked) { backup.SpecificType = SpecificTypes.Minutes; } else if (HoursRadio.Checked) { backup.SpecificType = SpecificTypes.Hours; } else if (DaysRadio.Checked) { backup.SpecificType = SpecificTypes.Days; } else if (WeeksRadio.Checked) { backup.SpecificType = SpecificTypes.Weeks; } else if (MonthsRadio.Checked) { backup.SpecificType = SpecificTypes.Months; } //Years if (index == 0 || backup.LastBackup < 1) { backup.LastBackup = DateTime.Now.Ticks; } MyBackup.SaveBackup(backup); RefreshMyTreeView(backup); MessageBox.Show("Backup settings have been saved successfully.", "Backup settings", MessageBoxButtons.OK, MessageBoxIcon.Information); }