// load meal list public void InitializeMealList() { StreamReader file = new StreamReader(_projectPath + MEAL_FILE_NAME); string name; while ((name = file.ReadLine()) != null) { string price = file.ReadLine(); string imagePath = file.ReadLine(); string description = file.ReadLine(); string categoryName = file.ReadLine(); Category category = _categoryControl.GetCategoryByName(categoryName); Meal meal = new Meal(); meal.SetValue(name, price, description, imagePath); meal.SetCategory(category); _mealControl.InitializeMealButton(meal); } file.Close(); }
// save meal button private void SaveMeal(object sender, EventArgs e) { Meal meal = new Meal(); meal.SetValue(_mealNameTextBox.Text, _priceTextBox.Text, _descriptionTextBox.Text, _pathTextBox.Text); meal.SetCategory(_categoryControl.GetCategoryByName(_categoryComboBox.SelectedItem.ToString())); if (_mealManagerGroupBox.Text.Equals(ADD_MEAL)) { bool success = _mealControl.InitializeMealButton(meal); if (!success) { ShowDoubleMessageBox(); } } else if (_mealManagerGroupBox.Text.Equals(EDIT_MEAL)) { _model.ChangeMealDetail(_mealListBox.SelectedItem.ToString(), meal); } RefreshBySaveMeal(); _model.UpdateMealList(); _mealControl.SaveMealListToFile(); }