Ejemplo n.º 1
0
        /// <summary>
        /// TDEE contruktor which makes connection with database
        /// </summary>
        public tdee()
        {
            InitializeComponent();
            databaseEntities db = new databaseEntities();

            var query = (from x in db.MEASURES
                         where x.Id == 1
                         select x).FirstOrDefault();

            if (query != null)
            {
                weight.Text = query.weight.ToString();
                age.Text    = query.age.ToString();
                height.Text = query.height.ToString();
                activityfactor.SelectedIndex = (int)query.activity;
                weightChange.SelectedIndex   = (int)query.weightchange;
            }

            var query_2 = (from x in db.macrosandtdee
                           where x.Id == 1
                           select x).FirstOrDefault();

            tdee1.Text   = query_2.wtdee.ToString();
            deficyt.Text = query_2.deficyt.ToString();
            needeat.Text = query_2.needeat.ToString();
            protein.Text = query_2.protein.ToString();
            fat.Text     = query_2.fat.ToString();
            carbs.Text   = query_2.carbs.ToString();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Registers new user, stores user login and password in database
        /// </summary>
        /// <param name="sender">The object which invoked the method/event/delegate</param>
        /// <param name="e">State information and event data associated with a routed event.</param>
        private void registeruser_Click(object sender, RoutedEventArgs e)
        {
            databaseEntities db = new databaseEntities();

            var usernameexists = from d in db.users
                                 where d.login == username.Text
                                 select d.login;

            if (username.Text.Length == 0)
            {
                Xceed.Wpf.Toolkit.MessageBox.Show("Enter a login");
                username.Focus();
            }
            else if (pass.Password.Length == 0)
            {
                Xceed.Wpf.Toolkit.MessageBox.Show("Enter a password");
                pass.Focus();
            }
            else if (confirmpass.Password.Length == 0)
            {
                Xceed.Wpf.Toolkit.MessageBox.Show("Enter a password");
                confirmpass.Focus();
            }
            else if (pass.Password != confirmpass.Password)
            {
                Xceed.Wpf.Toolkit.MessageBox.Show("Passwords are not the same");
                pass.Focus();
            }
            else if (usernameexists != null)
            {
                Xceed.Wpf.Toolkit.MessageBox.Show("Username is already taken");
                username.Focus();
            }
            else
            {
                users newuser = new users()
                {
                    login    = username.Text,
                    password = pass.Password
                };

                db.users.Add(newuser);
                db.SaveChanges();
                Xceed.Wpf.Toolkit.MessageBox.Show("Registration completed");
                var mw = Application.Current.Windows.Cast <Window>().FirstOrDefault(win => win is MainWindow) as MainWindow;
                mw.Main.Content = new login();
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Chechs if the username and password are corrent and if they are user is logged in
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The e.</param>
        private void loginbutton_Click(object sender, RoutedEventArgs e)
        {
            databaseEntities db = new databaseEntities();

            var myUser = db.users.FirstOrDefault(u => u.login == usernametextbox.Text && u.password == passwordtextbox.Password);

            if (myUser != null)
            {
                Xceed.Wpf.Toolkit.MessageBox.Show("You are logged in");
                var mw = Application.Current.Windows.Cast <Window>().FirstOrDefault(win => win is MainWindow) as MainWindow;
                mw.isLoggedIn    = true;
                mw.currentuserID = myUser.Id;
            }
            else
            {
                Xceed.Wpf.Toolkit.MessageBox.Show("Invalid password or username");
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Calculates the your daily caloric intake, the number of calories which you need to lower/increase to lose/gain weight and how much calories, carbs, fats, proteins you need to eat therefore,
        /// </summary>
        /// <param name="sender">The object which invoked the method/event/delegate</param>
        /// <param name="e">State information and event data associated with a routed event.</param>
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (this.weight.Text == "" || this.age.Text == "" || this.height.Text == "" || this.weightChange.Text == "" || this.activityfactor.Text == "" || this.weightChange.Text == "")
            {
                Xceed.Wpf.Toolkit.MessageBox.Show("Please enter all data");
            }
            else
            {
                this.tdee1.Text = "dsfsdffs";

                int    weight = int.Parse(this.weight.Text);
                int    age    = int.Parse(this.age.Text);
                int    height = int.Parse(this.height.Text);
                double activity;

                switch (activityfactor.SelectedIndex)
                {
                case 0:
                    activity = 1.2;
                    break;

                case 1:
                    activity = 1.375;
                    break;

                case 2:
                    activity = 1.55;
                    break;

                case 3:
                    activity = 1.725;
                    break;

                default:
                    activity = 1.5;
                    break;
                }

                double tdeee = ((9.99 * weight) + (6.25 * height) - (4.92 * age) + 5) * activity;
                this.tdee1.Text = tdeee.ToString();

                double def;

                switch (weightChange.SelectedIndex)
                {
                case 0:
                    def = -1.5;
                    break;

                case 1:
                    def = -1;
                    break;

                case 2:
                    def = -0.5;
                    break;

                case 3:
                    def = 0;
                    break;

                case 4:
                    def = 0.5;
                    break;

                case 5:
                    def = 1;
                    break;

                case 6:
                    def = 1.5;
                    break;

                default:
                    def = 0;
                    break;
                }

                this.deficyt.Text = (def * 1100).ToString();

                this.needeat.Text = (tdeee + def * 1100).ToString();

                this.protein.Text = ((tdeee + def * 0.2) / 4).ToString("F0");
                this.fat.Text     = ((tdeee + def * 0.25) / 9).ToString("F0");
                this.carbs.Text   = ((tdeee + def * 0.55) / 4).ToString("F0");

                databaseEntities db = new databaseEntities();

                var query = (from x in db.MEASURES
                             where x.Id == 1
                             select x);

                MEASURES obj = query.SingleOrDefault();
                obj.weight       = int.Parse(this.weight.Text);
                obj.age          = int.Parse(this.age.Text);
                obj.height       = int.Parse(this.height.Text);
                obj.activity     = activityfactor.SelectedIndex;
                obj.weightchange = weightChange.SelectedIndex;

                var query_2 = (from x in db.macrosandtdee
                               where x.Id == 1
                               select x);

                macrosandtdee o = query_2.SingleOrDefault();
                o.wtdee   = (int)tdeee;
                o.deficyt = (int)(def * 1100);
                o.needeat = (int)(tdeee + def * 1100);
                o.protein = (int)((tdeee + def * 0.2) / 4);
                o.fat     = (int)((tdeee + def * 0.25) / 9);
                o.carbs   = (int)((tdeee + def * 0.55) / 4);

                db.SaveChanges();
            }
        }