private void btnGuardar_Click_1(object sender, EventArgs e)
        {
            Habitante habitante = new Habitante();

            if (txtPrimer_Nombre.Text != null && txtApellido_Paterno.Text != null && txtApellido_Materno.Text != null &&
                txtCarnet.Text != null && cboxCarnet.Text != "" && cboxSexo.Text != "" && txtCalle.Text != null &&
                txtZona.Text != null)
            {
                habitante.Id_TipoHabitante = tipoHabitante;
                habitante.PrimerNombre     = txtPrimer_Nombre.Text;
                habitante.SegundoNombre    = txtSegundo_Nombre.Text;
                habitante.ApellidoPaterno  = txtApellido_Paterno.Text;
                habitante.ApellidoMaterno  = txtApellido_Materno.Text;
                habitante.Carnet           = txtCarnet.Text;
                habitante.ExtencionCI      = cboxCarnet.SelectedItem.ToString();
                habitante.Sexo             = sex;
                habitante.Calle            = txtCalle.Text;
                habitante.Zona             = txtZona.Text;
                habitante.Fotografia       = ubicacion.ToString();

                int resultado = GestionarHabitante.AgregarHabitante(habitante);
                if (resultado > 0)
                {
                    MessageBox.Show("El Habitante se registro exitosamente!!", "Guardado", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("No se logro registrar el habitante", "Error en el registro", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
            else
            {
                MessageBox.Show("Debe llenar todos los campos requeridos obligatoriamente [*]", "Error en el registro", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        public MySqlDataReader BuscarHabitante(Habitante habitante)
        {
            //Instanciamos a la clase de conexion a la BD
            BDConexion cn = new BDConexion();

            //Hacemos el enalce a nuestra BD
            conexionBD = cn.ObtenerConexion();
            //Creamos una variable donde obtendremos todos los datos
            MySqlDataReader obtenerDatos = null;

            string buscarHabitante = "SELECT h.id_Habitante, concat_ws(' ', h.primerNombre, h.segundoNombre) as NOMBRES, concat_ws(' ', h.apellidoPaterno, h.apellidoMaterno) as APELLIDOS, h.ci, concat_ws(' ', h.zona, h.calle) as DIRECCION, h.sexo, t.tipoHabitante as TIPO " +
                                     "FROM habitante h, tipo_habitante t " +
                                     "WHERE h.id_TipoHabitante = t.id_TipoHabitante " +
                                     "AND h.ci = '" + habitante.Carnet + "'";

            /*[CONSULTA]
             * SELECT h.id_Habitante, concat_ws(' ', h.primerNombre, h.segundoNombre) as NOMBRES, concat_ws(' ', h.apellidoPaterno, h.apellidoMaterno) as APELLIDOS, h.ci, concat_ws(' ', h.zona, h.calle) as DIRECCION, h.sexo, t.tipoHabitante as TIPO
             * FROM habitante h, tipo_habitante t
             * WHERE h.id_TipoHabitante = t.id_TipoHabitante
             * AND h.ci = '6041597';
             *
             *
             * ALTER TABLE habitante ADD extencionCI char(10) not null
             *                      AFTER ci;
             *
             *
             * SELECT concat_ws(' ', h.primerNombre, h.segundoNombre, h.apellidoPaterno, h.apellidoMaterno) as NOMBRE, v.nombre as 'NOMBRE DEPARTAMENTO', hv.titular as TITULAR
             * FROM habitante h, vivienda v, historial_vivienda hv
             * WHERE h.id_Habitante = hv.id_Habitante
             * AND v.id_Vivienda = hv.id_Vivienda;
             * */

            try
            {
                //Nos creamos una variable para la conexion y luego la consulta
                MySqlCommand cmd = new MySqlCommand();
                //Abrimos la conexion para nuestra conexion
                cmd.Connection = conexionBD;
                //le pasamos la consulta
                cmd.CommandText = buscarHabitante;
                //Creamos una variable donde obtendremos todos los datos
                obtenerDatos = cmd.ExecuteReader();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error en la consulta" + ex.Message);
            }

            return(obtenerDatos);
        }
        public static int AgregarHabitante(Habitante habitante)
        {
            int retorno = 0;
            //Intanciamos a la clase de conexion a nuestra BD
            BDConexion cn = new BDConexion();
            //Elaboramos el comando en insercion
            MySqlCommand cmd = new MySqlCommand(string.Format("INSERT INTO habitante( id_TipoHabitante, primerNombre, segundoNombre, apellidoPaterno, apellidoMaterno, CI, extencionCI, sexo, calle, zona, rutaFotoPerfil)" +
                                                              "VALUES ({0}, '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}', '{8}', '{9}', '{10}')",
                                                              habitante.Id_TipoHabitante, habitante.PrimerNombre, habitante.SegundoNombre, habitante.ApellidoPaterno, habitante.ApellidoMaterno, habitante.Carnet, habitante.ExtencionCI, habitante.Sexo, habitante.Calle, habitante.Zona, habitante.Fotografia),
                                                cn.ObtenerConexion());

            retorno = cmd.ExecuteNonQuery();
            return(retorno);
        }
        public static int AsiganrVivienda(Departamento departamento, Habitante habitante)
        {
            int retorno = 0;
            //Instanciamos en una variable la conexion a nuestra BD
            BDConexion cn = new BDConexion();
            //Elaboramos el comando en insercion
            MySqlCommand cmd = new MySqlCommand(string.Format("INSERT INTO historial_vivienda( id_Vivienda, id_Habitante, fechaInicioVivencia, fechaFinVivencia, titular)" +
                                                              "VALUES ({0}, {1}, '{2}', '{3}', {4})",
                                                              departamento.ID_Vivienda, habitante.Id_Habitante, habitante.FechaInicio, habitante.FechaFinal, habitante.Titular),
                                                cn.ObtenerConexion());

            retorno = cmd.ExecuteNonQuery();
            return(retorno);
        }
Exemplo n.º 5
0
        //Para registrar el Historial Departamento
        public static int HistorialBloque(Habitante habitante, Bloque_Piso bloque, DateTime fechaInicio, DateTime fechaConclusion)
        {
            int retorno = 0;
            //Instanciamos en una variable la conexion a nuestra BD
            BDConexion cn = new BDConexion();
            //Elaboramos el comando en insercion
            MySqlCommand cmd = new MySqlCommand(string.Format("INSERT INTO historial_representantes( id_Habitante, id_Bloque, fechaInicio, fechaConclusion)" +
                                                              "VALUES ({0}, {1}, '{2}', '{3}')",
                                                              habitante.Id_Habitante, bloque.Id_Bloque, fechaInicio, fechaConclusion),
                                                cn.ObtenerConexion());

            retorno = cmd.ExecuteNonQuery();
            return(retorno);
        }