Click here to Skip to main content
15,908,111 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello
I am making a project in Visual Basic to manage a hotel
In the reservation part when i am going to make a new reservation for example from 12-12-2014 to 04-01-2015 in the room 3 it makes the reservation but when i make another reservation for example from 14-12-2014 to 03-01-2015 in the room 3 it makes the reservation too but i dont want that the program to make the reservation at those days.
And i am using mysql database
Can you help me?
Thanks
Posted
Comments
OriginalGriff 13-Jan-14 7:23am    
What have you tried?
Where are you stuck?
Kornfeld Eliyahu Peter 13-Jan-14 7:24am    
Can you show us the code, where you store you reservation (probably with data structure in DB too)?
Member 10494891 13-Jan-14 15:09pm    
Dim cmd As New MySqlCommand("SELECT * FROM reserva WHERE dataent='" & String.Empty & "' and datasaida='" & String.Empty & "' and horareserva='" & String.Empty & "' and numnoites='" & String.Empty & "' and tipoquarto='" & String.Empty & "' and nquarto='" & String.Empty & "' and total='" & String.Empty & "' ", con)
con.Close()
con.Open()
Dim reader As MySqlDataReader = cmd.ExecuteReader
reader.Read()
If nometxt.Text = String.Empty And bicctxt.Text = String.Empty And moradatxt.Text = String.Empty And datanasctxt.Text = String.Empty Then
MessageBox.Show("Preencha todos os dados!", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Warning)
ElseIf nometxt.Text = String.Empty Then
MessageBox.Show("Preencha o Nome!", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Warning)
ElseIf bicctxt.Text = String.Empty Then
MessageBox.Show("Preencha o BI/CC!", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Warning)
ElseIf ncont.Text = String.Empty Then
MessageBox.Show("Preencha o Nº de Contribuinte!", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Warning)
ElseIf telefone.Text = String.Empty Then
MessageBox.Show("Preencha o Nº de Telefone!", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Warning)
ElseIf moradatxt.Text = String.Empty Then
MessageBox.Show("Preencha Morada!", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Warning)
ElseIf datanasctxt.Text = String.Empty Then
MessageBox.Show("Preencha a Data de Nascimento!", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Warning)
ElseIf tipoquarto.Text = String.Empty Then
MessageBox.Show("Escolha um Tipo de Quarto!", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Warning)
ElseIf numnoites.Text = String.Empty Then
MessageBox.Show("Escolha a data de entrada e a última noite!", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Warning)
ElseIf reader.HasRows = True Then
Console.WriteLine(registo.updateRecord("UPDATE reserva SET dataent=('" & dataentrada.Text & "'), datasaida=('" & datasaida.Text & "'), horareserva=('" & hora.Text & "'), numnoites=('" & numnoites.Text & "'), tipoquarto =('" & tipoquarto.Text & "'), nquarto=('" & nquarto.Text & "'), total=('" & totaltxt.Text & "'), funcionario=('" & func.Text & "') WHERE nome='" & nometxt.Text & "';"), con)
MessageBox.Show("Reserva efectuada com sucesso!", "Informação", MessageBoxButtons.OK, MessageBoxIcon.Information)
visualizar2()
nometxt.Text = ""
bicctxt.Text = ""
ncont.Text = ""
moradatxt.Text = ""
datanasctxt.Text = ""
totaltxt.Text = ""
tipoquarto.Text = ""
nquarto.Text = ""
idadetxt.Text = ""
numnoites.Text = ""
telefone.Text = ""
dataentrada.Value = Date.Now
datasaida.Value = Date.Now
Else
Console.WriteLine(registo.updateRecord("INSERT INTO reserva (nome, bicc, ncont, telemovel, morada, datanasc, idade,dataent, datasaida,horareserva, numnoites, tipoquarto, nquarto, total, funcionario) VALUES ('" & nometxt.Text & "', '" & bicctxt.Text & "', '" & ncont.Text & "','" & telefone.Text & "','" & moradatxt.Text & "', '" & datanasctxt.Text & "', '" & idadetxt.Text & "','" & dtentrada & "' , '" & dtsaida & "', '" & hora.Text & "','" & numnoites.Text & "','" & tipoquarto.Text & "', '" & nquarto.Text & "','" & totaltxt.Text & "', '" & Login.nometemp & "')"), con)
MessageBox.Show("Reserva efectuada com sucesso!", "Informação", MessageBoxButtons.OK, MessageBoxIcon.Information)
visualizar2()
nometxt.Text = ""
bicctxt.Text = ""
ncont.Text = ""
moradatxt.Text = ""
datanasctxt.Text = ""
totaltxt.Text = ""
tipoquarto.Text = ""
nquarto.Text =

1 solution

hi i have done that logic in C# , i am not good at VB.net
you can use this logic to work in VB.


C#
//12-12-2014 to 04-01-2015
       DateTime DbStartdateForRoom3 = new DateTime(2014, 12, 12);
       DateTime DbEnddateForRoom3 = new DateTime(2015, 01, 04);

       // 14-12-2014 to 03-01-2015

       DateTime selectedStartDate = new DateTime(2014, 12, 14);
       DateTime selectedEndDate = new DateTime(2015, 01, 03);

       List<DateTime> lstDatesEngaged = new List<DateTime>();
       int j =0;
       for (DateTime i = DbStartdateForRoom3; i <= DbEnddateForRoom3; i = DbStartdateForRoom3.AddDays(j))
       {
           lstDatesEngaged.Add( i);
           j++;
       }

       bool isBooked = lstDatesEngaged.Any(k => k == selectedStartDate || k == selectedEndDate);

       if (isBooked)
       {
           // show error message [Its already booked]
       }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900