/// <summary> /// check if the basket can be created (enough product in stock) /// </summary> /// <param name="recipes"></param> /// <returns></returns> public static bool IsPossible(List <Recipe> recipes) { bool isPossible = true; DDB ddB = new DDB(User.DataBase, User.Username, User.Password); List <Product> products = ddB.SelectProduct(); foreach (Recipe recipe in recipes) { List <ProductComposition> productCompositions = ddB.SelectProductComposition(new string[] { "nomRecette" }, new string[] { $"'{recipe.Name}'" }); foreach (ProductComposition productComposition in productCompositions) { Product product = products.FirstOrDefault(x => x.Reference == productComposition.RefProduct); if (product != null) { product.CurrentQuantity -= productComposition.Quantity; if (product.CurrentQuantity < 0) { isPossible = false; } } } } ddB.Close(); return(isPossible); }
/// <summary> /// Method appele a chaque commande. Elle permet de simuler la gestion des stockes /// </summary> /// <param name="recipe"></param> public static void ManageOrder(Recipe recipe, bool isOrder = false) { DDB ddB = new DDB(User.DataBase, User.Username, User.Password); List <ProductComposition> productCompositions = ddB.SelectProductComposition(new string[] { "nomRecette" }, new string[] { "'" + recipe.Name + "'" }); List <Product> products = new List <Product>(); productCompositions.ForEach(p => products.AddRange(ddB.SelectProduct(new string[] { "ref" }, new string[] { "'" + p.RefProduct + "'" }))); products.ForEach(p => ConsumeProduct(p, productCompositions)); if (isOrder) { recipe.Rating++; //equivalent à la notation de la recette à chaque fois que quelqu'un commande on l'incremente if (recipe.Rating == 10) { recipe.Price += 2; } if (recipe.Rating == 50) { recipe.Price += 5; recipe.IsTrending = true; //isTrending = true veut dire que la recette a été commandé plus de 50 fois } ddB.UpdateRecipe(recipe, new string[] { "nom" }, new string[] { $"'{recipe.Name}'" }); PayingCDR(recipe); } ddB.Close(); }
/// <summary> /// Show the recipe products /// </summary> private void InitilizationProduct() { //Request sql for the products DDB ddb = new DDB(User.DataBase, User.Username, User.Password); List <ProductComposition> products = ddb.SelectProductComposition(new string[] { "nomRecette" }, new string[] { $"'{this._recipe.Name}'" }); foreach (ProductComposition product in products) { AddProduct(product); } }
private void ProductComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { Product product = ProductComboBox.SelectedValue as Product; DDB ddb = new DDB(User.DataBase, User.Username, User.Password); List <ProductComposition> productCompositions = ddb.SelectProductComposition(new string[] { "refProduit" }, new string[] { $"'{product.Reference}'" }); List <Recipe> recipes = new List <Recipe>(); foreach (ProductComposition productComposition in productCompositions) { List <Recipe> tmp = ddb.SelectRecipe(new string[] { "nom" }, new string[] { $"'{productComposition.RecipeName}'" }); if (tmp.Count > 0) { recipes.Add(tmp[0]); } } contentStackPanel.Children.Clear(); foreach (Recipe recipe in recipes) { contentStackPanel.Children.Add(GetTextBlock(recipe.Name, new SolidColorBrush(Colors.Green), FontWeights.Bold)); } ddb.Close(); }
/// <summary> /// Change the value of min quantity and max quantity if needed. /// </summary> /// <param name="recipe"></param> public static void UpdateMinMaxQuantities(Recipe recipe) { DDB ddB = new DDB(User.DataBase, User.Username, User.Password); List <ProductComposition> productCompositions = ddB.SelectProductComposition(new string[] { "nomRecette" }, new string[] { "'" + recipe.Name + "'" }); foreach (ProductComposition prodComp in productCompositions) { int quantityConsumed = prodComp.Quantity; Product product = ddB.SelectProduct(new string[] { "ref" }, new string[] { "'" + prodComp.RefProduct + "'" }).First(); if (product.MinQuantity < quantityConsumed) { product.MinQuantity = quantityConsumed; product.MaxQuantity = 20 * quantityConsumed; ddB.UpdateProduct(product, new string[] { "ref" }, new string[] { "'" + product.Reference + "'" }); } } ddB.Close(); }
/// <summary> /// Verifie si il y a des produits qui n'ont pas ete utilises depuis plus de 30 jours /// </summary> /// <returns></returns> public static List <Product> RottenProducts(int jourMax = 30) { DDB ddb = new DDB(); //On recupere toutes les commandes effectuees depuis 30 jours List <Order> orders = ddb.SelectOrder(new string[] { "date" }, new string[] { "NOW()" }, "BETWEEN DATE_SUB(NOW(), INTERVAL 30 DAY) AND"); // . . . recettes effectuees depuis 30 jours List <Recipe> recipes = new List <Recipe>(); orders.ForEach(x => recipes.AddRange(ddb.SelectRecipe(new string[] { "nom" }, new string[] { "'" + x.RecipeName + "'" }))); // . . . produit utilises depuis 30 jours List <ProductComposition> productCompositions = new List <ProductComposition>(); recipes.ForEach(x => productCompositions.AddRange(ddb.SelectProductComposition(new string[] { "nomRecette" }, new string[] { "'" + x.Name + "'" }))); List <Product> products = new List <Product>(); productCompositions.ForEach(x => products.AddRange(ddb.SelectProduct(new string[] { "ref" }, new string[] { "'" + x.RefProduct + "'" }))); // . . . tout les produits List <Product> allProducts = ddb.SelectProduct(); //On soustrait les deux ensembles List <Product> rottenProducts = allProducts.FindAll(x => !Contain(products, x)); foreach (Product rotten in rottenProducts) { if (VerificationRapportCommande(rotten)) { rotten.CurrentQuantity /= 2; if (rotten.CurrentQuantity < rotten.MinQuantity) { int orderQuantity = rotten.MinQuantity - rotten.CurrentQuantity; OrderSuplies(rotten, orderQuantity, "reserves pourries"); ddb.UpdateProduct(rotten, new string[] { "ref" }, new string[] { "'" + rotten.Reference + "'" }); } } } ddb.Close(); return(rottenProducts); bool Contain(List <Product> list, Product prod) { foreach (Product p in list) { if (p.Reference.Equals(prod.Reference)) { return(true); } } return(false); } /// Verifie grace au rapport de commande si le produit na pas deja pourris il y a moins de 1 mois bool VerificationRapportCommande(Product rottenProduct) { XDocument xDocument = XDocument.Load(fichierCommande); XElement root = xDocument.Element("Commandes"); IEnumerable <XElement> rows = root.Descendants("Commande"); return(!rows.Any(product => (product.Descendants().Any (prod => (((((string)prod.Attribute("name")).Equals(rottenProduct.Name)) && (((string)prod.Attribute("cause")).Equals("reserves pourries"))) && (DateTime.Now.Subtract(DateTime.Parse((string)product.Attribute("Date"))).Days < jourMax))) ))); } }