예제 #1
0
 public void CheckBtn_Click(object sender, EventArgs e)
 {
     using (SqlConnection connection = new SqlConnection(MyMethodsLib.GetConnectionString()))
     {
         connection.Open();
         SqlCommand cmd = new SqlCommand
         {
             CommandText = "select * from [tblUserNamePassw] where Username=@Username"
         };
         cmd.Parameters.AddWithValue("@Username", Username.Text.Trim());
         cmd.Connection = connection;
         SqlDataReader dataReader = cmd.ExecuteReader();
         if (!dataReader.HasRows)
         {
             checkInfo.Visible   = true;
             checkInfo.Text      = "Username available";
             checkInfo.ForeColor = System.Drawing.Color.Green;
             dataReader.Close();
         }
         else
         {
             checkInfo.Visible   = true;
             checkInfo.Text      = "Username taken";
             checkInfo.ForeColor = System.Drawing.Color.Red;
         }
     }
 }
예제 #2
0
        public static bool CallLogisticRegression(string weight, string Username, string _trainDataPath)
        {
            bool      dietResult = false;
            MLContext mlContext  = new MLContext(seed: 0);
            var       model      = BinaryClassML.Train(mlContext, _trainDataPath);

            BinaryClassML.Evaluate(mlContext, model);
            // string weight = weightBox.Text;
            string con    = MyMethodsLib.GetConnectionString();
            string height = GetHeightFromDbs(Username, con).ToString();
            string bmi    = CalculateBMI(weight, height);

            dietResult = BinaryClassML.Predict(mlContext, model, bmi);
            return(dietResult);
        }
예제 #3
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";
            }
        }
예제 #4
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);
        }
예제 #5
0
        public void Button1_Click_2(object sender, EventArgs e)
        {
            //it must be taken from dbs the dates and weights in order to output
            this.progressChart.Series["Weight"].Points.Clear();
            string con          = MyMethodsLib.GetConnectionString();
            var    dates        = MyMethodsLib.GetDatesOfInputWeight(Username, con);
            var    weightInputs = MyMethodsLib.GetWeightInputs(Username, con);
            int    track        = 0;

            foreach (String date in dates)
            {
                this.progressChart.Series["Weight"].Points.AddXY(date, weightInputs[track]);
                track += 1;
            }
            this.progressChart.ChartAreas["ChartArea1"].AxisX.Title = "Date";
            this.progressChart.ChartAreas["ChartArea1"].AxisY.Title = "Your Weight";
        }
예제 #6
0
 public void SignIn_Click(object sender, EventArgs e)
 {
     using (
         SqlConnection connection = new SqlConnection(MyMethodsLib.GetConnectionString()))
     {
         connection.Open();
         SqlCommand cmd = new SqlCommand();
         cmd.CommandText = "select * from [tblUserNamePassw] where Username=@Username and Password=@Password";
         cmd.Parameters.AddWithValue("@Username", UsernameLogin.Text.Trim());
         cmd.Parameters.AddWithValue("@Password", PasswLogin.Text.Trim());
         cmd.Connection = connection;
         SqlDataReader dataReader = cmd.ExecuteReader();
         if (!dataReader.HasRows)
         {
             MessageBox.Show("Username does not exist or password is incorrect.");
             Clear();
         }
         else
         {
             SetUsername       = UsernameLogin.Text;
             this.DialogResult = DialogResult.OK;
         }
     }
 }
예제 #7
0
        public void SignUpButton_Click(object sender, EventArgs e)
        {
            if (Username.Text == "" || Password.Text == "" || passwConf.Text == "" || Height2.Text == "" || Weight.Text == "")
            {
                MessageBox.Show("Please fill mandatory fields");
            }
            else if (Password.Text != passwConf.Text)
            {
                MessageBox.Show("Passwords are not identical");
            }
            else
            {
                using (SqlConnection sqlConnect = new SqlConnection(MyMethodsLib.GetConnectionString()))
                {
                    sqlConnect.Open();
                    SqlCommand sqlCmdAddUserNamePasswGennderIfVeggie = new SqlCommand("UserAdd", sqlConnect);
                    SqlCommand sqlCmdAddMeasures  = new SqlCommand("MeasureAdd", sqlConnect);
                    SqlCommand sqlCmdAddOtherInfo = new SqlCommand("OtherInfoAdd", sqlConnect);

                    sqlCmdAddMeasures.CommandType = CommandType.StoredProcedure;
                    sqlCmdAddUserNamePasswGennderIfVeggie.CommandType = CommandType.StoredProcedure;
                    sqlCmdAddOtherInfo.CommandType = CommandType.StoredProcedure;


                    SqlCommand cmdAddUser = new SqlCommand
                    {
                        CommandText = "select * from [tblUserNamePassw] where Username=@Username"
                    };
                    cmdAddUser.Parameters.AddWithValue("@Username", Username.Text.Trim());
                    cmdAddUser.Connection = sqlConnect;
                    SqlDataReader dataReader = cmdAddUser.ExecuteReader();
                    if (dataReader.HasRows)
                    {
                        MessageBox.Show("Username is already taken, try different one.");
                    }
                    else
                    {
                        int countUsernameLetters = Username.Text.Trim().Count();
                        if (countUsernameLetters > 2)
                        {
                            sqlCmdAddUserNamePasswGennderIfVeggie.Parameters.AddWithValue("@Username", Username.Text.Trim());
                        }
                        else
                        {
                            MessageBox.Show("Username is too short.");
                        }
                    }
                    dataReader.Close();
                    int countPasswChars = Password.Text.Trim().Count();
                    if (countPasswChars > 6)
                    {
                        sqlCmdAddUserNamePasswGennderIfVeggie.Parameters.AddWithValue("@Password", Password.Text.Trim());
                    }
                    else
                    {
                        MessageBox.Show("Password is too short, should contain at least 7 digits/letters.");
                    }

                    bool isChecked = true;
                    if (radioBtnYes.Checked == isChecked || radioBtnNo.Checked == isChecked)
                    {
                        if (radioBtnYes.Checked == isChecked)
                        {
                            sqlCmdAddUserNamePasswGennderIfVeggie.Parameters.AddWithValue("@Vegetarian", "Yes");
                        }
                        else
                        {
                            sqlCmdAddUserNamePasswGennderIfVeggie.Parameters.AddWithValue("@Vegetarian", "No");
                        }
                    }
                    else
                    {
                        MessageBox.Show("Please, select if you are vegetarian or not.");
                    }


                    if (GenderBox.SelectedItem.ToString() != "")
                    {
                        sqlCmdAddUserNamePasswGennderIfVeggie.Parameters.AddWithValue("@Gender", GenderBox.SelectedItem.ToString());
                    }
                    else
                    {
                        MessageBox.Show("Please, select your gender.");
                    }
                    SqlCommand cmdAddMeasures = new SqlCommand
                    {
                        CommandText = "select Username from [tblMeasures]"
                    };
                    cmdAddMeasures.Parameters.AddWithValue("@Username", Username.Text.Trim());
                    cmdAddMeasures.Connection = sqlConnect;
                    SqlDataReader dataReader2 = cmdAddMeasures.ExecuteReader();
                    int           count       = 0;
                    if (dataReader2.HasRows)
                    {
                        while (dataReader2.Read())
                        {
                            count++;
                        }
                    }
                    sqlCmdAddMeasures.Parameters.AddWithValue("@MeasurementNo", count);
                    sqlCmdAddMeasures.Parameters.AddWithValue("@Username", Username.Text.Trim());
                    bool correctHeightValue = int.TryParse(Height2.Text.Trim(), out int heightNumber);

                    if (correctHeightValue)
                    {
                        if (heightNumber < 50 || heightNumber > 230)
                        {
                            MessageBox.Show("Are you sure you entered your height properly?");
                        }
                        else
                        {
                            sqlCmdAddMeasures.Parameters.AddWithValue("@Height", Convert.ToInt32(Height2.Text.Trim()));
                            //setHeight = heightNumber;
                        }
                    }
                    else
                    {
                        MessageBox.Show("Please put only digits as height in cm");
                    }

                    bool correctWeightValue = decimal.TryParse(Weight.Text.Trim(), out decimal weightNumber);
                    if (correctWeightValue)
                    {
                        if (weightNumber < 30 || weightNumber > 200)
                        {
                            MessageBox.Show("Are you sure you entered your weight correctly?");
                        }
                        else
                        {
                            sqlCmdAddMeasures.Parameters.AddWithValue("@Weight", decimal.Parse(Weight.Text.Trim()));
                        }
                    }
                    else
                    {
                        MessageBox.Show("Please put only digits as weight in kg");
                    }
                    dataReader2.Close();

                    SqlCommand cmdAddEmail = new SqlCommand
                    {
                        CommandText = "select Username from [tblMeasures]"
                    };
                    cmdAddEmail.Parameters.AddWithValue("@Username", Username.Text.Trim());
                    cmdAddEmail.Connection = sqlConnect;
                    SqlDataReader dataReader3 = cmdAddEmail.ExecuteReader();
                    int           countAgain  = 0;
                    if (dataReader3.HasRows)
                    {
                        while (dataReader3.Read())
                        {
                            countAgain++;
                        }
                    }

                    dataReader3.Close();
                    sqlCmdAddOtherInfo.Parameters.AddWithValue("@AddInfoID", countAgain);

                    if (Email.Text.Trim().Contains("@") || Email.Text.Trim().Count() == 0)
                    {
                        sqlCmdAddOtherInfo.Parameters.AddWithValue("@UserName", Username.Text.Trim());
                        sqlCmdAddOtherInfo.Parameters.AddWithValue("@Email", Email.Text.Trim());
                    }
                    else
                    {
                        MessageBox.Show("Given email is invalid");
                    }
                    sqlCmdAddUserNamePasswGennderIfVeggie.ExecuteNonQuery();
                    sqlCmdAddMeasures.ExecuteNonQuery();
                    sqlCmdAddOtherInfo.ExecuteNonQuery();
                    MessageBox.Show("Signing Up succeeded!" + "\n" + "Your login is: " + Username.Text.Trim());
                    //EnterDateAndUserWeightCsv(path);
                    this.DialogResult = DialogResult.OK;
                    Close();
                    Clear();
                }
            }
        }
예제 #8
0
        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";
        }
예제 #9
0
        public void RemoveAccountBtn_Click(object sender, EventArgs e)
        {
            int          MeasurementNo = 0;
            DialogResult d_res         = MessageBox.Show("Are you sure you want to remove your account with all your data?", "Confirm", MessageBoxButtons.YesNo);

            if (d_res == DialogResult.Yes)
            {
                //code for implementing data removal functionality
                using (
                    SqlConnection connection = new SqlConnection(MyMethodsLib.GetConnectionString()))
                {
                    try
                    {
                        // string deleteFromtblMeasures = "DELETE FROM [tblMeasures] WHERE Username=@Username";
                        string deleteFromtblOtherInfo     = "DELETE FROM [tblOtherInfo] WHERE Username=@Username";
                        string deleteFromtblUserNamePassw = "DELETE FROM [tblUserNamePassw] WHERE Username=@Username";

                        SqlCommand sqlCmdSelectMeasurementNo       = new SqlCommand();
                        SqlCommand sqlCmdDeleteFromtblDailyMealSet = new SqlCommand();
                        //SqlCommand sqlCmdDeleteFromtblMeasures = new SqlCommand();
                        SqlCommand sqlCmdDeleteFromtblOtherInfo     = new SqlCommand(deleteFromtblOtherInfo, connection);
                        SqlCommand sqlCmdDeleteFromtblUserNamePassw = new SqlCommand(deleteFromtblUserNamePassw, connection);

                        try
                        {
                            connection.Open();
                            sqlCmdSelectMeasurementNo.CommandType = CommandType.Text;
                            sqlCmdSelectMeasurementNo.CommandText = "select MeasurementNo from [tblMeasures] where Username=@Username";
                            sqlCmdSelectMeasurementNo.Parameters.AddWithValue("@Username", Username);
                            sqlCmdSelectMeasurementNo.Connection = connection;

                            SqlDataReader dataReader = sqlCmdSelectMeasurementNo.ExecuteReader();
                            //connection.Close();
                            if (dataReader.HasRows)
                            {
                                while (dataReader.Read())
                                {
                                    MeasurementNo = dataReader.GetInt32(0);
                                    try
                                    {
                                        sqlCmdDeleteFromtblDailyMealSet.CommandType = CommandType.Text;
                                        sqlCmdDeleteFromtblDailyMealSet.CommandText = "delete from [tblDailyMealSet] WHERE MeasurementNo=@MeasurementNo";
                                        sqlCmdDeleteFromtblDailyMealSet.Parameters.AddWithValue("@MeasurementNo", MeasurementNo);
                                        sqlCmdDeleteFromtblDailyMealSet.Connection = connection;
                                        sqlCmdDeleteFromtblDailyMealSet.ExecuteNonQuery();
                                        connection.Close();
                                    }
                                    catch (System.Exception)
                                    {
                                        MessageBox.Show("Potentially no records in this table");
                                    }
                                }
                            }
                            dataReader.Close();
                            connection.Close();
                        }
                        catch (System.Exception)
                        {
                        }

                        try
                        {
                            connection.Open();
                            SqlCommand sqlCmdDeleteFromtblMeasures = new SqlCommand("tblMeasuresDelete", connection)
                            {
                                CommandType = CommandType.StoredProcedure
                            };
                            //sqlCmdDeleteFromtblMeasures.CommandText = "DELETE FROM [tblMeasures] WHERE Username = @Username";

                            SqlCommand cmdDeleteFromMeasures = new SqlCommand
                            {
                                CommandText = "DELETE FROM [tblMeasures] WHERE Username = @Username"
                            };
                            cmdDeleteFromMeasures.Parameters.AddWithValue("@Username", Username);
                            cmdDeleteFromMeasures.Connection = connection;
                            sqlCmdDeleteFromtblMeasures.Parameters.AddWithValue("@Username", Username);
                            sqlCmdDeleteFromtblMeasures.ExecuteNonQuery();
                            connection.Close();
                        }
                        catch (System.Exception)
                        {
                        }

                        try
                        {
                            connection.Open();
                            SqlCommand sqlCmdDeleteFromtblMeasures = new SqlCommand("tblOtherInfoDelete", connection)
                            {
                                CommandType = CommandType.StoredProcedure
                            };
                            //sqlCmdDeleteFromtblMeasures.CommandText = "DELETE FROM [tblMeasures] WHERE Username = @Username";

                            SqlCommand cmdDeleteFromMeasures = new SqlCommand
                            {
                                CommandText = "DELETE FROM [tblOtherInfo] WHERE Username = @Username"
                            };
                            cmdDeleteFromMeasures.Parameters.AddWithValue("@Username", Username);
                            cmdDeleteFromMeasures.Connection = connection;
                            sqlCmdDeleteFromtblMeasures.Parameters.AddWithValue("@Username", Username);
                            sqlCmdDeleteFromtblMeasures.ExecuteNonQuery();
                            connection.Close();
                        }
                        catch (System.Exception)
                        {
                        }

                        try
                        {
                            connection.Open();
                            SqlCommand sqlCmd = new SqlCommand("tblUserDelete", connection)
                            {
                                CommandType = CommandType.StoredProcedure
                            };
                            SqlCommand cmd = new SqlCommand
                            {
                                CommandText = "DELETE FROM [tblUserNamePassw] WHERE Username = @Username"
                            };
                            cmd.Parameters.AddWithValue("@Username", Username);
                            cmd.Connection = connection;
                            sqlCmd.Parameters.AddWithValue("@Username", Username);
                            sqlCmd.ExecuteNonQuery();
                            connection.Close();
                        }
                        catch (System.Exception)
                        {
                        }
                    }
                    catch (System.Exception)
                    {
                    }
                    MessageBox.Show("Your Account has been successfully deleted!");
                    Close();
                }
            }
            else if (d_res == DialogResult.No)
            {
                // do nothing :)
            }
        }
예제 #10
0
        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!");
            }
        }
예제 #11
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 = "";
        }