Example #1
0
 public List<ExamEntity> getAllExam()
 {
     List<ExamEntity> list = new List<ExamEntity>();
     OdbcCommand command = new OdbcCommand("select * from examination order by id desc", connection);
     command.Prepare();
     OdbcDataReader reader =  command.ExecuteReader();
     while (reader.Read())
     {
         ExamEntity exam = new ExamEntity();
         exam.id = reader.GetInt32(0);
         exam.time = reader.GetInt32(1);
         exam.sNumber = reader.GetInt32(2);
         exam.mNumber = reader.GetInt32(3);
         exam.tNumber = reader.GetInt32(4);
         exam.sScore = reader.GetFloat(5);
         exam.mScore = reader.GetFloat(6);
         exam.tScore = reader.GetFloat(7);
         exam.ready = reader.GetInt32(8);
         exam.name = reader.GetString(9);
         list.Add(exam);
     }
     return list;
 }
Example #2
0
        public ExamEntity getExamById(int id) 
        {
            var cmd = buildCommand("select * from examination where id =? limit 1");
            cmd.AddIntParam("id", id);
            var reader = cmd.ExecuteReader();
            if (!reader.HasRows)
            {
                return null;
            }
            reader.Read();
            ExamEntity exam = new ExamEntity();
            exam.id = reader.GetInt32(0);
            exam.time = reader.GetInt32(1);
            exam.sNumber = reader.GetInt32(2);
            exam.mNumber = reader.GetInt32(3);
            exam.tNumber = reader.GetInt32(4);
            exam.sScore = reader.GetFloat(5);
            exam.mScore = reader.GetFloat(6);
            exam.tScore = reader.GetFloat(7);
            exam.ready = reader.GetInt32(8);
            exam.name = reader.GetString(9);
            return exam;

        }
Example #3
0
        public ExamEntity praseFromDoc(String filePath)
        {
            ExamEntity exam = new ExamEntity();
            Document doc = new Document(filePath);
            QuestionEntity currentQuestion=null;
            foreach(Section section in doc.Sections)
            {
                foreach(Paragraph paragraph in section.Paragraphs)
                {
                    var text = paragraph.Text.Trim();

                    
                    if(text.StartsWith("##"))//Configration
                    {
                        var list = text.Substring(3, text.Length - 4).Split(':');
                        if(list[0] == "time")
                        {
                            exam.time = int.Parse(list[1]);
                        }
                        else if(list[0] == "TF")
                        {
                            exam.tNumber = int.Parse(list[1]);
                            exam.tScore  = float.Parse(list[2]);
                        }
                        else if (list[0] == "SC")
                        {
                            exam.sNumber = int.Parse(list[1]);
                            exam.sScore  = float.Parse(list[2]);
                        }
                        else if (list[0] == "MC")
                        {
                            exam.mNumber = int.Parse(list[1]);
                            exam.mScore  = float.Parse(list[2]);
                        }
                    }
                    else if(text.StartsWith("$$"))//Start of a question 
                    {
                        var list = text.Substring(3, text.Length - 4).Split(':');
                        string problemType = list[0];
                        string ans = list[2];
                        currentQuestion = new QuestionEntity();
                        currentQuestion.type = problemType;
                        currentQuestion.ans = ans;
                        
                    }
                    else if(text.Length==0) //End of a question
                    {
                        DocPicture pic = null;
                        foreach (DocumentObject docObject in paragraph.ChildObjects)
                        {
                            if (docObject.DocumentObjectType == DocumentObjectType.Picture)
                            {
                                pic = docObject as DocPicture;
                            }
                        }
                        if(pic != null ) // a line with picture but no text
                        {
                            currentQuestion.image = pic.Image;
                        }
                        else // end of a question
                        {
                            if (currentQuestion != null)
                            {
                                if (currentQuestion.type.Equals("TF"))
                                {
                                    exam.tf.Add(currentQuestion);
                                }
                                else if (currentQuestion.type.Equals("SC"))
                                {
                                    exam.sc.Add(currentQuestion);
                                }
                                else// MC
                                {
                                    exam.mc.Add(currentQuestion);
                                }
                            }
                            currentQuestion = null;
                        }
                        
                    }
                    else 
                    {
                        if( currentQuestion.type=="TF")
                        {
                            
                            foreach (DocumentObject docObject in paragraph.ChildObjects)
                            {
                                
                                if (docObject.DocumentObjectType == DocumentObjectType.TextRange)
                                {
                                    TextRange info = docObject as TextRange;
                                    
                                    currentQuestion.statement += info.Text;
                                }
                                else if(docObject.DocumentObjectType == DocumentObjectType.Picture)
                                {
                                    DocPicture picture = docObject as DocPicture;
                                    
                                    currentQuestion.image = picture.Image;
                                }
                            }
                        }
                        else// SC && MC
                        {
                            if (text.StartsWith("A:") && text.Split(';').Length >=4) //at least 4 choices
                            {
                                var choiceList = text.Split(';');
                                currentQuestion.choices.AddRange(choiceList);
                            }
                            else
                            {
                                foreach (DocumentObject docObject in paragraph.ChildObjects)
                                {
                                    if (docObject.DocumentObjectType == DocumentObjectType.TextRange)
                                    {
                                        var info = (docObject as TextRange).Text;


                                        currentQuestion.statement += info;


                                    }
                                    else if (docObject.DocumentObjectType == DocumentObjectType.Picture)
                                    {
                                        DocPicture picture = docObject as DocPicture;
                                        currentQuestion.image = picture.Image;
                                    }
                                }
                            }
                            
                        }
                    }
                }

            }
            return exam;
        }