示例#1
0
        // Кнопка "ОК". Обработка события нажатия на кнопку.
        private void btnOK_Click(object sender, EventArgs e)
        {
            tbYear.Focus();
            btnOK.Focus();

            if (errorProvider.GetError(tbYear) != "")
            {
                return;
            }

            int year = int.Parse(tbYear.Text);

            var doc = new WordFile(Directory.GetCurrentDirectory() + @"\templates\Statement.docx");

            this.Hide();

            Task t = new Task(() => {
                var dataTable = export.GetStatementReport(year);

                MessageBox.Show("Сохрениение файла может занять некоторое время. После успешного сохранения будет показано уведомление", "Формирование отчета", MessageBoxButtons.OK, MessageBoxIcon.Information);

                doc.AddTable(dataTable);
                doc.ReplaceWordText("{year}", year.ToString());
                doc.Save(fileName);
            });

            t.Start();

            t.ContinueWith((task) => MessageBox.Show($"Файл {fileName}", "Ведомость распределения выпускников, которые окончили ВУЗ", MessageBoxButtons.OK, MessageBoxIcon.Information));

            this.Close();
        }