<% '===================================================================================== ' Objective: Search engine for Elita's Store ' Date: 26/Nov/2k1 ' Functionality requirement: ' 1. Ability to locate the store by AreaCode, City and/or ZipCode/Postal Code ' 2. Ability to deduct the searching parameter key by (2.1 and/or 2.2) until NOT EOF ' 2.1 sCity = cityTXT - 1 right char ' 2.2 sZipCode = zipTXt - 1 right char ' 3. AreaCode is specific parameter. Result in FOUND or NOT FOUND IFF len(City&Zip)<=0 ' 4. Result for "City matches" must have only unique cities found ' Note: ' Update from 27/Nov/2k1 - AreaCode search parameter is no longer required. ' Update 11/Sep/2k2 - validate non alpha searching parameters for city/zip. ' Fix code 16/Oct/2k2 - removal of option unable to locate the city. Revised by ' loading back old code and fix display. '===================================================================================== %> Elita Stores Search <% dim sAreaCode dim sCity dim sZipCode dim iCnt, iCntMAX dim sSELVal1, sSELVal2, sSELVal3 dim ConnPress dim RSPress dim sCollection dim sShipToName dim strSQLCT, strSQLZC iCnt = 0 ' iCntMAX = cint(Request.Form("locVALUE")) iCntMAX = 999 ' select case iCntMAX ' case 1 ' sSELVal1 = " selected " ' case 2 ' sSELVal2 = " selected " ' case 3 ' sSELVal3 = " selected " ' case else ' sSELVal3 = " selected " ' end select sAreaCode = trim(Request.Form("areaTXT")) sCity = trim(Request.Form("cityTXT")) sZipCode = trim(Request.Form("zipTXT")) sBoolean = trim(Request.Form("RADIOboolean")) sCityQuery = trim(Request.QueryString("sCityQ")) sStateQuery = trim(Request.QueryString("sStateQ")) sZipQuery = trim(Request.QueryString("sZipQ")) qsBoolean = trim(Request.QueryString("qsBoolean")) 'Response.Write( "sAreaCode:" & sAreaCode & "
") 'Response.Write( "sCity:" & sCity & "
") 'Response.Write( "sZipCode:" & sZipCode & "
") 'Response.Write( "sCityQuery:" & sCityQuery & "
") 'Response.Write( "sStateQuery:" & sStateQuery & "
") 'Response.Write( "sZipQuery:" & sZipQuery & "
") if iCntMAX <= 0 then iCntMAX = 1 end if if len(sCity) <= 0 then sCity = sCityQuery end if if len(sZipCode) <= 0 then sZipCode = sZipQuery end if if len(sBoolean) <= 0 then sBoolean = qsBoolean end if if (len(sBoolean) <= 0) and (len(qsBoolean) <= 0) then sBoolean = "OR" end if %>
    Search for a retailer by City
  City:
<% if len(trim(Request.QueryString("MSG")))>0 then Response.Write("

You have exceeded your search limit for today. Please come back and try again tomorrow.

") %> <% end if %> <% strSQLCT = "" strSQLZC = "" 'Response.Write("C:" & sCity & " Z:" & sZipCode & "
") if (len(trim(sAreaCode))>0 or len(trim(sCity))>0 or len(trim(sZipCode))>0) then if len(trim(sCity))>0 then strSQLCT = " where (City like '" & replace(sCity,"'","''") & "%' " end if if len(trim(sZipCode))>0 and len(trim(sCity))>0 then 'strSQLZC = strSQLCT & " or Zip like '" & replace(sZipCode,"'","''") & "%'" 'sBoolean strSQLZC = strSQLCT & " " & sBoolean & " Zip like '" & replace(sZipCode,"'","''") & "%') " else if len(trim(sZipCode))>0 then strSQLZC = " where (Zip like '" & replace(sZipCode,"'","''") & "%') " else strSQLZC = strSQLCT & ")" end if end if 'strSQL = "select * from tStoreLocations " & strSQLZC & " order by City, Zip asc" strSQL = "select distinct City, State from tStoreLocations " & strSQLZC 'Response.Write( strSQL ) 'Response.Write ( cstr(iCntMAX)) Set ConnPress = Server.CreateObject("ADODB.Connection") ConnPress.Open "Provider=MSDASQL;Driver={SQL Server}; Server=cove.safesecureweb.com; Database=devElita01;uid=dbelita;pwd=iNc0gnito" Set RSPress = Server.CreateObject("ADODB.Recordset") RSPress.Open strSQL,ConnPress,1,3 %>
    City matches
<% 'Display the group based on city If NOT RSPress.EOF Then Response.Write "" RSPress.MoveFirst iCnt = 0 sCityLast = "" maxrecs = RSPress.RecordCount Response.Write("

") While NOT RSPress.EOF 'sShipToName=trim(RSPress.Fields("ShipToName")) 'sAddr1=trim(RSPress.Fields("Addr1")) 'sAddr2=trim(RSPress.Fields("Addr2")) sCity=trim(RSPress.Fields("City")) sState=trim(RSPress.Fields("State")) 'sZip=trim(RSPress.Fields("Zip")) sZip = trim(sZipCode) if sCity <> sCityLast then sCityLast = sCity if (iCnt < iCntMAX) then 'Response.Write( cstr(iCnt+1) & ". " & sCity & ", " & sState & "," & sZip & "
" ) 'Response.Write( cstr(iCnt+1) & ". " & sCity & ", " & sState & "," & sZip & "
" ) 'if len(sZip) > 0 then ' Response.Write( cstr(iCnt+1) & ". " & sCity & ", " & sState & "," & sZip & "
" ) 'else Response.Write( cstr(iCnt+1) & ". " & sCity & ", " & sState & "
" ) nextpage = "" 'end if end if iCnt = iCnt + 1 end if RSPress.MoveNext Wend Response.Write("

") RSPress.MoveFirst Response.Write "
" else 'Response.Write("The system is unable to locate your city.
") 'Response.Write("Please fill in the form below for us to locate the store nearest to you.
Thank you.") %>

The system was unable find a match for your city. Please fill in the customer support to request a manual search for locate the store nearest to you. Thank you.

<% end if RSPress.Close ConnPress.Close end if %> <% 'Determine if search by city or store if len(sCityQuery) > 0 then %>
    Store matches <% Response.Write nextpage & "View More Choices" & "" %>
<% if len(trim(Request.QueryString("MSG"))) <= 0 then %> <% ' Display all that of rank = 50 strSQL = "select * from tStoreLocations " & strSQLZC & " and rank = '50'" strSQLCnt = "select count(*) as MaxCnt from tStoreLocations " & strSQLZC & " and rank = '50'" strSQLRank = "select * from tStoreLocationsRank where sRank = '50'" 'Response.Write (strSQL) 'Response.Write (strSQLCnt) Set ConnPress = Server.CreateObject("ADODB.Connection") ConnPress.Open "Provider=MSDASQL;Driver={SQL Server}; Server=cove.safesecureweb.com; Database=devElita01;uid=dbelita;pwd=iNc0gnito" Set RSPress = Server.CreateObject("ADODB.Recordset") RSPress.Open strSQL,ConnPress,1,3 Set RSPressCnt = Server.CreateObject("ADODB.Recordset") RSPressCnt.Open strSQLCnt,ConnPress,1,3 MaxCnt = RSPressCnt.Fields("MaxCnt").Value Set RSPressRank = Server.CreateObject("ADODB.Recordset") RSPressRank.Open strSQLRank,ConnPress,1,3 MaxRank = trim(RSPressRank.Fields("nMaxMatch").Value) if isnumeric(MaxCnt) then MaxCnt = clng(MaxCnt) else MaxCnt = 0 end if 'Display the result If NOT RSPress.EOF Then RSPress.MoveFirst iCnt = 1 arrIndex = clng(MaxRank) iNumFound = 1 if MaxCnt < arrIndex then arrIndex = MaxCnt end if redim arrRND(arrIndex+1) for i=1 to arrIndex bLoopNext = true while bLoopNext Randomize ' Initialize random-number generator. RndV1 = clng( ((MaxCnt-1) * Rnd) + 1 ) found = false j=1 while (not found) and (j<=i) for j=1 to i if arrRND(j)=RndV1 then found = true exit for end if next wend if not found then arrRND(i) = RndV1 bLoopNext = false else bLoopNext = true end if wend next 'for i=1 to arrIndex ' Response.Write( arrRND(i) & ":" ) 'next 'Response.Write("
") While NOT RSPress.EOF sShipToName=trim(RSPress.Fields("ShipToName")) sRank=trim(RSPress.Fields("Rank")) sAddr1=trim(RSPress.Fields("Addr1")) sAddr2=trim(RSPress.Fields("Addr2")) sCity=trim(RSPress.Fields("City")) sState=trim(RSPress.Fields("State")) sZip=trim(RSPress.Fields("Zip")) for i=1 to arrIndex if (arrRND(i) = clng(iCnt))then 'Response.Write( "

" & sShipToName & " Rank(" & sRank & ")
" ) Response.Write "" Response.Write( "

" & sShipToName & "
" ) Response.Write( "" & sAddr1 & "
" ) Response.Write( "" & sCity & ", " & sState & "," & sZip & "
" ) Response.Write "
" exit for end if next iCnt = iCnt + 1 RSPress.MoveNext wend end if RSPress.Close ConnPress.Close %> <% ' Display all that of rank = 10 strSQL = "select * from tStoreLocations " & strSQLZC & " and rank = '10'" strSQLCnt = "select count(*) as MaxCnt from tStoreLocations " & strSQLZC & " and rank = '10'" strSQLRank = "select * from tStoreLocationsRank where sRank = '10'" 'Response.Write (strSQL) 'Response.Write (strSQLCnt) Set ConnPress = Server.CreateObject("ADODB.Connection") ConnPress.Open "Provider=MSDASQL;Driver={SQL Server}; Server=cove.safesecureweb.com; Database=devElita01;uid=dbelita;pwd=iNc0gnito" Set RSPress = Server.CreateObject("ADODB.Recordset") RSPress.Open strSQL,ConnPress,1,3 Set RSPressCnt = Server.CreateObject("ADODB.Recordset") RSPressCnt.Open strSQLCnt,ConnPress,1,3 MaxCnt = RSPressCnt.Fields("MaxCnt").Value Set RSPressRank = Server.CreateObject("ADODB.Recordset") RSPressRank.Open strSQLRank,ConnPress,1,3 MaxRank = trim(RSPressRank.Fields("nMaxMatch").Value) if isnumeric(MaxCnt) then MaxCnt = clng(MaxCnt) else MaxCnt = 0 end if 'Display the result If NOT RSPress.EOF Then RSPress.MoveFirst iCnt = 1 arrIndex = clng(MaxRank) iNumFound = 1 if MaxCnt < arrIndex then arrIndex = MaxCnt end if redim arrRND(arrIndex+1) for i=1 to arrIndex bLoopNext = true while bLoopNext Randomize ' Initialize random-number generator. RndV1 = clng( ((MaxCnt-1) * Rnd) + 1 ) found = false j=1 while (not found) and (j<=i) for j=1 to i if arrRND(j)=RndV1 then found = true exit for end if next wend if not found then arrRND(i) = RndV1 bLoopNext = false else bLoopNext = true end if wend next 'for i=1 to arrIndex ' Response.Write( arrRND(i) & ":" ) 'next 'Response.Write("
") While NOT RSPress.EOF sShipToName=trim(RSPress.Fields("ShipToName")) sRank=trim(RSPress.Fields("Rank")) sAddr1=trim(RSPress.Fields("Addr1")) sAddr2=trim(RSPress.Fields("Addr2")) sCity=trim(RSPress.Fields("City")) sState=trim(RSPress.Fields("State")) sZip=trim(RSPress.Fields("Zip")) for i=1 to arrIndex if (arrRND(i) = clng(iCnt))then 'Response.Write( "

" & sShipToName & " Rank(" & sRank & ")
" ) Response.Write "" Response.Write( "

" & sShipToName & "
" ) Response.Write( "" & sAddr1 & "
" ) Response.Write( "" & sCity & ", " & sState & "," & sZip & "
" ) Response.Write "
" exit for end if next iCnt = iCnt + 1 RSPress.MoveNext wend end if RSPress.Close ConnPress.Close %> <% else Response.Write("

You have exceeded your search limit for today. Please come back to visit our store tomorrow. Thankyou.

") %>
    Store matches <% Response.Write nextpage & "More" & "" %>
<% end if %> <% end if %>