public MainWindow() { try { loggingFile = new FileInfo("logs.txt"); InitializeComponent(); this.DataContext = this; sessions = new ObservableCollection <Session>(); databaseConnection = DatabaseConnect(); //TIMER setting mainTicker = new DispatcherTimer(); mainTicker.Interval = new TimeSpan(0, 0, 0, 0, 42); mainTicker.Tick += TimerClock_Tick; mainTicker.Start(); // //CLOCK setting timerClock = new TimerClock(); // //BINDINGS bindingSessionDataGrid = new Binding(); bindingSessionDataGrid.Source = sessions; MainDataGrid.SetBinding(DataGrid.ItemsSourceProperty, bindingSessionDataGrid); // //Load sessions to Collection using (var communicator = new DatabaseCommunicator(DatabaseConnect())) { try { foreach (Session sessionToAdd in communicator.LoadSessions()) { sessions.Add(sessionToAdd); } } catch (Exception ex) { ExceptionLogger.LogException(loggingFile, true, ex); } } } catch (Exception ex) { ExceptionLogger.LogException(loggingFile, true, ex); return; } }
private void AddButton_Click(object sender, RoutedEventArgs e) { var toAdd = new Session( (Session.Subject)Enum.Parse(typeof(Session.Subject), Subject_TextBox.Text), float.Parse(Duration_TextBox.Text), DateTime.Now.Date ); using (DatabaseCommunicator databaseCommunicator = new DatabaseCommunicator(DatabaseConnect())) { try { if (databaseCommunicator.AddSession(toAdd)) { sessions.Add(toAdd); } } catch (Exception ex) { MessageBox.Show("An error has occured" + ex.ToString()); } } }