void ImportInitialFlashcardSet() { FlashcardSet f = JsonUtility.FromJson <FlashcardSet> (initialFlashcardSet); f.jsonString = initialFlashcardSet; FlashcardManager.instance.AddFlashcardSet(f); }
/// <summary> /// Event handler for when the item selection changes in the flashcard set list box. /// </summary> /// <param name="sender">The object that raised the event.</param> /// <param name="e">The event arguments for when the selection is changed.</param> private void FlashcardSetListBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { // Update the current flashcard to the one selected currentFlashcardSet = (FlashcardSet)flashcardSetListBox.SelectedItem; currentFlashcardState = FlashcardState.Term; flashcardsListCurrentIndex = 0; UpdateFlashcardUI(); }
/// <summary> /// Event handler for when the "Load Flashcard Set" button is clicked. /// </summary> /// <param name="sender">The object that raised the event.</param> /// <param name="e">The event arguments for when the button is clicked.</param> private void LoadSetButton_Click(object sender, RoutedEventArgs e) { OpenFileDialog openDialog = new OpenFileDialog(); openDialog.Filter = HelperClass.DialogFilter; if (openDialog.ShowDialog() == true) // Ok button was pressed on the dialog { try { string fileText = File.ReadAllText(openDialog.FileName); // Extract the information about the flashcard set from the JSON text using (JsonDocument document = JsonDocument.Parse(fileText)) { JsonElement root = document.RootElement; string setName = root.GetProperty(HelperClass.SetNameJsonPropertyName).ToString(); // Get the flashcards in the JSON List <Flashcard> flashcardsList = new List <Flashcard>(); foreach (JsonElement element in root.GetProperty(HelperClass.FlashcardsListJsonPropertyName).EnumerateArray()) { string term = element.GetProperty(HelperClass.TermJsonPropertyName).ToString(); string definition = element.GetProperty(HelperClass.DefinitionJsonPropertyName).ToString(); Flashcard flashcard = new Flashcard(term, definition); flashcardsList.Add(flashcard); } FlashcardSet set = new FlashcardSet(setName, flashcardsList); if (AlreadyLoaded(set)) // If the flashcard set is already loaded, prompt the user to make sure that that want to load in the flashcard set again { MessageBoxResult msgResult = MessageBox.Show("Flashcard set has already been loaded into the program! Are you sure you still want to load in flashcard set?", "Question", MessageBoxButton.YesNo, MessageBoxImage.Question); if (msgResult == MessageBoxResult.No) { return; } } flashcardSetListBox.Items.Add(set); flashcardSetListBox.SelectedItem = set; flashcardsListCurrentIndex = 0; UpdateFlashcardUI(); MessageBox.Show("Flashcard set loaded succesfully!", "Success", MessageBoxButton.OK, MessageBoxImage.Information); } } catch (Exception ex) { MessageBox.Show("An error occured while trying to parse the file '" + openDialog.FileName + "' which resulted in the flashcard set not being loaded into the program.\n\nException message: " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } }
public void createDetails(object sender, EventArgs e) { //Display All Flashcard Sets in DB createSet = new FlashcardSet { }; ((TextBox)createDetailsUC.getControl("txtName")).Text = ""; ((TextBox)createDetailsUC.getControl("txtDesc")).Text = ""; renderPage(createDetailsUC); }
/// <summary> /// Checks whether a flashcard set is already present in the flashcard set list box on the window. /// </summary> /// <param name="flashcardSet">The flashcard set to be checked for whether it is already loaded or not.</param> /// <returns>A boolean that states whether the flashcard set is loaded in the program or not.</returns> private bool AlreadyLoaded(FlashcardSet flashcardSet) { foreach (FlashcardSet fs in flashcardSetListBox.Items) { if (flashcardSet.Equals(fs)) // Duplicate found { return(true); } } return(false); }
public void AddFlashcardSet(FlashcardSet f) { for (int i = 0; i < loadedFlashcardSets.Count; i++) { if (f.id == loadedFlashcardSets [i].id) { return; } } loadedFlashcardSets.Add(f); swapToggles [loadedFlashcardSets.Count - 1].isOn = false; UpdateRecentFlashcardSets(f); UpdateLoadedSetsUIElements(); }
/// <summary> /// Event handler for when the "Save Flashcard Set" button is clicked. /// </summary> /// <param name="sender">The object that raised the event.</param> /// <param name="e">The event arguments for when the button is clicked.</param> private void SaveFlashcardSetButton_Click(object sender, RoutedEventArgs e) { if (flashcardsSetListBox.Items.Count == 0) { MessageBox.Show("You can't save an empty flashcard set!", "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } if (string.IsNullOrWhiteSpace(setNameText.Text)) { MessageBox.Show("Invalid set name.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } List <Flashcard> flashcards = new List <Flashcard>(); foreach (Flashcard flashcard in flashcardsSetListBox.Items) { flashcards.Add(flashcard); } FlashcardSet flashcardSet = new FlashcardSet(setNameText.Text, flashcards); string flashcardsSetJson = JsonSerializer.Serialize(flashcardSet); // Serialize the 'flashcardSet' to JSON text SaveFileDialog saveDialog = new SaveFileDialog(); saveDialog.Filter = HelperClass.DialogFilter; if (saveDialog.ShowDialog() == true) // Ok button was pressed on the save dialog, save the JSON text { try { File.WriteAllText(saveDialog.FileName, flashcardsSetJson); MessageBox.Show("Flashcard set saved succesfully!", "Success", MessageBoxButton.OK, MessageBoxImage.Information); } catch (Exception ex) { MessageBox.Show("An error occured while trying to save the flashcard set.\n\nException message: " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } }
/// <summary> /// Event handler for when the "Unload Current Set" button is clicked. /// </summary> /// <param name="sender">The object that raised the event.</param> /// <param name="e">The event arguments for when the button is clicked.</param> private void UnloadCurrentSetButton_Click(object sender, RoutedEventArgs e) { if (flashcardSetListBox.Items.Count > 0) { int selectedIndex = flashcardSetListBox.Items.IndexOf(currentFlashcardSet); flashcardSetListBox.Items.RemoveAt(selectedIndex); if (flashcardSetListBox.Items.Count > 0) { flashcardSetListBox.SelectedIndex = 0; } else { currentFlashcardSet = null; } currentFlashcardState = FlashcardState.Term; flashcardsListCurrentIndex = 0; UpdateFlashcardUI(); } }
public List <FlashcardSet> GetAllSetsOfFlashcards() { DBConnect db = new DBConnect(); SqlCommand sqlCmd = new SqlCommand(); sqlCmd.CommandType = CommandType.StoredProcedure; sqlCmd.CommandText = "TP_GetAllSetsOfFlashcards"; DataSet ds = db.GetDataSetUsingCmdObj(sqlCmd); List <FlashcardSet> set = new List <FlashcardSet>(); FlashcardSet flashcardSet; foreach (DataRow record in ds.Tables[0].Rows) { flashcardSet = new FlashcardSet(); flashcardSet.NameOfFlashcardSet = record["Flashcard_Set"].ToString(); flashcardSet.SubjectOfFlashcardSet = record["Subject"].ToString(); flashcardSet.UsernameOfFlashcardSet = record["Username"].ToString(); set.Add(flashcardSet); } return(set); }
void UpdateRecentFlashcardSets(FlashcardSet f) { for (int i = 0; i < recentFlashcardSets.Count; i++) { if (f.id == recentFlashcardSets [i].id) { //if fcs is already in recents, pushes it to the end of the list recentFlashcardSets.RemoveAt(i); recentFlashcardSets.Add(f); UpdateRecentSetsUI(); return; } } recentFlashcardSets.Add(f); if (recentFlashcardSets.Count > recentsListMaxSize) { recentFlashcardSets.RemoveAt(0); } UpdateRecentSetsUI(); }
IEnumerator OnResponse(WWW req) { yield return(req); print("done"); loadingIcon.SetActive(false); FlashcardSet f = JsonUtility.FromJson <FlashcardSet> (req.text); f.jsonString = req.text; //TODO: make on screen indication if (f.http_code == 404) { print("Invalid set ID"); } else { FlashcardManager.instance.AddFlashcardSet(f); } //testText.text = f.ToString(); //testText.text = req.text; }
public void learnStart(object sender, EventArgs e) { //Reset Global Variables learnProgress = 0; learnCorrect = 0; learnSet = new FlashcardSet { }; //Find List Item var listView = (ListView)learnMenuUC.getControl("listView"); if (listView.SelectedItems.Count == 1) { var setID = Convert.ToInt32(listView.SelectedItems[0].SubItems[0].Text); //Fetch Set from DB using (var db = new LiteDatabase(@"flashies.db")) { var sets = db.GetCollection <FlashcardSet>("sets"); learnSet = sets.FindById(setID); //Randomise Question Order Random rng = new Random(); int n = learnSet.flashcards.Count; while (n > 1) { n--; int k = rng.Next(n + 1); Flashcard value = learnSet.flashcards[k]; learnSet.flashcards[k] = learnSet.flashcards[n]; learnSet.flashcards[n] = value; } ((TextBox)learnQuestionUC.getControl("txtTitle")).Text = learnSet.name; ((TextBox)questionResultUC.getControl("txtTitle")).Text = learnSet.name; //Render Next Question renderLearnQuestion(this, e); } } }
public async Task UpdateFlashcardSetAsync(FlashcardSet flashcardSet) { _context.Entry(flashcardSet).State = EntityState.Modified; await _context.SaveChangesAsync(); }
public async Task AddFlashcardSetAsync(FlashcardSet flashcardSet) { _context.FlashcardSet.Add(flashcardSet); await _context.SaveChangesAsync(); }