0

当用户从复选框中选择订单时,我有此代码用于从订单表中删除一条或多条记录。现在我有了库存模块,一旦订单被取消,我希望我的库存记录更新数量(将产品数量添加回当前库存)。

实际上,如果代码是一次删除一条记录的实现,这应该不是问题。但是,这个删除代码是为了删除多条记录,以我的技能,我无法弄清楚如何添加另一个更新 Sql 命令。所以你能帮帮我吗?非常感谢。

以下是我现有的代码..

<%
    call navigation
    url = main_area & "?" & "page=" & page_current 
    return_page = "../backend/" &  url
    req_status = request("type")
    if req_status = "restore" then
        req_status = False
    else
        req_status = True
    end if

    record = request("bill_id")
    timestamp = now()
    record = trim(record)
    if len(record) > 3 then   ' multiple records was selected
        arrVals = split(record,",")             


        strSql = ""
        strSql = strSql & "DELETE * FROM tbl_bill_total WHERE "     
        for i = 0 to ubound(arrVals)
             if i = 0 then           
              strSql = strSql & "bill_id IN ("& trim(arrVals(i)) & "    "
             else
              strSql = strSql & ","& trim(arrVals(i)) & ""
             end if
        next
        strSql = strSql & ") "

        strSql2 = strSql2 & "DELETE * FROM tbl_order WHERE "    
        for t = 0 to ubound(arrVals)
             if t = 0 then
              strSql2 = strSql2 & " tbl_order.bill_id IN ("& trim(arrVals(t)) & "    "
             else
              strSql2 = strSql2 & ","& trim(arrVals(t)) & ""
             end if
        next
        strSql2 = strSql2 & "); "       

    else

        strSql  = "DELETE * FROM tbl_bill_total WHERE bill_id=" & record & " "  
        strSql2  = "DELETE * FROM tbl_order WHERE bill_id =" & record & " " 
    end if




Call DBConnOpen()
Set Rs = Server.CreateObject("ADODB.Recordset")
response.write strSql

conn.Execute strSql
conn.Execute strSql2
Call DBConnClose()

response.redirect return_page
%>

这是我要添加的 SQL 语句。由于它需要 pd_id 执行,我认为这应该在执行上述 SQL 语句之前执行。

Set rsOrder = conn.Execute("SELECT * FROM tbl_order WHERE bill_id = " & record & "" )           
pd_id = rsOrder.fields.item("pd_id")
od_qty = rsOrder.fields.item("od_qty")


Set rsInventory = conn.Execute("UPDATE tbl_inventory SET inv_qty_act = inv_qty_act + " & od_qty & ", inv_date =  " & date() & " WHERE pd_id = '" & pd_id & "'"  )   



(工作代码)
现在使用@John 提供的解决方案,它可以将选择的一个/多个记录的数量更新回数据库。

以下是消除添加')'的工作代码

<%
Call DBConnOpen()
Set Rs = Server.CreateObject("ADODB.Recordset")

    call navigation
    url = main_area & "?" & "page=" & page_current 
    return_page = "../backend/" &  url
    req_status = request("type")
    if req_status = "restore" then
        req_status = False
    else
        req_status = True
    end if

    record = request("bill_id")
    timestamp = now()
    record = trim(record)
    if len(record) > 3 then   ' multiple records was selected
        arrVals = split(record,",")             


        strSql = ""
        strSql = strSql & "DELETE * FROM tbl_bill_total WHERE "     
        for i = 0 to ubound(arrVals)
             if i = 0 then           
              strSql = strSql & "bill_id IN ("& trim(arrVals(i)) & "    "
             else
              strSql = strSql & ","& trim(arrVals(i)) & ""
             end if
        next
        strSql = strSql & ") "

        strSql2 = strSql2 & "DELETE * FROM tbl_order WHERE "    
        for t = 0 to ubound(arrVals)

        Set rsOrder = conn.Execute("SELECT * FROM tbl_order WHERE bill_id = " & arrVals(t) & "")     
            pd_id = rsOrder.fields.item("pd_id")  
            od_qty = rsOrder.fields.item("od_qty")  
                od_qty  = DzToPcs(od_qty)
        conn.Execute("UPDATE tbl_inventory SET inv_qty_act = inv_qty_act + " & od_qty & ", inv_date =  " & date() & " WHERE pd_id = '" & pd_id & "'"  ) 

             if t = 0 then
              strSql2 = strSql2 & " tbl_order.bill_id IN ("& trim(arrVals(t)) & "    "

             else
              strSql2 = strSql2 & ","& trim(arrVals(t)) & ""
             end if
        next
        strSql2 = strSql2 & "); "       


'   response.Write "strSql3 = " & strSql3
    else


        Set rsOrder = conn.Execute("SELECT * FROM tbl_order WHERE bill_id = " & record & " ")             
            pd_id = rsOrder.fields.item("pd_id")  
            od_qty = rsOrder.fields.item("od_qty")  
                od_qty  = DzToPcs(od_qty)   
        conn.Execute("UPDATE tbl_inventory SET inv_qty_act = inv_qty_act + " & od_qty & ", inv_date =  date() WHERE pd_id = '" & pd_id & "'"  ) 

        strSql  = "DELETE * FROM tbl_bill_total WHERE bill_id=" & record & " "  
        strSql2  = "DELETE * FROM tbl_order WHERE bill_id =" & record & " " 
    end if




'Call DBConnOpen() --> move to top line
'Set Rs = Server.CreateObject("ADODB.Recordset") --> move to top line
'response.write strSql2

conn.Execute strSql
conn.Execute strSql2
Call DBConnClose()

response.redirect return_page
%>
4

1 回答 1

1

我建议您在循环中进行库存冲销,如下所示:

<%
    call navigation
    url = main_area & "?" & "page=" & page_current 
    return_page = "../backend/" &  url
    req_status = request("type")
    if req_status = "restore" then
        req_status = False
    else
        req_status = True
    end if

    record = request("bill_id")
    timestamp = now()
    record = trim(record)
    if len(record) > 3 then   ' multiple records was selected
        arrVals = split(record,",")             


        strSql = ""
        strSql = strSql & "DELETE * FROM tbl_bill_total WHERE "     
        for i = 0 to ubound(arrVals)
             if i = 0 then           
              strSql = strSql & "bill_id IN ("& trim(arrVals(i)) & "    "
             else
              strSql = strSql & ","& trim(arrVals(i)) & ""
             end if
        next
        strSql = strSql & ") "

        strSql2 = strSql2 & "DELETE * FROM tbl_order WHERE "    
        for t = 0 to ubound(arrVals)

Set rsOrder = conn.Execute("SELECT * FROM tbl_order WHERE bill_id = " & arrVals(t)) & "" )             
pd_id = rsOrder.fields.item("pd_id")  
od_qty = rsOrder.fields.item("od_qty")  
conn.Execute("UPDATE tbl_inventory SET inv_qty_act = inv_qty_act + " & od_qty & ", inv_date =  " & date() & " WHERE pd_id = '" & pd_id & "'"  ) 

             if t = 0 then
              strSql2 = strSql2 & " tbl_order.bill_id IN ("& trim(arrVals(t)) & "    "
             else
              strSql2 = strSql2 & ","& trim(arrVals(t)) & ""
             end if
        next
        strSql2 = strSql2 & "); "       

    else

Set rsOrder = conn.Execute("SELECT * FROM tbl_order WHERE bill_id = " & record & "" )             
pd_id = rsOrder.fields.item("pd_id")  
od_qty = rsOrder.fields.item("od_qty")  
conn.Execute("UPDATE tbl_inventory SET inv_qty_act = inv_qty_act + " & od_qty & ", inv_date =  " & date() & " WHERE pd_id = '" & pd_id & "'"  ) 

        strSql  = "DELETE * FROM tbl_bill_total WHERE bill_id=" & record & " "  
        strSql2  = "DELETE * FROM tbl_order WHERE bill_id =" & record & " " 
    end if




Call DBConnOpen()
Set Rs = Server.CreateObject("ADODB.Recordset")
response.write strSql

conn.Execute strSql
conn.Execute strSql2
Call DBConnClose()

response.redirect return_page
%>
于 2012-10-02T22:40:32.393 回答