public void Show()
        {
            ExcelDoc excel = new ExcelDoc();

            CreateHeader(excel);

            CreateBody(excel);

            excel.Show();
        }
Exemple #2
0
        private void загрузитьEmailToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.InitialDirectory = @"C:\";
            openFileDialog.Filter = "Excel files (*.xls)|*.xls|All files (*.*)|*.*";
            openFileDialog.FilterIndex = 2;
            openFileDialog.RestoreDirectory = true;
            openFileDialog.Multiselect = false;

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                ExcelDoc excelDoc = new ExcelDoc(openFileDialog.FileName);
                int err = 0;
                int i = 2;
                try
                {

                    bool quest = true;
                    string s1;
                    clQuestion question = new clQuestion(globalData.UserID);

                    while (excelDoc.getValue("A" + i.ToString(), "A" + i.ToString()) != null)
                    {
                        s1 = excelDoc.getValue("A" + i.ToString(), "A" + i.ToString()).ToString().Replace("\"", "'");

                        if (quest)
                        {
                            question = new clQuestion(globalData.UserID);
                            question.Text = s1;
                            question.Save();

                            quest = false;
                        }
                        else
                        {
                            clAnswer answer = question.CreateAnswed();
                            answer.Right = (excelDoc.getValue("B" + i.ToString(), "B" + i.ToString()) != null);
                            answer.Text = s1;
                            answer.Save();
                        }

                        i++;

                        if (excelDoc.getValue("A" + i.ToString(), "A" + i.ToString()) == null)
                        {
                            i++;
                            quest = true;
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Ошибка при чтении файла. Системная ошибка: " + ex.Message + " В строке " + i.ToString());
                    err++;
                }
                finally
                {
                    if (err == 0)
                    {
                        excelDoc.Dispose();
                    }
                    else
                    {
                        MessageBox.Show("Загрузка завершена. Найдено " + err.ToString() + " ошибок.");
                        excelDoc.Show();
                    }
                }
            }
        }