コード例 #1
0
 // This button loads the last card in the deck
 private void Last_Click(object sender, RoutedEventArgs e)
 {
     index                      = Deck.cards.Count - 1;
     f                          = Deck.cards[index];
     TermBlock.Text             = f.Front;
     DefinitionBox.Text         = f.Back;
     CurrentCardTextbox.Content = (index + 1).ToString();
     loadImage();
     makeFrontVisible();
     IsFrontShowing = true;
 }
コード例 #2
0
        // This button opens the window explorer and allows the user to select a study deck to edit.
        private void SelectADeckbtn_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter = "JSON files (*StudyDeck.JSON)|*StudyDeck.JSON";
            if (openFileDialog.ShowDialog() == true)
            {
                filePath = openFileDialog.FileName;// Get the files path.

                // If a study deck exist then populate the rest of the form with the appropriate fields.
                if (File.Exists(filePath))
                {
                    // Before the form is populated, make sure it is a StudyDeck and not a QuestionDeck.
                    if (filePath.Contains(".StudyDeck"))
                    {
                        currentlyEditing.Text = System.IO.Path.GetFileNameWithoutExtension(filePath); // Get the files name only.
                        String[] arr = (currentlyEditing.Text).Split('.');
                        currentlyEditing.Text = arr[0];

                        // Make the rest of form visibile once a deck has been selected.
                        button.Visibility            = Visibility.Visible;
                        TermtextBox.Visibility       = Visibility.Visible;
                        Termlabel.Visibility         = Visibility.Visible;
                        DefinitiontextBox.Visibility = Visibility.Visible;
                        Definitionlabel.Visibility   = Visibility.Visible;
                        Deletebtn.Visibility         = Visibility.Visible;
                        Savebutton.Visibility        = Visibility.Visible;
                        NextBtn.Visibility           = Visibility.Visible;
                        Previousbtn.Visibility       = Visibility.Visible;
                        finish.Visibility            = Visibility.Visible;

                        JSONflashcards         = File.ReadAllText(filePath);
                        Deck                   = ser.Deserialize <StudyDeck>(JSONflashcards);
                        TotalCardstextBox.Text = (Deck.cards.Count).ToString();
                        flashCard              = Deck.cards[index];

                        TermtextBox.Text        = flashCard.Front;
                        DefinitiontextBox.Text  = flashCard.Back;
                        CurrentCardTextbox.Text = (index + 1).ToString();
                        loadImage();
                    }
                    else
                    {
                        MessageBox.Show("Sorry, You can only edit a Study Deck on this page. If you need to edit a Question deck"
                                        + " then go back to the deck builder page and click the 'Edit Question Deck' button.", "Help Window", MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                }
            }
        }
コード例 #3
0
 // This button loads the next flashcard in the deck.
 private void Nextbtn_Click(object sender, RoutedEventArgs e)
 {
     //  Note: Each time next is hit, always show front of the card and hide back
     if (index < Deck.cards.Count - 1)
     {
         index++;
         f = Deck.cards[index];
         TermBlock.Text             = f.Front;
         DefinitionBox.Text         = f.Back;
         CurrentCardTextbox.Content = (index + 1).ToString();
         loadImage();
         makeFrontVisible();
         IsFrontShowing = true;
     }
 }
コード例 #4
0
        // This button moves to the previous flashcard provided it is not the first card in the deck.
        private void Previousbtn_Click(object sender, RoutedEventArgs e)
        {
            if (index > 0)
            {
                index--;

                // Load flashcards onto the form.
                flashCard               = Deck.cards[index];
                TermtextBox.Text        = flashCard.Front;
                DefinitiontextBox.Text  = flashCard.Back;
                CurrentCardTextbox.Text = (index + 1).ToString();

                // Load the image if it exist onto the form.
                loadImage();
            }
        }
コード例 #5
0
        // This button opens the file explorer so the user can select a study deck to edit.
        private void SelectADeckbtn_Click(object sender, RoutedEventArgs e)
        {
            index = 0;
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter = "JSON files (*StudyDeck.JSON)|*StudyDeck.JSON";
            if (openFileDialog.ShowDialog() == true)
            {
                path = openFileDialog.FileName; // get file path

                if (path.Contains(".StudyDeck"))
                {
                    DeckTitlebox.Text = System.IO.Path.GetFileNameWithoutExtension(path); // get file name only
                    string [] arr = (DeckTitlebox.Text).Split('.');
                    DeckTitlebox.Text = arr[0];
                    makeFrontVisible();
                    // Show flashcard border and buttons
                    Rectangle1.Visibility         = Visibility.Visible;
                    Nextbtn.Visibility            = Visibility.Visible;
                    Flipbtn.Visibility            = Visibility.Visible;
                    Finishedbtn.Visibility        = Visibility.Visible;
                    CurrentCardTextbox.Visibility = Visibility.Visible;
                    backslash.Visibility          = Visibility.Visible;
                    TotalCardsBox.Visibility      = Visibility.Visible;

                    // Load the contents of the flashcard
                    JSONflashcards        = File.ReadAllText(path);
                    Deck                  = ser.Deserialize <StudyDeck>(JSONflashcards);
                    TotalCardsBox.Content = (Deck.cards.Count).ToString();
                    f = Deck.cards[index];
                    TermBlock.Text             = f.Front;
                    DefinitionBox.Text         = f.Back;
                    CurrentCardTextbox.Content = (index + 1).ToString();
                    loadImage();
                }
                else
                {
                    MessageBox.Show("Sorry, You can only review a Study Deck on this page.", "Help Window", MessageBoxButton.OK, MessageBoxImage.Information);
                }
            }
        }
コード例 #6
0
        // This button will add a card to a set only if the term and definition exist.
        private void Addbutton_Click(object sender, RoutedEventArgs e)
        {
            if (!string.IsNullOrEmpty(DeckTitletextBox.Text))
            {
                // Get filepaths so that they may be written to the correct folder.
                string RootPath, StudyDecksPath, ImagePath, QuestionsDeckPath;
                RootPath       = StudyDecksPath = ImagePath = QuestionsDeckPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
                RootPath      += @"\QuizApp";
                StudyDecksPath = RootPath + @"\StudyDecks";
                ImagePath      = RootPath + @"\Images";

                string filePath = StudyDecksPath + @"\" + fileName + ".StudyDeck.json";
                if (currentCard == 0)
                {
                    fileName = DeckTitletextBox.Text;
                    fileName = fileName.Trim();


                    // If the file exists then update it.
                    if (File.Exists(filePath))
                    {
                        // This reads the JSON file as one big long string .
                        JSONflashcards = File.ReadAllText(filePath);

                        //MessageBox.Show("Input path: " + filePath, "Help Window", MessageBoxButton.OK, MessageBoxImage.Information);
                        // This parses that string back into an object.
                        Deck = ser.Deserialize <StudyDeck>(JSONflashcards);
                    }
                    else // Create a new file.
                    {
                        fileName = fileName + ".StudyDeck.json";
                    }
                }

                // If both the term and defintion exist then add it to the set.
                if (!string.IsNullOrEmpty(TermtextBox.Text) && !string.IsNullOrEmpty(DefinitiontextBox.Text))
                {
                    // Populate flashcards.
                    if (ImageExist == true)
                    {
                        Flashcards populateFlashCards = new Flashcards(TermtextBox.Text, DefinitiontextBox.Text, temp);
                        Deck.cards.Add(populateFlashCards);
                    }
                    else
                    {
                        Flashcards populateFlashCards = new Flashcards(TermtextBox.Text, DefinitiontextBox.Text, null);
                        Deck.cards.Add(populateFlashCards);
                    }

                    // Reserialize the object and store it as a String.
                    string outputJSON = ser.Serialize(Deck);

                    // Write that string back to the JSON file.
                    File.WriteAllText(filePath, outputJSON);
                    //MessageBox.Show("Output path: " + filePath, "Help Window", MessageBoxButton.OK, MessageBoxImage.Information);

                    //  MessageBox.Show("Reserialize object and store it", "Help Window", MessageBoxButton.OK, MessageBoxImage.Information);
                    // Increment total cards and reset text boxes.
                    currentCard++;
                    TermtextBox.Text            = "";
                    DefinitiontextBox.Text      = "";
                    CardNumberLabeltextBox.Text = (currentCard).ToString();
                    TotalCardsBox.Text          = (Deck.cards.Count).ToString();
                    temp       = "";
                    ImageExist = false;
                    // Reset Image box.
                    ImageViewer1.Source = null;
                }

                // If the Term and Definiton DOES NOT EXIST.
                else if (string.IsNullOrEmpty(TermtextBox.Text) && string.IsNullOrEmpty(DefinitiontextBox.Text))
                {
                    TermtextBox.Text       = "";
                    DefinitiontextBox.Text = "";
                    MessageBox.Show("You did not enter a Definition or an Answer! Please try again", "Help Window", MessageBoxButton.OK, MessageBoxImage.Information);
                } // If the Term DOES NOT EXIST.
                else if (string.IsNullOrEmpty(TermtextBox.Text))
                {
                    MessageBox.Show("You did not enter a Definition or an Answer! Please try again", "Help Window", MessageBoxButton.OK, MessageBoxImage.Information);
                }
                // If the Definiton DOES NOT EXIST.
                else if (string.IsNullOrEmpty(DefinitiontextBox.Text))
                {
                    MessageBox.Show("You did not enter a Term! Please try again", "Help Window", MessageBoxButton.OK, MessageBoxImage.Information);
                }
            }
            else
            {
                MessageBox.Show("You must provide a deck title to save to. You only need to do this once and leave the field alone after that", "Help Window", MessageBoxButton.OK, MessageBoxImage.Information);
            }
        }