예제 #1
0
        public static bool writeToFile(string fileName, ListOfCards content)
        {
            try
            {
                //Putting the cards in 'content' into a List<tmpCard> for processing
                List <tmpCard> tmpListOfCards = new List <tmpCard>();

                for (int x = 0; x <= (content.getNumOfCards() - 1); x++)
                {
                    tmpListOfCards.Add(new tmpCard()
                    {
                        question = content.getCardAt(x).getQuestion(),
                        answer   = content.getCardAt(x).getAnswer()
                    });
                }
                //Converting 'tmpListOfCards' into JSON
                string json = JsonConvert.SerializeObject(tmpListOfCards.ToArray());

                //Writing to the file 'json'
                System.IO.File.WriteAllText(fileName, json);

                return(true);    //Writing to the file was successful
            }
            catch
            {
                return(false);   //Writing to file failed
            }
        }
예제 #2
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);
            }
        }
예제 #3
0
        //Loads the question in to the form (Hides the answer until the user wants to reveal it)
        private void loadQuestion(Card c)
        {
            richTextBoxQuestion.Text = c.getQuestion();     //Displaying the Question in the question rich text box
            richTextBoxAnswer.Text   = answerHiddenMessage; //Instructions to the user
            answerShown        = false;                     //Setting the boolean answerShown to false
            btnShowAnswer.Text = "Show Answer";
            currentAnswer      = c.getAnswer();             //Storing the answer to the question, so it can be revealed when the user wants it

            //Updating the counter that shows the user what card they are on, out of the total number of cards
            labelCardCounter.Text = (listOfCards.getCurrentPosition() + 1) + " / " + listOfCards.getNumOfCards();
        }