public static RecipeJournal getJournalEntries(long recipeId) { RecipeJournal savedjournalEntries = new RecipeJournal(); SqliteConnection db = new SqliteConnection("Filename=RecipeBook.db"); db.Open(); SqliteCommand selectCommand = new SqliteCommand("SELECT * from JOURNAL_ENTRIES WHERE RID = @RecipeID"); selectCommand.Connection = db; selectCommand.Parameters.AddWithValue("@RecipeID", recipeId); SqliteDataReader query = selectCommand.ExecuteReader(); while (query.Read()) { long id = query.GetInt64(0); String entryNotes = query.GetString(2); double rating = query.GetDouble(3); DateTime entryDate = query.GetDateTime(4); RecipeJournalEntry savedEntry = new RecipeJournalEntry(id); savedEntry.RecipeID = recipeId; savedEntry.EntryDate = entryDate; savedEntry.EntryNotes = entryNotes; savedEntry.Rating = rating; savedjournalEntries.Add(savedEntry); } db.Close(); Debug.WriteLine("Saved Entries: " + savedjournalEntries.getSize()); return(savedjournalEntries); }
private async void editEntry(object sender, RoutedEventArgs e) { RecipeJournalEntry editingEntry = (RecipeJournalEntry)((MenuFlyoutItem)e.OriginalSource).DataContext; JournalDialog journalDialog = new JournalDialog(editingEntry); await journalDialog.ShowAsync(); recipe.updateJournalEntry(journalDialog.NewEntry); }
private void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args) { if (entry == null) { long newId = RecipeList.journalEntryIdGenerator.getId(); entry = new RecipeJournalEntry(newId); } entry.setEntryDate(entryDatePicker.Date.Value); entry.setEntryNotes(entryNotesControl.Text); entry.setRating(entryRatingControl.Value); }
public JournalDialog(RecipeJournalEntry targetEntry) { this.InitializeComponent(); entry = targetEntry; if (entry != null) { entryDatePicker.Date = entry.EntryDate; entryNotesControl.Text = entry.EntryNotes; entryRatingControl.Value = entry.Rating; } entryDatePicker.MaxDate = DateTimeOffset.Now.Date; }
private void madeToday(object sender, RoutedEventArgs e) { long newId = RecipeList.journalEntryIdGenerator.getId(); RecipeJournalEntry madeTodayEntry = new RecipeJournalEntry(newId); madeTodayEntry.setEntryDate(DateTime.Now); madeTodayEntry.setEntryNotes("Added as quick entry"); madeTodayEntry.setRecipeId(recipe.ID); recipe.addJournalEntry(madeTodayEntry); FlyoutBase.ShowAttachedFlyout(this.mainContent); }
private async void deleteEntry(object sender, RoutedEventArgs e) { RecipeJournalEntry entryToRemove = (RecipeJournalEntry)((MenuFlyoutItem)e.OriginalSource).DataContext; String title = "Permenantly delete entry?"; String content = "If you delete this entry, you won't be" + " able to recover it. Are you sure you want to delete" + " it?"; String primaryButtonText = "Delete"; bool result = await tryDeleteItem(title, content, primaryButtonText); if (result) { recipe.removeJournalEntry(entryToRemove); } }
public static void deleteJournalEntry(RecipeJournalEntry deletingEntry) { SqliteConnection db = new SqliteConnection("Filename=RecipeBook.db"); db.Open(); SqliteCommand deleteCommand = new SqliteCommand(); deleteCommand.Connection = db; deleteCommand.CommandText = "DELETE FROM JOURNAL_ENTRIES WHERE ID = @ID"; deleteCommand.Parameters.AddWithValue("@ID", deletingEntry.ID); deleteCommand.ExecuteNonQuery(); db.Close(); }
private void removeEntries(object sender, RoutedEventArgs e) { int numSelected = entryList.SelectedItems.Count; if (numSelected > 0) { Debug.WriteLine("Items selected: " + numSelected); RecipeJournalEntry[] entriesToDelete = new RecipeJournalEntry[numSelected]; for (int i = 0; i < numSelected; i++) { entriesToDelete[i] = (RecipeJournalEntry)entryList.SelectedItems[i]; } for (int i = 0; i < numSelected; i++) { RecipeJournalEntry toDelete = entriesToDelete[i]; Debug.WriteLine("ID to delete: " + toDelete.getId()); recipe.removeJournalEntry(entriesToDelete[i]); } } }
public static void updateJournalEntry(RecipeJournalEntry updatedEntry) { SqliteConnection db = new SqliteConnection("Filename=RecipeBook.db"); db.Open(); SqliteCommand updateCommand = new SqliteCommand(); updateCommand.Connection = db; updateCommand.CommandText = "UPDATE JOURNAL_ENTRIES SET ENTRYNOTES = @EntryNotes, RATING = @Rating, ENTRYDATE = @EntryDate WHERE ID = @ID"; updateCommand.Parameters.AddWithValue("@ID", updatedEntry.ID); updateCommand.Parameters.AddWithValue("@EntryNotes", updatedEntry.EntryNotes); updateCommand.Parameters.AddWithValue("@Rating", updatedEntry.Rating); updateCommand.Parameters.AddWithValue("@EntryDate", updatedEntry.EntryDate); updateCommand.ExecuteNonQuery(); db.Close(); }
public static void addJournalEntry(RecipeJournalEntry newEntry) { SqliteConnection db = new SqliteConnection("Filename=RecipeBook.db"); db.Open(); SqliteCommand insertCommand = new SqliteCommand(); insertCommand.Connection = db; insertCommand.CommandText = "INSERT INTO JOURNAL_ENTRIES " + "(ID, RID, ENTRYNOTES, RATING, ENTRYDATE) VALUES " + "(@ID, @RecipeID, @EntryNotes, @Rating, @EntryDate)"; insertCommand.Parameters.AddWithValue("@ID", newEntry.ID); insertCommand.Parameters.AddWithValue("@RecipeID", newEntry.RecipeID); insertCommand.Parameters.AddWithValue("@EntryNotes", newEntry.EntryNotes); insertCommand.Parameters.AddWithValue("@Rating", newEntry.Rating); insertCommand.Parameters.AddWithValue("@EntryDate", newEntry.EntryDate); insertCommand.ExecuteReader(); db.Close(); }