private void UpdateAge() { try { if (Up_Age == String.Empty || Up_Age == null) { ErrorMes = Properties.Resources.emptyfield; } else if (activUser.Age == Convert.ToInt16(Up_Age)) { ErrorMes = Properties.Resources.olddata; } else { if (dbu.UpdateAgeUser(ID_user, Convert.ToInt16(Up_Age))) { activUser.Age = Convert.ToInt16(Up_Age); int remain_cal = db.GetDailyCal(ID_user, today.ToString()); int new_cal = 0; int now_day_cal = activUser.D_Cal; int eat_cal = now_day_cal - remain_cal; new_cal = GetNewDayCal(activUser.Gender, activUser.Purpose_of_Use, this.GetActivity(activUser.Activity), activUser.Height, activUser.Weight, activUser.Age); db.UpdateDailyCal(ID_user, today.ToString(), new_cal - eat_cal); if (dbu.UpdateDailyCalUser(ID_user, new_cal)) { Close(); } } } } catch (SystemException e) { ErrorMes = Properties.Resources.errordata; } }
private void Add_Product() { try { if (Mass == null || Mass == String.Empty) { ErrorMes = Properties.Resources.emptyfield; } else { int Daily_Cal = Obj.daily_cal; string id_product = dB_AddFood.GetIdProductByName(All_Product[Index].Name); string id_recipe = dB_AddFood.GetIdRecipeByName(All_Product[Index].Name); int cal = 0; int id_type_food = Properties.Settings.Default.IdTypeOfFood; if (id_product == "-1") { dB_AddFood.AddRecipeInDailyFood(All_Product[Index].ID, Convert.ToInt32(Mass), Convert.ToInt32(Properties.Settings.Default.IdUser), id_type_food, today.ToString()); cal = dB_AddFood.GetCalRecipeByID(id_recipe); } else if (id_recipe == "-1") { dB_AddFood.AddProductInDailyFood(All_Product[Index].ID, Convert.ToInt32(Mass), Convert.ToInt32(Properties.Settings.Default.IdUser), id_type_food, today.ToString()); cal = dB_AddFood.GetCalProductByID(id_product); } int caloriesEaten; caloriesEaten = Convert.ToInt32(Mass) * cal / 100; Close(); if (id_type_food == 1) { Obj.Name_food_breakfast.Add(new Food { Name = All_Product[Index].Name, Mass = Mass + "г", Cal = Convert.ToString(caloriesEaten) + "ккал" }); } else if (id_type_food == 2) { Obj.Name_food_lunch.Add(new Food { Name = All_Product[Index].Name, Mass = Mass + "г", Cal = Convert.ToString(caloriesEaten) + "ккал" }); } else if (id_type_food == 3) { Obj.Name_food_dinner.Add(new Food { Name = All_Product[Index].Name, Mass = Mass + "г", Cal = Convert.ToString(caloriesEaten) + "ккал" }); } else if (id_type_food == 4) { Obj.Name_food_snack.Add(new Food { Name = All_Product[Index].Name, Mass = Mass + "г", Cal = Convert.ToString(caloriesEaten) + "ккал" }); } else { } Daily_Cal -= caloriesEaten; db.UpdateDailyCal(Properties.Settings.Default.IdUser, today.ToString(), Daily_Cal); Obj.daily_cal = Daily_Cal; } } catch (SystemException) { ErrorMes = Properties.Resources.errordata; } }