コード例 #1
0
        private void selectList_SelectedIndexChanged(object sender, EventArgs e)
        {
            dataGridView1.Rows.Clear();
            select_id = Convert.ToInt32(selectList.SelectedItem.ToString());

            using (TestingAppEntities context = new TestingAppEntities())
            {
                context.Questions.Load();

                foreach (var item in context.Questions.Local.Where(i => i.CategoryId == select_id).ToList())
                {
                    object[] row = { item.Id, item.Text };
                    dataGridView1.Rows.Add(row);
                    dataGridView1.Refresh();
                }

                int curr_id = Convert.ToInt32(dataGridView1.Rows[0].Cells[0].Value);

                dataGridView2.Rows.Clear();
                foreach (var item in context.Answers.Where(i => i.QuestionId == curr_id))
                {
                    object[] row = { item.Id, item.Text };
                    dataGridView2.Rows.Add(row);
                    dataGridView2.Refresh();
                }
            }
        }
コード例 #2
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());
                    }
                }
            }
        }
コード例 #3
0
 public void SelectLoadAfterAddNewCategory()
 {
     using (TestingAppEntities context = new TestingAppEntities())
     {
         var test = context.Categories.ToList();
         selectList.DataSource    = test;
         selectList.DisplayMember = "TestName";
     }
 }
コード例 #4
0
 private void StartTestForm_Load(object sender, EventArgs e)
 {
     using (TestingAppEntities context = new TestingAppEntities())
     {
         var test = context.Categories.ToList();
         selectList.DataSource    = test;
         selectList.DisplayMember = "TestName";
     }
 }
コード例 #5
0
        private void selectListCategory_SelectedIndexChanged(object sender, EventArgs e)
        {
            int selected_id = Convert.ToInt32(selectListCategory.SelectedItem.ToString());

            using (TestingAppEntities context = new TestingAppEntities())
            {
                var question = context.Questions.Where(q => q.CategoryId == selected_id).ToList();
                selectListQuestion.DataSource    = question;
                selectListQuestion.DisplayMember = "Text";
            }
        }
コード例 #6
0
        private void AddAnswersForm_Load(object sender, EventArgs e)
        {
            using (TestingAppEntities context = new TestingAppEntities())
            {
                var category = context.Categories.ToList();
                selectListCategory.DataSource    = category;
                selectListCategory.DisplayMember = "TestName";

                var question = context.Questions.Where(q => q.CategoryId == 1).ToList();
                selectListQuestion.DataSource    = question;
                selectListQuestion.DisplayMember = "Text";
            }
        }
コード例 #7
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());
                        }
                    }
                }
            }
        }
コード例 #8
0
        public void AnswersLoadAfterAddNew(int curr_select_id)
        {
            dataGridView2.Rows.Clear();

            using (TestingAppEntities context = new TestingAppEntities())
            {
                context.Answers.Load();

                foreach (var item in context.Answers.Local.Where(i => i.QuestionId == curr_select_id /*== select_id*/))
                {
                    object[] row = { item.Id, item.Text };
                    dataGridView2.Rows.Add(row);
                }
            }
        }
コード例 #9
0
        private void dataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            select_id = (int)dataGridView1.Rows[e.RowIndex].Cells[0].Value;

            dataGridView2.Rows.Clear();
            using (TestingAppEntities context = new TestingAppEntities())
            {
                context.Answers.Load();

                foreach (var item in context.Answers.Local.Where(i => i.QuestionId == select_id))
                {
                    object[] row = { item.Id, item.Text };
                    dataGridView2.Rows.Add(row);
                }
            }
        }
コード例 #10
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();
        }
コード例 #11
0
        private void buttonLogin_Click(object sender, EventArgs e)
        {
            if (textBoxLogin.Text == string.Empty || textBoxPassword.Text == string.Empty)
            {
                MessageBox.Show("Заповніть всі поля", "Помилка", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                using (TestingAppEntities context = new TestingAppEntities())
                {
                    var user = context.Users.FirstOrDefault(u => u.Login == textBoxLogin.Text && u.Password == textBoxPassword.Text);

                    if (user != null)
                    {
                        MessageBox.Show("Привіт " + user.Login, "Вітаємо", MessageBoxButtons.OK);

                        if (user.Login == "admin")
                        {
                            new AdminForm().Show();
                            this.Hide();
                        }
                        else
                        {
                            new StartTestForm(user).Show();
                            this.Hide();
                        }
                    }
                    else
                    {
                        MessageBox.Show("Неправильний логін/пароль", "Помилка", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        textBoxLogin.Text    = string.Empty;
                        textBoxPassword.Text = string.Empty;
                    }
                }
            }
        }
コード例 #12
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());
                        }
                    }
                }
            }
        }
コード例 #13
0
        private void TestingProcessForm_Load(object sender, EventArgs e)
        {
            using (TestingAppEntities context = new TestingAppEntities())
            {
                var question = context.Questions.Include(q => q.Answers).Where(q => q.CategoryId == selected_id).ToList();
                question_count = question.Count;

                listAnswers = new List <Answer>();
                foreach (var itemQ in question)
                {
                    if (itemQ.Answers == null)
                    {
                        return;
                    }

                    foreach (var itemA in itemQ.Answers)
                    {
                        listAnswers.Add(itemA);
                    }
                }

                var current_answers = listAnswers.Where(l => l.QuestionId == question[0].Id).Select(q => new { Text = q.Text, Id = q.Id, IsTrue = q.IsTrue }).ToArray();

                int count_answers = 0;

                foreach (var item in current_answers)
                {
                    count_answers++;
                }

                Label label = new Label();
                label.Text = $"Питання {page_load_counter} з {question_count}";
                flowLayoutPanel1.Controls.Add(label);

                GroupBox gb = new GroupBox();
                gb.Size = new Size(480, 250);
                gb.Text = question[0].Text;

                RadioButton[] rb = new RadioButton[count_answers];

                int top = 30;
                for (int i = 0; i < count_answers; i++)
                {
                    rb[i] = new RadioButton();
                    if (i >= 1)
                    {
                        top += 30;
                    }
                    rb[i].Location        = new Point(15, top);
                    rb[i].AutoSize        = true;
                    rb[i].Text            = current_answers[i].Text;
                    rb[i].Tag             = current_answers[i].IsTrue;
                    rb[i].CheckedChanged += RadioChecked;

                    gb.Controls.Add(rb[i]);
                }

                flowLayoutPanel1.Controls.Add(gb);

                btnNext.Text   = "Далі";
                btnNext.Click += BtnNext_Click;
                btnBack.Text   = "Назад";
                btnBack.Click += BtnBack_Click;
                if (page_load_counter == 1)
                {
                    btnBack.Enabled = false;
                }

                flowLayoutPanel1.Controls.AddRange(new Button[] { btnBack, btnNext });
            }
        }
コード例 #14
0
        private void BtnNext_Click(object sender, EventArgs e)
        {
            page_load_counter++;

            using (TestingAppEntities context = new TestingAppEntities())
            {
                flowLayoutPanel1.Controls.Clear();

                var question        = context.Questions.Include(q => q.Answers).Where(q => q.CategoryId == selected_id).ToList();
                var current_answers = listAnswers.Where(a => a.QuestionId == question[page_load_counter - 1].Id).ToArray();

                int count_answers = 0;

                foreach (var item in current_answers)
                {
                    count_answers++;
                }

                Label label = new Label();
                label.Text = $"Питання {page_load_counter} з {question.Count}";
                flowLayoutPanel1.Controls.Add(label);

                GroupBox gb = new GroupBox();
                gb.Text = question[page_load_counter - 1].Text;
                gb.Size = new Size(480, 250);

                RadioButton[] rb = new RadioButton[count_answers];

                int top = 30;
                for (int i = 0; i < count_answers; i++)
                {
                    rb[i] = new RadioButton();
                    if (i >= 1)
                    {
                        top += 30;
                    }
                    rb[i].Location = new Point(15, top);
                    rb[i].AutoSize = true;
                    rb[i].Text     = current_answers[i].Text;
                    rb[i].Tag      = current_answers[i].IsTrue;

                    foreach (var item in radio_text)
                    {
                        if (item == rb[i].Text)
                        {
                            rb[i].Checked = true;
                        }
                    }

                    rb[i].CheckedChanged += RadioChecked;

                    gb.Controls.Add(rb[i]);
                }

                flowLayoutPanel1.Controls.Add(gb);

                btnNext.Text = "Далі";
                if (page_load_counter == question_count)
                {
                    btnNext.Enabled = false;
                }
                btnBack.Text    = "Назад";
                btnBack.Enabled = true;

                flowLayoutPanel1.Controls.AddRange(new Button[] { btnBack, btnNext });

                Button btnEnd = new Button();
                if (page_load_counter == question_count)
                {
                    btnEnd.Text = "Завершити";
                    flowLayoutPanel1.Controls.Add(btnEnd);
                }

                btnEnd.Click += EndTestClick;
            }
        }