/// <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> /// Show data which that we select in textboxes for updates /// </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 gridruns_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (this.gridruns.SelectedIndex >= 0) { if (this.gridruns.SelectedItems.Count >= 0) { if (this.gridruns.SelectedItems[0].GetType() == typeof(statisticRuns)) { statisticRuns x = (statisticRuns)this.gridruns.SelectedItems[0]; this.distTextboxUpadte.Text = x.distance.ToString();; this.timeTextboxUpdate.Text = x.time.ToString(); this.DateUpdate.SelectedDate = x.date; this.updatingRunID = x.Id; } } } }
/// <summary> /// Deletes selected data from 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 deleteButton_Click(object sender, RoutedEventArgs e) { var mw = Application.Current.Windows.Cast <Window>().FirstOrDefault(win => win is MainWindow) as MainWindow; var x = from d in db.statisticRuns where d.Id == this.updatingRunID select d; statisticRuns obj = x.SingleOrDefault(); if (obj != null) { db.statisticRuns.Remove(obj); db.SaveChanges(); } var stats = from d in db.statisticRuns where d.userID == mw.currentuserID select d; this.gridruns.ItemsSource = stats.ToList(); }
/// <summary> /// Updates selected items and stores 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 updateButton_Click(object sender, RoutedEventArgs e) { var mw = Application.Current.Windows.Cast <Window>().FirstOrDefault(win => win is MainWindow) as MainWindow; var x = from d in db.statisticRuns where d.Id == this.updatingRunID select d; statisticRuns obj = x.SingleOrDefault(); if (obj != null) { obj.distance = int.Parse(distTextboxUpadte.Text); obj.time = TimeSpan.ParseExact(timeTextboxUpdate.Text, "hh\\:mm\\:ss", null); obj.date = DateUpdate.SelectedDate; db.SaveChanges(); } var stats = from d in db.statisticRuns where d.userID == mw.currentuserID select d; this.gridruns.ItemsSource = stats.ToList(); }