public static int Agregar_producto(Pedidos_productos pPedidos) { int retorno = 0; MySqlCommand comando = new MySqlCommand(string.Format("Insert into pedidos_productos(productos_id_producto) values ('{0}')", pPedidos.Id_Producto), Conexion.ObtenerConexion()); retorno = comando.ExecuteNonQuery(); return(retorno); }
public static Pedidos_productos TotalGanancia(int id) { Pedidos_productos pPedidos_Productos = new Pedidos_productos(); MySqlCommand comando = new MySqlCommand(String.Format("select (total_venta - total_compra) as Ganancia from expendio.pedido_prductos where id_producto=1;'{0}'", id), Conexion.ObtenerConexion()); MySqlDataReader read_venta = comando.ExecuteReader(); while (read_venta.Read()) { pPedidos_Productos.Ganancia = read_venta.GetDouble(0); } return(pPedidos_Productos); }
public static Pedidos_productos TotalPrecioVenta(int id) { Pedidos_productos pPedidos_Productos = new Pedidos_productos(); MySqlCommand comando_venta = new MySqlCommand(String.Format("SELECT cantidad * paquetes * precio_venta from expendio.pedido_prductos where id_producto='{0}'", id), Conexion.ObtenerConexion()); MySqlDataReader read_venta = comando_venta.ExecuteReader(); while (read_venta.Read()) { pPedidos_Productos.Total_Venta = read_venta.GetDouble(0); } return(pPedidos_Productos); }
public static Pedidos_productos ObtenerProducto(int id) { Pedidos_productos pPedidosProducto = new Pedidos_productos(); MySqlCommand comando = new MySqlCommand(String.Format("select * from expendio.pedido_prductos where id_producto='{0}'", id), Conexion.ObtenerConexion()); MySqlDataReader read = comando.ExecuteReader(); while (read.Read()) { pPedidosProducto.Id = read.GetInt32(0); pPedidosProducto.Cantidad = read.GetInt32(4); } return(pPedidosProducto); }
private void pbx_modificar_pedido_Click(object sender, EventArgs e) { if (dgv_pedidos.SelectedRows.Count == 1) { dgv_pedidos.SetBounds(304, 95, 936, 399); label43.SetBounds(300, 32, 168, 57); panel_opc_pedidos.Visible = false; panel_modif_pedidos.Visible = true; int id = Convert.ToInt32(dgv_pedidos.CurrentRow.Cells[0].Value); PedidoProductoSelect = Pedidos_productosDAL.ObtenerProducto(id); cantidad_piezas_txt.Text = Pedidos_productosDAL.ObtenerProducto(id).Cantidad.ToString(); } else { MessageBox.Show("Selecciona un producto para modificar"); } }
private void btn_agregar_prod_Click(object sender, EventArgs e) { int categoria = cbx_categorias.SelectedIndex + 1; int proveedor = cbx_provedores.SelectedIndex + 1; int presentacion = cbx_presentacion.SelectedIndex + 1; int paquete = cbx_paquete.SelectedIndex + 1; double precio_compra = double.Parse(precio_compra_txt.Text.Trim()); double precio_venta = double.Parse(precio_venta_txt.Text.Trim()); //try //{ Inventario pInventario = new Inventario(); Producto pProducto = new Producto(); Productos_presentaciones pPP = new Productos_presentaciones(); Productos_paquetes pPack = new Productos_paquetes(); Pedidos_productos pPed_Prod = new Pedidos_productos(); int id_ultimo = Convert.ToInt32(ProductoDAL.ObtenerUltimoIDProducto().Id_producto_ultimo); pProducto.Nombre = nombre_prod_txt.Text.Trim(); //pProducto.Precio_compra = precio_compra; //pProducto.Precio_venta = precio_venta; pProducto.Categoria = categoria; pProducto.Proveedor = proveedor; int insert_producto = ProductoDAL.Agregar(pProducto); //AGREGAR PRODUCTO pPP.Id_producto = id_ultimo; pPP.Id_presentacion = presentacion; //AGREGAR CONTENIDO NETO FK pPack.Id_producto = id_ultimo; pPack.Id_paquete = paquete; //AGREGARR PAQUETE FK pInventario.productos_id_producto = id_ultimo; pInventario.Existencias = Int32.Parse(existencias_txt.Text.Trim()); //AGREGAR INVENTARIO FK pPed_Prod.Id_Producto = id_ultimo; //AGREGAR PRODUCTO A PEDIDOS FK int inset_invent = InventarioDAL.Agregar(pInventario); int inset_pedidos_productos = Pedidos_productosDAL.Agregar_producto(pPed_Prod); if (insert_producto > 0 && inset_invent > 0 && inset_pedidos_productos > 0) { MessageBox.Show("Producto Guardado Con Exito!!", "Guardado", MessageBoxButtons.OK, MessageBoxIcon.Information); llenar.GridView_productos(dgv_productos); Limpiar(); if (cbx_categorias.SelectedIndex == 0 || cbx_categorias.SelectedIndex == 1 || cbx_categorias.SelectedIndex == 2) { int insert_prodcuto_pesent = Productos_presentaciones.Agregar_productos_presentaciones(pPP); int insert_producto_paquete = Productos_paquetes.Agregar_productos_paquetes(pPack); if (insert_prodcuto_pesent > 0 && insert_producto_paquete > 0) { MessageBox.Show("Producto con Presentacion Guardado Con Exito!!", "Guardado", MessageBoxButtons.OK, MessageBoxIcon.Information); llenar.GridView_productos(dgv_productos); ActualizarComboBoxProductos(); Limpiar(); } else { MessageBox.Show("No se pudo guardar el Producto con Presentacion", "Fallo!!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); ActualizarComboBoxProductos(); llenar.GridView_productos(dgv_productos); } } } else { MessageBox.Show("No se pudo guardar el Producto Normal", "Fallo!!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); ActualizarComboBoxProductos(); llenar.GridView_productos(dgv_productos); } //} //catch (Exception) //{ // MessageBox.Show("ERROR. Completa los campos correspondientes"); //} }