Avatar billede webtrotter Nybegynder
27. oktober 2005 - 23:31 Der er 8 kommentarer

Opdatere tid i database

Hej

Jeg har downloadet et auktionsprogram fra Xcent, som jeg har fået til at fungere fint, men man vil jo altid gøre det bedre og nu vil jeg gerne have at hvis der bliver budt indenfor de sidste fem minutter, så skal sluttiden forlænges med fem minutter fra budtidspunktet.

Alle data er i en Access database, hvor der i en tabel (tblQABids) gemmes bud med tidsangivelse og i en anden tabel (tblQAAuctions) står katalogvaren med udløbsdato/tid.

Jeg vil gerne at når der bliver lagt et bud ind, så skal den tjekke om budtidspunktet der bliver lagt i tabellen tblQABids, er mindre end fem minutter før sluttiden - i givet fald skal den opdatere tiden i tabellen tblQAAuctions med budtidspunktet + 5 minutter.

Jeg har forsøgt forskellige løsninger, men enten fjerner den sluttiden eller også sker der intet med tiden. Håber der er en derude der kan hjælpe mig.

Her er koden på den hvor den opdaterer databasen:

    DoPageHeader
    TableHead GLS_PlaceBid
    OpenDBConn
   
    sUserName  = "" & Request.Form("UserName")
    sPassword  = "" & Request.Form("Password")
    iBidPlaced  = FVal(Request.Form("Bid"))
    iItemID    = FVal(Request.Form("ItemID"))
    DatoTid    = DateAdd("N",5,Now())

    lBidderID = 0
    sBidderEmail = ""
    lCatID = 0
   
    bidSQL = "SELECT * FROM tblQAAuctions WHERE aucID =" & SQLVal(iItemID)
    set bidRS = gobjConnect.Execute(bidSQL)
    If NOT bidRS.EOF Then
        iCurrentBidder = FVAL(bidRs("aucCurrentBidder"))
        sItemTitle =  "" & bidRS.Fields("aucItemTitle")
        vCloseDate = bidRS.Fields("aucCloseDate")
        lOwnerID = FVal(bidRS("aucItemOwner"))
        lCatID = FVal(bidRS.Fields("aucCategoryID"))
        If FVal(bidRS.Fields("aucCurrentBid")) > 0 Then
            iBidNeeded = FVal(bidRS.Fields("aucMinimumIncrement") + bidRS.Fields("aucCurrentBid"))
        Else
            iBidNeeded = FVal(bidRS.Fields("aucStartingBid"))
         
        End If
    Else
        iCurrentBidder = 0
        sItemTitle = ""
        vCloseDate = ""
    End If
    Response.Write "<TABLE BORDER=""0"" CELLPADDING=""5"" CELLSPACING=""0""><TR><TD>"
        If UserRegistered Then
            If CheckBid Then
                PlaceBid
                If iCurrentBidder > 0 Then
                    SendOutbidEmail
                End If
            End If
        End If
    Response.Write "</TD></TR></TABLE>"
    BidRS.Close
    Set BidRS = Nothing
    TableFoot
    DoPageFooter
    CloseDBConn


Sub PlaceBid
    uiSQL = "SELECT * FROM tblQARegistration WHERE regUserName = " & SQLStr(sUserName) & " AND regPassword = " & SQLStr(sPassword) & " "
    Set UserRS = gobjConnect.Execute(uiSQL)
    If NOT UserRS.EOF Then
        lBidderID = FVal(UserRS.Fields("regID"))
        sBidderEmail = "" & UserRS.Fields("regEmail")
    End If
    UserRS.Close
    Set UserRS = Nothing

    upBidsSQL = "INSERT INTO tblQABids (bidItemID, BidAmount, BidDate, bidBidderID) VALUES( " & _
                SQLVal(iItemID) & ", " & _
                SQLVal(iBidPlaced) & ", " & _
                SQLDate(NOW) & ", " & _
                SQLVal(lBidderID) & " ) "
    gobjConnect.Execute(upBidsSQL)
    'Response.Write upBidsSQL & "<BR>"

    pbSQL = "UPDATE tblQAAuctions Set " & _
            " aucCurrentBid = " & SQLVal(iBidPlaced) & _
            " , aucCurrentBidder = " & SQLVal(lBidderID)& " " & _
            " WHERE aucID = " & SQLVal(iItemID)
<== HER VIL JEG GERNE HAVE DEN TIL AT OPDATERE FELTET aucCloseDate MED DEN NYE TID ==>
    'Response.write pbSQL & "<BR>"
    gobjConnect.Execute(pbSQL)
   
    If len(sBidderEmail) > 0 Then
        SendBidEmail
    End If
   
    sBidMsg = "" &  Replace(GLS_SuccessfulBid, "%BIDAMOUNT%", FCurrency(iBidPlaced))
    sBidMsg = Replace(sBidMsg, "%ITEMNO%", iItemID)
    sBidMsg = Replace(sBidMsg, "%ITEMTITLE%", sItemTitle)
    Response.Write gsAuctionTextOpen & sBidMsg & "<BR>"
    Response.Write GLS_PrintConfirm & "<BR><P>"
    Response.Write "<A HREF=""QAViewAuctions.asp?catID=" & lCatID & """>" & GLS_GoToCategory & "</A><BR>"
    Response.Write "<A HREF=""QAViewItem.asp?ItemID=" & iItemID  & """>" & GLS_GoToItem & "</A><BR>" & gsAuctionTextClose
End Sub

Sub SendBidEmail
    sBody = "" & ReadFile(Server.MapPath("QAEmailTemplates\QABidNotice.txt"))
    sBody = Replace(sBody, "%AUCURL%", gsAucURL)
    sBody = Replace(sBody, "%TITLE%", sItemTitle)
    sBody = Replace(sBody, "%BID%", FCurrency(iBidPlaced))
    sBody = Replace(sBody, "%AUCID%", iItemID)
    sBody = Replace(sBody, "%AUCCLOSE%", DispShortDateTime(vCloseDate))
    sBody = sBody & Chr(13) & Chr(10) & "Powered by QuickAuction © XCENT"
   
    sSubject = GetFirstLine(sBody)
    SendEmailMessage sBidderEmail, gsAdminEmail, sSubject, sBody
   
End Sub

Sub SendOutbidEmail
    emailSQL = "SELECT regID, regEmail FROM tblQARegistration WHERE regID = " & SQLVal(iCurrentBidder)
    Set emailRS = gobjConnect.Execute(emailSQL)
    If NOT emailRS.EOF Then
        sBody = "" & ReadFile(Server.MapPath("QAEmailTemplates\QAOutbidNotice.txt"))
        sBody = Replace(sBody, "%AUCURL%", gsAucURL)
        sBody = Replace(sBody, "%TITLE%", sItemTitle)
        sBody = Replace(sBody, "%BID%", FCurrency(iBidPlaced))
        sBody = Replace(sBody, "%AUCID%", iItemID)
        sBody = Replace(sBody, "%AUCCLOSE%", DispShortDateTime(vCloseDate))
        sBody = sBody & Chr(13) & Chr(10) & "Powered by QuickAuction © XCENT"
        sTo = "" & emailRS.Fields("regEmail")
        sSubject = GetFirstLine(sBody)
        SendEmailMessage sTo, gsAdminEmail, sSubject, sBody
    End If
    emailRS.Close
    set emailRS = Nothing
End Sub

Function CheckBid
    If iBidPlaced >= iBidNeeded AND lOwnerID <> lBidderID Then
        CheckBid = True
    Else
        Response.Write(gsAuctionTextOpen & GLS_BidError &  gaAuctionTextClose & "<BR>")
        If iBidPlaced < iBidNeeded Then
            Response.Write gsErrorTextOpen & GLS_BidBelowMin & "<BR>" & gsErrorTextClose
        End If
        If lOwnerID = lBidderID Then
            Response.Write gsErrorTextOpen & GLS_BidOwner & "<BR>" & gsErrorTextClose
        End If
        Response.Write(gsAuctionTextOpen & GLS_GoBack & "<BR>" & gsAuctionTextClose)
        CheckBid = False
    End If
End Function

Function UserRegistered
    regSQL = "SELECT * FROM tblQARegistration WHERE regUsername = " & SQLStr(sUserName) & " AND regPassword = " & SQLStr(sPassword) & " "
    Set regRS = gobjConnect.Execute(regSQL)
    If NOT regRS.EOF Then
        UserRegistered = True
        lBidderID = regRS("regID")
    Else
        Response.Write(gsAuctionTextOpen & GLS_LoginErr & "<BR>")
        Response.Write(GLS_GoBack & "<BR><BR>")
        Response.Write(GLS_HowToRegister & gsAuctionTextClose)
        UserRegistered = False
    End If
    regRS.Close
    Set regRS = Nothing
End Function

%>
Avatar billede softspot Forsker
27. oktober 2005 - 23:37 #1
Hvis det er en Access-database, skulle jeg mene at du kan benytte flg. notation:

    pbSQL = "UPDATE tblQAAuctions Set " & _
            " aucCurrentBid = " & SQLVal(iBidPlaced) & _
            " , aucCurrentBidder = " & SQLVal(lBidderID)& " " & _
            " , aucCloseDate = DateAdd('n',5,aucCloseDate) " & _
            " WHERE aucID = " & SQLVal(iItemID)
Avatar billede webtrotter Nybegynder
28. oktober 2005 - 18:05 #2
Som jeg ser det ligger den fem minutter til ved buddet - men det skulle den kun gøre hvis der er mindre end fem minutter til sluttidspunktet....
Avatar billede softspot Forsker
29. oktober 2005 - 00:22 #3
Ja, det er du nok nød til at checke for inden du laver denne opdatering... Jeg har givet et bud på koden herunder...

pbcSQL = "SELECT aucCloseDate FROM tblQAAuctions WHERE aucID = " & SQLVal(iItemID)
set rs = gobjConnect.Execute(pbsSQL)
if not rs.eof then
  closeDate = rs("aucCloseDate")

  if datediff("n", closeDate, now) > 5 then
    pbSQL = "UPDATE tblQAAuctions Set " & _
            " aucCurrentBid = " & SQLVal(iBidPlaced) & _
            " , aucCurrentBidder = " & SQLVal(lBidderID)& " " & _
            " WHERE aucID = " & SQLVal(iItemID)
  else
    pbSQL = "UPDATE tblQAAuctions Set " & _
            " aucCurrentBid = " & SQLVal(iBidPlaced) & _
            " , aucCurrentBidder = " & SQLVal(lBidderID)& " " & _
            " , aucCloseDate = DateAdd('n',5,aucCloseDate) " & _
            " WHERE aucID = " & SQLVal(iItemID)
  end if
  gobjConnect.Execute(pbSQL)
else
  ' DET MÅ VÆRE EN FEJLSITUATION!?
end if
rs.close
Avatar billede webtrotter Nybegynder
29. oktober 2005 - 10:26 #4
Takker :-)
Avatar billede webtrotter Nybegynder
29. oktober 2005 - 10:27 #5
point på vej
Avatar billede softspot Forsker
29. oktober 2005 - 11:43 #6
Dvs. du gerne vil have et svar... :)
Avatar billede softspot Forsker
08. november 2005 - 11:36 #7
webtrotter, blev spørgsmålet væk?
Avatar billede softspot Forsker
05. marts 2007 - 13:58 #8
webtrotter??
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester