private void PopulateApartmentComboBox() { ApartmentsLogic al = new ApartmentsLogic(); cbxApartment.ItemsSource = al.GetApartments(); cbxApartment.DisplayMemberPath = "ApartmentName"; cbxApartment.SelectedValuePath = "ApartmentId"; cbxApartment.SelectedValue = 1; }
private void btnDelete_Click(object sender, RoutedEventArgs e) { try { var selectedApartment = dgApartments.SelectedItem != null ? dgApartments.SelectedItem as Model.Apartment : null; if (selectedApartment != null) { if (MessageBox.Show("ยืนยันที่จะลบข้อมูลอพาร์ตเมนต์ " + selectedApartment.ApartmentName, "ยืนยันการลบข้อมูล", MessageBoxButton.OKCancel, MessageBoxImage.Warning) == MessageBoxResult.OK) { ApartmentsLogic al = new ApartmentsLogic(); al.DaleteApartment(selectedApartment); dgApartments.ItemsSource = new ApartmentsLogic().GetApartments(); } } else { MessageBox.Show("กรุณาเลือกข้อมูลที่จะลบ", "เกิดข้อผิดพลาด", MessageBoxButton.OK, MessageBoxImage.Error); } } catch (Exception ex) { MessageBox.Show(ex.Message, "เกิดข้อผิดพลาด", MessageBoxButton.OK, MessageBoxImage.Error); } }