private void btnUpdate_Click(object sender, EventArgs e) { if (dtpDate.Value.Date < DateTime.Now.Date) { MessageBox.Show("Date of new flight can only after today", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (dtpDate.Value.Date == DateTime.Now.Date && dtpTime.Value.TimeOfDay <= DateTime.Now.TimeOfDay) { MessageBox.Show("Time of flight can only after now", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (Flight.Schedule.Date != dtpDate.Value.Date) { if (Db.Context.Schedules.Where(t => t.Date == dtpDate.Value.Date && t.FlightNumber == Flight.Schedule.FlightNumber).FirstOrDefault() != null) { MessageBox.Show($"Duplicate schedule with date {dtpDate.Value.ToString("dd/MM/yyyy")} and flight number {Flight.Schedule.FlightNumber}", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } Flight.Schedule.Date = dtpDate.Value.Date; Flight.Schedule.Time = dtpTime.Value.TimeOfDay; Flight.Schedule.EconomyPrice = (int)nudPrice.Value; Db.Context.SaveChanges(); ManageWindow.LoadFlights(); MessageBox.Show("Edit flight Successful", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); }
private void btnSave_Click(object sender, RoutedEventArgs e) { Flight.Schedule.Crew = crews[cbCrews.SelectedIndex]; Db.Context.SaveChanges(); ManageWindow.LoadFlights(); MessageBox.Show("Set up crew successful!", "Message", MessageBoxButton.OK, MessageBoxImage.Information); this.Close(); }