private void openButton1_Click(object sender, EventArgs e) { excelMonthscomboBox.Enabled = false; excelDataGridView.Enabled = true; OpenFileDialog openFileDialog1 = new OpenFileDialog(); openFileDialog1.Filter = "Excel Files|*.xlsx"; openFileDialog1.Title = "فایل اکسل را انتخاب نمائید"; if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK) { ExcelValidationClass valid = new ExcelValidationClass(); var file = openFileDialog1.FileName; path = file; try { // StartProgress(); ExcelManipulatorcs excel = new ExcelManipulatorcs(); try { excelData = excel.getDataFromFile(path); valid = excel.check(excelData, file); } catch (Exception ex) { MessageBox.Show(ex.Message); }; var monthComboBox = excel.getSheetsName(path); if (!setComboBoxData(monthComboBox)) { MessageBox.Show("sheet's name are not correct!"); } excelMonthscomboBox.Enabled = true; importButton1.Enabled = true; excelMonthscomboBox.SelectedIndex = 0; if (valid.isValid) { excelData = excel.ignoreBlanksRow(excelData); makeTable(excelData[0]); excelMonthscomboBox.SelectedIndex = 0; changeColumnName(); // CloseProgress(); } else { Reporter rpt = new Reporter(valid.report, (int)errorImages.info); rpt.Show(); importButton1.Enabled = false; } } catch (Exception a) { MessageBox.Show("خطا در باز کردن فایل. فایل مورد نظر خارج از قالب است! " + a.Message + " "); // CloseProgress(); } } }
private void check(object f) { try { string[] files = (string[])f; if (files == null || files.Length == 0) { MessageBox.Show("هشدار", "فایل را انتخاب کنید", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } ExcelManipulatorcs excel = new ExcelManipulatorcs(); List <string> list = new List <string>(); List <List <string> > t = new List <List <string> >(); foreach (String file in files) { string filenameWithoutPath = Path.GetFileName(file); var validation = excel.check(excel.getDataFromFile(file), filenameWithoutPath); if (!validation.isValid) { t.Add(validation.report); } else { string msg = " فایل سالم است : \n" + filenameWithoutPath; list.Add(msg); } } ; t.Add(list); if (InvokeRequired) { this.Invoke(new Action(() => CreateAndShowForm(t))); return; } } catch (Exception) { MessageBox.Show("جدول خارج از قالب است"); } }