protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            muctieu = (MucTieu)e.Parameter;
            nguoidung = connection.Table<NguoiDung>().Where(r => r.TenDangNhap == muctieu.TenDangNhap).FirstOrDefault();
            int tuoi = DateTime.Today.Year - DateTime.ParseExact(nguoidung.NgaySinh, "dd/MM/yyyy", new CultureInfo("vi-vn")).Year;
            chiso = new ChiSo(muctieu.CanNangBanDau, muctieu.ChieuCaoBanDau, nguoidung.GioiTinh, tuoi);
            // so ngay giam de nghi cho mac dinh = 30;
            int socangiamdenghi = chiso.tinhSoCanGiamDeNghi(); // cannang - cannanglytuong

            // muc 1
            DeNghi muc1 = new DeNghi();
            muc1.SoCanGiamDeNghi = socangiamdenghi;
            muc1.SoNgayGiamDeNghi = Convert.ToInt32(Math.Round(muc1.SoCanGiamDeNghi / 0.05));
            muc1Button.Content = string.Format("Giảm {0} kg trong vòng {1} ngày", muc1.SoCanGiamDeNghi, muc1.SoNgayGiamDeNghi);
            muc1Button.Tag = muc1;

            // muc 2 
            DeNghi muc2 = new DeNghi();
            muc2.SoCanGiamDeNghi = socangiamdenghi;
            muc2.SoNgayGiamDeNghi = Convert.ToInt32(Math.Round(muc2.SoCanGiamDeNghi / 0.1));
            muc2Button.Content = string.Format("Giảm {0} kg trong vòng {1} ngày", muc2.SoCanGiamDeNghi, muc2.SoNgayGiamDeNghi);
            muc2Button.Tag = muc2;

            // muc3
            DeNghi muc3 = new DeNghi();
            muc3.SoCanGiamDeNghi = socangiamdenghi;
            muc3.SoNgayGiamDeNghi = Convert.ToInt32(Math.Round(muc3.SoCanGiamDeNghi / 0.15));
             muc3Button.Content = string.Format("Giảm {0} kg trong vòng {1} ngày", muc3.SoCanGiamDeNghi, muc3.SoNgayGiamDeNghi);
            muc3Button.Tag = muc3;

            
        }
Example #2
0
        /// <summary>
        /// lấy thống kê ngày hiện tại 
        /// </summary>
        /// <param name="mtht">mục tiêu hiện tại</param>
        /// <returns>thống kê ngày</returns>
        public static ThongKeNgay getThongKeNgayHienTai(MucTieu mtht)
        {
            string today = DateTime.Today.ToString("dd/MM/yyyy");

            ThongKeNgay thongkengay = mtht != null ? connection.Table<ThongKeNgay>().Where(r => r.IdMucTieu == mtht.IdMucTieu && r.Ngay == today).FirstOrDefault() : null;
            return thongkengay;
        }
 protected override void OnNavigatedTo(NavigationEventArgs e)
 {
     nguoidung = TrangChu.nguoidung;
     muctieu = TrangChu.muctieu;
     if(muctieu != null)
     {
         if (muctieu.ThoiGianBatDau == null || muctieu.TrangThai == "Chưa bắt đầu")
         {
             muctieu.TrangThai = "Đã bắt đầu";
             muctieu.ThoiGianBatDau = DateTime.Today.ToString("dd/MM/yyyy");
             connection.Update(muctieu);
         }
     }
 }
Example #4
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            nguoidung = e.Parameter as NguoiDung;
            // kiem tra ngay hien tai da co trong db chua, chua co thi them vao
            muctieu = connection.Table<MucTieu>().Where(r => r.TenDangNhap == nguoidung.TenDangNhap && (r.TrangThai == "Đã bắt đầu" || r.TrangThai == "Chưa bắt đầu")).FirstOrDefault();

            string today = DateTime.Today.ToString("dd/MM/yyyy");

            thongkengay = (muctieu != null) ? connection.Table<ThongKeNgay>().Where(r => r.IdMucTieu == muctieu.IdMucTieu && r.Ngay == today).FirstOrDefault() : null;

            tendangnhapTextBlock.Text = nguoidung.TenDangNhap;
            tuoiTextBlock.Text = (DateTime.Today.Year - DateTime.ParseExact(nguoidung.NgaySinh, "dd/MM/yyyy", new CultureInfo("vi-vn")).Year).ToString();
            gioitinhTextBlock.Text = nguoidung.GioiTinh;
        }
 protected override void OnNavigatedTo(NavigationEventArgs e)
 {
     nguoidung = e.Parameter as NguoiDung;
     muctieu = TrangChu.getMucTieuHienTai(nguoidung);
     if(muctieu != null)
     {
         tkNgay = TrangChu.getThongKeNgayHienTai(muctieu);
         kaloBox.Text = tkNgay.LuongKaloNgoaiDuKien.ToString();
     }
     else
     {
         tkNgay = new ThongKeNgay();
         kaloBox.Text = "0";
     }
 }
Example #6
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {

            List<Uri> uriLst = new List<Uri>();
            for (int i = 1; i <= 13; i++)
            {
                uriLst.Add(new Uri("ms-appx:///Assets/lacvong" + i + ".png"));
            }
            for (int i = 0; i < 13; i++)
            {
                imgLst.Add(new BitmapImage(uriLst[i]));
            }
           
            threadImg = ThreadPoolTimer.CreatePeriodicTimer(UpdateSprite, TimeSpan.FromMilliseconds(100));

            //kiem tra bai tap nay da co trong database chua
            nguoidung = TrangChu.nguoidung;

            // lấy mục tiêu hiện tại (có thể null)
            muctieu = TrangChu.muctieu;
            if (muctieu != null)
            {
                // lấy thống kê ngày hiện tại (có thể null)
                thongkengay = TrangChu.getThongKeNgayHienTai(muctieu);
                //check da tap lan nao trong ngay chua

                lacVong = connection.Table<ThongKeBaiTap>().Where(r => r.IdThongKeNgay == thongkengay.IdThongKeNgay && r.IdBaiTap == 6).FirstOrDefault();
                if (lacVong == null)
                {
                    lacVong = new ThongKeBaiTap()
                    {
                        IdBaiTap = 6,
                        IdThongKeNgay = thongkengay.IdThongKeNgay,
                        QuangDuong = 0,
                        LuongKaloTieuHao = 0,
                        ThoiGianTap = 0
                    };
                    connection.Insert(lacVong);
                }

            }

            // neu khong thi cho tap nhung khong dua vao database
            else
            {
                lacVong = new ThongKeBaiTap();
            }
        }
Example #7
0
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            try
            {
                // lay nguoidung tu trang dang nhap vao
                nguoidung = (NguoiDung)e.Parameter;

                // lay muctieu hien tai cua nguoidung
                muctieu = getMucTieuHienTai(nguoidung);
            }
            catch (Exception)
            {
                MessageDialog msDialog = new MessageDialog("Một số lỗi đã xảy ra");
                await msDialog.ShowAsync();
                Frame.Navigate(typeof(MainPage));
            }
        }
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            // lấy người dùng hiện tại
            nguoidung = TrangChu.nguoidung;
            // lay muctieu hien tai
            muctieu = TrangChu.muctieu;
            
            // neu muctieu == null -> thu lay muctieu da hoan thanh truoc do
            if (muctieu == null) muctieu = connection.Table<MucTieu>().Where(r=>r.TenDangNhap == nguoidung.TenDangNhap && r.TrangThai=="Hoàn thành").OrderBy(r=>r.IdMucTieu).FirstOrDefault();

            if (muctieu != null)
            {
                // lay danh sách các ngày từ mục tiêu hiện tại
                ThongKeNgayList = connection.Table<ThongKeNgay>().Where(r => r.IdMucTieu == muctieu.IdMucTieu).ToList<ThongKeNgay>();
                // lấy danh sách các mục tiêu khác của người dùng hiện tại (để hiển thị)
                List<MucTieu> muctieukhacList = connection.Table<MucTieu>().Where(r => r.TenDangNhap == nguoidung.TenDangNhap && r.IdMucTieu != muctieu.IdMucTieu).ToList();
                ThongKeNgayKhacList = new List<ThongKeNgay>();
                // lấy danh sách các ngày từ các mục tiêu trước
                foreach (var muctieukhac in muctieukhacList)
                {
                    var list = connection.Table<ThongKeNgay>().Where(r => r.IdMucTieu == muctieukhac.IdMucTieu).ToList();
                    list.ForEach(r => ThongKeNgayKhacList.Add(r));
                }
            }
            else
            {
                ThongKeNgayList = new List<ThongKeNgay>();
                List<MucTieu> muctieukhacList = connection.Table<MucTieu>().Where(r => r.TenDangNhap == nguoidung.TenDangNhap).ToList();

                ThongKeNgayKhacList = new List<ThongKeNgay>();
                // lấy danh sách các ngày từ các mục tiêu trước
                foreach (var muctieukhac in muctieukhacList)
                {
                    var list = connection.Table<ThongKeNgay>().Where(r => r.IdMucTieu == muctieukhac.IdMucTieu).ToList();
                    list.ForEach(r => ThongKeNgayKhacList.Add(r));
                }
            }

            Initialize_Calendar(calendarDate);



        }
 private async void themMucTieuButton_Click(object sender, RoutedEventArgs e)
 {
     muctieu = new MucTieu();
     if(await checkNumberTextBox() == true)
     {
         // nếu cân cặng thấp hơn cân nặng lý tưởng ==> không thuộc đối tượng giảm cân => không cho tạo mục tiêu
         if(idealweight >= weight)
         {
             MessageDialog msDialog = new MessageDialog("Bạn không nên giảm cân!");
             await msDialog.ShowAsync();
             return;
         }
         muctieu.TenDangNhap = nguoidung.TenDangNhap;
         muctieu.CanNangBanDau = weight;
         muctieu.ChieuCaoBanDau = height;
         // lam tron thanh 2 con so thap phan
         muctieu.ChiSoBMR = Math.Round(bmr, 2);
         Frame.Navigate(typeof(TaoMoiMucTieu2), muctieu);
     }
    
 }
Example #10
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            nguoidung = TrangChu.nguoidung;

            muctieu = TrangChu.muctieu;
            if (muctieu != null)
            {
                thongkengay = TrangChu.getThongKeNgayHienTai(muctieu);
                // lấy danh sách món ăn đã chọn từ ngày hôm đó
                monanDBList = connection.Table<ThucDon>().Where(r => r.IdThongKeNgay == thongkengay.IdThongKeNgay).ToList<ThucDon>();

                
            }
            else
            {
                thongkengay = new ThongKeNgay();
                monanDBList = new List<ThucDon>();
            }
            // lấy danh sách các món ăn từ database
            monAnList = connection.Table<MonAn>().ToList<MonAn>();
            TongLuongKalo = 0;
        }
Example #11
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {

            
            // lấy thông tin từ  trang muc tap
            mucTap muctap = (mucTap)e.Parameter;
            tenBt = muctap.tenBaiTap;
            level = muctap.level;
            tenBT.Text = tenBt;
            nguoidung = TrangChu.nguoidung;
            muctieu = TrangChu.muctieu;


            //image
            List<Uri> uriLst = new List<Uri>();
            if(tenBt == "Gập bụng")
            {
                for (int i = 1; i <= 4; i++)
                {
                    uriLst.Add(new Uri("ms-appx:///Assets/gapbung" + i + ".png"));
                }
            }
            else
            {
                for (int i = 1; i <= 6; i++)
                {
                    uriLst.Add(new Uri("ms-appx:///Assets/hitdat" + i + ".png"));
                }
            }
            
            for (int i = 0; i < 4; i++)
            {
                imgLst.Add(new BitmapImage(uriLst[i]));
            }

            threadImg = ThreadPoolTimer.CreatePeriodicTimer(UpdateSprite, TimeSpan.FromMilliseconds(200));


            // lay thong tin bai tap bung hay hit dat dua vao ten
            baiTapBung = connection.Table<BaiTap>().Where(r => r.TenBaiTap == tenBt).FirstOrDefault();
            idBT = baiTapBung.IdBaiTap;

            if (muctieu != null)
            {
                thongKeNgay = TrangChu.getThongKeNgayHienTai(muctieu);
                thongKeTapBung = connection.Table<ThongKeBaiTap>().Where(r => r.IdThongKeNgay == thongKeNgay.IdThongKeNgay && r.IdBaiTap == idBT).FirstOrDefault();
                if (thongKeTapBung == null)
                {
                    thongKeTapBung = new ThongKeBaiTap()
                    {
                        IdThongKeNgay = thongKeNgay.IdThongKeNgay,
                        IdBaiTap = idBT,
                        LuongKaloTieuHao = 0,
                        SoLan = 0
                    };
                    connection.Insert(thongKeTapBung);
                }
            }
            else
            {
                thongKeTapBung = new ThongKeBaiTap();
            }
        }
Example #12
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {

            //image
            List<Uri> uriLst = new List<Uri>();
            for (int i = 1; i <= 2; i++)
            {
                uriLst.Add(new Uri("ms-appx:///Assets/nhayday0" + i + ".png"));
            }

            for (int i = 0; i < 2; i++)
            {
                imgLst.Add(new BitmapImage(uriLst[i]));
            }
            threadImg = ThreadPoolTimer.CreatePeriodicTimer(UpdateSprite, TimeSpan.FromMilliseconds(400));

            ScenarioEnableButton.IsEnabled = true;
            ScenarioDisableButton.IsEnabled = false;
            ScenarioPauseButton.IsEnabled = false;

            nguoidung = TrangChu.nguoidung;
            muctieu = TrangChu.muctieu;
            if (muctieu != null)
            {
                thongkengay = TrangChu.getThongKeNgayHienTai(muctieu);
                nhayday = connection.Table<ThongKeBaiTap>().Where(r => r.IdThongKeNgay == thongkengay.IdThongKeNgay && r.IdBaiTap == 5).FirstOrDefault();
                if (nhayday == null)
                {
                    nhayday = new ThongKeBaiTap()
                    {
                        IdBaiTap = 5,
                        IdThongKeNgay = thongkengay.IdThongKeNgay,
                        QuangDuong = 0,
                        SoBuoc = 0,
                        LuongKaloTieuHao = 0,
                        ThoiGianTap = 0
                    };
                    connection.Insert(nhayday);
                }
            }

            // mục tiêu == null || thống kê ngày == null -> tập nhưng không đưa vào database
            else
            {
                nhayday = new ThongKeBaiTap();
            }

        }
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            ScenarioEnableButton.IsEnabled = true;
            ScenarioDisableButton.IsEnabled = false;
            ScenarioPauseButton.IsEnabled = false;

            nguoidung = TrangChu.nguoidung;
            muctieu = TrangChu.muctieu;
            if (muctieu != null)
            {
                thongkengay = TrangChu.getThongKeNgayHienTai(muctieu);
                chaybo = connection.Table<ThongKeBaiTap>().Where(r => r.IdThongKeNgay == thongkengay.IdThongKeNgay && r.IdBaiTap == 1).FirstOrDefault();
                if (chaybo == null)
                {
                    chaybo = new ThongKeBaiTap()
                    {
                        IdBaiTap = 1,
                        IdThongKeNgay = thongkengay.IdThongKeNgay,
                        QuangDuong = 0,
                        SoBuoc = 0,
                        LuongKaloTieuHao = 0,
                        ThoiGianTap = 0
                    };
                    connection.Insert(chaybo);
                }
            }

            // mục tiêu == null || thống kê ngày == null -> tập nhưng không đưa vào database
            else
            {
                chaybo = new ThongKeBaiTap();
            }

        }
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            //Uri uri1 = new System.Uri("ms-appx:///Assets/tabata1.png");
            //Uri uri2 = new System.Uri("ms-appx:///Assets/tabata2.png");
            //Uri uri3 = new System.Uri("ms-appx:///Assets/tabata3.png");
            //Uri uri4 = new System.Uri("ms-appx:///Assets/tabata4.png");
            //Uri uri5 = new System.Uri("ms-appx:///Assets/tabata5.png");
            //List<Uri> uriLst = new List<Uri>();
            //uriLst.Add(uri1);
            //uriLst.Add(uri2);
            //uriLst.Add(uri3);
            //uriLst.Add(uri4);
            //uriLst.Add(uri5);
            List<Uri> uriLst = new List<Uri>();
            for(int i=1; i<=5; i++)
            {
                uriLst.Add(new Uri("ms-appx:///Assets/tabata" + i + ".png"));
            }
            //List<ImageSource> imglstSou = new List<ImageSource>();
            //for(int i = 0; i < 5; i++)
            //{
            //    imglstSou.Add(new BitmapImage(uriLst[i]));
            //}
            for(int i = 0; i < 5; i++)
            {
                imgLst.Add(new BitmapImage(uriLst[i]));
            }
            threadImg = ThreadPoolTimer.CreatePeriodicTimer(UpdateSprite, TimeSpan.FromMilliseconds(400));

            //kiem tra bai tap nay da co trong database chua
            nguoidung = TrangChu.nguoidung;

            // lấy mục tiêu hiện tại (có thể null)
            muctieu = TrangChu.muctieu;
            if (muctieu != null)
            {
                // lấy thống kê ngày hiện tại (có thể null)
                thongkengay = TrangChu.getThongKeNgayHienTai(muctieu);
                //check da tap lan nao trong ngay chua

                tabata = connection.Table<ThongKeBaiTap>().Where(r => r.IdThongKeNgay == thongkengay.IdThongKeNgay && r.IdBaiTap == 8).FirstOrDefault();
                if (tabata == null)
                {
                    tabata = new ThongKeBaiTap()
                    {
                        IdBaiTap = 8,
                        IdThongKeNgay = thongkengay.IdThongKeNgay,
                        QuangDuong = 0,
                        LuongKaloTieuHao = 0,
                        ThoiGianTap = 0
                    };
                    connection.Insert(tabata);
                }
            }

            // neu khong thi cho tap nhung khong dua vao database
            else
            {
                tabata = new ThongKeBaiTap();
            }
        }
Example #15
0
        private void OnNavigated(object sender, NavigationEventArgs e)
        {
            this.SplitView.IsPaneOpen = false;

            if ((sender as Frame).Content.GetType() == typeof(TrangChu))
            {
                var tc = (sender as Frame).Content as TrangChu;
                if(e.Parameter.GetType() == typeof(NguoiDung))
                {
                    nguoidung = e.Parameter as NguoiDung;
                    muctieu = TrangChu.getMucTieuHienTai(nguoidung);

                    thongkengay = TrangChu.getThongKeNgayHienTai(muctieu);

                    tendangnhapTextBlock.Text = nguoidung.TenDangNhap;
                    tuoiTextBlock.Text = (DateTime.Today.Year - DateTime.ParseExact(nguoidung.NgaySinh, "dd/MM/yyyy", new CultureInfo("vi-vn")).Year).ToString();
                    gioitinhTextBlock.Text = nguoidung.GioiTinh;
                }
            }
                // neu tro ve trang MainPage thi loại bỏ shell
                if ((sender as Frame).Content.GetType() == typeof(MainPage))
            {
                Frame.Navigate(typeof(MainPage));
                Frame.BackStack.Clear();
            }
        }
Example #16
0
        //get current location
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            nguoidung = TrangChu.nguoidung;


            // lấy mục tiêu hiện tại (có thể null)
            muctieu = TrangChu.getMucTieuHienTai(nguoidung);
            if (muctieu != null)
            {
                // lấy thống kê ngày hiện tại (có thể null)
                thongkengay = TrangChu.getThongKeNgayHienTai(muctieu);
                //check da tap lan nao trong ngay chua

                dapXe = connection.Table<ThongKeBaiTap>().Where(r => r.IdThongKeNgay == thongkengay.IdThongKeNgay && r.IdBaiTap == 2).FirstOrDefault();
                if (dapXe == null)
                {
                    dapXe = new ThongKeBaiTap()
                    {
                        IdBaiTap = 2,
                        IdThongKeNgay = thongkengay.IdThongKeNgay,
                        QuangDuong = 0,
                        LuongKaloTieuHao = 0,
                        ThoiGianTap = 0
                    };
                    connection.Insert(dapXe);
                }

            }

            // neu khong thi cho tap nhung khong dua vao database
            else
            {
                dapXe = new ThongKeBaiTap();
            }


            var accessStatus = await Geolocator.RequestAccessAsync();
            switch (accessStatus)
            {
                case GeolocationAccessStatus.Allowed:

                    // Get the current location
                    position = await locator.GetGeopositionAsync();
                    point = position.Coordinate.Point;
                    myMap.ZoomLevel = 15;

                    // Set map location
                    await myMap.TrySetViewAsync(point);
                    locator.MovementThreshold = 1;

                    //create a icon in current location
                    icon = new MapIcon();
                    icon.Image = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/pin.png"));
                    icon.NormalizedAnchorPoint = new Point(0.5, 1);
                    icon.Location = position.Coordinate.Point;
                    icon.Title = "You are here";
                    myMap.MapElements.Add(icon);
                    //  locator = new Geolocator { ReportInterval = 500 };

                    // Subscribe to PositionChanged event to get location updates
                    locator.PositionChanged += OnPositionChanged;
                    break;

                case GeolocationAccessStatus.Denied:
                    // Handle when access to location is denied
                    break;

                case GeolocationAccessStatus.Unspecified:
                    // Handle when an unspecified error occurs
                    break;
            }


        }