public static bool InsertingProductInPedido(PedidoProdutosDTO pedido) { try { return PedidoDAO.InsertingProductInPedido(pedido); } catch (Exception e) { throw e; } }
private void btn_ok_Click(object sender, EventArgs e) { PedidoDTO pedido = new PedidoDTO(); PedidoProdutosDTO pedidoProduto = new PedidoProdutosDTO(); int contador = 0; pedido.fornecedor.codigo = Convert.ToInt32(cbx_fornecedor.SelectedValue); pedido.total = total; if (GeralRN.InsertPedido(pedido)) { while (contador < this.dtgrid_venda.Rows.Count) { pedidoProduto.codigo_pedido = this.lbl_pedido.Text; pedidoProduto.codigo_produto = this.dtgrid_venda.Rows[contador].Cells["code"].Value.ToString(); pedidoProduto.quantidade_ites = Convert.ToInt32(this.dtgrid_venda.Rows[contador].Cells["quatde"].Value); pedidoProduto.total = Convert.ToDouble(this.dtgrid_venda.Rows[contador].Cells["precototal"].Value.ToString().Replace("R$ ", "")); GeralRN.InsertingProductInPedido(pedidoProduto); contador++; } if (GeralRN.GeneratePdfPedido(this.lbl_pedido.Text, Convert.ToInt32(cbx_fornecedor.SelectedValue))) { RecreatePedido(); } } }
public static bool InsertingProductInPedido(PedidoProdutosDTO pedido) { StringBuilder SQL = new StringBuilder(); SQL.Append(@"INSERT INTO Pedidos_Produtos(codigo_produto, codigo_pedido, total, qtdeItens) VALUES(@CODIGO_PRODUTO, @CODIGO_PEDIDO, @TOTAL, @QTDE)"); try { using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Mendes_Varejo"].ConnectionString)) { connection.Open(); SqlCommand command = new SqlCommand(SQL.ToString(), connection); command.Parameters.AddWithValue("@CODIGO_PRODUTO", pedido.codigo_produto); command.Parameters.AddWithValue("@CODIGO_PEDIDO", pedido.codigo_pedido); command.Parameters.AddWithValue("@TOTAL", pedido.total); command.Parameters.AddWithValue("@QTDE", pedido.quantidade_ites); command.ExecuteNonQuery(); command.Dispose(); } return true; } catch (Exception e) { throw e; } }