Example #1
0
        public bool Add(LikedMealDTO entity)
        {
            LikedMeal likedmeal = new LikedMeal();

            likedmeal.MemberID     = entity.MemberID;
            likedmeal.MealOptionID = entity.MealOptionID;

            return(dao.Add(likedmeal));
        }
Example #2
0
        private void btnAddLikes_Click(object sender, EventArgs e)
        {
            if (theMeal == null)
            {
                return;
            }
            LikedMealDTO lmDto = new LikedMealDTO(new LikedMeal
            {
                MemberID     = StaticUser.UserID,
                MealOptionID = theMeal.ID
            });

            if (lmBLL.Add(lmDto))
            {
                MessageBox.Show($"{theMeal.Name} 已加入我的最愛");
                this.lblLikedCount.Text = lmBLL.LikedMealsCount.ToString();
            }
        }
        private void DGVMealHistory_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex < 0 || e.RowIndex < 0) return;
            int dietLogID = (int)DGVMealHistory.Rows[e.RowIndex].Cells["DietLogID"].Value;
            if (DGVMealHistory.Columns[e.ColumnIndex].Name == "btnLike")
            {

                int mealID = dlBll.GetDietLog(dietLogID).MealOption.ID;

                LikedMealDTO lmDto = new LikedMealDTO(new LikedMeal
                {
                    MemberID = StaticUser.UserID,
                    MealOptionID = mealID
                });
                if (lmBLL.Add(lmDto))
                {
                    MessageBox.Show($"已加入我的最愛");
                }
            }
            else if (DGVMealHistory.Columns[e.ColumnIndex].Name == "btnDelete")
            {
                DateTime date = (DateTime)DGVMealHistory.Rows[e.RowIndex].Cells["日期"].Value;
                string tod = DGVMealHistory.Rows[e.RowIndex].Cells["時段"].Value.ToString();
                string mName = DGVMealHistory.Rows[e.RowIndex].Cells["餐點名稱"].Value.ToString();
                string portion = DGVMealHistory.Rows[e.RowIndex].Cells["份量"].Value.ToString();

                string showInfo = date.ToString("MM / dd / yyyy") + $" {tod}\n{mName} {portion}份"; ;

                DialogResult dialogResult = MessageBox.Show(showInfo, "刪除紀錄?", MessageBoxButtons.YesNo);
                if (dialogResult == DialogResult.Yes)
                {
                    if (dlBll.DeleteDietLog(dietLogID))
                    {
                        MessageBox.Show("紀錄已刪除");
                        TimeOfDayDTO t = cBoxTimesOfDay.SelectedItem as TimeOfDayDTO;
                        if (DGVMealHistory.Rows.Count-1 == dlBll.GetDietLogHistory().Count)
                        {
                            bS_MealHistory.DataSource = dlBll.GetDietLogHistory().ToList();
                        }
                        else if (t == null)
                        {
                            bS_MealHistory.DataSource = dlBll.GetDietLogHistory(mCalendar.SelectionStart, mCalendar.SelectionEnd).ToList();
                        }
                        else
                        {
                            bS_MealHistory.DataSource = dlBll.GetDietLogHistory(mCalendar.SelectionStart, mCalendar.SelectionEnd, t.ID).ToList();

                        }
                    }
                }
            }
            else if (DGVMealHistory.Columns[e.ColumnIndex].Name == "btnEdit")
            {
                if (double.TryParse(Interaction.InputBox("請輸入更改後的份量(可含小數):", "修改份量?"), out double newPortion))
                {
                    if (dlBll.UpdateDietLogPortion(dietLogID, newPortion))
                    {
                        MessageBox.Show("紀錄已修改");
                        bS_MealHistory.DataSource = dlBll.GetDietLogHistory().ToList();      //改成抓現在的葉面

                    }
                }

            }
        }