private void LLenaCampo(Colectas colectas)
 {
     IdNumericUpDown.Value   = colectas.ColectasId;
     DescripcionTextBox.Text = colectas.Descripcion;
     MetaTextBox.Text        = colectas.Meta.ToString();
     LogradoTextBox.Text     = colectas.Logrado.ToString();
 }
        private Colectas LLenaClase()
        {
            Colectas colectas = new Colectas();

            colectas.ColectasId  = Convert.ToInt32(IdNumericUpDown.Value);
            colectas.Descripcion = DescripcionTextBox.Text;
            colectas.Meta        = Convert.ToDouble(MetaTextBox.Text);

            return(colectas);
        }
        private void BuscarButton_Click(object sender, EventArgs e)
        {
            Colectas colectas = new Colectas();
            int      id;

            int.TryParse(IdNumericUpDown.Text, out id);

            Limpiar();
            colectas = ColectasBLL.Buscar(id);

            if (colectas != null)
            {
                LLenaCampo(colectas);
            }
            else
            {
                MessageBox.Show("Colectas no encontrado", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        public static Colectas Buscar(int id)
        {
            Contexto db       = new Contexto();
            Colectas colectas = new Colectas();

            try
            {
                colectas = db.Colectas.Find(id);
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                db.Dispose();
            }
            return(colectas);
        }
        public static bool Modificar(Colectas colectas)
        {
            bool     paso = false;
            Contexto db   = new Contexto();

            try
            {
                db.Entry(colectas).State = EntityState.Modified;
                paso = db.SaveChanges() > 0;
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                db.Dispose();
            }
            return(paso);
        }
        private static bool Insertar(Colectas colectas)
        {
            bool paso     = false;
            var  contexto = new Contexto();

            try
            {
                contexto.Colectas.Add(colectas);
                paso = contexto.SaveChanges() > 0;
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                contexto.Dispose();
            }

            return(paso);
        }
        public static bool Guardar(Colectas colectas)
        {
            bool     paso = false;
            Contexto db   = new Contexto();

            try
            {
                if (db.Colectas.Add(colectas) != null)
                {
                    paso = db.SaveChanges() > 0;
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                db.Dispose();
            }
            return(paso);
        }
        private bool ExisteEnLaBaseDeDatos()
        {
            Colectas colectas = ColectasBLL.Buscar((int)IdNumericUpDown.Value);

            return(colectas != null);
        }