Пример #1
0
        private void DeleteQTest(int index)
        {
            QTests.CommitEdit();

            _QTests.RemoveAt(index);

            QTests.ItemsSource = new ListCollectionView(_QTests);
        }
Пример #2
0
        private void QTestUp(int index)
        {
            QTests.CommitEdit();

            if (index == -1 || index == 0)
            {
                return;
            }

            var currItem = _QTests.ElementAt(index);

            _QTests.RemoveAt(index);
            _QTests.Insert(index - 1, currItem);

            QTests.ItemsSource = new ListCollectionView(_QTests);
        }
Пример #3
0
        private void Save()
        {
            if (currTest != null && !IsTestChanged)
            {
                CloseForm();
            }

            QTests.CommitEdit();

            if (TestName.Text == string.Empty)
            {
                ErrorLabel.Content    = "[ Введите название теста ]";
                ErrorLabel.Visibility = Visibility.Visible;
                return;
            }

            if (currTest == null && !repository.CheckTestName(TestName.Text))
            {
                ErrorLabel.Content    = "[ Тест с таким названием уже существует ]";
                ErrorLabel.Visibility = Visibility.Visible;
                return;
            }

            if (_QTests.Count < 5)
            {
                ErrorLabel.Content    = "[ Минимальное число вопросов - 5 ]";
                ErrorLabel.Visibility = Visibility.Visible;
                return;
            }

            if (_QTests.Where(x => x.Question == string.Empty ||
                              x.RightAnswer == string.Empty ||
                              x.WrongAnswers == string.Empty).Any())
            {
                ErrorLabel.Content    = "[ Все ячейки должны быть заполнены ]";
                ErrorLabel.Visibility = Visibility.Visible;
                return;
            }

            var test_id = repository.SaveTest(new Test {
                TestID   = currTest == null ? 0 : currTest.TestID,
                Name     = $"{TestType.SelectedIndex}{TestName.Text}",
                Priority = (byte)TestRank.SelectedIndex,
                Time     = (byte)((TestTime.SelectedIndex + 1) * 15)
            }).TestID;

            List <QTest> qtests = new List <QTest>();

            foreach (var x in _QTests)
            {
                qtests.Add(new QTest {
                    QTestID      = x.QTestID,
                    TestID       = test_id,
                    Question     = x.Question,
                    RightAnswer  = x.RightAnswer,
                    WrongAnswers = x.WrongAnswers
                });
            }
            repository.SaveQTests(qtests);

            GetTests();
        }