Example #1
0
        static void loadCards(Quiz quiz, CardList list)
        {
            string        sql     = "SELECT * FROM \"question\" WHERE \"quiz\" = @quiz";
            SQLiteCommand command = new SQLiteCommand(sql, dbConn);

            command.Parameters.Add("@quiz", DbType.Int32);
            command.Parameters["@quiz"].Value = quiz.ID;

            SQLiteDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {
                Card card = new Card(reader["question"].ToString(), reader["answer"].ToString());
                card.Type = reader["type"].ToString();
                // Fallback to flashcard type in case something went wrong
                if (card.Type == "")
                {
                    card.Type = "flashcard";
                }
                card.ID = int.Parse(reader["id"].ToString());

                if (card.Type == "multiplechoice")
                {
                    string   options     = reader["options"].ToString();
                    string[] optionArray = options.Split(new string[] { ";;" }, StringSplitOptions.None);
                    if (optionArray.Length != 4)
                    {
                        continue;
                    }

                    card.AddOption(0, optionArray[0]);
                    card.AddOption(1, optionArray[1]);
                    card.AddOption(2, optionArray[2]);
                    card.AddOption(3, optionArray[3]);
                }

                list.Add(card);
            }
        }
Example #2
0
        static void loadCards(StreamReader file, CardList list)
        {
            string line;
            Card   card = new Card();

            while ((line = file.ReadLine()) != null)
            {
                // Comments begin with #
                if (line[0] == '#')
                {
                    continue;
                }

                // === signifies the end of each question
                if (line == "===")
                {
                    list.Add(card);
                    card = new Card();
                    continue;
                }

                string property = "";
                string value    = "";
                int    position = line.IndexOf(':');
                if (position > 0)
                {
                    property = line.Substring(0, position);
                    value    = line.Substring(position + 1).Trim();
                }

                switch (property)
                {
                case "question":
                    card.Question = value;
                    break;

                case "type":
                    // Fallback to flashcard if type is blank
                    if (value == "")
                    {
                        value = "flashcard";
                    }
                    card.Type = value;
                    break;

                case "answer":
                    card.Answer = value;
                    break;

                case "a":
                    card.AddOption(0, value);
                    break;

                case "b":
                    card.AddOption(1, value);
                    break;

                case "c":
                    card.AddOption(2, value);
                    break;

                case "d":
                    card.AddOption(3, value);
                    break;
                }
            }
            // Add last card to deck
            list.Add(card);
        }