Exemplo n.º 1
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();
            }
        }
Exemplo n.º 2
0
        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();
            }
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 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;
        }
Exemplo n.º 5
0
 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";
     }
 }
Exemplo n.º 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();
            }
        }
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            //image
            List <Uri> uriLst = new List <Uri>();

            for (int i = 1; i <= 5; i++)
            {
                uriLst.Add(new Uri("ms-appx:///Assets/dungngoi" + i + ".png"));
            }

            for (int i = 0; i < 5; 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);
                dungngoi    = connection.Table <ThongKeBaiTap>().Where(r => r.IdThongKeNgay == thongkengay.IdThongKeNgay && r.IdBaiTap == 4).FirstOrDefault();
                if (dungngoi == null)
                {
                    dungngoi = new ThongKeBaiTap()
                    {
                        IdBaiTap         = 4,
                        IdThongKeNgay    = thongkengay.IdThongKeNgay,
                        QuangDuong       = 0,
                        SoBuoc           = 0,
                        LuongKaloTieuHao = 0,
                        ThoiGianTap      = 0
                    };
                    connection.Insert(dungngoi);
                }
            }

            // mục tiêu == null || thống kê ngày == null -> tập nhưng không đưa vào database
            else
            {
                dungngoi = new ThongKeBaiTap();
            }
        }
Exemplo n.º 8
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;
        }
Exemplo n.º 9
0
        /// <summary>
        /// Khi người dùng tap vào một ngày, sẽ hiện ra thống kê cho ngày hôm đó
        /// </summary>
        private void Grid_Tapped(object sender, TappedRoutedEventArgs e)
        {
            thongkengayFlipView.Visibility = Visibility.Visible;
            btdetailStackPanel.Visibility  = Visibility.Collapsed;
            Initialize_Calendar(calendarDate);

            // change background of the grid that is tapped
            (sender as Grid).Background = new SolidColorBrush(Colors.LightSeaGreen);

            TextBlock textblock = (sender as Grid).Children[0] as TextBlock;

            // nếu ô trống thì bỏ qua
            if (textblock.Text == null || textblock.Text == "")
            {
                return;
            }

            string date = Int32.Parse(textblock.Text).ToString("00") + "/" + CalendarHeader.Tag.ToString(); /* dd/MM/yyyy */

            ngayTextBlock.Text = date;

            //DateTime date = DateTime.ParseExact(str, "dd/MM/yyyy", new CultureInfo("vi-vn"));
            ThongKeNgay tkn = connection.Table <ThongKeNgay>().Where(r => r.IdMucTieu == muctieu.IdMucTieu && r.Ngay == date).FirstOrDefault();

            if (tkn != null)
            {
                thongkeFlipView.Visibility = Visibility.Visible;
                muctieuTextBlock.Text      = tkn.IdMucTieu.ToString();
                kaloduavaoTextBlock.Text   = tkn.LuongKaloDuaVao.ToString();
                kalotieuhaoTextBlock.Text  = tkn.LuongKaloTieuHao.ToString();

                int soluongbaitap = connection.ExecuteScalar <int>("SELECT COUNT(*) FROM ThongKeBaiTap WHERE IdThongKeNgay =?", tkn.IdThongKeNgay);
                soluongbtTextBlock.Text = soluongbaitap.ToString();

                int tongthoigiantap = connection.ExecuteScalar <int>("SELECT SUM(ThoiGianTap) FROM THONGKEBAITAP WHERE IdThongKeNgay =?", tkn.IdThongKeNgay);
                thoigiantapTextBlock.Text = tongthoigiantap.ToString();

                var q = connection.Table <ThongKeBaiTap>().Where(r => r.IdThongKeNgay == tkn.IdThongKeNgay);
                List <BaiTapDaTap> baidatapList = new List <BaiTapDaTap>();
                foreach (var item in q)
                {
                    var tenbaitap = connection.Table <BaiTap>().Where(r => r.IdBaiTap == item.IdBaiTap).FirstOrDefault().TenBaiTap;
                    baidatapList.Add(new BaiTapDaTap()
                    {
                        IdThongKeBaiTap  = item.IdThongKeNgay,
                        IdThongKeNgay    = item.IdThongKeNgay,
                        IdBaiTap         = item.IdBaiTap,
                        TenBaiTap        = tenbaitap,
                        LuongKaloTieuHao = item.LuongKaloTieuHao,
                        QuangDuong       = item.QuangDuong,
                        ThoiGianTap      = item.ThoiGianTap
                    });
                }
                (PieChart.Series[0] as PieSeries).ItemsSource = baidatapList;
            }
            else
            {
                thongkengayFlipView.Visibility = Visibility.Collapsed;
                //kaloduavaoTextBlock.Text = "0";
                //kalotieuhaoTextBlock.Text = "0";
                //soluongbtTextBlock.Text = "0";
                //thoigiantapTextBlock.Text = "0";
            }
        }
Exemplo n.º 10
0
        private async void Page_Loaded(object sender, RoutedEventArgs e)
        {
            // neu muctieu == null ---> tuc nguoidung chua co muc tieu nao hien tai
            if (muctieu == null)
            {
                // an header dau tien
                calsGiamGrid.Visibility = Visibility.Collapsed;
            }
            else
            {
                string today = DateTime.Today.ToString("dd/MM/yyyy");
                // neu nguoi dung chua bat dau muc tieu hien tai
                if (muctieu.ThoiGianBatDau == null || muctieu.TrangThai == "Chưa bắt đầu")
                {
                    calsGiamGrid.Visibility = Visibility.Collapsed;
                    MessageDialog msDialog = new MessageDialog("Bạn vẫn chưa bắt đầu tập luyện!\n");
                    msDialog.Commands.Add(new UICommand("Ok, đến trang tập luyện"));
                    msDialog.Commands.Add(new UICommand("Để sau"));
                    var result = await msDialog.ShowAsync();

                    if (result.Label.Equals("Để sau"))
                    {
                        return;
                    }
                    else
                    {
                        // dat thoi gian bat dau la ngay hom nay
                        muctieu.ThoiGianBatDau = today;
                        muctieu.TrangThai      = "Đã bắt đầu";
                        connection.Update(muctieu);
                        Frame.Navigate(typeof(DanhSachBaiTap), nguoidung);
                    }
                }

                // kiem tra thoigianketthuc cua muc tieu

                //DateTime ngayketthuc = DateTime.Parse(muctieu.ThoiGianBatDau).AddDays((int)muctieu.SoNgay); <--- nho dung ParseExact de theo chuan dd/MM/yyyy
                DateTime ngayketthuc = DateTime.ParseExact(muctieu.ThoiGianBatDau, "dd/MM/yyyy", new CultureInfo("vi-vn")).AddDays(muctieu.SoNgay);
                // neu da vuot qua so ngay
                if (DateTime.Today > ngayketthuc)
                {
                    muctieu.TrangThai = "Hoàn thành";
                    connection.Update(muctieu);
                    MessageDialog msDialog = new MessageDialog("Chúc mừng, bạn đã tập hết số ngày của mục tiêu đề ra\nHãy xem lại quá trình luyện tập của bạn!");
                    msDialog.Commands.Add(new UICommand("Xem thống kê"));
                    msDialog.Commands.Add(new UICommand("Mục tiêu mới"));
                    var result = await msDialog.ShowAsync();

                    if (result.Label.Equals("Mục tiêu mới"))
                    {
                        // chuyển tới trang mục tiêu mới
                        denTaoMucTieuMoiPage();
                    }
                    else
                    {
                        // chuyển đến trang thống kê
                        Frame.Navigate(typeof(ThongKePage), nguoidung);
                    }
                }
                // neu van con trong thoi han cua muc tieu
                else
                {
                    thongkengay = connection.Table <ThongKeNgay>().Where(r => r.IdMucTieu == muctieu.IdMucTieu && r.Ngay == today).FirstOrDefault();
                    if (thongkengay == null)
                    {
                        thongkengay           = new ThongKeNgay();
                        thongkengay.IdMucTieu = muctieu.IdMucTieu;
                        thongkengay.Ngay      = today;
                        // mặc định = chỉ số bmr
                        thongkengay.LuongKaloDuaVao = muctieu.ChiSoBMR;
                        connection.Insert(thongkengay);
                    }
                }
                // LuongKaloCanGiamHomNay = KaloCanTieuHaoMoiNgay (để giảm cân) - LuongKaloTieuHao (chohoatdongbaitap) - chisobmr (luongkalo chohoatdonghangngay) + tongluongkaloduavao
                if (muctieu != null && thongkengay != null)
                {
                    double calsCanGiam = muctieu.LuongKaloCanTieuHaoMoiNgay;
                    calsCanGiamTextBlock.Text = calsCanGiam.ToString();

                    // luong cals giam tu bai tap
                    double calsGiamBaiTap = thongkengay.LuongKaloTieuHao;
                    calsBaiTapTextBlock.Text = calsGiamBaiTap.ToString();

                    // luong Cals giam tu thuc don
                    double calsGiamThucDon = muctieu.ChiSoBMR - thongkengay.LuongKaloDuaVao - thongkengay.LuongKaloNgoaiDuKien;
                    calsThucDonTextBlock.Text = calsGiamThucDon.ToString();

                    double calsConThieu = calsCanGiam - calsGiamBaiTap - calsGiamThucDon;
                    calsConThieuTextBlock.Text = calsConThieu.ToString();
                }
            }
        }
Exemplo n.º 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();
            }
        }
Exemplo n.º 12
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;
            }
        }
Exemplo n.º 13
0
        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();
            }
        }