Example #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();
        }
Example #2
0
        /// <summary>
        /// Формирует справки - направления на работу.
        /// </summary>
        /// <param name="student">Экземпляр класса с данными о студенте</param>
        /// <param name="specialization">Экземпляр класса с данными о специализации</param>
        /// <param name="workPlace">Экземпляр класса с данными о месте работы студента</param>
        /// <param name="path">Путь к сохраняемому файлу</param>
        /// <param name="template">Путь к файлу-шаблону</param>
        private void SaveEmploymentReport(IStudent student, ISpecialization specialization, IStudentCompany workPlace, string path, string template)
        {
            var doc = new WordFile(template);

            doc.ReplaceWordText("{surname}", student.Surname.Trim());
            doc.ReplaceWordText("{name}", student.Name.Trim());
            doc.ReplaceWordText("{patronymic}", student.Patronymic.Trim());
            doc.ReplaceWordText("{year}", student.YearOfGraduation.ToString());
            doc.ReplaceWordText("{chiper}", GetChiper(student, specialization));
            doc.ReplaceWordText("{specialization}", GetFullSpecializationText(specialization));
            doc.ReplaceWordText("{nameOfStateDepartment}", workPlace?.NameOfStateDepartment.Trim());
            doc.ReplaceWordText("{nameOfCompany}", workPlace?.NameOfCompany.Trim());
            doc.ReplaceWordText("{post}", workPlace?.Post.Trim());

            doc.Save(path);

            if (OpenAfterCreate)
            {
                System.Diagnostics.Process.Start(path);
            }
            else
            {
                MessageBox.Show($"Файл {path}", "Отчет сформирован", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }