public bool RegistrarDetalleIngreso(EDetalleIngreso entidad) { if (Validar(entidad)) { return(detalleIngreso.Registrar(entidad)); } else { return(false); } }
public List <EDetalleIngreso> Mostrar(int idIngreso) { var cadena = ConfigurationManager.ConnectionStrings["Cnn"].ConnectionString; var lista = new List <EDetalleIngreso>(); using (var cn = new SqlConnection(cadena)) { try { if (cn.State == ConnectionState.Closed) { cn.Open(); } using (var cmd = cn.CreateCommand()) { cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "MostrarDetalleIngreso"; cmd.Parameters.AddWithValue("@IdIngreso", idIngreso); var drd = cmd.ExecuteReader(); while (drd.Read()) { var enti = new EDetalleIngreso() { IdArticulo = drd.GetInt32(drd.GetOrdinal("IdArticulo")), Articulo = drd.GetString(drd.GetOrdinal("Articulo")), PrecioCompra = drd.GetDecimal(drd.GetOrdinal("PrecioCompra")), PrecioVenta = drd.GetDecimal(drd.GetOrdinal("PrecioVenta")), StockInicial = drd.GetInt32(drd.GetOrdinal("StockInicial")), FecProduccion = drd.GetDateTime(drd.GetOrdinal("FecProduccion")), FecVencimiento = drd.GetDateTime(drd.GetOrdinal("FecVencimiento")), Subtotal = drd.GetDecimal(drd.GetOrdinal("Subtotal")) }; lista.Add(enti); } } } catch (SqlException e) { MessageBox.Show(e.Message, "SQL Error Mostrar Detalle ingreso", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { if (cn.State == ConnectionState.Open) { cn.Close(); } } } return(lista); }
public bool Registrar(EDetalleIngreso entidad) { var cadena = ConfigurationManager.ConnectionStrings["Cnn"].ConnectionString; int res = 0; using (var cn = new SqlConnection(cadena)) { try { if (cn.State == ConnectionState.Closed) { cn.Open(); } using (var cmd = cn.CreateCommand()) { cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "RegistrarDetalleIngreso"; cmd.Parameters.AddWithValue("@IdIngreso", entidad.IdIngreso); cmd.Parameters.AddWithValue("@IdArticulo", entidad.IdArticulo); cmd.Parameters.AddWithValue("@PrecioCompra", entidad.PrecioCompra); cmd.Parameters.AddWithValue("@PrecioVenta", entidad.PrecioVenta); cmd.Parameters.AddWithValue("@StockInicial", entidad.StockInicial); cmd.Parameters.AddWithValue("@StockActual", entidad.StockActual); cmd.Parameters.AddWithValue("@FecProduccion", entidad.FecProduccion); cmd.Parameters.AddWithValue("@FecVencimiento", entidad.FecVencimiento); res = cmd.ExecuteNonQuery(); } } catch (SqlException e) { MessageBox.Show(e.Message, "SQL Error Registrar Detalle ingreso", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { if (cn.State == ConnectionState.Open) { cn.Close(); } } } if (res == 1) { return(true); } else { return(false); } }
private bool Validar(EDetalleIngreso entidad) { builder.Clear(); if (entidad.PrecioCompra <= 0) { builder.Append("Ingrese un Precio de compra válido"); } if (entidad.PrecioVenta <= 0) { builder.Append("\nIngrese un Precio de venta válido"); } if (entidad.StockInicial < 0) { builder.Append("\nIngrese un Stock inicial válido"); } if (entidad.StockActual < 0) { builder.Append("\nNo se ha podido ingresar el Stock actual"); } return(builder.Length == 0); }
private void BtnGuardar_Click(object sender, EventArgs e) { try { if (entiIngreso == null) { entiIngreso = new EIngreso(); } entiIngreso.IdTrabajador = UserCache.IdTrabajador; entiIngreso.IdProveedor = Convert.ToInt32(lblIdProveedor.Text); entiIngreso.Fecha = dtpFecha.Value; entiIngreso.TipoComprobante = cmbComprobante.Text; entiIngreso.Serie = txtSerie.Text.Trim(); entiIngreso.Correlativo = txtCorrelativo.Text.Trim(); entiIngreso.Igv = Convert.ToDecimal(txtIgv.Text.Trim()); entiIngreso.Estado = "EMITIDO"; //Capturamos el IdUltimo int idUltimo = ingreso.RegistrarIngreso(entiIngreso); if (idUltimo > 0) { MessageBox.Show("¡Ingreso a almacén con éxito!", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Information); //Regsitramos el Detalle ingreso if (entiDetalle == null) { entiDetalle = new EDetalleIngreso(); } int numFilas = dgvDetalleIngresos.Rows.Count; int contador = 0; for (int i = 0; i < numFilas; i++) { entiDetalle.IdIngreso = idUltimo; entiDetalle.IdArticulo = Convert.ToInt32(dgvDetalleIngresos.Rows[i].Cells[0].Value.ToString()); entiDetalle.PrecioCompra = Convert.ToDecimal(dgvDetalleIngresos.Rows[i].Cells[2].Value.ToString()); entiDetalle.PrecioVenta = Convert.ToDecimal(dgvDetalleIngresos.Rows[i].Cells[3].Value.ToString()); entiDetalle.StockInicial = Convert.ToInt32(dgvDetalleIngresos.Rows[i].Cells[4].Value.ToString()); entiDetalle.StockActual = Convert.ToInt32(dgvDetalleIngresos.Rows[i].Cells[4].Value.ToString()); entiDetalle.FecProduccion = Convert.ToDateTime(dgvDetalleIngresos.Rows[i].Cells[5].Value.ToString()); entiDetalle.FecVencimiento = Convert.ToDateTime(dgvDetalleIngresos.Rows[i].Cells[6].Value.ToString()); if (!detalle.RegistrarDetalleIngreso(entiDetalle)) { contador++; } } if (contador == 0) { MessageBox.Show("¡Detalle de ingreso registrado con éxito!", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Information); } } if (ingreso.builder.Length != 0) { MessageBox.Show(ingreso.builder.ToString(), "INGRESO: Para continuar", MessageBoxButtons.OK, MessageBoxIcon.Warning); if (detalle.builder.Length != 0) { MessageBox.Show(detalle.builder.ToString(), "DETALLE INGRESO: Para continuar", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error inesperado", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { MostrarIngreso(); LimpiarIngreso(); Deshabilitar(); btnNuevo.Enabled = true; EliminarFilaDetalleIngreso(); } }