private async void button4_Click(object sender, EventArgs e) { //create button button4.Enabled = false; button5.Enabled = false; var cfg = MCv2Persistance.Instance.Config; ProgressDialog pgd = new ProgressDialog("Database Backup"); pgd.Show(); pgd.SetMarqueeStyle(); var now_is = DateTime.Now; var backup_filename = cfg.DatabaseConfiguration.DatabaseConnectionProperties.Hostname.Replace('.', '_') + "_" + cfg.DatabaseConfiguration.DatabaseConnectionProperties.Schema + "_" + now_is.Year + "_" + now_is.Month + "_" + now_is.Day + "_" + now_is.ToFileTimeUtc().ToString(); pgd.LabelText = "Saving backup to " + backup_filename + ".db2bak"; await DBBackupAndRestore.Backup("./backups/" + backup_filename + ".db2bak"); pgd.Dispose(); await RefreshUI(); }
public MCIv2Form() { var cfg = MCv2Persistance.Instance.Config; var bcfg = cfg.BackupConfiguration; if (bcfg.EnableAutoBackup) { ProgressDialog pgd = new ProgressDialog("Database Backup"); pgd.Show(); pgd.SetMarqueeStyle(); var now_is = DateTime.Now; var backup_filename = "auto_backup_" + cfg.DatabaseConfiguration.DatabaseConnectionProperties.Hostname.Replace('.', '_') + "_" + cfg.DatabaseConfiguration.DatabaseConnectionProperties.Schema + "_" + now_is.Year + "_" + now_is.Month + "_" + now_is.Day + "_" + now_is.ToFileTimeUtc().ToString(); pgd.LabelText = "Saving backup to " + backup_filename + ".db2bak"; DBBackupAndRestore.Backup("./backups/" + backup_filename + ".db2bak").Wait(); pgd.Dispose(); bcfg.LastAutoBackupTimestamp = DateTime.Now; } if (bcfg.EnableBackupNag && (DateTime.Now - bcfg.LastNagBackupTimestamp) > bcfg.BackupNagInterval) { var res = MessageBox.Show(this, "It's been " + (DateTime.Now - bcfg.LastNagBackupTimestamp).TotalDays + " days since the last local database backup." + Environment.NewLine + "Would you like to perform a backup now?", "Warning", MessageBoxButtons.YesNo); if (res == DialogResult.Yes) { //backup database string file_name = null; using (SaveFileDialog sfd = new SaveFileDialog()) { sfd.Filter = "Supported Extentions (*.db2bak)|*.db2bak"; sfd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); var now_is = DateTime.Now; sfd.FileName = cfg.DatabaseConfiguration.DatabaseConnectionProperties.Hostname.Replace('.', '_') + "_" + cfg.DatabaseConfiguration.DatabaseConnectionProperties.Schema + "_" + now_is.Year + "_" + now_is.Month + "_" + now_is.Day + "_" + now_is.ToFileTimeUtc().ToString(); if (sfd.ShowDialog() == DialogResult.OK) { file_name = sfd.FileName; } } if (file_name != null) { ProgressDialog pgd = new ProgressDialog("Database Backup"); pgd.Show(); pgd.SetMarqueeStyle(); pgd.LabelText = "Saving backup to " + file_name; DBBackupAndRestore.Backup(file_name).Wait(); pgd.Dispose(); bcfg.LastNagBackupTimestamp = DateTime.Now; } } } MCv2Persistance.Instance.Config = cfg; InitializeComponent(); //context menu toolStripMenuItem2.Click += (a, b) => { Clipboard.SetText(new Func <string>(() => { var str = ""; var items = listBox2.Items.Cast <string>(); foreach (var item in items) { str += item + Environment.NewLine; } return(str); }).Invoke()); }; DoubleBuffered = true; var version_strings = Assembly.GetExecutingAssembly().GetName().Version.ToString().Split('.'); var version_string = "MCI v" + version_strings[0] + "." + version_strings[1] + " Prerelease " + version_strings[2] + "." + version_strings[3]; Text = version_string; //Set double buffering on the gridview using reflection and the bindingflags enum. typeof(DataGridView).InvokeMember("DoubleBuffered", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.SetProperty, null, dataGridView1, new object[] { true }); card_lookup_controls.Add(listBox1); card_lookup_controls.Add(textBox3); card_lookup_controls.Add(button1); card_lookup_controls.Add(listBox2); card_lookup_controls.Add(button2); card_lookup_controls.Add(button22); update_holdoff_timer.Elapsed += async(s, ea) => { rct = new CancellationTokenSource(); update_holdoff_timer.Stop(); //try //{ await Task.Run(async() => { string tb0 = "", tb1 = ""; Invoke((MethodInvoker)(() => { tb0 = textBox1.Text.Trim(); tb1 = textBox3.Text.Trim(); textBox3.Text = ""; textBox1.BackColor = Color.LightCyan; Refresh(); })); //RemoveDataGridView1Events(); await UserLookupAndDisplay(tb0, true, rct); //RestoreDataGridView1Events(); //if there are rows displayed then refresh card lookup and display //var selected_users = ULAD_GetSelectedUsers(); //if(selected_users.Count() > 0) //{ //await CardLookupAndDisplay(selected_user, tb1, true); //} Invoke((MethodInvoker)(() => { textBox1.BackColor = SystemColors.Window; Refresh(); })); }, rct.Token); //} //catch (Exception ex) { } rct.Dispose(); rct = null; }; V2LE_ResetAll(); }