示例#1
0
        private static DayEntry SelectDayEntry(DateTime date, out int affected) //selects one DayEntry from DB based on Date given
        {
            affected = 0;

            SqlParameter[]    sparams = new SqlParameter[] { new SqlParameter("@DayDate", date.ToString("yyyy/MM/dd")) };
            DataRowCollection rows    = DBHelper.selectStatement("SELECT m.MealID FROM Meals m WHERE m.TimeEaten=@DayDate;", sparams); //selects Meals based on DayEaten

            if (rows.Count == 0)                                                                                                       //If No day(meal entries for the Date) is found Stop/do Nothing
            {
                return(null);
            }

            DayEntry day = new DayEntry();

            day._date = date;
            int affmeal;

            foreach (DataRow row in rows)    //adds Meals data into MealEntries for this newly made DayEntry
            {
                day.addMealEntry(SelectMealEntry(((int)row["MealID"]), out affmeal));
                affected += affmeal;
            }

            rows = DBHelper.selectStatement("SELECT n.Score, n.NoteTExt FROM Notes n WHERE n.OfDay=@DayDate;", sparams); //selects Note data for this day from Notes
            if (rows.Count == 1)                                                                                         //creates Note for this DayEntry is data was found
            {
                day._note = new Note(rows[0]["Score"] == DBNull.Value ? "" : rows[0]["Score"].ToString(),
                                     rows[0]["NoteText"] == DBNull.Value ? "" : rows[0]["NoteText"].ToString());
                affected++;
            }

            day.setCalculatedValues();  //calculate the final food values
            return(day);
        }
示例#2
0
        private void button_addMeal_Click(object sender, EventArgs e)   //adds a new meal(and selects it) for current day
        {
            _day.addMealEntry(new MealEntry());
            //_day._mealEntries.Last()._note = new Note(textBox_noteMealScore.Text, textBox_noteMealText.Text);
            _day._mealEntries.Last()._name    = "Meal" + _day._mealEntries.Count;
            _day._mealEntries.Last()._portion = Convert.ToDouble(textBox_portion.Text);
            ((BindingSource)comboBox_meals.DataSource).ResetBindings(false);
            comboBox_meals.SelectedItem = _day._mealEntries.Last();
            if (!button_setMealNote.Enabled)
            {
                button_setMealNote.Enabled = true;
            }
            if (!button_setMealPortion.Enabled)
            {
                button_setMealPortion.Enabled = true;
            }

            updateDay();
        }