PageRenderTime 46ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/FlashCard/WindowsFormsApplication1/Tabs/Vocab.cs

https://bitbucket.org/floAr/personal
C# | 188 lines | 157 code | 31 blank | 0 comment | 10 complexity | 89560629231649b9508d6363d70659e8 MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using WMPLib;
  10. namespace FlashCard
  11. {
  12. public partial class Vocab : UserControl
  13. {
  14. private Deck<Word> wordDeck;
  15. private WindowsMediaPlayerClass player = new WindowsMediaPlayerClass();
  16. public Vocab()
  17. {
  18. InitializeComponent();
  19. }
  20. public void LoadDeck(Deck<Word> wordDeck)
  21. {
  22. this.wordDeck = wordDeck;
  23. this.englishLbl.Visible = false;
  24. this.englishSentenceLbl.Visible = false;
  25. this.noteLbl.Visible = false;
  26. this.NextWord();
  27. }
  28. public void incorrectBtn_Click(object sender, EventArgs e)
  29. {
  30. wordDeck.MarkIncorrect();
  31. this.NextWord();
  32. }
  33. public void correctBtn_Click(object sender, EventArgs e)
  34. {
  35. wordDeck.MarkCorrect();
  36. this.NextWord();
  37. }
  38. public void revealBtn_Click(object sender, EventArgs e)
  39. {
  40. this.englishLbl.Visible = this.kanaLbl.Visible;
  41. this.noteLbl.Visible = this.kanaLbl.Visible;
  42. this.englishSentenceLbl.Visible = this.kanaSentenceLbl.Visible;
  43. this.kanaLbl.Visible = true;
  44. this.kanaSentenceLbl.Visible = true;
  45. PlayCurrentSentence(null, null);
  46. }
  47. private void NextWord()
  48. {
  49. this.englishLbl.Visible = false;
  50. this.englishSentenceLbl.Visible = false;
  51. this.noteLbl.Visible = false;
  52. this.kanaLbl.Visible = false;
  53. this.kanaSentenceLbl.Visible = false;
  54. this.kanjiLbl.Visible = true;
  55. this.kanjiSentenceLbl.Visible = true;
  56. wordDeck.NextCard();
  57. this.RefreshPage();
  58. }
  59. public void RefreshPage()
  60. {
  61. if (wordDeck.CurrentCard != null)
  62. {
  63. this.currentWordPointLbl.Text = wordDeck.CurrentCard.Stats.Points.ToString();
  64. this.currentWordPointLbl.ForeColor = Color.Red;
  65. if (wordDeck.CurrentCard.Stats.Points >= wordDeck.PointCutOff)
  66. {
  67. if (wordDeck.CurrentCard.Stats.Points < 100)
  68. this.currentWordPointLbl.ForeColor = Color.Green;
  69. else
  70. this.currentWordPointLbl.ForeColor = Color.Blue;
  71. }
  72. this.englishLbl.Text = wordDeck.CurrentCard.EnglishWord;
  73. this.noteLbl.Text = wordDeck.CurrentCard.Note;
  74. this.kanaLbl.Text = wordDeck.CurrentCard.KanaWord;
  75. this.kanjiLbl.Text = wordDeck.CurrentCard.KanjiWord;
  76. this.englishSentenceLbl.Text = wordDeck.CurrentCard.EnglishSentence;
  77. this.kanaSentenceLbl.Text = wordDeck.CurrentCard.KanaSentence;
  78. this.kanjiSentenceLbl.Text = wordDeck.CurrentCard.KanjiSentence;
  79. if (string.IsNullOrEmpty(wordDeck.CurrentCard.KanjiWord))
  80. {
  81. this.kanaSentenceLbl.Visible = true;
  82. this.kanaLbl.Visible = true;
  83. }
  84. }
  85. int totalPoints = 0;
  86. List<Word> unknownWords = wordDeck.UnknownCards;
  87. foreach (Word word in unknownWords)
  88. {
  89. totalPoints += word.Stats.Points;
  90. }
  91. int wellKnownCount = 0;
  92. foreach (Word word in wordDeck.EnabledCards)
  93. {
  94. if (word.Stats.Points >= 100)
  95. wellKnownCount++;
  96. }
  97. this.currentProgressBar.Maximum = Math.Max(0, wordDeck.EnabledCards.Count * wordDeck.PointCutOff - wordDeck.PointBase);
  98. this.currentProgressBar.Value = Math.Max(0, wordDeck.CalculatePointBase() - wordDeck.PointBase);
  99. int unknownCount = unknownWords.Count;
  100. int knownCount = wordDeck.EnabledCards.Count - unknownCount;
  101. this.knownWordsLbl.Text = knownCount.ToString();
  102. this.unknownWordsLbl.Text = unknownCount.ToString();
  103. this.wellKnownLbl.Text = wellKnownCount.ToString();
  104. this.avgScoreLbl.Text = wordDeck.AveragePoints.ToString();
  105. this.totalProgressBar.Maximum = wordDeck.AllCards.Values.Count( w => wordDeck.EnabledCategories.Contains(w.Category));
  106. this.totalProgressBar.Value = knownCount;
  107. switch (wordDeck.ReviewMode)
  108. {
  109. case ReviewMode.On:
  110. this.reviewChkBox.CheckState = CheckState.Checked;
  111. break;
  112. case ReviewMode.Temporary:
  113. this.reviewChkBox.CheckState = CheckState.Indeterminate;
  114. break;
  115. case ReviewMode.Off:
  116. this.reviewChkBox.CheckState = CheckState.Unchecked;
  117. break;
  118. }
  119. }
  120. private void reviewChkBox_CheckedChanged(object sender, EventArgs e)
  121. {
  122. switch (reviewChkBox.CheckState)
  123. {
  124. case CheckState.Checked:
  125. wordDeck.ReviewMode = ReviewMode.On;
  126. break;
  127. case CheckState.Unchecked:
  128. wordDeck.ReviewMode = ReviewMode.Off;
  129. break;
  130. case CheckState.Indeterminate:
  131. break;
  132. }
  133. }
  134. private void reviewBtn_Click(object sender, EventArgs e)
  135. {
  136. wordDeck.ReviewCards(50);
  137. }
  138. private void PlayCurrentWord(object sender, EventArgs e)
  139. {
  140. if (!string.IsNullOrEmpty(wordDeck.CurrentCard.WordSound))
  141. {
  142. player.controls.stop();
  143. player.URL = wordDeck.CurrentCard.WordSound;
  144. player.controls.play();
  145. }
  146. }
  147. private void PlayCurrentSentence(object sender, EventArgs e)
  148. {
  149. if (!string.IsNullOrEmpty(wordDeck.CurrentCard.SentenceSound))
  150. {
  151. player.controls.stop();
  152. player.URL = wordDeck.CurrentCard.SentenceSound;
  153. player.controls.play();
  154. }
  155. }
  156. }
  157. }