PageRenderTime 52ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/FlashCard/WindowsFormsApplication1/Form1.cs

https://bitbucket.org/floAr/personal
C# | 144 lines | 128 code | 16 blank | 0 comment | 24 complexity | fd0675dede3703dabb0f7d96c2155df7 MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Collections;
  10. using System.IO;
  11. using System.Xml;
  12. using System.Globalization;
  13. using System.Diagnostics;
  14. namespace FlashCard
  15. {
  16. public partial class Form1 : Form
  17. {
  18. private const string WordDeckFileName = "FlashCard\\WordDeck.xml";
  19. private const string KanjiDeckFileName = "FlashCard\\KanjiDeck.xml";
  20. private readonly string[] WordCardFiles = new string[]
  21. {
  22. "Data\\WordData.xml",
  23. };
  24. private readonly string[] KanjiCardFiles = new string[]
  25. {
  26. "Data\\KanjiData.xml",
  27. };
  28. private readonly Type[] KnownTypes = new Type[]
  29. {
  30. typeof(Word),
  31. typeof(KanjiCharacter),
  32. typeof(Card),
  33. typeof(CardStats),
  34. };
  35. private Deck<Word> wordDeck;
  36. private Deck<KanjiCharacter> kanjiDeck;
  37. public Form1()
  38. {
  39. InitializeComponent();
  40. this.KeyPreview = true;
  41. string appdataPath = System.Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
  42. string wordDeckPath = Path.Combine(appdataPath, WordDeckFileName);
  43. string kanjiDeckPath = Path.Combine(appdataPath, KanjiDeckFileName);
  44. if (File.Exists(wordDeckPath) && File.Exists(kanjiDeckPath))
  45. {
  46. this.wordDeck = Deck<Word>.Deserialize(wordDeckPath, WordCardFiles);
  47. this.kanjiDeck = Deck<KanjiCharacter>.Deserialize(kanjiDeckPath, KanjiCardFiles);
  48. }
  49. else
  50. {
  51. Debug.Fail("Decks not found");
  52. this.wordDeck = new Deck<Word>();
  53. this.kanjiDeck = new Deck<KanjiCharacter>();
  54. List<Word> imported = SmartFM.ImportList(19053);
  55. foreach (Word newCard in imported)
  56. {
  57. this.wordDeck.AddCard(newCard);
  58. }
  59. this.wordDeck.EnabledCategories.Add("None");
  60. }
  61. this.vocabControl.LoadDeck(wordDeck);
  62. this.kanjiControl.LoadDeck(kanjiDeck);
  63. this.exploreVocabControl.LoadDeck(wordDeck);
  64. this.exploreKanjiControl.LoadDeck(kanjiDeck);
  65. this.statsControl.LoadDeck(wordDeck, kanjiDeck);
  66. this.settingsControl.LoadDeck(wordDeck, kanjiDeck);
  67. }
  68. private void Form1_FormClosing(object sender, FormClosingEventArgs e)
  69. {
  70. string appdataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
  71. string wordDeckPath = Path.Combine(appdataPath, WordDeckFileName);
  72. string kanjiDeckPath = Path.Combine(appdataPath, KanjiDeckFileName);
  73. Utility.Serialize<Deck<Word>>(wordDeck, wordDeckPath, KnownTypes);
  74. Utility.Serialize<Deck<KanjiCharacter>>(kanjiDeck, kanjiDeckPath, KnownTypes);
  75. Utility.Serialize<List<Word>>(wordDeck.AllCards.Values.ToList(), WordCardFiles[0], KnownTypes);
  76. Utility.Serialize<List<KanjiCharacter>>(kanjiDeck.AllCards.Values.ToList(), KanjiCardFiles[0], KnownTypes);
  77. }
  78. private void Form1_KeyPress(object sender, KeyPressEventArgs e)
  79. {
  80. if (tabs.SelectedIndex == 0)
  81. {
  82. if (e.KeyChar == '2')
  83. vocabControl.revealBtn_Click(sender, e);
  84. else if (e.KeyChar == '1')
  85. vocabControl.correctBtn_Click(sender, e);
  86. else if (e.KeyChar == '3')
  87. vocabControl.incorrectBtn_Click(sender, e);
  88. }
  89. else if (tabs.SelectedIndex == 1)
  90. {
  91. if (e.KeyChar == '2')
  92. kanjiControl.revealBtn_Click(sender, e);
  93. else if (e.KeyChar == '1')
  94. kanjiControl.correctBtn_Click(sender, e);
  95. else if (e.KeyChar == '3')
  96. kanjiControl.incorrectBtn_Click(sender, e);
  97. }
  98. }
  99. private void tabs_SelectedIndexChanged(object sender, EventArgs e)
  100. {
  101. switch (tabs.SelectedIndex)
  102. {
  103. case 0:
  104. vocabControl.RefreshPage();
  105. break;
  106. case 1:
  107. kanjiControl.RefreshPage();
  108. break;
  109. case 2:
  110. exploreVocabControl.RefreshPage();
  111. break;
  112. case 3:
  113. statsControl.UpdateGraph();
  114. break;
  115. default:
  116. break;
  117. }
  118. }
  119. private void button1_Click(object sender, EventArgs e)
  120. {
  121. List<KanjiCharacter> kanjis = Importers.ImportKanji();
  122. foreach (KanjiCharacter character in kanjis)
  123. {
  124. this.kanjiDeck.AddCard(character);
  125. }
  126. }
  127. }
  128. }