/// <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); }
private void OkButton_Click(object sender, RoutedEventArgs e) { DDB ddb = new DDB(User.DataBase, User.Username, User.Password); if (ddb.SelectRecipeCreator(new string[] { "numero" }, new string[] { $"'{User.ConnectedClient.PhoneNumber}'" }).Count == 0) //if is not a cdr { ddb.InsertRecipeCreator(User.ConnectedClient.PhoneNumber); } DoubleContainer <string, RecipeType> recipeType = CategoryComboBox.SelectedItem as DoubleContainer <string, RecipeType>; ddb.InsertRecipe(NameTextBox.Text, recipeType.OtherValue, DescTextBox.Text, User.ConnectedClient.PhoneNumber, Convert.ToInt32(PriceCB.SelectedValue), HealthyCB.IsChecked == true ? true : false, BioCB.IsChecked == true ? true : false, VeganCB.IsChecked == true ? true : false, ChimiCB.IsChecked == true ? true : false); //operator ter because it's bool? not bool foreach (DoubleContainer <Product, ProductComposition> productComposition in this._products) // if the user change the name after adding the product composition { productComposition.OtherValue.RecipeName = NameTextBox.Text; ddb.Insert <ProductComposition>(productComposition.OtherValue); } ddb.Close(); MainWindow mainWindow = Application.Current.Windows.OfType <MainWindow>().FirstOrDefault(); mainWindow.DataContext = new MainMenu(); }
/// <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(); }
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(); }
/// <summary> /// Recupere les 5 meilleurs recettes du meilleur cdr /// </summary> /// <param name="nb"></param> /// <returns></returns> private List <Recipe> GetTop5RecipesOfBestCdr(int nb = 5, bool ofWeek = false) { RecipeCreator bestCdr = GetTop5BestCDR(1, ofWeek).First(); // recupere le meilleur cdr DDB ddb = new DDB(User.DataBase, User.Username, User.Password); BestCDRAllTB.Text = ddb.SelectClient(new string[] { "numero" }, new string[] { $"'{bestCdr.Id}'" })[0].Name; List <Recipe> recipes = GetTop5Recipes(-1); // recupere les meilleurs recettes List <Recipe> top5RecipesOfBestCdr = new List <Recipe>(); ddb.Close(); nb = (nb == -1) ? recipes.Count() : nb; int cpt = 0; while (top5RecipesOfBestCdr.Count < nb && cpt < recipes.Count) // recupre les nb premieres { if (recipes[cpt].NumberCreator.Equals(bestCdr.Id)) { top5RecipesOfBestCdr.Add(recipes[cpt]); } cpt++; } return(top5RecipesOfBestCdr); }
/// <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); }
private void View() { DDB ddb = new DDB(User.DataBase, User.Username, User.Password); answerTextBlock.Text = ddb.SelectRecipe().Count.ToString(); ddb.Close(); }
private int GetOrder(string recipeName) { DDB ddb = new DDB(User.DataBase, User.Username, User.Password); int nbOrders = ddb.SelectOrder(new string[] { "nomRecette" }, new string[] { $"'{recipeName}'" }).Count(); ddb.Close(); return(nbOrders); }
private Client GetClient(string numberCreator) { DDB ddb = new DDB(User.DataBase, User.Username, User.Password); Client client = ddb.SelectClient(new string[] { "numero" }, new string[] { $"'{numberCreator}'" })[0]; ddb.Close(); return(client); }
private void FillCDROfTheWeek() { RecipeCreator bestCdrOfWeek = GetTop5BestCDR(1, true).First(); DDB ddb = new DDB(); CDRWeekTB.Text = ddb.SelectClient(new string[] { "numero" }, new string[] { $"'{bestCdrOfWeek.Id}'" }).First().Name; ddb.Close(); }
public void ClientSelect() { DDB ddb = new DDB(User.DataBase, User.Username, User.Password); List <Client> clients = ddb.SelectClient(); ddb.Close(); Assert.AreEqual(0, clients.Count); }
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); }
public void SupplierSelect() { DDB ddb = new DDB(User.DataBase, User.Username, User.Password); List <Supplier> suppliers = ddb.SelectSupplier(); ddb.Close(); Assert.AreEqual(0, suppliers.Count); }
public void CDRSelect() { DDB ddb = new DDB(User.DataBase, User.Username, User.Password); List <RecipeCreator> cdrs = ddb.SelectRecipeCreator(); ddb.Close(); Assert.AreEqual(0, cdrs.Count); }
public void OrderSelect() { DDB ddb = new DDB(User.DataBase, User.Username, User.Password); List <Order> orders = ddb.SelectOrder(); ddb.Close(); Assert.AreEqual(0, orders.Count); }
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); }
public ClientInformation() { this._client = User.ConnectedClient; InitializeComponent(); InitilizationRecipes(); DDB ddb = new DDB(User.DataBase, User.Username, User.Password); cdrGrid.Visibility = ddb.SelectRecipeCreator(new string[] { "numero" }, new string[] { $"'{this._client.PhoneNumber}'" }).Count > 0 ? Visibility.Visible : Visibility.Hidden; ddb.Close(); }
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(); }
/// <summary> /// Pay the creator of the recipe /// </summary> /// <param name="recipe"></param> private static void PayingCDR(Recipe recipe) { DDB ddB = new DDB(User.DataBase, User.Username, User.Password); RecipeCreator recipeCreator = ddB.SelectRecipeCreator(new string[] { "numero" }, new string[] { $"'{recipe.NumberCreator}'" })[0]; Client client = ddB.SelectClient(new string[] { "numero" }, new string[] { $"'{recipeCreator.Id}'" })[0]; client.Money += recipe.IsTrending ? 4 : 2; ddB.UpdateClient(client, new string[] { "nom" }, new string[] { $"'{client}'" }); ddB.Close(); }
private void RecipeButton_Click(object sender, RoutedEventArgs e) { Recipe recipe = recipeCB.SelectedItem as Recipe; DDB ddb = new DDB(User.DataBase, User.Username, User.Password); ddb.DeleteRecipe(recipe); ddb.Close(); LoadComboBox(); FillGridTop5(); FillGridTopCDR(); FillCDROfTheWeek(); }
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(); }
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(); }
/// <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); }
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); } }
private void CdrButton_Click(object sender, RoutedEventArgs e) { Client client = cdrCB.SelectedItem as Client; DDB ddb = new DDB(User.DataBase, User.Username, User.Password); RecipeCreator recipeCreator = ddb.SelectRecipeCreator(new string[] { "numero" }, new string[] { $"'{client.PhoneNumber}'" })[0]; ddb.DeleteRecipeCreator(recipeCreator); ddb.Close(); LoadComboBox(); FillGridTop5(); FillGridTopCDR(); FillCDROfTheWeek(); }
/// <summary> /// Le produit commande est consomme /// </summary> /// <param name="product"></param> /// <param name="productsComposition"></param> private static void ConsumeProduct(Product product, List <ProductComposition> productsComposition) { ProductComposition productComposition = productsComposition.Find(x => x.RefProduct.Equals(product.Reference)); product.CurrentQuantity -= productComposition.Quantity; if (product.CurrentQuantity < product.MinQuantity) { int quantityNeeded = product.MaxQuantity - product.CurrentQuantity; OrderSuplies(product, quantityNeeded, "plus de stockes"); } DDB ddb = new DDB(); ddb.UpdateProduct(product, new string[] { "ref" }, new string[] { "'" + product.Reference + "'" }); ddb.Close(); }
private void LoadCDRComboBox() { DDB ddb = new DDB(User.DataBase, User.Username, User.Password); List <Client> clients = new List <Client>(); List <RecipeCreator> recipeCreators = ddb.SelectRecipeCreator(); foreach (RecipeCreator recipeCreator in recipeCreators) { clients.Add(ddb.SelectClient(new string[] { "numero" }, new string[] { $"'{recipeCreator.Id}'" })[0]); } if (clients.Count > 0) { cdrCB.ItemsSource = clients; cdrCB.SelectedIndex = 0; } ddb.Close(); }
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(); }
/// <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 }
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(); }