Hej!
Här kommer hela scrpitet...
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<% Option Explicit %>
<%session.lcid=1053%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Kundvagn</title>
<link href="../Stylesheet/stylemainFrame.css" rel="stylesheet" type="text/css">
</head>
<body>
<%
Dim objConn, strSearchField, strSQL, objRS, intCounter, objDict, strEnumber, strArticleName, strUnit, strSupplier, curPrice, strFC, strLowest, strLastENumber, strLastSupplier, objPricesDict, strOrder, bgcolor, strOption, strShow, lngTotalStorel, lngTotalSolar
If session("userId") <> "" Then
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.ConnectionString = "DSN=IntranetSydostel"
objConn.Open
strSQL = "SELECT tblArticle.articleName, tblArticle.articleUnit, tblCart.userId, tblCart.quantity, tblDiscount.articleDiscount, tblPrice.articlePrice, tblSupplier.SupplierName, tblArticle.eNumber FROM (((tblArticle INNER JOIN tblCart ON tblArticle.eNumber = tblCart.eNumber) INNER JOIN tblPrice ON tblArticle.eNumber = tblPrice.eNumber) INNER JOIN tblDiscount ON tblPrice.articleCategory = tblDiscount.articleCategory) INNER JOIN tblSupplier ON tblPrice.articleSupplierId = tblSupplier.SupplierId WHERE tblCart.userId = " & session("userId") & " ORDER BY tblArticle.eNumber, tblPrice.articlePrice ASC"
lngTotalStorel = 0
lngTotalSolar = 0
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open strSQL, objConn, 3, 1 ' Recordsetet öppnar vi så här för att kunna få ut ett värde från egenskapen recordcount.
intCounter = 0 ' skapa en liten posträknare som vi sedan räknar upp
Set objDict = Server.CreateObject("Scripting.Dictionary") 'ett dictionaryobjekt
If objRS.EOF then
Response.Write("<span class=""text"">Kundvagnen är tom!</span><br>")
Else
Response.Write("<span class=""text"">Följande artiklar finns i kundvagnen:</span><br><br>")
Response.write "<table width=""690"" border=""0"" cellspacing=""0"" cellpadding=""0""><tr class=""tabellhuvud""><td width=""60"" height=""18"" class=""tabellhuvud"">E-nr</td><td width=""250"" class=""tabellhuvud"">Benämning</td><td width=""45"" class=""tabellhuvud"">Enhet</td><td width=""75"" class=""tabellhuvud"">Solar</td><td width=""75"" class=""tabellhuvud"">Storel</td><td width=""75"" class=""tabellhuvud"">Ahlsell</td><td width=""60"" class=""tabellhuvud"">Lägst</td><td width=""50"" class=""tabellhuvud"">ta bort</td></tr>"
Do While not objRS.EOF
strENumber = "" & objRS("ENumber")
strArticleName = "" & objRS("articleName")
strUnit = "" & objRS("articleUnit")
strSupplier = "" & objRS("SupplierName")
'If strShow = "avtal" then
'curPrice = "" & FormatCurrency(Cdbl(objRS("articlePriceWithDiscount")))
' End If
'If strShow = "netto" then
curPrice = "" & FormatCurrency(Cdbl(objRS("articlePrice"))*0.01)
'End If
Select case strSupplier
Case "Storel"
lngTotalStorel = lngTotalStorel + CLng(objRS("articlePrice")*0.01)
Case "Solar"
lngTotalSolar = lngTotalSolar + CLng(objRS("articlePrice")*0.01)
End Select
if strENumber <> strLastEnumber then
if intCounter <> 0 then
' aha, här har det gjorts saker förut. Skicka iväg till utskriftsfunktionen.
' markering av det jättesunkiga priset
objDict.Item(strLastSupplier) = Replace(objDict.Item(strLastSupplier), "black", "red")
call writePrices(objDict)
objDict.RemoveAll
end if
set objDict = Server.CreateObject("Scripting.Dictionary")
objDict.Add "eNumber", strENumber
objDict.Add "articleName", strArticleName
objDict.Add "articleUnit", strUnit
intCounter = 1
strLastENumber = strENumber
else
intCounter=intCounter + 1
end if
if not objDict.Exists(strSupplier) then
' Bara en säkerhetskoll att vi inte lägger in något om det redan är inlagt för denna leverantör
select case intCounter
case 1
' weee, det här är det jättebästa priset!
strFC = "green"
objDict.Add "lowest", strSupplier
case else
strFC = "black"
end select
strLastSupplier = strSupplier
objDict.Add strSupplier, "<font color=""" & strFC & """>" & curPrice & "</font>"
end if
objRS.MoveNext
Loop
' Vi måste köra visningskoden här också för att få med den sista produkten.
objDict.Item(strLastSupplier) = Replace(objDict.Item(strLastSupplier), "black", "red")
call writePrices(objDict)
Response.write "<tr class=""tabellhuvud""><td width=""60"" height=""18"" class=""tabellhuvud""></td><td width=""250"" class=""tabellhuvud""></td><td width=""45"" class=""tabellhuvud"">Summa</td><td width=""75"" class=""tabellhuvud"">" & FormatCurrency(lngTotalSolar) & "</td><td width=""75"" class=""tabellhuvud"">" & FormatCurrency(lngTotalStorel) & "</td><td width=""75"" class=""tabellhuvud""></td><td width=""60"" class=""tabellhuvud""></td><td width=""50"" class=""tabellhuvud""></td></tr>"
Response.Write "</table>"
End if
objRS.Close
Set objRS = Nothing
objConn.Close
Set objConn = Nothing
Set objDict = Nothing
Set objPricesDict = Nothing
public sub writePrices (objPricesDict)
If bgcolor = "#FFFFFF" then bgcolor = "#EFEFEF" else bgcolor = "#FFFFFF"
Response.write "<tr onMouseOver=""this.style.backgroundColor='#D3DEF8';"" onMouseOut=""this.style.backgroundColor='';"" bgcolor=""" & bgcolor & """><td height=""20"" class=""itabell"">" & objPricesDict.Item("eNumber") & "</td><td class=""itabell"">" & objPricesDict.Item("articleName") & "</td><td class=""itabell"">" & objPricesDict.Item("articleUnit") & "</td>"
if objPricesDict.Exists("Solar") then
Response.write "<td class=""itabell"">" & objPricesDict.Item("Solar") & "</td>"
else
Response.write "<td class=""itabell""><i>Saknas</i></td>"
end if
if objPricesDict.Exists("Storel") then
Response.write "<td class=""itabell"">" & objPricesDict.Item("Storel") & "</td>"
else
Response.write "<td class=""itabell""><i>Saknas</i></td>"
end if
if objPricesDict.Exists("Elektroskandia") then
Response.write "<td class=""itabell"">" & objPricesDict.Item("Elektroskandia") & "</td>"
else
Response.write "<td class=""itabell""><i>Saknas</i></td>"
end if
Response.write "<td class=""itabell"">" & objPricesDict.Item("lowest") & "</td>"
Response.Write "<td class=""itabell""><a href=""removeArticle.asp?eNumber=" & objPricesDict.Item("eNumber") & """><img src=""../Images/soptunna.gif"" alt=""Klicka här för att lägga till artikeln!"" width=""31"" height=""17"" border=""0""></a></td>"
end sub
Else
Response.Write "Ej inloggad"
End if
%>
</body>
</html>
Mvh