private void SaveButtonClick(object sender, RoutedEventArgs e)
 {
     if (!HasValidationErrors)
     {
         if (HasNull)
         {
             BindingExpression bindingExpression = NameTB.GetBindingExpression(TextBox.TextProperty);
             bindingExpression.UpdateSource();
             bindingExpression = KcalTB.GetBindingExpression(TextBox.TextProperty);
             bindingExpression.UpdateSource();
             bindingExpression = CarboTB.GetBindingExpression(TextBox.TextProperty);
             bindingExpression.UpdateSource();
             bindingExpression = ProteinTB.GetBindingExpression(TextBox.TextProperty);
             bindingExpression.UpdateSource();
             bindingExpression = FatTB.GetBindingExpression(TextBox.TextProperty);
             bindingExpression.UpdateSource();
         }
         else
         {
             dieterDBM = new DieterDBM();
             dieterDBM.Products.InsertOnSubmit(newProduct);
             dieterDBM.SubmitChanges();
             dieterDBM.Dispose();
             MessageBox.Show("Dodano produkt.");
             DialogResult = true;
         }
     }
     else
     {
         MessageBox.Show("Błędne dane.");
     }
 }
Exemple #2
0
        private void DeleteMealClick(object sender, RoutedEventArgs e)
        {
            dieterDBM = new DieterDBM();
            int id          = Utils.GetIdFromUGrid((UniformGrid)((Button)sender).Parent);
            var removedMeal = dieterDBM.Meals.Single(m => m.Id == id);

            dieterDBM.Meals.DeleteOnSubmit(removedMeal);
            dieterDBM.SubmitChanges();

            var currentDay = dieterDBM.Days.Single(d => d.Id == dayId);

            SumNutritionalContents(currentDay);
            dieterDBM.SubmitChanges();
            dieterDBM.Dispose();
            InitMealsList();
        }
Exemple #3
0
 private void AddDay(object sender, RoutedEventArgs e)
 {
     dieterDBM = new DieterDBM();
     dieterDBM.Days.InsertOnSubmit(new Day());
     dieterDBM.SubmitChanges();
     dieterDBM.Dispose();
     InitDaysList();
 }
Exemple #4
0
        private void DeleteProductFromMealClick(object sender, RoutedEventArgs e)
        {
            int id = Utils.GetIdFromUGrid((UniformGrid)((Button)sender).Parent);

            dieterDBM = new DieterDBM();
            ProductMeal removedProductMeal = (from productMeal in dieterDBM.ProductMeal where productMeal.Id == id select productMeal).Single();

            dieterDBM.ProductMeal.DeleteOnSubmit(removedProductMeal);
            dieterDBM.SubmitChanges();

            var currentMeal = (from meal in dieterDBM.Meals where meal.Id == mealId select meal).First();

            SumNutritionalContents(currentMeal);
            dieterDBM.SubmitChanges();
            dieterDBM.Dispose();
            InitProductMealsList();
        }
Exemple #5
0
        public void RefreshDayNutritionalContents()
        {
            dieterDBM = new DieterDBM();
            var currentDay = (from dbDay in dieterDBM.Days where dbDay.Id == dayId select dbDay).First();

            SumNutritionalContents(currentDay);
            dieterDBM.SubmitChanges();
            dieterDBM.Dispose();
            InitMealsList();
        }
Exemple #6
0
        private void AddMeal(object sender, RoutedEventArgs e)
        {
            dieterDBM = new DieterDBM();
            var currentDay = (from dbDay in dieterDBM.Days where dbDay.Id == dayId select dbDay).First();

            currentDay.Meals.Add(new Meal());
            dieterDBM.SubmitChanges();
            dieterDBM.Dispose();
            InitMealsList();
        }
Exemple #7
0
        private void DeleteDayClick(object sender, RoutedEventArgs e)
        {
            int id = Utils.GetIdFromUGrid((UniformGrid)((Button)sender).Parent);

            dieterDBM = new DieterDBM();
            var day = (from d in dieterDBM.Days where d.Id == id select d).Single();

            dieterDBM.Days.DeleteOnSubmit(day);
            dieterDBM.SubmitChanges();
            dieterDBM.Dispose();
            InitDaysList();
        }
Exemple #8
0
        private void AddProductToMeal(double amount)
        {
            dieterDBM = new DieterDBM();
            ProductMeal productMeal = MakeProductMeal(amount);
            var         currentMeal = (from meal in dieterDBM.Meals where meal.Id == mealId select meal).First();

            currentMeal.ProductMeals.Add(productMeal);
            SumNutritionalContents(currentMeal);
            dieterDBM.SubmitChanges();
            dieterDBM.Dispose();
            Clear();
            InitProductMealsList();
        }
Exemple #9
0
        private void DeleteProductClick(object sender, RoutedEventArgs e)
        {
            dieterDBM = new DieterDBM();
            Product product        = (Product)productsComboBox.SelectedItem;
            var     deletedProduct = (from p in dieterDBM.Products where p.Id == product.Id select p).Single();

            try
            {
                dieterDBM.Products.DeleteOnSubmit(deletedProduct);
                dieterDBM.SubmitChanges();
                dieterDBM.Dispose();
                InitCombo();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                MessageBox.Show("Produkt jest używany nie można usunąć");
            }
        }