private bool ExisteEnLaBaseDeDatos()
        {
            Repositorio <Alergias> db = new Repositorio <Alergias>();
            Alergias alergias         = db.Buscar((int)IdNumericUpDown.Value);

            return(alergias != null);
        }
        private Alergias LlenarClase()
        {
            Alergias alergias = new Alergias();

            alergias.AlergiasId  = (int)IdNumericUpDown.Value;
            alergias.Descripcion = DescripcionTextBox.Text;
            return(alergias);
        }
        private void GuardarButton_Click(object sender, EventArgs e)
        {
            bool paso = false;
            Repositorio <Alergias> db = new Repositorio <Alergias>();
            Alergias A = new Alergias();

            if (!Validar())
            {
                return;
            }

            A = LlenarClase();
            if (IdNumericUpDown.Value == 0)
            {
                if (!ValidarRepetir())
                {
                    return;
                }
                paso = db.Guardar(A);
            }
            else
            {
                if (!ExisteEnLaBaseDeDatos())
                {
                    MessageBox.Show("No se puede modificar una Alergia que no existe", "fallo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                paso = db.Modificar(A);
            }
            if (!ExisteEnLaBaseDeDatos())
            {
                if (paso)
                {
                    MessageBox.Show("Guardado!!", "Exito", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            else
            {
                if (paso)
                {
                    MessageBox.Show("Modificado!!", "Exito", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("No fue posible guardar!!", "Fallo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            Limpiar();
        }
        private void BuscarButton_Click(object sender, EventArgs e)
        {
            int      id;
            Alergias alergias         = new Alergias();
            Repositorio <Alergias> db = new Repositorio <Alergias>();

            int.TryParse(IdNumericUpDown.Text, out id);
            Limpiar();
            alergias = db.Buscar(id);

            if (alergias != null)
            {
                LLenarCampo(alergias);
            }
            else
            {
                MessageBox.Show("alergia no encontrado");
            }
        }
 private void LLenarCampo(Alergias alergias)
 {
     IdNumericUpDown.Value   = alergias.AlergiasId;
     DescripcionTextBox.Text = alergias.Descripcion;
 }