示例#1
0
 public DeckView(Deck deck)
 {
     this.deck = deck.Clone();
     this.removed_deck = new Deck();
     this.save_changes = false;
     InitializeComponent();
     ShowDeck();
 }
示例#2
0
文件: Deck.cs 项目: fmin2958/Pamya
 public Deck Clone()
 {
     var clone_deck = new Deck();
     foreach (Word w in dc)
     {
         clone_deck.AddWord(w.Clone());
     }
     return clone_deck;
 }
示例#3
0
        public EditDeckDialog(Deck d)
        {
            CurrentDeck = d.Clone();

            if (Words.Count == 0)
                Words.Add(new Word());

            foreach (Word w in CurrentDeck.Words)
            {
                if (w.Translations == null || w.Translations.Count == 0)
                    w.Translations = new List<string>() { null };
                if (w.Examples == null || w.Examples.Count == 0)
                    w.Examples = new List<string>() { null };
                if (w.Translations[0] == null)
                    w.Translations.RemoveAt(0);
                if (w.Examples[0] == null)
                    w.Examples.RemoveAt(0);
            }

            InitializeComponent();
        }
示例#4
0
        public void _OpenDeck(string FileName, int GameType)
        {
            //this.Title = "Pamya - " + fname; //FIXME
            CurrentDeckFolder = DecksFolder + @"\" + FileName;
            DeckFile = CurrentDeckFolder + @"\deck.sqlite";

            UserFile = CurrentDeckFolder + @"\userdata.sqlite";

            //I feel like this is too much overhead
            SQLiteConnection deckdbcon;
            deckdbcon =
            new SQLiteConnection("Data Source=" + DeckFile + ";Version=3;");
            deckdbcon.Open();

            SQLiteConnection userdbcon;
            userdbcon =
            new SQLiteConnection("Data Source=" + UserFile + ";Version=3;");
            userdbcon.Open();

            string sql = "SELECT * FROM deck ORDER BY id ASC";
            SQLiteCommand command = new SQLiteCommand(sql, deckdbcon);
            SQLiteDataReader deck_reader = command.ExecuteReader();

            CurrentDeck = new Deck();

            while (deck_reader.Read())
            {
                var word = new Word(deck_reader["question"].ToString(), deck_reader["answer"].ToString());
                word.id = Convert.ToInt32(deck_reader["id"]);
                word.wav_file_loc = deck_reader["wavfileloc"].ToString();
                word.guid = deck_reader["guid"].ToString();
                word.example = deck_reader["example"].ToString();
                word.image_file_location = deck_reader["imagefileloc"].ToString();
                var user_sql = "SELECT * FROM deck WHERE guid='" + deck_reader["guid"].ToString() + "'";
                var user_command = new SQLiteCommand(user_sql, userdbcon);
                try
                {
                    var user_reader = user_command.ExecuteReader();
                    user_reader.Read();
                    word.EF = Convert.ToDouble(user_reader["ef"]);
                    word.I = Convert.ToDouble(user_reader["i"]);
                    word.n = Convert.ToInt32(user_reader["n"]);
                    word.studied = Convert.ToBoolean(user_reader["studied"]);
                    word.time_due = Convert.ToInt32(user_reader["timedue"]);
                    user_reader.Close();
                    CurrentDeck.AddWord(word);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }

            }

            deck_reader.Close();

            userdbcon.Close();
            deckdbcon.Close();

            //TODO
            //FIND OUT WHICH GAME IS PLAYED

            //OPEN THE GAME

            GameChangeDelegates[GameType + 1].DynamicInvoke(); // +1 as 0 is the mainmenu page
        }
示例#5
0
        public void _GetCurrentDeck(string FileName)
        {
            try
            {
                CurrentDeckFolder = DecksFolder + @"\" + FileName;
                CurrentDeckFile = CurrentDeckFolder + @"\word.db";
                var db = new LiteDatabase(CurrentDeckFile);
                var wordCol = db.GetCollection<Word>("words");
                var results = wordCol.FindAll();
                CurrentDeck = new Deck();
                CurrentDeck.Words = results.ToList();

                //Initialise null values
                foreach (Word w in CurrentDeck.Words)
                {
                    if (w.Translations == null)
                        w.Translations = new List<string>();
                    if (w.Examples == null)
                        w.Examples = new List<string>();
                }

                //Set OrderId if it does not exist
                if (CurrentDeck.Words.FindAll(tw => tw.OrderId == 0).Count > 0)
                {
                    CurrentDeck.Words = CurrentDeck.Words.OrderBy(a => a.Id).ToList();
                    for (int i = 0; i < CurrentDeck.Words.Count; i++)
                    {
                        CurrentDeck.Words[i].OrderId = i + 1;
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
            CurrentDeck.Words = CurrentDeck.Words.OrderBy(a => a.OrderId).ToList();
        }
示例#6
0
        public void _EditDeck(Deck dDeck)
        {
            if (File.Exists(CurrentDeckFile))
            {
                //this is shit
                var db = new LiteDatabase(CurrentDeckFile);
                var wordCol = db.GetCollection<Word>("words");
                var allWords = wordCol.FindAll().ToList();

                //remove all words that were removed
                foreach (Word w in allWords)
                {
                    if (dDeck.Words.FindAll(tw => tw.sGuid.Equals(w.sGuid)).Count == 0)
                    {
                        wordCol.Delete(w.Id);
                    }
                }

                db.Commit();

                UpdateDeckDB(dDeck.Words);

                PamyaDeck.Instance.CurrentDeck = dDeck;

                ShowDeck();
            }
        }
示例#7
0
        private void _ImportFromText(string text, string DeckFolder)
        {
            var DeckFile = DeckFolder + @"\word.db";

            Debug.Print(DeckFolder);

            var importDeck = new Deck();
            importDeck.fillDeckFromString(text); // change this
            var db = new LiteDatabase(DeckFile); //this does not belong here, move. FIXME
            var wordCol = db.GetCollection<Word>("words");
            List<Word> newWords = new List<Word>();
            foreach (var w in importDeck.Words)
            {
                if (wordCol.Find(tw => tw.sGuid == w.sGuid).ToList().Count == 0)
                {
                    wordCol.Insert(w);
                }
            }
            db.Commit();
        }