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(); }
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 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(); }
/// <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 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(); }
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> /// 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); } }