private void changeDate(DateTime date)
        {
            //DatePickerDiary.Date = date;
            App.CurrentDay = DayViewModel.GetDayByDate(date);
            dayViewModel = App.CurrentDay;
            GridDayTotal.DataContext = dayViewModel;

            TextBlockDate.Text = convertDate(date);
            Intakes = new IntakesViewModel();
            intks = Intakes.GetIntakesList(dayViewModel.Id);
            ListViewDays.ItemsSource = intks;
        }
Esempio n. 2
0
        /// <summary>
        /// Invoked when the application is launched normally by the end user.  Other entry points
        /// will be used when the application is launched to open a specific file, to display
        /// search results, and so forth.
        /// </summary>
        /// <param name="args">Details about the launch request and process.</param>
        protected override void OnLaunched(LaunchActivatedEventArgs args)
        {
            // Initialize the database if necessary
            using (var db = new SQLite.SQLiteConnection(DBPath))
            {
                // Create the tables if they don't exist
                db.CreateTable<Day>();
                db.CreateTable<Intake>();
                Day day = new Day();
                day.Date = DateTime.Today;
                db.Insert(day);
            }

            CurrentDay = DayViewModel.GetDayByDate(DateTime.Today);

            Frame rootFrame = Window.Current.Content as Frame;

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            if (rootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();

                if (args.PreviousExecutionState == ApplicationExecutionState.Terminated)
                {
                    //TODO: Load state from previously suspended application
                }

                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
            }

            if (rootFrame.Content == null)
            {
                // When the navigation stack isn't restored navigate to the first page,
                // configuring the new page by passing required information as a navigation
                // parameter
                if (!rootFrame.Navigate(typeof(MainPage), args.Arguments))
                {
                    throw new Exception("Failed to create initial page");
                }
            }

            // Ensure the current window is active
            Window.Current.Activate();
        }
 //private CaloriesCounter.App app = (Application.Current as App);
 public ObservableCollection<DayViewModel> GetDays()
 {
     days = new ObservableCollection<DayViewModel>();
     using (var db = new SQLite.SQLiteConnection(App.DBPath))
     {
         var query = db.Table<Day>();
         foreach (var _day in query)
         {
             var day = new DayViewModel()
             {
                 Id = _day.Id,
                 Total = _day.Total,
                 Date = _day.Date,
                 Carbohydrates = _day.Carbohydrates,
                 Fibre = _day.Fibre,
                 Fat = _day.Fat,
                 Protein = _day.Protein
                 //TODO: other properties too
             };
             days.Add(day);
         }
     }
     return days;
 }
Esempio n. 4
0
        /**
        public string GetCustomerName(int customerId)
        {
            string customerName = "Unknown";
            using (var db = new SQLite.SQLiteConnection(app.DBPath))
            {
                var customer = (db.Table<Customer>().Where(
                    c => c.Id == customerId)).Single();
                customerName = customer.Name;
            }
            return customerName;
        }**/
        public string SaveDay(DayViewModel day)
        {
            string result = string.Empty;
            using (var db = new SQLite.SQLiteConnection(App.DBPath))
            {
                string change = string.Empty;
                try
                {
                    var existingDay = (db.Table<Day>().Where(
                        d => d.Id == day.Id)).SingleOrDefault();

                    if (existingDay != null)
                    {
                        existingDay.Date = day.Date;
                        existingDay.Carbohydrates = day.Carbohydrates;
                        existingDay.Protein = day.Protein;
                        existingDay.Fat = day.Fat;
                        existingDay.Fibre = day.Fibre;
                        existingDay.Total = day.Total;

                        int success = db.Update(existingDay);
                    }
                    else
                    {
                        int success = db.Insert(new Day()
                        {
                            Id = day.id,
                            Date = day.Date,
                            Carbohydrates = day.Carbohydrates,
                            Protein = day.Protein,
                            Fat = day.Fat,
                            Fibre = day.Fibre,
                            Total = day.Total
                        });
                    }
                    result = "Success";
                }
                catch (Exception)
                {
                    result = "This day was not saved.";
                }
            }
            return result;
        }
Esempio n. 5
0
 //private CaloriesCounter.App app = (Application.Current as App);
 public DayViewModel GetDay(int dayId)
 {
     var day = new DayViewModel();
     using (var db = new SQLite.SQLiteConnection(App.DBPath))
     {
         var _day = (db.Table<Day>().Where(
             d => d.Id == dayId)).Single();
         day.Id = _day.Id;
         day.Total = _day.Total;
         day.Date = _day.Date;
         day.Carbohydrates = _day.Carbohydrates;
         day.Protein = _day.Protein;
         day.Fat = _day.Fat;
         day.Fibre = _day.Fibre;
     }
     return day;
 }
Esempio n. 6
0
        /// <summary>
        /// Gets day by date, if date doesn't exist,
        /// a new day by given date will be created to db
        /// </summary>
        /// <param name="date"></param>
        /// <returns></returns>
        public static DayViewModel GetDayByDate(DateTime date)
        {
            var day = new DayViewModel();
            using (var db = new SQLite.SQLiteConnection(App.DBPath))
            {
                try {

                    var _day = (db.Table<Day>().Where(d => d.Date == date)).Single();
                    day.Id = _day.Id;
                    day.Total = _day.Total;
                    day.Date = _day.Date;
                    day.Carbohydrates = _day.Carbohydrates;
                    day.Protein = _day.Protein;
                    day.Fat = _day.Fat;
                    day.Fibre = _day.Fibre;
                }
                catch (Exception)
                {
                    Day dayrow = new Day();
                    dayrow.Date = date;
                    day.Date = date;
                    db.Insert(dayrow);
                }
                return day;
            }
        }