コード例 #1
0
        private void buttonAdd_Click(object sender, EventArgs e)
        {
            int curr_select_id = Convert.ToInt32(selectList.SelectedItem.ToString());

            if (textBoxQuestion.Text == string.Empty || textBoxAnswer.Text == string.Empty)
            {
                MessageBox.Show("Заповніть всі поля", "Помилка", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            if (!radio1_checked && !radio2_checked)
            {
                MessageBox.Show("Оберіть варіант відповіді", "Помилка", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                using (TestingAppEntities context = new TestingAppEntities())
                {
                    try
                    {
                        Question q = new Question
                        {
                            Text       = textBoxQuestion.Text,
                            CategoryId = curr_select_id
                        };

                        int id = q.Id;

                        if (radioButton1.Checked)
                        {
                            radio = true;
                        }

                        Answer a = new Answer
                        {
                            Text       = textBoxAnswer.Text,
                            IsTrue     = radio,
                            QuestionId = q.Id
                        };

                        context.Questions.Add(q);
                        context.Answers.Add(a);
                        context.SaveChanges();

                        MessageBox.Show("Додано");

                        textBoxQuestion.Text = string.Empty;
                        textBoxAnswer.Text   = string.Empty;

                        admin.QuestionsLoadAfterAddNew();

                        this.Close();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.ToString());
                    }
                }
            }
        }
コード例 #2
0
        private void buttonReg_Click(object sender, EventArgs e)
        {
            if (textBoxFName.Text == string.Empty || textBoxLName.Text == string.Empty || textBoxEmail.Text == string.Empty ||
                textBoxLogin.Text == string.Empty || textBoxPassword.Text == string.Empty)
            {
                MessageBox.Show("Заповніть всі поля", "Помилка", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                using (TestingAppEntities context = new TestingAppEntities())
                {
                    context.Users.Load();

                    var user = context.Users.FirstOrDefault(u => u.Login == textBoxLogin.Text && u.Email == textBoxEmail.Text);

                    if (user != null)
                    {
                        MessageBox.Show("Такий користувач вже існує", "Помилка", MessageBoxButtons.OK, MessageBoxIcon.Error);

                        textBoxFName.Text    = string.Empty;
                        textBoxLName.Text    = string.Empty;
                        textBoxEmail.Text    = string.Empty;
                        textBoxLogin.Text    = string.Empty;
                        textBoxPassword.Text = string.Empty;
                    }
                    else
                    {
                        try
                        {
                            context.Users.Add(new User
                            {
                                FirstName = textBoxFName.Text,
                                LastName  = textBoxLName.Text,
                                Email     = textBoxEmail.Text,
                                Login     = textBoxLogin.Text,
                                Password  = textBoxPassword.Text
                            });

                            context.SaveChanges();

                            MessageBox.Show("Ви успішно зареєструвались", "Вітаємо", MessageBoxButtons.OK);
                            this.Close();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.ToString());
                        }
                    }
                }
            }
        }
コード例 #3
0
        private void EndTestClick(object sender, EventArgs e)
        {
            int right_answers = 0;
            int wrong_answers = 0;

            foreach (var rb in radio_bool)
            {
                if (rb == true)
                {
                    right_answers++;
                }
                else
                {
                    wrong_answers++;
                }
            }

            using (TestingAppEntities context = new TestingAppEntities())
            {
                try
                {
                    context.Results.Add(new Result
                    {
                        CountRightAnswers = right_answers,
                        CountWrongAnswers = wrong_answers,
                        CategoryId        = selected_id,
                        UserId            = user.Id
                    });

                    context.SaveChanges();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }

            MessageBox.Show($"Шановний {user.Login}!\n Ви закінчили проходження тесту!\n\n Правильних відповідей: {right_answers}. Неправильних: {wrong_answers}");

            this.Close();
        }
コード例 #4
0
        private void buttonCreate_Click(object sender, EventArgs e)
        {
            if (textBoxTestName.Text == string.Empty || textBoxQuestion.Text == string.Empty ||
                textBoxAnswer.Text == string.Empty)
            {
                MessageBox.Show("Всі поля мають бути заповнені", "Помилка", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            if (!radio1_checked && !radio2_checked)
            {
                MessageBox.Show("Оберіть варіант відповіді", "Помилка", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                using (TestingAppEntities context = new TestingAppEntities())
                {
                    context.Categories.ToList();
                    var category = context.Categories.FirstOrDefault(cat => cat.TestName == textBoxTestName.Text);
                    if (category != null)
                    {
                        MessageBox.Show("Така категорія вже існує", "Помилка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        Category c = new Category
                        {
                            TestName = textBoxTestName.Text
                        };

                        Question q = new Question
                        {
                            Text       = textBoxQuestion.Text,
                            CategoryId = c.Id
                        };

                        if (radioButton1.Text == "Правильна")
                        {
                            radio = true;
                        }
                        Answer a = new Answer
                        {
                            Text       = textBoxAnswer.Text,
                            IsTrue     = radio,
                            QuestionId = q.Id
                        };

                        try
                        {
                            context.Categories.Add(c);
                            context.Questions.Add(q);
                            context.Answers.Add(a);

                            context.SaveChanges();
                            MessageBox.Show(c.TestName + " створено");

                            textBoxTestName.Text = string.Empty;
                            textBoxQuestion.Text = string.Empty;
                            textBoxAnswer.Text   = string.Empty;

                            admin.SelectLoadAfterAddNewCategory();

                            this.Close();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.ToString());
                        }
                    }
                }
            }
        }