Exemple #1
0
 private void btnSaveQuestion_Click(object sender, RoutedEventArgs e)
 {
     //добавление нового вопроса
     if (txtAddQuestion.Text == "")
     {
         return;
     }
     using (TestingEntities db = new TestingEntities())
     {
         Question question = db.Questions.FirstOrDefault(q => q.name_question == txtAddQuestion.Text);
         //проверка на уникальность вопроса
         if (question == null)
         {
             int id = cmbTests.SelectedIndex + 1;
             db.Questions.Add(new Question {
                 name_question = txtAddTest.Text, testId = id
             });
             db.SaveChanges();
         }
         else
         {
             MessageBox.Show("Вопрос уже существует.");
             btnClearQuestion_Click(null, null);
         }
     }
 }
Exemple #2
0
 private void btnSave_Click(object sender, RoutedEventArgs e)
 {
     //добавление нового теста
     if (txtAddTest.Text == "")
     {
         return;
     }
     using (TestingEntities db = new TestingEntities())
     {
         Test test = db.Tests.FirstOrDefault(t => t.name_test == txtAddTest.Text);
         //проверка на уникальность нового названия
         if (test == null)
         {
             db.Tests.Add(new Test {
                 name_test = txtAddTest.Text
             });
             db.SaveChanges();
         }
         else
         {
             MessageBox.Show("Тест с таким названием уже существует.");
             btnClear_Click(null, null);
         }
     }
 }
Exemple #3
0
 private void btnDelQuestion_Click(object sender, RoutedEventArgs e)
 {
     //удаление выбраного вопроса
     using (TestingEntities db = new TestingEntities())
     {
         db.Questions.Remove(db.Questions.First(q => q.id == questionId));
         var deleteAnswer = db.Answers.Where(a => a.questionId == questionId);
         //удаление ответов удаленного вопроса
         db.Answers.RemoveRange(deleteAnswer);
         db.SaveChanges();
     }
 }
Exemple #4
0
 private void btnChangeQuestion_Click(object sender, RoutedEventArgs e)
 {
     //редактирование вопроса
     if (txtQuestion.Text == "")
     {
         return;
     }
     using (TestingEntities db = new TestingEntities())
     {
         db.Questions.First(q => q.id == questionId).name_question = txtTest.Text;
         db.SaveChanges();
     }
 }
Exemple #5
0
 private void Button_Click_1(object sender, RoutedEventArgs e)
 {
     //редактирование теста
     if (txtTest.Text == "")
     {
         return;
     }
     using (TestingEntities db = new TestingEntities())
     {
         db.Tests.First(t => t.id == testId).name_test = txtTest.Text;
         db.SaveChanges();
     }
 }
Exemple #6
0
        private void btnDeleteAnswer_Click(object sender, RoutedEventArgs e)
        {
            if (deleteAnswer.Count == 0)
            {
                return;
            }
            string answer = deleteAnswer.FirstOrDefault(a => a == correctlyAnswer);

            //проверка на удаление правильного ответа
            if (answer != null)
            {
                MessageBox.Show("Вы удаляете ответ, помеченный как правильный.");
                return;
            }
            int countListBoxItem = 0;

            foreach (var item in listBox.Items)
            {
                countListBoxItem++;
            }
            //удаление вопросов из листа
            for (int i = 0; i < countListBoxItem; i++)
            {
                foreach (var item in ((listBox.Items[i] as ListBoxItem).Content as StackPanel).Children)
                {
                    if (item is TextBox)
                    {
                        string answerItem = (item as TextBox).Text;
                        answer = deleteAnswer.FirstOrDefault(a => a == answerItem);
                        if (answer != null)
                        {
                            listBox.Items.Remove(listBox.Items[i]);
                        }
                    }
                }
            }
            //удаление вопросов из базы
            using (TestingEntities db = new TestingEntities())
            {
                foreach (string item in deleteAnswer)
                {
                    Answer ans = db.Answers.FirstOrDefault(a => a.answer_name == item);
                    if (ans != null)
                    {
                        db.Answers.Remove(ans);
                    }
                }
                db.SaveChanges();
            }
        }
        private void ViewRusult_Loaded(object sender, RoutedEventArgs e)
        {
            User name;
            Test testName;

            //заполняем результаты теста
            using (TestingEntities db = new TestingEntities())
            {
                name            = db.Users.FirstOrDefault(u => u.id == studentId);
                testName        = db.Tests.FirstOrDefault(t => t.id == testId);
                txtResult.Text  = "Студент: " + name.first_name + " " + name.last_name + "\nТест: " + testName.name_test + "\nВсего вопросов: " + totalAnswer.ToString();
                txtResult.Text += "\nПравильных ответов: " + correntlyAnswer.ToString() + "\nРезультат: " + ((int)((double)correntlyAnswer / totalAnswer * 100)).ToString() + "%";
                db.UserRatings.Add(new UserRating {
                    userId = studentId, testId = this.testId, rating = ((int)((double)correntlyAnswer / totalAnswer * 100)).ToString()
                });
                db.SaveChanges();
            }
        }
Exemple #8
0
        private void btnSaveAnswers_Click(object sender, RoutedEventArgs e)
        {
            int countListBoxItem = 0;

            foreach (var item in listBox.Items)
            {
                countListBoxItem++;
            }
            //сохранение ответов
            using (TestingEntities db = new TestingEntities())
            {
                string answerItem  = "";
                bool?  isCorrectly = false;
                var    answers     = db.Answers.Where(a => a.questionId == idQuestion);
                db.Answers.RemoveRange(answers);
                for (int i = 0; i < countListBoxItem; i++)
                {
                    foreach (var item in ((listBox.Items[i] as ListBoxItem).Content as StackPanel).Children)
                    {
                        if (item is TextBox)
                        {
                            answerItem = (item as TextBox).Text;
                        }
                        else if (item is StackPanel)
                        {
                            foreach (var item1 in (item as StackPanel).Children)
                            {
                                if (item1 is RadioButton)
                                {
                                    isCorrectly = (item1 as RadioButton).IsChecked;
                                }
                            }
                        }
                    }
                    Answer newAnswer = new Answer();
                    newAnswer.answer_name = answerItem;
                    newAnswer.questionId  = idQuestion;
                    newAnswer.correctly   = (isCorrectly == false) ? 0 : 1;
                    db.Answers.Add(newAnswer);
                    db.SaveChanges();
                }
            }
        }
Exemple #9
0
 private void Button_Click(object sender, RoutedEventArgs e)
 {
     //удаление теста
     if (cmbTests.SelectedItem == null)
     {
         return;
     }
     using (TestingEntities db = new TestingEntities())
     {
         db.Tests.Remove(db.Tests.First(t => t.id == testId));
         var deleteQestion = db.Questions.Where(q => q.testId == testId);
         //удаление вопросов и ответов удаленного теста
         foreach (Question item in deleteQestion)
         {
             var deleteAnswer = db.Answers.Where(a => a.questionId == item.id);
             db.Answers.RemoveRange(deleteAnswer);
         }
         db.Questions.RemoveRange(deleteQestion);
         db.SaveChanges();
     }
 }