/FlashCard/WindowsFormsApplication1/Form1.cs
C# | 144 lines | 128 code | 16 blank | 0 comment | 24 complexity | fd0675dede3703dabb0f7d96c2155df7 MD5 | raw file
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.Collections;
- using System.IO;
- using System.Xml;
- using System.Globalization;
- using System.Diagnostics;
-
- namespace FlashCard
- {
- public partial class Form1 : Form
- {
- private const string WordDeckFileName = "FlashCard\\WordDeck.xml";
- private const string KanjiDeckFileName = "FlashCard\\KanjiDeck.xml";
-
- private readonly string[] WordCardFiles = new string[]
- {
- "Data\\WordData.xml",
- };
-
- private readonly string[] KanjiCardFiles = new string[]
- {
- "Data\\KanjiData.xml",
- };
-
- private readonly Type[] KnownTypes = new Type[]
- {
- typeof(Word),
- typeof(KanjiCharacter),
- typeof(Card),
- typeof(CardStats),
- };
-
- private Deck<Word> wordDeck;
- private Deck<KanjiCharacter> kanjiDeck;
-
- public Form1()
- {
- InitializeComponent();
-
- this.KeyPreview = true;
-
- string appdataPath = System.Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
- string wordDeckPath = Path.Combine(appdataPath, WordDeckFileName);
- string kanjiDeckPath = Path.Combine(appdataPath, KanjiDeckFileName);
- if (File.Exists(wordDeckPath) && File.Exists(kanjiDeckPath))
- {
- this.wordDeck = Deck<Word>.Deserialize(wordDeckPath, WordCardFiles);
- this.kanjiDeck = Deck<KanjiCharacter>.Deserialize(kanjiDeckPath, KanjiCardFiles);
- }
- else
- {
- Debug.Fail("Decks not found");
- this.wordDeck = new Deck<Word>();
- this.kanjiDeck = new Deck<KanjiCharacter>();
- List<Word> imported = SmartFM.ImportList(19053);
- foreach (Word newCard in imported)
- {
- this.wordDeck.AddCard(newCard);
- }
- this.wordDeck.EnabledCategories.Add("None");
- }
-
- this.vocabControl.LoadDeck(wordDeck);
- this.kanjiControl.LoadDeck(kanjiDeck);
- this.exploreVocabControl.LoadDeck(wordDeck);
- this.exploreKanjiControl.LoadDeck(kanjiDeck);
- this.statsControl.LoadDeck(wordDeck, kanjiDeck);
- this.settingsControl.LoadDeck(wordDeck, kanjiDeck);
- }
-
- private void Form1_FormClosing(object sender, FormClosingEventArgs e)
- {
- string appdataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
- string wordDeckPath = Path.Combine(appdataPath, WordDeckFileName);
- string kanjiDeckPath = Path.Combine(appdataPath, KanjiDeckFileName);
-
- Utility.Serialize<Deck<Word>>(wordDeck, wordDeckPath, KnownTypes);
- Utility.Serialize<Deck<KanjiCharacter>>(kanjiDeck, kanjiDeckPath, KnownTypes);
-
- Utility.Serialize<List<Word>>(wordDeck.AllCards.Values.ToList(), WordCardFiles[0], KnownTypes);
- Utility.Serialize<List<KanjiCharacter>>(kanjiDeck.AllCards.Values.ToList(), KanjiCardFiles[0], KnownTypes);
- }
-
- private void Form1_KeyPress(object sender, KeyPressEventArgs e)
- {
- if (tabs.SelectedIndex == 0)
- {
- if (e.KeyChar == '2')
- vocabControl.revealBtn_Click(sender, e);
- else if (e.KeyChar == '1')
- vocabControl.correctBtn_Click(sender, e);
- else if (e.KeyChar == '3')
- vocabControl.incorrectBtn_Click(sender, e);
- }
- else if (tabs.SelectedIndex == 1)
- {
- if (e.KeyChar == '2')
- kanjiControl.revealBtn_Click(sender, e);
- else if (e.KeyChar == '1')
- kanjiControl.correctBtn_Click(sender, e);
- else if (e.KeyChar == '3')
- kanjiControl.incorrectBtn_Click(sender, e);
- }
- }
-
- private void tabs_SelectedIndexChanged(object sender, EventArgs e)
- {
- switch (tabs.SelectedIndex)
- {
- case 0:
- vocabControl.RefreshPage();
- break;
- case 1:
- kanjiControl.RefreshPage();
- break;
- case 2:
- exploreVocabControl.RefreshPage();
- break;
- case 3:
- statsControl.UpdateGraph();
- break;
- default:
- break;
- }
- }
-
- private void button1_Click(object sender, EventArgs e)
- {
- List<KanjiCharacter> kanjis = Importers.ImportKanji();
-
- foreach (KanjiCharacter character in kanjis)
- {
- this.kanjiDeck.AddCard(character);
- }
- }
- }
- }