I have a function that I want to call from several pages so I want to write it once, call it several times. How do I do this - someone suggested creating a file functions.aspx and then including it but it didn't work
Code:
Private Function HaveSerials(ByVal First As Int64, ByVal Last As Int64, ByVal Type As String, ByVal Category As String, ByVal Owner As Int64) As Boolean
'This function checks to see if the items requested to transfer are actually in the possession of the
'Transfer Vendor.
'It counts the number of items returned from the select and the number of items if all were available
'If they match then the Transfer Vendor has them all.
'This means that the user cannot ask for serials 1-10 knowing that 9 is unavailable. They
'must ask for items 1-8, 10-10 in 2 separate transfers.
Dim connStr As String = ConfigurationManager.ConnectionStrings("buspassconnectionstring").ConnectionString
Dim conn As New SqlConnection(connStr)
Dim cmd As New SqlCommand("Select count(*) as num_returned from item where Condition = 'Sellable' and Type = '" & Type & "' and Category ='" & Category & "' and Serial_Number between " & First & " and " & Last & " and Owner = " & Owner, conn)
Dim rdr As SqlDataReader
Dim number As Int32
Try
conn.Open()
rdr = cmd.ExecuteReader
rdr.Read()
If Not IsDBNull(rdr("num_returned")) Then
number = rdr("num_returned")
Else
number = 0
End If
rdr.Close()
conn.Close()
Catch
number = 0
End Try
If number = Last - First + 1 Then
HaveSerials = True
Else
HaveSerials = False
End If
End Function