public void BMIBox_TextChanged(object sender, EventArgs e) { string con = MyMethodsLib.GetConnectionString(); string height = MyMethodsLib.GetHeightFromDbs(Username, con).ToString(); this.BMIBox.Text = MyMethodsLib.CalculateBMI(this.weightBox.Text.ToString(), height); this.WeightResultBox.Text = "Press"; double.TryParse(this.BMIBox.Text, out double valToCompare); if (valToCompare < 24.9) { dietModeBox.Text = "Not set"; string dietModeBoxToBeSet = MyMethodsLib.SetDietModeDbs(Username, dietModeBox.Text, con); dietModeBox.Text = dietModeBoxToBeSet; intakeBox.Text = "0"; } }
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 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 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 = ""; }