<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%> <% Option Explicit %> <%session.lcid=1053%> Kundvagn <% Dim objConn, strSearchField, strSQL, objRS, intCounter, objDict, strEnumber, strArticleName, strUnit, strSupplier, curPrice, strFC, strLowest, strLastENumber, strLastSupplier, objPricesDict, strOrder, bgcolor, strOption, strShow, lngTotalStorel, lngTotalSolar, strQuantity, pricesetting, blnEmptyCart blnEmptyCart = False If session("userId") <> "" Then Set objConn = Server.CreateObject("ADODB.Connection") objConn.ConnectionString = "DSN=IntranetSydostel" objConn.Open if Request.Cookies("sydostel")("pricesetting") = "" then pricesetting = 0 else pricesetting = cint(Request.Cookies("sydostel")("pricesetting")) end if if pricesetting = 0 then ' SQL-fråga för priser netto 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" else ' SQL-fråga för priser avtal strSQL = "SELECT tblArticle.articleName, tblArticle.articleUnit, tblCart.userId, tblCart.quantity, tblDiscount.articleDiscount, tblPrice.articlePrice, tblSupplier.SupplierName, tblArticle.eNumber, 0.01*[articlePrice]*(1-([articleDiscount]*0.01)) AS articlePriceWithDiscount 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, 0.01*[articlePrice]*(1-([articleDiscount]*0.01)) ASC" end if 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 session("orderId") = "" then Response.Write "Sammanställning
" Else Response.Write "Sammanställning
" Response.Write "OrderId " & session("orderId") & "
" End if If objRS.EOF then blnEmptyCart = true Response.Write("Varukorgen är tom!
") Else Response.Write("
") Response.Write("Följande artiklar finns i varukorgen:
") Response.write "" Do While not objRS.EOF strENumber = "" & objRS("ENumber") strArticleName = "" & objRS("articleName") strUnit = "" & objRS("articleUnit") strSupplier = "" & objRS("SupplierName") strQuantity = "" & objRS("quantity") if pricesetting = 0 then curPrice = "" & FormatCurrency(Cdbl(objRS("articlePrice"))*0.01) Else curPrice = "" & FormatCurrency(Cdbl(objRS("articlePriceWithDiscount"))) End If If pricesetting = 0 then Select case strSupplier Case "Storel" lngTotalStorel = lngTotalStorel + Cdbl(objRS("articlePrice")*0.01) Case "Solar" lngTotalSolar = lngTotalSolar + Cdbl(objRS("articlePrice")*0.01) End Select Else Select case strSupplier Case "Storel" lngTotalStorel = lngTotalStorel + Cdbl(objRS("articlePriceWithDiscount")) Case "Solar" lngTotalSolar = lngTotalSolar + Cdbl(objRS("articlePriceWithDiscount")) End Select End if 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 objDict.Add "quantity", strQuantity 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, "" & curPrice & "" 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 "" Response.Write "
E-nrBenämningEnhetSolarStorelAhlsellLägstAntalÄndraTa bort
Summa" & FormatCurrency(lngTotalSolar) & "" & FormatCurrency(lngTotalStorel) & "
" Response.write "Samtliga priser är exklusive moms!
" if pricesetting = 0 then Response.Write "Visar Nettopriser" Else Response.Write "Visar avtalspriser" End If End if If blnEmptyCart = False then If session("orderId") = "" then Response.Write "
" Response.Write "

" Response.Write "" Response.write "" Response.Write "" Response.Write"
Spara sammanställning  
Spara sammanställningen som:
" Else Response.Write "
" Response.Write "

" Response.Write "" Response.write "" Response.Write "" Response.Write"
Spara sammanställning 
Spara sammanställning:
" End if 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 "" & objPricesDict.Item("eNumber") & "" & objPricesDict.Item("articleName") & "" & objPricesDict.Item("articleUnit") & "" if objPricesDict.Exists("Solar") then Response.write "" & objPricesDict.Item("Solar") & "" else Response.write "Saknas" end if ' Response.write ""& objPricesDict.Item("Solar")*objPricesDict.Item("quantity") & "" if objPricesDict.Exists("Storel") then Response.write "" & objPricesDict.Item("Storel") & "" else Response.write "Saknas" end if if objPricesDict.Exists("Elektroskandia") then Response.write "" & objPricesDict.Item("Elektroskandia") & "" else Response.write "Saknas" end if Response.write "" & objPricesDict.Item("lowest") & "" Response.Write "" Response.Write "" Response.Write "" end sub Else Response.Write "Ej inloggad" End if %>