Пример #1
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            User.DataBase = "cook";
            User.Username = usernameTB.Text;
            User.Password = passwordTB.Text;
            File.WriteAllLines(User.Path, new string[] { User.DataBase, User.Username, User.Password });

            DDB ddb = new DDB(User.DataBase, User.Username, User.Password);

            //ddb.Command("drop database cook;");
            //ddb.Command($"create database cook;");
            string[] create = File.ReadAllLines("creation.sql");

            foreach (string line in create) //Excute the sql script
            {
                ddb.Command(line);          //creation of the table
            }
            string[] fill = File.ReadAllLines("peuplement.sql");

            foreach (string line in fill)
            {
                ddb.Command(line);                                            //fill the table
            }
            ddb.SelectRecipe().ForEach(x => Stock.UpdateMinMaxQuantities(x)); //a rajouter a moment des commandes
            ddb.SelectRecipe().ForEach(x => Stock.ManageOrder(x));
            Stock.RottenProducts();

            ddb.Close();
            MainWindow mainWindow = Application.Current.Windows.OfType <MainWindow>().FirstOrDefault();

            mainWindow.DataContext = new MainMenu();
        }
Пример #2
0
        private void View()
        {
            DDB ddb = new DDB(User.DataBase, User.Username, User.Password);

            answerTextBlock.Text = ddb.SelectRecipe().Count.ToString();
            ddb.Close();
        }
Пример #3
0
        /// <summary>
        /// Sort the list of recipes depending on the name of the 'sender'
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Sort_Changed(object sender, RoutedEventArgs e)
        {
            DDB           ddb           = new DDB(User.DataBase, User.Username, User.Password);
            List <Recipe> listeRecettes = ddb.SelectRecipe();

            ddb.Close();

            if (((CheckBox)sender).Name.Equals(AlphabetiqueCB.Name))
            {
                listeRecettes.Sort((a, b) => (a.Name.CompareTo(b.Name)));
                NoteCB.IsChecked = false;
                PrixCB.IsChecked = false;
            }
            if (((CheckBox)sender).Name.Equals(NoteCB.Name))
            {
                listeRecettes.Sort((a, b) => (a.Rating.CompareTo(b.Rating)));
                AlphabetiqueCB.IsChecked = false;
                PrixCB.IsChecked         = false;
            }
            if (((CheckBox)sender).Name.Equals(PrixCB.Name))
            {
                listeRecettes.Sort((a, b) => (a.Price.CompareTo(b.Price)));
                NoteCB.IsChecked         = false;
                AlphabetiqueCB.IsChecked = false;
            }

            DataContext = new RecipesViewer(listeRecettes);
        }
Пример #4
0
        public MainMenu()
        {
            InitializeComponent();
            LoadSettings();
            CDRButton.Visibility    = User.ConnectedClient != null ? Visibility.Visible : Visibility.Hidden;
            BaksetButton.Visibility = User.ConnectedClient != null ? Visibility.Visible : Visibility.Hidden;
            //DataContext = new WelcomePage();
            DDB ddb = new DDB(User.DataBase, User.Username, User.Password);

            if (ddb.IsOpen)
            {
                DataContext = new RecipesViewer(ddb.SelectRecipe());
                if (User.ConnectedClient != null)
                {
                    ClientTextBlock.Text = User.ConnectedClient.Name;
                    //ClientButton.IsEnabled = false; if we want to disconnect from the client account
                }
            }
            else
            {
                DemoButton.Visibility   = Visibility.Hidden;
                UserGrid.Visibility     = Visibility.Hidden;
                FilterBorder.Visibility = Visibility.Hidden;
                DataContext             = new BDDLogin();
            }
        }
Пример #5
0
        public void RecipeSelect()
        {
            DDB ddb = new DDB(User.DataBase, User.Username, User.Password);

            List <Recipe> recipes = ddb.SelectRecipe();

            ddb.Close();
            Assert.AreEqual(0, recipes.Count);
        }
Пример #6
0
        private void LoadRecipeComboBox()
        {
            DDB           ddb     = new DDB(User.DataBase, User.Username, User.Password);
            List <Recipe> recipes = ddb.SelectRecipe();

            if (recipes.Count > 0)
            {
                recipeCB.ItemsSource   = recipes;
                recipeCB.SelectedIndex = 0;
            }
            ddb.Close();
        }
Пример #7
0
        /// <summary>
        /// Recupere les 5 recettes les plus commandes de tout les temps
        /// </summary>
        /// <param name="nb"> nb de recettes retournees (par defaut 5) (-1 si toutes)</param>
        /// <param name="ofWeek"> si true => 5 meilleurs recettes de la semaine </param>
        /// <returns></returns>
        private List <Recipe> GetTop5Recipes(int nb = 5, bool ofWeek = false)
        {
            ///RECUPERATION DES COMMANDES
            DDB           ddb     = new DDB(User.DataBase, User.Username, User.Password);
            List <Recipe> recipes = ddb.SelectRecipe(); // recupere toutes les recettes

            List <Order> orders = new List <Order>();   // recupere les commandes

            if (ofWeek)                                 // (des 7 derniers jours si true)
            {
                orders = ddb.SelectOrder(new string[] { "date" }, new string[] { "NOW()" }, "BETWEEN DATE_SUB(NOW(), INTERVAL 7 DAY) AND");
            }
            else
            {
                orders = ddb.SelectOrder();         // (sinon de tout)
            }
            ddb.Close();

            ///CALCUL DU NOMBRE DE FOIS QUE CHAQUE RECETTES A ETE COMMANDE
            List <List <int> > compteur = new List <List <int> >(); // compteur sur le nombre d apparitions de chaque recette

            //      [nombre d'apparition][indexe recette (par rapport a liste recipe)]
            // [0] (exemple:    3                       0
            // [1]              2                       1   )
            // ...
            for (int i = 0; i < recipes.Count; i++)
            {
                compteur.Add(new List <int>());
                compteur[i].Add(0);  // compteur (debut 0)
                compteur[i].Add(i);  // indexe recette
                for (int j = 0; j < orders.Count; j++)
                {
                    if (recipes[i].Name.Equals(orders[j].RecipeName))   // si on trouve une recette dans les commandes
                    {
                        compteur[i][0] += 1;                            // compteur + 1
                    }
                }
            }
            compteur.Sort((a, b) => (a[0].CompareTo(b[0]))); // on trie la colonne par rapport a la colonne des compteurs  ([0])
            compteur.Reverse();                              // on dispose les resultats dans l ordre decroissant

            ///RECUPERATION DES MEILLEURS RECETTES
            nb = (nb == -1) ? compteur.Count() : nb;    // recupere la de nb (si nb==-1  nb = le nombre total de recettes)
            List <Recipe> top5 = new List <Recipe>();

            for (int i = 0; i < nb; i++)                // on garde seulement les 'nb' premieres recettes
            {
                top5.Add(recipes[compteur[i][1]]);
            }

            return(top5);
        }
Пример #8
0
        private void InitilizationRecipes()
        {
            RecipeStackPanel.Children.Clear();
            //Get recipes created by the client
            DDB ddb = new DDB(User.DataBase, User.Username, User.Password);

            List <Recipe> recipes = ddb.SelectRecipe(new string[] { "numeroCreateur" }, new string[] { $"'{this._client.PhoneNumber}'" });

            ddb.Close();
            foreach (Recipe recipe in recipes)
            {
                AddRecipe(recipe);
            }
        }
Пример #9
0
        private void LoadCDR()
        {
            DDB ddb = new DDB(User.DataBase, User.Username, User.Password);
            List <RecipeCreator> recipeCreators = ddb.SelectRecipeCreator();

            foreach (RecipeCreator recipeCreator in recipeCreators)
            {
                string        value   = ddb.SelectClient(new string[] { "numero" }, new string[] { $"'{recipeCreator.Id}'" })[0].Name;
                List <Recipe> recipes = ddb.SelectRecipe(new string[] { "numeroCreateur" }, new string[] { $"'{recipeCreator.Id}'" });
                int           count   = 0;
                foreach (Recipe recipe in recipes)
                {
                    List <Order> orders = ddb.SelectOrder(new string[] { "nomRecette" }, new string[] { $"'{recipe.Name}'" });
                    count += orders.Count;
                }
                value += $" {count}";
                contentStackPanel.Children.Add(GetTextBlock(value, new SolidColorBrush(Colors.Green), FontWeights.Bold));
            }
            ddb.Close();
        }
Пример #10
0
        /// <summary>
        /// Filter the list of recipes by looking at which checkboxes are checked
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Filter_CheckedChanged(object sender, RoutedEventArgs e)
        {
            List <Recipe> recettesFiltrees;
            List <string> colonnesAfiltrer = new List <string>();
            List <string> valeurscolonnes  = new List <string>();

            if (HealthyCB?.IsChecked == true)
            {
                colonnesAfiltrer.Add("estHealthy");
                valeurscolonnes.Add("true");
            }
            if (BioCB?.IsChecked == true)
            {
                colonnesAfiltrer.Add("estBio");
                valeurscolonnes.Add("true");
            }
            if (VeganCB?.IsChecked == true)
            {
                colonnesAfiltrer.Add("estVegan");
                valeurscolonnes.Add("true");
            }
            if (ChimiqueCB?.IsChecked == true)
            {
                colonnesAfiltrer.Add("estChimique");
                valeurscolonnes.Add("true");
            }
            if (TendanceCB?.IsChecked == true)
            {
                colonnesAfiltrer.Add("estTendance");
                valeurscolonnes.Add("true");
            }

            DDB ddb = new DDB(User.DataBase, User.Username, User.Password);

            recettesFiltrees = ddb.SelectRecipe(colonnesAfiltrer.ToArray(), valeurscolonnes.ToArray());
            ddb.Close();

            DataContext = new RecipesViewer(recettesFiltrees);
            // recettesFiltrees
        }
Пример #11
0
        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();
        }
Пример #12
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)))
                                 )));
            }
        }
Пример #13
0
        /// <summary>
        /// Recupere les 5 meilleurs cdr de tout les temps
        /// </summary>
        /// <param name="nb"> nb de cdr retournees (par defaut 5) (-1 si toutes)</param>
        /// <param name="ofWeek"> si true => 5 meilleurs cdr de la semaine </param>
        /// <returns></returns>
        private List <RecipeCreator> GetTop5BestCDR(int nb = 5, bool ofWeek = false)
        {
            DDB ddb = new DDB();

            List <RecipeCreator> listCdr = ddb.SelectRecipeCreator();  // recupere tout les cdr


            List <Order> orders = new List <Order>();   // recupere les commandes (de la derniere semaine si necessaire)

            if (ofWeek)
            {
                orders = ddb.SelectOrder(new string[] { "date" }, new string[] { "NOW()" }, "BETWEEN DATE_SUB(NOW(), INTERVAL 7 DAY) AND");
            }
            else
            {
                orders = ddb.SelectOrder();
            }

            List <int[]> compteur = new List <int[]>(); // compteur stockant le nombre de recettes comandes par cdr

            for (int i = 0; i < listCdr.Count; i++)
            {
                compteur.Add(new int[] { 0, i });
                List <Recipe> listRecipes = ddb.SelectRecipe(new string[] { "numeroCreateur" }, new string[] { $"{listCdr[i].Id}" });

                foreach (Order order in orders)
                {
                    if (ContainRecipe(listRecipes, order))
                    {
                        compteur[i][0]++;
                    }
                }
            }
            compteur.Sort((a, b) => (a[0].CompareTo(b[0])));
            compteur.Reverse();

            nb = (nb == -1) ? compteur.Count() : nb;
            List <RecipeCreator> top5 = new List <RecipeCreator>();

            for (int i = 0; i < nb; i++)  // recupere le nombre de cdr necessaire
            {
                top5.Add(listCdr[compteur[i][1]]);
            }


            ddb.Close();

            return(top5);


            bool ContainRecipe(List <Recipe> list, Order o)
            {
                foreach (Recipe r in list)
                {
                    if (r.Name.Equals(o.RecipeName))
                    {
                        return(true);
                    }
                }
                return(false);
            }
        }