...
nonAvailableCheckin and nonAvailableCheckout array:
Before adding the Datepicker routine, we have previously created 2 arrays, one with the arrival nonavailable dates and another with the departure nonavailable dates.
Here is an example of how we can create these arrays, using the Calendar function:
Code Block | ||||
---|---|---|---|---|
| ||||
Dim property_id As Integer = 1001 'Variables needed for the logic: Dim arrivalDaysNotAvailable As String = "" Dim departureDaysNotAvailable As String = "" Dim minimumStays As String = "" Dim dayBeforeAvailable As Boolean = False 'Reading the Calendar WS for the next 12 months 'Here we will create 2 arrays, one for arrivals and one for departures, where we will put all the unavailable dates: Dim cson As String = icnea.Calendar(property_id, Today, 12, Funcions.Empresa, Funcions.Password) Dim css As Object = New JavaScriptSerializer() With {.MaxJsonLength = Int32.MaxValue} Dim c As Object = css.Deserialize(Of Object)(cson) If c("Calendar").length > 0 Then For i As Integer = 0 To c("Calendar").length - 1 If CBool(c("Calendar")(i)("available")) Then 'available days dayBeforeAvailable = True Else If dayBeforeAvailable Then 'it is the first unavailable day of the interval Else 'unavailable days for the departure calendar departureDaysNotAvailable &= """" & CDate(c("Calendar")(i)("date")).ToString("dd/MM/yyy").Replace(".", "/").Replace("-", "/") & """," End If 'unavailable days for the arrival calendar arrivalDaysNotAvailable &= """" & CDate(c("Calendar")(i)("date")).ToString("dd/MM/yyy").Replace(".", "/").Replace("-", "/") & """," dayBeforeAvailable = False End If 'minimum stay minimumStays += c("Calendar")(i)("minimum_stay") & "," Next End If 'We delete the last character for each array, which is a comma If arrivalDaysNotAvailable.Length > 0 Then arrivalDaysNotAvailable = arrivalDaysNotAvailable.Remove(arrivalDaysNotAvailable.Length - 1) End If If departureDaysNotAvailable.Length > 0 Then departureDaysNotAvailable = departureDaysNotAvailable.Remove(departureDaysNotAvailable.Length - 1) End If If minimumStays.Length > 0 Then minimumStays = minimumStays.Remove(minimumStays.Length - 1) End If 'We add the arrays in this variable that will be the script that we will add before the Datepicker routine: Dim datePickerArrays As String = "" datePickerArrays &= "<script>" datePickerArrays &= "let nonAvailableCheckin = [" & arrivalDaysNotAvailable & "];" datePickerArrays &= "let nonAvailableCheckout = [" & departureDaysNotAvailable & "];" datePickerArrays &= "let minimumStay = [" & minimumStays & "];" datePickerArrays &= "</script>" |
...