Ejemplo n.º 1
0
        public void LoadQuestions(string directoryName)
        {
            directory = directoryName;

            questionData.Clear();
            questions.Clear();

            if (File.Exists(QuestionDataFileName))
            {
                string[] input = File.ReadAllLines(QuestionDataFileName, new UTF8Encoding(true));
                quizTitle = input[0];
                for (int i = 1; i < input.Length; ++i)
                {
                    string   line   = input[i];
                    string[] fields = line.Split('\t');
                    if (fields.Length >= 5)
                    {
                        QuestionData qd = new QuestionData();
                        qd.Id = fields[0];
                        qd.ChineseImageFileName = fields[1];
                        qd.ChineseText          = fields[2];
                        qd.EnglishText          = fields[3];
                        qd.SoundFileName        = fields[4];
                        questionData.Add(qd);
                    }
                }
            }
            else
            {
                quizTitle = Path.GetFileName(directoryName);
            }
        }
Ejemplo n.º 2
0
        public void LoadAnswers(TermKind from, TermKind to)
        {
            FromTerm = from;
            ToTerm   = to;

            questions.Clear();
            string[] input = new string[0];

            if (File.Exists(AnswerDataFileName))
            {
                input = File.ReadAllLines(AnswerDataFileName);
            }

            for (int i = 0; i < questionData.Count; ++i)
            {
                QuestionData qd = questionData[i];
                Question     q  = new Question();

                GetQuestionAnswerData(from, qd, out q.QuestionStyle, out q.QuestionString);
                GetQuestionAnswerData(to, qd, out q.AnswerStyle, out q.AnswerString);

                if (i < input.Length)
                {
                    q.LoadAnswers(input[i]);
                }

                questions.Add(q);
            }
        }
Ejemplo n.º 3
0
 void GetQuestionAnswerData(TermKind termKind, QuestionData qd, out TermStyle termStyle, out string termString)
 {
     if (termKind == TermKind.ChineseCharacter)
     {
         if (string.IsNullOrWhiteSpace(qd.ChineseImageFileName))
         {
             termStyle  = TermStyle.Text;
             termString = qd.ChineseText;
         }
         else
         {
             termStyle  = TermStyle.Picture;
             termString = Path.Combine(directory, qd.ChineseImageFileName);
         }
     }
     else if (termKind == TermKind.ChineseSound)
     {
         termStyle  = TermStyle.Sound;
         termString = Path.Combine(directory, qd.SoundFileName);
     }
     else if (termKind == TermKind.EnglishWord)
     {
         termStyle  = TermStyle.Text;
         termString = qd.EnglishText;
     }
     else
     {
         throw new ArgumentException("termKind");
     }
 }
Ejemplo n.º 4
0
 void LoadQuestionData(QuestionData qd)
 {
     textBoxId.Text = qd.Id;
     textBoxChineseImageFileName.Text = qd.ChineseImageFileName;
     textBoxChineseText.Text          = qd.ChineseText;
     textBoxEnglishText.Text          = qd.EnglishText;
     textBoxSoundFileName.Text        = qd.SoundFileName;
 }
Ejemplo n.º 5
0
 public void ReplaceQuestion(int index, QuestionData qd)
 {
     if (index == questionData.Count)
     {
         questionData.Add(qd);
     }
     else
     {
         questionData[index] = qd;
     }
 }
Ejemplo n.º 6
0
        void UpdateQuestion()
        {
            if (questionNumber >= 0)
            {
                QuestionData qd = new QuestionData();
                qd.Id = textBoxId.Text;
                qd.ChineseImageFileName = textBoxChineseImageFileName.Text;
                qd.ChineseText          = textBoxChineseText.Text;
                qd.EnglishText          = textBoxEnglishText.Text;
                qd.SoundFileName        = textBoxSoundFileName.Text;

                quiz.ReplaceQuestion(questionNumber, qd);
            }
        }
Ejemplo n.º 7
0
 public void AddQuestion(QuestionData qd)
 {
     questionData.Add(qd);
 }
Ejemplo n.º 8
0
 void GetQuestionAnswerData(TermKind termKind, QuestionData qd, out TermStyle termStyle, out string termString)
 {
     if (termKind == TermKind.ChineseCharacter) {
         if (string.IsNullOrWhiteSpace(qd.ChineseImageFileName)) {
             termStyle = TermStyle.Text;
             termString = qd.ChineseText;
         }
         else {
             termStyle = TermStyle.Picture;
             termString = Path.Combine(directory, qd.ChineseImageFileName);
         }
     }
     else if (termKind == TermKind.ChineseSound) {
         termStyle = TermStyle.Sound;
         termString = Path.Combine(directory, qd.SoundFileName);
     }
     else if (termKind == TermKind.EnglishWord) {
         termStyle = TermStyle.Text;
         termString = qd.EnglishText;
     }
     else {
         throw new ArgumentException("termKind");
     }
 }
Ejemplo n.º 9
0
 public void ReplaceQuestion(int index, QuestionData qd)
 {
     if (index == questionData.Count)
         questionData.Add(qd);
     else
         questionData[index] = qd;
 }
Ejemplo n.º 10
0
        public void LoadQuestions(string directoryName)
        {
            directory = directoryName;

            questionData.Clear();
            questions.Clear();

            if (File.Exists(QuestionDataFileName)) {
                string[] input = File.ReadAllLines(QuestionDataFileName, new UTF8Encoding(true));
                quizTitle = input[0];
                for (int i = 1; i < input.Length; ++i) {
                    string line = input[i];
                    string[] fields = line.Split('\t');
                    if (fields.Length >= 5) {
                        QuestionData qd = new QuestionData();
                        qd.Id = fields[0];
                        qd.ChineseImageFileName = fields[1];
                        qd.ChineseText = fields[2];
                        qd.EnglishText = fields[3];
                        qd.SoundFileName = fields[4];
                        questionData.Add(qd);
                    }
                }
            }
            else {
                quizTitle = Path.GetFileName(directoryName);
            }
        }
Ejemplo n.º 11
0
 void LoadQuestionData(QuestionData qd)
 {
     textBoxId.Text = qd.Id;
     textBoxChineseImageFileName.Text = qd.ChineseImageFileName;
     textBoxChineseText.Text = qd.ChineseText;
     textBoxEnglishText.Text = qd.EnglishText;
     textBoxSoundFileName.Text = qd.SoundFileName;
 }
Ejemplo n.º 12
0
        void UpdateQuestion()
        {
            if (questionNumber >= 0) {
                QuestionData qd = new QuestionData();
                qd.Id = textBoxId.Text;
                qd.ChineseImageFileName = textBoxChineseImageFileName.Text;
                qd.ChineseText = textBoxChineseText.Text;
                qd.EnglishText = textBoxEnglishText.Text;
                qd.SoundFileName = textBoxSoundFileName.Text;

                quiz.ReplaceQuestion(questionNumber, qd);
            }
        }
Ejemplo n.º 13
0
 public void AddQuestion(QuestionData qd)
 {
     questionData.Add(qd);
 }