Mostrar Mensajes

Esta sección te permite ver todos los posts escritos por este usuario. Ten en cuenta que sólo puedes ver los posts escritos en zonas a las que tienes acceso en este momento.


Mensajes - victor garay

Páginas: [1]
1
Estoy guardando los datos de pacientes en un archivo binario: numero de expediente, dni, apellidos, nombres, telefono, direccion y fotografia.

El problema se me presenta cuando busco a los pacientes x su numero de expediente, solo me muestra los datos del ultimo paciente ingresados, los anteriores desaparecen, al parecer el problema se presenta cuando se guarda los datos se sobreescribe y no los agrega al archivo binario. aqui les dejo los codigos de guardar y buscar respectivamente a ver si me ayudan. gracias:


Código: [Seleccionar]
private void btcGuardarActionPerformed(java.awt.event.ActionEvent evt) {                                           
        // TODO add your handling code here:
        Object nombreArchivo = archivo;
        System.out.println(nombreArchivo);
        try{
            ObjectOutputStream fileout = new ObjectOutputStream(new FileOutputStream((String) nombreArchivo));
            fileout.writeObject(txtNroExpediente.getText());
            fileout.writeObject(txtDni.getText());
            fileout.writeObject(txtApellidos.getText());
            fileout.writeObject(txtNombres.getText());
            fileout.writeObject(txtDireccion.getText());
            fileout.writeObject(txtTelefono.getText());
            fileout.writeObject(lblFoto.getIcon());
            fileout.flush();
            JOptionPane.showMessageDialog(null, "Los datos del paciente se guardaron corecttamente...");
            if(fileout!=null){
               fileout.close();
            }
        }catch(IOException e){}
        desactivarTextFields();
        btcGuardar.setEnabled(false);
        btcNuevo.setEnabled(true);
        btcBuscar.setEnabled(false);
    }                                         

    private void btcBuscarActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        Object nombreArchivo = archivo;
        try{
            try (ObjectInputStream filein = new ObjectInputStream(new FileInputStream((String) nombreArchivo))){
                Object expediente = filein.readObject();
                Object dni = filein.readObject();
                Object apellidos = filein.readObject();
                Object nombres = filein.readObject();
                Object direccion = filein.readObject();
                Object telefono = filein.readObject();
                Object foto = filein.readObject();
            if (txtNroExpediente.getText().equals(expediente)){   
                txtNroExpediente.setText((String) expediente);
                txtDni.setText((String) dni);
                txtApellidos.setText((String) apellidos);
                txtNombres.setText((String) nombres);
                txtDireccion.setText((String) direccion);
                txtTelefono.setText((String) telefono);
                lblFoto.setIcon((Icon) foto);
            }
                if(filein!=null){
                    filein.close();
                }
            } catch (ClassNotFoundException ex) {
                Logger.getLogger(JDPacientes.class.getName()).log(Level.SEVERE, null, ex);
            }
        }catch(IOException e){}   
    }

Páginas: [1]

Sobre la educación, sólo puedo decir que es el tema más importante en el que nosotros, como pueblo, debemos involucrarnos.

Abraham Lincoln (1808-1865) Presidente estadounidense.

aprenderaprogramar.com: Desde 2006 comprometidos con la didáctica y divulgación de la programación

Preguntas y respuestas

¿Cómo establecer o cambiar la imagen asociada (avatar) de usuario?
  1. Inicia sesión con tu nombre de usuario y contraseña.
  2. Pulsa en perfil --> perfil del foro
  3. Elige la imagen personalizada que quieras usar. Puedes escogerla de una galería de imágenes o subirla desde tu ordenador.
  4. En la parte final de la página pulsa el botón "cambiar perfil".