Пример #1
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         BindSubject();
         BindChapter();
         if (Request.QueryString["id"] != null)
         {
             int id = Convert.ToInt32(Request.QueryString["id"]);
             answer = answerBLL.GetModel(id);
             txtQues.Text = answer.ques;
             ddlDiff.ClearSelection();
             ddlDiff.Items.FindByValue(answer.diff.ToString()).Selected = true;
             txtAns.Text = answer.ans;
             ddlSubject.Items.FindByValue(MyUtil.GetSubjectIDbyChapterID(answer.chapterid).ToString()).Selected = true;
         }
     }
 }
Пример #2
0
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List <Model.tbAnswer> DataTableToList(DataTable dt)
        {
            List <Model.tbAnswer> modelList = new List <Model.tbAnswer>();
            int rowsCount = dt.Rows.Count;

            if (rowsCount > 0)
            {
                Model.tbAnswer model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new Model.tbAnswer();
                    if (dt.Rows[n]["id"].ToString() != "")
                    {
                        model.id = int.Parse(dt.Rows[n]["id"].ToString());
                    }
                    if (dt.Rows[n]["chapterid"].ToString() != "")
                    {
                        model.chapterid = int.Parse(dt.Rows[n]["chapterid"].ToString());
                    }
                    model.ques = dt.Rows[n]["ques"].ToString();
                    model.ans  = dt.Rows[n]["ans"].ToString();
                    if (dt.Rows[n]["diff"].ToString() != "")
                    {
                        model.diff = int.Parse(dt.Rows[n]["diff"].ToString());
                    }
                    if (dt.Rows[n]["selectcount"].ToString() != "")
                    {
                        model.selectcount = int.Parse(dt.Rows[n]["selectcount"].ToString());
                    }
                    if (dt.Rows[n]["rightcount"].ToString() != "")
                    {
                        model.rightcount = int.Parse(dt.Rows[n]["rightcount"].ToString());
                    }
                    if (dt.Rows[n]["questype"].ToString() != "")
                    {
                        model.questype = int.Parse(dt.Rows[n]["questype"].ToString());
                    }


                    modelList.Add(model);
                }
            }
            return(modelList);
        }
Пример #3
0
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public bool Update(Model.tbAnswer model)
 {
     return(dal.Update(model));
 }
Пример #4
0
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public int  Add(Model.tbAnswer model)
 {
     return(dal.Add(model));
 }
Пример #5
0
        /// <summary>
        /// 导入到数据库
        /// </summary>
        /// <param name="dt"></param>
        /// <returns>返回插入不成功的学号</returns>
        public static List<String> ExportToDB(DataTable dt)
        {
            List<String> list = new List<string>();
            tbAnswerDAL answerDAL = new tbAnswerDAL();

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                tbAnswer answer = new tbAnswer();
                int chapterid = GetChapterID(dt.Rows[i][0].ToString(), dt.Rows[i][1].ToString());
                if (chapterid != 0)
                {
                    answer.chapterid = chapterid;
                }
                else
                {
                    list.Add("行" + (i + 2) + "的科目或章节不存在!");
                    continue;
                }
                answer.ques = dt.Rows[i][2].ToString().Trim();                

                String diff = dt.Rows[i][3].ToString();
                if (diff != "容易" && diff != "较易" && diff != "一般" && diff != "较难" && diff != "困难")
                {
                    list.Add("行" + (i + 2) + "的难度设置不正确!");
                    continue;
                }
                if (diff == "容易")
                {
                    answer.diff = 1;
                }
                if (diff == "较易")
                {
                    answer.diff = 2;
                }
                if (diff == "一般")
                {
                    answer.diff = 3;
                }
                if (diff == "较难")
                {
                    answer.diff = 4;
                }
                if (diff == "困难")
                {
                    answer.diff = 5;
                }

                String ans = dt.Rows[i][4].ToString();
                if (ans=="")
                {
                    list.Add("行" + (i + 2) + "的答案不正确!");
                    continue;
                }
                answer.ans = ans;
                answer.questype = 1;//随机类型
                //判断题目是否存在
                if (DbHelperSQL.Exists("select * from tbAnswer where ques=@ques", new SqlParameter("@ques", answer.ques)))
                {
                    list.Add("行" + (i + 2) + "的题目已经存在!");
                    continue;
                }
                answerDAL.Add(answer);
            }
            return list;
        }
Пример #6
0
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<Model.tbAnswer> DataTableToList(DataTable dt)
		{
			List<Model.tbAnswer> modelList = new List<Model.tbAnswer>();
			int rowsCount = dt.Rows.Count;
			if (rowsCount > 0)
			{
				Model.tbAnswer model;
				for (int n = 0; n < rowsCount; n++)
				{
					model = new Model.tbAnswer();					
													if(dt.Rows[n]["id"].ToString()!="")
				{
					model.id=int.Parse(dt.Rows[n]["id"].ToString());
				}
																																if(dt.Rows[n]["chapterid"].ToString()!="")
				{
					model.chapterid=int.Parse(dt.Rows[n]["chapterid"].ToString());
				}
																																				model.ques= dt.Rows[n]["ques"].ToString();
																																model.ans= dt.Rows[n]["ans"].ToString();
																												if(dt.Rows[n]["diff"].ToString()!="")
				{
					model.diff=int.Parse(dt.Rows[n]["diff"].ToString());
				}
																																if(dt.Rows[n]["selectcount"].ToString()!="")
				{
					model.selectcount=int.Parse(dt.Rows[n]["selectcount"].ToString());
				}
																																if(dt.Rows[n]["rightcount"].ToString()!="")
				{
					model.rightcount=int.Parse(dt.Rows[n]["rightcount"].ToString());
				}
																																if(dt.Rows[n]["questype"].ToString()!="")
				{
					model.questype=int.Parse(dt.Rows[n]["questype"].ToString());
				}
																										
				
					modelList.Add(model);
				}
			}
			return modelList;
		}
Пример #7
0
        /// <summary>
        /// 导入到数据库
        /// </summary>
        /// <param name="dt"></param>
        /// <returns>返回插入不成功的学号</returns>
        public static List<String> ExportToDB(DataTable dt)
        {
            List<String> list = new List<string>();

            tbPaper paper = new tbPaper();
            tbSingle single = new tbSingle();
            tbCheck check = new tbCheck();
            tbJudge judge = new tbJudge();
            tbBlank blank = new tbBlank();
            tbAnswer answer = new tbAnswer();

            tbPaperDAL paperDAL = new tbPaperDAL();
            tbSingleDAL singleDAL = new tbSingleDAL();
            tbCheckDAL checkDAL = new tbCheckDAL();
            tbJudgeDAL judgeDAL = new tbJudgeDAL();
            tbBlankDAL blankDAL = new tbBlankDAL();
            tbAnswerDAL answerDAL = new tbAnswerDAL();
            //取得数据库连接
            SqlConnection conn = SQLHelper.GetConnection();
            //打开数据库连接
            conn.Open();
            //创建事务
            SqlTransaction SqlTransaction = conn.BeginTransaction();

            try
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    String flag = dt.Rows[i][0].ToString();
                    String temp = dt.Rows[i][1].ToString();
                    switch (flag)
                    {
                        case "#科目#":
                            //获取科目id
                            try
                            {
                                int subjectid = (int)DbHelperSQL.GetSingle("select id from tbSubject where subjectname=@subjectname and id in" + MyUtil.GetMySubjectString(), new SqlParameter("@subjectname", dt.Rows[i][1].ToString()));
                                paper.subjectid = subjectid;
                            }
                            catch (Exception)
                            {
                                list.Add("科目不存在或者没有权限!");
                                continue;
                            }
                            break;
                        case "#标题#":
                            paper.papertitle = dt.Rows[i][1].ToString();
                            if (String.IsNullOrEmpty(paper.papertitle))
                            {
                                list.Add("标题设置不正确!");
                                continue;
                            }
                            break;
                        case "#时间#":
                            try
                            {
                                paper.durationtime = Convert.ToInt32(dt.Rows[i][1].ToString().TrimEnd('分'));
                            }
                            catch (Exception)
                            {
                                list.Add("时间格式不正确!");
                                continue;
                            }
                            break;
                        case "#单选分值#":
                            try
                            {
                                paper.sr_scoreofeach = Convert.ToInt32(dt.Rows[i][1].ToString().TrimEnd('分'));
                            }
                            catch (Exception)
                            {
                                list.Add("单选分值格式不正确!");
                                continue;
                            }
                            break;
                        case "#多选分值#":
                            try
                            {
                                paper.cb_scoreofeach = Convert.ToInt32(dt.Rows[i][1].ToString().TrimEnd('分'));
                            }
                            catch (Exception)
                            {
                                list.Add("多选分值格式不正确!");
                                continue;
                            }
                            break;
                        case "#判断分值#":
                            try
                            {
                                paper.jd_scoreofeach = Convert.ToInt32(dt.Rows[i][1].ToString().TrimEnd('分'));
                            }
                            catch (Exception)
                            {
                                list.Add("判断分值格式不正确!");
                                continue;
                            }
                            break;
                        case "#填空分值#":
                            try
                            {
                                paper.bf_scoreofeach = Convert.ToInt32(dt.Rows[i][1].ToString().TrimEnd('分'));
                            }
                            catch (Exception)
                            {
                                list.Add("填空分值格式不正确!");
                                continue;
                            }
                            break;
                        case "#简答分值#":
                            try
                            {
                                paper.sa_scoreofeach = Convert.ToInt32(dt.Rows[i][1].ToString().TrimEnd('分'));
                            }
                            catch (Exception)
                            {
                                list.Add("简答分值格式不正确!");
                                continue;
                            }
                            break;
                        case "#单选#":
                            single.chapterid = 0;//不属于任何章节
                            single.diff = 3;//默认难度一般
                            single.questype = 2;//固定类型
                            single.ques = dt.Rows[i][1].ToString();
                            single.option_a = dt.Rows[i][2].ToString();
                            single.option_b = dt.Rows[i][3].ToString();
                            single.option_c = dt.Rows[i][4].ToString();
                            single.option_d = dt.Rows[i][5].ToString();
                            single.ans = dt.Rows[i][6].ToString();
                            if (single.ans != "A" && single.ans != "B" && single.ans != "C" && single.ans != "D")
                            {
                                list.Add("行" + (i + 2) + "的单选答案不正确!");
                                continue;
                            }
                            int singleid = singleDAL.AddTran(single, SqlTransaction);
                            paper.sr_list += singleid + ",";
                            paper.sr_count += 1;
                            break;
                        case "#多选#":
                            check.chapterid = 0;//不属于任何章节
                            check.diff = 3;//默认难度一般
                            check.questype = 2;//固定类型
                            check.ques = dt.Rows[i][1].ToString();
                            check.option_a = dt.Rows[i][2].ToString();
                            check.option_b = dt.Rows[i][3].ToString();
                            check.option_c = dt.Rows[i][4].ToString();
                            check.option_d = dt.Rows[i][5].ToString();
                            check.option_e = dt.Rows[i][6].ToString();
                            check.option_f = dt.Rows[i][7].ToString();
                            check.option_g = dt.Rows[i][8].ToString();
                            check.ans = dt.Rows[i][9].ToString();
                            if (check.ans == "" || check.ans == null)
                            {
                                list.Add("行" + (i + 2) + "的多选答案不正确!");
                                continue;
                            }
                            int checkid = checkDAL.AddTran(check, SqlTransaction);
                            paper.cb_list += checkid + ",";
                            paper.cb_count += 1;
                            break;
                        case "#判断#":
                            judge.chapterid = 0;//不属于任何章节
                            judge.diff = 3;//默认难度一般
                            judge.questype = 2;//固定类型
                            judge.ques = dt.Rows[i][1].ToString();
                            judge.ans = dt.Rows[i][2].ToString();
                            if (judge.ans != "对" && judge.ans != "错")
                            {
                                list.Add("行" + (i + 2) + "的判断答案不正确!");
                                continue;
                            }
                            int judgeid = judgeDAL.AddTran(judge, SqlTransaction);
                            paper.jd_list += judgeid + ",";
                            paper.jd_count += 1;
                            break;
                        case "#填空#":
                            blank.chapterid = 0;//不属于任何章节
                            blank.diff = 3;//默认难度一般
                            blank.questype = 2;//固定类型
                            blank.ques = dt.Rows[i][1].ToString();
                            blank.ans = dt.Rows[i][2].ToString();
                            blank.blanklength = blank.ans.Length;
                            int blankid = blankDAL.AddTran(blank, SqlTransaction);
                            paper.bf_list += blankid + ",";
                            paper.bf_count += 1;
                            break;
                        case "#简答#":
                            answer.chapterid = 0;//不属于任何章节
                            answer.diff = 3;//默认难度一般
                            answer.questype = 2;//固定类型
                            answer.ques = dt.Rows[i][1].ToString();
                            answer.ans = dt.Rows[i][2].ToString();
                            int answerid = answerDAL.AddTran(answer, SqlTransaction);
                            paper.sa_list += answerid + ",";
                            paper.sa_count += 1;
                            break;
                    }
                }
                if (list.Count == 0)
                {
                    if (paper.sr_list.EndsWith(","))
                    {
                        paper.sr_list = paper.sr_list.TrimEnd(',');
                    }
                    if (paper.cb_list.EndsWith(","))
                    {
                        paper.cb_list = paper.cb_list.TrimEnd(',');
                    }
                    if (paper.jd_list.EndsWith(","))
                    {
                        paper.jd_list = paper.jd_list.TrimEnd(',');
                    }
                    if (paper.bf_list.EndsWith(","))
                    {
                        paper.bf_list = paper.bf_list.TrimEnd(',');
                    }
                    if (paper.sa_list.EndsWith(","))
                    {
                        paper.sa_list = paper.sa_list.TrimEnd(',');
                    }
                    paper.allscore = paper.sr_count * paper.sr_scoreofeach + paper.cb_count * paper.cb_scoreofeach + paper.jd_count * paper.jd_scoreofeach + paper.bf_count * paper.bf_scoreofeach + paper.sa_count * paper.sa_scoreofeach;
                    paper.papertype = 2;//固定试卷
                    paper.createtime = DateTime.Now;
                    paper.userid = ((tbUser)HttpContext.Current.Session[Constant.User]).id;
                    paperDAL.AddTran(paper, SqlTransaction);
                    SqlTransaction.Commit();
                }
            }
            catch (Exception)
            {
                try
                {
                    SqlTransaction.Rollback();
                }
                catch (Exception)
                {
                    //事务回滚出错
                }
            }
            finally
            {
                //关闭各种资源
                SqlTransaction.Dispose();
                conn.Close();
            }

            return list;
        }
Пример #8
0
    /// <summary>
    /// 收集数据
    /// </summary>
    /// <returns></returns>
    private PaperContent CollectData()
    {
        PaperContent studentAnswer = new PaperContent();

        //单选题
        foreach (RepeaterItem item in rptSR.Items)
        {
            tbSingle sr = new tbSingle();

            sr.id = Convert.ToInt32(((HiddenField)item.FindControl("hfSR")).Value);

            if (((RadioButton)item.FindControl("rbtnA")).Checked)
            {
                sr.ans = "A";
                studentAnswer.SRContent.Add(sr);
                continue;
            }
            if (((RadioButton)item.FindControl("rbtnB")).Checked)
            {
                sr.ans = "B";
                studentAnswer.SRContent.Add(sr);
                continue;
            }
            if (((RadioButton)item.FindControl("rbtnC")).Checked)
            {
                sr.ans = "C";
                studentAnswer.SRContent.Add(sr);
                continue;
            }
            if (((RadioButton)item.FindControl("rbtnD")).Checked)
            {
                sr.ans = "D";
                studentAnswer.SRContent.Add(sr);
                continue;
            }
            //没选
            studentAnswer.SRContent.Add(sr);
        }

        //多选题
        foreach (RepeaterItem item in rptCB.Items)
        {
            tbCheck cb = new tbCheck();

            cb.id = Convert.ToInt32(((HiddenField)item.FindControl("hfCB")).Value);

            cb.ans = "";
            if (((CheckBox)item.FindControl("chkA")).Checked)
            {
                cb.ans += "A";
            }
            if (((CheckBox)item.FindControl("chkB")).Checked)
            {
                cb.ans += "B";
            }
            if (((CheckBox)item.FindControl("chkC")).Checked)
            {
                cb.ans += "C";
            }
            if (((CheckBox)item.FindControl("chkD")).Checked)
            {
                cb.ans += "D";
            }
            if (((CheckBox)item.FindControl("chkE")).Checked)
            {
                cb.ans += "E";
            }
            if (((CheckBox)item.FindControl("chkF")).Checked)
            {
                cb.ans += "F";
            }
            if (((CheckBox)item.FindControl("chkG")).Checked)
            {
                cb.ans += "G";
            }
            studentAnswer.CBContent.Add(cb);
        }

        //判断题
        foreach (RepeaterItem item in rptJD.Items)
        {
            tbJudge jd = new tbJudge();

            jd.id = Convert.ToInt32(((HiddenField)item.FindControl("hfJD")).Value);

            if (((RadioButton)item.FindControl("rbtnRight")).Checked)
            {
                jd.ans = "对";
                studentAnswer.JDContent.Add(jd);
                continue;
            }
            if (((RadioButton)item.FindControl("rbtnWrong")).Checked)
            {
                jd.ans = "错";
                studentAnswer.JDContent.Add(jd);
            }
            //没选
            studentAnswer.JDContent.Add(jd);
        }

        //填空题
        foreach (RepeaterItem item in rptBF.Items)
        {
            tbBlank bf = new tbBlank();

            bf.id = Convert.ToInt32(((HiddenField)item.FindControl("hfBF")).Value);

            bf.ans = ((TextBox)item.FindControl("txtBF")).Text.Trim();
            studentAnswer.BFContent.Add(bf);

        }

        //简答题
        foreach (RepeaterItem item in rptSA.Items)
        {
            tbAnswer sa = new tbAnswer();

            sa.id = Convert.ToInt32(((HiddenField)item.FindControl("hfSA")).Value);

            sa.ans = ((TextBox)item.FindControl("txtAnswer")).Text.Trim();
            studentAnswer.SAContent.Add(sa);
        }
        return studentAnswer;
    }