Esempio n. 1
0
        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();
        }
Esempio n. 2
0
 private void Button_Click(object sender, RoutedEventArgs e)
 {
     if (!string.IsNullOrEmpty(numberTB.Text))
     {
         DDB    ddb    = new DDB(User.DataBase, User.Username, User.Password);
         Client client = new Client(this._email, passwordTB.Password, Models.Enums.UserType.user, nameTB.Text, numberTB.Text, adressTB.Text);
         User.ConnectedClient = client;
         ddb.Insert <Client>(client);
         MainWindow mainWindow = Application.Current.Windows.OfType <MainWindow>().FirstOrDefault();
         mainWindow.DataContext = new MainMenu();
     }
 }
Esempio n. 3
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();
            }
        }