private void btn_Pre_logs_Click(object sender, EventArgs e) { if (previousLogs != null && previousLogs.Count > 0) // clear { if (MessageBox.Show("Are you sure you want to clear current Stats from memory", "Clear Memory!", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { previousLogs.Clear(); previousLogs_errors.Clear(); Stat_info = new Stat_Info(); Calc_Groups_Counts(); } return; } var file_csv = txt_auto_csv_file.Text; if (File.Exists(file_csv)) { if (MessageBox.Show(string.Format("Are you sure you want to read previous logs from this csv file.{0}{0}CSV File:{0}{1}", Environment.NewLine, file_csv), "previous logs!", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { ReadPreviuseLogFile(file_csv); Calc_Groups_Counts(); } } else { MessageBox.Show(string.Format("This csv file does not exist{0}{0}CSV File:{0}{1}", Environment.NewLine, file_csv), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); txt_auto_csv_file.Focus(); txt_auto_csv_file.SelectAll(); } }
private void button1_Click(object sender, EventArgs e) { try { if (backgroundWorker1.IsBusy) { if (MessageBox.Show(this, "Do you want to cancel the process?", "Cancel process", MessageBoxButtons.YesNo) != DialogResult.Yes) { return; } button1.Text = "Process"; backgroundWorker1.CancelAsync(); cancellationTokenSource.Cancel(); return; } if (string.IsNullOrWhiteSpace(textBox1.Text)) { MessageBox.Show("You have to set the images folder!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); textBox1.Focus(); textBox1.SelectAll(); return; } if (!Directory.Exists(textBox1.Text)) { MessageBox.Show("This directory is not exist!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); textBox1.Focus(); textBox1.SelectAll(); return; } if (string.IsNullOrWhiteSpace(txt_auto_csv_file.Text) && chk_auto_csv_file.Checked) { MessageBox.Show("You have to set the csv file to save results automatically!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); txt_auto_csv_file.Focus(); txt_auto_csv_file.SelectAll(); return; } if (!txt_auto_csv_file.Text.ToLower().EndsWith(".csv") && chk_auto_csv_file.Checked) { MessageBox.Show("csv file must have .csv extension !", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); txt_auto_csv_file.Focus(); txt_auto_csv_file.SelectAll(); return; } if (File.Exists(txt_auto_csv_file.Text) && chk_auto_csv_file.Checked) { var result = MessageBox.Show(string.Format("This csv file already exist.{0}What do you want to do:{0}{0}Retry: Resume previous operation.{0}Ignore: Start over and clean csv file.{0}Abort: Cancel the operation and do nothing.{0}{0}CSV File:{0}{1}", Environment.NewLine, txt_auto_csv_file.Text), "csv file exist", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Question); if (result == DialogResult.Cancel || result == DialogResult.Abort) { txt_auto_csv_file.Focus(); txt_auto_csv_file.SelectAll(); return; } else if (result == DialogResult.Retry) { Stat_info = new Stat_Info(); previousLogs.Clear(); ReadPreviuseLogFile(txt_auto_csv_file.Text); } else if (result == DialogResult.Ignore) { var f = new FileInfo(txt_auto_csv_file.Text); if (f.Exists) { File.Create(f.FullName).Dispose();//make sure can write to file } } } if (!File.Exists(txt_auto_csv_file.Text) && chk_auto_csv_file.Checked) { try { var f = new FileInfo(txt_auto_csv_file.Text); if (f.Exists) { File.Create(f.FullName).Dispose();//make sure can write to file } else { File.Create(f.FullName).Dispose();//make sure can write to file f.Delete(); } } catch (Exception er) { MessageBox.Show("This csv file is not valid!" + Environment.NewLine + er.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); txt_auto_csv_file.Focus(); txt_auto_csv_file.SelectAll(); return; } } if (CSV_Autofile != null) { CSV_Autofile.Dispose(); } if (previousLogs == null || previousLogs.Count < 1) { Stat_info = new Stat_Info(); } button1.Text = "Stop"; buttonPause.Text = "Pause"; buttonPause.Enabled = txt_auto_csv_file.ReadOnly = true; btn_imags_cnt.Enabled = false; backgroundWorker1.RunWorkerAsync(textBox1.Text); } catch (Exception er) { MessageBox.Show(er.FullErrorMessage(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }