Esempio n. 1
0
        public void CreateTickets(TicketsSettings ticketsSettings)
        {
            if (string.IsNullOrWhiteSpace(ticketsSettings.PathToQuestions))
            {
                throw new InvalidOperationException("Не указан путь до файла с вопросами");
            }

            var questions = GetQuestions(ticketsSettings.PathToQuestions);

            if (questions.Count / ticketsSettings.QuestionsCount > ticketsSettings.TicketsCount ||
                (questions.Count < ticketsSettings.TicketsCount && ticketsSettings.QuestionsCount.Equals(1)))
            {
                throw new InvalidOperationException("Невозможно сформировать заданное количество экзаменационных билетов, используя указанный список вопросов.");
            }

            var tasks = new List <Task>() as ICollection <Task>;

            if (ticketsSettings.CanIncludeTasks)
            {
                if (string.IsNullOrWhiteSpace(ticketsSettings.PathToTasks))
                {
                    throw new InvalidOperationException("Не указан путь до файла с задачами.\nЭто обязательно, если активирован режим \"Включать задачи в билеты\".");
                }
                else
                {
                    tasks = GetTasks(ticketsSettings.PathToTasks);
                }
            }

            var ticketsTemplate = new TicketsWordTemplate(ticketsSettings, questions, tasks);

            wordHandler.Write(ticketsSettings.DestinationFilepath, ticketsTemplate);
        }
Esempio n. 2
0
        private void OnExportClick(object sender, EventArgs eventArgs)
        {
            var saveDialogResult = saveFileDialog.ShowDialog();

            if (saveDialogResult.Equals(DialogResult.OK))
            {
                var ticketsSettings = new TicketsSettings()
                {
                    Header              = tbHeader.Text,
                    FacultyTitle        = tbFacultyTitle.Text,
                    DepartmentTitle     = tbDepartmentTitle.Text,
                    DisciplineTitle     = tbDisciplineTitle.Text,
                    StudyYear           = tbStudyYear.Text,
                    DepartmentChief     = tbDepartmentChief.Text,
                    QuestionsCount      = Convert.ToInt32(ntbQuestionsCount.Value),
                    CanUseTaskWord      = cbCanUseTaskWord.Checked,
                    CanIncludeTasks     = cbCanIncludeTasks.Checked,
                    TicketsCount        = Convert.ToInt32(ntbTicketsCount.Value),
                    DestinationFilepath = saveFileDialog.FileName,
                    PathToQuestions     = tbPathToQuestions.Text,
                    PathToTasks         = tbPathToTasks.Text
                };

                try
                {
                    ticketService.CreateTickets(ticketsSettings);
                    Process.Start(ticketsSettings.DestinationFilepath);
                }

                catch (Exception error)
                {
                    MessageBox.Show(this, error.Message, "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                }
            }
        }
Esempio n. 3
0
        public TicketsWordTemplate(TicketsSettings ticketsSettings, ICollection <Question> questions, ICollection <Task> tasks)
        {
            this.ticketsSettings = ticketsSettings;
            this.questions       = questions;
            this.tasks           = tasks;

            random = new Random();

            usedQuestions = new List <Question>();
            usedTasks     = new List <Task>();
        }