private void btnGuardar_Click(object sender, EventArgs e) { if (!validar()) { } else { if (!(dataGridView1.SelectedRows.Count == 0)) { int idmed = int.Parse(dataGridView1.CurrentRow.Cells[0].Value.ToString()); int cantidad = int.Parse(txtCantidadIngresada.Text); Model model = new Model(); Medicamentos med = new Medicamentos(); InventarioMedicamentos im = new InventarioMedicamentos(); InventarioMedicamentos old = new InventarioMedicamentos(); old = model.Entidades.InventarioMedicamentos.Find(idmed); if (idmed != old.idmedicamento) { im.fechaCaducidad = dtFecha.Value.Date; im.CodLote = txtLote.Text; im.idmedicamento = idmed; string idprovee = cmbFabricante.SelectedItem.ToString(); proveedores p = model.Entidades.proveedores.Single(a => a.Nombre.Equals(idprovee)); im.idproveedor = p.idproveedor; if ((controladorinventario.insertarAinventario(im))) { MessageBox.Show("ok"); } else { MessageBox.Show("ERROR"); } } else // ACTUALIZA EL INVENTARIO DE MEDICAMENTOS { MessageBox.Show("ERROR COMPADRE"); } }//fin seleccion else { MessageBox.Show("POR FAVOR, SELECCIONE UNA OPCION"); } } /* * */ }
public bool insertarAinventario(InventarioMedicamentos im) { try { Model model = new Model(); model.Entidades.InventarioMedicamentos.Add(im); model.Entidades.SaveChanges(); model.cerrarConexion(); } catch (Exception ex) { return(false); } return(true); }
public bool eliminarInv(int id) { try { Model model = new Model(); InventarioMedicamentos original = model.Entidades.InventarioMedicamentos.Find(id); model.Entidades.InventarioMedicamentos.Remove(original); model.Entidades.SaveChanges(); model.cerrarConexion(); } catch (Exception ex) { return(false); } return(true); }
public bool modificarInv(int id, InventarioMedicamentos inv) { try { Model model = new Model(); InventarioMedicamentos original = model.Entidades.InventarioMedicamentos.Find(id); original.CodLote = inv.CodLote; model.Entidades.SaveChanges(); model.cerrarConexion(); } catch (Exception ex) { return(false); } return(true); }