예제 #1
0
        void CreateTest()
        {
            // Добавляем тест в БД
            Tests test = new Tests()
            {
                AuthorID = UsersService.currentUser.id,
                Name     = testNameTBox.Text,


                PassTime = CalcService.HoursToSeconds((int)passHoursTBox.Value)
                           + CalcService.MinutesToSeconds((int)passMinutesTBox.Value)
                           + Convert.ToInt32(passSecondsTBox.Value),


                QuestionTime = CalcService.HoursToSeconds((int)questionHoursTBox.Value)
                               + CalcService.MinutesToSeconds((int)questionMinutesTBox.Value)
                               + Convert.ToInt32(questionSecondsTBox.Value),


                NumToPassFive  = Convert.ToInt32(passFiveTBox.Value),
                NumToPassFour  = Convert.ToInt32(passFourTBox.Value),
                NumToPassThree = Convert.ToInt32(passThreeTBox.Value)
            };

            MainClass.db.Tests.Add(test);
            MainClass.db.SaveChanges();

            TestsService.isEditingTest = true;
            TestsService.editingTest   = test;
            //TestsService.addedTest = test;
        }
예제 #2
0
        void UpdateTest()
        {
            // Меняем данные на пользовательские
            TestsService.editingTest.AuthorID = UsersService.currentUser.id;
            TestsService.editingTest.Name     = testNameTBox.Text;

            TestsService.editingTest.PassTime = CalcService.HoursToSeconds((int)passHoursTBox.Value)
                                                + CalcService.MinutesToSeconds((int)passMinutesTBox.Value)
                                                + Convert.ToInt32(passSecondsTBox.Value);

            TestsService.editingTest.QuestionTime = CalcService.HoursToSeconds((int)questionHoursTBox.Value)
                                                    + CalcService.MinutesToSeconds((int)questionMinutesTBox.Value)
                                                    + Convert.ToInt32(questionSecondsTBox.Value);

            TestsService.editingTest.NumToPassFive  = Convert.ToInt32(passFiveTBox.Value);
            TestsService.editingTest.NumToPassFour  = Convert.ToInt32(passFourTBox.Value);
            TestsService.editingTest.NumToPassThree = Convert.ToInt32(passThreeTBox.Value);

            MainClass.db.SaveChanges();
        }
예제 #3
0
        private WordTest LoadWordDocument(string openDialogFilePath)
        {
            word = new Microsoft.Office.Interop.Word.Application();
            doc  = new Document();

            object fileName = openDialogFilePath;
            // Пустой объект для ненужных параметров
            object missing = System.Type.Missing;

            try
            {
                // Открытие документа
                doc = word.Documents.Open(ref fileName,
                                          ref missing, ref missing, ref missing, ref missing,
                                          ref missing, ref missing, ref missing, ref missing,
                                          ref missing, ref missing, ref missing, ref missing,
                                          ref missing, ref missing, ref missing);
            }
            catch (Exception ex)
            {
                MessageService.ShowError("Ошибка при загрузке документа: " + ex.Message);
                this.Dispatcher.Invoke(() => { spinnerIcon.Visibility = Visibility.Hidden; });
                return(null);
            }
            WordTest wordTest = new WordTest();                                 // Создаем тест

            wordTest.TestName = doc.Paragraphs[1].Range.Text.Replace("\r", ""); // Первый параграф - имя теста

            // Парсим время на прохождение теста из второго параграфа
            Regex timeRegular = new Regex("[0-9]{2}:[0-9]{2}:[0-9]{2}");

            string[] wordTime = timeRegular.Match(doc.Paragraphs[2].Range.Text).Value.Split(':');


            int testTimeInSeconds;

            // Если получилось спарсить то грузим вопрос и варианты ответа
            if (wordTime.Length != 0)
            {
                // Переводим время в секунды
                testTimeInSeconds = CalcService.HoursToSeconds(int.Parse(wordTime[0])) +
                                    CalcService.MinutesToSeconds(int.Parse(wordTime[1])) +
                                    int.Parse(wordTime[2]);
                wordTest.TestPassTime = testTimeInSeconds;

                wordTest.TestQuestions = new ObservableCollection <WordQuestions>();
                for (int i = 1; i <= doc.Lists[1].ListParagraphs.Count; i++)
                {
                    WordQuestions question = new WordQuestions()
                    {
                        QuestionText = doc.Lists[1].ListParagraphs[i].Range.Text.Replace("\r", "")
                    };
                    question.OptionsList = new ObservableCollection <string>(doc.Lists[i + 1].Range.Text.Split('\r').Where(x => !String.IsNullOrWhiteSpace(x)).ToList());
                    wordTest.TestQuestions.Add(question);
                }
            }

            ((_Document)doc).Close();
            ((_Application)word).Quit();
            return(wordTest);
        }