Exemple #1
0
        private void SumScore(int exa_id, int uid)
        {
            int truth_count = 0;
            int score       = 0;

            BLL.common_questions     qBll  = new BLL.common_questions();
            BLL.answer_record        arBll = new BLL.answer_record();
            BLL.common_answers       aBll  = new BLL.common_answers();
            Model.user_info          user  = new BLL.user_info().GetModel(uid);
            Model.common_examination exa   = new BLL.common_examination().GetModel(exa_id);
            if (exa != null)
            {
                DataTable dt = arBll.GetList(" exa_id = " + exa_id + " and user_id = " + uid);

                foreach (DataRow item in dt.Rows)
                {
                    #region 批改作业按老师选择对错为准
                    int is_truth = Convert.ToInt32(item["is_truth"]);

                    if (is_truth == 1)
                    {
                        truth_count++;
                        score += Convert.ToInt32(item["score"]);
                    }
                    #endregion

                    #region 批改作业按答题记录为准
                    //int q_id = Convert.ToInt32(item["q_id"]);
                    //string answer = item["answer"].ToString();

                    //Model.common_questions question = qBll.GetModel(q_id);
                    //if (!string.IsNullOrEmpty(answer))//没有答题
                    //{
                    //    if (question.type == (int)EnumCollection.questions_type.单选题 || question.type == (int)EnumCollection.questions_type.判断题)
                    //    {
                    //        Model.common_answers anModel = aBll.GetModel(Convert.ToInt32(answer));
                    //        if (anModel.options == question.answer)
                    //        {
                    //            truth_count++;
                    //            score += Convert.ToInt32(item["score"]);
                    //        }
                    //    }
                    //    if (question.type == (int)EnumCollection.questions_type.多选题)
                    //    {
                    //        string[] ids = answer.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                    //        string anids = string.Empty;
                    //        foreach (string id in ids)
                    //        {
                    //            Model.common_answers anModel = aBll.GetModel(Convert.ToInt32(id));
                    //            anids += anModel.options + ",";
                    //        }
                    //        if (question.answer == Utils.DelLastComma(anids))
                    //        {
                    //            truth_count++;
                    //            score += Convert.ToInt32(item["score"]);
                    //        }
                    //    }
                    //    if (question.type == (int)EnumCollection.questions_type.填空题 || question.type == (int)EnumCollection.questions_type.主观题)
                    //    {
                    //        if (answer.Contains(question.answer))
                    //        {
                    //            truth_count++;
                    //            score += Convert.ToInt32(item["score"]);
                    //        }
                    //    }
                    //}
                    #endregion
                }

                BLL.answer_result   bll   = new BLL.answer_result();
                Model.answer_result model = bll.GetModel(" group_id = " + (int)EnumCollection.examination_group.课堂作业 + " and exa_id = " + exa_id + " and user_id = " + uid);
                if (model != null)
                {
                    model.truth_num   = truth_count;
                    model.count       = exa.nums;
                    model.truth_ratio = Convert.ToDecimal((decimal)model.truth_num / (decimal)model.count) * 100;
                    model.score       = score;
                    model.status      = (int)EnumCollection.correcting_status.已批改;

                    bll.Update(model);
                }
                else
                {
                    model             = new Model.answer_result();
                    model.group_id    = (int)EnumCollection.examination_group.课堂作业;
                    model.exa_id      = exa_id;
                    model.exa_title   = exa.name;
                    model.user_id     = uid;
                    model.avatar      = user.avatar;
                    model.nick_name   = user.nick_name;
                    model.use_min     = 0;
                    model.use_sec     = 0;
                    model.truth_num   = truth_count;
                    model.count       = exa.nums;
                    model.truth_ratio = 0;
                    model.score       = score;
                    model.status      = (int)EnumCollection.correcting_status.未批改;
                    model.add_time    = System.DateTime.Now;

                    bll.Add(model);
                }
            }
        }
        //保存
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            ChkAdminLevel("_ybd_answer_result", EnumCollection.ActionEnum.Add.ToString()); //检查权限

            #region
            string strError = string.Empty;
            if (txtgroup_id.Text.Trim() == "" || txtgroup_id.Text.Trim().Length > 4)
            {
                strError += "分组ID为空或超出长度![br]";
            }
            if (txtexa_id.Text.Trim() == "" || txtexa_id.Text.Trim().Length > 4)
            {
                strError += "试卷ID为空或超出长度![br]";
            }
            if (txtexa_title.Text.Trim() == "" || txtexa_title.Text.Trim().Length > 50)
            {
                strError += "试卷标题为空或超出长度![br]";
            }
            if (txtuser_id.Text.Trim() == "" || txtuser_id.Text.Trim().Length > 4)
            {
                strError += "答题者ID为空或超出长度![br]";
            }
            if (txtavatar.Text.Trim() == "" || txtavatar.Text.Trim().Length > 50)
            {
                strError += "头像为空或超出长度![br]";
            }
            if (txtnick_name.Text.Trim() == "" || txtnick_name.Text.Trim().Length > 50)
            {
                strError += "昵称为空或超出长度![br]";
            }
            if (txtuse_min.Text.Trim() == "" || txtuse_min.Text.Trim().Length > 4)
            {
                strError += "用时-分钟为空或超出长度![br]";
            }
            if (txtuse_sec.Text.Trim() == "" || txtuse_sec.Text.Trim().Length > 4)
            {
                strError += "用时-秒钟为空或超出长度![br]";
            }
            if (txttruth_num.Text.Trim() == "" || txttruth_num.Text.Trim().Length > 4)
            {
                strError += "答对题数为空或超出长度![br]";
            }
            if (txtcount.Text.Trim() == "" || txtcount.Text.Trim().Length > 4)
            {
                strError += "总题数为空或超出长度![br]";
            }
            if (txttruth_ratio.Text.Trim() == "" || txttruth_ratio.Text.Trim().Length > 5)
            {
                strError += "正确率为空或超出长度![br]";
            }
            if (txtscore.Text.Trim() == "" || txtscore.Text.Trim().Length > 4)
            {
                strError += "总分为空或超出长度![br]";
            }
            if (txtstatus.Text.Trim() == "" || txtstatus.Text.Trim().Length > 4)
            {
                strError += "批改状态 1已批改 0未批改为空或超出长度![br]";
            }
            if (txtadd_time.Text.Trim() == "" || txtadd_time.Text.Trim().Length > 8)
            {
                strError += "完成时间为空或超出长度![br]";
            }

            if (strError != string.Empty)
            {
                JscriptMsg(strError, "", "Error");
                return;
            }
            #endregion

            Model.answer_result model = new Model.answer_result();
            BLL.answer_result   bll   = new BLL.answer_result();

            model.group_id    = Convert.ToInt32(txtgroup_id.Text);
            model.exa_id      = Convert.ToInt32(txtexa_id.Text);
            model.exa_title   = Convert.ToString(txtexa_title.Text);
            model.user_id     = Convert.ToInt32(txtuser_id.Text);
            model.avatar      = Convert.ToString(txtavatar.Text);
            model.nick_name   = Convert.ToString(txtnick_name.Text);
            model.use_min     = Convert.ToInt32(txtuse_min.Text);
            model.use_sec     = Convert.ToInt32(txtuse_sec.Text);
            model.truth_num   = Convert.ToInt32(txttruth_num.Text);
            model.count       = Convert.ToInt32(txtcount.Text);
            model.truth_ratio = Convert.ToDecimal(txttruth_ratio.Text);
            model.score       = Convert.ToInt32(txtscore.Text);
            model.status      = Convert.ToInt32(txtstatus.Text);
            model.add_time    = Convert.ToDateTime(txtadd_time.Text);

            int id = bll.Add(model);
            if (id > 0)
            {
                AddAdminLog(EnumCollection.ActionEnum.Add.ToString(), "添加答题结果信息,主键:" + id); //记录日志
                JscriptMsg("添加答题结果信息成功!", "Manage.aspx", "");
            }
            else
            {
                JscriptMsg("保存过程中发生错误!", "");
            }
        }