Archivo Secuencial A Ser Implementadas Empleado

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

// DEFINICION DE LAS VARIABLES

String t1, t2, t3, t4, t5, t6;


// PROCEDIMIENTO REGISTRAR

public void Registrar() {


int sw = 0;
DataOutputStream fosar = null;
try {
while (sw == 0) {
fosar = new DataOutputStream(new FileOutputStream("D:\\empleado.dat", true));
fosar.writeUTF(Text1.getText());
fosar.writeUTF(Text2.getText());
fosar.writeUTF(Text3.getText());
fosar.writeUTF(Text4.getText());
fosar.writeUTF(Text5.getText());
fosar.writeUTF(Text6.getText());
fosar.close();
sw = 1;
limpiar();
}
} catch (FileNotFoundException fnfe) {
TextArea.setText("Archivo no encontrado");
} catch (IOException ioe) {
TextArea.setText("Error al grabar");
}
}
// LIMPIAR LA PANTALLA

public void limpiar() {


Text1.setText("");
Text2.setText("");
Text3.setText("");
Text4.setText("");
Text5.setText("");
Text6.setText("");
TextArea.setText("");
}

public void Ver_registrado() {


TextArea.setText(" ");
DataInputStream fis = null;
String t1, t2, t3, t4, t5, t6;
try {
fis = new DataInputStream(new FileInputStream("D:\\empleado.dat"));
while (true) {
t1 = fis.readUTF();
t2 = fis.readUTF();
t3 = fis.readUTF();
t4 = fis.readUTF();
t5 = fis.readUTF();
t6 = fis.readUTF();

TextArea.append("# de Registro :" + "\t" + t1);


TextArea.append("\nNOMBRES :" + "\t" + t2);
TextArea.append("\nAP. PATERNO :" + "\t" + t3);
TextArea.append("\nAP. MATERNO :" + "\t" + t4);
TextArea.append("\nCARNET O NIT:" + "\t" + t5);
TextArea.append("\nDIRECCION:" + t6 + "\n\n");

}
} catch (FileNotFoundException fnfe) {
TextArea.append("Ningun archivo registrado");
} catch (IOException ioe) {
}
try {
fis.close();
} catch (IOException ioe) {
TextArea.append("Error al grabar");
}
}
// ELIMINA UN REGISTRO
public void Eliminar(String t9) {
DataInputStream wcc = null;
DataOutputStream Archtemp = null;
char opcion = 'n';
int sw = 0;
try {
Archtemp = new DataOutputStream(new FileOutputStream("D:\\noe.dat"));
wcc = new DataInputStream(new FileInputStream("D:\\empleado.dat"));
String aux = Text9.getText();
sw = 0;
while (true) {
t1 = wcc.readUTF();
t2 = wcc.readUTF();
t3 = wcc.readUTF();
t4 = wcc.readUTF();
t5 = wcc.readUTF();
t6 = wcc.readUTF();

if (aux.compareTo(t1) != 0) {
Archtemp.writeUTF(t1);
Archtemp.writeUTF(t2);
Archtemp.writeUTF(t3);
Archtemp.writeUTF(t4);
Archtemp.writeUTF(t5);
Archtemp.writeUTF(t6);

} else {
sw = 1;
}
}
} catch (IOException variablerror) {
}
try {
wcc.close();
Archtemp.close();
if (sw == 1) {
File file1 = new File("D:\\empleado.dat");
File file2 = new File("D:\\noe.dat");
if (file1.exists()) {
file1.delete();
}
file2.renameTo(file1);
}
TextArea.setText("eliminado");
} catch (IOException variablerror) {
TextArea.setText("Error!");
}
}
// MODIFICAR LOS DATOS
public void Modificar(String t10) {
int sw = 0;
char opcion = 'n';
DataInputStream wcc = null;
DataOutputStream Archtemp = null;
try {
Archtemp = new DataOutputStream(new FileOutputStream("D:\\noa.dat"));
wcc = new DataInputStream(new FileInputStream("D:\\empleado.dat"));
String codi = t10;
sw = 0;
while (true) {
t1 = wcc.readUTF();
t2 = wcc.readUTF();
t3 = wcc.readUTF();
t4 = wcc.readUTF();
t5 = wcc.readUTF();
t6 = wcc.readUTF();

if (codi.compareTo(t1) == 0) {
Text1.setText(t1);
Text2.setText(t2);
Text3.setText(t3);
Text4.setText(t4);
Text5.setText(t5);
Text6.setText(t6);

t1 = (Text1.getText());
t2 = (Text2.getText());
t3 = (Text3.getText());
t4 = (Text4.getText());
t5 = (Text5.getText());
t6 = (Text6.getText());
}
Archtemp.writeUTF(t1);
Archtemp.writeUTF(t2);
Archtemp.writeUTF(t3);
Archtemp.writeUTF(t4);
Archtemp.writeUTF(t5);
Archtemp.writeUTF(t6);
}
} catch (IOException variablerror) {
}
try {
wcc.close();
Archtemp.close();
File file1 = new File("D:\\empleado.dat");
File file2 = new File("D:\\noa.dat");
if (file1.exists()) {
file1.delete();
}
file2.renameTo(file1);
} catch (IOException varablerror) {
TextArea.setText("Error!");
}
}

public void Grabar(String aux) {


int sw = 0;
char opcion = 'n';
DataInputStream wcc = null;
DataOutputStream Archtemp = null;
try {
Archtemp = new DataOutputStream(new FileOutputStream("D:\\noa.dat"));
wcc = new DataInputStream(new FileInputStream("D:\\empleado.dat"));
t1 = (Text1.getText());
t2 = (Text2.getText());
t3 = (Text3.getText());
t4 = (Text4.getText());
t5 = (Text5.getText());
t6 = (Text6.getText());
if (aux.equals("SI")) {
Archtemp.writeUTF(t1);
Archtemp.writeUTF(t2);
Archtemp.writeUTF(t3);
Archtemp.writeUTF(t4);
Archtemp.writeUTF(t5);
Archtemp.writeUTF(t6);
}
} catch (IOException variablerror) {
}
try {
wcc.close();
Archtemp.close();
File file1 = new File("D:\\empleado.dat");
File file2 = new File("D:\\noa.dat");
if (file1.exists()) {
file1.delete();
}
file2.renameTo(file1);
} catch (IOException varablerror) {
TextArea.setText("Error!");
}
}
// BUSCAR UN REGISTRO

public void Buscar(String t12) {


limpiar();
int sw = 0;
DataInputStream fis = null;
try {
fis = new DataInputStream(new FileInputStream("D:\\empleado.dat"));
String codigo = t12;
while (true && sw == 0) {
t1 = fis.readUTF();
t2 = fis.readUTF();
t3 = fis.readUTF();
t4 = fis.readUTF();
t5 = fis.readUTF();
t6 = fis.readUTF();

if (t1.compareTo(codigo) == 0) {
TextArea.append("# de Registro :" + "\t" + t1);
TextArea.append("\nNOMBRES :" + "\t" + t2);
TextArea.append("\nAP. PATERNO :" + "\t" + t3);
TextArea.append("\nAP. MATERNO :" + "\t" + t4);
TextArea.append("\nCARNET O NIT:" + "\t" + t5);
TextArea.append("\nDIRECCION:" + t6 + "\n\n");

sw = 1;
}
}
} catch (FileNotFoundException fnfe) {
TextArea.append("Archivo no encontrado");
} catch (IOException ioe) {
}
try {
fis.close();
} catch (IOException ioe) {
}
if (sw == 0) {
TextArea.setText("El archivo con este codigo no existe");
}
}

You might also like