private void LoadFoodList() { try { wpFood.Children.Clear(); List <FoodDTO> foodList = FoodDAO.Instance.GetListFood(); foreach (FoodDTO food in foodList) { MealButton foodBTN = new MealButton(); foodBTN.SetName(food.Name); foodBTN.btnMeal.Tag = food; foodBTN.btnMeal.Click += BtnMeal_Click; wpFood.Children.Add(foodBTN); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
//新增菜單以及初始化按鈕屬性 public void AddMeal(string name, int price, string description) { MealButton newMealButton = new MealButton(); string projectPath = Path.GetDirectoryName(Path.GetDirectoryName(System.IO.Directory.GetCurrentDirectory())); string imagePath = name + IMAGE_FORMAT; newMealButton.Visible = false; newMealButton.Dock = System.Windows.Forms.DockStyle.Fill; newMealButton.Text = name + ENTER_STRING + Convert.ToString(price) + SPACE_STRING + DOLLAR_STRING; newMealButton.Font = new System.Drawing.Font(TYPE, 12F, System.Drawing.FontStyle.Bold); newMealButton.TextAlign = ContentAlignment.TopRight; newMealButton.SetButton(name, price, description,projectPath + IMAGE_PATH_NAME + name + IMAGE_FORMAT); newMealButton.BackgroundImage = Image.FromFile(projectPath + IMAGE_PATH_NAME + name + IMAGE_FORMAT); var tempImage = new Bitmap(newMealButton.BackgroundImage, new Size(WIDTH, HEIGHT)); newMealButton.BackgroundImage = tempImage; _mealList.Add(newMealButton); }