Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
Dim checkindate As DateTime = checkinDTP.Value
Dim checkoutdate As DateTime = checkoutDTP.Value
Dim checkinTarihi, checkoutTarihi As Date
checkinTarihi = checkinDTP.Value
checkoutTarihi = checkoutDTP.Value
Dim suAnkiTarih As Date
suAnkiTarih = Date.Now
Dim kisisay As Integer = 1
Dim rezSay, kapasite As Integer
kapasite = Convert.ToInt32(odaNo.SelectedValue.ToString)
rezSay = Convert.ToInt32(odaNo.SelectedValue.ToString)
RezervasyonSayisi(rezSay)
OdaKapasite(kapasite)
If misafirID.SelectedIndex = -1 Or misafirAdi.Text = “” Or odaNo.SelectedIndex = -1 Then
MsgBox(“Hatalı İşlem…”)
ElseIf checkinTarihi < suAnkiTarih OrElse checkoutTarihi < suAnkiTarih OrElse checkoutTarihi <= checkinTarihi Then
MsgBox(“Lütfen rezervasyon tarihini kontrol ediniz!”)
Else
Select Case rezSay
Case < kapasite
baglanti.Open()
Dim sorgu As String = “INSERT INTO rezervasyon (musteriID, musteriAdi, odaNo, girisTarihi, cikisTarihi) VALUES (@musteriID, @musteriAdi, @odaNo, @girisTarihi, @cikisTarihi)”
Dim komut As New SqlCommand(sorgu, baglanti)
komut.Parameters.AddWithValue("@musteriID", misafirID.SelectedValue.ToString())
komut.Parameters.AddWithValue("@musteriAdi", misafirAdi.Text)
komut.Parameters.AddWithValue("@odaNo", odaNo.SelectedValue.ToString())
komut.Parameters.AddWithValue("@girisTarihi", SqlDbType.DateTime).Value = checkindate
komut.Parameters.AddWithValue("@cikisTarihi", SqlDbType.DateTime).Value = checkoutdate
komut.ExecuteNonQuery()
baglanti.Close()
populate()
OdaGuncelle()
'Clear()
Case Else
MsgBox("Oda kapasitesi dolu. Başka bir oda seçiniz.")
End Select
End If
End Sub
Public Function RezervasyonSayisi(rezSay As Integer) As Integer
Dim rezervsayonSayisi As Integer = 0
Try
baglanti.Open()
Dim sorgu As String = “SELECT COUNT(*) FROM rezervasyon WHERE odaNo = @odaNo”
Dim komut As SqlCommand
komut = New SqlCommand(sorgu, baglanti)
komut.Parameters.AddWithValue(“@odaNo”, odaNo)
RezervasyonSayisi = Convert.ToInt32(komut.ExecuteScalar())
Catch ex As Exception
MsgBox(“Hata:” + ex.Message)
Finally
If baglanti.State = ConnectionState.Open Then
baglanti.Close()
End If
End Try
Return rezervsayonSayisi
End Function
Public Function OdaKapasite(kapasite As Integer) As Integer
Dim kapasitesayisi As Integer = 0
Try
baglanti.Open()
Dim sorgu As String = “SELECT kapasite FROM odalar WHERE odaNo = @odaNo”
Dim komut As SqlCommand
komut = New SqlCommand(sorgu, baglanti)
komut.Parameters.AddWithValue(“@odaNo”, Convert.ToInt32(odaNo.SelectedValue))
kapasitesayisi = komut.ExecuteScalar()
Catch ex As Exception
MsgBox(“Hata:” + ex.Message)
Finally
If baglanti.State = ConnectionState.Open Then
baglanti.Close()
End If
End Try
Return kapasitesayisi
End Function
I shared my codes for adding reservation button, calculating the number of reservations for the selected room and getting the capacity of the selected room. After the system error, it gives the error “room capacity is full…” in the reservation adding section.
Aysun YADİGAR is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.