Esempio n. 1
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);
         }
     }
 }
Esempio n. 2
0
 private void btnNext_Click(object sender, RoutedEventArgs e)
 {
     //проверяем был ли ответ
     if (!beAnswer)
     {
         return;
     }
     //проверяем правильность ответа
     using (TestingEntities db = new TestingEntities())
     {
         int    i      = listQuestion[idQuestion].id;
         Answer answer = db.Answers.FirstOrDefault(a => a.questionId == i && a.answer_name == Ans);
         if (answer.correctly != 0)
         {
             correctAnswer++;
         }
     }
     idQuestion++;
     //если вопросов больше нет
     if (idQuestion == totalAnswer)
     {
         viewRusult window = new viewRusult(studentId, testId, totalAnswer, correctAnswer);
         window.Show();
         this.Close();
     }
     else
     {
         initList();
     }
     beAnswer = false;
 }
Esempio n. 3
0
        private void ComboBoxItemQueation_Selected(object sender, RoutedEventArgs e)
        {
            //выбор вопроса
            listBox.Items.Clear();
            string nameQuestion = ((sender as ComboBoxItem).Content as TextBlock).Text;

            using (TestingEntities db = new TestingEntities())
            {
                //заполнение листа ответами
                Question question = db.Questions.FirstOrDefault(q => q.name_question == nameQuestion);
                idQuestion = question.id;
                var answers = db.Answers.Where(a => a.questionId == idQuestion);
                if (answers == null)
                {
                    addListBoxItem("");
                    addListBoxItem("");
                }
                else
                {
                    foreach (Answer item in answers)
                    {
                        addListBoxItem(item.answer_name);
                    }
                }
            }
        }
Esempio n. 4
0
 private void initList()
 {
     listAnswer.Items.Clear();
     txtNameQuestion.Text = "";
     using (TestingEntities db = new TestingEntities())
     {
         txtNameQuestion.Text = listQuestion[idQuestion].name_question;
         int i = listQuestion[idQuestion].id;
         //получаем вопрос
         var answers = db.Answers.Where(a => a.questionId == i);
         //заполняем список ответов
         foreach (Answer item in answers)
         {
             ListBoxItem listBoxItem = new ListBoxItem();
             listBoxItem.Margin = new Thickness(5);
             StackPanel stackItem = new StackPanel();
             stackItem.Orientation = Orientation.Horizontal;
             TextBlock textBlock = new TextBlock();
             textBlock.MaxWidth     = 750;
             textBlock.TextWrapping = TextWrapping.Wrap;
             textBlock.Text         = item.answer_name;
             RadioButton radio = new RadioButton {
                 IsChecked = false, GroupName = "Answer"
             };
             radio.Checked += radio_Checked;
             stackItem.Children.Add(radio);
             stackItem.Children.Add(textBlock);
             listBoxItem.Content = stackItem;
             listAnswer.Items.Add(listBoxItem);
         }
     }
 }
Esempio n. 5
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);
         }
     }
 }
 //заполнение списка
 void initList(bool isTest)
 {
     listBox.Items.Clear();
     using (TestingEntities db = new TestingEntities())
     {
         //заполнение списка тестов
         if (isTest)
         {
             var tests = db.Tests;
             foreach (var item in tests)
             {
                 ListBoxItem listBoxItem = new ListBoxItem();
                 listBoxItem.Margin = new Thickness(5);
                 TextBlock textBlock = new TextBlock();
                 textBlock.Text      = item.name_test;
                 listBoxItem.Content = textBlock;
                 listBox.Items.Add(listBoxItem);
             }
         }
         else
         {
             //заполнение списка студентов
             var students = db.Users.Where(u => u.Role.role_name == "Студент");
             foreach (var item in students)
             {
                 ListBoxItem listBoxItem = new ListBoxItem();
                 listBoxItem.Margin = new Thickness(5);
                 TextBlock textBlock = new TextBlock();
                 textBlock.Text      = item.first_name + " " + item.last_name;
                 listBoxItem.Content = textBlock;
                 listBox.Items.Add(listBoxItem);
             }
         }
     }
 }
Esempio n. 7
0
 private void ComboBoxItemQueation_Selected(object sender, RoutedEventArgs e)
 {
     txtQuestion.Text = "";
     txtQuestion.Text = ((sender as ComboBoxItem).Content as TextBlock).Text;
     using (TestingEntities db = new TestingEntities()) {
         Question question = db.Questions.FirstOrDefault(q => q.name_question == txtQuestion.Text);
         questionId = question.id;
     }
 }
Esempio n. 8
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();
     }
 }
Esempio n. 9
0
 void PassingTest_Loaded(object sender, RoutedEventArgs e)
 {
     using (TestingEntities db = new TestingEntities())
     {
         //получаем выбранный тест
         Test test = db.Tests.First(t => t.id == testId);
         txtNameTest.Text = test.name_test;
         totalAnswer      = db.Questions.Where(q => q.testId == testId).Count();
         listQuestion     = db.Questions.Where(q => q.testId == testId).ToList();
         initList();
     }
 }
Esempio n. 10
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();
     }
 }
Esempio n. 11
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();
     }
 }
Esempio n. 12
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();
            }
        }
Esempio n. 13
0
 private void RedactorAnswer_Loaded(object sender, RoutedEventArgs e)
 {
     using (TestingEntities db = new TestingEntities())
     {
         var tests = db.Tests;
         foreach (Test item in tests)
         {
             ComboBoxItem comboBoxItem = new ComboBoxItem();
             TextBlock    textBlock    = new TextBlock();
             textBlock.Text         = item.name_test;
             comboBoxItem.Content   = textBlock;
             comboBoxItem.Selected += ComboBoxItem_Selected;
             cmbTest.Items.Add(comboBoxItem);
         }
     }
 }
Esempio n. 14
0
 private void RedaktorTestov_Loaded(object sender, RoutedEventArgs e)
 {
     using (TestingEntities db = new TestingEntities())
     {
         var tests = db.Tests;
         //заполняем комбобокс тестами
         foreach (Test item in tests)
         {
             ComboBoxItem comboBoxItem = new ComboBoxItem();
             TextBlock    textBlock    = new TextBlock();
             textBlock.Text         = item.name_test;
             comboBoxItem.Content   = textBlock;
             comboBoxItem.Selected += ComboBoxItem_Selected;
             cmbTests.Items.Add(comboBoxItem);
         }
     }
 }
        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();
            }
        }
Esempio n. 16
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();
                }
            }
        }
Esempio n. 17
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();
     }
 }
 private void Button_Click(object sender, RoutedEventArgs e)
 {
     using (TestingEntities db = new TestingEntities())
     {
         User user = db.Users.FirstOrDefault(u => u.user_login == txtLogin.Text);
         //Проверяем правильность ввода данных
         if (user == null || txtPaasword.Password != user.user_password)
         {
             lblErr.Visibility = Visibility.Visible;
             lblErr.Visibility = Visibility.Visible;
             txtLogin.Clear();
             txtPaasword.Clear();
             txtLogin.Focus();
             return;
         }
         bool role;
         //Выбор интерфейса преподаватель/студент
         role = (user.Role.role_name == "Преподаватель") ? true : false;
         MainWindowProgram window = new MainWindowProgram(role, user.id);
         window.Show();
         this.Close();
     }
 }
Esempio n. 19
0
 private void ComboBoxItem_Selected(object sender, RoutedEventArgs e)
 {
     //заполняем ответы по выбраному тесту
     txtTest.Text = "";
     txtTest.Text = ((sender as ComboBoxItem).Content as TextBlock).Text;
     cmbQuestion.Items.Clear();
     txtAddQuestion.Clear();
     txtQuestion.Clear();
     using (TestingEntities db = new TestingEntities())
     {
         Test test = db.Tests.FirstOrDefault(t => t.name_test == txtTest.Text);
         testId = test.id;
         var questions = db.Questions.Where(q => q.testId == testId);
         foreach (Question item in questions)
         {
             ComboBoxItem comboBoxItemQueation = new ComboBoxItem();
             TextBlock    textBlock            = new TextBlock();
             textBlock.Text = item.name_question;
             comboBoxItemQueation.Content   = textBlock;
             comboBoxItemQueation.Selected += ComboBoxItemQueation_Selected;
             cmbQuestion.Items.Add(comboBoxItemQueation);
         }
     }
 }
Esempio n. 20
0
        private void ComboBoxItem_Selected(object sender, RoutedEventArgs e)
        {
            //выбор теста
            cmbQuestion.Items.Clear();
            listBox.Items.Clear();
            string nameTest = ((sender as ComboBoxItem).Content as TextBlock).Text;

            using (TestingEntities db = new TestingEntities())
            {
                Test test = db.Tests.FirstOrDefault(t => t.name_test == nameTest);
                idTest = test.id;
                var questions = db.Questions.Where(q => q.testId == idTest);
                //заполнение комбобокса вапросами
                foreach (Question item in questions)
                {
                    ComboBoxItem comboBoxItemQueation = new ComboBoxItem();
                    TextBlock    textBlock            = new TextBlock();
                    textBlock.Text = item.name_question;
                    comboBoxItemQueation.Content   = textBlock;
                    comboBoxItemQueation.Selected += ComboBoxItemQueation_Selected;;
                    cmbQuestion.Items.Add(comboBoxItemQueation);
                }
            }
        }
        private void btnResults_Click(object sender, RoutedEventArgs e)
        {
            if (listBox.SelectedItem == null)
            {
                return;
            }
            //если интерфейс преподавателя
            if (isTeacher)
            {
                using (TestingEntities db = new TestingEntities())
                {
                    //исли активен список студентов
                    if (isStudent)
                    {
                        //получаем имя и фамилию студента, выбранного в списке
                        string studentName = ((listBox.SelectedItem as ListBoxItem).Content as TextBlock).Text;
                        var    tests       = db.Tests;
                        //выбираем результаты по выбранному студенту
                        var results = db.UserRatings.Where(r => (r.User.first_name + " " + r.User.last_name) == studentName).ToList();
                        listBox.Items.Clear();
                        //заполняем листбокс
                        foreach (var item in tests)
                        {
                            UserRating  rating      = results.FirstOrDefault(r => r.testId == item.id);
                            ListBoxItem listBoxItem = new ListBoxItem();
                            listBoxItem.Margin = new Thickness(5);
                            TextBlock textBlock = new TextBlock();
                            //если студент не здавал еще тест
                            if (rating == null)
                            {
                                textBlock.Text = item.name_test + "\t не здавал";
                            }
                            //оценка
                            else
                            {
                                textBlock.Text = item.name_test + " \t" + rating.rating + "%";
                            }
                            listBoxItem.Content = textBlock;
                            listBox.Items.Add(listBoxItem);
                        }
                    }
                    else
                    {
                        //если активен список тестов
                        int testId = listBox.SelectedIndex + 1;

                        listBox.Items.Clear();
                        foreach (var item in db.Users.Where(u => u.Role.role_name == "Студент"))
                        {
                            //выбераем результаты по каждому тесту
                            UserRating  result      = db.UserRatings.FirstOrDefault(r => (r.testId == testId) && (r.userId == item.id));
                            ListBoxItem listBoxItem = new ListBoxItem();
                            listBoxItem.Margin = new Thickness(5);
                            TextBlock textBlock = new TextBlock();
                            //если результатов нет
                            if (result == null)
                            {
                                textBlock.Text = item.first_name + " " + item.last_name + "\t не здавал";
                            }
                            else
                            {
                                textBlock.Text = item.first_name + " " + item.last_name + "\t" + result.rating + "%";
                            }
                            listBoxItem.Content = textBlock;
                            listBox.Items.Add(listBoxItem);
                        }
                    }
                }
            }
            else
            {
                //интерфейс студента
                using (TestingEntities db = new TestingEntities())
                {
                    //выбираем все тесты по данному студенту
                    int  testId = listBox.SelectedIndex + 1;
                    Test tests  = db.Tests.FirstOrDefault(t => t.id == testId);
                    listBox.Items.Clear();
                    UserRating  results     = db.UserRatings.FirstOrDefault(r => (r.userId == id) && (r.testId == tests.id));
                    ListBoxItem listBoxItem = new ListBoxItem();
                    listBoxItem.Margin = new Thickness(5);
                    TextBlock textBlock = new TextBlock();
                    //если результатов нет
                    if (results == null)
                    {
                        textBlock.Text = tests.name_test + " \tне здавал";
                    }
                    //оценка
                    else
                    {
                        textBlock.Text = tests.name_test + "\t " + results.rating + "%";
                    }
                    listBoxItem.Content = textBlock;
                    listBox.Items.Add(listBoxItem);
                }
            }
        }