private void ChambresDataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e) { try { if (this.ChambresDataGrid.SelectedItem == null) { return; } ChambresSet chambre = (ChambresSet)ChambresDataGrid.SelectedItem; if (chambre == null) { return; } ChargementComboHotels(this.CbHotels_TabChambres); this.BtAjouterChambre.IsEnabled = true; this.BtSupprimerChambre.IsEnabled = true; this.LbIdChambre.Content = chambre.Id.ToString(); this.TbNomChambre.Text = chambre.Nom; this.TbNbLits.Text = chambre.NbLits.ToString(); this.RdHasClimO.IsChecked = chambre.Climatisation; this.CbHotels_TabChambres.SelectedItem = chambre.keyHotel; ActiverDesactiverControlesChambres(true); } catch (Exception ex) { throw new Exception(ex.Message); } }
public bool ValiderChambre(int idChambre, string nom, bool climatisation, int nbLits, int keyHotel) { try { ChambresSet chambre; if (idChambre != 0) //si id!=0 alors l'hotel existe déjà { chambre = GetChambre(idChambre); } else { chambre = new ChambresSet(); } chambre.Nom = nom; chambre.Climatisation = climatisation; chambre.NbLits = nbLits; chambre.KeyHotel = keyHotel; if (idChambre == 0) //nouvel hotel { this.ChambresSet.Add(chambre); } this.SaveChanges(); return(true); } catch (Exception ex) { throw; } }
private void BtValiderChambre_Click(object sender, RoutedEventArgs e) { try { if (CbHotels_TabChambres.SelectedValue == null) { MessageBox.Show("Veuillez choisir un hotel"); return; } using (var db = new ModelBooking()) { bool isNewChambre; ChambresSet chambre; if ((string)this.LbIdChambre.Content != "" && this.LbIdChambre.Content != null) { isNewChambre = false; int idChambre = Convert.ToInt32(this.LbIdChambre.Content); var resultQuery = (from chambres in db.ChambresSet where chambres.Id == idChambre select chambres); if (resultQuery.Any()) { chambre = resultQuery.First(); } else { return; } } else { isNewChambre = true; chambre = new ChambresSet(); } chambre.Nom = this.TbNomChambre.Text; chambre.Climatisation = (bool)this.RdHasClimO.IsChecked; chambre.NbLits = Convert.ToInt32(this.TbNbLits.Text); chambre.keyHotel = Convert.ToInt32(this.CbHotels_TabChambres.SelectedValue); if (isNewChambre) { db.ChambresSet.Add(chambre); } db.SaveChanges(); } MessageBox.Show("Enregistré !"); LoadChambres(); ActiverDesactiverControlesChambres(false); } catch (Exception ex) { throw; } }
public bool SupprimerChambre(ChambresSet chambre) { try { var resultQuery = (from chambres in this.ChambresSet where chambres.Id == chambre.Id select chambres); if (resultQuery.Any()) { this.ChambresSet.Remove(resultQuery.First()); this.SaveChanges(); return(true); } return(false); } catch (Exception ex) { throw; } }