Exemplo n.º 1
0
        private void Save_Button_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                // Get informations about product.
                string name        = NameInput.Text;
                string description = DescriptionInput.Text;
                string unit;
                double weight;

                if (UnitInput.SelectedIndex == 0)
                {
                    unit   = "g";
                    weight = GetParsedDouble(WeightInput.Text.ToString());
                }
                else
                {
                    unit   = "ml";
                    weight = GetParsedDouble(CapacityInput.Text.ToString());
                }

                double calories = GetParsedDouble(CaloriesInput.Text.ToString());
                double carbs    = GetParsedDouble(CarbsInput.Text.ToString());
                double proteins = GetParsedDouble(ProteinsInput.Text.ToString());
                double fat      = GetParsedDouble(FatInput.Text.ToString());

                Product product = new Product(name, description, unit, weight, calories, fat, carbs, proteins);

                IProductsProvider provider = new XMLProductsParser();
                provider.AddProduct(product);

                MyProducts myProducts = new MyProducts();
                myProducts.Show();
                this.Close();
            }
            catch (NullReferenceException)
            {
                MessageBox.Show("You have to fill every field!");
            }
            catch (FormatException)
            {
                MessageBox.Show("Cannot save new product! Invalid data!");
            }
            catch (ArgumentOutOfRangeException ex)
            {
                MessageBox.Show(ex.Message);
            }
            catch (Exception)
            {
                MessageBox.Show("Something went wrong! :(");
            }
        }
Exemplo n.º 2
0
        public void AddProductsToList()
        {
            IProductsProvider provider = new XMLProductsParser();
            List <Product>    products = provider.GetAllProducts();

            if (products == null)
            {
                return;
            }

            foreach (Product p in products)
            {
                Console.WriteLine(p.ToString());
                if (productsList.Items.Contains(p))
                {
                    return;
                }
                productsList.Items.Add(p);
            }
        }
Exemplo n.º 3
0
        public AddProductToMeal(FoodDiary diary, string mealType)
        {
            InitializeComponent();
            this.diary    = diary;
            this.mealType = mealType;

            IProductsProvider provider = new XMLProductsParser();

            products = provider.GetAllProducts();

            if (products == null)
            {
                return;
            }

            foreach (Product p in products)
            {
                ProductInput.Items.Add(p.Name);
            }
        }