Esempio n. 1
0
        public ArrayList GetQuestion_random(int length, int index)
        {
            ArrayList Question = new ArrayList();
            int       count    = (int)collection.Find(filter: new BsonDocument()).Count();
            Random    ran      = new Random();
            int       skipnum  = ran.Next(0, count - length);
            var       cursor   = collection.Find(new BsonDocument()).Skip(skipnum).Limit(length).ToCursor();
            int       i        = index;

            foreach (var document in cursor.ToEnumerable())
            {
                document["_id"] = document["_id"].ToString();
                Exam_Question exam_Question = new Exam_Question
                {
                    Index        = i.ToString() + "、 ",
                    Id           = document["id"].ToString(),
                    Target       = document["target"].ToString(),
                    Question     = document["question"].ToString(),
                    Type         = document["Type"].ToString(),
                    Imageurl     = document["imageurl"].ToString(),
                    Sinaimg      = document["sinaimg"].ToString(),
                    Bestanswer   = document["bestanswer"].ToString(),
                    Bestanswerid = document["bestanswerid"].ToString(),
                    A            = document["options"]["a"].ToString(),
                    B            = document["options"]["b"].ToString(),
                    C            = document["options"]["c"].ToString(),
                    D            = document["options"]["d"].ToString()
                };
                i++;
                Question.Add(exam_Question);
            }
            return(Question);
        }
Esempio n. 2
0
        public static Hashtable Get_Score(DataList dataList, ArrayList question, string type)
        {
            Hashtable hashtable        = new Hashtable();
            ArrayList question_choosed = new ArrayList();
            int       score            = 0;

            if (type == "questions_more")
            {
                for (int i = 0; i < dataList.Items.Count; i++)
                {
#pragma warning disable CS0436 // 类型与导入类型冲突
                    Exam_Question exam = (Exam_Question)question[i];
#pragma warning restore CS0436 // 类型与导入类型冲突
                    string       checkboxchoosed = null;
                    CheckBoxList checkBoxList    = (CheckBoxList)dataList.Items[i].FindControl("check_options");
                    // 获取选择项
                    for (int j = 0; j < checkBoxList.Items.Count; j++)
                    {
                        if (checkBoxList.Items[j].Selected)
                        {
                            checkboxchoosed = checkboxchoosed + (j + 1).ToString();
                        }
                    }
                    question_choosed.Add(checkboxchoosed);

                    // 比对答案
                    if (checkboxchoosed == exam.Target)
                    {
                        score++;
                    }
                }
            }
            else
            {
                for (int i = 0; i < dataList.Items.Count; i++)
                {
#pragma warning disable CS0436 // 类型与导入类型冲突
                    Exam_Question exam = (Exam_Question)question[i];
#pragma warning restore CS0436 // 类型与导入类型冲突
                    RadioButtonList radio = (RadioButtonList)dataList.Items[i].FindControl("radio_options");
                    // 获取选择项
                    for (int j = 0; j < radio.Items.Count; j++)
                    {
                        if (radio.Items[j].Selected)
                        {
                            question_choosed.Add(j);
                            // 比对答案
                            if ((j + 1).ToString() == exam.Target)
                            {
                                score++;
                            }
                            break;
                        }
                    }
                }
            }
            hashtable.Add(type + "_score", score);
            hashtable.Add(type + "_chosed", question_choosed);
            return(hashtable);
        }
Esempio n. 3
0
        public static void Loading_Question(DataList dataList, ArrayList question, string type)
        {
            if (type == "questions_one")
            {
                for (int i = 0; i < dataList.Items.Count; i++)
                {
#pragma warning disable CS0436 // 类型与导入类型冲突
                    Exam_Question exam = (Exam_Question)question[i];
#pragma warning restore CS0436 // 类型与导入类型冲突
                    RadioButtonList radio = (RadioButtonList)dataList.Items[i].FindControl("radio_options");
                    if (exam.A != "")
                    {
                        radio.Items.Add(exam.A);
                    }
                    if (exam.B != "")
                    {
                        radio.Items.Add(exam.B);
                    }
                    if (exam.C != "")
                    {
                        radio.Items.Add(exam.C);
                    }
                    if (exam.D != "")
                    {
                        radio.Items.Add(exam.D);
                    }
                }
            }
            else if (type == "questions_more")
            {
                for (int i = 0; i < dataList.Items.Count; i++)
                {
#pragma warning disable CS0436 // 类型与导入类型冲突
                    Exam_Question exam = (Exam_Question)question[i];
#pragma warning restore CS0436 // 类型与导入类型冲突
                    CheckBoxList check = (CheckBoxList)dataList.Items[i].FindControl("check_options");
                    if (exam.A != "")
                    {
                        check.Items.Add(exam.A);
                    }
                    if (exam.B != "")
                    {
                        check.Items.Add(exam.B);
                    }
                    if (exam.C != "")
                    {
                        check.Items.Add(exam.C);
                    }
                    if (exam.D != "")
                    {
                        check.Items.Add(exam.D);
                    }
                }
            }
        }
Esempio n. 4
0
        public static ArrayList GetQuestionsOrChoosed(BsonDocument document, string type)
        {
            ArrayList arrayList = new ArrayList();
            var       questions = document[type];
            BsonArray array     = (BsonArray)document[type][0];

            if (type == "question_one" || type == "question_more" || type == "question_judge")
            {
                foreach (var item in array)
                {
                    Exam_Question exam = new Exam_Question
                    {
                        Target       = item["target"].ToString(),
                        Id           = item["id"].ToString(),
                        Question     = item["question"].ToString(),
                        Sinaimg      = item["sinaimg"].ToString(),
                        Imageurl     = item["imageurl"].ToString(),
                        Bestanswer   = item["bestanswer"].ToString(),
                        Bestanswerid = item["bestanswerid"].ToString(),
                        A            = item["options"]["a"].ToString(),
                        B            = item["options"]["b"].ToString(),
                        C            = item["options"]["c"].ToString(),
                        D            = item["options"]["d"].ToString(),
                        Index        = item["Index"].ToString(),
                        Type         = item["Type"].ToString(),
                    };
                    arrayList.Add(exam);
                }
            }
            else if (type == "questions_more_chosed")
            {
                foreach (var item in array)
                {
                    string choosed = item.ToString();
                    arrayList.Add(choosed);
                }
            }
            else
            {
                foreach (var item in array)
                {
                    int choosed = item.AsInt32;
                    arrayList.Add(choosed);
                }
            }
            return(arrayList);
        }
Esempio n. 5
0
        public static void Loading_Result(DataList dataList, ArrayList question, string type, ArrayList choosed)
        {
            if (type == "questions_more")
            {
                for (int i = 0; i < dataList.Items.Count; i++)
                {
#pragma warning disable CS0436                                            // 类型与导入类型冲突
                    Exam_Question exam = (Exam_Question)question[i];
#pragma warning restore CS0436                                            // 类型与导入类型冲突
                    string       checkboxchoosed = choosed[i].ToString(); // 用户选择的项
                    CheckBoxList checkBoxList    = (CheckBoxList)dataList.Items[i].FindControl("check_options");
                    for (int j = 0; j < checkboxchoosed.Length; j++)
                    {
                        int num = Int32.Parse(checkboxchoosed[j].ToString()) - 1;
                        checkBoxList.Items[num].Selected = true;
                    }
                    if (checkboxchoosed == exam.Target)
                    {
                        Panel Panel_result_image = (Panel)dataList.Items[i].FindControl("Panel_result_image");
                        Image image = new Image
                        {
                            CssClass = "image_result",
                            ImageUrl = "~/Images/选中.png"
                        };
                        Panel_result_image.Controls.Add(image);
                    }
                    else
                    {
                        Panel Panel_Answer       = (Panel)dataList.Items[i].FindControl("Panel_Answer");
                        Panel Panel_result_image = (Panel)dataList.Items[i].FindControl("Panel_result_image");
                        Image image = new Image
                        {
                            CssClass = "image_result",
                            ImageUrl = "~/Images/关闭.png"
                        };
                        Panel_result_image.Controls.Add(image);
                        Label bestanswer = new Label
                        {
                            Text = "本题解析:</br>" + exam.Bestanswer,
                        };
                        Panel_Answer.Controls.Add(bestanswer);
                    }
                    checkBoxList.Enabled = false;
                }
            }
            else
            {
                for (int i = 0; i < dataList.Items.Count; i++)
                {
#pragma warning disable CS0436 // 类型与导入类型冲突
                    Exam_Question exam = (Exam_Question)question[i];
#pragma warning restore CS0436 // 类型与导入类型冲突
                    int             target = Convert.ToInt32(choosed[i]) + 1;
                    RadioButtonList radio  = (RadioButtonList)dataList.Items[i].FindControl("radio_options");
                    radio.Items[target - 1].Selected = true;
                    if (target.ToString() == exam.Target)
                    {
                        Panel Panel_result_image = (Panel)dataList.Items[i].FindControl("Panel_result_image");
                        Image image = new Image
                        {
                            CssClass = "image_result",
                            ImageUrl = "~/Images/选中.png"
                        };
                        Panel_result_image.Controls.Add(image);
                    }
                    else
                    {
                        Panel Panel_Answer       = (Panel)dataList.Items[i].FindControl("Panel_Answer");
                        Panel Panel_result_image = (Panel)dataList.Items[i].FindControl("Panel_result_image");
                        Image image = new Image
                        {
                            CssClass = "image_result",
                            ImageUrl = "~/Images/关闭.png"
                        };
                        Panel_result_image.Controls.Add(image);
                        Label bestanswer = new Label
                        {
                            Text = "本题解析:</br>" + exam.Bestanswer,
                        };
                        Panel_Answer.Controls.Add(bestanswer);
                    }
                    radio.Enabled = false;
                }
            }
        }