通过状态显示可用房间

时间:2016-03-17 13:51:42

标签: asp.net web

我们有一个asp.net酒店房间预订项目,我很难通过其状态显示房间。因此,如果用户预订房间,则会反映出来的情况。表中的状态。现在,我试图展示那些没有“没有”的房间。状态,而不是显示有' Out'状态。以下是我一直渴望修复的代码:

  <% 
          Dim MyConnNew As OdbcConnection
          Dim MyCommNew As OdbcCommand
          Dim MyDataReadNew As OdbcDataReader

          Dim logic As Integer = 0

    MyConnNew = New OdbcConnection("DRIVER={MySQL ODBC 3.51 Driver};Database=hotelsdb;Server=localhost;UID=root;")
          MyConnNew.Open()
          If MyConnNew.State = 0 Then
              MyConnNew.Open()
          End If
    MyCommNew = New OdbcCommand("select * from hotelbookings where status ='" + "Out" + "'", MyConnNew)
          MyDataReadNew = MyCommNew.ExecuteReader()
          Dim roomParams As New List(Of Integer)()

          While (MyDataReadNew.Read())
        If MyDataReadNew.Item("roomid") <> 0 Then
            roomParams.Add(MyDataReadNew.Item("roomid"))
            logic = 1
        End If

          End While
          Dim roomArray() As Integer = roomParams.ToArray()
              If logic <> 0 Then


        MyCommNew = New OdbcCommand("select * from hotelrooms", MyConnNew)
                      MyDataReadNew = MyCommNew.ExecuteReader()

        Dim valid As Boolean
              valid = False
              While (MyDataReadNew.Read())

                  For i As Integer = 0 To roomArray.Length - 1
                If MyDataReadNew.Item("roomid") = roomArray(i) Then
                    valid = True
                End If
                  Next

                  If valid <> True Then


                 %>

 <div class="col-xs-12 col-sm-4 col-md-4">
                <input type="hidden" value="<%Response.Write(MyDataReadNew.Item("roomid"))%>"/>
                <div class="grid wow zoomIn">
                    <figure class="effect-bubba">
                        <a href="Rooms.aspx">
                        <img src="assets/images/<%Response.Write(MyDataReadNew.Item("roomimage"))%>"/>

                        </a>            
                    </figure>
                    <div class="text-left">
                         <input type="hidden" value="<%Response.Write(MyDataReadNew.Item("roomnumber"))%>" />
                    <ul class="list-unstyled">

        <li><h2><%Response.Write(MyDataReadNew.Item("roomtype"))%> Room</h2></li>
        <li><b>Adults:</b> Up to 3 adult(s)</li>
        <li><b>Children (0-12 yrs old):</b> Free</li>
        <li><b>Starting rate per night:</b> <%Response.Write(MyDataReadNew.Item("roomrate"))%> php</li>
        <li><a class="btn btn-primary"  href="insertreservation.aspx?room_id=<% Response.Write(MyDataReadNew.Item("roomid"))%>" >Reserve</a><br/></li>
       </ul>

                        </div>
                </div>

            </div>

  
            <nav id="myscroll" class="navbar navbar-default navbar-static top" role="navigation">
                <h2>Select Available rooms</h2>
<div class="alert alert-info"><p><b>All rooms have:</b> 40-inch LED HDTV with cable channels• Media panel with HDMI, USB and A/V connectivity• Speaker Phone with iPod dock and FM Stereo• Executive Writing Desk• Complimentary Wi-Fi</p>

</div>
            </nav>

            <div data-spy="scroll" data-target="#myscroll" data-offset="0" style="height:500px;overflow:auto; position: relative;">
            <div class="container">



      <%While (MyDataReadNew.Read())%>                
 <div class="col-xs-12 col-sm-4 col-md-4">
                <input type="hidden" value="<%Response.Write(MyDataReadNew.Item("roomid"))%>"/>
                <div class="grid wow zoomIn">
                    <figure class="effect-bubba">
                        <a href="Rooms.aspx">
                        <img src="assets/images/<%Response.Write(MyDataReadNew.Item("roomimage"))%>"/>

                        </a>            
                    </figure>
                    <div class="text-left">
                         <input type="hidden" value="<%Response.Write(MyDataReadNew.Item("roomnumber"))%>" />
                    <ul class="list-unstyled">

        <li><h2><%Response.Write(MyDataReadNew.Item("roomtype"))%> Room</h2></li>
        <li><b>Adults:</b> Up to 3 adult(s)</li>
        <li><b>Children (0-12 yrs old):</b> Free</li>
        <li><b>Starting rate per night:</b> <%Response.Write(MyDataReadNew.Item("roomrate"))%> php</li>
        <li><a class="btn btn-primary"  href="insertreservation.aspx?roomid=<% Response.Write(MyDataReadNew.Item("roomid"))%>" >Reserve</a><br/></li>
       </ul>

                        </div>
                </div>

            </div>

             <%
                    End While
                End If
                MyDataReadNew.Close()
                    MyConnNew.Close()
                    %>          
                </div>

希望你能帮忙解决这个问题:)谢谢

1 个答案:

答案 0 :(得分:0)

首先,您可以写下:

,而不是两个查询
Select distinct  hotelrooms.roomid, hotelrooms.roomimage, hotelrooms.roomtype --other fields here
from hotelbookings
left outer join hotelrooms on hotelrooms.roomid=hotelbookings.roomid
where hotelbookings.status ='Out'

select * 
from hotelrooms 
where roomid in --or 'not in'
(select hotelbookings.roomid 
from hotelbookings 
where hotelbookings.status ='Out')

然后我们需要表格结构。 我无法理解您发布的原因

<div class="col-xs-12 col-sm-4 col-md-4">...</div>

也许它与你的问题无关。