Exemplo n.º 1
0
        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            AddFoodItem AddFoodItemm = new AddFoodItem();

            AddFoodItemm.FormClosed += AddfoodClosed;
            OpenForm(AddFoodItemm);
        }
        public bool Handle(AddFoodItem command)
        {
            bool res = false;

            if (command.command())
            {
                res = true;
            }
            return(res);
        }
Exemplo n.º 3
0
        //adds a food item in the database, respecting the validation rules
        public int addFoodItem(BFoodItem bFoodItem)
        {
            Mediator       m = new Mediator();
            FindLatestFood findLatestFood = new FindLatestFood();
            FoodItem       latestFood     = m.findLatestFoodHandler.Handle(findLatestFood).response;

            if (!(latestFood.Name.Equals(bFoodItem.Name) && latestFood.PurchaseDate.Equals(bFoodItem.PurchaseDate) && latestFood.ExpDate.Equals(bFoodItem.ExpDate) && latestFood.Quantity.Equals(bFoodItem.Quantity)))
            {
                //Invalid Purchase date
                if (bFoodItem.PurchaseDate.Equals(DateTime.MinValue))
                {
                    return(1);
                }

                //Invalid Expiration date
                if (bFoodItem.ExpDate.Equals(DateTime.MinValue))
                {
                    return(2);
                }

                //Invalid Consumption date
                if (bFoodItem.ConsDate.Equals(DateTime.MinValue))
                {
                    return(3);
                }

                //Name can contain only english letters
                if (!Regex.IsMatch(bFoodItem.Name, @"^[a-zA-z]+$"))
                {
                    return(4);
                }

                //Qunatity limits
                if (bFoodItem.Quantity < 0)
                {
                    return(5);
                }

                if (bFoodItem.Quantity > 1000)
                {
                    return(6);
                }

                //Calories limits
                if (bFoodItem.Calories < 0)
                {
                    return(7);
                }

                if (bFoodItem.Calories > 1000000)
                {
                    return(8);
                }

                if (bFoodItem.ConsDate > DateTime.Now)
                {
                    return(9);
                }

                if (bFoodItem.PurchaseDate > DateTime.Now)
                {
                    return(10);
                }

                //Successfully inserted
                AddFoodItem addFoodItem = new AddFoodItem(convert_to_fi(bFoodItem));
                m.addFoodItemHandler.Handle(addFoodItem);

                //fia.addFoodItem(convert_to_fi(bFoodItem));
                return(0);
            }
            return(11);
        }
Exemplo n.º 4
0
 private async void buta_ddDataToDatabase_Clicked(object sender, EventArgs e)
 {
     var addFood = new AddFoodItem();
     await addFood.AddFoodItemsDataAsync();
 }
Exemplo n.º 5
0
        private void AddItems_Click(object sender, RoutedEventArgs e)
        {
            AddFoodItem fooditemscreen = new AddFoodItem();

            pageload(fooditemscreen);
        }