below the code from the file responsble for the action.
<%@ WebHandler Language="VB" Class="Map" %>
' ###################################################################################################
' #-------------------------------------------------------------------------------------------------#
' #-- inuReservation module for DotNetNuke - http://www.reservation.in-u.at --#
' #-- Copyright © 2009-2011 by in-u!® http://www.in-u.at --#
' #-------------------------------------------------------------------------------------------------#
' #-- This software is protected by copyright laws and international copyright treaties, as well --#
' #-- as other intellectual property laws and treaties. --#
' #-- You may not reverse engineer, decompile, or disassemble the software, except and only --#
' #-- to the extent that such activity is expressly permitted by applicable law notwithstanding --#
' #-- this limitation. You may not use this code or parts of this code in your own development. --#
' #-- The software is licensed as a single product. Its component parts may not be separated or --#
' #-- used on more than one production server and additional on ONE local installation for --#
' #-- testing purposes only which is not used for the delivery of actual content. --#
' #-------------------------------------------------------------------------------------------------#
' #-- Filename: Map.ashx | Version: v 1.2.0 | Author: datzg --#
' #-------------------------------------------------------------------------------------------------#
' ###################################################################################################
Imports System
Imports System.IO
Imports System.Web
Imports System.Drawing
Imports System.Drawing.Imaging
Imports System.Drawing.Drawing2D
Imports System.Data
Imports DotNetNuke
Imports System.Collections.Generic
Imports DotNetNuke.Entities.Modules.PortalModuleBase ' for module settings
Public Class Map
Implements IHttpHandler
Public Sub ProcessRequest(ByVal ctx As HttpContext) Implements IHttpHandler.ProcessRequest
' ###############################################################################
' ### GET PARAMETERS
' ###############################################################################
Dim PicWidth As Integer
Dim PicHeight As Integer
Dim Mode As Integer
Dim ModuleID As Integer
Dim Highlight As String
Dim MapFile As String
Dim DateTimeString As String
Dim freeid As Integer
Dim nonfreeid As Integer
Dim durtime As String
PicWidth = HttpContext.Current.Request("W") ' W=Width of the Pic in px
Mode = HttpContext.Current.Request("M") ' M=Mode (0=Guest, 1=Worker, 2=Admin)
ModuleID = HttpContext.Current.Request("mID") ' miD=Modul ID
Highlight = HttpContext.Current.Request("HL") ' HL=Highlight ...the coordinates/area to highlight (Format: Cx-yCx-y...)
MapFile = HttpContext.Current.Request("fID") ' FileID of the File that represents the Map-image
DateTimeString = HttpContext.Current.Request("DT") ' Show Free/NonFree Status of the tables for this Date/Time yyyMMdd_(h)hmm
freeid = HttpContext.Current.Request("f") ' FileID of the File that represents the Map-image
nonfreeid = HttpContext.Current.Request("nf") ' FileID of the File that represents the Map-image
durtime = HttpContext.Current.Request("du") ' Standard Duration of guest visits
' ###############################################################################
' ### DEFINE AND RESIZE THE BACKGROUND FOR THE MAP
' ###############################################################################
' get the path for the image from the FileID
Dim pid As Integer
pid = PortalController.GetCurrentPortalSettings.PortalId
Dim PathFile As String
Dim objFileController As New DotNetNuke.Services.FileSystem.FileController
Dim objFileInfo As DotNetNuke.Services.FileSystem.FileInfo = objFileController.GetFileById(MapFile, pid)
PathFile = objFileInfo.PhysicalPath
Dim Pic As Bitmap
Pic = Image.FromFile(PathFile)
Dim newImage As Bitmap
' ###############################################################################
' ### IMAGE RESIZING
' ###############################################################################
If PicWidth = 9999 Then
' do not resize the image
newImage = New Bitmap(Pic.Width, Pic.Height, Imaging.PixelFormat.Format24bppRgb)
newImage.SetResolution(Pic.HorizontalResolution, Pic.VerticalResolution)
Dim gr As Graphics = Graphics.FromImage(newImage)
gr.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
gr.DrawImage(Pic, New Rectangle(0, 0, Pic.Width, Pic.Height), New Rectangle(1, 1, Pic.Width - 1, Pic.Height - 1), GraphicsUnit.Pixel)
gr.Dispose()
Else
' Resize to:
Dim PicWidthOrig As Integer = Pic.Width
Dim PicHeightOrig As Integer = Pic.Height
PicHeight = PicWidth * PicHeightOrig / PicWidthOrig
newImage = New Bitmap(PicWidth, PicHeight, Imaging.PixelFormat.Format24bppRgb)
newImage.SetResolution(Pic.HorizontalResolution, Pic.VerticalResolution)
Dim gr As Graphics = Graphics.FromImage(newImage)
gr.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
gr.DrawImage(Pic, New Rectangle(0, 0, PicWidth, PicHeight), New Rectangle(1, 1, Pic.Width - 1, Pic.Height - 1), GraphicsUnit.Pixel)
gr.Dispose()
End If
Pic.Dispose()
' ###############################################################################
' ### PREPARE BACKGROUND FOR DRAWING
' ###############################################################################
Dim bmp As Object
bmp = New Bitmap(newImage)
Dim Graphic As Graphics = Graphics.FromImage(bmp)
ctx.Response.Clear()
ctx.Response.ContentType = "image/jpg"
ctx.Response.AddHeader("Content-Disposition", "inline;filename=map.jpg") 'Der virtuelle Dateiname des zurückgegebenen Bildes
' ###############################################################################
' DRAW OPTIONAL IMAGES FOR FREE/NOT FREE TABLES FOR ### U S E R S ###
' ###############################################################################
If Mode = 0 Or Mode = 1 Then
' *******************************************************
' *** Usermode or workermode interpret the parameters if sent
' *******************************************************
' ### DRAW THE ACTUAL REGION IF COORDS ARE PASSED
Dim SingleCoordinate(50) As String
SingleCoordinate = Split(Highlight, "C") 'Coordinates come in format: TableName x-y C x-y C x-y...)
Dim i, cX1, cY1 As Integer
Dim SplitCstart(1) As String
Dim SplitCend(1) As String
If Highlight <> "" Then
Dim NumberOfPoints As Integer
NumberOfPoints = SingleCoordinate.Length + 1
Dim points As System.Drawing.Point() = New Point(NumberOfPoints - 1) {}
' Read in the points
For i = 0 To SingleCoordinate.Length - 1
SplitCstart = Split(SingleCoordinate(i), "-")
cX1 = SplitCstart(0)
cY1 = SplitCstart(1)
points(i) = New Point(CInt(cX1), CInt(cY1))
Next
Dim penDOT1 As New Pen(Color.Black, 1)
penDOT1.DashPattern = New Single() {10.0F, 10.0F}
Dim pen2 As New Pen(Color.Gray, 1)
If SingleCoordinate.Length > 2 Then
'Set the closing point of the polygon to the first point
SplitCstart = Split(SingleCoordinate(0), "-")
cX1 = SplitCstart(0)
cY1 = SplitCstart(1)
points(NumberOfPoints - 1) = New Point(cX1, cY1)
' Fill the polygon
Dim brushColor As Color = Color.FromArgb(90, Color.White)
Dim shadowBrush As SolidBrush = New SolidBrush(brushColor)
Graphic.FillPolygon(shadowBrush, points)
shadowBrush.Dispose()
End If
If SingleCoordinate.Length > 2 Then
' draw the lines of the polygon
Graphic.DrawPolygon(pen2, points)
Graphic.DrawPolygon(penDOT1, points)
ElseIf SingleCoordinate.Length = 2 Then
' just draw a line
Graphic.DrawLine(pen2, points(0), points(1))
Else
' Set the crosshair on point 1
Dim HL(1) As String
Dim HLx, HLy As Integer
SplitCstart = Split(SingleCoordinate(0), "-")
HL = Split(Highlight, "-")
HLx = SplitCstart(0)
HLy = SplitCstart(1)
Dim penHL4 As New Pen(Color.Black, 1)
Dim penHL5 As New Pen(Color.Gray, 3)
'Yellow
Graphic.DrawLine(penHL4, HLx - 10, HLy, HLx - 2, HLy)
Graphic.DrawLine(penHL4, HLx + 10, HLy, HLx + 2, HLy)
Graphic.DrawLine(penHL4, HLx, HLy - 10, HLx, HLy - 2)
Graphic.DrawLine(penHL4, HLx, HLy + 10, HLx, HLy + 2)
'Red
Graphic.DrawLine(penHL5, HLx - 10, HLy, HLx - 2, HLy)
Graphic.DrawLine(penHL5, HLx + 10, HLy, HLx + 2, HLy)
Graphic.DrawLine(penHL5, HLx, HLy - 10, HLx, HLy - 2)
Graphic.DrawLine(penHL5, HLx, HLy + 10, HLx, HLy + 2)
penHL4.Dispose()
penHL5.Dispose()
End If
pen2.Dispose()
penDOT1.Dispose()
End If
' ### DRAW alternative images for blocked/not blocked tables in this timeframe
' DateTimeString holds the date and Time information to get the free/nonfree tables from the DB
' Check if there are images defined generally for blocked/not blocked tables
' get the FILEIDs and path for the Image files (imgFree, imgnotFree)
If DateTimeString > "" Then
' get the imagepath of the image
Dim objFileCont As New DotNetNuke.Services.FileSystem.FileController
Dim freePath As DotNetNuke.Services.FileSystem.FileInfo = objFileCont.GetFileById(freeid, pid)
Dim freePic As Bitmap = Image.FromFile(freePath.PhysicalPath)
' generate the images
Dim nonfreePath As DotNetNuke.Services.FileSystem.FileInfo = objFileCont.GetFileById(nonfreeid, pid)
Dim nonfreePic As Bitmap = Image.FromFile(nonfreePath.PhysicalPath)
' Get a List of defined Table-Regions from the DB (All defined Tables)
Dim obj_ResContr As New inu.Modules.inuReservation.inuReservationController
' Get a list of reservations and check if a table is free at the specified date/ time
' First just get reservations of the actual choosen date
Dim obj_TabInfo As List(Of inu.Modules.inuReservation.iR_TableInfo)
obj_TabInfo = obj_ResContr.GetTables(ModuleID)
Dim a As Integer = obj_TabInfo.Count - 1
Dim TableStatus(a) As Boolean
Dim TableIDs(a) As Integer
Dim ActTableID As Integer = 0
' Check each Table separately
For i = 0 To a
TableStatus(i) = True 'Set all Tables to free
Next
For Each Table In obj_TabInfo
TableIDs(ActTableID) = Table.ItemId
'Check if this table is free on this day/time
'Dim isFree As Boolean = True
Dim TheDateString As String
Dim TheCount As Integer
For i = 1 To 3
Dim TheResList As Object = Nothing
'Dim TheResList As New List(Of inu.Modules.inuReservation.iR_ReservationInfo)
Select Case i
Case 1 ' ###### Today check ######
TheDateString = Left(DateTimeString, 8)
'Dim ResListToDay As List(Of inu.Modules.inuReservation.iR_ReservationInfo)
TheResList = obj_ResContr.GetReservationsByDateAndTable(ModuleID, TheDateString, Table.ItemId)
TheCount = TheResList.Count
If TheCount > 0 Then ' There are Reservations for this table today - check if one of them confflicts with act Time
For Each item In TheResList
Dim ActualSelectionStart As String = Right(DateTimeString, 4)
'Calculate the End-Time of the actual userselection
Dim ActualSelectionEnd As String = TimeStringsAdd(ActualSelectionStart, durtime, 0)
'Calculate the End-Time of the reservation item to compare
Dim itemsEndTime As String = TimeStringsAdd(item.RTime, item.RDuration, 0)
Dim itemsStartTime As String = item.RTime
' If the ActualStartTime >= the items EndTime
' Or the ActualEndTime <= the Items Start Time
If Val(ActualSelectionStart) >= Val(itemsEndTime) Or Val(ActualSelectionEnd) <= Val(itemsStartTime) Then
' Then the table seems to be free on first sight - no conflict with this reservation
' But we have to check tomorrow morning and yesterday evening for conflicts too
'GoTo readyForNextDayCheck
Else
' There is an conflict with this reservation ... this table is definitely not free
' Exit and paint "nonfree"
TableStatus(ActTableID) = False
GoTo readyForNextTable
End If
Next
End If
Case 2 ' ' ###### Tomorrow check ######
Dim tempdate2 As Date
TheDateString = Right(Left(DateTimeString, 6), 2) & "/" & Right(Left(DateTimeString, 8), 2) & "/" & Left(DateTimeString, 4)
tempdate2 = Convert.ToDateTime(TheDateString)
tempdate2 = tempdate2.AddDays(1)
TheDateString = tempdate2.ToString("yyyyMMdd")
TheResList = obj_ResContr.GetReservationsByDateAndTable(ModuleID, TheDateString, Table.ItemId)
TheCount = TheResList.Count
If TheCount > 0 Then ' There are Reservations for this table today - check if one of them confflicts with act Time
For Each item In TheResList
Dim ActualSelectionStart As String = Right(DateTimeString, 4)
'Calculate the End-Time of the actual userselection
Dim ActualSelectionEnd As String = TimeStringsAdd(ActualSelectionStart, durtime)
'Calculate the End-Time of the reservation item to compare
Dim itemsEndTime As String = TimeStringsAdd(item.RTime, item.RDuration)
Dim itemsStartTime As String = item.RTime
If InStr(ActualSelectionEnd, "+") > 0 Then
' Only if the actual Selection floats to the next day
ActualSelectionEnd = Replace(ActualSelectionEnd, "+", "")
If Val(ActualSelectionEnd) <= Val(itemsStartTime) Then
' OK doesnt conflict with this reservationitem
' But eventually we have to check yesterday evening for conflicts too
'GoTo readyForNextDayCheck
Else
' There is an conflict with this reservation ... this table is definitely not free
' Exit and paint "nonfree"
TableStatus(ActTableID) = False
GoTo readyForNextTable
End If
End If
Next
End If
Case 3 ' ###### Yesterday check ######
Dim tempdate3 As Date
TheDateString = Right(Left(DateTimeString, 6), 2) & "/" & Right(Left(DateTimeString, 8), 2) & "/" & Left(DateTimeString, 4)
tempdate3 = Convert.ToDateTime(TheDateString)
tempdate3 = tempdate3.AddDays(-1)
TheDateString = tempdate3.ToString("yyyyMMdd")
TheResList = obj_ResContr.GetReservationsByDateAndTable(ModuleID, TheDateString, Table.ItemId)
TheCount = TheResList.Count
If TheCount > 0 Then ' There are Reservations for this table today - check if one of them confflicts with act Time
For Each item In TheResList
Dim ActualSelectionStart As String = Right(DateTimeString, 4)
'Calculate the End-Time of the actual userselection
Dim ActualSelectionEnd As String = TimeStringsAdd(ActualSelectionStart, durtime)
'Calculate the End-Time of the reservation item to compare
Dim itemsEndTime As String = TimeStringsAdd(item.RTime, item.RDuration)
Dim itemsStartTime As String = item.RTime
If InStr(itemsEndTime, "+") > 0 Then
' Only if yesterdays reservation item floats into today
itemsEndTime = Replace(itemsEndTime, "+", "")
If Val(itemsEndTime) <= Val(ActualSelectionStart) Then
' OK doesnt conflict with this reservationitem
' But eventually we have to check yesterday evening for conflicts too
'GoTo readyForNextDayCheck
Else
' There is an conflict with this reservation ... this table is definitely not free
' Exit and paint "nonfree"
TableStatus(ActTableID) = False
GoTo readyForNextTable
End If
End If
Next
End If
End Select
readyForNextDayCheck:
Next
readyForNextTable:
ActTableID = ActTableID + 1
Next
' All Tables processed
readyForPaint:
' all reservations checked
' --------------------------------------------------------------------------------
obj_TabInfo = obj_ResContr.GetTables(ModuleID)
'Dim TableStatus(a) As Boolean
'Dim TableIDs(a) As Integer
' Paint the icon for each Table separately
For i = 0 To a
For Each Table In obj_TabInfo
If Table.ItemId = TableIDs(i) Then
' found - set the icon corresponding to the status
Dim IconToDraw As Bitmap
If TableStatus(i) = True Then
IconToDraw = freePic ' the fileid for "free-Icon"
Else
IconToDraw = nonfreePic ' the fileid for "non-free-Icon"
End If
Dim TCoordinate(50) As String
TCoordinate = Split(Table.TCoords, "C") 'Coordinates come in format: x-y C x-y C x-y...)
' Calculate the middle point of the polygon to find the position to draw a alternative image for blocked/not blocked
Dim MiddleX As Integer = 0
Dim MiddleY As Integer = 0
For j = 0 To TCoordinate.Length - 1
SplitCstart = Split(TCoordinate(j), "-")
MiddleX = MiddleX + SplitCstart(0)
MiddleY = MiddleY + SplitCstart(1)
Next
MiddleX = MiddleX / TCoordinate.Length
MiddleY = MiddleY / TCoordinate.Length
' Calculate the offset x & y to position the image depending on its width
Dim coordX As Integer = MiddleX - (IconToDraw.Width / 2)
Dim CoordY As Integer = MiddleY - (IconToDraw.Height / 2)
' draw the image free/not free
Graphic.DrawImage(IconToDraw, CInt(coordX), CInt(CoordY))
End If
Next
Next
End If
ElseIf Mode = 2 Then
' *******************************************************
' *** Admin mode
' *******************************************************
' ### SHOW THE ALREADY DEFINED REGIONS IN DB FOR ### A D M I N S ###
' Get a List of defined Table-Regions from the DB
Dim obj_TableContr As New inu.Modules.inuReservation.inuReservationController
Dim TableList As List(Of inu.Modules.inuReservation.iR_TableInfo)
TableList = obj_TableContr.GetTables(ModuleID)
' Draw the defined regions and paint them semi transparent
' Get the Coordinates from the DB
For Each lstItem In TableList
Dim SingleCoordinate(50) As String
SingleCoordinate = Split(lstItem.TCoords, "C") 'Coordinates come in format: x-y C x-y C x-y...)
' Split the Coordinates to single Coordinates
If SingleCoordinate(0) = "" Then
' No coordinates ... nothing to draw
Else
Dim i, cX1, cY1 As Integer
Dim SplitCstart(1) As String
Dim SplitCend(1) As String
Dim NumberOfPoints As Integer
NumberOfPoints = SingleCoordinate.Length + 1
Dim points As System.Drawing.Point() = New Point(NumberOfPoints - 1) {}
' Read in the points
For i = 0 To SingleCoordinate.Length - 1
SplitCstart = Split(SingleCoordinate(i), "-")
cX1 = SplitCstart(0)
cY1 = SplitCstart(1)
points(i) = New Point(CInt(cX1), CInt(cY1))
Next
Dim penDOT1 As New Pen(Color.Black, 1)
penDOT1.DashPattern = New Single() {10.0F, 10.0F}
Dim pen2 As New Pen(Color.Gray, 1)
If SingleCoordinate.Length > 2 Then
'Set the closing point of the polygon to the first point
SplitCstart = Split(SingleCoordinate(0), "-")
cX1 = SplitCstart(0)
cY1 = SplitCstart(1)
points(NumberOfPoints - 1) = New Point(cX1, cY1)
' Fill the polygon
Dim brushColor As Color = Color.FromArgb(90, Color.White)
Dim shadowBrush As SolidBrush = New SolidBrush(brushColor)
Graphic.FillPolygon(shadowBrush, points)
End If
If SingleCoordinate.Length > 2 Then
' draw the lines of the polygon
Graphic.DrawPolygon(pen2, points)
Graphic.DrawPolygon(penDOT1, points)
ElseIf SingleCoordinate.Length = 2 Then
' just draw a line
Graphic.DrawLine(pen2, points(0), points(1))
Else
' Set the crosshair on point 1
Dim HL(1) As String
Dim HLx, HLy As Integer
SplitCstart = Split(SingleCoordinate(0), "-")
HL = Split(Highlight, "-")
HLx = SplitCstart(0)
HLy = SplitCstart(1)
Dim penHL2 As New Pen(Color.Black, 1)
Dim penHL3 As New Pen(Color.Gray, 3)
'Yellow
Graphic.DrawLine(penHL3, HLx - 10, HLy, HLx - 2, HLy)
Graphic.DrawLine(penHL3, HLx + 10, HLy, HLx + 2, HLy)
Graphic.DrawLine(penHL3, HLx, HLy - 10, HLx, HLy - 2)
Graphic.DrawLine(penHL3, HLx, HLy + 10, HLx, HLy + 2)
'Red
Graphic.DrawLine(penHL2, HLx - 10, HLy, HLx - 2, HLy)
Graphic.DrawLine(penHL2, HLx + 10, HLy, HLx + 2, HLy)
Graphic.DrawLine(penHL2, HLx, HLy - 10, HLx, HLy - 2)
Graphic.DrawLine(penHL2, HLx, HLy + 10, HLx, HLy + 2)
penHL2.Dispose()
penHL3.Dispose()
pen2.Dispose()
penDOT1.Dispose()
End If
End If
Next
' ### DRAW THE ACTUAL REGION IF COORDS ARE PASSED
If Highlight <> "" Then
Dim SingleCoordinate(50) As String
SingleCoordinate = Split(Highlight, "C") 'Coordinates come in format: TableName x-y C x-y C x-y...)
Dim i, cX1, cY1 As Integer
Dim SplitCstart(1) As String
Dim SplitCend(1) As String
Dim NumberOfPoints As Integer
NumberOfPoints = SingleCoordinate.Length + 1
Dim points As System.Drawing.Point() = New Point(NumberOfPoints - 1) {}
' Read in the points
For i = 0 To SingleCoordinate.Length - 1
SplitCstart = Split(SingleCoordinate(i), "-")
cX1 = SplitCstart(0)
cY1 = SplitCstart(1)
points(i) = New Point(CInt(cX1), CInt(cY1))
Next
Dim penDOT1 As New Pen(Color.Red, 1)
penDOT1.DashPattern = New Single() {10.0F, 10.0F}
Dim pen2 As New Pen(Color.Yellow, 1)
If SingleCoordinate.Length > 2 Then
'Set the closing point of the polygon to the first point
SplitCstart = Split(SingleCoordinate(0), "-")
cX1 = SplitCstart(0)
cY1 = SplitCstart(1)
points(NumberOfPoints - 1) = New Point(cX1, cY1)
' Fill the polygon
Dim brushColor As Color = Color.FromArgb(90, Color.Yellow)
Dim shadowBrush As SolidBrush = New SolidBrush(brushColor)
Graphic.FillPolygon(shadowBrush, points)
shadowBrush.Dispose()
End If
If SingleCoordinate.Length > 2 Then
' draw the lines of the polygon
Graphic.DrawPolygon(pen2, points)
Graphic.DrawPolygon(penDOT1, points)
ElseIf SingleCoordinate.Length = 2 Then
' just draw a line
Graphic.DrawLine(pen2, points(0), points(1))
Else
' Set the crosshair on point 1
Dim HL(1) As String
Dim HLx, HLy As Integer
SplitCstart = Split(SingleCoordinate(0), "-")
HL = Split(Highlight, "-")
HLx = SplitCstart(0)
HLy = SplitCstart(1)
Dim penHL2 As New Pen(Color.Red, 1)
Dim penHL3 As New Pen(Color.Yellow, 3)
'Yellow
Graphic.DrawLine(penHL3, HLx - 10, HLy, HLx - 2, HLy)
Graphic.DrawLine(penHL3, HLx + 10, HLy, HLx + 2, HLy)
Graphic.DrawLine(penHL3, HLx, HLy - 10, HLx, HLy - 2)
Graphic.DrawLine(penHL3, HLx, HLy + 10, HLx, HLy + 2)
'Red
Graphic.DrawLine(penHL2, HLx - 10, HLy, HLx - 2, HLy)
Graphic.DrawLine(penHL2, HLx + 10, HLy, HLx + 2, HLy)
Graphic.DrawLine(penHL2, HLx, HLy - 10, HLx, HLy - 2)
Graphic.DrawLine(penHL2, HLx, HLy + 10, HLx, HLy + 2)
penHL2.Dispose()
penHL3.Dispose()
End If
pen2.Dispose()
penDOT1.Dispose()
End If
Else
' *******************************************************
' should not happen, but if ... then its an error because it only exists mode 0 1 and 2
' *******************************************************
End If
' ###############################################################################
' ### GIVE BACK THE FINISHED IMAGE
' ###############################################################################
bmp.Save(ctx.Response.OutputStream, ImageFormat.Jpeg)
Graphic.Dispose()
bmp.Dispose()
ctx.Response.End()
End Sub
' Math Functions for Timestrings
Private Function TimeStringsAdd(ByVal T1 As String, ByVal T2 As String, Optional ByVal ShowPlusMinus As Integer = 1) As String
Dim result As String
Dim t1H, t2H, t1M, t2M As String
If Len(T1) < 4 Then
t1H = Left(T1, 1)
Else
t1H = Left(T1, 2)
End If
If Len(T2) < 4 Then
t2H = Left(T2, 1)
Else
t2H = Left(T2, 2)
End If
t1M = Right(T1, 2)
t2M = Right(T2, 2)
Dim hours_i As Integer = CInt(t1H) + CInt(t2H)
Dim minutes_i As Integer = CInt(t1M) + CInt(t2M)
Dim hours As String
Dim minutes As String
If minutes_i >= 60 Then
hours_i = hours_i + 1
minutes_i = minutes_i - 60
End If
If hours_i < 10 Then
hours = "0" & CType(hours_i, String)
Else
hours = CType(hours_i, String)
End If
If minutes_i < 10 Then
minutes = "0" & CType(minutes_i, String)
Else
minutes = CType(minutes_i, String)
End If
If ShowPlusMinus = 1 Then
If hours >= 24 And minutes > 0 Then
' this time is on the next day
hours = hours - 24
result = "+" & hours & minutes
Else
result = hours & minutes
End If
Else
result = hours & minutes
End If
Return result
End Function
Private Function TimeStringsSubtract(ByVal T1 As String, ByVal T2 As String) As String
Dim result As String
Dim t1H, t2H, t1M, t2M As String
If Len(T1) < 4 Then
t1H = Left(T1, 1)
Else
t1H = Left(T1, 2)
End If
If Len(T2) < 4 Then
t2H = Left(T2, 1)
Else
t2H = Left(T2, 2)
End If
t1M = Right(T1, 2)
t2M = Right(T2, 2)
Dim hours_i As Integer = CInt(t1H) - CInt(t2H)
Dim minutes_i As Integer = CInt(t1M) - CInt(t2M)
Dim hours As String
Dim minutes As String
If minutes_i < 0 Then
hours_i = hours_i - 1
minutes_i = minutes_i + 60
End If
If hours_i < 10 And hours_i >= 0 Then
hours = "0" & CType(hours_i, String)
Else
hours = CType(hours_i, String)
End If
If minutes_i < 10 Then
minutes = "0" & CType(minutes_i, String)
Else
minutes = CType(minutes_i, String)
End If
If hours < 0 And minutes > 0 Then
' this time is on the previous day
hours = hours + 24
result = "-" & hours & minutes
Else
result = hours & minutes
End If
Return result
End Function
Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
Return False
End Get
End Property
End Class