Exemple #1
0
        /// <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();
        }
Exemple #2
0
        /// <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);
        }
Exemple #3
0
        private TextBlock GetTextBlock(ProductComposition productCompo, SolidColorBrush colorBrush, FontWeight fontWeight, int fontSize = 12)
        {
            DDB     ddb     = new DDB(User.DataBase, User.Username, User.Password);
            Product product = ddb.SelectProduct(new string[] { "ref" }, new string[] { $"'{productCompo.RefProduct}'" })[0];
            string  text    = productCompo.RefProduct;

            if (text.Length > 10)
            {
                string tmp = string.Empty;
                for (int i = 0;
                     i < 10;
                     i++)
                {
                    tmp += text[i];
                }
                text = $"{tmp} ...";
            }
            return(new TextBlock()
            {
                Text = $"{product.Name} {productCompo.Quantity}{product.Unit}",
                Margin = new Thickness(10),
                FontSize = fontSize,
                VerticalAlignment = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Center,
                Background = new SolidColorBrush(Colors.Transparent),
                FontWeight = fontWeight,
                Foreground = colorBrush,
                FontFamily = titleTB.FontFamily
            });
        }
        private void LoadProducts()
        {
            DDB ddb = new DDB(User.DataBase, User.Username, User.Password);

            this._allProducts = ddb.SelectProduct();

            ProductsComboBox.ItemsSource   = this._allProducts;
            ProductsComboBox.SelectedIndex = 0;
        }
Exemple #5
0
        public void ProductSelect()
        {
            DDB ddb = new DDB(User.DataBase, User.Username, User.Password);

            List <Product> products = ddb.SelectProduct();

            ddb.Close();
            Assert.AreEqual(0, products.Count);
        }
Exemple #6
0
        private void LoadProduct()
        {
            DDB            ddb      = new DDB(User.DataBase, User.Username, User.Password);
            List <Product> products = ddb.SelectProduct(new string[] { "quantite_actuelle" }, new string[] { $"quantite_min * 2" }, ">");

            foreach (Product product in products)
            {
                contentStackPanel.Children.Add(GetTextBlock($"{product.Name} current :{product.CurrentQuantity}, min :{product.MinQuantity}", new SolidColorBrush(Colors.Green), FontWeights.Bold));
            }
            ddb.Close();
        }
Exemple #7
0
        private void LoadProduct()
        {
            DDB            ddb      = new DDB(User.DataBase, User.Username, User.Password);
            List <Product> products = ddb.SelectProduct(new string[] { "quantite_actuelle" }, new string[] { $"quantite_min * 2" }, ">");

            ProductComboBox.ItemsSource = products;
            if (products.Count > 0)
            {
                ProductComboBox.SelectedIndex = 0;
            }
            ddb.Close();
        }
Exemple #8
0
        /// <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();
        }
Exemple #9
0
        /// <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)))
                                 )));
            }
        }