public void InitializeMealButtonTest() { Category category = new Category(); category.Name = "飲料"; Meal meal = new Meal(); meal.SetValue("香草奶昔", "25", "", "/image/Milkshake Vanilla_hero.png"); meal.SetCategory(category); bool success = _mealControl.InitializeMealButton(meal); Assert.IsTrue(success); success = _mealControl.InitializeMealButton(meal); Assert.IsFalse(success); }
// 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(); }