public List<OrderViewModel> GetProductenPerOrder(int oid) { List<OrderViewModel> orders = new List<OrderViewModel>(); try { conn.Open(); string select = @"select * from tbl_orderregel orr join tbl_product p on orr.product_id = p.product_id join tbl_order o on orr.order_id = o.order_id where o.order_id = @id"; MySqlCommand cmd = new MySqlCommand(select, conn); MySqlParameter idParam = new MySqlParameter("@id", MySqlDbType.Int32); idParam.Value = oid; cmd.Parameters.Add(idParam); MySqlDataReader datareader = cmd.ExecuteReader(); while (datareader.Read()) { Product productnaam = new Product(); int id = datareader.GetInt16("order_id"); double totaal = datareader.GetDouble("totaal"); int gebruiker = datareader.GetInt16("gebruiker_id"); Order order = new Order { ID = id, Totaal = totaal, StrStatus = "..", aantalProducten = 0, Gebruiker = gebruiker }; int productID = datareader.GetInt16("Product_ID"); int aantal = datareader.GetInt16("Aantal"); double subtotaal = datareader.GetDouble("Subtotaal"); productnaam = productdbcontroller.GetProduct(productID); OrderRegel orderregel = new OrderRegel { ProductID = productID, OrderID = oid, ProductNaam = productnaam.Naam, Aantal = aantal, Subtotaal = subtotaal }; OrderViewModel orderview = new OrderViewModel { Order = order, Orderregel = orderregel }; orders.Add(orderview); } return orders; } catch (Exception e) { return null; } finally { conn.Close(); } }
public List<OrderRegel> GetAllOrderRegels(int oid) { List<OrderRegel> orderregellist = new List<OrderRegel>(); try { conn.Open(); string select = @"SELECT * FROM tbl_orderregel WHERE Order_ID='" + oid + "'"; MySqlCommand cmd = new MySqlCommand(select, conn); MySqlDataReader datareader = cmd.ExecuteReader(); while (datareader.Read()) { Product productnaam = new Product(); int productID = datareader.GetInt16("Product_ID"); int aantal = datareader.GetInt16("Aantal"); double totaal = datareader.GetDouble("Subtotaal"); productnaam = productdbcontroller.GetProduct(productID); OrderRegel orderregel = new OrderRegel { ProductID = productID, OrderID = oid, ProductNaam = productnaam.Naam, Aantal = aantal, Subtotaal = totaal }; orderregellist.Add(orderregel); } return orderregellist; } catch (Exception e) { Console.WriteLine("ProductDBController GetAllProducten() " + e); return null; } finally { conn.Close(); } }