private void Update_DoubleClick(object sender, MouseButtonEventArgs e) { if (lstView.SelectedItems.Count != 1) { MessageBox.Show("Please choose one item to update", "Information"); return; } try { int index = lstView.SelectedIndex; AddEditFlightDialog addEditDialog = new AddEditFlightDialog((Flight)lstView.SelectedItem); addEditDialog.Owner = this; addEditDialog.AddNewFlightCallback += (c) => { currFlight = c; }; bool?result = addEditDialog.ShowDialog(); // this line must be stay after the assignment, otherwise value is not assigned if (result == true) { db.UpdateFlight(currFlight); flightList.ElementAt(index).Id = currFlight.Id; flightList.ElementAt(index).OnDay = currFlight.OnDay; flightList.ElementAt(index).FromCode = currFlight.FromCode; flightList.ElementAt(index).ToCode = currFlight.ToCode; flightList.ElementAt(index).Type = currFlight.Type; flightList.ElementAt(index).Passengers = currFlight.Passengers; lstView.Items.Refresh(); } } catch (DataInvalidException ex) { MessageBox.Show(ex.Message, "Error Information"); } }
private void CommandBinding_AddNewFlight(object sender, ExecutedRoutedEventArgs e) { try { AddEditFlightDialog addEditDialog = new AddEditFlightDialog(null); addEditDialog.Owner = this; addEditDialog.AddNewFlightCallback += (t) => { currFlight = t; }; bool?result = addEditDialog.ShowDialog(); if (result == true) { int newId = db.AddFlight(currFlight); currFlight.Id = newId; flightList.Add(currFlight); lstView.Items.Refresh(); } } catch (DataInvalidException ex) { MessageBox.Show(ex.Message, "Error Information"); } }