Mini Kabibi Habibi

Current Path : C:/Users/Public/Documents/DXperience 13.1 Demos/ASP.NET/VB/HotelBooking/
Upload File :
Current File : C:/Users/Public/Documents/DXperience 13.1 Demos/ASP.NET/VB/HotelBooking/Results.aspx.vb

Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports DevExpress.Web.ASPxGridView
Imports DevExpress.Web.Data
Imports DevExpress.Web.ASPxClasses
Imports System.Text
Imports System.Drawing
Imports System.Collections

Partial Public Class Results
	Inherits System.Web.UI.Page
	Protected Sub Page_Init(ByVal sender As Object, ByVal e As EventArgs)
		If Data.Instance.CurrentQuery Is Nothing Then
			Response.Redirect("Default.aspx")
		End If

		divSearchIsNotAvailable.Visible = Data.Instance.CurrentQuery.IsSearch
		filterPanel.Visible = Not Data.Instance.CurrentQuery.IsSearch
		gvResults.Visible = Not Data.Instance.CurrentQuery.IsSearch

		Utils.SetDefaultDateEditValues(deCheckIn, deCheckOut)
		If Data.Instance.CurrentQuery.IsSearch Then
			Data.Instance.CurrentQuery.IsSearch = False
		End If
	End Sub
	Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
		InitEditorsValues()
		LoadGridData()
	End Sub
	Protected Sub deCheckIn_Validation(ByVal sender As Object, ByVal e As DevExpress.Web.ASPxEditors.ValidationEventArgs)
		Utils.ValidateCheckInDate(e)
	End Sub
	Protected Sub deCheckOut_Validation(ByVal sender As Object, ByVal e As DevExpress.Web.ASPxEditors.ValidationEventArgs)
		Utils.ValidateCheckOutDate(CDate(deCheckIn.Value), e)
	End Sub
	Protected Sub btnRefresh_Click(ByVal sender As Object, ByVal e As EventArgs)
		InitializeSearchQuery()
		LoadGridData()
	End Sub
	Protected Sub cmbCity_Callback(ByVal source As Object, ByVal e As CallbackEventArgsBase)
		Dim country As String = e.Parameter
		If String.IsNullOrEmpty(country) Then
			Return
		End If
		cmbCity.DataSource = Data.Instance.Countries.Find(Function(c) c.Name = country).Cities
		cmbCity.DataBind()
	End Sub
	Protected Function GetHotelPrice(ByVal container As GridViewDataItemTemplateContainer) As String
		Dim hotel As Hotel = GetHotel(container)
		If hotel.MinPrice = hotel.MaxPrice Then
			Return String.Format("${0}", hotel.MinPrice)
		End If
		Return String.Format("${0} - ${1}", hotel.MinPrice, hotel.MaxPrice)
	End Function
	Protected Function GetOrderUrl(ByVal container As GridViewDataItemTemplateContainer) As String
		Return Utils.GetOrderFormUrl(GetHotel(container))
	End Function
	Protected Function GetHotelImageUrl(ByVal index As Integer) As String
		Return Utils.GetImageUrl((CType(gvResults.GetRow(index), Hotel)).ImageUrl, Utils.GridImageSize)
	End Function
	Protected Function GetHotelDescription(ByVal index As Integer) As String
		Return (CType(gvResults.GetRow(index), Hotel)).Description
	End Function
	Protected Function GetPreviewHotelImageUrl(ByVal index As Integer) As String
		Return Utils.GetImageUrl((CType(gvResults.GetRow(index), Hotel)).ImageUrl, Utils.PopupImageSize)
	End Function
	Protected Function GetExpandButtonFunction(ByVal index As Integer) As String
		If gvResults.DetailRows.IsVisible(index) Then
			Return "gvHideDetails"
		Else
			Return "gvShowDetails"
		End If
	End Function
	Protected Function GetExpandButtonTitle(ByVal index As Integer) As String
		If gvResults.DetailRows.IsVisible(index) Then
			Return "Hide details"
		Else
			Return "Show details"
		End If
	End Function
	Protected Function GetExpandedBoldClass(ByVal index As Integer) As String
		If gvResults.DetailRows.IsVisible(index) Then
			Return "bold"
		Else
			Return ""
		End If
	End Function

	Private Sub InitEditorsValues()
		ccbHotelServices.DataSource = Data.Instance.HotelServices
		ccbHotelServices.DataBind()
		ccbHotestars.DataSource = Data.Instance.HotelStars
		ccbHotestars.DataBind()
		ccbRoomServices.DataSource = Data.Instance.RoomServices
		ccbRoomServices.DataBind()
		cmbRoomType.DataSource = Data.Instance.RoomTypes
		cmbRoomType.DataBind()
		cmbCountry.DataSource = Data.Instance.Countries
		cmbCountry.DataBind()

		Dim query As SearchQuery = Data.Instance.CurrentQuery
		If (Not IsPostBack) Then
			If (Not String.IsNullOrEmpty(query.Country)) Then
				cmbCountry.Value = query.Country
				cmbCity.DataSource = Data.Instance.Countries.Find(Function(c) c.Name = query.Country).Cities
				cmbCity.DataBind()
			End If
			If (Not String.IsNullOrEmpty(query.City)) Then
				cmbCity.Value = query.City
			End If

			If query.FromDate.HasValue Then
				deCheckIn.Value = query.FromDate
			Else
				deCheckIn.Value = deCheckIn.Value
			End If
			If query.ToDate.HasValue Then
				deCheckOut.Value = query.ToDate
			Else
				deCheckOut.Value = deCheckOut.Value
			End If
			seMinPrice.Value = query.MinPrice
			seMaxPrice.Value = query.MaxPrice
			cmbRoomType.Value = query.RoomType
			seAdults.Value = query.Adults
			seChildren.Value = query.Children
			ccbHotelServices.Values = query.HotelServices
			ccbHotestars.ValueType = GetType(Integer)
			ccbHotestars.Values = query.Stars
			ccbRoomServices.Values = query.RoomServices
		End If
	End Sub
	Private Sub LoadGridData()
		gvResults.DataSource = Data.Instance.GetSearchResults()
		gvResults.DataBind()
	End Sub
	Private Function GetHotel(ByVal container As GridViewDataItemTemplateContainer) As Hotel
		Return TryCast(container.Grid.GetRow(container.VisibleIndex), Hotel)
	End Function
	Private Sub InitializeSearchQuery()
		If seMaxPrice.Value Is Nothing Then
			If seMinPrice.Value Is Nothing Then
				Data.Instance.CurrentQuery = New SearchQuery() With {.Country = CStr(cmbCountry.Value), .City = CStr(cmbCity.Value), .MaxPrice = 0, .MinPrice = 0, .FromDate = CDate(deCheckIn.Value), .ToDate = CDate(deCheckOut.Value), .RoomType = CStr(cmbRoomType.Value), .Adults = Convert.ToInt32(seAdults.Value), .Children = Convert.ToInt32(seChildren.Value), .Stars = ccbHotestars.Values.Cast(Of Integer)().ToArray(), .HotelServices = ccbHotelServices.Values.Cast(Of String)().ToArray(), .RoomServices = ccbRoomServices.Values.Cast(Of String)().ToArray()}
			Else
				Data.Instance.CurrentQuery = New SearchQuery() With {.Country = CStr(cmbCountry.Value), .City = CStr(cmbCity.Value), .MaxPrice = 0, .MinPrice = CDec(seMinPrice.Value), .FromDate = CDate(deCheckIn.Value), .ToDate = CDate(deCheckOut.Value), .RoomType = CStr(cmbRoomType.Value), .Adults = Convert.ToInt32(seAdults.Value), .Children = Convert.ToInt32(seChildren.Value), .Stars = ccbHotestars.Values.Cast(Of Integer)().ToArray(), .HotelServices = ccbHotelServices.Values.Cast(Of String)().ToArray(), .RoomServices = ccbRoomServices.Values.Cast(Of String)().ToArray()}
			End If
		Else
			If seMinPrice.Value Is Nothing Then
				Data.Instance.CurrentQuery = New SearchQuery() With {.Country = CStr(cmbCountry.Value), .City = CStr(cmbCity.Value), .MaxPrice = CDec(seMaxPrice.Value), .MinPrice = 0, .FromDate = CDate(deCheckIn.Value), .ToDate = CDate(deCheckOut.Value), .RoomType = CStr(cmbRoomType.Value), .Adults = Convert.ToInt32(seAdults.Value), .Children = Convert.ToInt32(seChildren.Value), .Stars = ccbHotestars.Values.Cast(Of Integer)().ToArray(), .HotelServices = ccbHotelServices.Values.Cast(Of String)().ToArray(), .RoomServices = ccbRoomServices.Values.Cast(Of String)().ToArray()}
			Else
				Data.Instance.CurrentQuery = New SearchQuery() With {.Country = CStr(cmbCountry.Value), .City = CStr(cmbCity.Value), .MaxPrice = CDec(seMaxPrice.Value), .MinPrice = CDec(seMinPrice.Value), .FromDate = CDate(deCheckIn.Value), .ToDate = CDate(deCheckOut.Value), .RoomType = CStr(cmbRoomType.Value), .Adults = Convert.ToInt32(seAdults.Value), .Children = Convert.ToInt32(seChildren.Value), .Stars = ccbHotestars.Values.Cast(Of Integer)().ToArray(), .HotelServices = ccbHotelServices.Values.Cast(Of String)().ToArray(), .RoomServices = ccbRoomServices.Values.Cast(Of String)().ToArray()}
			End If
		End If
	End Sub
End Class