/FlashCard/WindowsFormsApplication1/Tabs/Settings.cs
C# | 83 lines | 72 code | 11 blank | 0 comment | 17 complexity | 5e3dc9830880538b67a2c28179c1f05d 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 System.Collections;
-
- namespace FlashCard.Tabs
- {
- public partial class Settings : UserControl
- {
- private Deck<Word> wordDeck;
- private Deck<KanjiCharacter> kanjiDeck;
-
- public Settings()
- {
- InitializeComponent();
- }
-
- public void LoadDeck(Deck<Word> wordDeck, Deck<KanjiCharacter> kanjiDeck)
- {
- this.wordDeck = wordDeck;
- this.kanjiDeck = kanjiDeck;
-
- this.wordCategoryListBox.Items.AddRange(this.wordDeck.AllCards.Values.Select(w => w.Category).Distinct().ToArray());
- this.kanjiCategoryListBox.Items.AddRange(this.kanjiDeck.AllCards.Values.Select(w => w.Category).Distinct().ToArray());
-
- CheckCorrectBoxes(this.wordDeck.EnabledCategories, this.wordCategoryListBox);
- CheckCorrectBoxes(this.kanjiDeck.EnabledCategories, this.kanjiCategoryListBox);
- }
-
- private void CheckCorrectBoxes(IEnumerable<string> categories, CheckedListBox listBox)
- {
- int count = categories.Count();
- for (int i = 0; i < listBox.Items.Count; i++)
- {
- string item = listBox.Items[i] as string;
- listBox.SetItemChecked(i, count == 0 || categories.Contains(item));
- }
- }
-
- private void wordCategoryListBox_ItemCheck(object sender, ItemCheckEventArgs e)
- {
- string category = this.wordCategoryListBox.Items[e.Index] as string;
- if (e.NewValue == CheckState.Checked && !this.wordDeck.EnabledCategories.Contains(category))
- {
- this.wordDeck.EnabledCategories.Add(category);
- }
- else if (e.NewValue == CheckState.Unchecked && this.wordDeck.EnabledCategories.Contains(category))
- {
- this.wordDeck.EnabledCategories.Remove(category);
- }
-
- wordDeck.UpdateCategories();
- }
-
- private void kanjiCategoryListBox_ItemCheck(object sender, ItemCheckEventArgs e)
- {
- string category = this.kanjiCategoryListBox.Items[e.Index] as string;
- if (e.NewValue == CheckState.Checked && !this.kanjiDeck.EnabledCategories.Contains(category))
- {
- this.kanjiDeck.EnabledCategories.Add(category);
- }
- else if (e.NewValue == CheckState.Unchecked && this.kanjiDeck.EnabledCategories.Contains(category))
- {
- this.kanjiDeck.EnabledCategories.Remove(category);
- }
-
- kanjiDeck.UpdateCategories();
- }
-
- private void importBtn_Click(object sender, EventArgs e)
- {
- foreach (KanjiCharacter character in Importers.ImportKanji())
- {
- this.kanjiDeck.AddCard(character);
- }
- }
- }
- }