Show available rooms through Status - asp.net

We have an asp.net hotel room reservation project and I have difficulties in showing the rooms through its status. So if the user will book a room, it will reflect 'In' status in the table. And now, I tried to show the rooms which doesn't have 'In' Status and instead, show the rooms which have 'Out' status. Here is the code that I've been dying to fix:
<%
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>
Hope you'll help with this :) Thanks

First of all, instead of two queries, you can write:
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'
or
select *
from hotelrooms
where roomid in --or 'not in'
(select hotelbookings.roomid
from hotelbookings
where hotelbookings.status ='Out')
Then we need tables structure.
I can't understand why you post
<div class="col-xs-12 col-sm-4 col-md-4">...</div>
maybe it's not related to your question.

Related

Click a button from a drop-down menu with RSelenium

I have problem. I have to click the line "in codici prodotto".
<div class="row typeahead">
<div class="col-sm-12 cursor typeahead-row" data-ng-class="{'typeahead-row-selected': view.searchSlots[0].selected}" style="margin-bottom:2px" data-ng-mousedown="searchDocs(model.inputheaderlg)"> " 67D16EA#ABZ "
{{model.inputheaderlg | limitTo: 50}} <span data-ng-if="model.inputheaderlg.length >50">...</span> <span style="color:#bbb"> in informazioni</span> <span class="pull-right"><img style="margin-bottom:3px" alt="vai" src="/opencms/opencms/immagini/rifacimento_nuovo_portale/HP/frecciatype.png"></span>
</div>
<div class="col-sm-12 cursor voffset typeahead-row" data-ng-class="{'typeahead-row-selected': view.searchSlots[1].selected}" data-ng-if="showProduct()" data-ng-mousedown="searchProdotti(model.inputheaderlg)"> " 67D16EA#ABZ "
{{model.inputheaderlg | limitTo: 50}} <span data-ng-if="model.inputheaderlg.length >50">...</span> <span style="color:#bbb"> in prodotti</span> <span class="pull-right"><img style="margin-bottom:3px" alt="vai" src="/opencms/opencms/immagini/rifacimento_nuovo_portale/HP/frecciatype.png"></span>
</div>
<div class="col-sm-12 cursor typeahead-row" data-ng-class="{'typeahead-row-selected': view.searchSlots[2].selected}" data-ng-if="showProductCodes()" data-ng-mousedown="searchCodice(model.inputheaderlg)"> " 67D16EA#ABZ "
{{model.inputheaderlg | limitTo: 50}} <span data-ng-if="model.inputheaderlg.length >50">...</span> <span style="color:#bbb"> in codici prodotto</span> <span class="pull-right"><img style="margin-bottom:3px" alt="vai" src="/opencms/opencms/immagini/rifacimento_nuovo_portale/HP/frecciatype.png"</span>
</div>
</div>
I have tried CSS and with XPATH......
#css
webelem4 <- remote_driver$findElement(using = "css",'#headersearchformlg .ng-scope+ .ng-scope span:nth-child(1)')
webelem4$clickElement
#xpath
webelem4 <- remote_driver$findElement(using = "xpath",'//*
[#id="headersearchformlg"]/fieldset/div/div[3]/div/div[3]')
webelem4$clickElement
.....but I always get the same answer.
Class method definition for method clickElement()
function ()
{
"Click the element."
qpath <- sprintf("%s/session/%s/element/%s/click",
serverURL, sessionInfo[["id"]], elementId)
queryRD(qpath, "POST")
}
<environment: 0x00000248bd0ad708>
Methods used:
"queryRD"

Rails - how to add css to a helper method

Im trying to move a long if statement out of my view and into a helper method.
I currently have:
module ProfilesHelper
def items_for_profile_menu(profile)
if current_user = #profile.user_id
"<li class="col-xs-4 col-sm-2 nopadding menuitem" style="background:#006F7F">
<a href="index.html" class="hvr-sweep-to-bottom">
# link_to dashboard_path(#profile.dashboard)
<span>Dashboard</span>
</a>
</li>
<li class="col-xs-4 col-sm-2 nopadding menuitem" style="background:#39AFBF">
<a href="#resume" class="hvr-sweep-to-bottom">
<!-- <i class="flaticon-graduation61"></i> --><br><br>
<span>Timeline</span></a>
</li>"
<% else %>
"<li class="col-xs-6 col-sm-3 nopadding menuitem orange">
<i class="flaticon-placeholders4"></i><span>Impact</span>
</li>
<li class="col-xs-6 col-sm-3 nopadding menuitem red">
<i class="flaticon-earphones18"></i><span>Feedback</span>
</li>"
<% end %>
end
end
Im getting stuck figuring out whether I can write css in the helper itself? If I can, how can I learn about the modifications required to get it working? In the view I was able to write: background:#006F7F in the list item. If I add that to the helper - then the # is received as a comment.
Can anyone see how to setup a helper method with CSS?
Use .html_safe for example:
def my_name
name = "<h1>Eric Santos!</h1>"
name.html_safe
end
hope you get the idea!
You are not terminating string properly in your code. One double quote (") will terminate previous double quote ("). So your string is consider like "<li class=" as one string and looking for " after that and you will get error if this is not the case.
So for declaring class inside a big string use single quotes (') inside a big double quoted (") string and concat each big string with (+).
To add class use single quote "<li class='col-xs-4 col-sm-2 nopadding menuitem'>Hi </li>" + "<li class='col-xs-4 col-sm-2 nopadding menuitem'>Hello </li>"
Change your code like below.
module ProfilesHelper
def items_for_profile_menu(profile)
if current_user = #profile.user_id
"<li class='col-xs-4 col-sm-2 nopadding menuitem' style='background:#006F7F'>
<a href='index.html' class='hvr-sweep-to-bottom'>
<span>Dashboard</span></a>
</li>
<li class='col-xs-4 col-sm-2 nopadding menuitem' style='background:#39AFBF'>
<a href='#resume' class='hvr-sweep-to-bottom'>
<span>Timeline</span></a>
</li>"
else
"<li class='col-xs-6 col-sm-3 nopadding menuitem orange'>
<a href='#stats' class='hvr-sweep-to-bottom'><i class='flaticon-placeholders4'></i><span>Impact</span></a>
</li>
<li class='col-xs-6 col-sm-3 nopadding menuitem red'>
<a href='#feedback' class='hvr-sweep-to-bottom'><i class='flaticon-earphones18'></i><span>Feedback</span></a>
</li>"
end
end
end

Getting the value from a button text for thyme leaf

Ok, I have this somewhat complex piece of HTML that I have to integrate with. It is a button with a drop down (using aria) and I had to pass in a currency list and be able to select one of the dropdown elements (currency values) and update the button text with the selected value. I write a tiny bit of js and that works well. I use thymeleaf to pass in values to populate and that works well. I also need to read the values that were set from the post to the spring mvc controller but I always get a empty string for the value that I set via js.
here is the javascript
$(".currencyDropdown li a").click(function () {
var selText = $(this).text().trim();
var button = $("#currencyButton");
button.text(selText);
console.log("currency selected is:" + selText);
});
here is the html
<div class="col-sm-9 col-sm-offset-3 col-xs-12 form-row">
<div class="dropdown">
<button class="btn btn-default dropdown-toggle field-small"
type="button"
id="currencyButton"
name="currencyButton"
th:field="${pals.selectedCurrency}"
data-toggle="dropdown"
th:inline="text">
[[${pals.selectedCurrency}]]
<i class="fa fa-caret-down"></i>
</button>
<ul id="currencyDropdown"
class="dropdown-menu currencyDropdown"
role="menu"
aria-labelledby="currencyButton">
<li role="presentation"
th:each="currency:${pals.currencyList}">
<a role="menuitem"
tabindex="-1"
href="#"
th:inline="text">
[[${currency}]]
</a>
</li>
</ul>
</div>
What I am trying to read back in the spring mvc controller is the pals.selectedCurrency value and it is always empty. Something I am missing? I was playing around and tried setting value and field. In reality I want to read the inline text that my js inserts.
I think you must add a th:fragment on you button and change the text of the button via ajax from backing bean from server, not from javascript. It's something like this :
<form th:action="#{/PersonEdit/save(contract=${param.contract})}" th:object="${personBean}"
method="POST" th:if="${param.contract != null}">
... other form components
<div class="form-group">
<label class="col-sm-4 control-label"
th:text="#{person.edit.policy.tfoms}"></label>
<div class="col-sm-8">
<select class="form-control" th:field="*{tfoms}"
onchange="loadInsuranceCompanies()">
<option th:each="t : ${tfomses}"
th:value="${t.uidtfoms}"
th:text="${t.shortName}"
th:selected="${personBean.tfoms != null
and personBean.tfoms.equals(t)}"></option>
</select>
</div>
</div>
<div th:class="${#fields.hasErrors('insuranceCompany')}
? 'form-group has-error' : 'form-group'">
<label class="col-sm-4 control-label"
th:text="#{person.edit.policy.ic}"></label>
<div class="col-sm-8" id="insuranceCompaniesContent">
<select class="form-control" id="insuranceCompany"
name="insuranceCompany"
th:fragment="insuranceCompany">
<option th:each="i : ${insuranceCompanies}"
th:value="${i.uidinsurancecompany}"
th:text="${i.shortName}"
th:selected="${personBean.insuranceCompany != null
and personBean.insuranceCompany.equals(i)}"></option>
</select>
<div th:if="${#fields.hasErrors('insuranceCompany')}"
th:each="err : ${#fields.errors('insuranceCompany')}">
<span class="text-danger" th:text="${err}"></span><br/>
</div>
</div>
</div>
In my case I refreshing one dropdown via another.Then refresh this fragment via ajax on item selection
function loadInsuranceCompanies() {
var url = [[#{/PersonEdit/insuranceCompanies}]];
if ($('#tfoms').val() !== '') {
url = url + '/' + $('#tfoms').val();
}
$("#insuranceCompaniesContent").load(url);
}
I think the trouble can be because you using not a standard select as a dropdown.
Ok, I figured out a relatively simple answer to it. I have to use the html that was provided because of look and feel considerations from the customer.
so what I did was add a hidden input and set that from the java script.
$(".currencyDropdown li a").click(function () {
var selText = $(this).text().trim();
$("#currencyButton").text(selText);
$("#currencySelected").val(selText);
console.log("currency selected is:" + selText);
});
<input type="hidden"
id="currencySelected"
th:field="${pals.selectedCurrency}"/>
<button class="btn btn-default dropdown-toggle field-small"
type="button"
id="currencyButton"
data-toggle="dropdown"
th:inline="text">
[[${pals.selectedCurrency}]]
<i class="fa fa-caret-down"></i>
</button>
<ul id="currencyDropdown"
class="dropdown-menu currencyDropdown"
role="menu"
aria-labelledby="currencyButton">
<li role="presentation"
th:each="currency:${pals.currencyList}">
<a role="menuitem"
tabindex="-1"
href="#"
th:inline="text">
[[${currency}]]
</a>
</li>
</ul>
I see the correct values that were selected for my dropdown on the spring mvc controller and now I can get on with the rest of the stuff.

Dynamic Bootstrap Accordian loads in show

I have a bootstrap accordion that is generated dynamically from code behind. It is loaded during page_init. Everything works except they are all set to open ('show') not closed ('hide').
If I take the generated markup and run it, it works fine so the html is OK. Any ideas?
Thanks
============== EDIT ============
This script resolves the problem
Private Sub SectionClose()
Try
Dim SB As New StringBuilder
SB.Append("$(document).ready(function(){")
SB.Append(" $('#accordion').accordion({ collapsible: true, active: false }); ")
SB.Append("$('.selector').accordion(); ")
SB.Append("}); ")
ScriptManager.RegisterStartupScript(Me, Me.GetType(), "ShowCollapse", SB.ToString, True)
Catch ex As Exception
Dim vError As New SendError
vError.MailError("214", PageName, ex)
End Try
End Sub
and it now works perfectly, but throws a Object doesn't support property or method 'accordion'
This is what the generated markup looks like
<div class="panel panel-default">
<div class="panel-heading">Current Board Members</div>
<!-- Start of Dynamic elements -->
<div id="MainContent_ContactBoardMembers" class="panel-body">
<div class="panel-group" id="accordion">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title"><a data-toggle="collapse" data-parent="#accordion" href="#collapse_1">John Doe - Treasurer</a></h4>
</div>
<div id="collapse_1" class="panel-collapse collapse">
<div class="panel-body"></div>
</div>
<div class="panel-heading">
<h4 class="panel-title"><a data-toggle="collapse" data-parent="#accordion" href="#collapse_2">John Smith - President</a></h4>
</div>
<div id="collapse_2" class="panel-collapse collapse">
<div class="panel-body"></div>
</div>
<div class="panel-heading">
<h4 class="panel-title"><a data-toggle="collapse" data-parent="#accordion" href="#collapse_3">Bill Mathews - Director at large</a></h4>
</div>
<div id="collapse_3" class="panel-collapse collapse">
<div class="panel-body"></div>
</div>
</div>
</div>
</div>
<!-- End of Dynamic elements -->
</div>
Edit - added to show how to create accordion from code behind
Dim i As Integer = 0
For Each Row As DataRow In DT.Rows
i = Row("Member_ID")
Dim MemberName As String = ""
MemberName += vFunction.ReturnText(Row("First_Name"))
MemberName += " " & vFunction.ReturnText(Row("Surname"))
MemberName += " - " & vFunction.ReturnText(Row("Position"))
Dim PanelHeading As New HtmlGenericControl("div")
With PanelHeading
.Attributes.Add("class", "panel-heading")
End With
Dim H4 As New HtmlGenericControl("h4")
With H4
.Attributes.Add("class", "panel-title")
End With
PanelHeading.Controls.Add(H4)
Dim aData As New HtmlGenericControl("a")
With aData
.Attributes.Add("class", "accordion-toggle collapsed")
.Attributes.Add("data-toggle", "collapse")
.Attributes.Add("data-parent", "#accordion")
.Attributes.Add("href", "#collapse_" & i)
' .Attributes.Add("data-target", "#collapse_" & i)
.InnerHtml = MemberName
End With
H4.Controls.Add(aData)
I noticed that the 'solution' (adding the script) didn't help and when I added jquery.ui to the page (for some reason it wasn't working in the bundle) the error went, but the issue was still there - I did notice that every time there was a javascript error the accordion worked, so I disabled one script at a time in the masterpage.
The NavBar is built dynamically and a script is loaded to change #media according to how large it is - once I changed .collapse to .navbar-collapse everything worked :-)

Create custom portelt - mixture of news and events

I'm trying to create a custom portelt which displays news or event items based on a keyword. I don't want to use the collects portlet facility. I've created a Python Script which fetches the necessary results like this:
from Products.CMFCore.utils import getToolByName
portal_catalog = getToolByName(context, 'portal_catalog')
return portal_catalog.searchResults(
Subject = 'Startseite',
end={'query': DateTime(),
'range': 'min'},
sort_on='start',
sort_limit=3,
review_state='external')[:5]
So this should fetch all objects with the review_state 'external' and the keyword (or subject) 'Startseite'. Now I've created a page template which is used to render a classic portelt:
<html xmlns:tal="http://xml.zope.org/namespaces/tal"
xmlns:metal="http://xml.zope.org/namespaces/metal"
i18n:domain="plone">
<body>
<div metal:define-macro="portlet"
tal:define="view context/##events_view;
results context/startpage_informations;
events_link view/all_events_link;
prev_events_link view/prev_events_link"
tal:condition="results">
<dl class="portlet" id="portlet-events">
<dt class="portletHeader">
<span class="portletTopLeft"></span>
<a href=""
tal:attributes="href events_link"
class="tile">
Wichtige Neuigkeiten:
</a>
<span class="portletTopRight"></span>
</dt>
<tal:events tal:repeat="obj results">
<dd class="portletItem"
tal:define="oddrow repeat/obj/odd"
tal:attributes="class python:test(oddrow, 'portletItem even', 'portletItem odd')">
<a href="#"
class="tile"
tal:attributes="href obj/getURL;
title obj/Description">
<img src="#" alt="" tal:replace="structure here/news_icon.gif" />
<span tal:replace="obj/pretty_title_or_id">
Some Event
</span>
<span class="portletItemDetails"
tal:define="starts python:toLocalizedTime(obj.start, long_format=1);
ends python:toLocalizedTime(obj.end, long_format=1);
startTime python:toLocalizedTime(obj.start,time_only=1);
endTime python:toLocalizedTime(obj.end,time_only=1);
startDay python:toLocalizedTime(obj.start, long_format=0);
endDay python:toLocalizedTime(obj.end, long_format=0);">
<span>
<tal:condition condition="obj/location">
<tal:location content="obj/location">Location</tal:location>,<br />
</tal:condition>
<tal:sameday tal:condition="python:startDay==endDay">
<span tal:condition="startDay" tal:replace="startDay">:[If this is an event, show its start time and date]</span><br />
Uhrzeit: <span tal:condition="startTime" tal:replace="startTime">[If this is an event, show its start time and date]</span> -
<span tal:condition="endTime" tal:replace="endTime">[If this is an event, show its start time and date]</span>
</tal:sameday>
<tal:multiday tal:condition="python:startDay!=endDay">
Vom <span tal:condition="starts" tal:replace="starts">[If this is a multi-day event, show its start date]</span><br />bis
<tal:hasendday tal:condition="ends">
<span tal:replace="ends">[If this is a multi-day event, show its end date]</span>
</tal:hasendday>
</tal:multiday>
</span>
</span>
</a>
</dd>
</tal:events>
</dl>
</div>
</body>
</html>

Resources