/// <summary>
        /// Thêm câu hỏi vào bộ câu hỏi
        /// </summary>
        /// <param name="question"></param>
        /// <returns>ID của câu hỏi trong bộ câu hỏi</returns>
        public int addQuestion(MyBaseQuestion question)
        {
            question.Id = questions.Count;
            questions.Add(question);

            return(question.Id);
        }
 public void updateQuestion(MyBaseQuestion question)
 {
     for (int i = 0; i < questions.Count; i++)
     {
         if (questions[i].Id == question.Id)
         {
             questions[i] = question;
         }
     }
 }
Exemple #3
0
        public void updateQuestionToForm(MyBaseQuestion question)
        {
            if (this.txQuestion.InvokeRequired)
            {
                SetQuestionCallback d = new SetQuestionCallback(updateQuestionToForm);
                this.Invoke(d, new object[] { question });
            }
            else
            {
                _answer = "";
                clearAllAnswerButton();
                txQuestion.Text = _currentQuestion.Question;
                lbTime.Text = _currentQuestion.Time.ToString();

                switch (_currentQuestion.type)
                {
                    case MyQuestionType.MyMissingFieldQuestion:
                        lbType.Text = "Điền khuyết";
                        gbFillMissingField.Visible = true;
                        gbOneChoice.Visible = false;
                        tbClientAnswer.Focus();
                        break;
                    case MyQuestionType.MyOneChoiceQuestion:
                        lbType.Text = "Câu trả lời DUY NHẤT";
                        gbFillMissingField.Visible = false;
                        gbOneChoice.Visible = true;
                        _multi_aswer = false;
                        break;
                    case MyQuestionType.MyMultiChoiceQuestion:
                        lbType.Text = "Nhiều lựa chọn";
                        gbFillMissingField.Visible = false;
                        gbOneChoice.Visible = true;
                        _multi_aswer = true;
                        break;
                }

                btChoiseA.Text = _currentQuestion.choiceA;
                btChoiseB.Text = _currentQuestion.choiceB;
                btChoiseC.Text = _currentQuestion.choiceC;
                btChoiseD.Text = _currentQuestion.choiceD;

                pbTime.Maximum = _currentQuestion.Time;
                pbTime.Minimum = 0;
                pbTime.Value = 0;

                tmProcessBar.Enabled = true;
                tmProcessBar.Start();
                tmProcessBar.Interval = 1000;
            }
        }
        public void loadQuestionToForm(MyBaseQuestion question)
        {
            tbQuestion.Text = question.Question;
            tbAnswer.Text = question.Answer;
            tbChoiceA.Text = question.choiceA;
            tbChoiceB.Text = question.choiceB;
            tbChoiceC.Text = question.choiceC;
            tbChoiceD.Text = question.choiceD;
            tbScore.Value = question.Score;
            tbTime.Value = question.Time;

            switch (question.type)
            {
                case MyQuestionType.MyMissingFieldQuestion:
                    rbMissingField.Checked = true;
                    break;
                case MyQuestionType.MyMultiChoiceQuestion:
                    rbMultiQuestion.Checked = true;
                    break;
                case MyQuestionType.MyOneChoiceQuestion:
                    rbOneChoice.Checked = true;
                    break;
                default:
                    MessageBox.Show("Không tìm thấy loại câu hỏi!");
                    break;
            }

            if (question.isUpcase)
            {
                rdExactlyChoise.Checked = true;
            }
            else
            {
                rbdNotExactlyChoice.Checked = true;
            }
        }
        public void convertFromJObjcet(JObject jobject)
        {
            this.address = jobject["Address"].ToString();
            this.name    = jobject["Name"].ToString();

            foreach (var item in jobject["questions"])
            {
                try
                {
                    MyBaseQuestion question = new MyBaseQuestion();
                    question.Answer    = item["Answer"].ToString();
                    question.choiceA   = item["choiceA"].ToString();
                    question.choiceB   = item["choiceB"].ToString();
                    question.choiceC   = item["choiceC"].ToString();
                    question.choiceD   = item["choiceD"].ToString();
                    question.ClassName = item["ClassName"].ToString();
                    question.Id        = int.Parse(item["Id"].ToString());
                    question.isUpcase  = bool.Parse(item["isUpcase"].ToString());
                    question.Prioriy   = int.Parse(item["Prioriy"].ToString());
                    question.Question  = item["Question"].ToString();


                    if (item["Time"] == null)
                    {
                        question.Time = 30;
                    }
                    else
                    {
                        question.Time = int.Parse(item["Time"].ToString());
                    }

                    if (item["Score"] == null)
                    {
                        question.Score = 1;
                    }
                    else
                    {
                        question.Score = int.Parse(item["Score"].ToString());
                    }


                    switch (int.Parse(item["type"].ToString()))
                    {
                    case 1:
                        question.type = MyQuestionType.MyOneChoiceQuestion;
                        break;

                    case 2:
                        question.type = MyQuestionType.MyMultiChoiceQuestion;
                        break;

                    case 3:
                        question.type = MyQuestionType.MyMissingFieldQuestion;
                        break;
                    }

                    questions.Add(question);
                }
                catch
                {
                    throw new Exception("Có lỗi khi mở câu hỏi! Bộ câu hỏi: " + this.Address);
                }
            }
        }
        /// <summary>
        /// Thêm câu hỏi vào bộ câu hỏi
        /// </summary>
        /// <param name="question"></param>
        /// <returns>ID của câu hỏi trong bộ câu hỏi</returns>
        public int addQuestion(MyBaseQuestion question)
        {
            question.Id = questions.Count;
            questions.Add(question);

            return question.Id;
        }
 public void updateQuestion(MyBaseQuestion question)
 {
     for (int i = 0; i < questions.Count; i++)
     {
         if (questions[i].Id == question.Id)
         {
             questions[i] = question;
         }
     }
 }
        public void convertFromJObjcet(JObject jobject)
        {
            this.address = jobject["Address"].ToString();
            this.name = jobject["Name"].ToString();

            foreach (var item in jobject["questions"])
            {
                try
                {

                    MyBaseQuestion question = new MyBaseQuestion();
                    question.Answer = item["Answer"].ToString();
                    question.choiceA = item["choiceA"].ToString();
                    question.choiceB = item["choiceB"].ToString();
                    question.choiceC = item["choiceC"].ToString();
                    question.choiceD = item["choiceD"].ToString();
                    question.ClassName = item["ClassName"].ToString();
                    question.Id = int.Parse(item["Id"].ToString());
                    question.isUpcase = bool.Parse(item["isUpcase"].ToString());
                    question.Prioriy = int.Parse(item["Prioriy"].ToString());
                    question.Question = item["Question"].ToString();

                    if (item["Time"] == null)
                    {
                        question.Time = 30;
                    }
                    else
                    {
                        question.Time = int.Parse(item["Time"].ToString());
                    }

                    if (item["Score"] == null)
                    {
                        question.Score = 1;
                    }
                    else
                    {
                        question.Score = int.Parse(item["Score"].ToString());
                    }

                    switch (int.Parse(item["type"].ToString()))
                    {
                        case 1:
                            question.type = MyQuestionType.MyOneChoiceQuestion;
                            break;
                        case 2:
                            question.type = MyQuestionType.MyMultiChoiceQuestion;
                            break;
                        case 3:
                            question.type = MyQuestionType.MyMissingFieldQuestion;
                            break;
                    }

                    questions.Add(question);
                }
                catch
                {
                    throw new Exception("Có lỗi khi mở câu hỏi! Bộ câu hỏi: " + this.Address);
                }
            }
        }
        public MyTr_Sv_Question(JObject question)
        {
            _question = new MyBaseQuestion();
            _myTransactioncode = Transaction_Code.sv_question;
            _question.Answer = question["Question"]["Answer"].ToString();
            _question.choiceA = question["Question"]["choiceA"].ToString();
            _question.choiceB = question["Question"]["choiceB"].ToString();
            _question.choiceC = question["Question"]["choiceC"].ToString();
            _question.choiceD = question["Question"]["choiceD"].ToString();
            _question.Question = question["Question"]["Question"].ToString();
            _question.Time = int.Parse(question["Question"]["Time"].ToString());
            _question.Score = int.Parse(question["Question"]["Score"].ToString());

            int type = int.Parse(question["Question"]["type"].ToString());

            switch (type)
            {
                case 1:
                    _question.type = MyQuestionType.MyOneChoiceQuestion;
                    break;
                case 2:
                    _question.type = MyQuestionType.MyMultiChoiceQuestion;
                    break;
                case 3:
                    _question.type = MyQuestionType.MyMissingFieldQuestion;
                    break;
            }
        }
Exemple #10
0
        private void tmProcessBar_Tick(object sender, EventArgs e)
        {
            if (_currentQuestion != null)
            {
                lbCurrentTime.Text = pbTime.Value.ToString();
                pbTime.Increment(1);

                if (_currentQuestion.Time == pbTime.Value)
                {
                    _currentQuestion = null;
                }
            }
        }
Exemple #11
0
        private void processRequest(string dataFromClient)
        {
            JObject jObject = JObject.Parse(dataFromClient);

            MyTransactionFactory factory = MyTransactionFactory.getInstance();
            MyBaseTransaction transaction = factory.createTransaction(jObject);

            switch (transaction.MyTransactioncode)
            {
                case Transaction_Code.sv_disconnect:
                    // Nếu server đóng thì client cũng sẽ close session
                    MessageBox.Show("You has beend disconnect from server!");
                    stop();
                    break;
                case Transaction_Code.sv_question:
                    MyTr_Sv_Question transQuestion = factory.recreateMyTr_Sv_Question(jObject);
                    _currentQuestion = transQuestion.Question;
                    updateQuestionToForm(_currentQuestion);
                    break;
                case Transaction_Code.sv_end_questions:
                    MessageBox.Show("Bài kiểm tra đã kết thúc!");
                    clearAllAnswerButton();
                    break;
            }
        }
        private void addQuestionToLvQuestion(MyBaseQuestion question)
        {
            // Update ListView Question
            int idquestion = question.Id;

            ListViewItem item = new ListViewItem();
            item.Text = idquestion.ToString();

            if (question.Question.Length > 20)
            {
                item.SubItems.Add(question.Question.Substring(0, 20));
            }
            else
            {
                item.SubItems.Add(question.Question);
            }

            lvListQuestion.Items.Add(item);
        }
        private void addNewQuestion()
        {
            MyBaseQuestion question = new MyBaseQuestion();

            question.Question = tbQuestion.Text;
            question.Time = (int)tbTime.Value;
            question.choiceA = tbChoiceA.Text;
            question.choiceB = tbChoiceB.Text;
            question.choiceC = tbChoiceC.Text;
            question.choiceD = tbChoiceD.Text;
            question.Score = (int)tbScore.Value;
            // nếu câu hỏi là câu hỏi điền khuyết

            question.Answer = tbAnswer.Text;

            if (rbdNotExactlyChoice.Checked)
            {
                question.isUpcase = true;
            }
            else
            {
                question.isUpcase = false;
            }

            if (rbOneChoice.Checked)
            {
                question.type = MyQuestionType.MyOneChoiceQuestion;
            }
            if (rbMultiQuestion.Checked)
            {
                question.type = MyQuestionType.MyMultiChoiceQuestion;
            }
            if (rbMissingField.Checked)
            {
                question.type = MyQuestionType.MyMissingFieldQuestion;
            }

            _groupquestion.addQuestion(question);
            addQuestionToLvQuestion(question);
        }
Exemple #14
0
        private void updateCurrentQuestionToForm(MyBaseQuestion question)
        {
            txQuestion.Text = question.Question;
            lbAnswer.Text = question.Answer;
            lbTime.Text = question.Time.ToString();

            switch (question.type)
            {
                case MyQuestionType.MyMissingFieldQuestion:
                    lbType.Text = "Điền khuyết";
                    break;
                case MyQuestionType.MyOneChoiceQuestion:
                    lbType.Text = "Câu trả lời DUY NHẤT";
                    break;
                case MyQuestionType.MyMultiChoiceQuestion:
                    lbType.Text = "Nhiều lựa chọn";
                    break;
            }

            btChoiseA.Text = question.choiceA;
            btChoiseB.Text = question.choiceB;
            btChoiseC.Text = question.choiceC;
            btChoiseD.Text = question.choiceD;

            pbTime.Maximum = question.Time;
            pbTime.Minimum = 0;
            pbTime.Value = 0;

            tmProcessBar.Enabled = true;
            tmProcessBar.Start();
            tmProcessBar.Interval = 1000;
        }
Exemple #15
0
 private void sendQuestionToClient(MyBaseQuestion _currentQuestion)
 {
     MyTr_Sv_Question tras = new MyTr_Sv_Question();
     tras.Question = _currentQuestion;
     _myClientManage.sendToAll(tras);
 }
Exemple #16
0
        private void openNextQuestion()
        {
            _currentQuestion = _groupquestion.getNextQuestion();

            if (_currentQuestion == null)
            {
                MessageBox.Show("Đã hết bộ câu hỏi");
                //cleanGroupQuestion();
                _myClientManage.sendToAll(Transaction_Code.sv_end_questions);

                return;
            }
            lbNumberQuestion.Text = (_groupquestion.CurrentIndexQuestion + 1).ToString();
            updateCurrentQuestionToForm(_currentQuestion);
            sendQuestionToClient(_currentQuestion);
            clearListViewUserAnswer();
        }