コード例 #1
0
        public List <TimeOfDayDTO> GetTimesOfDay()
        {
            List <TimeOfDayDTO> tod = new List <TimeOfDayDTO>();

            foreach (TimesOfDay td in dao.GetTimesOfDay())
            {
                TimeOfDayDTO tDto = new TimeOfDayDTO();
                tDto.ID   = td.ID;
                tDto.Name = td.Name;
                tod.Add(tDto);
            }
            return(tod);
        }
コード例 #2
0
        private void btnRefresh_Click(object sender, EventArgs e)
        {
            this.bS_MealHistory.DataSource = null;
            TimeOfDayDTO toD = cBoxTimesOfDay.SelectedItem as TimeOfDayDTO;
            if (toD == null)
            {
                bS_MealHistory.DataSource = dlBll.GetDietLogHistory(this.mCalendar.SelectionStart, this.mCalendar.SelectionEnd);
            }
            else
            {
                bS_MealHistory.DataSource = dlBll.GetDietLogHistory(this.mCalendar.SelectionStart, this.mCalendar.SelectionEnd, toD.ID);

            }
        }
コード例 #3
0
 private void mCalendar_DateChanged(object sender, DateRangeEventArgs e)
 {
     this.bS_MealHistory.DataSource = null;
     MonthCalendar mc = sender as MonthCalendar;
     TimeOfDayDTO toD = cBoxTimesOfDay.SelectedItem as TimeOfDayDTO;
     if (toD == null)
     {
         bS_MealHistory.DataSource = dlBll.GetDietLogHistory(mc.SelectionStart, mc.SelectionEnd);
     }
     else
     {
         bS_MealHistory.DataSource = dlBll.GetDietLogHistory(mc.SelectionStart, mc.SelectionEnd, toD.ID);
     }
 }
コード例 #4
0
        private void btnAddToTempList_Click(object sender, EventArgs e)
        {
            if (theMeal == null)
            {
                return;
            }
            TimeOfDayDTO selectedTOD = this.cBoxTimesOfDay.SelectedItem as TimeOfDayDTO;

            if (selectedTOD == null || this.tBoxTotalCal.Text == "")
            {
                MessageBox.Show("請確認時段及份量");
                return;
            }
            //double gainCalories = dBll.GetMealConsumedCalories(theMeal.Calories, thePortion);

            DietLogDTO dL = new DietLogDTO();

            dL.MemberID     = StaticUser.UserID;
            dL.MealOptionID = theMeal.ID;
            dL.Portion      = thePortion;
            dL.TimeOfDayID  = selectedTOD.ID;
            dL.Date         = this.dateTimePicker1.Value; //
            dL.EditTime     = DateTime.Now;
            //-------------------------
            dL.圖片       = theMeal.Image;
            dL.日期       = dL.Date;
            dL.時段       = selectedTOD.Name;
            dL.餐點名稱     = theMeal.Name;
            dL.每100克卡路里 = (int)theMeal.Calories;
            dL.份量       = dL.Portion;
            dL.總卡路里     = (int)(dL.每100克卡路里 * dL.份量);
            mealList.Add(dL);

            this.bS_AddedMeals.DataSource = mealList.ToList().OrderByDescending(dl => dl.Date).ThenBy(dl => dl.TimeOfDayID);

            ShowReqdColumns();
            this.tBoxTotalCal.Text = "";
        }
コード例 #5
0
        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();      //改成抓現在的葉面

                    }
                }

            }
        }