public List <Product> GetAllProducten(OrderAllProducten oap = OrderAllProducten.ALLES, int cat = -1, int merk = -1, int limiet = 6, bool nonactive = false) { List <Product> producten = new List <Product>(); try { conn.Open(); String order = null; String con = null; String act = null; bool actief = true; if (oap == OrderAllProducten.RANDOM) { order = "RAND()"; } else if (oap == OrderAllProducten.ALLES) { order = "1"; } if (merk > 0) { con += " AND Merk_ID=" + merk; } if (cat > 0) { con += " AND Categorie_ID=" + cat; } if (!nonactive) { act = " AND Actief='Y'"; } string select = @"SELECT * FROM tbl_product WHERE 1=1 " + con + act + " ORDER BY " + order + " LIMIT " + limiet; MySqlCommand cmd = new MySqlCommand(select, conn); MySqlDataReader datareader = cmd.ExecuteReader(); while (datareader.Read()) { int productID = datareader.GetInt16("Product_ID"); string productnaam = datareader.GetString("Productnaam"); string beschrijving = datareader.GetString("Beschrijving"); double prijs = datareader.GetDouble("Prijs"); int voorraad = datareader.GetInt16("Voorraad"); if (nonactive) { string tmp = datareader.GetString("Actief"); if (tmp.Equals("Y")) { actief = true; } else if (tmp.Equals("N")) { actief = false; } } string image; if (datareader.IsDBNull(10)) { image = "no_image.png"; } else { image = datareader.GetString("Image"); } Product product = new Product { ID = productID, Naam = productnaam, Beschrijving = beschrijving, Prijs = prijs, Voorraad = voorraad, Image = image, Actief = actief }; producten.Add(product); } return(producten); } catch (Exception e) { Console.WriteLine("ProductDBController GetAllProducten() " + e); return(null); } finally { conn.Close(); } }
public List<Product> GetAllProducten(OrderAllProducten oap = OrderAllProducten.ALLES, int cat = -1, int merk = -1, int limiet = 6, bool nonactive = false) { List<Product> producten = new List<Product>(); try { conn.Open(); String order = null; String con = null; String act = null; bool actief = true; if (oap == OrderAllProducten.RANDOM) { order = "RAND()"; } else if (oap == OrderAllProducten.ALLES) { order = "1"; } if (merk > 0) { con += " AND Merk_ID=" + merk; } if (cat > 0) { con += " AND Categorie_ID=" + cat; } if (!nonactive) { act = " AND Actief='Y'"; } string select = @"SELECT * FROM tbl_product WHERE 1=1 " + con + act + " ORDER BY " + order + " LIMIT " + limiet; MySqlCommand cmd = new MySqlCommand(select, conn); MySqlDataReader datareader = cmd.ExecuteReader(); while (datareader.Read()) { int productID = datareader.GetInt16("Product_ID"); string productnaam = datareader.GetString("Productnaam"); string beschrijving = datareader.GetString("Beschrijving"); double prijs = datareader.GetDouble("Prijs"); int voorraad = datareader.GetInt16("Voorraad"); if (nonactive) { string tmp = datareader.GetString("Actief"); if (tmp.Equals("Y")) { actief = true; } else if (tmp.Equals("N")) { actief = false; } } string image; if (datareader.IsDBNull(10)) { image = "no_image.png"; } else { image = datareader.GetString("Image"); } Product product = new Product { ID = productID, Naam = productnaam, Beschrijving = beschrijving, Prijs = prijs, Voorraad = voorraad, Image = image, Actief = actief }; producten.Add(product); } return producten; } catch (Exception e) { Console.WriteLine("ProductDBController GetAllProducten() " + e); return null; } finally { conn.Close(); } }