%
dim Lat1, Long1, Lat2, Long2
Set DataRec = Server.CreateObject("ADODB.RecordSet")
Set DataRec0 = Server.CreateObject("ADODB.RecordSet")
Set DataRec1 = Server.CreateObject("ADODB.RecordSet")
function GetZipList(zipcode,mileage)
tempZip = ""
ZipList = ""
if zipcode = "" then zipcode = "00000"
' response.write zipcode
zipleft = left(zipcode,2) * 1000 - 2000
zipright = left(zipcode,2) * 1000 + 2000
sError = GetLatLong(zipcode,"1")
strSQL = "Select top 5000 zipcode from distributor where (zipcode >= '"&zipleft&"' and zipcode <= '"&zipright&"') and not zipcode = '' order by zipcode desc"
' response.write strsql
DataRec0.Open strSQL, DataConn
do while not DataRec0.eof
zipcode2 = trim(DataRec0("zipcode"))
sError = GetLatLong(zipcode2,"2")
distance = GetDistance(Lat1, Long1, Lat2, Long2, "M")
if cdbl(distance) <= cdbl(mileage) and instr(ZipList,zipcode2)=0 and cdbl(distance) >= 0 then
ZipList = ZipList & "," & "'" & zipcode2 & "'"
end if
DataRec0.movenext
loop
DataRec0.close
if ZipList = "" then ZipList = "00000"
GetZipList = right(ZipList,len(ZipList)-1)
end function
function GetLatLong(zipcode,ziptype)
strSQL = "Select longitude,latitude from Zipcode where zipcode = '"&zipcode&"' "
DataRec1.Open strSQL, DataConn
if not DataRec1.eof then
if ziptype = "1" then
Lat1 = trim(DataRec1("longitude"))
Long1 = trim(DataRec1("latitude"))
else
Lat2 = trim(DataRec1("longitude"))
Long2 = trim(DataRec1("latitude"))
end if
else
if ziptype = "1" then
Lat1 = 0
Long1 = 0
else
Lat2 = 0
Long2 = 0
end if
end if
DataRec1.close
end function
function GetDistance(Lat1, Long1, Lat2, Long2, Unit)
pi = 3.14159265358979323846
x = (sin(DegToRads(Lat1)) * sin(DegToRads(Lat2)) + cos(DegToRads(Lat1)) * cos(DegToRads(Lat2)) * cos(abs((DegToRads(long2))-(DegToRads(long1)))))
x = atn((sqr(1-x^2))/x)
GetDistance = 1.852 * 60.0 * ((x/pi)*180)
select case ucase(Unit)
case "M"
GetDistance = GetDistance / 1.609344
case "N"
GetDistance = GetDistance / 1.852
end select
' response.write "Lat1 = "& Lat1 &" Long1 = "& long1 & " Lat2 = "& Lat2 & " Long2 = "& long2 & " ----- distance = "& GetDistance & "
"
end function
function DegToRads(Deg)
pi = 3.14159265358979323846
DegToRads = cdbl(Deg * pi / 180)
end function
'sURL = Request.ServerVariables("HTTP_REFERER")
'sURL = mid(sURL,instrrev(sURL,"/")+1,len(sURL))
page=request("page")
if page="" or not isNumeric(page) then page=1
iPageSize = 24
if request("allpage")="on" then iPageSize = 99999
iPageCurrent=cint(page)
searchflag=request("searchflag")
group=request("group")
zipcode=request("zipcode")
mileage = request("mileage")
city = request("city")
state = request("state")
productno = request("productno")
if mileage = "" or isNull(mileage) or not isNumeric(mileage) then mileage = 5
if zipcode = "" or isNull(zipcode) or not isNumeric(zipcode) then zipcode = ""
info="group="&group&"&zipcode="&zipcode&"&mileage="&mileage&"&productno="&productno&"&state="&state&"&searchflag="&searchflag
sTableName = "distributor"
strSQL = "SELECT * FROM " &sTableName& " where (category like '%"&group&"%' or category is null) and Store_NO='"&session("store_NO")&"' order by indexno,Company"
if searchflag = "zipcode" then
if isNumeric(zipcode) then
zip=left(zipcode,3)
sSearchForList = GetZipList(zipcode,Mileage)
strSQL = "SELECT * FROM " &sTableName& " where (category like '%"&group&"%' or category is null) and Store_NO='"&session("store_NO")&"' "
strSQL = strSQL & "and zipcode in ("& sSearchForList &") "
strSQL = strSQL & "order by indexno,city,Company"
end if
end if
if searchflag = "state" then
strSQL = "SELECT * FROM " &sTableName& " where (category like '%"&group&"%' or category is null) and Store_NO='"&session("store_NO")&"' "
strSQL = strSQL & "and state like '%" & state & "%' "
strSQL = strSQL & "order by indexno,city,Company"
'response.write strSQL
end if
if searchflag = "city" then
strSQL = "SELECT * FROM " &sTableName& " where (category like '%"&group&"%' or category is null) and Store_NO='"&session("store_NO")&"' "
strSQL = strSQL & "and city like '%" & city & "%' and state like '%" & state & "%' "
strSQL = strSQL & "order by indexno,city,Company"
end if
if searchflag = "productno" then
strSQL = "SELECT distributor.* FROM distributor inner join product_distributor on product_distributor.distributor_no = distributor.distributor_no "
strSQL = strSQL & "where (distributor.category like '%"&group&"%' or distributor.category is null) and distributor.Store_NO='"&session("store_NO")&"' "
strSQL = strSQL & "and product_distributor.product_no like '%" & productno & "%' and distributor.state like '%" & state & "%' "
strSQL = strSQL & "order by distributor.indexno,distributor.city,distributor.Company"
end if
'response.write strSQL
DataRec.PageSize = iPageSize
DataRec.CacheSize = iPageSize
DataRec.Open strSQL, DataConn, adOpenStatic, adLockReadOnly, adCmdText
iPageCount = DataRec.PageCount
iRecordCount = DataRec.RecordCount
if request("allpage")="on" then iPageSize = iRecordCount
if iPageCurrent > iPageCount then iPageCurrent = iPageCount
if iPageCurrent < 1 then iPageCurrent = 1
%>
|
|
|
|
STORE LOCATOR
<%
if not iPageCount = 0 then
DataRec.AbsolutePage = iPageCurrent
else
%>
Sorry, we can not locate the store you searched for. Please try again. |
<%
'response.redirect "javascript:history.go(-1)"
'response.end
end if
%>
<%
if not iPageCount = 0 then DataRec.AbsolutePage = iPageCurrent
iRecordsShown = 0
iColumn=0
bgcolor="EBD996"
Do While iRecordsShown < iPageSize And Not DataRec.EOF
CATEGORY=trim(Datarec("CATEGORY"))
COMPANY=trim(Datarec("COMPANY"))
CONTACT=trim(Datarec("CONTACT"))
ADDRESS=trim(Datarec("ADDRESS"))
CITY=trim(Datarec("CITY"))
STATE=trim(Datarec("STATE"))
COUNTRY=trim(Datarec("COUNTRY"))
ZIPCODE=trim(Datarec("ZIPCODE"))
TEL=trim(Datarec("TEL"))
FAX=trim(Datarec("FAX"))
EMAIL=trim(Datarec("EMAIL"))
OPENHOUR=trim(Datarec("OPENHOUR"))
%>
<%=company%>
<% if not address = "" then %>
<%=address%>
<%end if%>
<% if not city = "" then %>
<%=city%>, <%=state%> <%=zipcode%>
<%=country%>
<%end if%>
Tel: <%=tel%>
<% if not fax = "" then %>
Fax: <%=fax%>
<%end if%>
<% if not email = "" then %>
e-Mail: <%=email%>
<%end if%>
<% if not contact = "" then %>
Contact: <%=contact%>
<%end if%>
<% if not address = "" then %>
View Map
<% end if %>
<% if not OPENHOUR = "" then %>
Store Hours:
<%=OPENHOUR%>
<% end if %>
|
<%
DataRec.MoveNext
iRecordsShown = iRecordsShown + 1
iColumn=iColumn+1
if iColumn mod 2 = 0 then response.write " "
bgcolor=""
if iColumn mod 4 = 0 or iColumn mod 4 = 1 then bgcolor="EBD996"
loop
DataRec.Close
Set DataRec = Nothing
%>
|
|
|
|
|
|
|
|