<% On Error Resume Next Response.Expires = 0 Dim Uploader, File Dim objConn, objRS, strQuery, IobjCheck, ICheckQuery, NstrQuery, UobjRS, UstrQuery, UstrQuery2, UstrQuery1, DobjRS, DstrQuery, DstrQuery2, DstrQuery1 Dim strConnection Dim tPID, tPhotoID, tPhoto Dim count, tRank1, tRank2, tIID Dim fso, tOName, tNName if Session("Admin") = "" then Response.Write "
You have been logout.
" else Set objConn = Server.CreateObject("ADODB.Connection") strConnection = "DSN=pedersens;Database=WebDB;" objConn.Open strConnection Set Uploader = New FileUploader Uploader.Upload() Set fso = CreateObject("Scripting.FileSystemObject") tPID = Uploader.Form("PID") for intLoop = 1 to Session("PNumber") tPhotoID = Uploader.Form("photoID" & intLoop) tU = Uploader.Form("U" & intLoop) tD = Uploader.Form("D" & intLoop) tDel = Uploader.Form("Del" & intLoop) if tU <> "" then strQuery = "SELECT * FROM ProductPhoto WHERE ID = " & tPhotoID Set objRS = objConn.Execute(strQuery) UstrQuery = "SELECT * FROM ProductPhoto WHERE ProductID = " & objRS("ProductID") & " ORDER BY Rank DESC" Set UobjRS = objConn.Execute(UstrQuery) if not UobjRS.EOF then count = 1 Do While not UobjRS.EOF if count = 2 then tRank2 = UobjRS("Rank") UstrQuery2 = "UPDATE ProductPhoto SET Rank = '" & tRank1 & "' WHERE ID = " & UobjRS("ID") objConn.Execute(UstrQuery2) UstrQuery1 = "UPDATE ProductPhoto SET Rank = '" & tRank2 & "' WHERE ID = " & objRS("ID") objConn.Execute(UstrQuery1) exit do end if if UobjRS("ID") = objRS("ID") then tRank1 = UobjRS("Rank") count = count + 1 end if UobjRS.MoveNext Loop end if Response.Redirect("productPhotoEdit.asp?pid=" & tPID) End If if tD <> "" then strQuery = "SELECT * FROM ProductPhoto WHERE ID = " & tPhotoID Set objRS = objConn.Execute(strQuery) DstrQuery = "SELECT * FROM ProductPhoto WHERE ProductID = " & objRS("ProductID") & " ORDER BY Rank" Set DobjRS = objConn.Execute(DstrQuery) if not DobjRS.EOF then count = 1 Do While not DobjRS.EOF if count = 2 then tRank2 = DobjRS("Rank") DstrQuery2 = "UPDATE ProductPhoto SET Rank = '" & tRank1 & "' WHERE ID = " & DobjRS("ID") objConn.Execute(DstrQuery2) DstrQuery1 = "UPDATE ProductPhoto SET Rank = '" & tRank2 & "' WHERE ID = " & objRS("ID") objConn.Execute(DstrQuery1) exit do end if if DobjRS("ID") = objRS("ID") then tRank1 = DobjRS("Rank") count = count + 1 end if DobjRS.MoveNext Loop end if Response.Redirect("productPhotoEdit.asp?pid=" & tPID) End If if tDel <> "" then RstrQuery = "SELECT * FROM ProductPhoto WHERE ID = " & tPhotoID set RobjRS = objConn.Execute(RstrQuery) if fso.FileExists(Server.MapPath("/product") & "/" & RobjRS("Photo")) then fso.DeleteFile(Server.MapPath("/product") & "/" & RobjRS("Photo")) end if strQuery = "DELETE * FROM ProductPhoto WHERE ID = " & tPhotoID objConn.Execute(strQuery) Response.Redirect("productPhotoEdit.asp?pid=" & tPID) End If Next For Each File In Uploader.Files.Items tPhoto = File.FileName ICheckQuery = "SELECT ID FROM ProductPhoto WHERE Photo = '" & tPhoto & "'" set IobjCheck = objConn.execute(ICheckQuery) if not IobjCheck.EOF then count = 0 tIID = IobjCheck("ID") Do While not IobjCheck.EOF count = count + 1 ICheckQuery = "SELECT ID FROM ProductPhoto WHERE Photo = '" & count & tPhoto & "'" set IobjCheck = objConn.execute(ICheckQuery) Loop tOName = Server.MapPath("/product") & "\" & tPhoto tNName = Server.MapPath("/product") & "\" & count & tPhoto fso.MoveFile tOName, tNName NstrQuery = "UPDATE ProductPhoto SET Photo = '" & count & tPhoto & "' WHERE ID = " & tIID objConn.execute(NstrQuery) end if Path = Server.MapPath("/product") File.SaveToDisk (Path) tID = GetNextID strQuery = "INSERT INTO ProductPhoto(ID, ProductID, Photo, Rank) VALUES (" & tID & ", " & tPID & ", '" & tPhoto & "', " & tID & ")" objConn.Execute(strQuery) IobjCheck.close Set IobjCheck = Nothing Next Response.Redirect("productPhotoEdit.asp?pid=" & tPID) objConn.close Set objConn = Nothing end if %>