Esempio n. 1
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);
        }
Esempio n. 2
0
        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";
            }
        }
Esempio n. 3
0
        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 = "";
        }