public List <Detalle> GetCorte(string fecha1, string fecha2, int tipo) { //Corte del dia y por usuario List <Ventas> ventas = new List <Ventas>(); List <Detalle> detalle = new List <Detalle>(); ventas = new DAOVentas().GetVentas(fecha1, fecha2, 1); SqlCeConnection conn = new SqlCeConnection(@"Data Source=|DataDirectory|\DB\DB_local.sdf"); conn.Open(); //commands represent a query or a stored procedure SqlCeCommand cmd = conn.CreateCommand(); foreach (Ventas venta in ventas) { cmd.CommandText = "SELECT * FROM detalle_venta WHERE id_venta='" + venta.Id + "'"; SqlCeDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { detalle.Add(new Detalle( reader["id_venta"].ToString(), reader["id_producto"].ToString(), int.Parse(reader["cantidad"].ToString()), float.Parse(reader["precio"].ToString()), float.Parse(reader["total"].ToString()) )); } } return(detalle); }
public Ventas UltVenta(out string error) { try { error = ""; if (error.Equals("")) { DAOVentas venDao = new DAOVentas(); Ventas venta = venDao.UltimaVenta(out error); if (venta == null) { error += "No hay datos"; } return(venta); } else { return(null); } } catch (Exception ex) { error = ex.Message; return(null); } }
private void cantidad_textbox_KeyPress(object sender, KeyPressEventArgs e) { if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar)) { e.Handled = true; } if (e.KeyChar == (char)Keys.Enter) { int cantidad = 0; if (!int.TryParse(cantidad_textbox.Text, out cantidad)) { MessageBox.Show("Debe ingresar un número entero.", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { if (ObtenerCantidadProducto(Codigo_textbox.Text) == 0) { MessageBox.Show("Error en la busqueda de la cantidad del producto seleccionado.", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (ObtenerCantidadProducto(Codigo_textbox.Text) < int.Parse(cantidad_textbox.Text)) { MessageBox.Show("La cantidad ingresada es mayor a la vendida.", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (ObtenerCantidadProducto(Codigo_textbox.Text) >= int.Parse(cantidad_textbox.Text)) { //Se hace la devolucion del producto //Obtener el precio del producto e ingresarlo, al igual ingresarlo en la base de datos Detalle detalle = new Detalle(); detalle.id_producto = Codigo_textbox.Text; detalle.id_venta = new Validaciones().LimpiarString(clave_venta_textbox.Text); detalle.cantidad = ObtenerCantidadProducto(Codigo_textbox.Text) - int.Parse(cantidad_textbox.Text); detalle.precio = productoDetalle.precio; detalle.total = productoDetalle.precio * detalle.cantidad; new DAODetalle().ModificarDetalle(detalle); List <Detalle> detalles = new List <Detalle>(); detalles = new DAODetalle().GetDetails(new Validaciones().LimpiarString(clave_venta_textbox.Text)); Ventas devolucion = new DAOVentas().GetVentaXId(clave_venta_textbox.Text); devolucion.Total = ObtenerTotalVenta(detalles); new DAOVentas().ModificarVenta(devolucion); //Se verifica si el producto es una oferta para regresar la cantidad. DTOOfertas oferta = new DAOOfertas().GetOferta(Codigo_textbox.Text); if (oferta != null) { new DAOProductos().Aumentarproductos(oferta.codigo, oferta.cantidad * int.Parse(cantidad_textbox.Text)); } else { new DAOProductos().Aumentarproductos(Codigo_textbox.Text, int.Parse(cantidad_textbox.Text)); } MessageBox.Show("Devolución realizada con éxito.", "Devolución", MessageBoxButtons.OK, MessageBoxIcon.Information); FocusTicket(); } } } }
public void cargarVentas() { DataTable dt = DAOVentas.getAll(); if (dt != null) { dgVentas.DataSource = dt; } else { MessageBox.Show("Error al cargar las ventas", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void dgVentas_SelectionChanged(object sender, EventArgs e) { int index = dgVentas.CurrentRow.Index; DataTable dt = DAOVentas.getProductosByVenta(int.Parse(dgVentas[0, index].Value.ToString())); if (dt != null) { dgProductos.DataSource = dt; } else { MessageBox.Show("Error al cargar los productos", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public void VentaNuevo(Ventas venta, out string msjValida) { msjValida = ""; if (venta._usuario == 0) { msjValida = "El campo Usuario viene vacio" + "\n"; } if (venta._NroOperacion == 0) { msjValida += "El campo Numro de Operacion viene vacio" + "\n"; } if (venta._cantidad_productos == 0) { msjValida += "No se Agrego ningun producto ala venta" + "\n"; } if (venta._total_venta == 0) { msjValida += "El campo Total venta esta vacio" + "\n"; } if (msjValida.Equals("")) { DAOVentas cpVenta = new DAOVentas(); bool exito = cpVenta.insertaVentaEnBD(venta, out msjValida); if (exito == false) { msjValida = "Error en el proceso de Ingreso de la Venta " + msjValida; } } }