Пример #1
0
        private void Prev_Click(object sender, EventArgs e)
        {
            if (this.StudAns.Count > 0)
            {
                int i = 0;
                foreach (System.Windows.Forms.CheckBox chkBx in this.checkBoxes)
                {
                    this.tableLayoutPanel1.Controls.Remove(chkBx);
                }

                this.CurrQuestion = new GlobalClass.QuestionAnswersMapper(this.StudAns.Last().ID, this.StudAns.Last().ID_subject, this.StudAns.Last().Question, this.StudAns.Last().AnswerCount, this.StudAns.Last().Answers);
                this.StudAns.Remove(this.StudAns.Last());
                this.QuestionBox.Text = this.CurrQuestion.Question;
                checkBoxes            = new List <CheckBox>();
                i = 0;
                foreach (GlobalClass.AnswerMapper sd in this.CurrQuestion.Answers)
                {
                    System.Windows.Forms.CheckBox AnswerCheckBox = new System.Windows.Forms.CheckBox();
                    checkBoxes.Add(AnswerCheckBox);
                    AnswerCheckBox.AutoSize = true;
                    AnswerCheckBox.Name     = "AnswerCheckBox" + i;
                    AnswerCheckBox.Size     = new System.Drawing.Size(431, 167);
                    AnswerCheckBox.TabIndex = 0;
                    AnswerCheckBox.Text     = sd.Answer;
                    AnswerCheckBox.UseVisualStyleBackColor = true;
                    this.tableLayoutPanel1.Controls.Add(AnswerCheckBox, i % 2, (i - i % 2) / 2);
                    i++;
                    checkBoxes.Add(AnswerCheckBox);
                }
            }
        }
Пример #2
0
        public TestingForm(List <GlobalClass.QuestionAnswersMapper> Test, int test_id, int user_id)
        {
            InitializeComponent();
            this.testId           = test_id;
            this.userId           = user_id;
            this.SetTest          = Test;
            this.CurrQuestion     = this.SetTest[0];
            this.QuestionBox.Text = this.CurrQuestion.Question;
            checkBoxes            = new List <CheckBox>();
            int i = 0;

            foreach (GlobalClass.AnswerMapper sd in this.CurrQuestion.Answers)
            {
                System.Windows.Forms.CheckBox AnswerCheckBox = new System.Windows.Forms.CheckBox();
                AnswerCheckBox.AutoSize = true;
                AnswerCheckBox.Name     = "AnswerCheckBox" + i;
                AnswerCheckBox.Size     = new System.Drawing.Size(431, 167);
                AnswerCheckBox.TabIndex = 0;
                AnswerCheckBox.Text     = sd.Answer;
                AnswerCheckBox.UseVisualStyleBackColor = true;
                this.tableLayoutPanel1.Controls.Add(AnswerCheckBox, i % 2, (i - i % 2) / 2);
                i++;
                checkBoxes.Add(AnswerCheckBox);
            }
        }
Пример #3
0
        private void StudentGridView_CellDoubleClick(object sender, DataGridViewCellEventArgs location)
        {
            int rowId = (int)((long)StudentGridView.Rows[this.mouseLocation.RowIndex].Cells["ID"].Value);

            SelectedTest = this.elementBase.SelectOneTest(rowId);
            List <GlobalClass.QuestionAnswersMapper> setQuestion = new List <GlobalClass.QuestionAnswersMapper>();

            IEnumerable <IGrouping <string, GlobalClass.AnswerWithQuestionMapper> > query =
                SelectedTest.GroupBy(Question => Question.Question, Question => Question);

            foreach (IGrouping <string, GlobalClass.AnswerWithQuestionMapper> QuestionGRoup in query)
            {
                List <GlobalClass.AnswerMapper> tempAnswers = new List <GlobalClass.AnswerMapper>();
                // Print the key value of the IGrouping.
                // Iterate over each value in the
                // IGrouping and print the value.
                int id_Q = -1;
                foreach (GlobalClass.AnswerWithQuestionMapper Answer in QuestionGRoup)
                {
                    GlobalClass.AnswerMapper tempAnswer = new GlobalClass.AnswerMapper(Answer.ID_Answer, Answer.Answer, Answer.isTrue);
                    id_Q = Answer.ID_Question;
                    tempAnswers.Add(tempAnswer);
                }
                GlobalClass.QuestionAnswersMapper tempQuestion = new GlobalClass.QuestionAnswersMapper(id_Q, -1, QuestionGRoup.Key, tempAnswers.Count, tempAnswers);
                setQuestion.Add(tempQuestion);
            }

            TestingForm NewTest = new TestingForm(setQuestion, rowId, selectedUser.ID);

            NewTest.ShowDialog();
        }
Пример #4
0
 public SelectedQuestion(GlobalClass.QuestionAnswersMapper OneQuestion)
 {
     InitializeComponent();
     this.SelectedQuest = OneQuestion;
     QuestT.Text        = SelectedQuest.Question;
     foreach (GlobalClass.AnswerMapper Answer in this.SelectedQuest.Answers)
     {
         this.checkedListBox1.Items.Add(Answer.Answer, Answer.isTrue);
     }
 }
Пример #5
0
        private void подробностиToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int rowId = (int)((long)TeacherGridView.Rows[this.mouseLocation.RowIndex].Cells["ID"].Value);

            GlobalClass.QuestionAnswersMapper OneQuestion = this.elementBase.SelectQuestionWithAnswers(rowId);
            SelectedQuestion SelQuest = new SelectedQuestion(OneQuestion);

            SelQuest.ShowDialog();
            generateTable(1);
            this.TeacherGridView.DataSource            = this.elementBase.SelectQuestions(this.idSubject);
            this.TeacherGridView.Columns["ID"].Visible = false;
        }
Пример #6
0
        private void SaveBtn_Click(object sender, EventArgs e)
        {
            List <GlobalClass.AnswerMapper> Answers = new List <GlobalClass.AnswerMapper>();


            foreach (rowAddAnswer oneAnswer in RowListanswer)
            {
                GlobalClass.AnswerMapper tempAnswer = new GlobalClass.AnswerMapper(0, oneAnswer.AnswerT.Text, oneAnswer.checkBx.Checked);
                Answers.Add(tempAnswer);
            }
            GlobalClass.QuestionAnswersMapper tempQ = new GlobalClass.QuestionAnswersMapper(0, (int)this.SubjectList.SelectedValue, this.QuestionT.Text, this.RowListanswer.Count, Answers);
            elementBase.InsertQuestionWithAnswers(tempQ);
            this.Close();
        }
Пример #7
0
        public void InsertQuestionWithAnswers(GlobalClass.QuestionAnswersMapper InsertingThing)
        {
            if (this.openConnection() == true)
            {
                MySqlCommand cmd = new MySqlCommand();
                cmd.Connection = dbConnect;
                string query = @"INSERT INTO `questions` (`ID_subject`,`Question`)
                                    VALUES (" + InsertingThing.ID_subject + ",'" + InsertingThing.Question + "')";
                cmd.CommandText = query;
                cmd.ExecuteNonQuery();
                long inserted_id_Question = -1;
                inserted_id_Question = cmd.LastInsertedId;
                if (inserted_id_Question > -1)
                {
                    foreach (GlobalClass.AnswerMapper tempAnswer in InsertingThing.Answers)
                    {
                        query           = @"INSERT INTO `answer` (`answer`,`true_variant`)
                                     VALUES ('" + tempAnswer.Answer + "'," + (tempAnswer.isTrue ? 1 : 0) + ")";
                        cmd.CommandText = query;
                        cmd.ExecuteNonQuery();
                        long inserted_id_Answer = -1;
                        inserted_id_Answer = cmd.LastInsertedId;
                        if (inserted_id_Answer > -1)
                        {
                            query           = @"INSERT INTO `qs_ar` (`ID_Q`,`ID_A`)
                                     VALUES ('" + inserted_id_Question + "'," + inserted_id_Answer + ")";
                            cmd.CommandText = query;
                            cmd.ExecuteNonQuery();
                        }
                    }
                }

                //close connection
                this.CloseConnection();
            }
        }
Пример #8
0
        public GlobalClass.QuestionAnswersMapper SelectQuestionWithAnswers(int id)
        {
            string questionQuery = @"select a.ID, a.ID_subject, a.Question from questions as a where a.ID = " + id;
            string answersQuery  = @"select  b.ID, b.answer, b.true_variant 
                                    from qs_ar as a 
                                    join answer as b ON b.ID = a.ID_A
                                    where a.ID_Q = " + id;

            List <GlobalClass.AnswerMapper> Answers = new List <GlobalClass.AnswerMapper>();

            GlobalClass.QuestionAnswersMapper tempQ = new GlobalClass.QuestionAnswersMapper();

            if (this.openConnection() == true)
            {
                MySqlCommand    cmd        = new MySqlCommand(answersQuery, dbConnect);
                MySqlDataReader dataReader = cmd.ExecuteReader();

                //Read the data and store them in the list
                while (dataReader.Read())
                {
                    int     I = (int)((long)dataReader["ID"]);
                    string  A = (string)dataReader["answer"];
                    int     F = (int)((sbyte)dataReader["true_variant"]);
                    Boolean Fl;
                    if (F == 1)
                    {
                        Fl = true;
                    }
                    else
                    {
                        Fl = false;
                    }
                    GlobalClass.AnswerMapper tempAnswer = new GlobalClass.AnswerMapper(I, A, Fl);
                    Answers.Add(tempAnswer);
                }

                //close Data Reader
                dataReader.Close();

                cmd        = new MySqlCommand(questionQuery, dbConnect);
                dataReader = cmd.ExecuteReader();

                //Read the data and store them in the list
                while (dataReader.Read())
                {
                    int    I  = (int)((long)dataReader["ID"]);
                    int    IS = (int)((long)dataReader["ID_subject"]);
                    string A  = (string)dataReader["Question"];
                    tempQ = new GlobalClass.QuestionAnswersMapper(I, IS, A, Answers.Count, Answers);
                }

                //close Data Reader
                dataReader.Close();
                //close Connection
                this.CloseConnection();

                //return list to be displayed
                return(tempQ);
            }
            else
            {
                return(tempQ);
            }
        }
Пример #9
0
        private void Next_Click(object sender, EventArgs e)
        {
            this.SetTest.Remove(this.CurrQuestion);

            List <GlobalClass.AnswerMapper> StudAnswers = new List <GlobalClass.AnswerMapper>();
            int i = 0;

            foreach (System.Windows.Forms.CheckBox chkBx in this.checkBoxes)
            {
                if (chkBx.Checked)
                {
                    StudAnswers.Add(this.CurrQuestion.Answers[i]);
                }
                this.tableLayoutPanel1.Controls.Remove(chkBx);
                i++;
            }
            GlobalClass.StudQuestionAnswersMapper StudAnswer = new GlobalClass.StudQuestionAnswersMapper(this.CurrQuestion.ID, this.CurrQuestion.ID_subject, this.CurrQuestion.Question, this.CurrQuestion.AnswerCount, this.CurrQuestion.Answers, StudAnswers);
            StudAns.Add(StudAnswer);

            if (this.SetTest.Count > 0)
            {
                this.CurrQuestion     = this.SetTest[0];
                this.QuestionBox.Text = this.CurrQuestion.Question;
                checkBoxes            = new List <CheckBox>();
                i = 0;
                foreach (GlobalClass.AnswerMapper sd in this.CurrQuestion.Answers)
                {
                    System.Windows.Forms.CheckBox AnswerCheckBox = new System.Windows.Forms.CheckBox();
                    AnswerCheckBox.AutoSize = true;
                    AnswerCheckBox.Name     = "AnswerCheckBox" + i;
                    AnswerCheckBox.Size     = new System.Drawing.Size(431, 167);
                    AnswerCheckBox.TabIndex = 0;
                    AnswerCheckBox.Text     = sd.Answer;
                    AnswerCheckBox.UseVisualStyleBackColor = true;
                    this.tableLayoutPanel1.Controls.Add(AnswerCheckBox, i % 2, (i - i % 2) / 2);
                    i++;
                    checkBoxes.Add(AnswerCheckBox);
                }
            }
            else
            {
                int right_answers = 0;
                foreach (GlobalClass.StudQuestionAnswersMapper SA in StudAns)
                {
                    int right_count = 0;
                    foreach (GlobalClass.AnswerMapper Ans in SA.Answers)
                    {
                        if (Ans.isTrue)
                        {
                            right_count++;
                        }
                    }

                    int stud_right_count = 0;

                    if (right_count == SA.StudAnswers.Count)
                    {
                        foreach (GlobalClass.AnswerMapper Ans in SA.StudAnswers)
                        {
                            if (Ans.isTrue)
                            {
                                stud_right_count++;
                            }
                        }
                        if (stud_right_count == right_count)
                        {
                            right_answers++;
                        }
                    }
                }
                elementBase.InsertUserResult(StudAns, userId, testId);
                string            message = "Вы ответили на " + right_answers + " из " + this.StudAns.Count + ";";
                string            caption = "Окончание теста";
                MessageBoxButtons buttons = MessageBoxButtons.OK;
                this.Hide();
                MessageBox.Show(message, caption, buttons);

                this.Close();
            }
        }