public HttpResponseMessage regDetalle([FromBody] DetallePedidoModel pedido) { try { using (SqlConnection conn = new SqlConnection(DatabaseConnectionString)) { //SqlCommand cmd = new SqlCommand("INSERT INTO DETALLEPEDIDO(idProducto,idPedido,Cantidad) VALUES (@producto,@pedido,@cantidad)", conn); SqlCommand cmd = new SqlCommand("EXEC CREATEDETALLEPEDIDO @producto, @pedido, @sucursal, @cantidad", conn); cmd.Parameters.AddWithValue("@producto", pedido.idProducto); cmd.Parameters.AddWithValue("@pedido", pedido.idPedido); cmd.Parameters.AddWithValue("@cantidad", pedido.Cantidad); cmd.Parameters.AddWithValue("@sucursal", pedido.idSucursal); cmd.Connection = conn; conn.Open(); cmd.ExecuteReader(); var message = Request.CreateResponse(HttpStatusCode.Created, pedido); conn.Close(); return(message); } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public void GuardarDetallePedido() { fechaActual = DateTime.Today; DetallePedidoModel detallePedidoModel = new DetallePedidoModel { CodPedido = int.Parse(txtCodigoPedido.Text), CodProducto = int.Parse(txtCodigoProducto.Text), Descripcion = txtDescripcion.Text, Categoria = vCategoria, Cantidad = int.Parse(txtCantidad.Text), Precio = decimal.Parse(txtPrecio.Text), Descuento = decimal.Parse(txtDescuento.Text), Ganancia = vGanancia, Fecha = fechaActual }; if (dDetallePedido.CrearDetallePedido(detallePedidoModel) == true) { EdidtarPedido(); } else { MessageBox.Show("Error al Agregar Producto"); } }
public void GuardarPedido(List <DetallePedidoModel> ListadoDetallePedido) { ValidarVacios(); PedidoModel pedidoModel = new PedidoModel { CodUsuarioDelSistema = 1, CodigoCliente = int.Parse(txtCodigoCliente.Text), NombreCliente = txtNombreCliente.Text, LugarEntrega = txtLugarEntrega.Text, FechaOrden = Convert.ToDateTime(dtpFechaActual.Text), FechaEntrega = Convert.ToDateTime(dtpFechaEntrega.Text), TotalDescuentos = decimal.Parse(txtTotalDescuento.Text), Total = decimal.Parse(txtTotal.Text), TotalGanancia = totalGanancia, Estado = estado, Comentario = txtComentario.Text }; idPedido = dPedido.CrearPedido(pedidoModel); if (idPedido == "" || idPedido == null) { MessageBox.Show("ERROR AL CREAR EL PEDIDO"); } else { foreach (var data in ListadoDetallePedido) { DetallePedidoModel detallePedidoModel = new DetallePedidoModel { CodPedido = int.Parse(idPedido), CodProducto = data.CodProducto, Descripcion = data.Descripcion, Categoria = data.Categoria, Cantidad = data.Cantidad, Precio = data.Precio, Descuento = data.Descuento, Ganancia = data.Ganancia, Fecha = data.Fecha }; dDetallePedido.CrearDetallePedido(detallePedidoModel); } LimpiarTodo(); desabilitar_textbox(); btnNuevoPedido.Enabled = true; btnGuardarPedido.Enabled = false; btnBuscarCliente.Enabled = false; btnBuscarProducto.Enabled = false; btnAgregar.Enabled = false; //btnEliminar.Enabled = false; MessageBox.Show("PEDIDO GUARDADO CON EXITO..."); } }
public bool CrearDetallePedido(DetallePedidoModel detallePedidoModel) { SqlCommand cmd = null; bool prueba; cmd = new SqlCommand(" insert into DetallePedido(codPedido,codProducto,descripcion,categoria,cantidad,precio,descuento,ganancia,fecha)" + " values (@codPedido,@codProducto,@descripcion,@categoria,@cantidad,@precio,@descuento,@ganancia,@fecha)", conectar.conn); cmd.CommandType = CommandType.Text; cmd.Parameters.Add(new SqlParameter("@codPedido", detallePedidoModel.CodPedido)); cmd.Parameters.Add(new SqlParameter("@codProducto", detallePedidoModel.CodProducto)); cmd.Parameters.Add(new SqlParameter("@descripcion", detallePedidoModel.Descripcion)); cmd.Parameters.Add(new SqlParameter("@categoria", detallePedidoModel.Categoria)); cmd.Parameters.Add(new SqlParameter("@cantidad", detallePedidoModel.Cantidad)); cmd.Parameters.Add(new SqlParameter("@precio", detallePedidoModel.Precio)); cmd.Parameters.Add(new SqlParameter("@descuento", detallePedidoModel.Descuento)); cmd.Parameters.Add(new SqlParameter("@ganancia", detallePedidoModel.Ganancia)); cmd.Parameters.Add(new SqlParameter("@fecha", detallePedidoModel.Fecha)); conectar.abrir(); int resultado = cmd.ExecuteNonQuery(); cmd = null; conectar.cerrar(); if (resultado > 0) { prueba = true; } else { prueba = false; } return(prueba); }
public HttpResponseMessage updateDetalle(DetallePedidoModel detalle) { try { using (SqlConnection conn = new SqlConnection(DatabaseConnectionString)) { SqlCommand cmd = new SqlCommand("EXEC UPDATEDETALLEPEDIDO @producto, @pedido, @sucursal, @cantidad", conn); cmd.Parameters.AddWithValue("@producto", detalle.idProducto); cmd.Parameters.AddWithValue("@pedido", detalle.idPedido); cmd.Parameters.AddWithValue("@sucursal", detalle.idSucursal); cmd.Parameters.AddWithValue("@cantidad", detalle.Cantidad); cmd.Connection = conn; conn.Open(); cmd.ExecuteReader(); var message = Request.CreateResponse(HttpStatusCode.Accepted, detalle); conn.Close(); return(message); } }catch (Exception e) { return(Request.CreateResponse(HttpStatusCode.BadRequest, "Error")); } }