public void CreateNewItem(int userID) { var dbHelper = new DatabaseHelper(); using (var conn = dbHelper.GetDatabaseConnection()) { using (var command = dbHelper.GetSQLiteCommand(conn)) { string query = "INSERT INTO InventoryItems (Name, Description, PicturePath, Cost, " + "CostCurrencyID, Quantity, BarcodeNumber, CreatedByUserID, ProfitPerItem, ProfitPerItemCurrencyID, ItemTypeID, " + "ItemPurchaseCost, ItemPurchaseCostCurrencyID, ItemsPerPurchase) VALUES " + "(@name, @description, @picturePath, @cost, @costCurrencyID, @quantity, @barcodeNumber, @createdByUserID," + " @profitPerItem, @profitPerItemCurrencyID, @itemTypeID," + " @itemPurchaseCost, @itemPurchaseCostCurrencyID, @itemsPerPurchase)"; command.CommandText = query; command.Parameters.AddWithValue("@name", Name); command.Parameters.AddWithValue("@description", Description); command.Parameters.AddWithValue("@picturePath", PicturePath); command.Parameters.AddWithValue("@cost", Cost.ToString()); command.Parameters.AddWithValue("@costCurrencyID", CostCurrency?.ID); command.Parameters.AddWithValue("@quantity", Quantity); command.Parameters.AddWithValue("@barcodeNumber", BarcodeNumber); command.Parameters.AddWithValue("@createdByUserID", userID); command.Parameters.AddWithValue("@profitPerItem", ProfitPerItem.ToString()); command.Parameters.AddWithValue("@profitPerItemCurrencyID", ProfitPerItemCurrency?.ID); command.Parameters.AddWithValue("@itemTypeID", Type?.ID); command.Parameters.AddWithValue("@itemPurchaseCost", ItemPurchaseCost.ToString()); command.Parameters.AddWithValue("@itemPurchaseCostCurrencyID", ItemPurchaseCostCurrency?.ID); command.Parameters.AddWithValue("@itemsPerPurchase", ItemsPerPurchase); command.ExecuteNonQuery(); ID = (int)conn.LastInsertRowId; conn.Close(); } } }
public void SaveItemUpdates(int userID) { var dbHelper = new DatabaseHelper(); using (var conn = dbHelper.GetDatabaseConnection()) { using (var command = dbHelper.GetSQLiteCommand(conn)) { string query = "UPDATE InventoryItems SET Name = @name, Description = @description, PicturePath = @picturePath, " + "Cost = @cost, CostCurrencyID = @costCurrencyID, BarcodeNumber = @barcodeNumber, " + "CreatedByUserID = @createdByUserID, ProfitPerItem = @profitPerItem, ProfitPerItemCurrencyID = @profitPerItemCurrencyID, " + "ItemTypeID = @itemTypeID " + " WHERE ID = @id"; command.CommandText = query; command.Parameters.AddWithValue("@name", Name); command.Parameters.AddWithValue("@description", Description); command.Parameters.AddWithValue("@picturePath", PicturePath); command.Parameters.AddWithValue("@cost", Cost.ToString()); command.Parameters.AddWithValue("@costCurrencyID", CostCurrency?.ID); command.Parameters.AddWithValue("@barcodeNumber", BarcodeNumber); command.Parameters.AddWithValue("@createdByUserID", userID); command.Parameters.AddWithValue("@profitPerItem", ProfitPerItem.ToString()); command.Parameters.AddWithValue("@profitPerItemCurrencyID", ProfitPerItemCurrency?.ID); command.Parameters.AddWithValue("@itemTypeID", Type?.ID); command.Parameters.AddWithValue("@id", ID); command.ExecuteNonQuery(); conn.Close(); } } }