public void Agregar(Venta v, DetalleVenta dv) { db.cmd.CommandText = "INSERT INTO DetalleVenta(cantidad,descuento,precio,idVenta,idProducto) VALUES(@cantidad,@descuento,@precio,@idVenta,@idProducto)"; db.cmd.Parameters.AddWithValue("@cantidad", dv.Cantidad); db.cmd.Parameters.AddWithValue("@descuento", dv.Descuento); db.cmd.Parameters.AddWithValue("@precio", dv.Precio); db.cmd.Parameters.AddWithValue("@idVenta", v.IdVenta); db.cmd.Parameters.AddWithValue("@idProducto", dv.IdProducto); try { if (tipo) db.conn.Open(); db.cmd.ExecuteNonQuery(); if (tipo) db.conn.Close(); db.cmd.Parameters.Clear(); } catch (SqlException e) { MessageBox.Show(e.Message); } }
public void AgregarDetalle() { if (String.IsNullOrEmpty(TxtProducto)) { MessageBox.Show("No ha ingresado ningún producto", "AVISO", MessageBoxButton.OK, MessageBoxImage.Error); return; } DetalleVentaSQL dvsql = new DetalleVentaSQL(); Producto p = dvsql.Buscar(TxtProducto,idTienda); if (p == null) { return; } Evaluador ev = new Evaluador(); int nuevo = 1; int cant; List<DetalleVenta> aux = new List<DetalleVenta>(); foreach (DetalleVenta item in LstVenta) { if (item.IdProducto == p.IdProducto) { if (ev.esNumeroEntero(TxtCantidad) && ev.esPositivo(Convert.ToInt32(TxtCantidad))) item.Cantidad += Int32.Parse(TxtCantidad); else { MessageBox.Show("Tiene que poner una cantidad"); return; } item.SubTotal = item.Cantidad * p.Precio; //item.Descuento += CalculaDescuento(p.IdProducto, item.Cantidad); desc = 0;// item.Descuento; //TxtDescuentoTotal = desc.ToString(); total += Math.Round(Int32.Parse(TxtCantidad) * p.Precio, 2); TxtTotal = total.ToString(); subt = Math.Round(total / (1 + IGV), 2); TxtSubTotal = subt.ToString(); igv_total = Math.Round(subt * IGV, 2); TxtIGVTotal = igv_total.ToString(); TxtPagaCon = txtPagaCon; nuevo = 0; } aux.Add(item); } if (nuevo == 1) { DetalleVenta dv = new DetalleVenta(); dv.IdProducto = p.IdProducto; dv.CodProducto = p.CodigoProd; dv.Descripcion = p.Nombre; dv.Unidad = p.UnidadMedida; dv.Precio = p.Precio; if (ev.esNumeroEntero(TxtCantidad)) cant = Int32.Parse(TxtCantidad); else { MessageBox.Show("Tiene que poner una cantidad"); return; } dv.Descuento = CalculaDescuento(p.IdProducto,cant); dv.SubTotal = p.Precio * cant; dv.Cantidad = cant; aux.Add(dv); ActualizaCampos(dv,1); } LstVenta = aux; TxtCantidad = ""; }
private void ActualizaCampos(DetalleVenta dv, int tipo,List<DetalleVenta> lst = null) { //tipo = 1 -> aumenta detalle de venta if (tipo == 1) { desc += dv.Descuento; total += Math.Round(dv.SubTotal - desc, 2); subt = Math.Round(total / (1 + IGV), 2); igv_total = Math.Round(subt * IGV, 2); //TxtDescuentoTotal = desc.ToString(); TxtTotal = total.ToString(); TxtSubTotal = subt.ToString(); TxtIGVTotal = igv_total.ToString(); } //tipo 2 es para descontar al quitar una linea del detalle if (tipo == 2) { desc -= dv.Descuento; total -= Math.Round(dv.SubTotal - dv.Descuento, 2); subt = Math.Round(total / (1 + IGV), 2); igv_total = Math.Round(subt * IGV, 2); TxtDescuentoTotal = desc.ToString(); TxtTotal = total.ToString(); TxtSubTotal = subt.ToString(); TxtIGVTotal = igv_total.ToString(); /*int c = lst.Count(); if (c == 0) { TxtDescuentoTotal = ""; TxtTotal = ""; TxtSubTotal = ""; TxtIGVTotal = ""; }*/ } TxtPagaCon = txtPagaCon; }
public void SelectedItemChanged(object sender) { detalleSeleccionado = ((sender as DataGrid).SelectedItem as DetalleVenta); }
private void descontarDeSector(Venta v, DetalleVenta dv, int tipoDescuento=1) { int idTienda = new TiendaSQL().obtenerTienda(v.IdUsuario); db.cmd.CommandText = "SELECT * FROM Almacen WHERE idTienda=@idTienda AND tipo=@tipo"; db.cmd.Parameters.AddWithValue("@idTienda", idTienda); db.cmd.Parameters.AddWithValue("@tipo", 2); SqlDataReader rs2 = db.cmd.ExecuteReader(); rs2.Read(); int idAlmacen = Convert.ToInt32(rs2["idAlmacen"].ToString()); rs2.Close(); db.cmd.Parameters.Clear(); if (tipoDescuento == 2) // cuando se tiene que reponer el stock { db.cmd.CommandText = "UPDATE Sector SET cantidad=cantidad+@cantidad WHERE idAlmacen=@idAlmacen AND idProducto=@idProducto; UPDATE ProductoxTienda SET stockActual=stockActual+@cantidad WHERE idTienda=@idTienda AND idProducto=@idProducto"; } else { db.cmd.CommandText = "UPDATE Sector SET cantidad=cantidad-@cantidad WHERE idAlmacen=@idAlmacen AND idProducto=@idProducto; UPDATE ProductoxTienda SET stockActual=stockActual-@cantidad WHERE idTienda=@idTienda AND idProducto=@idProducto"; } db.cmd.Parameters.AddWithValue("@cantidad", dv.Cantidad); db.cmd.Parameters.AddWithValue("@idAlmacen", idAlmacen); db.cmd.Parameters.AddWithValue("@idProducto", dv.IdProducto); db.cmd.Parameters.AddWithValue("@idTienda", idTienda); try { if (tipo) db.conn.Open(); db.cmd.ExecuteNonQuery(); db.cmd.Parameters.Clear(); if (tipo) db.conn.Close(); } catch (SqlException e) { MessageBox.Show(e.Message); } }
public int Actualizar(DetalleVenta dv) { throw new NotImplementedException(); }
public List<DetalleVenta> BuscarTodos(int idVenta = 0) { List<DetalleVenta> lista = new List<DetalleVenta>(); if (idVenta == 0) { db.cmd.CommandText = "select * from DetalleVenta "; } else { db.cmd.CommandText = "select * from DetalleVenta where idVenta=@idVenta"; db.cmd.Parameters.AddWithValue("@idVenta", idVenta); } try { if (tipo) db.conn.Open(); SqlDataReader reader = db.cmd.ExecuteReader(); while (reader.Read()) { DetalleVenta d = new DetalleVenta(); d.IdProducto = Convert.ToInt32(reader["idProducto"].ToString()); d.IdDetalleV = Convert.ToInt32(reader["idVenta"].ToString()); d.Descuento = Convert.ToDouble(reader["descuento"].ToString()); d.Cantidad = Convert.ToInt32(reader["cantidad"].ToString()); lista.Add(d); } reader.Close(); db.cmd.Parameters.Clear(); if (tipo) db.conn.Close(); } catch (SqlException e) { MessageBox.Show(e.Message); } return lista; }