private void OKBtn_Click(object sender, RoutedEventArgs e) { MainWindow mainWindow = Application.Current.Windows.Cast <Window>().FirstOrDefault(window => window is MainWindow) as MainWindow; Service service = (Service)mainWindow.service; service.AddCategory(CategoryName.Text); mainWindow.ProductUpdate(service.GetCategories()); Close(); }
private void AddProductOKBtn_Click(object sender, RoutedEventArgs e) { if (AddProductName.Text == "" || AddProductGramms.Text == "" || AddProductProtein.Text == "" || AddProductCarbs.Text == "" || AddProductCalories.Text == "" || AddProductFats.Text == "") { return; } MainWindow mainWindow = Application.Current.Windows.Cast <Window>().FirstOrDefault(window => window is MainWindow) as MainWindow; if (mainWindow.ProductTree.SelectedItem != null) { Service service = (Service)mainWindow.service; Category category = service.GetCategory(((Category)mainWindow.ProductTree.SelectedItem).name); int weight; double protein, carbs, calories, fats; int.TryParse(AddProductGramms.Text, out weight); double.TryParse(AddProductProtein.Text, out protein); double.TryParse(AddProductCarbs.Text, out carbs); double.TryParse(AddProductCalories.Text, out calories); double.TryParse(AddProductFats.Text, out fats); service.AddProduct(category, AddProductName.Text, weight, protein, fats, carbs, calories); mainWindow.ProductUpdate(service.GetCategories()); Close(); } }