/// <summary> /// Deletes a Shoplist item from the ShopListItem table. /// </summary> /// <param name="shopList"></param> /// <param name="item"></param> /// <returns> /// Returns a Tuple<bool, string> with a processing message. /// </returns> public static Tuple <bool, string> DeleteShopListItem(ShopList shopList, ShopListItem item) { Tuple <bool, string> result = new Tuple <bool, string>(false, ""); using (SQLiteConnection connection = new SQLiteConnection(LoadConnectionString())) { try { if (SADatabaseReader.DoesShopListItemExist((int)shopList.SHOPLISTID, item)) { connection.Execute($"DELETE FROM ShopListItem WHERE ShopList_ID = {shopList.SHOPLISTID} AND ShopListProduct_ID = {item.ShopListProductID}"); result = new Tuple <bool, string>(true, $"ShopList item {item.ProductName}({item.ShopListProductID}) succesvol verwijderd."); } else { result = new Tuple <bool, string>(false, $"ShopList item {item.ProductName}({item.ShopListProductID}) bestaat niet."); } } catch (SQLiteException ex) { // TODO : SADatabaseReader.DeleteShopListItem: Error logging naar log.db throw; } } return(result); }
/// <summary> /// Saves or updates a shopList item in the ShopListItem table. /// </summary> /// <param name="shopList"></param> /// <param name="item"></param> /// <returns> /// Returns a Tuple<bool, string>, with a processing message. /// </returns> public static Tuple <bool, string> SaveShopListItem(ShopList shopList, ShopListItem item) { Tuple <bool, string> result = new Tuple <bool, string>(false, ""); using (SQLiteConnection connection = new SQLiteConnection(LoadConnectionString(), SQLiteOpenFlags.ReadWrite)) { try { if (SADatabaseReader.DoesShopListExist(shopList)) { if (SADatabaseReader.DoesShopListItemExist((int)shopList.SHOPLISTID, item)) { string updateQuery = $"UPDATE ShopListItem SET Unit = {item.Unit}, Amount = {item.Amount}, ItemAcquired = {item.Acquired}, DateTimeModified = '{item.ITEMUPDATED}' " + $"WHERE ShopList_ID = {shopList.SHOPLISTID} AND ShopListProduct_ID = {item.ShopListProductID}"; connection.Execute(updateQuery); result = new Tuple <bool, string>(true, $"ShopList item {item.ShopListProductID} is bijgewerkt."); } else { string insertQuery = "INSERT INTO ShopListItem (ShopList_ID, ShopListProduct_ID, Unit, Amount, ItemAcquired, DateTimeAdded) " + $"VALUES ({shopList.SHOPLISTID}, {item.ShopListProductID}, {item.Unit}, {item.Amount}, {item.Acquired}, '{item.ItemAdded}')"; connection.Execute(insertQuery); result = new Tuple <bool, string>(true, $"ShopList item {item.ShopListProductID} is toegevoegd aan {shopList.Name}({shopList.SHOPLISTID})."); } } else { result = new Tuple <bool, string>(false, $"ShopList {shopList.Name}({shopList.SHOPLISTID}) bestaat niet of is nog niet opgeslagen."); } } catch (SQLiteException ex) { // TODO : SADatabaseReader.SaveShopListItem: Error logging naar log.db throw; } } return(result); }