public void DeletePosition(int OrderIDKEY) { AddToOrderDTO addtoorder = new AddToOrderDTO(); addtoorder.OrderIDKEY = Convert.ToInt32(Console.ReadLine()); Console.WriteLine($"Deleting position OrderIDKey: {addtoorder.OrderIDKEY}"); _addtoorderDAL.DeleteAddToOrder(addtoorder.OrderIDKEY); }
//adds one order position to order public AddToOrderDTO CreateAddToOrder(AddToOrderDTO addtoorder) { using (SqlConnection conn = new SqlConnection(this.connectionString)) using (SqlCommand comm = conn.CreateCommand()) { comm.CommandText = "insert into AddToOrder (OrderIDKEY, ItemIDKEY, Amount) values (@OrderIDKEY, @ItemIDKEY, @OAmount)"; comm.Parameters.Clear(); comm.Parameters.AddWithValue("@OrderIDKEY", addtoorder.OrderIDKEY); comm.Parameters.AddWithValue("@ItemIDKEY", addtoorder.ItemIDKEY); comm.Parameters.AddWithValue("@Amount", addtoorder.Amount); conn.Open(); return(addtoorder); } }
public AddToOrderDTO AddPosition(AddToOrderDTO addtoorder) { Console.WriteLine("ENTER ORDER ID, ITEM ID, AMOUNT TO ADD TO ORDER"); addtoorder = new AddToOrderDTO { OrderIDKEY = Convert.ToInt32(Console.ReadLine()), ItemIDKEY = Convert.ToInt32(Console.ReadLine()), Amount = Convert.ToInt32(Console.ReadLine()) }; return(_addtoorderDAL.CreateAddToOrder(addtoorder)); }
public void CreateAddToOrderTest() { AddToOrderDAL dal = new AddToOrderDAL(ConfigurationManager.ConnectionStrings["Shipper"].ConnectionString); var result = new AddToOrderDTO { OrderIDKEY = 5, ItemIDKEY = 1, Amount = 28 }; result = dal.CreateAddToOrder(result); Assert.IsTrue(result.OrderIDKEY == 5 && result.ItemIDKEY == 1, "AddToOrder was not created"); }
private void newPositionButton_Click(object sender, EventArgs e) { try { AddToOrderDTO position = new AddToOrderDTO { OrderIDKEY = _orderID, ItemIDKEY = Convert.ToInt32(ItemIDOrder.Text), Amount = Convert.ToInt32(AmountOrder.Text) }; _customer.AddPosition(position); ItemIDOrder.Clear(); AmountOrder.Clear(); } catch { MessageBox.Show("Invalid data"); } }
public AddToOrderDTO AddToOrder(AddToOrderDTO addtoorder) { throw new NotImplementedException(); }
//Update Order: Completes Order and marks it as COMPLETED public OrderDTO PackOrder(int OrderID) { double price = 0; int stock = 0; AddToOrderDTO orderitem = new AddToOrderDTO(); ItemDTO item = new ItemDTO(); OrderDTO order = new OrderDTO(); ItemDAL dal = new ItemDAL(ConfigurationManager.ConnectionStrings["Shipper"].ConnectionString); OrderDAL dal1 = new OrderDAL(ConfigurationManager.ConnectionStrings["Shipper"].ConnectionString); using (SqlConnection conn = new SqlConnection(this.connectionString)) using (SqlCommand comm = conn.CreateCommand()) { comm.CommandText = "select * from AddToOrder where OrderIDKEY=@OrderIDKEY"; comm.Parameters.AddWithValue("@OrderIDKey", OrderID); conn.Open(); SqlDataReader reader = comm.ExecuteReader(); List <AddToOrderDTO> orderitems = new List <AddToOrderDTO>(); while (reader.Read()) { orderitems.Add(new AddToOrderDTO { OrderIDKEY = Convert.ToInt32(reader["OrderIDKEY"]), ItemIDKEY = Convert.ToInt32(reader["ItemIDKEY"]), Amount = Convert.ToInt32(reader["Amount"]), }); } for (int i = 0; i < orderitems.Count; i++) { if (orderitems[i].Amount > dal.GetItemById(orderitems[i].ItemIDKEY).OnStock) { break; } else { stock = dal.GetItemById(orderitems[i].ItemIDKEY).OnStock - orderitems[i].Amount; price = dal1.GetOrderById(orderitems[i].OrderIDKEY).Price + orderitems[i].Amount * dal.GetItemById(orderitems[i].ItemIDKEY).Price; item = new ItemDTO { ItemID = dal.GetItemById(orderitems[i].ItemIDKEY).ItemID, Name = dal.GetItemById(orderitems[i].ItemIDKEY).Name, Price = dal.GetItemById(orderitems[i].ItemIDKEY).Price, OnStock = stock }; dal.UpdateItem(item); } } } OrderDAL dal2 = new OrderDAL(ConfigurationManager.ConnectionStrings["Shipper"].ConnectionString); order = new OrderDTO { OrderID = OrderID, Price = price, Comment = "Completed" }; using (SqlConnection conn1 = new SqlConnection(this.connectionString)) using (SqlCommand comm1 = conn1.CreateCommand()) { comm1.CommandText = "update [Order] set Price= @Price, Comment=@Comment where OrderID = @OrderID"; comm1.Parameters.Clear(); comm1.Parameters.AddWithValue("@OrderID", order.OrderID); comm1.Parameters.AddWithValue("@Price", order.Price); comm1.Parameters.AddWithValue("@Comment", order.Comment); conn1.Open(); order.OrderID = Convert.ToInt32(comm1.ExecuteScalar()); } return(order); }
public AddToOrderDTO AddPosition(AddToOrderDTO addtoorder) { return(_addtoorderDAL.CreateAddToOrder(addtoorder)); }