コード例 #1
0
        private void EditButton_Click(object sender, RoutedEventArgs e)
        {
            Guest selectedItem = (Guest)guestDataGrid.SelectedItem;

            if (selectedItem != null)
            {
                var newGuest = new EditGuestWindow(selectedItem);

                if (newGuest.ShowDialog() == true)
                {
                    var update = (from guest in MainWindow.db.Guests where guest.ID == selectedItem.ID select guest).Single();
                    update.Name         = newGuest.G_Name;
                    update.Telephone    = newGuest.G_Telephone;
                    update.IdentityCard = newGuest.G_IdentityCard;
                    MainWindow.db.SaveChanges();

                    guestDataGrid.ItemsSource = MainWindow.db.Guests.ToList();
                }
            }
        }
コード例 #2
0
        private void guestDataGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            DataGridRow row = ItemsControl.ContainerFromElement((DataGrid)sender, e.OriginalSource as DependencyObject) as DataGridRow;

            if (row != null)
            {
                Guest selectedItem = (Guest)row.Item;

                var newGuest = new EditGuestWindow(selectedItem);

                if (newGuest.ShowDialog() == true)
                {
                    var update = (from guest in MainWindow.db.Guests where guest.ID == selectedItem.ID select guest).Single();
                    update.Name         = newGuest.G_Name;
                    update.Telephone    = newGuest.G_Telephone;
                    update.IdentityCard = newGuest.G_IdentityCard;
                    MainWindow.db.SaveChanges();

                    guestDataGrid.ItemsSource = MainWindow.db.Guests.ToList();
                }
            }
        }