/FlashCard/WindowsFormsApplication1/Tabs/Vocab.cs
C# | 188 lines | 157 code | 31 blank | 0 comment | 10 complexity | 89560629231649b9508d6363d70659e8 MD5 | raw file
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Drawing;
- using System.Data;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using WMPLib;
-
- namespace FlashCard
- {
- public partial class Vocab : UserControl
- {
- private Deck<Word> wordDeck;
- private WindowsMediaPlayerClass player = new WindowsMediaPlayerClass();
-
- public Vocab()
- {
- InitializeComponent();
- }
-
- public void LoadDeck(Deck<Word> wordDeck)
- {
- this.wordDeck = wordDeck;
-
- this.englishLbl.Visible = false;
- this.englishSentenceLbl.Visible = false;
- this.noteLbl.Visible = false;
-
- this.NextWord();
- }
-
- public void incorrectBtn_Click(object sender, EventArgs e)
- {
- wordDeck.MarkIncorrect();
-
- this.NextWord();
- }
-
- public void correctBtn_Click(object sender, EventArgs e)
- {
- wordDeck.MarkCorrect();
-
- this.NextWord();
- }
-
- public void revealBtn_Click(object sender, EventArgs e)
- {
- this.englishLbl.Visible = this.kanaLbl.Visible;
- this.noteLbl.Visible = this.kanaLbl.Visible;
- this.englishSentenceLbl.Visible = this.kanaSentenceLbl.Visible;
- this.kanaLbl.Visible = true;
- this.kanaSentenceLbl.Visible = true;
-
- PlayCurrentSentence(null, null);
- }
-
- private void NextWord()
- {
- this.englishLbl.Visible = false;
- this.englishSentenceLbl.Visible = false;
- this.noteLbl.Visible = false;
- this.kanaLbl.Visible = false;
- this.kanaSentenceLbl.Visible = false;
- this.kanjiLbl.Visible = true;
- this.kanjiSentenceLbl.Visible = true;
-
- wordDeck.NextCard();
-
- this.RefreshPage();
- }
-
- public void RefreshPage()
- {
- if (wordDeck.CurrentCard != null)
- {
- this.currentWordPointLbl.Text = wordDeck.CurrentCard.Stats.Points.ToString();
- this.currentWordPointLbl.ForeColor = Color.Red;
- if (wordDeck.CurrentCard.Stats.Points >= wordDeck.PointCutOff)
- {
- if (wordDeck.CurrentCard.Stats.Points < 100)
- this.currentWordPointLbl.ForeColor = Color.Green;
- else
- this.currentWordPointLbl.ForeColor = Color.Blue;
- }
-
- this.englishLbl.Text = wordDeck.CurrentCard.EnglishWord;
- this.noteLbl.Text = wordDeck.CurrentCard.Note;
- this.kanaLbl.Text = wordDeck.CurrentCard.KanaWord;
- this.kanjiLbl.Text = wordDeck.CurrentCard.KanjiWord;
-
- this.englishSentenceLbl.Text = wordDeck.CurrentCard.EnglishSentence;
- this.kanaSentenceLbl.Text = wordDeck.CurrentCard.KanaSentence;
- this.kanjiSentenceLbl.Text = wordDeck.CurrentCard.KanjiSentence;
-
- if (string.IsNullOrEmpty(wordDeck.CurrentCard.KanjiWord))
- {
- this.kanaSentenceLbl.Visible = true;
- this.kanaLbl.Visible = true;
- }
- }
-
- int totalPoints = 0;
-
- List<Word> unknownWords = wordDeck.UnknownCards;
- foreach (Word word in unknownWords)
- {
- totalPoints += word.Stats.Points;
- }
-
- int wellKnownCount = 0;
- foreach (Word word in wordDeck.EnabledCards)
- {
- if (word.Stats.Points >= 100)
- wellKnownCount++;
- }
-
- this.currentProgressBar.Maximum = Math.Max(0, wordDeck.EnabledCards.Count * wordDeck.PointCutOff - wordDeck.PointBase);
- this.currentProgressBar.Value = Math.Max(0, wordDeck.CalculatePointBase() - wordDeck.PointBase);
-
- int unknownCount = unknownWords.Count;
- int knownCount = wordDeck.EnabledCards.Count - unknownCount;
-
- this.knownWordsLbl.Text = knownCount.ToString();
- this.unknownWordsLbl.Text = unknownCount.ToString();
- this.wellKnownLbl.Text = wellKnownCount.ToString();
- this.avgScoreLbl.Text = wordDeck.AveragePoints.ToString();
-
- this.totalProgressBar.Maximum = wordDeck.AllCards.Values.Count( w => wordDeck.EnabledCategories.Contains(w.Category));
- this.totalProgressBar.Value = knownCount;
-
- switch (wordDeck.ReviewMode)
- {
- case ReviewMode.On:
- this.reviewChkBox.CheckState = CheckState.Checked;
- break;
- case ReviewMode.Temporary:
- this.reviewChkBox.CheckState = CheckState.Indeterminate;
- break;
- case ReviewMode.Off:
- this.reviewChkBox.CheckState = CheckState.Unchecked;
- break;
-
- }
- }
-
- private void reviewChkBox_CheckedChanged(object sender, EventArgs e)
- {
- switch (reviewChkBox.CheckState)
- {
- case CheckState.Checked:
- wordDeck.ReviewMode = ReviewMode.On;
- break;
- case CheckState.Unchecked:
- wordDeck.ReviewMode = ReviewMode.Off;
- break;
- case CheckState.Indeterminate:
- break;
- }
- }
-
- private void reviewBtn_Click(object sender, EventArgs e)
- {
- wordDeck.ReviewCards(50);
- }
-
- private void PlayCurrentWord(object sender, EventArgs e)
- {
- if (!string.IsNullOrEmpty(wordDeck.CurrentCard.WordSound))
- {
- player.controls.stop();
- player.URL = wordDeck.CurrentCard.WordSound;
- player.controls.play();
- }
- }
-
- private void PlayCurrentSentence(object sender, EventArgs e)
- {
- if (!string.IsNullOrEmpty(wordDeck.CurrentCard.SentenceSound))
- {
- player.controls.stop();
- player.URL = wordDeck.CurrentCard.SentenceSound;
- player.controls.play();
- }
- }
- }
- }