Exemplo n.º 1
0
        public void LoadExamPaper(BaobaoBook book)
        {
            ExamPaper paper = null;

            AnswerList.Clear();
            QuestionList.Clear();
            if (book != null)
            {
                if (!_books.ContainsKey(book) || _books[book] == null)
                {
                    string examPaper = book.Name;
                    paper = FileSettingsHelper <ExamPaper> .LoadSetting(Path.Combine(ZibaobaoLibContext.Instance.PersistentStorage.DataPath, examPaper));

                    _books[book] = paper;
                }
                else
                {
                    paper = _books[book];
                }
            }
            if (paper != null)
            {
                foreach (var question in paper.Questions)
                {
                    QuestionList.Add(question);
                }

                if (QuestionList.Count > 0)
                {
                    _currentQuestionIndex = -1;
                    CurrentQuestionIndex  = 0;
                }
            }
        }
        // Save questionlist
        public void SaveQuestionList()
        {
            var item = SelectedQuestionList.Id == 0 ? null : _sfestival.QuestionLists.Single(i => i.Id == SelectedQuestionList.Id);

            if (item == null)
            {
                try
                {
                    _sfestival.QuestionLists.Add(SelectedQuestionList.ToQuestionList());
                    QuestionList.Add(SelectedQuestionList);
                    SwitchView = 0;
                    DBContext.Instance.SaveChanges();
                }
                catch (DbEntityValidationException dbEx)
                {
                    foreach (var validationErrors in dbEx.EntityValidationErrors)
                    {
                        foreach (var validationError in validationErrors.ValidationErrors)
                        {
                            Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage);
                        }
                    }
                }
            }
            else
            {
                DBContext.Instance.SaveChanges();
                SwitchView = 0;
            }
        }
Exemplo n.º 3
0
        private void AddQuestion()
        {
            Question q = new Question(_catagory, _query, _answers.ToList(), _correctAnswer);

            QuestionList.Add(q);
            ResetForm();
        }
Exemplo n.º 4
0
 private void RefreshListOfExaminationItems()
 {
     foreach (var item in _testController.GetCurrentListOfExaminationItems())
     {
         QuestionList.Add(new ExaminationItemViewModel(item));
     }
 }
 private void SaveParsedWords(VocabularyRecord[] items)
 {
     foreach (var item in items)
     {
         if (!QuestionList.Any(q => string.Compare(q.ForeignText, item.ForeignText, true) == 0))
         {
             QuestionList.Add(new VocabularyRecordViewModel(item));
         }
     }
     SaveCommand.Execute(null);
 }
Exemplo n.º 6
0
        public void AddQuestAnswers()
        {
            QnA_Model newQuestionAdd = new QnA_Model {
                Question = Question, Difficulty = Difficulty, Answer = Answer
            };

            QuestionList.Add(newQuestionAdd);



            // string filepath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "temp.txt");
            //// newQuestionAdd = newQuestionAdd;
            // XmlSerializer serializer  = new XmlSerializer(typeof(List<QnA_Model>));
            // Stream writer = new FileStream(filepath, FileMode.Create); // Initialises the writer

            // serializer.Serialize(writer, Question); // Writes to the file
            // writer.Close();
            // now you can elete under me



            int indexOfAddedQuestion = QuestionList.IndexOf(newQuestionAdd);

            QuestionList.Move(indexOfAddedQuestion, 0);

            //QnA_Model qmodel = new QnA_Model();
            //  qmodel.Question = Question;
            System.Xml.Serialization.XmlSerializer xmlwriter = new System.Xml.Serialization.XmlSerializer(typeof(QnA_Model));
            var paths = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "//topicstore.txt";

            System.IO.FileStream file = System.IO.File.Create(paths);

            xmlwriter.Serialize(file, newQuestionAdd);
            file.Close();



            System.Xml.Serialization.XmlSerializer reader =
                new System.Xml.Serialization.XmlSerializer(typeof(QnA_Model));
            System.IO.StreamReader fileRead = new System.IO.StreamReader(paths);
            QnA_Model qmodels = (QnA_Model)reader.Deserialize(file);

            file.Close();



            //string fileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "temp.txt");



            //  File.WriteAllText(fileName, Question + Difficulty + Answer);
        }
        private void PlayAnswerSound(bool isCorrect)
        {
            var number = QuestionList.Count + 1;

            QuestionList.Add(number, isCorrect);
            if (isCorrect)
            {
                _correct.Play();
            }
            else
            {
                _incorrect.Play();
            }
        }
        private void AddCommandHandler()
        {
            var question = new VocabularyRecord()
            {
                ShowDateStart = DateTime.Now.Date, ShowDateEnd = DateTime.Now.Date.AddDays(3)
            };
            var vm = new VocabularyItemDialogViewModel(
                (item) => { QuestionList.Add(new VocabularyRecordViewModel(item)); SaveCommand.Execute(null); }
                );

            vm.Question = question;
            dialogService.ShowDialog(vm, false, "modalDialog");
            RaiseCanExecuteChanged();
        }
Exemplo n.º 9
0
        public void LoadQuestionList(DifficultyType type)
        {
            QuestionList.Clear();

            String file = String.Format("{0}{1}/{2}/{3}/{4}.txt", questionRoot, Constants.CONTENT_DIRECTORY, Constants.DATA_DIRECTORY,
                                        Constants.LEVELS_DIRECTORY, type);

            var lines = MyGame.Manager.FileManager.LoadTxt(file);

            foreach (String line in lines)
            {
                Question question = LoadQuestion(line);
                QuestionList.Add(question);
            }
        }
Exemplo n.º 10
0
        internal static QuestionList DataTableToTitleList(DataTable Dt)
        {
            QuestionList questions = new QuestionList();

            try
            {
                foreach (DataRow item in Dt.Rows)
                {
                    questions.Add(DataRowToTitle(item));
                }
            }
            catch
            {
            }
            return(questions);
        }
Exemplo n.º 11
0
        private void GoNext()
        {
            if (QuestionList.Count > 0)
            {
                QuestionList [QuestionList.Count - 1].AnsweredCmd = null;
            }
            if (QuestionList.Count == _RawAssessmentList.Count)
            {
                DoAnswer();
                foreach (IAssessmentItemData data in QuestionList)
                {
                    ((AssessmentViewModel)data).IsDone = true;
                }
            }
            else
            {
                AssessmentViewModel nextQuestion = _RawAssessmentList [QuestionList.Count];
                if (nextQuestion.QuestionType == 0)                  // fill in the blanks

                {
                    foreach (var ques in _RawAssessmentList)
                    {
                        if (ques.QuestionType == 0)
                        {
                            ques.IsDone = true;
                            if (string.IsNullOrEmpty(ques.Answer))
                            {
                                QuestionList.Add(ques);
                            }
                        }
                    }
                    SelectedItem = QuestionList [QuestionList.Count - 1];
                    RaisePropertyChanged(() => QuestionList);
                }
                else
                {
                    nextQuestion.AnsweredCmd = new RelayCommand(() => {                     // multichoice question
                        GoNext();
                    });
                    QuestionList.Add(nextQuestion);
                    RaisePropertyChanged(() => QuestionList);
                    SelectedItem = QuestionList [QuestionList.Count - 1];
                }
            }
        }
Exemplo n.º 12
0
        public async void EditQuestion()
        {
            int indexOfNewQuestion = QuestionList.IndexOf(SelectedQuestion);

            QuestionList.Remove(SelectedQuestion);
            QnA_Model newQuestionEdit = new QnA_Model {
                Question = Question, Difficulty = Difficulty, Answer = Answer
            };

            QuestionList.Add(newQuestionEdit);
            int indexOfDeletedQuestion = QuestionList.IndexOf(newQuestionEdit);

            if (indexOfNewQuestion >= 0)
            {
                QuestionList.Move(indexOfDeletedQuestion, indexOfNewQuestion);
            }
            else
            {
                await App.Current.MainPage.DisplayAlert("No Flashcard Selected", "You must select a flashcard to edit!", "Gotcha!");
            }
        }
Exemplo n.º 13
0
        public SimpleExaminationViewModel(BaseScene scene, String json) : base(scene, json)
        {
            CanAnalysis = true;
            init();
            JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer();
            var response = javaScriptSerializer.Deserialize <SimpleExaminationScene>(json);

            examination = response.Convert();
            if (examination.ExaminationQuestions != null)
            {
                foreach (var v in examination.ExaminationQuestions)
                {
                    QuestionVM vm = new QuestionVM();
                    vm.Set(v);
                    QuestionList.Add(vm);
                    TotalScore += v.Score;
                }
            }
            if (examination.Voters != null)
            {
                foreach (var v in examination.Voters)
                {
                    StudentVM studentNM = new StudentVM();
                    studentNM.Set(v);
                    StudentList.Add(studentNM);
                }
            }
            if (response.RegionScenes != null)
            {
                RegionList.Clear();
                foreach (var v in response.RegionScenes)
                {
                    RegionList.Add(v.convert());
                }
            }
        }
Exemplo n.º 14
0
        public void Load(QuestionList list)
        {
            _list = list;
            _list.Clear();

            FileStream FileToLoad = new FileStream(@_path, FileMode.Open, FileAccess.Read);
            StreamReader Reader = new StreamReader(FileToLoad, System.Text.Encoding.Default);

            Question tmp = new Question();

            for (int i = 0; i < 15; i++)
            {
                tmp = new Question();
                tmp.Question_ = Reader.ReadLine();

                for (int j = 0; j < 4; j++)
                    tmp.Set_Answer(j, Reader.ReadLine());

                _list.Add(tmp);
            }

            Reader.Close();
            FileToLoad.Close();
        }
Exemplo n.º 15
0
        private void Import()
        {
            OpenFileDialog dialog = new OpenFileDialog();

            dialog.DefaultExt = ".xls";                                              // Default file extension
            dialog.Filter     = "Excel 2003 文档|*.xls|Excel 2007 文档|*.xlsx|所有文件|*.*"; // Filter files by extension
            if (dialog.ShowDialog() == true)
            {
                string filename = dialog.FileName;

                string fileType = Path.GetExtension(filename).ToLower();
                try
                {
                    ISheet     sheet       = null;
                    int        sheetNumber = 0;
                    FileStream fs          = new FileStream(filename, FileMode.Open, FileAccess.Read);
                    if (fileType == ".xlsx")
                    {
                        // 2007版本
                        XSSFWorkbook workbook = new XSSFWorkbook(fs);
                        sheet = workbook.GetSheetAt(0);
                        if (sheet != null)
                        {
                            QuestionList.Clear();
                            int count = sheet.LastRowNum;
                            for (int i = 1; i <= count; i++)
                            {
                                QuestionList.Add(new Question()
                                {
                                    Answer  = sheet.GetRow(i).GetCell(1).ToString(),
                                    Subject = sheet.GetRow(i).GetCell(0).ToString()
                                });
                            }
                            RandCount = SumCount = QuestionList.Count;
                        }
                    }
                    else if (fileType == ".xls")
                    {
                        // 2003版本
                        HSSFWorkbook workbook = new HSSFWorkbook(fs);
                        sheetNumber = workbook.NumberOfSheets;
                        sheet       = workbook.GetSheetAt(0);
                        if (sheet != null)
                        {
                            QuestionList.Clear();
                            int count = sheet.LastRowNum;
                            for (int i = 1; i <= count; i++)
                            {
                                QuestionList.Add(new Question()
                                {
                                    Answer  = sheet.GetRow(i).GetCell(1).ToString(),
                                    Subject = sheet.GetRow(i).GetCell(0).ToString()
                                });
                            }
                            RandCount = SumCount = QuestionList.Count;
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Exemplo n.º 16
0
 /// <summary>
 /// Adds a question to the list.
 /// </summary>
 /// <param name="question">The question to add.</param>
 public void Add(Question question)
 {
     QuestionList.Add(question);
 }
Exemplo n.º 17
0
        public void Load(QuestionList list)
        {
            _list = list;
            _list.Clear();

            Question tmp;

            string QuestExpression = "SELECT * from mainTable";

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                  connection.Open();

                  SqlCommand command = new SqlCommand(QuestExpression, connection);
                  SqlDataReader reader = command.ExecuteReader();

                  if (reader.HasRows)
                  {
                      while (reader.Read())
                      {
                          tmp = new Question();
                          tmp.Question_ = reader.GetString(1);
                          tmp.Set_Answers(reader.GetString(2), reader.GetString(3), reader.GetString(4), reader.GetString(5));
                          list.Add(tmp);
                      }
                  }
            }
        }
Exemplo n.º 18
0
        private void BtnSave_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                int result;

                //Check whether adding a new question or updating a question
                switch (editMode)
                {
                /////////////////Editing a question/answer
                case EditMode.Update:
                    //Check if question of answer
                    if (txtText.Text != String.Empty)
                    {
                        switch (qaMode)
                        {
                        case QAMode.Answer:
                            Answer answer = answers.ElementAt(cboQorAs.SelectedIndex);
                            answer.Text = txtText.Text;
                            result      = answer.Update();
                            if (result > 0)
                            {
                                lblStatus.Content = "Updated Answer: " + answer.Text;
                            }
                            else
                            {
                                throw new Exception("Answer not updated");
                            }


                            break;

                        case QAMode.Question:
                            Question question = questions.ElementAt(cboQorAs.SelectedIndex);
                            question.Text = txtText.Text;
                            result        = question.UpdateQuestion();
                            if (result > 0)
                            {
                                lblStatus.Content = "Updated Question: " + question.Text;
                            }
                            else
                            {
                                throw new Exception("Question not updated");
                            }

                            break;

                        default:
                            break;
                        }
                    }
                    else
                    {
                        throw new Exception("Did you mean to delete this " + qaMode.ToString() + "? Please use the delete button instead.");
                    }

                    rebindComboBox(qaMode);
                    break;



                ////////////////////////Adding a question/answer
                case EditMode.Add:
                    //Check if question of answer
                    if (txtText.Text != String.Empty)
                    {
                        switch (qaMode)
                        {
                        case QAMode.Answer:
                            //Create a new answer and put it in the database
                            Answer answer = new Answer();
                            answer.Text = txtText.Text;
                            answers.Add(answer);
                            result = answer.Insert();

                            //Update the label with success or failure message
                            if (result > 0)
                            {
                                lblStatus.Content = "Added Answer: " + answer.Text;
                            }
                            else
                            {
                                throw new Exception("Answer not inserted");
                            }


                            break;

                        case QAMode.Question:
                            //Create question and add to the DB
                            Question question = new Question();
                            question.Text = txtText.Text;
                            questions.Add(question);
                            result = question.InsertQuestion();
                            //Show result on screen
                            if (result > 0)
                            {
                                lblStatus.Content = "Added Question: " + question.Text;
                            }
                            else
                            {
                                throw new Exception("Question not inserted");
                            }

                            break;

                        default:
                            break;
                        }

                        //Clear the entered text
                        txtText.Text = String.Empty;
                    }
                    else
                    {
                        throw new Exception("You must enter a value to add");
                    }
                    break;

                default:
                    break;
                }

                //Rebind the combobox
                rebindComboBox(qaMode);
            }
            catch (Exception ex)
            {
                lblStatus.Content = ex.Message;
            }
        }