mercredi 26 décembre 2018

How to reservation only in available time without exposure to clash in reservation website ( ASP.NET VB)?

I have a booking page for the halls on this page (the name of the Hall, the date of booking and the time of booking "from and to"). For example, the hall "A" was booked on 12/11/2018 from 12:00 pm to 1:00 pm . So,The Hall must not be booked again during this time of the same date, except before 12:00 pm or after 1:00 pm.

Well, I've written the code but the program is going to insert even if there is a reservation. I do not know if the error was in the condition or the Query or perhaps another reason. There is no indication of fault or error, it's just not working as required.

This is my code in the Query:-

SELECT Event_ID, Start_Time, End_Time, [Date], Event_name, Number_of_Attendees, Cpr, Hall_Number, Comments
 FROM    Resevation_of_Halls
 WHERE  (Hall_Number = ?)AND
 ([Date] =? )AND
 (([Start_Time] BETWEEN ? AND ?)
 OR
 ([End_Time] BETWEEN ? AND ?))

This code it means:-

(([Start_Time] BETWEEN 'Start.text' AND 'End.text')

OR

([End_Time] BETWEEN 'Start.text' AND 'End.text'))

  • (Start.text):it's text box for start time.

  • (End.text): it's text box for End time.

I have tried:

Gridview1: it's for data insert in the database.

Gridview2: It is determined if it is possible to reserve the hall or not through the (Query "where").

Protected Sub Reserv_btn_Click(sender As Object, e As EventArgs) Handles Reserv_btn.Click



       If GridView2.Rows.Count > 0 Then
           Label1.Text = "Hall can not be reserved"
       Else
           If GridView1.Rows.Count > 0 Then

           ReservationDB.InsertParameters("Cpr").DefaultValue = Session.Item("cpr")
               ReservationDB.InsertParameters("Hall_Number").DefaultValue = HallName.SelectedValue
               ReservationDB.InsertParameters("Date").DefaultValue = Datetxt.Text
               ReservationDB.InsertParameters("Start_Time").DefaultValue = Startxt.Text
               ReservationDB.InsertParameters("End_Time").DefaultValue = Endtxt.Text
               ReservationDB.InsertParameters("Event_name").DefaultValue = Eventxt.Text
               ReservationDB.InsertParameters("Comments").DefaultValue = Commtxt.Text

               ReservationDB.Insert()

               Label1.Text = "hall was booked!!"
               Datetxt.Text = ""
               Startxt.Text = ""
               Endtxt.Text = ""
               Eventxt.Text = ""
               Commtxt.Text = ""

             End If
       End If

   End Sub

Aucun commentaire:

Enregistrer un commentaire