public static bool Modificar(rEntradaArt rEntradaArt) { bool paso = false; Contexto contexto = new Contexto(); try { rEntradaArt art = BLL.rEntradaArtBLL.Buscar(rEntradaArt.EntradaId); int resta; resta = rEntradaArt.Cantidad - art.Cantidad; Articulos articulos = BLL.ArticulosBLL.Buscar(rEntradaArt.ArticuloId); articulos.Inventario += resta; BLL.ArticulosBLL.Modificar(articulos); contexto.Entry(rEntradaArt).State = EntityState.Modified; if (contexto.SaveChanges() > 0) { paso = true; } contexto.Dispose(); } catch (Exception) { throw; } return(paso); }
public static bool Eliminar(int id) { bool paso = true; Contexto contexto = new Contexto(); try { rEntradaArt rEntradaArt = contexto.rEntradaArts.Find(id); if (rEntradaArt != null) { Articulos articulos = BLL.ArticulosBLL.Buscar(rEntradaArt.EntradaId); articulos.Inventario -= rEntradaArt.Cantidad; BLL.ArticulosBLL.Modificar(articulos); contexto.Entry(rEntradaArt).State = EntityState.Deleted; } if (contexto.SaveChanges() > 0) { paso = true; contexto.Dispose(); } } catch (Exception) { throw; } return(paso); }
public static bool Guardar(rEntradaArt rEntradaArt) { bool paso = false; Contexto contexto = new Contexto(); try { if (contexto.rEntradaArts.Add(rEntradaArt) != null) { Articulos articulos = BLL.ArticulosBLL.Buscar(rEntradaArt.ArticuloId); articulos.Inventario += rEntradaArt.Cantidad; BLL.ArticulosBLL.Modificar(articulos); contexto.SaveChanges(); paso = true; } contexto.Dispose(); } catch (Exception) { throw; } return(paso); }
private rEntradaArt LlenarClase() { rEntradaArt rEntradaArt = new rEntradaArt(); rEntradaArt.EntradaId = Convert.ToInt32(EntradaIDNumericUpDown.Value); rEntradaArt.ArticuloId = (int)ArticuloComboBox.SelectedValue; rEntradaArt.Fecha = FechaDateTimePicker1.Value.Date; rEntradaArt.Cantidad = Convert.ToInt32(CantidadNumericUpDown2.Value); return(rEntradaArt); }
public static rEntradaArt Buscar(int id) { rEntradaArt rEntradaArt = new rEntradaArt(); Contexto contexto = new Contexto(); try { rEntradaArt = contexto.rEntradaArts.Find(id); contexto.Dispose(); } catch (Exception) { throw; } return(rEntradaArt); }
private void Guardarbutton_Click(object sender, EventArgs e) { bool paso = false; //if(Validar(2)) //{ // MessageBox.Show("llenar todos los compos marcados"); // return; //} if (EntradaIDNumericUpDown.Value == 0) { paso = BLL.rEntradaArtBLL.Guardar(LlenarClase()); } else { int id = Convert.ToInt32(EntradaIDNumericUpDown.Value); rEntradaArt rEntradaArt = BLL.rEntradaArtBLL.Buscar(id); if (rEntradaArt != null) { paso = BLL.rEntradaArtBLL.Modificar(LlenarClase()); } else { MessageBox.Show("Id no existe", "Fallo", MessageBoxButtons.OK, MessageBoxIcon.Error); } } if (paso) { MessageBox.Show("Guardo", "Exito", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("No se guardo", "Fallo", MessageBoxButtons.OK, MessageBoxIcon.Error); } GeneralErrorProvider.Clear(); }
private void BuscarButtonT_Click(object sender, EventArgs e) { //if (Validar(1)) //{ // MessageBox.Show("Ingrese el ID"); // return; //} int id = Convert.ToInt32(EntradaIDNumericUpDown.Value); rEntradaArt rEntradaArt = BLL.rEntradaArtBLL.Buscar(id); if (rEntradaArt != null) { EntradaIDNumericUpDown.Value = rEntradaArt.EntradaId; ArticuloComboBox.Text = rEntradaArt.ArticuloId.ToString(); CantidadNumericUpDown2.Value = rEntradaArt.Cantidad; } else { MessageBox.Show("No se encontro", "Fallo", MessageBoxButtons.OK, MessageBoxIcon.Error); } GeneralErrorProvider.Clear(); }