Ejemplo n.º 1
0
        private void BindData()
        {
            this.page = RequestHelper.GetQueryInt("page", 1);

            DataTable dtids = new BLL.examination_question().GetViewList("View_ExaminationQuestion", " group_id = " + group + " and exa_id = " + exaid);
            string    ids   = string.Empty;

            foreach (DataRow item in dtids.Rows)
            {
                ids += Convert.ToInt32(item["id"]) + ",";
            }

            ids = Utils.DelLastComma(ids);

            string where = " group_id = " + this.group + " and data_id = " + this.chapter;
            if (!string.IsNullOrEmpty(ids))
            {
                where += " and id not in (" + ids + ") ";
            }

            BLL.common_questions bLL = new BLL.common_questions();
            DataTable            dt  = bLL.GetListByPage(where, "id", this.page, this.pageSize);

            this.rptList.DataSource = dt;
            this.rptList.DataBind();

            this.totalCount = bLL.GetRecordCount(where);

            //绑定页码
            txtPageNum.Text = this.pageSize.ToString();
            string pageUrl = Utils.CombUrlTxt("unselected_question.aspx", "exaid={0}&page={1}&group={2}", this.exaid + "", "__id__", this.group + "");

            PageContent.InnerHtml = Utils.OutPageList(this.pageSize, this.page, this.totalCount, pageUrl, 8);
        }
        private bool DoEdit()
        {
            bool result = false;

            BLL.common_questions   bll   = new BLL.common_questions();
            Model.common_questions model = bll.GetModel(this.id);

            model.group_id = Convert.ToInt32(this.rbtnGroup.SelectedValue);
            model.type     = Convert.ToInt32(this.rbtnType.SelectedValue);
            model.data_id  = this.chapter;
            model.number   = 0;
            model.title    = Convert.ToString(this.txttitle.Text.Trim());
            model.answer   = (model.type == (int)EnumCollection.questions_type.单选题 || model.type == (int)EnumCollection.questions_type.多选题 ||
                              model.type == (int)EnumCollection.questions_type.判断题) ? this.txtAnswers.Text.Trim().ToUpper() : this.txtAnswers.Text.Trim();
            model.score    = Convert.ToDecimal(this.txtscore.Text.Trim());
            model.analysis = Convert.ToString(this.txtanalysis.Text.Trim());
            model.add_time = System.DateTime.Now;

            if (bll.Update(model))
            {
                AddAdminLog(EnumCollection.ActionEnum.Modify.ToString(), "修改试题信息,主键:" + id); //记录日志
                result = true;
            }
            return(result);
        }
Ejemplo n.º 3
0
        //批量删除
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            ChkAdminLevel("_ybd_common_questions", EnumCollection.ActionEnum.Delete.ToString()); //检查权限
            int sucCount   = 0;
            int errorCount = 0;

            BLL.common_questions bll = new BLL.common_questions();
            for (int i = 0; i < rptList.Items.Count; i++)
            {
                int      id = Convert.ToInt32(((HiddenField)rptList.Items[i].FindControl("hidId")).Value);
                CheckBox cb = (CheckBox)rptList.Items[i].FindControl("chkId");
                if (cb.Checked)
                {
                    if (bll.Delete(id))
                    {
                        sucCount += 1;
                    }
                    else
                    {
                        errorCount += 1;
                    }
                }
            }
            AddAdminLog(EnumCollection.ActionEnum.Delete.ToString(), "删除题目信息" + sucCount + "条,失败" + errorCount + "条"); //记录日志
            JscriptMsg("删除成功" + sucCount + "条,失败" + errorCount + "条!", Utils.CombUrlTxt("Manage.aspx", "keywords={0}", this.keywords));
        }
Ejemplo n.º 4
0
        private void BindData()
        {
            #region 组装查询条件
            string whereStr  = " 1 = 1 ";
            string _keywords = keywords.Replace("'", "");

            if (!string.IsNullOrEmpty(_keywords))
            {
                if (Utils.IsSafeSqlString(_keywords))
                {
                    whereStr += " and (Title like  '%" + _keywords + "%')";
                }
                else
                {
                    JscriptMsg("搜索关键词中包含危险字符,检索终止!", Utils.CombUrlTxt("Manage.aspx", "keywords={0}", ""));
                    return;
                }
            }
            #endregion

            this.page        = RequestHelper.GetQueryInt("page", 1);
            txtKeywords.Text = this.keywords;
            BLL.common_questions bll = new BLL.common_questions();
            this.rptList.DataSource = bll.GetListByPage(whereStr, "ID DESC", this.page, this.pageSize);
            this.rptList.DataBind();

            this.totalCount = bll.GetRecordCount(whereStr);
            //绑定页码
            txtPageNum.Text = this.pageSize.ToString();
            string pageUrl = Utils.CombUrlTxt("Manage.aspx", "keywords={0}&page={1}", this.keywords, "__id__");
            PageContent.InnerHtml = Utils.OutPageList(this.pageSize, this.page, this.totalCount, pageUrl, 8);
        }
        //批量删除
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            ChkAdminLevel("_common_questions", EnumCollection.ActionEnum.Delete.ToString()); //检查权限
            int sucCount   = 0;
            int errorCount = 0;

            BLL.common_questions bll = new BLL.common_questions();
            for (int i = 0; i < rptList.Items.Count; i++)
            {
                int      id = Convert.ToInt32(((HiddenField)rptList.Items[i].FindControl("hidId")).Value);
                CheckBox cb = (CheckBox)rptList.Items[i].FindControl("chkId");
                if (cb.Checked)
                {
                    if (bll.Delete(id))
                    {
                        Appoa.DBUtility.DbHelperSQL.ExecuteSql(" delete from ybd_common_answers where question_id = " + id);
                        sucCount += 1;
                    }
                    else
                    {
                        errorCount += 1;
                    }
                }
            }
            AddAdminLog(EnumCollection.ActionEnum.Delete.ToString(), "删除题目信息" + sucCount + "条,失败" + errorCount + "条"); //记录日志
            JscriptMsg("删除成功" + sucCount + "条,失败" + errorCount + "条!", Utils.CombUrlTxt("questions_list.aspx", "keywords={0}&type={1}&group={2}&chapter={3}", this.keywords, this.type + "", this.group + "", this.chapter + ""));
        }
Ejemplo n.º 6
0
        //保存
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            ChkAdminLevel("_ybd_common_questions", EnumCollection.ActionEnum.Modify.ToString()); //检查权限
            BLL.common_questions   bll   = new BLL.common_questions();
            Model.common_questions model = bll.GetModel(this.id);

            model.group_id = Convert.ToInt32(txtgroup_id.Text);
            model.type     = Convert.ToInt32(txttype.Text);
            model.data_id  = Convert.ToInt32(txtdata_id.Text);
            model.number   = Convert.ToInt32(txtnumber.Text);
            model.title    = Convert.ToString(txttitle.Text);
            model.answer   = Convert.ToString(txtanswer.Text);
            model.score    = Convert.ToDecimal(txtscore.Text);
            model.analysis = Convert.ToString(txtanalysis.Text);
            model.add_time = Convert.ToDateTime(txtadd_time.Text);

            if (bll.Update(model))
            {
                AddAdminLog(EnumCollection.ActionEnum.Modify.ToString(), "修改题目信息信息,主键:" + id); //记录日志
                JscriptMsg("修改题目信息信息成功!", "Manage.aspx");
            }
            else
            {
                JscriptMsg("保存过程中发生错误!", "");
            }
        }
Ejemplo n.º 7
0
        private void getQuestionOptions()
        {
            int id = RequestHelper.GetFormInt("id");

            Model.common_questions question = new BLL.common_questions().GetModel(id);
            if (question == null)
            {
                writeMsgError("没有此题目");
                return;
            }

            DataTable dt = new BLL.common_answers().GetList(" question_id = " + id + " order by options asc ");

            writeMsgSuccess("", dt);
        }
        private void ShowInfo()
        {
            BLL.common_questions   bll   = new BLL.common_questions();
            Model.common_questions model = bll.GetModel(this.id);
            if (model == null)
            {
                JscriptMsg("信息不存在或已被删除!", "back");
                return;
            }

            this.rbtnGroup.SelectedValue = model.group_id + "";
            this.rbtnType.SelectedValue  = model.type + "";
            this.txttitle.Text           = model.title + "";
            this.txtAnswers.Text         = model.answer + "";
            this.txtscore.Text           = Convert.ToInt32(model.score) + "";
            this.txtanalysis.Text        = model.analysis + "";
        }
        private void BindData()
        {
            #region 组装查询条件
            string whereStr  = " data_id = " + this.chapter;
            string _keywords = keywords.Replace("'", "");

            if (!string.IsNullOrEmpty(_keywords))
            {
                if (Utils.IsSafeSqlString(_keywords))
                {
                    whereStr += " and (Title like  '%" + _keywords + "%')";
                }
                else
                {
                    JscriptMsg("搜索关键词中包含危险字符,检索终止!", Utils.CombUrlTxt("questions_list.aspx", "keywords={0}&chapter={1}", "", this.chapter + ""));
                    return;
                }
            }

            if (this.group > 0)
            {
                this.ddlGroup.SelectedValue = this.group + "";
                whereStr += " and group_id = " + this.group;
            }

            if (this.type > 0)
            {
                this.ddlType.SelectedValue = this.type + "";
                whereStr += " and type = " + this.type;
            }
            #endregion

            this.page        = RequestHelper.GetQueryInt("page", 1);
            txtKeywords.Text = this.keywords;
            BLL.common_questions bll = new BLL.common_questions();
            this.rptList.DataSource = bll.GetListByPage(whereStr, "ID DESC", this.page, this.pageSize);
            this.rptList.DataBind();

            this.totalCount = bll.GetRecordCount(whereStr);
            //绑定页码
            txtPageNum.Text = this.pageSize.ToString();
            string pageUrl = Utils.CombUrlTxt("questions_list.aspx", "keywords={0}&page={1}&type={2}&group={3}&chapter={4}", this.keywords, "__id__", this.type + "", this.group + "", this.chapter + "");
            PageContent.InnerHtml = Utils.OutPageList(this.pageSize, this.page, this.totalCount, pageUrl, 8);
        }
Ejemplo n.º 10
0
 private void BindInfo()
 {
     BLL.common_questions   bll   = new BLL.common_questions();
     Model.common_questions model = bll.GetModel(this.id);
     if (model == null)
     {
         JscriptMsg("信息不存在或已被删除!", "back");
         return;
     }
     txtgroup_id.Text = model.group_id + "";
     txttype.Text     = model.type + "";
     txtdata_id.Text  = model.data_id + "";
     txtnumber.Text   = model.number + "";
     txttitle.Text    = model.title + "";
     txtanswer.Text   = model.answer + "";
     txtscore.Text    = model.score + "";
     txtanalysis.Text = model.analysis + "";
     txtadd_time.Text = model.add_time + "";
 }
        private void BindData()
        {
            Model.common_questions quModel = new BLL.common_questions().GetModel(this.id);
            if (quModel == null)
            {
                JscriptMsg("没有此题目", "back");
                return;
            }
            this.question = quModel.title;

            #region 组装查询条件
            string whereStr  = " group_id = " + (int)EnumCollection.examination_group.课堂作业 + " and exa_id = " + this.exa_id + " and q_id = " + this.id;
            string _keywords = keywords.Replace("'", "");

            if (!string.IsNullOrEmpty(_keywords))
            {
                if (Utils.IsSafeSqlString(_keywords))
                {
                    whereStr += " and (Title like  '%" + _keywords + "%')";
                }
                else
                {
                    JscriptMsg("搜索关键词中包含危险字符,检索终止!", Utils.CombUrlTxt("currect_answer_list.aspx", "keywords={0}", ""));
                    return;
                }
            }
            #endregion

            this.page        = RequestHelper.GetQueryInt("page", 1);
            txtKeywords.Text = this.keywords;
            BLL.answer_record bll = new BLL.answer_record();
            this.rptList.DataSource = bll.GetListByPage("*", "View_Currect_Question", whereStr, "id", this.page, this.pageSize);
            this.rptList.DataBind();

            this.totalCount = bll.GetRecordCount(whereStr);
            //绑定页码
            txtPageNum.Text = this.pageSize.ToString();
            string pageUrl = Utils.CombUrlTxt("currect_answer_list.aspx", "keywords={0}&page={1}", this.keywords, "__id__");
            PageContent.InnerHtml = Utils.OutPageList(this.pageSize, this.page, this.totalCount, pageUrl, 8);
        }
Ejemplo n.º 12
0
        private void saveQuestionOptions()
        {
            int    id       = RequestHelper.GetFormInt("id");
            int    group    = RequestHelper.GetFormInt("group", 0);
            int    type     = RequestHelper.GetFormInt("type", 0);
            int    chapter  = RequestHelper.GetFormInt("chapter", 0);
            string title    = RequestHelper.GetFormString("title");
            int    score    = RequestHelper.GetFormInt("score", 0);
            string answers  = RequestHelper.GetFormString("answers");
            string analysis = RequestHelper.GetFormString("analysis");
            string options  = RequestHelper.GetFormString("options");

            Appoa.Web.UI.ManagePage mngPage = new Web.UI.ManagePage();
            BLL.common_questions    bll     = new BLL.common_questions();
            Model.common_questions  model   = bll.GetModel(id);

            if (model != null)
            {
                #region 修改题目信息
                model.group_id = group;
                model.type     = type;
                model.data_id  = chapter;
                model.number   = 0;
                model.title    = title;
                model.answer   = (model.type == (int)EnumCollection.questions_type.单选题 || model.type == (int)EnumCollection.questions_type.多选题 ||
                                  model.type == (int)EnumCollection.questions_type.判断题) ? answers.Trim().ToUpper() : answers.Trim();
                model.score    = score;
                model.analysis = HttpUtility.UrlDecode(analysis, System.Text.Encoding.UTF8);

                if (bll.Update(model))
                {
                    try
                    {
                        #region  择题设置选项
                        if (model.type == (int)EnumCollection.questions_type.单选题 || model.type == (int)EnumCollection.questions_type.多选题 || model.type == (int)EnumCollection.questions_type.判断题)
                        {
                            JArray               optionArr = JsonConvert.DeserializeObject <JArray>(options);
                            BLL.common_answers   anBll     = new BLL.common_answers();
                            Model.common_answers anModel   = null;

                            List <int> ids = new List <int>();
                            foreach (JObject obj in optionArr)
                            {
                                ids.Add(Convert.ToInt32(obj["options_id"].ToString()));
                            }

                            DataTable dt = anBll.GetList(" question_id = " + model.id);
                            foreach (DataRow item in dt.Rows)
                            {
                                int afid = Convert.ToInt32(item["id"]);
                                if (afid > 0)
                                {
                                    if (!ids.Contains(afid))
                                    {
                                        anBll.Delete(afid);
                                    }
                                }
                            }

                            foreach (JObject item in optionArr)
                            {
                                int options_id = Convert.ToInt32(item["options_id"]);
                                anModel = anBll.GetModel(options_id);
                                if (anModel != null)
                                {
                                    #region 修改选项
                                    anModel.question_id = model.id;
                                    anModel.options     = item["options"].ToString();
                                    anModel.contents    = item["options_contents"].ToString();
                                    anModel.score       = Convert.ToInt32(item["options_score"].ToString());
                                    if (anBll.Update(anModel))
                                    {
                                        mngPage.AddAdminLog(EnumCollection.ActionEnum.Modify.ToString(), "修改选项信息,主键:" + options_id); //记录日志
                                    }
                                    #endregion
                                }
                                else
                                {
                                    #region 添加选项
                                    anModel             = new Model.common_answers();
                                    anModel.question_id = model.id;
                                    anModel.options     = item["options"].ToString();
                                    anModel.contents    = item["options_contents"].ToString();
                                    anModel.score       = Convert.ToInt32(item["options_score"].ToString());
                                    anModel.add_time    = System.DateTime.Now;

                                    int anid = anBll.Add(anModel);
                                    if (anid > 0)
                                    {
                                        mngPage.AddAdminLog(EnumCollection.ActionEnum.Add.ToString(), "添加选项信息,主键:" + anid); //记录日志
                                    }
                                    #endregion
                                }
                            }
                        }
                        #endregion
                    }
                    catch (Exception e)
                    {
                        writeMsgError("系统错误:" + e.Message);
                    }

                    mngPage.AddAdminLog(EnumCollection.ActionEnum.Modify.ToString(), "修改试题信息,主键:" + model.id); //记录日志

                    writeMsgSuccess("修改题目信息成功");
                }
                else
                {
                    writeMsgError("修改题目信息失败");
                }
                #endregion
            }
            else
            {
                #region 添加题目信息
                model          = new Model.common_questions();
                model.group_id = group;
                model.type     = type;
                model.data_id  = chapter;
                model.number   = 0;
                model.title    = title;
                model.answer   = (model.type == (int)EnumCollection.questions_type.单选题 || model.type == (int)EnumCollection.questions_type.多选题 ||
                                  model.type == (int)EnumCollection.questions_type.判断题) ? answers.Trim().ToUpper() : answers.Trim();
                model.score    = score;
                model.analysis = HttpUtility.UrlDecode(analysis, System.Text.Encoding.UTF8);
                model.add_time = System.DateTime.Now;

                int qid = bll.Add(model);
                if (qid > 0)
                {
                    try
                    {
                        #region  择题设置选项
                        if (model.type == (int)EnumCollection.questions_type.单选题 || model.type == (int)EnumCollection.questions_type.多选题 || model.type == (int)EnumCollection.questions_type.判断题)
                        {
                            JArray               optionArr = JsonConvert.DeserializeObject <JArray>(options);
                            BLL.common_answers   anBll     = new BLL.common_answers();
                            Model.common_answers anModel   = null;

                            foreach (JObject item in optionArr)
                            {
                                int options_id = Convert.ToInt32(item["options_id"]);
                                if (options_id > 0)
                                {
                                    #region 修改选项
                                    anModel = anBll.GetModel(options_id);
                                    if (anModel != null)
                                    {
                                        anModel.question_id = qid;
                                        anModel.options     = item["options"].ToString();
                                        anModel.contents    = item["options_contents"].ToString();
                                        anModel.score       = Convert.ToInt32(item["options_score"].ToString());
                                        if (anBll.Update(anModel))
                                        {
                                            mngPage.AddAdminLog(EnumCollection.ActionEnum.Modify.ToString(), "修改选项信息,主键:" + options_id); //记录日志
                                        }
                                    }
                                    #endregion
                                }
                                else
                                {
                                    #region 添加选项
                                    anModel             = new Model.common_answers();
                                    anModel.question_id = qid;
                                    anModel.options     = item["options"].ToString();
                                    anModel.contents    = item["options_contents"].ToString();
                                    anModel.score       = Convert.ToInt32(item["options_score"].ToString());
                                    anModel.add_time    = System.DateTime.Now;

                                    int anid = anBll.Add(anModel);
                                    if (anid > 0)
                                    {
                                        mngPage.AddAdminLog(EnumCollection.ActionEnum.Add.ToString(), "添加选项信息,主键:" + anid); //记录日志
                                    }
                                    #endregion
                                }
                            }
                        }
                        #endregion
                    }
                    catch (Exception e)
                    {
                        writeMsgError("系统错误:" + e.Message);
                    }

                    mngPage.AddAdminLog(EnumCollection.ActionEnum.Add.ToString(), "添加试题信息,主键:" + qid); //记录日志

                    writeMsgSuccess("添加题目信息成功");
                }
                else
                {
                    writeMsgError("添加题目信息失败");
                }
                #endregion
            }
        }
Ejemplo n.º 13
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);
                }
            }
        }
Ejemplo n.º 14
0
        private void BindData()
        {
            BLL.course_chapter   ccBll   = new BLL.course_chapter();
            Model.course_chapter chapter = ccBll.GetModel(this.chapter);
            if (chapter == null)
            {
                JscriptMsg("没有此节", "back");
                return;
            }

            this.chapter_name = chapter.name;
            Model.course_chapter pModel = ccBll.GetModel(chapter.parent_id);
            if (pModel == null)
            {
                JscriptMsg("没有此章", "back");
                return;
            }

            this.parent_name = pModel.name;
            Model.classroom_info ciModel = new BLL.classroom_info().GetModel(pModel.course_id);
            if (ciModel == null)
            {
                JscriptMsg("没有此课堂", "back");
                return;
            }

            this.class_name = ciModel.name;
            Model.user_info user = new BLL.user_info().GetModel(" phone = '" + adminInfo.user_name + "' ");
            if (user == null)
            {
                JscriptMsg("没有此教师", "back");
                return;
            }

            if (ciModel.user_id != user.id)
            {
                JscriptMsg("此课堂不属于你", "back");
                return;
            }

            Model.common_examination exaModel = new BLL.common_examination().GetModel(this.exa_id);
            if (exaModel == null)
            {
                JscriptMsg("没有此作业", "back");
                return;
            }

            this.examination = exaModel.name;
            #region 组装查询条件
            string whereStr = " 1 = 1 ";

            DataTable dtids = new BLL.examination_question().GetList(" exa_id = " + this.exa_id);
            string    ids   = string.Empty;
            foreach (DataRow item in dtids.Rows)
            {
                ids += Convert.ToInt32(item["q_id"]) + ",";
            }

            ids = Utils.DelLastComma(ids);

            if (!string.IsNullOrEmpty(ids))
            {
                whereStr += " and id in (" + ids + ") ";
            }


            string _keywords = keywords.Replace("'", "");

            if (!string.IsNullOrEmpty(_keywords))
            {
                if (Utils.IsSafeSqlString(_keywords))
                {
                    whereStr += " and (Title like  '%" + _keywords + "%')";
                }
                else
                {
                    JscriptMsg("搜索关键词中包含危险字符,检索终止!", Utils.CombUrlTxt("currect_question_list.aspx", "keywords={0}", ""));
                    return;
                }
            }

            if (this.type > 0)
            {
                this.ddlType.SelectedValue = this.type + "";
                whereStr += " and type = " + this.type;
            }
            #endregion

            this.page        = RequestHelper.GetQueryInt("page", 1);
            txtKeywords.Text = this.keywords;
            BLL.common_questions bll = new BLL.common_questions();
            this.rptList.DataSource = bll.GetListByPage(whereStr, "ID", this.page, this.pageSize);
            this.rptList.DataBind();

            this.totalCount = bll.GetRecordCount(whereStr);
            //绑定页码
            txtPageNum.Text = this.pageSize.ToString();
            string pageUrl = Utils.CombUrlTxt("currect_question_list.aspx", "keywords={0}&page={1}&type={2}", this.keywords, "__id__", this.type + "");
            PageContent.InnerHtml = Utils.OutPageList(this.pageSize, this.page, this.totalCount, pageUrl, 8);
        }
Ejemplo n.º 15
0
        //保存
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            ChkAdminLevel("_ybd_common_questions", EnumCollection.ActionEnum.Add.ToString()); //检查权限

            #region
            string strError = string.Empty;
            if (txtgroup_id.Text.Trim() == "" || txtgroup_id.Text.Trim().Length > 4)
            {
                strError += "分组ID为空或超出长度![br]";
            }
            if (txttype.Text.Trim() == "" || txttype.Text.Trim().Length > 4)
            {
                strError += "题型为空或超出长度![br]";
            }
            if (txtdata_id.Text.Trim() == "" || txtdata_id.Text.Trim().Length > 4)
            {
                strError += "关联数据ID为空或超出长度![br]";
            }
            if (txtnumber.Text.Trim() == "" || txtnumber.Text.Trim().Length > 4)
            {
                strError += "序号为空或超出长度![br]";
            }
            if (txttitle.Text.Trim() == "" || txttitle.Text.Trim().Length > 200)
            {
                strError += "标题为空或超出长度![br]";
            }
            if (txtanswer.Text.Trim() == "" || txtanswer.Text.Trim().Length > 4000)
            {
                strError += "参考答案为空或超出长度![br]";
            }
            if (txtscore.Text.Trim() == "" || txtscore.Text.Trim().Length > 5)
            {
                strError += "分值为空或超出长度![br]";
            }
            if (txtanalysis.Text.Trim() == "" || txtanalysis.Text.Trim().Length > 2000)
            {
                strError += "解析为空或超出长度![br]";
            }
            if (txtadd_time.Text.Trim() == "" || txtadd_time.Text.Trim().Length > 8)
            {
                strError += "添加时间为空或超出长度![br]";
            }

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

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

            model.group_id = Convert.ToInt32(txtgroup_id.Text);
            model.type     = Convert.ToInt32(txttype.Text);
            model.data_id  = Convert.ToInt32(txtdata_id.Text);
            model.number   = Convert.ToInt32(txtnumber.Text);
            model.title    = Convert.ToString(txttitle.Text);
            model.answer   = Convert.ToString(txtanswer.Text);
            model.score    = Convert.ToDecimal(txtscore.Text);
            model.analysis = Convert.ToString(txtanalysis.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("保存过程中发生错误!", "");
            }
        }
        private DataTable ExcelToDataTable(string filePath, bool isColumnName)
        {
            int chapter = RequestHelper.GetQueryInt("chapter");

            DataTable  dataTable     = null;
            DataTable  dtOption      = null;
            FileStream fs            = null;
            DataColumn column        = null;
            DataRow    dataRow       = null;
            IWorkbook  workbook      = null;
            ISheet     sheetQuestion = null;
            ISheet     sheetOption   = null;
            IRow       row           = null;
            ICell      cell          = null;
            int        startRow      = 0;

            BLL.common_questions qbll = new BLL.common_questions();
            BLL.common_answers   obll = new BLL.common_answers();
            int group = Convert.ToInt32(this.rbtnGroup.SelectedValue);

            try
            {
                using (fs = File.OpenRead(filePath))
                {
                    // 2007版本
                    if (filePath.IndexOf(".xlsx") > 0)
                    {
                        workbook = new XSSFWorkbook(fs);
                    }
                    // 2003版本
                    else if (filePath.IndexOf(".xls") > 0)
                    {
                        workbook = new HSSFWorkbook(fs);
                    }

                    Dictionary <string, int> dic = GetQuestionDic();
                    if (workbook != null)
                    {
                        #region 问题表
                        sheetQuestion = workbook.GetSheetAt(0);//读取第一个sheetQuestion,当然也可以循环读取每个sheetQuestion
                        dataTable     = new DataTable();
                        if (sheetQuestion != null)
                        {
                            int rowCount = sheetQuestion.LastRowNum;//总行数
                            if (rowCount > 0)
                            {
                                IRow firstRow  = sheetQuestion.GetRow(0); //第一行
                                int  cellCount = firstRow.LastCellNum;    //列数

                                //构建datatable的列
                                if (isColumnName)
                                {
                                    startRow = 1;//如果第一行是列名,则从第二行开始读取
                                    for (int i = firstRow.FirstCellNum; i < cellCount; ++i)
                                    {
                                        cell = firstRow.GetCell(i);
                                        if (cell != null)
                                        {
                                            if (cell.StringCellValue != null)
                                            {
                                                column = new DataColumn(cell.StringCellValue);
                                                dataTable.Columns.Add(column);
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    for (int i = firstRow.FirstCellNum; i < cellCount; ++i)
                                    {
                                        column = new DataColumn("column" + (i + 1));
                                        dataTable.Columns.Add(column);
                                    }
                                }

                                //填充行
                                for (int i = startRow; i <= rowCount; ++i)
                                {
                                    row = sheetQuestion.GetRow(i);
                                    if (row == null)
                                    {
                                        continue;
                                    }

                                    dataRow = dataTable.NewRow();
                                    for (int j = row.FirstCellNum; j < cellCount; ++j)
                                    {
                                        cell = row.GetCell(j);
                                        if (cell == null)
                                        {
                                            dataRow[j] = "";
                                        }
                                        else
                                        {
                                            //CellType(Unknown = -1,Numeric = 0,String = 1,Formula = 2,Blank = 3,Boolean = 4,Error = 5,)
                                            switch (cell.CellType)
                                            {
                                            case CellType.Blank:
                                                dataRow[j] = "";
                                                break;

                                            case CellType.Numeric:
                                                short format = cell.CellStyle.DataFormat;
                                                //对时间格式(2015.12.5、2015/12/5、2015-12-5等)的处理
                                                if (format == 14 || format == 31 || format == 57 || format == 58)
                                                {
                                                    dataRow[j] = cell.DateCellValue;
                                                }
                                                else
                                                {
                                                    dataRow[j] = cell.NumericCellValue;
                                                }
                                                break;

                                            case CellType.String:
                                                dataRow[j] = cell.StringCellValue;
                                                break;
                                            }
                                        }
                                    }
                                    dataTable.Rows.Add(dataRow);
                                }
                            }
                        }
                        #endregion

                        Model.common_questions question = null;

                        foreach (DataRow item in dataTable.Rows)
                        {
                            question = qbll.GetModel(" group_id = " + group + " and title = '" + item[0].ToString() + "' ");
                            if (question == null)
                            {
                                question          = new Model.common_questions();
                                question.group_id = group;
                                question.type     = dic[item[1].ToString()];
                                question.data_id  = chapter;
                                question.number   = 0;
                                question.title    = item[0].ToString();
                                question.answer   = item[2].ToString();
                                question.score    = Convert.ToDecimal(item[3]);
                                question.analysis = item[4].ToString();
                                question.add_time = System.DateTime.Now;

                                qbll.Add(question);
                            }
                            else
                            {
                                question.group_id = group;
                                question.type     = dic[item[1].ToString()];
                                question.data_id  = chapter;
                                question.number   = 0;
                                question.answer   = item[2].ToString();
                                question.score    = Convert.ToDecimal(item[3]);
                                question.analysis = item[4].ToString();

                                qbll.Update(question);
                            }
                        }

                        #region  项表
                        sheetOption = workbook.GetSheetAt(1);//读取第一个sheetOption,当然也可以循环读取每个sheetOption
                        dtOption    = new DataTable();
                        if (sheetOption != null)
                        {
                            int rowCount = sheetOption.LastRowNum;//总行数
                            if (rowCount > 0)
                            {
                                IRow firstRow  = sheetOption.GetRow(0); //第一行
                                int  cellCount = firstRow.LastCellNum;  //列数

                                //构建datatable的列
                                if (isColumnName)
                                {
                                    startRow = 1;//如果第一行是列名,则从第二行开始读取
                                    for (int i = firstRow.FirstCellNum; i < cellCount; ++i)
                                    {
                                        cell = firstRow.GetCell(i);
                                        if (cell != null)
                                        {
                                            if (cell.StringCellValue != null)
                                            {
                                                column = new DataColumn(cell.StringCellValue);
                                                dtOption.Columns.Add(column);
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    for (int i = firstRow.FirstCellNum; i < cellCount; ++i)
                                    {
                                        column = new DataColumn("column" + (i + 1));
                                        dtOption.Columns.Add(column);
                                    }
                                }

                                //填充行
                                for (int i = startRow; i <= rowCount; ++i)
                                {
                                    row = sheetOption.GetRow(i);
                                    if (row == null)
                                    {
                                        continue;
                                    }

                                    dataRow = dtOption.NewRow();
                                    for (int j = row.FirstCellNum; j < cellCount; ++j)
                                    {
                                        cell = row.GetCell(j);
                                        if (cell == null)
                                        {
                                            dataRow[j] = "";
                                        }
                                        else
                                        {
                                            //CellType(Unknown = -1,Numeric = 0,String = 1,Formula = 2,Blank = 3,Boolean = 4,Error = 5,)
                                            switch (cell.CellType)
                                            {
                                            case CellType.Blank:
                                                dataRow[j] = "";
                                                break;

                                            case CellType.Numeric:
                                                short format = cell.CellStyle.DataFormat;
                                                //对时间格式(2015.12.5、2015/12/5、2015-12-5等)的处理
                                                if (format == 14 || format == 31 || format == 57 || format == 58)
                                                {
                                                    dataRow[j] = cell.DateCellValue;
                                                }
                                                else
                                                {
                                                    dataRow[j] = cell.NumericCellValue;
                                                }
                                                break;

                                            case CellType.String:
                                                dataRow[j] = cell.StringCellValue;
                                                break;
                                            }
                                        }
                                    }
                                    dtOption.Rows.Add(dataRow);
                                }
                            }
                        }
                        #endregion

                        Model.common_questions qModle = null;
                        Model.common_answers   option = null;

                        foreach (DataRow item in dtOption.Rows)
                        {
                            qModle = qbll.GetModel(" group_id = " + group + " and title = '" + item[0].ToString() + "' ");
                            if (qModle != null)
                            {
                                option = obll.GetModel(" question_id = " + qModle.id + " and contents = '" + item[2].ToString() + "' ");
                                if (option == null)
                                {
                                    option             = new Model.common_answers();
                                    option.question_id = qModle.id;
                                    option.options     = item[1].ToString();
                                    option.contents    = item[2].ToString();
                                    option.score       = dtOption.Columns.Count > 3 ? Convert.ToInt32(item[3].ToString()) : 0;
                                    option.add_time    = System.DateTime.Now;

                                    obll.Add(option);
                                }
                                else
                                {
                                    option.options = item[1].ToString();
                                    option.score   = dtOption.Columns.Count > 3 ? Convert.ToInt32(item[3].ToString()) : 0;

                                    obll.Update(option);
                                }
                            }
                        }
                    }
                }
                return(dataTable);
            }
            catch (Exception)
            {
                if (fs != null)
                {
                    fs.Close();
                }
                return(null);
            }
        }