Exemplo n.º 1
0
        internal decimal CalculateAndSetUserBMR(Cl_UserViewModel vrpUserViewModel)
        {
            try
            {
                if (vrpUserViewModel == null ||
                    vrpUserViewModel.Age <= 0 ||
                    vrpUserViewModel.HeightInCm <= decimal.Zero ||
                    vrpUserViewModel.Sex <= 0 ||
                    vrpUserViewModel.Weight <= decimal.Zero)
                {
                    return(decimal.Zero);
                }

                switch (vrpUserViewModel.Sex)
                {
                case (int)E_Sex.Female:
                {
                    return(655 + (decimal)9.6 * vrpUserViewModel.Weight + (decimal)1.8 * vrpUserViewModel.HeightInCm - (decimal)4.7 * vrpUserViewModel.Age);
                }

                case (int)E_Sex.Male:
                {
                    return(66 + (decimal)13.7 * vrpUserViewModel.Weight + 5 * vrpUserViewModel.HeightInCm - (decimal)6.8 * vrpUserViewModel.Age);
                }

                default: return(decimal.Zero);
                }
            }
            catch (Exception vrlException)
            {
                MessageBox.Show("Wystąpił błąd " + vrlException.Message);
                return(decimal.Zero);
            }
        }
Exemplo n.º 2
0
        internal void LoadUserAdditionalData()
        {
            try
            {
                Cl_UserViewModel vrlUserViewModel = vrcUserRepository.GetAdditionalUserDataById(vrcView.UserId);
                if (vrlUserViewModel == null)
                {
                    vrcView.IsNewUser = true;
                    return;
                }

                vrcView.Age        = vrlUserViewModel.Age;
                vrcView.Sex        = (int)vrlUserViewModel.Sex;
                vrcView.Weight     = vrlUserViewModel.Weight;
                vrcView.HeightInCm = vrlUserViewModel.HeightInCm;
                SetUserViewModelData(vrcView.Age, vrcView.Sex, vrcView.Weight, vrcView.HeightInCm);
                vrcView.BMR = CalculateAndSetUserBMR(vrcUserViewModel);
            }
            catch (SqlException vrlSqlException)
            {
                MessageBox.Show("Wystąpił błąd bazy danych" + vrlSqlException.Message);
            }
            catch (Exception vrlException)
            {
                MessageBox.Show("Wystąpił błąd" + vrlException.Message);
            }
        }
Exemplo n.º 3
0
 private void SetUserViewModelData(int vrpAge, int vrpSex, decimal vrpWeight, decimal vrpHeight)
 {
     vrcUserViewModel = new Cl_UserViewModel
     {
         Age        = vrpAge,
         HeightInCm = vrpHeight,
         Weight     = vrpWeight,
         Sex        = vrpSex
     };
 }
Exemplo n.º 4
0
 public bool AddUserAdditionalDataById(Cl_UserViewModel vrpUser)
 {
     using (MySqlConnection vrlConnection = new MySqlConnection(new Cl_RemoteDB().ConnectionString))
     {
         vrlConnection.Open();
         vrlConnection.Query("INSERT INTO kal_UserData(usd_usr_Id, usd_Age, usd_Sex, usd_Weight, usd_Height) VALUES('" + vrpUser.Id + "', '" + vrpUser.Age + "','" + vrpUser.Sex + "', '" + vrpUser.Weight + "', " + vrpUser.HeightInCm + ")");
         vrlConnection.Close();
         return(true);
     }
 }
Exemplo n.º 5
0
 public bool EditUserAdditionalDataById(Cl_UserViewModel vrpUser)
 {
     using (MySqlConnection vrlConnection = new MySqlConnection(new Cl_RemoteDB().ConnectionString))
     {
         vrlConnection.Open();
         vrlConnection.Query("UPDATE kal_UserData SET usd_Age = " + vrpUser.Age + ", usd_Sex = " + vrpUser.Sex + ", usd_Weight = " + vrpUser.Weight + ", usd_Height = " + vrpUser.HeightInCm + " WHERE usd_usr_Id = " + vrpUser.Id);
         vrlConnection.Close();
         return(true);
     }
 }
Exemplo n.º 6
0
 public Cl_UserViewModel GetAdditionalUserDataById(int vrpUserId)
 {
     using (MySqlConnection vrlConnection = new MySqlConnection(new Cl_RemoteDB().ConnectionString))
     {
         vrlConnection.Open();
         Cl_UserViewModel _User = vrlConnection.Query <Cl_UserViewModel>
                                      ("SELECT usd_usr_Id as Id, usd_Sex as Sex, usd_Age as Age, usd_Weight as Weight, usd_Height as HeightInCm from kal_UserData where usd_usr_Id = '" + vrpUserId + "'").FirstOrDefault();
         vrlConnection.Close();
         return(_User);
     }
 }