/***********************************************************/ // "Update" click /***********************************************************/ private void btnUpdate_Click(object sender, RoutedEventArgs e) { // Check if start- and endtime hours and minutes has been filled out if (tbStartTimeHour.Text == "" || tbStartTimeMinutes.Text == "" || tbEndTimeHour.Text == "" || tbEndTimeMinutes.Text == "") { MessageBox.Show("Please fill out hours and minutes"); return; } // Get start time var dtStart = DateTime.Parse(dpStartTimeDate.SelectedDate.Value.ToString("dd-MM-yyyy")); TimeSpan ts = new TimeSpan(int.Parse(tbStartTimeHour.Text), int.Parse(tbStartTimeMinutes.Text), 0); dtStart += ts; // Get end time var dtEnd = DateTime.Parse(dpEndTimeDate.SelectedDate.Value.ToString("dd-MM-yyyy")); ts = new TimeSpan(int.Parse(tbEndTimeHour.Text), int.Parse(tbEndTimeMinutes.Text), 0); dtEnd += ts; // Check if end time is before start time if (dtEnd < dtStart) { MessageBox.Show("End time is before start time"); return; } ObservableCollection <TimeRegistration> list = (ObservableCollection <TimeRegistration>)dgTimeRegistrations.ItemsSource; TimeRegistration tr = null; // If no row is selected select first object if (dgTimeRegistrations.SelectedIndex == -1) { tr = list[0]; } else { tr = list[dgTimeRegistrations.SelectedIndex]; } // Update time registration var wsObj = WebserviceCalls.UpdateTimeRegistration(tr.TimeRegId, dtStart.ToString("yyyy-MM-dd'T'HH:mm:ss"), dtEnd.ToString("yyyy-MM-dd'T'HH:mm:ss")); if (wsObj.Success) { GetTimeRegistrations(); } else { MessageBox.Show(wsObj.Response.ToString()); } }