Exemplo n.º 1
0
        // Constructor
        public MainPage()
        {
            InitializeComponent();
            Loaded += MainPage_Loaded;
            items = itemTable.ToCollectionView();
            MessageBox.Show("Itemtable: " + itemTable.ToString());
            add = new Item();
            GridAdd.DataContext = add;
            
            //Get today as default
            selectedDate = new DateTime();
            selectedDate = DateTime.Today;
            SelectedDay = new Day();
            SelectedDay.Date = selectedDate;
            SelectedDay = App.ViewModel.AddDay(SelectedDay);
   
            if (SelectedDay.Intakes != null) LongListDiary.ItemsSource = SelectedDay.Intakes;

            Diary.DataContext = SelectedDay;
            
            MessageBox.Show("Itemcount" + items.Count);
            // Sample code to localize the ApplicationBar
            //BuildLocalizedApplicationBar();
        }
        /// <summary>
        /// Adds a new day to the database if date is not found
        /// </summary>
        /// <param name="newDay"></param>
        /// <returns></returns>
        public Day AddDay(Day newDay)
        {
            dateToAdd = newDay.Date;
            Day find = getDay(newDay.Date);
            if (find != null)
            {
                return find;
            }

            newDay.Total = newDay.Intakes.Select(i => i.Calories).Sum(); //toimiiko?
            MessageBox.Show("Total: " + newDay.Total);
            calorieCounterDB.Days.InsertOnSubmit(newDay);
            calorieCounterDB.SubmitChanges();

            DaysList.Add(newDay);
            return newDay;
        }
 /// <summary>
 /// Checks if the dates match comparing two
 /// different day-objects
 /// </summary>
 /// <param name="dayToCompare"></param>
 /// <returns></returns>
 private bool IsSameDay(Day dayToCompare)
 {
     int comparison = dayToCompare.Date.Day.CompareTo(dateToAdd.Day);
     if (comparison != 0) return false;
     else return true;
 }
Exemplo n.º 4
0
 private void changeDay(DateTime date)
 {
     SelectedDay = new Day();
     SelectedDay.Date = date;
     SelectedDay = App.ViewModel.AddDay(SelectedDay);
     MessageBox.Show("Haettu selectedDay");
     if (SelectedDay.Intakes != null) LongListDiary.ItemsSource = SelectedDay.Intakes;
     MessageBox.Show("Haettu selectedDay");
     Diary.DataContext = SelectedDay;
 }