Beispiel #1
0
        private void ClickToLoadWeight(object sender, EventArgs e)
        {
            string weight = _mainPageWeightText.Text;

            if (Weights.IsWeightInputCorrect(weight))
            {
                try
                {
                    var             dateTimeToday = DateTime.Today.ToString("yyyy-MM-dd");
                    MySqlConnection conW          = DietTracker.DatabaseConnect.OpenDefaultDBConnection();

                    MySqlCommand updateCaloriesCommand = new MySqlCommand();
                    updateCaloriesCommand.CommandText = "UPDATE day SET Weight = '" + weight + "' WHERE UserID = '" + Username + "' AND Date = '" + dateTimeToday + "';";
                    updateCaloriesCommand.Connection  = conW;

                    conW.Open();
                    updateCaloriesCommand.ExecuteNonQuery();
                    conW.Close();

                    MessageBox.Show("Updated weight succesfully");

                    MainPageGraphs.MainPageForm mainPage = new MainPageGraphs.MainPageForm(Username, CaloriesRead);
                    mainPage.Tag = this;
                    Hide();
                    mainPage.Show(this);
                }
                catch
                {
                    MessageBox.Show("Something went wrong in your weight input, please try again");
                }
            }
        }
Beispiel #2
0
        private void ClickToLoadCalories(object sender, EventArgs e)
        {
            string calories = _mainPageCalorieText.Text;

            if (Calories.IsCaloriesInputCorrect(calories))
            {
                try
                {
                    var             dateTimeToday = DateTime.Today.ToString("yyyy-MM-dd");
                    MySqlConnection conCal        = DietTracker.DatabaseConnect.OpenDefaultDBConnection();
                    MySqlConnection conCCal       = DietTracker.DatabaseConnect.OpenDefaultDBConnection();

                    MySqlCommand whatIsCurrentCalorieCommand = new MySqlCommand();
                    whatIsCurrentCalorieCommand.CommandText = "SELECT Calories FROM day WHERE UserID = '" + Username + "' AND Date = '" + dateTimeToday + "';";
                    whatIsCurrentCalorieCommand.Connection  = conCCal;

                    conCCal.Open();
                    MySqlDataReader readCalories = whatIsCurrentCalorieCommand.ExecuteReader();
                    readCalories.Read();
                    int caloriesRead = readCalories.GetInt32(0);
                    conCCal.Close();

                    int caloriesVal = Int32.Parse(calories);
                    caloriesRead += caloriesVal;

                    MySqlCommand updateCaloriesCommand = new MySqlCommand();
                    updateCaloriesCommand.CommandText = "UPDATE day SET Calories = '" + caloriesRead + "' WHERE UserID = '" + Username + "' AND Date = '" + dateTimeToday + "';";
                    updateCaloriesCommand.Connection  = conCal;
                    conCal.Open();
                    updateCaloriesCommand.ExecuteNonQuery();
                    conCal.Close();

                    MessageBox.Show("Updated calories succesfully to: " + caloriesRead);
                    MainPageGraphs.MainPageForm mainPage = new MainPageGraphs.MainPageForm(Username, caloriesRead);
                    mainPage.Tag = this;
                    Hide();
                    mainPage.Show(this);
                }
                catch
                {
                    MessageBox.Show("Something with your input in calories was wrong, please try again");
                }
            }
        }
Beispiel #3
0
        private void MainPageBack_Click(object sender, EventArgs e)
        {
            MySqlConnection conCal = DietTracker.DatabaseConnect.OpenDefaultDBConnection();

            var          dateTimeToday = DateTime.Today.ToString("yyyy-MM-dd");
            MySqlCommand WhatIsCurrentCalorieCommand = new MySqlCommand();

            WhatIsCurrentCalorieCommand.CommandText = "SELECT Calories FROM day WHERE UserID = '" + _username + "' AND Date = '" + dateTimeToday + "';";
            WhatIsCurrentCalorieCommand.Connection  = conCal;
            conCal.Open();
            MySqlDataReader ReadCalories = WhatIsCurrentCalorieCommand.ExecuteReader();

            ReadCalories.Read();
            int CaloriesRead = ReadCalories.GetInt32(0);

            conCal.Close();

            MainPageGraphs.MainPageForm mainPageForm = new MainPageGraphs.MainPageForm(_username, CaloriesRead);
            mainPageForm.Tag = this;
            Hide();
            mainPageForm.Show(this);
        }
Beispiel #4
0
        private void UpdateButton_Click(object sender, EventArgs e)
        {
            DateTime doB;
            var      a        = 0;
            User     Orguser  = User.GetUser(_username);
            User     Tempuser = Orguser.DoUserChange();

            Tempuser.password = Orguser.password;
            Tempuser.name     = Orguser.name;
            doB               = Convert.ToDateTime(Orguser.doB);
            Tempuser.doB      = doB.ToString("yyyy-MM-dd");
            Tempuser.doB      = Tempuser.doB.Substring(0, 10);
            Tempuser.height   = Orguser.height;
            Tempuser.weight   = Orguser.weight;
            Tempuser.activity = Orguser.activity;



            if (UpdatePagePassword.Text != "")
            {
                Tempuser.password = UpdatePagePassword.Text;
                a++;
            }
            if (UpdatePageName.Text != "")
            {
                Tempuser.name = UpdatePageName.Text;
                a++;
            }
            if (UpdatePageDoB.Value.ToShortDateString() != "10-05-2018")
            {
                Tempuser.doB = UpdatePageDoB.Value.ToString("yyyy-MM-dd");
                if (Tempuser.doB == "2018-05-10")
                {
                    Tempuser.doB = Orguser.doB;
                }
                a++;
            }
            if (UpdatePageHeight.Text != "")
            {
                Tempuser.height = Convert.ToInt32(UpdatePageHeight.Text);
                a++;
            }
            if (UpdatePageWeight.Text != "")
            {
                Tempuser.weight = Convert.ToDouble(UpdatePageWeight.Text, CultureInfo.InvariantCulture);
                a++;
            }
            if (UpdatePageActivity.Value != 0)
            {
                Tempuser.activity = Convert.ToInt32(UpdatePageActivity.Value);
                a++;
            }

            if (Tempuser != Orguser)
            {
                try
                {
                    if (!string.IsNullOrEmpty(Tempuser.password) && Tempuser.password != Orguser.password &&
                        Tempuser.IsUpdateInfoCorrect(Tempuser.user, Tempuser.name, Tempuser.doB,
                                                     Convert.ToInt32(Tempuser.height), Convert.ToDouble(Tempuser.weight), Tempuser.activity, Tempuser, Orguser) != false)
                    {
                        MySqlConnection conUU = DatabaseConnect.OpenDefaultDBConnection();
                        MySqlConnection conUP = DatabaseConnect.OpenDefaultDBConnection();

                        MySqlCommand UpdateUserCommand = new MySqlCommand();
                        MySqlCommand UpdatePwdCommand  = new MySqlCommand();
                        UpdateUserCommand.CommandText = "UPDATE diettracker.users SET Name = '" + Tempuser.name +
                                                        "', DoB = '" + Tempuser.doB + "', Height = '" + Tempuser.height + "', Weight = '" + Tempuser.weight +
                                                        "', Activity = '" + Tempuser.activity + "' WHERE Username = '******';";
                        UpdatePwdCommand.CommandText = "UPDATE diettracker.password SET Password = '******' WHERE ForeignID = '" + Orguser.id + "';";

                        UpdateUserCommand.Connection = conUU;
                        UpdatePwdCommand.Connection  = conUP;
                        conUU.Open();
                        UpdateUserCommand.ExecuteNonQuery();
                        conUU.Close();
                        conUP.Open();
                        UpdatePwdCommand.ExecuteNonQuery();
                        conUP.Close();

                        MySqlConnection conFW = DatabaseConnect.OpenDefaultDBConnection();
                        MySqlCommand    SelectFirstWeightValueCommand = new MySqlCommand();
                        SelectFirstWeightValueCommand.CommandText = "SELECT Date, Weight from day WHERE UserID = '" + _username + "' AND Date <= COALESCE((SELECT Date FROM day ORDER BY Date ASC LIMIT 1),(SELECT MAX(Date) FROM day));";
                        SelectFirstWeightValueCommand.Connection  = conFW;
                        conFW.Open();
                        MySqlDataReader FirstWeightRead = SelectFirstWeightValueCommand.ExecuteReader();
                        FirstWeightRead.Read();
                        string date   = FirstWeightRead.GetDateTime(0).ToString("yyyy-MM-dd");
                        string weight = FirstWeightRead.GetDouble(1).ToString(CultureInfo.InvariantCulture);
                        conFW.Close();

                        MySqlConnection conUFW = DatabaseConnect.OpenDefaultDBConnection();
                        MySqlCommand    UpdateFirstWeightValueCommand = new MySqlCommand();
                        UpdateFirstWeightValueCommand.CommandText = "UPDATE day SET Weight = '" + Tempuser.weight + "' WHERE UserID = '" + _username + "' AND Date = '" + date + "' AND Weight = '" + weight + "';";
                        UpdateFirstWeightValueCommand.Connection  = conUFW;
                        conUFW.Open();
                        UpdateFirstWeightValueCommand.ExecuteNonQuery();
                        conUFW.Close();


                        MySqlConnection conCal = DietTracker.DatabaseConnect.OpenDefaultDBConnection();

                        var          dateTimeToday = DateTime.Today.ToString("yyyy-MM-dd");
                        MySqlCommand WhatIsCurrentCalorieCommand = new MySqlCommand();
                        WhatIsCurrentCalorieCommand.CommandText = "SELECT Calories FROM day WHERE UserID = '" + _username + "' AND Date = '" + dateTimeToday + "';";
                        WhatIsCurrentCalorieCommand.Connection  = conCal;
                        conCal.Open();
                        MySqlDataReader ReadCalories = WhatIsCurrentCalorieCommand.ExecuteReader();
                        ReadCalories.Read();
                        int CaloriesRead = ReadCalories.GetInt32(0);
                        conCal.Close();

                        MainPageGraphs.MainPageForm mainPage = new MainPageGraphs.MainPageForm(_username, CaloriesRead);
                        mainPage.Tag = this;
                        Hide();
                        mainPage.Show(this);
                    }
                    else if (Tempuser.IsUpdateInfoCorrect(Tempuser.user, Tempuser.name, Tempuser.doB,
                                                          Convert.ToInt32(Tempuser.height), Convert.ToDouble(Tempuser.weight), Tempuser.activity, Tempuser, Orguser) != false)
                    {
                        MySqlConnection ConU          = DatabaseConnect.OpenDefaultDBConnection();
                        MySqlCommand    UpdateCommand = new MySqlCommand();
                        UpdateCommand.CommandText = "UPDATE diettracker.users SET Name = '" + Tempuser.name +
                                                    "', DoB = '" + Tempuser.doB + "', Height = '" + Tempuser.height + "', Weight = '" + Tempuser.weight.ToString(CultureInfo.InvariantCulture) +
                                                    "', Activity = '" + Tempuser.activity + "' WHERE Username = '******';";
                        UpdateCommand.Connection = ConU;
                        ConU.Open();
                        UpdateCommand.ExecuteNonQuery();
                        ConU.Close();

                        MySqlConnection conCal = DietTracker.DatabaseConnect.OpenDefaultDBConnection();

                        var          dateTimeToday = DateTime.Today.ToString("yyyy-MM-dd");
                        MySqlCommand WhatIsCurrentCalorieCommand = new MySqlCommand();
                        WhatIsCurrentCalorieCommand.CommandText = "SELECT Calories FROM day WHERE UserID = '" + _username + "' AND Date = '" + dateTimeToday + "';";
                        WhatIsCurrentCalorieCommand.Connection  = conCal;
                        conCal.Open();
                        MySqlDataReader ReadCalories = WhatIsCurrentCalorieCommand.ExecuteReader();
                        ReadCalories.Read();
                        int CaloriesRead = ReadCalories.GetInt32(0);
                        conCal.Close();

                        MySqlConnection conFW = DatabaseConnect.OpenDefaultDBConnection();
                        MySqlCommand    SelectFirstWeightValueCommand = new MySqlCommand();
                        SelectFirstWeightValueCommand.CommandText = "SELECT Date, Weight from day WHERE UserID = '" + _username + "' AND Date >= COALESCE((SELECT Date FROM day ORDER BY Date ASC LIMIT 1),(SELECT MAX(Date) FROM day));";
                        SelectFirstWeightValueCommand.Connection  = conFW;
                        conFW.Open();
                        MySqlDataReader FirstWeightRead = SelectFirstWeightValueCommand.ExecuteReader();
                        FirstWeightRead.Read();
                        string date   = FirstWeightRead.GetDateTime(0).ToString("yyyy-MM-dd");
                        string weight = FirstWeightRead.GetDouble(1).ToString(CultureInfo.InvariantCulture);

                        conFW.Close();

                        MySqlConnection conUFW = DatabaseConnect.OpenDefaultDBConnection();
                        MySqlCommand    UpdateFirstWeightValueCommand = new MySqlCommand();
                        UpdateFirstWeightValueCommand.CommandText = "UPDATE day SET Weight = '" + Tempuser.weight.ToString(CultureInfo.InvariantCulture) + "' WHERE UserID = '" + _username + "' AND Date = '" + date + "' AND Weight = '" + weight + "';";
                        UpdateFirstWeightValueCommand.Connection  = conUFW;
                        conUFW.Open();
                        UpdateFirstWeightValueCommand.ExecuteNonQuery();
                        conUFW.Close();

                        MainPageGraphs.MainPageForm mainPage = new MainPageGraphs.MainPageForm(_username, CaloriesRead);
                        mainPage.Tag = this;
                        Hide();
                        mainPage.Show(this);
                    }
                }
                catch
                {
                    MessageBox.Show("Something went wrong");
                }
            }
        }