예제 #1
0
        /// <summary>          
        /// 插入选择题信息
        /// </summary>
        /// <param name="s">选择题实体</param>
        public static int InsertSelectChoice(SelectChoiceInfo s)
        {
            ExamDbDataContext dc = DataAccess.CreateDBContext();

            dc.SelectChoiceInfo.InsertOnSubmit(s);
            
            dc.SubmitChanges();
           // PurgeCacheItems("AllSubjects_" + s.DepartmentID.ToString());
            return s.SelectChoiceID;
        }
예제 #2
0
        public static bool InsertQuestionsByExcleFile(string filePath)
        {
            ExamDbDataContext dc = DataAccess.CreateDBContext();

            string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filePath + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=1\"";
            if (filePath.EndsWith("xlsx")) strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filePath + ";Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=1\"";

            OleDbConnection myConn = new OleDbConnection(strConn);
            string strCom = " SELECT * FROM [Sheet1$]";
            OleDbCommand cmd = new OleDbCommand(strCom, myConn);
            OleDbDataReader dr = null;
            IList<QuestionInfo> questions = new List<QuestionInfo>();
            IList<ChoiceItemInfo> choiceitems = new List<ChoiceItemInfo>();
            try
            {
                myConn.Open();
                dr = cmd.ExecuteReader();
                while (dr.Read())//在此处逐条输入试题信息
                {
                    string questionTypeName = dr["题型"].ToString();

                    if (string.IsNullOrEmpty(questionTypeName)) continue;

                    QuestionInfo q = new QuestionInfo();
                    q.Title=dr["题目内容"].ToString();
                    q.RefAnswer=dr["参考答案"].ToString();
                    string sAnswers = ""; 

                    switch (questionTypeName)
                    {
                        case "选择":
                    
                    SelectChoiceInfo s = new SelectChoiceInfo();
                    s.Title = dr["题目内容"].ToString();
                    sAnswers = dr["参考答案"].ToString();
                    if (sAnswers.Length == 1) s.IsSingleSelect = true;
                    else s.IsSingleSelect = false;
                    s.ChoiceCount = 4;


                    s.CourseID = BLLBase.ReturnID(BLLBase.GetCourseDic(), dr["课程"].ToString());
                    s.ChapterID = BLLBase.ReturnID(BLLBase.GetChapterDic(), dr["章节"].ToString());

                   int choiceID= Choice.InsertSelectChoice(s);

                   string[] choiceNames = { "A", "B", "C", "D" };
                   for (int i = 0; i < 4; i++)
                   {
                      string m= choiceNames[i];
                       ChoiceItemInfo c = new ChoiceItemInfo();
                      c.Title= dr[m].ToString();
                      if (sAnswers.Contains(m))
                          c.IsRight = true;
                      else c.IsRight = false;
                      c.SelectChoiceID = choiceID;

                      choiceitems.Add(c);

                   }
                            break;

                        case "填空":

                            break;
                        case "判断":

                            break;
                        case "简答":

                            break;
                        case "程序填空":

                            break;
                    }


                }
            }
            catch (Exception e)
            {
                HttpContext.Current.Response.Write("错误信息:" + e.Message);
                return false;

            }
            finally
            {
                if (dr != null) dr.Close();
                myConn.Close();
                

            }
            
            if (questions == null) return false;
            dc.ChoiceItemInfo.InsertAllOnSubmit<ChoiceItemInfo>(choiceitems);
            dc.SubmitChanges();
            return true;
        }
예제 #3
0
        /// <summary>
        /// 将excel文件中的数据转换成选择题实体集合
        /// </summary>
        /// <param name="filePath">excel文件的物理路径</param>
        /// <returns></returns>
       private static IList<ChoiceItemInfo> ChangeExcelToChoices(string filePath)
        {

            IList<ChoiceItemInfo> choiceitems = new List<ChoiceItemInfo>();
            string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filePath + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=1\"";
            if (filePath.EndsWith("xlsx")) strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filePath + ";Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=1\"";

            OleDbConnection myConn = new OleDbConnection(strConn);
            string strCom = " SELECT * FROM [Sheet1$]";
            OleDbCommand cmd = new OleDbCommand(strCom, myConn);
            OleDbDataReader dr = null;
            try
            {
                myConn.Open();
                dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    //if(dr["姓名"]==null||dr["学号"]==null||dr["班级"]==null||dr["专业"]==null|| dr["家庭地址"]==null)
                    //   continue;
                    string sAnswers = "";                    
                    SelectChoiceInfo s = new SelectChoiceInfo();
                    s.Title=dr["题目"].ToString();
                    sAnswers = dr["答案"].ToString();
                    if (sAnswers.Length == 1) s.IsSingleSelect = true;
                    else s.IsSingleSelect = false;
                    s.ChoiceCount = 4;


                    s.CourseID = BLLBase.ReturnID(BLLBase.GetCourseDic(), dr["课程"].ToString());
                    s.ChapterID = BLLBase.ReturnID(BLLBase.GetChapterDic(), dr["章节"].ToString());

                   int choiceID= Choice.InsertSelectChoice(s);

                   string[] choiceNames = { "A", "B", "C", "D" };
                   for (int i = 0; i < 4; i++)
                   {
                      string m= choiceNames[i];
                       ChoiceItemInfo c = new ChoiceItemInfo();
                      c.Title= dr[m].ToString();
                      if (sAnswers.Contains(m))
                          c.IsRight = true;
                      else c.IsRight = false;
                      c.SelectChoiceID = choiceID;

                      choiceitems.Add(c);

                   }

  //   HttpContext.Current.Response.Write("一条记录<br>");

                }
            }
            catch (Exception e)
            {
                HttpContext.Current.Response.Write("错误信息:" + e.Message);
                choiceitems = null;

            }
            finally
            {
                if (dr != null) dr.Close();
                myConn.Close();

            } return choiceitems;
        }
예제 #4
0
 /// <summary>
 /// 删除选择题信息
 /// </summary>
 /// <param name="s">选择题实体</param>
 public static void DeleteSelectChoice(SelectChoiceInfo s, ExamDbDataContext dc)
 {
     AttachInfo<SelectChoiceInfo>(dc.SelectChoiceInfo, s);
     dc.SelectChoiceInfo.DeleteOnSubmit(s);
     dc.SubmitChanges();
 }
예제 #5
0
        /// <summary>
        /// 更新选择题信息
        /// </summary>
        /// <param name="s">选择题实体</param>
        public static void UpdateSelectChoice(SelectChoiceInfo s, ExamDbDataContext dc)
        {
            AttachInfo<SelectChoiceInfo>(dc.SelectChoiceInfo, s);
            dc.SubmitChanges();

           // PurgeCacheItems("AllSelectChoices_" + s.DepartmentID.ToString());
        }
예제 #6
0
        private static XElement GetChoice(ExamDbDataContext dc, int ChoiceID, SelectChoiceInfo s,string parentName)
        {
            XElement choice = new XElement(parentName);

            choice.SetAttributeValue("choiceID", s.SelectChoiceID);

            choice.SetAttributeValue("title", s.Title);

            var choices = dc.ChoiceItemInfo.Where(p => p.SelectChoiceID == ChoiceID).ToList<ChoiceItemInfo>();

            //如何打乱次序?
            IList<int> indexs = new List<int> { 0, 1, 2, 3 }; //假设都是只有四个选项。

            IList<int> items = Utility.GetRandomList(indexs, 4);//假设都是只有四个选项。

            IList<string> seqs = new List<string> { "A. ","B. ","C. ","D. " }; //假设都是只有四个选项。

            for(int i=0;i<4;i++)///如何加上A,B,C,D的序号
            {
                ChoiceItemInfo c = choices[items[i]];
                XElement choiceItem = new XElement("ChoiceItem");
                choiceItem.SetAttributeValue("choiceItemID",c.ChoiceItemID);
                choiceItem.SetAttributeValue("title",seqs[i]+c.Title);
                choiceItem.SetAttributeValue("isSelected", "false");
                choice.Add(choiceItem);
            }
            return choice;
        }
        protected void imgBtnSave_Click(object sender, ImageClickEventArgs e)
        {

         
                //再增加一题,判断题目是否完全相同。。 
                int answerNum = 0;

                foreach (ListItem l in chkListAnswer.Items)
                {
                    if (l.Selected) answerNum++;
                }
                //if (chkA.Checked) answerNum++;
                //if (chkB.Checked) answerNum++;
                //if (chkC.Checked) answerNum++;
                //if (chkD.Checked) answerNum++;

                if (answerNum == 0)
                {
                    this.ClientScript.RegisterStartupScript(this.GetType(), "Hint", "<script>alert('请设置答案')</script>");
                    return;
                }
            if (imgBtnSave.ToolTip == "添加")
            {
                SelectChoiceInfo s = new SelectChoiceInfo();

               s.Title = txtTitle.Text;

                if (answerNum > 1) s.IsSingleSelect = false;
                else s.IsSingleSelect = true;

                //s.RightAnswer = strAnswers;

                s.ChoiceCount = 4; //可根据输入的答案决定选项个数。

                int choiceID = Choice.InsertSelectChoice(s);

                IList<TextBox> tlist = GetTextBoxIntoList();

                InsertItemsOfChoice(choiceID, tlist);

                //InsertChoiceItem(choiceID, txtAnswerA.Text, chkA.Checked);
                //InsertChoiceItem(choiceID, txtAnswerB.Text, chkB.Checked);
                //InsertChoiceItem(choiceID, txtAnswerC.Text, chkC.Checked);
                //InsertChoiceItem(choiceID, txtAnswerD.Text, chkD.Checked);


            }

            else
            {
                int choiceId =int.Parse(hideChoiceID.Value);

                 Choice.UpdateSelectChoice(choiceId,txtTitle.Text,answerNum==1);//更新选择题目

                 IList<TextBox> tlist = GetTextBoxIntoList();
                 int i = 0;
                 foreach (TextBox t in tlist)
                 {
                    
                     int cItemID = int.Parse(t.ToolTip); 
                     ChoiceItemInfo cItem = ChoiceItem.GetChoiceItemByID(cItemID);
                     //cItem.ChoiceItemID = cItemID;
                     cItem.Title = t.Text;
                     cItem.IsRight = chkListAnswer.Items[i].Selected;
                     ChoiceItem.UpdateChoiceItemByCopy(cItem);
                     i++;
                 }
            
            }



            ClearControl();
            this.ClientScript.RegisterStartupScript(this.GetType(), "Hint", "<script>alert('成功保存数据')</script>");



        }
예제 #8
0
		private void detach_SelectChoiceInfo(SelectChoiceInfo entity)
		{
			this.SendPropertyChanging();
			entity.CourseInfo = null;
		}
예제 #9
0
		private void attach_SelectChoiceInfo(SelectChoiceInfo entity)
		{
			this.SendPropertyChanging();
			entity.ChapterInfo = this;
		}