Ejemplo n.º 1
0
        //An event hanlder that executes when the user click's on the add button
        private void btnAdd_Click(object sender, EventArgs e)
        {
            //Creating an instance of the add card form to get input from the user
            AddCard addFrm = new AddCard();

            //Displaying form and waiting till the user has finished entering the their input
            if (addFrm.ShowDialog(this) == DialogResult.OK)
            {
                // *** Need to add validation ***

                //Adding the new card based on the public variables (holds the user's input)
                listOfCards.addCard(new Card(addFrm.question, addFrm.answer));

                //Adding the new card to the list
                listBoxOfQuestions.Items.Add(listOfCards.getNumOfCards() + ". " + addFrm.question);
            }
        }
Ejemplo n.º 2
0
        //Reads a given file path, and then returns the content as a 'ListOfCards'
        public static ListOfCards readFromFile(string fileName)
        {
            //Reading from the file the user selected using a stream
            using (StreamReader r = new StreamReader(fileName))
            {
                //Reading file into a string
                string json = r.ReadToEnd();
                //Converting the json string into a 'Card' object (Using the below card class)
                List <tmpCard> tmpListOfCards = JsonConvert.DeserializeObject <List <tmpCard> >(json);

                //Creating a instance of ListOfCards, so we can return it once the cards have been put in
                ListOfCards returnListOfCards = new ListOfCards();

                //Putting the 'Cards' from the 'tmpListOfCards' into the 'listOfCards' (Covering from a tmpCard to a Card, foreach element)
                foreach (tmpCard c in tmpListOfCards)
                {
                    returnListOfCards.addCard(new Card(c.question, c.answer));
                }

                //Returning the 'ListOfCard' that was read from the file
                return(returnListOfCards);
            }
        }