Exercice VB: Gestion des réservations et des séjours pour Hôtel
Rédigé par GC Team, Publié le 08 Janvier 2012, Mise à jour le Mardi, 30 Novembre 1999 00:00![](/images/thumb/146/default.png)
On désire informatiser la gestion des réservations et des séjours pour l’hôtel Ibis :
Pour les séjours, on enregistre la date d’entrée, le type de séjour (Journalier, Semaine, Weekend) et la durée du séjour. Pour un séjour Semaine, la durée est 7j., pour type Weekend la durée est 3j., et pour le type Journalier la durée est le nombre de jours souhaités par le client.
Le schéma relationnel de la base de données est le suivant :
Client (IdClient, NomClient, AdresseClient, TelClient)
Réservation (CodeReservation, IdClient, Date, PensionComplete)
Sejour (NumSejour, CodeReservation, DateSejour, TypeSejour, DureeSejour)
ReservationAnnulee (CodeReservation, IdClient, DateAnnulation)
Travail à faire :
Réaliser une interface utilisateur conviviale et ergonomique pour l’application de gestion des réservations.
Ecrire un programme pour gérer les réservations annulées tel que :
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 |
Public Class Facturation Inherits System.Windows.Forms.Form Private Sub Facturation_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim etat As New sejour CrystalReportViewer1.ReportSource = etat End Sub End Class ------------------------------------------------------------------------------- Imports System.Data.SqlClient Public Class Gestion_des_clients Inherits System.Windows.Forms.Form Dim pos, i, trouvé As Integer Dim mot_rech, var As String Private Sub Gestion_des_clients_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load cmd = New SqlCommand cmd.Connection = cn cmd.CommandText = "select * from client" da = New SqlDataAdapter(cmd) ds = New DataSet da.Fill(ds, "client") End Sub Private Sub bt_premier_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt_premier.Click pos = 0 txb_id.Text = ds.Tables("client").Rows(0).Item(0) txb_nom.Text = ds.Tables("client").Rows(0).Item(1) txb_adresse.Text = ds.Tables("client").Rows(0).Item(2) txb_tel.Text = ds.Tables("client").Rows(0).Item(3) End Sub Private Sub bt_dernier_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt_dernier.Click pos = ds.Tables("client").Rows.Count - 1 txb_id.Text = ds.Tables("client").Rows(pos).Item(0) txb_nom.Text = ds.Tables("client").Rows(pos).Item(1) txb_adresse.Text = ds.Tables("client").Rows(pos).Item(2) txb_tel.Text = ds.Tables("client").Rows(pos).Item(3) End Sub Private Sub bt_precedent_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt_precedent.Click If pos > 0 Then pos = pos - 1 txb_id.Text = ds.Tables("client").Rows(pos).Item(0) txb_nom.Text = ds.Tables("client").Rows(pos).Item(1) txb_adresse.Text = ds.Tables("client").Rows(pos).Item(2) txb_tel.Text = ds.Tables("client").Rows(pos).Item(3) Else MsgBox("c est le premier enregistrement") End If End Sub Private Sub bt_suivant_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt_suivant.Click If pos < ds.Tables("client").Rows.Count - 1 Then pos = pos + 1 txb_id.Text = ds.Tables("client").Rows(pos).Item(0) txb_nom.Text = ds.Tables("client").Rows(pos).Item(1) txb_adresse.Text = ds.Tables("client").Rows(pos).Item(2) txb_tel.Text = ds.Tables("client").Rows(pos).Item(3) Else MsgBox("c est le dernier enregistrement") End If End Sub Private Sub bt_ajouter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt_ajouter.Click If txb_id.Text = "" Or txb_nom.Text = "" Or txb_adresse.Text = "" Or txb_tel.Text = "" Then MsgBox("vous devez remplir toutes les champs") Else ds.Tables("client").Constraints.Add("pk1", ds.Tables("client").Columns("id_client"), True) row = ds.Tables("client").NewRow row.Item(0) = txb_id.Text row.Item(1) = txb_nom.Text row.Item(2) = txb_adresse.Text row.Item(3) = txb_tel.Text Try ds.Tables("client").Rows.Add(row) odb = New SqlCommandBuilder(da) da.Update(ds, "client") ds.Clear() da.Fill(ds, "client") 'dt = ds.Tables("client") MessageBox.Show("enregistrement effectué...", "Enregistrer", MessageBoxButtons.OK) Catch ex As Exception MsgBox(ex.Message) init() Exit Sub End Try End If End Sub Private Sub bt_supprimer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt_supprimer.Click var = MessageBox.Show("voulez vous supprimer cette enregistrement", "Supprimer", MessageBoxButtons.YesNo) If var = vbYes Then ds.Tables("client").Rows(pos).Delete() odb = New SqlCommandBuilder(da) da.Update(ds, "client") ds.Clear() da.Fill(ds, "client") dt = ds.Tables("client") MessageBox.Show("l'enregistrement a etais supprimer", "Supprimer", MessageBoxButtons.OK) ElseIf var = vbNo Then MessageBox.Show("suppretion annuler...", "Supprimer", MessageBoxButtons.OK) End If End Sub Sub init() txb_id.Text = "" txb_nom.Text = "" txb_adresse.Text = "" txb_tel.Text = "" End Sub Private Sub bt_modifier_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt_modifier.Click 'row = ds.Tables("client").Rows(pos) ds.Tables("client").Rows(pos).Item(0) = txb_id.Text ds.Tables("client").Rows(pos).Item(1) = txb_nom.Text ds.Tables("client").Rows(pos).Item(2) = txb_adresse.Text ds.Tables("client").Rows(pos).Item(3) = txb_tel.Text odb = New SqlCommandBuilder(da) da.Update(ds, "client") ds.Clear() da.Fill(ds, "client") dt = ds.Tables("client") MessageBox.Show("modification effectué.......", "Modifier", MessageBoxButtons.OK) End Sub Private Sub bt_rechercher_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt_rechercher.Click pos = 0 trouvé = 0 mot_rech = InputBox("taper le Cin du client") dt = ds.Tables("client") While pos < dt.Rows.Count If mot_rech = dt.Rows(pos).Item(0) Then txb_id.Text = dt.Rows(pos).Item(0) txb_nom.Text = dt.Rows(pos).Item(1) txb_adresse.Text = dt.Rows(pos).Item(2) txb_tel.Text = dt.Rows(pos).Item(3) trouvé += 1 Exit While Else pos += 1 End If End While If trouvé = 0 Then var = MessageBox.Show("ce client ne figure pas sur la liste", "erreur", MessageBoxButtons.OK) txb_id.Text = "" txb_nom.Text = "" txb_adresse.Text = "" txb_tel.Text = "" End If End Sub End Class ----------------------------------------------------------------------------- Imports System.Data.SqlClient Public Class Gestion_des_réservations Inherits System.Windows.Forms.Form Private Sub Gestion_des_réservations_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load cmd = New SqlCommand cmd.Connection = cn cmd.CommandText = "select * from client" da = New SqlDataAdapter(cmd) ds = New DataSet da.Fill(ds, "client") cb_num_client.DataSource = ds.Tables(0) cb_num_client.DisplayMember = "id_client" cb_num_client.Text = "" 'cb_num_client.ValueMember = "id_client" End Sub Private Sub cb_num_client_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cb_num_client.SelectedIndexChanged Dim i As Integer For i = 0 To ds.Tables("client").Rows.Count - 1 If cb_num_client.Text = ds.Tables("client").Rows(i).Item(0) Then lbl_nom.Text = ds.Tables("client").Rows(i).Item(1) lbl_tel.Text = ds.Tables("client").Rows(i).Item(3) End If Next End Sub Private Sub bt_ajout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt_ajout.Click cmd = New SqlCommand cmd.Connection = cn cmd.CommandText = "select * from Réservation" da = New SqlDataAdapter(cmd) ds = New DataSet da.Fill(ds, "Réservation") row = ds.Tables("Réservation").NewRow row.Item(0) = txb_cod_reservation.Text row.Item(1) = cb_num_client.Text row.Item(2) = txb_date.Text row.Item(3) = txb_pension.Text ds.Tables("Réservation").Rows.Add(row) odb = New SqlCommandBuilder(da) da.Update(ds, "Réservation") MsgBox("ajout effecuté") End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt_annuler.Click Dim pos, trouvé As Integer Dim mot_rech, var As String pos = 0 trouvé = 0 mot_rech = InputBox("taper le code_réservation à supprimer") cmd = New SqlCommand cmd.Connection = cn cmd.CommandText = "select * from Réservation " da = New SqlDataAdapter(cmd) ds = New DataSet da.Fill(ds, "Réservation") While pos < ds.Tables("Réservation").Rows.Count If ds.Tables("Réservation").Rows(pos).Item(0) = mot_rech Then var = MessageBox.Show("voulez vous vraiment supprimer cet enregistrement", "supprimer", MessageBoxButtons.YesNo) If var = "6" Then cmd = New SqlCommand cmd.Connection = cn cmd.CommandType = CommandType.StoredProcedure cmd.CommandText = "annuler_reservation" cmd.Parameters.Add("@mot", SqlDbType.Int) cmd.Parameters.Add("@dat", SqlDbType.DateTime) cmd.Parameters(0).Value = mot_rech cmd.Parameters(1).Value = txb_date_annulation.Text cmd.ExecuteNonQuery() MsgBox("effectué") End If trouvé += 1 Exit While Else pos += 1 End If End While If trouvé = 0 Then MessageBox.Show("ce numéro ne figure pas sur la liste", "erreur", MessageBoxButtons.OK) End If End Sub End Class ------------------------------------------------------------------------------ Imports System.Data.SqlClient Public Class Gestion_séjour Inherits System.Windows.Forms.Form Private Sub Gestion_séjour_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load remplir_list() End Sub Sub remplir_list() cmd = New SqlCommand cmd.Connection = cn cmd.CommandText = "select * from Réservation" da = New SqlDataAdapter(cmd) ds = New DataSet da.Fill(ds, "Réservation") ListBox1.DataSource = ds.Tables(0) ListBox1.DisplayMember = "code_reservation" 'cb_num_client.ValueMember = "id_client" End Sub Private Sub bt_ajouter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt_nouveau.Click TextBox1.Text = "" ComboBox1.Text = "" TextBox2.Text = "" End Sub Private Sub bt_ajouter_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt_ajouter.Click cmd = New SqlCommand cmd.Connection = cn cmd.CommandText = "select * from sejour" da = New SqlDataAdapter(cmd) ds = New DataSet da.Fill(ds, "sejour") row = ds.Tables("sejour").NewRow 'Try ' row(1) = ListBox1.SelectedItem ' row(2) = TextBox1.Text ' row(3) = ComboBox1.Text ' row(4) = TextBox2.Text 'Catch ex As Exception ' MsgBox(ex.Message) 'End Try 'ds.Tables("sejour").Rows.Add(row) 'odb = New SqlCommandBuilder(da) 'da.Update(ds, "sejour") 'MsgBox("enregistrement effectué") End Sub Private Sub bt_imprimer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt_imprimer.Click Dim frm As New Facturation Dim etat As New sejour frm.CrystalReportViewer1.ReportSource = etat frm.CrystalReportViewer1.SelectionFormula = "{Sejour.NumSejour}=" & TextBox3.Text frm.Show() End Sub End Class ------------------------------------------------------------------------------ Imports System.Data.SqlClient Module Module1 Dim str As String = "data source='.';initial catalog=FF_V9_2007;integrated security=sspi" Public cn As New SqlConnection(str) Public ds As DataSet Public da As SqlDataAdapter Public cmd As SqlCommand Public dt As DataTable Public row As DataRow Public odb As SqlCommandBuilder End Module ----------------------------------------------------------------------------- Public Class Form1 Inherits System.Windows.Forms.Form Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load cn.Open() End Sub Private Sub MenuItem6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem6.Click Dim frm As New Gestion_des_réservations frm.Show() End Sub Private Sub MenuItem7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem7.Click Dim frm As New Gestion_séjour frm.Show() End Sub Private Sub MenuItem8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem8.Click Dim frm As New Réservation_par_type frm.Show() End Sub Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem1.Click Dim frm As New Gestion_des_clients frm.Show() End Sub Private Sub MenuItem4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) End Sub End Class ------------------------------------------------------------------------------ Imports System.Data.SqlClient Public Class Réservation_par_type Inherits System.Windows.Forms.Form Private Sub Réservation_par_type_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load cmd = New SqlCommand cmd.Connection = cn cmd.CommandText = "select * from sejour" da = New SqlDataAdapter(cmd) ds = New DataSet da.Fill(ds, "sejour") ComboBox1.DataSource = ds.Tables(0) ComboBox1.DisplayMember = "TypeSejour" End Sub Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged cmd = New SqlCommand cmd.Connection = cn cmd.CommandText = "select CodeReservation,DureeSejour from sejour where TypeSejour='" & ComboBox1.Text & "'" da = New SqlDataAdapter(cmd) ds = New DataSet da.Fill(ds, "sejour") DataGrid1.DataSource = ds.Tables(0) cmd = New SqlCommand cmd.Connection = cn cmd.CommandText = "select count(*) from sejour where TypeSejour='" & ComboBox1.Text & "'" Dim i As Integer i = cmd.ExecuteScalar Label3.Text = i End Sub End Class |