public void WelcomeScreen_Load(object sender, EventArgs e) { string con = MyMethodsLib.GetConnectionString(); unameBox.Text = Username; string height = MyMethodsLib.GetHeightFromDbs(Username, con).ToString(); weightBox.Text = MyMethodsLib.GetWeightFromDbs(Username, con).ToString(); BMIBox.Text = MyMethodsLib.CalculateBMI(this.weightBox.Text.ToString(), height); double kgToLoose = MyMethodsLib.KgToLoose(Username, weightBox.Text); kgBox.Text = MyMethodsLib.WeightResultOutput(Username, kgToLoose, weightBox.Text); intakeBox.Text = MyMethodsLib.CaloriesIntake(Username).ToString(); dietModeBox.Text = MyMethodsLib.GetDietModeFromDbs(Username, MyMethodsLib.GetConnectionString()); SetupCharts4Projection(Username); }
public void SetupCharts4Projection(string Username) { double weightToLoose = MyMethodsLib.KgToLoose(Username, weightBox.Text); string slowDays = MyMethodsLib.DaysToAchieveGoal(weightToLoose.ToString(), 0.1); string steadyDays = MyMethodsLib.DaysToAchieveGoal(weightToLoose.ToString(), 0.2); string intenseDays = MyMethodsLib.DaysToAchieveGoal(weightToLoose.ToString(), 0.3); slowModeBox.Text = slowDays; slowWeeksBox.Text = MyMethodsLib.TimeToAchieveGoal(slowDays, 7); slowMonthsBox.Text = MyMethodsLib.TimeToAchieveGoal(slowDays, 30); steadyModeBox.Text = steadyDays; steadyWeeksBox.Text = MyMethodsLib.TimeToAchieveGoal(steadyDays, 7); steadyMonthsBox.Text = MyMethodsLib.TimeToAchieveGoal(steadyDays, 30); intenseModeBox.Text = intenseDays; intenseWeeksBox.Text = MyMethodsLib.TimeToAchieveGoal(intenseDays, 7); intenseMonthsBox.Text = MyMethodsLib.TimeToAchieveGoal(intenseDays, 30); }
public void Button2_Click(object sender, EventArgs e) { using (SqlConnection connection = new SqlConnection(MyMethodsLib.GetConnectionString())) { string dailyWeight = dayWeightBox.Text.ToString(); if (dailyWeight != "") { int.TryParse(dailyWeight, out int Weight); try { var Date = DateTime.Now.Date; SqlCommand cmdCheckLastInputDate = new SqlCommand { CommandText = "SELECT Date FROM [tblMeasures] WHERE Username=@Username" }; cmdCheckLastInputDate.Parameters.AddWithValue("@Username", Username); cmdCheckLastInputDate.Parameters.AddWithValue("@Date", Date); List <DateTime> dates = new List <DateTime>(); cmdCheckLastInputDate.Connection = connection; try { connection.Open(); SqlDataReader dataReader = cmdCheckLastInputDate.ExecuteReader(); if (dataReader.HasRows) //it has rows, proved { while (dataReader.Read()) //this while does not go anywhere, why? { var Date2 = dataReader.GetDateTime(0).Date; dates.Add(Date2); } dataReader.Close(); SqlCommand cmdCheckRowsNo = new SqlCommand { CommandText = "SELECT * FROM [tblMeasures]", Connection = connection }; int counter = 0; SqlDataReader dataReaderForAllTable = cmdCheckRowsNo.ExecuteReader(); while (dataReaderForAllTable.Read()) { counter++; } dataReaderForAllTable.Close(); Int32 Height = 0; SqlCommand cmdUserHeight = new SqlCommand { CommandText = "SELECT Height FROM [tblMeasures] WHERE Username=@Username" }; cmdUserHeight.Parameters.AddWithValue("@Username", Username); cmdUserHeight.Parameters.AddWithValue("@Height", Height); cmdUserHeight.Connection = connection; SqlDataReader dataReader4Height = cmdUserHeight.ExecuteReader(); if (dataReader4Height.HasRows) { while (dataReader4Height.Read()) { Height = dataReader4Height.GetInt32(0); } dataReader4Height.Close(); } else { MessageBox.Show("Something went wrong: Line 595; DataReader doesn't have rows!"); } string comparedDate = ""; foreach (DateTime dd in dates) { if (dd == Date) { comparedDate = dd.ToString(); } } if (comparedDate == "") { try { SqlCommand sqlInsertNewWeightRecord = new SqlCommand(); int MeasurementNo = counter; sqlInsertNewWeightRecord.CommandText = "INSERT INTO [tblMeasures] (MeasurementNo, Username, Height, Weight, Date) VALUES (@MeasurementNo, @Username, @Height, @Weight, @Date)"; sqlInsertNewWeightRecord.Parameters.AddWithValue("@MeasurementNo", MeasurementNo); sqlInsertNewWeightRecord.Parameters.AddWithValue("@Username", Username); sqlInsertNewWeightRecord.Parameters.AddWithValue("@Height", Height); sqlInsertNewWeightRecord.Parameters.AddWithValue("@Weight", Weight); sqlInsertNewWeightRecord.Parameters.AddWithValue("@Date", Date); sqlInsertNewWeightRecord.Connection = connection; sqlInsertNewWeightRecord.ExecuteNonQuery(); weightBox.Text = Weight.ToString(); dayWeightBox.Clear(); connection.Close(); string bmi = MyMethodsLib.CalculateBMI(Weight.ToString(), Height.ToString()); BMIBox.Text = bmi; MessageBox.Show("Your Today's Weight has been recorded in database!"); } catch (System.Exception) { MessageBox.Show("Something went wrong: Line 1254"); } } else { MessageBox.Show("You can't add more data today, you can modify today input only."); dayWeightBox.Clear(); } } } catch (System.Exception) { MessageBox.Show("Something went wrong: Line 630"); } } catch (System.Exception) { MessageBox.Show("Something went wrong: Line 628"); } } } kgBox.Text = MyMethodsLib.WeightResultOutput(Username, MyMethodsLib.KgToLoose(Username, weightBox.Text), weightBox.Text); SetupCharts4Projection(Username); string currentWeight = weightBox.Text; double.TryParse(currentWeight, out double currentWeightDouble); string daysToAchieveGoalsSlowMode = slowModeBox.Text; int.TryParse(daysToAchieveGoalsSlowMode, out int daysAllProcessSlowMode); int gapDivisor = daysAllProcessSlowMode / 6; int counter2 = gapDivisor; while (counter2 < daysAllProcessSlowMode - 1) { this.slowModeChart.Series["Weight"].Points.AddXY(counter2, currentWeightDouble - 0.1 * counter2); counter2 += gapDivisor; } this.slowModeChart.ChartAreas["ChartArea1"].AxisX.Title = "Days"; this.slowModeChart.ChartAreas["ChartArea1"].AxisY.Title = "Your Weight Drop"; //for steadyModeChart string daysToAchieveGoalSteadyMode = steadyModeBox.Text; int.TryParse(daysToAchieveGoalSteadyMode, out int daysAllProcessSteadyMode); int gapDivisorSteady = daysAllProcessSteadyMode / 6; int counterSteady = gapDivisorSteady; while (counterSteady < daysAllProcessSteadyMode - 1) { this.steadyModeChart.Series["Weight"].Points.AddXY(counterSteady, currentWeightDouble - 0.2 * counterSteady); counterSteady += gapDivisorSteady; } this.steadyModeChart.ChartAreas["ChartArea1"].AxisX.Title = "Days"; this.steadyModeChart.ChartAreas["ChartArea1"].AxisY.Title = "Your Weight Drop"; //for intenseModeChart string daysToAchieveGoalIntenseMode = intenseModeBox.Text; int.TryParse(daysToAchieveGoalIntenseMode, out int daysAllProcessIntenseMode); int gapDivisorIntense = daysAllProcessIntenseMode / 6; int counterIntense = gapDivisorIntense; while (counterIntense < daysAllProcessIntenseMode - 1) { this.intenseModeChart.Series["Weight"].Points.AddXY(counterIntense, currentWeightDouble - 0.3 * counterIntense); counterIntense += gapDivisorIntense; } this.intenseModeChart.ChartAreas["ChartArea1"].AxisX.Title = "Days"; this.intenseModeChart.ChartAreas["ChartArea1"].AxisY.Title = "Your Weight Drop"; }
public void Button1_Click(object sender, EventArgs e) { string con = MyMethodsLib.GetConnectionString(); int MeasurementNo = MyMethodsLib.GetMeasurementNoWithTodayDate(Username, con); var today2 = DateTime.Now.Date; var tomorrow2 = today2.AddDays(1); var dateForMealFromDbs2 = MyMethodsLib.GetMealDate(MeasurementNo, con); if (tomorrow2 != dateForMealFromDbs2) { string mode = ""; string kgToLoose = MyMethodsLib.WeightResultOutput(Username, MyMethodsLib.KgToLoose(Username, weightBox.Text), weightBox.Text); if (kgToLoose != "0") { if (slowModeRadioBtn.Checked) { mode = "M: Slow"; } else if (steadyModeRadioBtn.Checked) { mode = "M: Steady"; } else if (intenseModeRadioBtn.Checked) { mode = "M: Intense"; } else { mode = ""; MessageBox.Show("Please, choose Your diet mode!"); } } else { mode = "Not set"; MessageBox.Show("We cannot help you as Your Weight is perfectly fine!"); } using (SqlConnection connection = new SqlConnection(MyMethodsLib.GetConnectionString())) { try { string DietMode = mode; SqlCommand cmd2 = new SqlCommand { CommandText = "UPDATE [tblMeasures] SET DietMode=@DietMode WHERE MeasurementNo=@MeasurementNo" }; connection.Open(); cmd2.Parameters.AddWithValue("@MeasurementNo", MeasurementNo); cmd2.Parameters.AddWithValue("@DietMode", DietMode); cmd2.Connection = connection; cmd2.ExecuteNonQuery(); connection.Close(); dietModeBox.Text = DietMode; MessageBox.Show("Your Diet Mode is set!"); if (DietMode != "Not set") { intakeBox.Text = MyMethodsLib.CaloriesIntake(Username).ToString(); } else { intakeBox.Text = "N\\A"; MessageBox.Show("Sorry, not this time!"); } } catch (System.Exception) { if (connection.State == ConnectionState.Open) { connection.Close(); } MessageBox.Show("Something went wrong with SQL query Line 905"); } } } string getPath = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, @"..\..\..\")); string path = getPath + "DietData"; string breakJsonName = "b.json"; string break2JsonName = "b2.json"; string lunchJsonName = "l.json"; string dinnerJsonName = "d.json"; //IF THERE IS ALREADY DATE FOR TOMORROW, DO NOT ALLOW TO CHANGE DIET MODE, //OUTPUT THE MESSAGE BOX WITH RELEVANT INFO //START DOING METHODS FOR OUTPUTTING TEXT TO RICH BOXES //REMEMBER, THERE MIGHT BE NO ENTRY IN THIS DBS //SO REMEMBER TO CHECK IT var today = DateTime.Now.Date; var tomorrow = today.AddDays(1); var dateForMealFromDbs = MyMethodsLib.GetMealDate(MeasurementNo, con); if (tomorrow == dateForMealFromDbs) { MessageBox.Show("You can't change diet mode today, try tomorrow!"); } else { var randomRecipes = MyMethodsLib.RandomizeRecipesSelection(MyMethodsLib.CaloriesIntake(Username).ToString(), MyMethodsLib. GetVeggieOptionFromDbs(Username, con), path, breakJsonName, break2JsonName, lunchJsonName, dinnerJsonName); MyMethodsLib.RecordRecipesToDbs(randomRecipes, MeasurementNo, con); int breakID = MyMethodsLib.GetBreakfastID(MeasurementNo, con); int break2ID = MyMethodsLib.GetBreakfast2ID(MeasurementNo, con); int lunchID = MyMethodsLib.GetLunchID(MeasurementNo, con); int dinnerID = MyMethodsLib.GetDinnerID(MeasurementNo, con); string break2RTFName = Username + "_" + tomorrow.ToString("ddMMyyyy") + "_breakfast2.rtf"; string breakRTFName = Username + "_" + tomorrow.ToString("ddMMyyyy") + "_breakfast.rtf"; string lunchRTFName = Username + "_" + tomorrow.ToString("ddMMyyyy") + "_lunch.rtf"; string dinnerRTFName = Username + "_" + tomorrow.ToString("ddMMyyyy") + "_dinner.rtf"; //breakfast MyMethodsLib.SetUpRecipe(path, breakJsonName, breakID, tomorrow, breakRTFName); //breakfast2 MyMethodsLib.SetUpRecipe(path, break2JsonName, break2ID, tomorrow, break2RTFName); //lunch MyMethodsLib.SetUpRecipe(path, lunchJsonName, lunchID, tomorrow, lunchRTFName); //dinner MyMethodsLib.SetUpRecipe(path, dinnerJsonName, dinnerID, tomorrow, dinnerRTFName); //MessageBox.Show("Your Diet Mode is selected!"); } }
public void UpdateBtn_Click(object sender, EventArgs e) { //declare variables needed for operations string Vegetarian = ""; string Gender = GenderBox.Text; string Password = oldPasswBox.Text; string ModifWeightIn = modifLastWeightIn.Text; if (yesRadioBtn.Checked) { Vegetarian = "Yes"; } if (noRadioBtn.Checked) { Vegetarian = "No"; } string con = MyMethodsLib.GetConnectionString(); if (nameBox.Text != "") { MyMethodsLib.ChangeUserName(Username, nameBox.Text, con); nameBox.Text = ""; } if (surnameBox.Text != "") { MyMethodsLib.ChangeUserSurName(Username, surnameBox.Text, con); surnameBox.Text = ""; } if (emailBx.Text != "") { MyMethodsLib.ChangeEmail(Username, emailBx.Text, con); emailBx.Text = ""; } using (SqlConnection sqlConnect = new SqlConnection(MyMethodsLib.GetConnectionString())) { if (Vegetarian != "") { try { sqlConnect.Open(); SqlCommand sqlCmdUpdateVegetarian = new SqlCommand("VegetarianUpdate", sqlConnect) { CommandType = CommandType.StoredProcedure }; SqlCommand cmdUpdateVegetarian = new SqlCommand { CommandText = "SELECT * from [tblUserNamePassw] WHERE UserName=@UserName" }; cmdUpdateVegetarian.Parameters.AddWithValue("@Username", Username); cmdUpdateVegetarian.Parameters.AddWithValue("@Vegetarian", Vegetarian); cmdUpdateVegetarian.Connection = sqlConnect; sqlCmdUpdateVegetarian.Parameters.AddWithValue("@Username", Username); sqlCmdUpdateVegetarian.Parameters.AddWithValue("@Vegetarian", Vegetarian); sqlCmdUpdateVegetarian.ExecuteNonQuery(); MessageBox.Show("Vegetarian option was changed!"); sqlConnect.Close(); yesRadioBtn.Checked = false; noRadioBtn.Checked = false; } catch (System.Exception) { MessageBox.Show("SQL Query unsuccessful"); } } //code to update Gender if (Gender != "") { try { sqlConnect.Open(); SqlCommand sqlCmdUpdateGender = new SqlCommand("GenderUpdate", sqlConnect) { CommandType = CommandType.StoredProcedure }; SqlCommand sqlCommand = new SqlCommand { CommandText = "SELECT * from [tblUserNamePassw] WHERE UserName=@UserName" }; SqlCommand cmdUpdateGender = sqlCommand; cmdUpdateGender.Parameters.AddWithValue("@Username", Username); cmdUpdateGender.Parameters.AddWithValue("@Gender", Gender); cmdUpdateGender.Connection = sqlConnect; sqlCmdUpdateGender.Parameters.AddWithValue("@Username", Username); sqlCmdUpdateGender.Parameters.AddWithValue("@Gender", Gender); sqlCmdUpdateGender.ExecuteNonQuery(); MessageBox.Show("Gender changed successfully!"); GenderBox.SelectedItem = ""; sqlConnect.Close(); } catch (System.Exception) { MessageBox.Show("SQL Query unsuccessful"); } } // fun now... .code to update Password if (Password != "") { try { sqlConnect.Open(); SqlCommand sqlCmdUpdatePassword = new SqlCommand("PasswordUpdate", sqlConnect) { CommandType = CommandType.StoredProcedure }; SqlCommand cmdUpdatePassword = new SqlCommand { CommandText = "SELECT Password from [tblUserNamePassw] WHERE UserName=@UserName" }; cmdUpdatePassword.Parameters.AddWithValue("@Username", Username); cmdUpdatePassword.Connection = sqlConnect; try { string oldPassword = ""; SqlDataReader dataReader = cmdUpdatePassword.ExecuteReader(); if (dataReader.HasRows) { while (dataReader.Read()) { oldPassword = dataReader.GetSqlString(0).ToString(); } } dataReader.Close(); if (Password == oldPassword) { if (newPasswBox.Text != "" && newPasswBox.Text.Count() > 6) { Password = newPasswBox.Text; } else { MessageBox.Show("Please make sure your new password contains at least 7 letters!"); } } } catch (System.Exception) { MessageBox.Show("Unsuccessful operation!"); } sqlCmdUpdatePassword.Parameters.AddWithValue("@Username", Username); sqlCmdUpdatePassword.Parameters.AddWithValue("@Password", Password); sqlCmdUpdatePassword.ExecuteNonQuery(); sqlConnect.Close(); MessageBox.Show("Password successfullly changed!"); } catch (System.Exception) { MessageBox.Show("SQL Query unsuccessful"); } } //code to update last weight if (ModifWeightIn != "") { try { var Date = DateTime.Now.Date; SqlCommand cmdUpdateWeight = new SqlCommand { CommandText = "SELECT Date from [tblMeasures] WHERE UserName=@UserName AND Date=@Date" }; cmdUpdateWeight.Parameters.AddWithValue("@Username", Username); cmdUpdateWeight.Parameters.AddWithValue("@Weight", ModifWeightIn); cmdUpdateWeight.Parameters.AddWithValue("@Date", Date); cmdUpdateWeight.Connection = sqlConnect; string dateFromDbs = ""; SqlCommand sqlCmdUpdateWeight = new SqlCommand(); sqlConnect.Open(); try { SqlDataReader dataReader = cmdUpdateWeight.ExecuteReader(); if (dataReader.HasRows) { while (dataReader.Read()) { dateFromDbs = dataReader.GetDateTime(0).Date.ToString(); } dataReader.Close(); if (dateFromDbs == Date.ToString()) { try { sqlCmdUpdateWeight.CommandText = "UPDATE [tblMeasures] SET Weight=@Weight WHERE UserName= @UserName and Date=@Date"; sqlCmdUpdateWeight.Parameters.AddWithValue("@Username", Username); sqlCmdUpdateWeight.Parameters.AddWithValue("@Weight", ModifWeightIn); sqlCmdUpdateWeight.Parameters.AddWithValue("@Date", Date); sqlCmdUpdateWeight.Connection = sqlConnect; sqlCmdUpdateWeight.ExecuteNonQuery(); sqlConnect.Close(); weightBox.Text = ModifWeightIn; //string con = MyMethodsLib.GetConnectionString(); string height = MyMethodsLib.GetHeightFromDbs(Username, con).ToString(); BMIBox.Text = MyMethodsLib.CalculateBMI(ModifWeightIn, height); MessageBox.Show("Today's Weight Input modified successfully!"); } catch (System.Exception) { MessageBox.Show("Ooops"); } } sqlConnect.Close(); } else { MessageBox.Show("ATTEMPT FAILED. You can only modify today's input."); sqlConnect.Close(); } } catch (System.Exception) { MessageBox.Show("Shit happened"); if (sqlConnect.State == ConnectionState.Open) { sqlConnect.Close(); } } } catch (System.Exception) { MessageBox.Show("SQL Query unsuccessful"); } } } double kgToLoose = MyMethodsLib.KgToLoose(Username, weightBox.Text); kgBox.Text = MyMethodsLib.WeightResultOutput(Username, kgToLoose, weightBox.Text); nameBox.Text = ""; surnameBox.Text = ""; oldPasswBox.Text = ""; newPasswBox.Text = ""; modifLastWeightIn.Text = ""; }