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; } }
private List<OrderItem> getOrderItems(int orderId) { using (OleDbConnection sqlConn = new OleDbConnection(database)) { List<OrderItem> orderItems = new List<OrderItem>(); try { sqlConn.Open(); OleDbCommand cmd = sqlConn.CreateCommand(); String select = "SELECT * FROM [ORDER_ITEMS] WHERE [order_id] = @orderId"; cmd.CommandText = select; cmd.Parameters.Add("orderId", OleDbType.Integer).Value = orderId; OleDbDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { OrderItem orderItem = new OrderItem(); orderItem.setOrderId((int)reader["order_id"]); orderItem.setProductId((int)reader["product_id"]); orderItem.setCount((int)reader["count"]); orderItem.setSalePrice(Double.Parse(reader["sale_price"].ToString(), NumberStyles.Currency)); orderItems.Add(orderItem); } return orderItems; } catch (OleDbException ex) { orderItems = null; return orderItems; } finally { sqlConn.Close(); } } }
public int addOrderItem(OrderItem orderItem) { orderItems.Add(orderItem); return this.getOrderItemsCount(); }
public int removeOrderItem(OrderItem orderItem) { orderItems.Remove(orderItem); return this.getOrderItemsCount(); }