private void ExecuteBtn_Click(object sender, EventArgs e) { Cursor = Cursors.WaitCursor; try { // Validate template info ValidateTemplateInfo(); string[] testCase = null; List <KeyValuePair <int, int> > subTitleList = new List <KeyValuePair <int, int> >(); if (radioButtonChoice.Checked) { testCase = txtTestCase.Text.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); } string[] ignoreTestCase = txtIgnoreTestCase.Text.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); // Get chosen sub title list from template info for (int i = 0; i < dgvSubTitle.Rows.Count - 1; i++) { if (dgvSubTitle.Rows[i].Cells[0].Value == null) { throw new Exception("Type value of some chosen sub title are empty. Please check template info again."); } if (dgvSubTitle.Rows[i].Cells[1].Value == null) { throw new Exception("Index value of some chosen sub title are empty. Please check template info again."); } int subTitleType = Convert.ToInt32(dgvSubTitle.Rows[i].Cells[0].Value.ToString()); int subTitleIndex = Convert.ToInt32(dgvSubTitle.Rows[i].Cells[1].Value.ToString()); if (subTitleIndex <= 0) { throw new Exception("Index value of some chosen sub title = 0 (index must start from 1). Please check template info again."); } subTitleList.Add(new KeyValuePair <int, int> (subTitleType, subTitleIndex)); } // Create ReportInfo and TemplateInfo from inputted data ReportInfo report = new ReportInfo() { SheetName = cbxSheet.Text, ResultPath = txtPath.Text, ReportType = cbxReportType.SelectedValue.ToString(), FilterFile = txtFilterFile.Text, TestSuiteName = txtTestSuite.Text, TargetPath = txtExcelPath.Text, ReportDate = dateTimePicker.Value, TestCaseList = testCase, IgnoreTestCaseList = ignoreTestCase }; TemplateInfo template = new TemplateInfo() { TestCaseColumnName = txtTestCaseColumnName.Text, FillableColumnStartName = txtFillableColumnStartName.Text, FillableRowStartIndex = Convert.ToInt32(txtFillableRowStartIndex.Text), DateRowIndex = Convert.ToInt32(txtDateRowIndex.Text), ColumnNumberPerDate = Convert.ToInt32(txtColumnNumberPerDate.Text), SubTitleColumnIndexList = subTitleList }; // Execute updating chosen Excel file with collected data from reports Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); cldt.UpdateExcel(report, template); stopwatch.Stop(); MessageBox.Show(String.Format("Completed in {0} seconds", stopwatch.ElapsedMilliseconds / 1000), "Status", MessageBoxButtons.OK, MessageBoxIcon.Information); // Open Excel after finish if (chxOpenFile.Checked) { cldt.OpenExcel(report.TargetPath, report.SheetName); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } Cursor = Cursors.Arrow; }