コード例 #1
0
        /// <summary>
        /// Agrega datos a la base de datos con el objeto Voluntario como parámetro
        /// </summary>
        /// <param name="voluntario"></param>
        /// <returns>
        /// true si agrega el datos
        /// false si no valida los datos de la ventana o si no logra agregar el dato a la base de datos
        /// </returns>
        public bool AgregarDatosConObjeto(Voluntario voluntario)
        {
            if (ValidarConObjeto(voluntario))
            {
                using (SqlConnection connection = new SqlConnection("Data Source=JOSE-DAVID" + @"\JD;Initial Catalog=Prueba;Integrated Security=True"))
                {
                    using (SqlCommand command = new SqlCommand())
                    {
                        command.Connection  = connection;           // <== lacking
                        command.CommandType = CommandType.Text;
                        command.CommandText = "INSERT into Tbl_Voluntario (identificacion, fecha, nombre, apellido1, apellido2, telefono, profesion, domicilio, inscripcion, donacion, correo) VALUES (@identificacion, @fecha, @nombre, @apellido1, @apellido2, @telefono, @profesion, @domicilio, @inscripcion, @donacion, @correo)";
                        command.Parameters.AddWithValue("@identificacion", voluntario.Get_identificacion());
                        command.Parameters.AddWithValue("@fecha", voluntario.Get_fecha());
                        command.Parameters.AddWithValue("@nombre", voluntario.Get_nombre());
                        command.Parameters.AddWithValue("@apellido1", voluntario.Get_primerApellido());
                        command.Parameters.AddWithValue("@apellido2", voluntario.Get_segundoApellido());
                        command.Parameters.AddWithValue("@telefono", voluntario.Get_telefono());
                        command.Parameters.AddWithValue("@profesion", voluntario.Get_profesion());
                        command.Parameters.AddWithValue("@domicilio", voluntario.Get_domicilio());
                        command.Parameters.AddWithValue("@inscripcion", _inscripcion);
                        command.Parameters.AddWithValue("@donacion", _donacion);
                        command.Parameters.AddWithValue("@correo", voluntario.Get_correo());


                        try
                        {
                            connection.Open();
                            int recordsAffected = command.ExecuteNonQuery();
                        }
                        catch (SqlException)
                        {
                            MessageBox.Show("Catch Voluntario");
                        }
                        finally
                        {
                            connection.Close();
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("Faltan datos Voluntario");
                return(false);
            }
            return(true);
        }
コード例 #2
0
 /// <summary>
 /// Valida que los datos estén en los TextBox de la ventana AlimentandoEsperanzas en la pestaña de Voluntario
 /// </summary>
 /// <param name="voluntario"></param>
 /// <returns>
 /// true si valida correctamente
 /// false si hay un campo vacío
 /// </returns>
 public bool ValidarConObjeto(Voluntario voluntario)
 {
     if (string.IsNullOrWhiteSpace(voluntario.Get_identificacion()) ||
         string.IsNullOrWhiteSpace(voluntario.Get_nombre()) ||
         string.IsNullOrWhiteSpace(voluntario.Get_fecha()) ||
         string.IsNullOrWhiteSpace(voluntario.Get_primerApellido()) ||
         string.IsNullOrWhiteSpace(voluntario.Get_segundoApellido()) ||
         string.IsNullOrWhiteSpace(voluntario.Get_telefono()) ||
         string.IsNullOrWhiteSpace(voluntario.Get_profesion()) ||
         string.IsNullOrWhiteSpace(voluntario.Get_domicilio()) ||
         string.IsNullOrWhiteSpace(_inscripcion) ||
         string.IsNullOrWhiteSpace(_donacion)
         )
     {
         return(false);
     }
     else
     {
         return(true);
     }
 }