/// <summary> /// Returns a list of flavouring objects. the data comes from rows in the flavourings table where inPersonalStash=1. This method might be made more general later. /// </summary> /// <returns></returns> public static ObservableCollection <Flavouring> GetFlavouringData() { ObservableCollection <Flavouring> flavourings = new ObservableCollection <Flavouring>(); string dbpath = Path.Combine(ApplicationData.Current.LocalFolder.Path, "sqliteSample.db"); using (SqliteConnection db = new SqliteConnection($"Filename={dbpath}")) { db.Open(); SqliteCommand selectCommand = new SqliteCommand ("SELECT name, (SELECT name FROM companies WHERE companies.idNumbC=flavourings.companyName_FK)," + "versionNumber FROM flavourings WHERE inPersonalStash=1", db); //SqliteCommand selectCommand = new SqliteCommand(selectCommand, db); SqliteDataReader query = selectCommand.ExecuteReader(); while (query.Read()) { Flavouring tempFlavour = new Flavouring(); tempFlavour.Name = query.GetString(0); tempFlavour.CompanyManufacturer = query.GetString(1); tempFlavour.VersionNumber = query.GetInt32(2); flavourings.Add(tempFlavour); } } return(flavourings); }
public void TestFlavouringOverload() { //Testing the overloaded Flavouring constructor Flavouring tempFlavouring = new Flavouring("Apple", 1, true, "Capella"); Boolean expectedBool = true; Assert.AreEqual(expectedBool, tempFlavouring.InPersonalStash); }
public void TestFlavouring() { //Testing the parameter-less constuctor Flavouring tempFlavouring = new Flavouring(); tempFlavouring.Name = "Apple"; string expectedString = "Apple"; Assert.AreEqual(expectedString, tempFlavouring.Name); }
private void addFlavourButton_Click(object sender, RoutedEventArgs e) { if (String.IsNullOrEmpty(nameOfFlavourInput.Text) || String.IsNullOrEmpty(companyInput.Text) || String.IsNullOrEmpty(versionNumberInput.Text)) { userInfo.Text = "You must enter full details of a flavouring to save it."; } else { Flavouring userAddedFlavouring = new Flavouring(nameOfFlavourInput.Text, Convert.ToInt32(versionNumberInput.Text), true, companyInput.Text); Flavourings.Add(userAddedFlavouring); personalStashList.ItemsSource = Flavourings; } }
/// <summary> /// Removes an item from the personal stash list. The removal is not persistant due to the database being populated every time the app starts. /// See https://docs.microsoft.com/en-us/windows/uwp/get-started/settings-learning-track to maybe make this persistant. /// Removing an item from the personal stash then navigating to a different page and then back to the personal stash page and attempting to remove another item /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void removeFlavourFromStash(object sender, RoutedEventArgs e) { Flavouring flavourToRemove = (Flavouring)personalStashList.SelectedItem; //Remove flavouring from Flavourings list Flavourings.Remove(flavourToRemove); //Set inPersonalStash variable in flavourings table to 0 DatabaseClasses.DataAccess.removeFromPersonalStash(flavourToRemove.Name); /*Removing an item from the personal stash then navigating to a different page and then back to the personal stash page and attempting to remove another item * sometimes throws a null pointer exception */ }