private EArticulosImport[] LeerArchivo(string path) { var engine = new FileHelperEngine <EArticulosImport>(); // Switch error mode on engine.ErrorManager.ErrorMode = ErrorMode.SaveAndContinue; var productosLeídos = engine.ReadFile(pathLectura); if (engine.ErrorManager.HasErrors) { engine.ErrorManager.SaveErrors(@"C:/Temp/erroresLectura.txt"); MessageBox.Show("Ver C:/Temp/erroresLectura.txt", "Error"); _lecturaArchivo = false; } foreach (var item in productosLeídos) { if (item.Id == 0) //Alta { EArticulosRepository.ProcesarAltaProducto(item); } if (item.Id > 0) //Modificación { EArticulosRepository.ProcesarModificacionProducto(item); } if (item.LecturaArchivo == 2) { _lecturaArchivo = false; } } return(productosLeídos); }
private void btnEditar_Click(object sender, EventArgs e) { EArticulos a = ObtenerArticuloSeleccionado(); using (var f = new frmEdicion(a)) { if (f.ShowDialog() == DialogResult.OK) { try { int IdEmpresa = Lib.Configuration.IdEmpresa; EArticulosRepository.Actualizar(a.Id, IdEmpresa, f.CodigoBarra, f.Descripcion, f.IdMarca, f.IdRubro, f.IdProveedor, f.IdUnidad, f.CostoInicial, f.Descuento1, f.DescuentoPorc1, f.Descuento2, f.DescuentoPorc2, f.Descuento3, f.DescuentoPorc3, f.Costo, f.Stock, f.StockMinimo, f.Lista1, f.ListaPorc1, f.Lista2, f.ListaPorc2, f.Lista3, f.ListaPorc3, f.IVA, f.Observaciones, f.Estado); ConsultarDatos(); dgvDatos.SetRow(r => Convert.ToDecimal(r.Cells[0].Value) == a.Id); } catch (Exception ex) { ShowError("Error al intentar grabar los datos: \n" + ex.Message); } } } }
private void CargarProductosDescripcion() { var a = EArticulosRepository.ObtenerArticulos(); cbArticulos.DataSource = a; cbArticulos.DisplayMember = "Descripcion"; cbArticulos.ValueMember = "Id"; if (a.Any()) { cbClientes.SelectedIndex = 0; } }
private void CargarProductosCodBarra() { var a = EArticulosRepository.ObtenerArticulos(); cbArticulos.DataSource = a; cbArticulos.DisplayMember = "CodBarra"; cbArticulos.ValueMember = "Id"; if (a.Any()) { cbProveedores.SelectedIndex = 0; } }
private void cargarDetalles(int idRemito) { dgvDetalles.SetDataSource( from d in RemitosDetallesRepository.ObtenerDetallesDelRemito(idRemito) select new { EArticulosRepository.ObtenerArticulosPorId( Convert.ToDecimal(d.IdArticulo)).Descripcion, d.Cantidad } ); }
private void cargarDetalles(int idCompra) { dgvDetalles.SetDataSource( from d in EComprasDetallesRepository.ObtenerDetallesDeCompra(idCompra) select new { EArticulosRepository.ObtenerArticulosPorId( Convert.ToDecimal(d.IdArticulo)).Descripcion, d.Precio, d.Cantidad, d.Importe } ); }
private EArticulos ObtenerArticuloSeleccionado() { try { int rowindex = dgvDatos.CurrentCell.RowIndex; var id = (Int32)dgvDatos.Rows[rowindex].Cells[0].Value; var a = EArticulosRepository.ObtenerArticulosPorId(id); return(a); } catch (Exception) { return(null); } }
private void AgregarArticulo(int idarticulo) { var art = EArticulosRepository.ObtenerArticulosPorId(idarticulo); if (buscarArticuloEnDetalle(idarticulo)) { modificarCantidadDetalles(_filaArticulo); } else { decimal precio = EArticulosRepository.ObtenerArticulosPorId(art.Id).Costo; dgvDetalles.Rows.Add(art.Id, art.CodBarra, art.Descripcion, 1, precio, precio); modificarCantidadDetalles(dgvDetalles.Rows.Count - 1); calcularImportes(); } }
private static void Exportar() { var engine = new FileHelperAsyncEngine <EArticulosImport>(); var productos = EArticulosRepository.ObtenerArticulosParaExportar(); var destino = VerificarDestino(); using (engine.BeginWriteFile(destino)) { foreach (EArticulosImport cust in productos) { engine.WriteNext(cust); } } string ver = string.Format(@"Buscar en C:/Temp/Productos {0:dd-MM-yyyy}.txt", DateTime.Now); MessageBox.Show(ver, "Error"); }
private void AgregarArticulo(int idarticulo) { var art = EArticulosRepository.ObtenerArticulosPorId(idarticulo); if (buscarArticuloEnDetalle(idarticulo)) { modificarCantidadDetalles(_filaArticulo); } else { //decimal precio = ObtenerPrecioPorLista(Convert.ToInt16(cbLista.Text), art.Id); //dgvDetalles.Rows.Add(art.Id, art.CodBarra, art.Descripcion, 1, precio, precio); dgvDetalles.Rows.Add(art.Id, art.CodBarra, art.Descripcion, 1); modificarCantidadDetalles(dgvDetalles.Rows.Count - 1); //calcularImportes(); } }
private decimal ObtenerPrecioPorLista(short lista, int idarticulo) { decimal precio = -1; var articulo = EArticulosRepository.ObtenerArticulosPorId(idarticulo); if (lista == 1 && articulo.PrecioL1 > 0) { precio = Convert.ToDecimal(articulo.PrecioL1); } if (lista == 2 && articulo.PrecioL2 > 0) { precio = Convert.ToDecimal(articulo.PrecioL2); } if (lista == 3 && articulo.PrecioL3 > 0) { precio = Convert.ToDecimal(articulo.PrecioL3); } return(precio); }
private void ConsultarDatos() { // var tds = TiposDocumentoRepository.ObtenerTiposDocumento(); dgvDatos.SetDataSource(from a in EArticulosRepository.ObtenerArticulos() orderby a.Id select new { a.Id, a.CodBarra, a.Descripcion, a.Stock, a.StockMinimo, a.Costo, a.PrecioL1, a.PrecioL2, a.PrecioL3 }); dgvDatos.Columns[0].Visible = false; }
private void btnEliminar_Click(object sender, EventArgs e) { var a = ObtenerArticuloSeleccionado(); if (MessageBox.Show("¿Está seguro de que desea eliminar el articulo seleccionado?", "Eliminar Artículos", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { try { EArticulosRepository.Eliminar(a.Id); ConsultarDatos(); dgvDatos.SetRow(r => Convert.ToDecimal(r.Cells[0].Value) == a.Id); } catch (Exception ex) { ShowError(ex.Message); } } }
private void NuevaCompra() { using (var f = new frmEdicion()) { if (f.ShowDialog() == DialogResult.OK) { try { var compra = EComprasRepository.Insertar(f.IdProveedor, f.Fecha, f.ImporteTotal, f.Retirado, f.Pagado, f.IdUsuario); for (int i = 0; i <= Convert.ToInt32(f.dgvDetalles.Rows.Count - 1); i++) { EComprasDetallesRepository.Insertar(compra.Id, Convert.ToInt32(f.dgvDetalles.Rows[i].Cells[0].Value), Convert.ToInt16(f.dgvDetalles.Rows[i].Cells[3].Value), Convert.ToDecimal(f.dgvDetalles.Rows[i].Cells[4].Value), Convert.ToDecimal(f.dgvDetalles.Rows[i].Cells[5].Value)); } //if (Configuration.ImprimeVentas) ImprimirVenta(f, venta.Id); if (Configuration.CompraIncrementaStock) { for (int i = 0; i <= Convert.ToInt32(f.dgvDetalles.Rows.Count - 1); i++) { EArticulosRepository.IncrementarStockArticulo(Convert.ToInt32(f.dgvDetalles.Rows[i].Cells[0].Value), Convert.ToInt16(f.dgvDetalles.Rows[i].Cells[3].Value)); } } if (f.Pagado == 1) { MovimientosRepository.InsertarCompra(compra); } ConsultarDatos(); dgvDatos.SetRow(r => Convert.ToDecimal(r.Cells[0].Value) == compra.Id); } catch (Exception ex) { ShowError("Error al intentar grabar los datos: \n" + ex.Message); } } } }
private void btnGuardar_Click(object sender, EventArgs e) { _lecturaArchivo = true; if (string.IsNullOrEmpty(pathLectura)) { MessageBox.Show("Debe seleccionar el archivo a importar...", "Atención"); return; } var productosLeídos = LeerArchivo(pathLectura); if (!_lecturaArchivo) { MessageBox.Show("Cargar el archivo.", "Error"); return; } foreach (var item in productosLeídos) { EArticulosRepository.GuardarProductoLeidoPorTxt(item); } }
private void GuardarVenta() { EVentas _venta = new EVentas(); List <EVentasDetalles> _detalleVenta = new List <EVentasDetalles>(); try { _venta.IdCliente = IdCliente; _venta.Fecha = Fecha; _venta.Importe = Subtotal; _venta.Descuento = Descuento; _venta.DescuentoPorc = DescPorc; _venta.ImporteTotal = ImporteTotal; _venta.PrecioLista = PrecioLista; _venta.IdUsuario = IdUsuario; _venta.Estado = Estado; var idVentaRegistrada = VentasRepository.Insertar(_venta); if (idVentaRegistrada == 0) { MessageBox.Show("Error al registrar Venta", "Registrar venta"); return; } for (int i = 0; i <= Convert.ToInt32(dgvDetalles.Rows.Count - 1); i++) { EVentasDetalles detalle = new EVentasDetalles(); detalle.IdArticulo = Convert.ToInt32(dgvDetalles.Rows[i].Cells[0].Value); detalle.Cantidad = Convert.ToInt32(dgvDetalles.Rows[i].Cells[3].Value); detalle.Precio = Convert.ToInt32(dgvDetalles.Rows[i].Cells[4].Value); detalle.Importe = Convert.ToInt32(dgvDetalles.Rows[i].Cells[5].Value); detalle.IdVenta = idVentaRegistrada; _detalleVenta.Add(detalle); if (!VentasDetallesRepository.Insertar(detalle)) { VentasRepository.EliminarVentaRegistradaIncorrectamente(idVentaRegistrada); VentasDetallesRepository.EliminarDetallesVentaRegistradosIncorrectamente(idVentaRegistrada); MessageBox.Show("Error al registrar Venta", "Registrar venta"); return; } } if (Configuration.ImprimeVentas) { ImprimirVenta(_venta.Id); } if (Configuration.VentaDescuentaStock) { foreach (var item in _detalleVenta) { EArticulosRepository.DescontarStockArticulo( Convert.ToDecimal(item.IdArticulo), Convert.ToDecimal(item.Cantidad)); } } if (Configuration.SoloCobroEfectivo) { } MessageBox.Show("Venta registrada correctamente", "Registrar venta"); LimpiarVentana(); } catch (Exception ex) { ShowError("Error al intentar leer los datos: \n" + ex.Message); } }