public static void addItemToCart(InventoryItem item) { List<InventoryItem> items = (List<InventoryItem>)HttpContext.Current.Session[USER_CART]; if (items != null) { items.Add(item); HttpContext.Current.Session[USER_CART] = items; } else { items = new List<InventoryItem>(); items.Add(item); HttpContext.Current.Session[USER_CART] = items; } }
public Boolean addItemToOrder(InventoryItem inventoryItem, int count) { if (count <= inventoryItem.getProductCount()) { OrderItem orderItem = new OrderItem(); orderItem.setProductId(inventoryItem.getInventoryId()); orderItem.setCount(count); orderItem.setSalePrice(inventoryItem.getSalePrice()); orderItems.Add(orderItem); inventoryItem.orderItem(count); inventoryItems.Add(inventoryItem); return true; } else { return false; } }
public static bool updateInventoryItem(InventoryItem item) { ProductsDAO datalayer = new ProductsDAO(); bool success = datalayer.updateInventoryItem(item); return success; }
public static bool insertNewItem(InventoryItem updateItem) { ProductsDAO datalayer = new ProductsDAO(); bool success = datalayer.insertNewItem(updateItem); return success; }
public string getViewItemHtml(InventoryItem item) { htmlBuilder.Append(getBeginingSingleItemDiv()); htmlBuilder.Append(getItemNameHtml()); htmlBuilder.Append(getImageHtml()); htmlBuilder.Append(getLongItemDescriptionHtml()); htmlBuilder.Append(getPriceDiv()); htmlBuilder.Append(getAddToCartLink()); htmlBuilder.Append(getEndingHtml()); return htmlBuilder.ToString(); }
public InventoryHtmlPrinter(InventoryItem item) { this.item = item; htmlBuilder = new StringBuilder(); }
public InventoryItem getProductByName(String name) { InventoryItem item = new InventoryItem(); using (OleDbConnection sqlconn = new OleDbConnection(database)) { try { sqlconn.Open(); OleDbCommand cmd = sqlconn.CreateCommand(); String select = "SELECT * FROM [INVENTORY_ITEM] WHERE [product_name] = @name"; cmd.CommandText = select; cmd.Parameters.Add("name", OleDbType.VarChar, 255).Value = name; OleDbDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { item = getItemFromReader(reader); } return item; } catch (OleDbException ex) { return item; } finally { sqlconn.Close(); } } }
private InventoryItem getItemFromReader(OleDbDataReader reader) { int inventoryId = (int)reader["inventory_id"]; String productName = (String)reader["product_name"]; int productCount = (int)reader["product_count"]; int itemsOnHold = (int)reader["items_on_hold"]; Double unitPrice = Double.Parse(reader["unit_price"].ToString(), NumberStyles.Currency); Double salePrice = Double.Parse(reader["sale_price"].ToString(), NumberStyles.Currency); String shortDescription = (String)reader["short_description"]; String longDescription = (String)reader["long_description"]; String imagePath = (String)reader["image_path"]; InventoryItem item = new InventoryItem(inventoryId, productName, productCount, itemsOnHold, unitPrice, salePrice, shortDescription, longDescription, imagePath); return item; }
internal bool updateInventoryItem(InventoryItem item) { using (OleDbConnection sqlconn = new OleDbConnection(database)) { try { sqlconn.Open(); OleDbCommand cmd = sqlconn.CreateCommand(); String update = "UPDATE [INVENTORY_ITEM] SET " + "[product_name] = @productName, " + "[product_count] = @productCount, " + "[items_on_hold] = @itemsOnHold, " + "[unit_price] = @unitPrice, " + "[sale_price] = @salePrice, " + "[short_description] = @shortDescription, " + "[long_description] = @longDescription, " + "[image_path] = @imagePath " + "WHERE [inventory_id] = @inventoryId"; cmd.CommandText = update; cmd.Parameters.Add("productName", OleDbType.VarChar, 255).Value = item.getProductName(); cmd.Parameters.Add("productCount", OleDbType.Integer).Value = item.getProductCount(); cmd.Parameters.Add("itemsOnHold", OleDbType.Integer).Value = item.getItemsOnHold(); cmd.Parameters.Add("unitPrice", OleDbType.Currency).Value = item.getUnitPrice(); cmd.Parameters.Add("salePrice", OleDbType.Currency).Value = item.getSalePrice(); cmd.Parameters.Add("shortDescription", OleDbType.VarChar, 255).Value = item.getShortDescription(); cmd.Parameters.Add("longDescription", OleDbType.LongVarChar).Value = item.getLongDescription(); cmd.Parameters.Add("imagePath", OleDbType.VarChar, 255).Value = item.getImageUrl(); cmd.Parameters.Add("inventoryId", OleDbType.Integer).Value = item.getInventoryId(); int rows = cmd.ExecuteNonQuery(); return true; } catch(OleDbException ex) { return false; } finally { sqlconn.Close(); } } }
internal bool insertNewItem(InventoryItem updateItem) { using (OleDbConnection sqlconn = new OleDbConnection(database)) { try { sqlconn.Open(); OleDbCommand cmd = sqlconn.CreateCommand(); string insert = "INSERT INTO [INVENTORY_ITEM] ([product_name], [product_count], [items_on_hold], " + "[unit_price], [sale_price], [short_description], [long_description], [image_path]) " + "VALUES (@productName, @productCount, @itemsOnHold, @unitPrice, @salePrice, @shortDescription, @longDescription, @imagePath)"; cmd.CommandText = insert; cmd.Parameters.Add("productName", OleDbType.VarChar, 255).Value = updateItem.getProductName(); cmd.Parameters.Add("productCount", OleDbType.Integer).Value = updateItem.getProductCount(); cmd.Parameters.Add("itemsOnHold", OleDbType.Integer).Value = updateItem.getItemsOnHold(); cmd.Parameters.Add("unitPrice", OleDbType.Currency).Value = updateItem.getUnitPrice(); cmd.Parameters.Add("salePrice", OleDbType.Currency).Value = updateItem.getSalePrice(); cmd.Parameters.Add("shortDescription", OleDbType.VarChar, 255).Value = updateItem.getShortDescription(); cmd.Parameters.Add("longDescription", OleDbType.LongVarChar).Value = updateItem.getLongDescription(); cmd.Parameters.Add("imagePath", OleDbType.VarChar, 255).Value = updateItem.getImageUrl(); int rows = cmd.ExecuteNonQuery(); if (rows == 1) { return true; } else { return false; } } catch (OleDbException ex) { return false; } finally { sqlconn.Close(); } } }