예제 #1
0
        private void saveButton_Click_1(object sender, EventArgs e)
        {
            int    count         = mainQuestionPanelList.Count;
            JArray jProblemArray = new JArray();
            JArray jAnswerArray  = new JArray();
            int    num           = 0;

            for (int i = 0; i < count; i++)
            {
                List <SubQuestionPanel> subQuestionPanelList = mainQuestionPanelList[i].SubQuestionPanelsList;
                int     cnt         = subQuestionPanelList.Count;
                JObject mainJObject = new JObject();
                JArray  subArray    = new JArray();
                if (mainQuestionPanelList[i].MainQuestionLabel.Text == "")
                {
                    MessageBox.Show((i + 1).ToString() + "번 페이지의 문제 유형을 적어주세요.", "출제 오류", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    examPageNavigationPanel.NowPageTextBox.Text = (i + 1).ToString();
                    return;
                }
                mainJObject.Add("question", mainQuestionPanelList[i].MainQuestionLabel.Text);
                for (int j = 0; j < cnt; j++)
                {
                    int     type    = subQuestionPanelList[j].Type;
                    JObject jObject = new JObject();
                    jObject.Add("type", type);
                    jObject.Add("num", num + 1);
                    jObject.Add("score", int.Parse(subQuestionPanelList[j].ExamScorePanel.ScoreTextBox.Text));
                    JObject answerJObject = new JObject();
                    answerJObject.Add("num", num + 1);
                    answerJObject.Add("score", int.Parse(subQuestionPanelList[j].ExamScorePanel.ScoreTextBox.Text));

                    if (subQuestionPanelList[j].QuestionLabel.Text == "")
                    {
                        MessageBox.Show("문제를 작성해주세요. (" + (num + 1).ToString() + "번 문제)", "출제 오류", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        shortCutButtonList[num].PerformClick();
                        return;
                    }

                    jObject.Add("question", subQuestionPanelList[j].QuestionLabel.Text);
                    if (type == 0)
                    {
                        OXPanel oxPanel = (OXPanel)subQuestionPanelList[j];
                        answerJObject.Add("answer", oxPanel.Answer);
                        answerJObject.Add("type", "Choice");
                    }
                    else if (type == 1)
                    {
                        ShortAnswerQuestionPanel shortAnswerQuestionPanel = (ShortAnswerQuestionPanel)subQuestionPanelList[j];
                        answerJObject.Add("answer", shortAnswerQuestionPanel.AnswerPanel.AnswerLabel.Text);
                        answerJObject.Add("type", "Text");
                    }
                    else if (type == 2)
                    {
                        EssayQuestionPanel essayQuestionPanel = (EssayQuestionPanel)subQuestionPanelList[j];
                        answerJObject.Add("answer", essayQuestionPanel.AnswerPanel.AnswerLabel.Text);
                        answerJObject.Add("type", "Essay");
                        jObject.Add("maxLength", int.Parse(essayQuestionPanel.AnswerPanel.MaxLengthTextBox.Text));
                    }
                    else
                    {
                        MultipleChoiceQuestionPanel multipleChoiceQuestionPanel = (MultipleChoiceQuestionPanel)subQuestionPanelList[j];
                        List <MultipleChoicePanel>  multipleChoicePanelList     = multipleChoiceQuestionPanel.ChoicePaneList;
                        int len = multipleChoicePanelList.Count;
                        if (len == 0)
                        {
                            MessageBox.Show("객관식 문제는 보기가 반드시 필요합니다. (" + (num + 1).ToString() + "번 문제)", "출제 오류", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            shortCutButtonList[num].PerformClick();
                            return;
                        }
                        else if (multipleChoiceQuestionPanel.Answer == -1)
                        {
                            MessageBox.Show("객관식 문제의 정답은 반드시 필요합니다. (" + (num + 1).ToString() + "번 문제)", "출제 오류", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            shortCutButtonList[num].PerformClick();
                            return;
                        }
                        JArray examples = new JArray();
                        for (int t = 0; t < len; t++)
                        {
                            JObject example = new JObject();
                            example.Add("example", multipleChoicePanelList[t].ExampleLabel.Text);
                            examples.Add(example);
                        }
                        jObject.Add("examples", examples);
                        answerJObject.Add("answer", multipleChoiceQuestionPanel.Answer);
                        answerJObject.Add("type", "Choice");
                    }
                    subArray.Add(jObject);
                    jAnswerArray.Add(answerJObject);
                    num++;
                }
                mainJObject.Add("subQuestions", subArray);
                if (cnt > 0)
                {
                    jProblemArray.Add(mainJObject);
                }
            }
            if (num == 0)
            {
                MessageBox.Show("하나 이상의 문제를 출제하셔야 합니다.", "출제 오류", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            //Console.WriteLine(jProblemArray);
            //Console.WriteLine(jAnswerArray);
            makeExam(jProblemArray, jAnswerArray);
        }
예제 #2
0
        private void setSavedQuestions(JArray questions, JArray answers)
        {
            int index = 0;
            int cnt   = questions.Count;

            for (int i = 0; i < cnt; i++)
            {
                string mainQuestion = (string)questions[i]["question"];
                this.examPageNavigationPanel.AddPageButton.PerformClick();
                mainQuestionPanelList[i].MainQuestionLabel.Text      = mainQuestion;
                mainQuestionPanelList[i].MainQuestionTextBox.Text    = mainQuestion;
                mainQuestionPanelList[i].MainQuestionLabel.Visible   = true;
                mainQuestionPanelList[i].MainQuestionTextBox.Visible = false;
                JArray subQuestions = (JArray)questions[i]["subQuestions"];
                int    subCnt       = (int)subQuestions.Count;
                for (int j = 0; j < subCnt; j++)
                {
                    int    type        = (int)subQuestions[j]["type"];
                    int    score       = (int)answers[index]["score"];
                    string answer      = (string)answers[index]["answer"];
                    string subQuestion = (string)subQuestions[j]["question"];
                    mainQuestionPanelList[i].QuestionKind.QuestionKindComboBox.SelectedIndex = type;
                    mainQuestionPanelList[i].AddQuestionButton.PerformClick();
                    SubQuestionPanel subQuestionPanel = mainQuestionPanelList[i].SubQuestionPanelsList[j];
                    subQuestionPanel.QuestionLabel.Text               = subQuestion;
                    subQuestionPanel.QuestionTextBox.Text             = subQuestion;
                    subQuestionPanel.QuestionLabel.Visible            = true;
                    subQuestionPanel.QuestionTextBox.Visible          = false;
                    subQuestionPanel.ExamScorePanel.ScoreTextBox.Text = score.ToString();
                    if (type == 0)
                    {
                        OXPanel oxPanel = (OXPanel)subQuestionPanel;
                        if (answer == "1")
                        {
                            oxPanel.OButton.PerformClick();
                        }
                        else
                        {
                            oxPanel.XButton.PerformClick();
                        }
                        oxPanel.setLayout();
                    }
                    else if (type == 1)
                    {
                        ShortAnswerQuestionPanel shortAnswerQuestionPanel = (ShortAnswerQuestionPanel)subQuestionPanel;
                        shortAnswerQuestionPanel.AnswerPanel.AnswerLabel.Text   = answer;
                        shortAnswerQuestionPanel.AnswerPanel.AnswerTextBox.Text = answer;
                        if (!answer.Equals(""))
                        {
                            shortAnswerQuestionPanel.AnswerPanel.AnswerLabel.Visible   = true;
                            shortAnswerQuestionPanel.AnswerPanel.AnswerTextBox.Visible = false;
                        }
                        shortAnswerQuestionPanel.setLayout();
                    }
                    else if (type == 2)
                    {
                        EssayQuestionPanel essayQuestionPanel = (EssayQuestionPanel)subQuestionPanel;
                        int maxLength = (int)subQuestions[j]["maxLength"];
                        essayQuestionPanel.AnswerPanel.AnswerTextBox.MaxLength = maxLength;
                        essayQuestionPanel.AnswerPanel.MaxLengthTextBox.Text   = maxLength.ToString();
                        essayQuestionPanel.AnswerPanel.AnswerLabel.Text        = answer;
                        essayQuestionPanel.AnswerPanel.AnswerTextBox.Text      = answer;
                        if (!answer.Equals(""))
                        {
                            essayQuestionPanel.AnswerPanel.AnswerLabel.Visible   = true;
                            essayQuestionPanel.AnswerPanel.AnswerTextBox.Visible = false;
                        }
                        essayQuestionPanel.setLayout();
                    }
                    else
                    {
                        MultipleChoiceQuestionPanel multipleChoiceQuestionPanel = (MultipleChoiceQuestionPanel)subQuestionPanel;
                        JArray examples = (JArray)subQuestions[j]["examples"];
                        int    len      = examples.Count;

                        for (int t = 0; t < len; t++)
                        {
                            string example = (string)examples[t]["example"];
                            multipleChoiceQuestionPanel.AddButton.PerformClick();
                            multipleChoiceQuestionPanel.ChoicePaneList[t].ExampleLabel.Text      = example;
                            multipleChoiceQuestionPanel.ChoicePaneList[t].ExampleTextBox.Text    = example;
                            multipleChoiceQuestionPanel.ChoicePaneList[t].ExampleLabel.Visible   = true;
                            multipleChoiceQuestionPanel.ChoicePaneList[t].ExampleTextBox.Visible = false;
                        }
                        multipleChoiceQuestionPanel.ChoicePaneList[int.Parse(answer)].ExampleRadioButton.PerformClick();
                        multipleChoiceQuestionPanel.setLayout();
                    }
                    index++;
                }
            }
        }