/// <summary> /// Adding our run stats to 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> public void AddButton_Click(object sender, RoutedEventArgs e) { var mw = Application.Current.Windows.Cast <Window>().FirstOrDefault(win => win is MainWindow) as MainWindow; if (this.distTextbox.Text == "" || this.timeTextBox.Text == "") { Xceed.Wpf.Toolkit.MessageBox.Show("Please enter all data"); } else { statisticRuns newRecord = new statisticRuns() { distance = int.Parse(distTextbox.Text), time = TimeSpan.ParseExact(timeTextBox.Text, "hh\\:mm\\:ss", null), date = Calendar.SelectedDate, userID = mw.currentuserID }; db.statisticRuns.Add(newRecord); db.SaveChanges(); var stats = from d in db.statisticRuns where d.userID == mw.currentuserID select d; this.gridruns.ItemsSource = stats.ToList(); } }
/// <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(); } }
/// <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(); } }