예제 #1
0
        /// <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();
        }
예제 #2
0
        private void BuyButton_Click(object sender, RoutedEventArgs e)
        {
            //Do command
            int count = 0;

            Basket.Recipes.ForEach(x => count += x.Price);
            if (count <= User.ConnectedClient.Money) // if the user has enough money
            {
                if (Stock.IsPossible(Basket.Recipes))
                {
                    foreach (Recipe recipe in Basket.Recipes)
                    {
                        Order order = new Order(Guid.NewGuid().ToString(), DateTime.Now, User.ConnectedClient.PhoneNumber, recipe.Name);
                        DDB   ddb   = new DDB(User.DataBase, User.Username, User.Password);
                        ddb.Insert <Order>(order);
                        Stock.ManageOrder(recipe, true);
                    }
                    DDB ddb1 = new DDB(User.DataBase, User.Username, User.Password);
                    Basket.Recipes.Clear();
                    User.ConnectedClient.Money -= count;
                    MainWindow mainWindow = Application.Current.Windows.OfType <MainWindow>().FirstOrDefault();
                    mainWindow.DataContext = new MainMenu();
                    ddb1.UpdateClient(User.ConnectedClient, new string[] { "nom" }, new string[] { $"'{User.ConnectedClient.Name}'" });
                    PopUp popUp = new PopUp("Commande passé", "Vous allez être livrer bientôt");
                    popUp.ShowDialog();
                }
                else
                {
                    //not enough stock
                    PopUp popUp = new PopUp("Panier incorrect", "Les produits ne sont pas disponibles.");
                    popUp.ShowDialog();
                }
            }
            else
            {
                //not enough money
                PopUp popUp = new PopUp("Achat impossible", "Vous n'avez pas assez d'argent sur votre compte.");
                popUp.ShowDialog();
            }
        }