Carrinho não grava novo campo
Amigos no codigo abaixo o carrinho grava tres campos na tabela pedido_item, agora é necessario gravar mais um (vrl_unitario), inclui o campo nos inserts, a rotina não dá erro nenhum, mas tb não grava o campo novo. Estou travado nisso há horas!! Agradeço a ajuda!
<%
Option Explicit
%>
<!--#include file="bib_conexao.asp"-->
<!--#include file="header.htm"-->
<%
Dim Conexao, rsMax, rsPedidoItem, strSQL, novo_codPedido, sub_total, field_name, strSQLPed
'abre a conexão
Call abre_Conexao
If Session("codPed") = "" Then
Set rsMax = Server.CreateObject("ADODB.Recordset")
rsMax.Open "SELECT MAX(COD_pedido) AS max_codPedido FROM Pedidos", Conexao
If IsNull(rsMax("max_codPedido")) Then
novo_codPedido = 1
Else
novo_codPedido = rsMax("max_codPedido") + 1
End If
rsMax.Close
Set rsMax = Nothing
Conexao.Execute "INSERT INTO Pedidos (COD_Pedido) VALUES (" & novo_codPedido & ")"
Session("codPed") = novo_codPedidoEnd If
Set rsPedidoItem = Server.CreateObject("ADODB.Recordset")
If Request.QueryString("id") <> "" Then
rsPedidoItem.Open "SELECT * FROM Pedido_Item WHERE COD_Pedido = " & Session("codPed") & " AND COD_Produto = " & Request.QueryString("id"), Conexao
If rsPedidoItem.EOF Then
Conexao.Execute "INSERT INTO Pedido_Item (cod_Pedido, cod_Produto, qtd_Pedido, vrl_unitario) VALUES (" & Session("codPed") & ", " & Request.QueryString("id") & ", 1, " &txtvalor& ")"
End If
rsPedidoItem.CloseEnd If
If Request.Form <> "" Then
Conexao.Execute "DELETE FROM Pedido_Item WHERE COD_Pedido = " & Session("codPed")
For Each field_name In Request.Form
If field_name <> "B1" And Request.Form(field_name) <> "0" And field_name <> "txtvalor" And Trim(Request.Form(field_name)) <> "" Then
strSQL = "INSERT INTO Pedido_Item (COD_Pedido, COD_Produto, QTD_Pedido, vrl_unitario) VALUES ("& Session("codPed") & ", " & field_name & ", " & Request.Form(field_name) & ", " & txtvalor & ")"
Conexao.Execute strSQL
End If
NextEnd If
%>
<html>
<head>
<title>Fechamento</title>
</head>
<script type="text/javascript">
function checa_Preco_digitado(valoralterado, valorBanco) {
if (valoralterado < valorBanco) {
alert("Preço alterado menor do que o preço original!")
document.getElementById("texto").value = valorBanco;
}
}
function somentenumero(obj, e) {
var tecla = (window.event) ? e.keyCode : e.which;
var texto = document.getElementById("texto").value;
var indexvir = texto.indexOf(",");
var indexpon = texto.indexOf(".");
if (tecla == 8 || tecla == 0)
return true;
if (tecla != 44 && tecla != 46 && tecla < 48 || tecla > 57)
return false;
if (tecla == 44) { if (indexvir !== -1 || indexpon !== -1) { return true } }
if (tecla == 46) { if (indexvir !== -1 || indexpon !== -1) { return true } }
}
function MM_openBrWindow(theURL, winName, features) { //v2.0
window.open(theURL, winName, features);
}
</script>
<body BGCOLOR="#FFFFFF"><%
strSQLPed = "SELECT Pedido_Item.*, Produtos.Produto, "
strSQLPed = strSQLPed & "Produtos.VRL_Unitario, Produtos.qtd_estoque "
strSQLPed = strSQLPed & "FROM Produtos INNER JOIN Pedido_Item "
strSQLPed = strSQLPed & "ON Produtos.COD_Produto = Pedido_Item.COD_Produto"
strSQLPed = strSQLPed & " WHERE Pedido_Item.COD_Pedido = " & Session("codPed") & " AND Produtos.COD_Produto = Pedido_Item.COD_Produto"
Set rsPedidoItem = Conexao.Execute(strSQLPed)
If rsPedidoItem.EOF = True then
Response.write ("<br><div align=center><b>Pedido Sem Itens.</b></div>")
Else
%>
<form method="POST" action="<%= Request.ServerVariables("SCRIPT_NAME") %>">
<div align="center"><center>
<table border="0" cellspacing="1" cellpadding="1" width="675">
<tr bgcolor="#FF6633">
<td width="328" align="center">
<div align="center">
<p><b><font color="#FFFFFF" size="2" face="Verdana">Produto</font></b> </div>
</td>
<td width="56" align="center">
<div align="center"> <b>
<p><font face="Verdana" color="#FFFFFF" size="2"><small>Preço</small></font>
</b> </div>
</td>
<td width="70" align="center">
<div align="center">
<p><b><font face="Verdana" color="#FFFFFF" size="2"><small>QTD</small></font>
</b> </div>
</td>
<td width="148" align="center"><b>
<p><font face="Verdana" color="#FFFFFF" size="2"><small>Total</small></font>
</b>
</td>
<td width="57" align="center">
<div align="center"> <b>
<p>
</b></div>
</td>
</tr>
<%
If not rsPedidoItem.EOF then rsPedidoItem.MoveFirst
sub_total = 0
While Not rsPedidoItem.EOF
%>
<tr align="center">
<td width="328" bgcolor="#EEEEEE" align="left" height="13"><font face="Verdana" color="#000000" size="1"><%= rsPedidoItem("Produto") %>
</font>
</td>
<td width="56" bgcolor="#EEEEEE" align="right" height="13"><font face="Verdana" size="1">
<input type="text" id="texto" align="right" style="height: 20px; width: 150px; margin-left: 0px;" value="<%= FormatNumber(rsPedidoItem("VRL_Unitario"),2) %>" name="txtvalor" onBlur="checa_Preco_digitado(this.value,this.defaultValue)" onKeyPress="return somentenumero(this, event);"
/>
</font>
</td>
<td width="70" bgcolor="#EEEEEE" align="center" height="13"> <font face="Verdana" size=1>
<input type="TEXT" name="<%= rsPedidoItem("cod_Produto") %>" size="3" maxlength="3" value="<%= rsPedidoItem("QTD_Pedido") %>">
</font>
</td>
<td width="148" bgcolor="#EEEEEE" align="right" height="13"><font face="Verdana" size="1">
<%= FormatNumber(rsPedidoItem("QTD_Pedido") * rsPedidoItem("VRL_Unitario"))%></font>
</td>
<td width="57" bgcolor="#EEEEEE" align="center" height="13">
<a href=ExcluiItemCarrinhoF.asp?id=<%= rsPedidoItem("cod_Produto")%>>
<font face="Verdana" size="1">excluir</font></a>
</td>
</tr>
<%
'Calcula subtotal
sub_total = sub_total + rsPedidoItem("QTD_Pedido") * rsPedidoItem("VRL_Unitario")
rsPedidoItem.MoveNext
Wend
rsPedidoItem.Close
Session("sub_total") = sub_total
sub_total = replace(sub_total, ",",".")
Conexao.Execute "UPDATE Pedidos SET sub_total = " & sub_total & " WHERE cod_Pedido = " & Session("codPed")
Conexao.Close
%>
<tr align="center">
<td align="center" width="328">
<div align="center"> <font face="Arial">
<p>
</font> </div>
</td>
<td align="center" width="56">
</td>
<td width="70" bgcolor="#EEEEEE" align="center">
<div align="right"><small><font face="Arial" size="2">
<p><b><font face="Verdana">Subtotal:
</font></b>
</font></small></div>
</td>
<td width="148" bgcolor="#EEEEEE" align="right">
<font face="Verdana" size=2><b>
<%= FormatNumber(Session("sub_total"),2) %>
</b></font> </td>
<td width="57" bgcolor="#EEEEEE" align="center">
</td>
</tr>
</table>
</center></div><div align="center"><center>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td width="100%" valign="middle">
<div align="center">
<p><input type="submit" value="Recalcular" name="B1">
</div>
</td>
</tr>
</table>
</center>
</div>
</form>
<table border="0" cellpadding="0" cellspacing="0" width="583" align="center">
<tr>
<td align="center" width="183"><A href="javascript:history.go(-1)">Voltar</A></td>
<td align="center" width="183">
<a href="DadosPedidoF.asp">Dados do pedido </a>
</td>
<td align="center" width="217">
<a href="ExcluiCarrinhoF.asp">Excluir o carrinho </a>
</td>
</tr>
<tr>
<td colspan="3" align="center"><FONT COLOR="#FF0000"><strong>MAXIMO 10 ITENS POR PEDIDO</strong></FONT></td>
</tr>
</table>
<%
End If
%>
</body>
</html>Discussão (2)
Carregando comentários...