jcortes96 / software2

Espacio para subir pruebas de software
0 stars 58 forks source link

Andrea Daza- Oscar Peña- Sebastian Cardenas #33

Open cardenaz1101 opened 5 years ago

cardenaz1101 commented 5 years ago

package array_registros; import java.io.; import javax.swing.; import java.util.*;

public class operaciones { ImageIcon img=new ImageIcon(getClass().getResource("/imagen/reg.png")); ImageIcon img2=new ImageIcon(getClass().getResource("/imagen/modi.jpg")); ImageIcon img3=new ImageIcon(getClass().getResource("/imagen/elim.jpg")); static int salida; static String op; static ArrayList struct=new ArrayList(); int i,mat; String nom; String matri; String carre;

/********************************************************************************************/
void princi() throws IOException
{
    String[] menu= { "1.CAPTURAR","2.CONSULTAR","3.MODIFICAR","4.ELIMINAR","5.SALIR"};

    do {
        do {
    op=(String)JOptionPane.showInputDialog(null,"REGISTROS","Menu",JOptionPane.DEFAULT_OPTION,img,menu,menu[0]);
    if(op==null)
    {
        princi();
    }
    else

    switch (op.charAt(0)) 
    {
        case '1': captura();break;
        case '2': consultar();break;
        case '3': Modificar();break;
        case '4': eliminar();break;
        case '5':
            salida=JOptionPane.showConfirmDialog(null, "¿Esta seguro?", "Alerta!", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
            if(salida==0){
            System.exit(0);
            }
            if(salida!=0){
            princi();
            }
            break;
    }
        } while (salida == 1);
    } while(op.charAt(0) != '5'); 
}
/*********************************************************************************************/

/*********************************************************************************************/

void captura() throws IOException { matri = JOptionPane.showInputDialog (null, "Matricula: ","Registros",JOptionPane.PLAIN_MESSAGE); mat=Integer.parseInt(matri); boolean contenido=struct.contains(mat); BufferedReader bf = new BufferedReader(new FileReader("archi.txt")); for( i=0;i<struct.size();i++) {
if(mat==struct.get(i).getMatricula() ) {
contenido=true; break; }
} if(contenido==true) { JOptionPane.showMessageDialog(null,"MATRICULA EXISTENTE","Error",JOptionPane.ERROR_MESSAGE); princi(); } if(contenido==false) { nom = JOptionPane.showInputDialog (null, "Nombre: ","Registro "+(i+1),JOptionPane.PLAIN_MESSAGE); carre = JOptionPane.showInputDialog (null, "Carrera: ","Registro "+(i+1),JOptionPane.PLAIN_MESSAGE);

  struct.add(new Variables (mat,carre,nom));

    guarda();}

} /*****/

/*********************************************************************************************/

void consultar() { int op2;

        String[] options = {"Listar","Consultar","Volver"};
    do {
        do {
            op2 = JOptionPane.showOptionDialog(null, "Seleccione la Opcion que desee", "Menu Consultar", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE,img, options, options[0]);
            switch (op2) 
            {
                case 0:listar();break;
                case 1:B_avanzada();break;
                case 2:
                    salida = JOptionPane.showConfirmDialog(null, "¿Desea Volver al Menu principal?", "Alerta!", JOptionPane.YES_NO_OPTION, JOptionPane.PLAIN_MESSAGE, img);
                    break;    
            }
        } while (salida == 1);
    } while (op2 != 2);

}
/*********************************************************************************************/

/*********************************************************************************************/

void listar() { for(int i=0;i<struct.size();i++) { JOptionPane.showMessageDialog(null,"Matricula: "+struct.get(i).getMatricula()+"\nNombre: "+struct.get(i).getNombre() +"\nCarrera: "+struct.get(i).getCarrera(),"Registro "+(i+1),JOptionPane.PLAIN_MESSAGE); }

}
/*********************************************************************************************/

/*********************************************************************************************/

void B_avanzada() { String matri = JOptionPane.showInputDialog (null, "Matricula: ","Busqueda",JOptionPane.PLAIN_MESSAGE); mat=Integer.parseInt(matri);

    boolean asd=struct.contains(mat);

    for( i=0;i<struct.size();i++)
    {
        if(mat==struct.get(i).getMatricula())
        {
            asd=true;
            break;
        }
    }

    if(asd==true)
    {
        JOptionPane.showMessageDialog(null,"Matricula: "+struct.get(i).getMatricula()+"\nNombre: "+struct.get(i).getNombre()
        +"\nCarrera: "+struct.get(i).getCarrera(),"Registro "+(i+1),JOptionPane.PLAIN_MESSAGE);
    }

    if(asd==false)
    {
        JOptionPane.showMessageDialog(null,"MATRICULA NO EXISTENTE","Error",JOptionPane.ERROR_MESSAGE);
    }   

}
/*********************************************************************************************/

void Modificar() throws IOException
{
    String matri = JOptionPane.showInputDialog (null, "Matricula: ","Busqueda",JOptionPane.PLAIN_MESSAGE);
    int mat=Integer.parseInt(matri);
    boolean contenido=struct.contains(mat);
    for( i=0;i<struct.size();i++)
    {
        if(mat==struct.get(i).getMatricula())
        {
            contenido=true;
            break;
        }
    }
    if(contenido==true)
    {
        JOptionPane.showMessageDialog(null,"Matricula: "+struct.get(i).getMatricula()+"\nNombre: "+struct.get(i).getNombre()
         +"\nCarrera: "+struct.get(i).getCarrera(),"Registro "+(i+1),JOptionPane.PLAIN_MESSAGE);

    String[] menu= { "1.MATRICULA","2.NOMBRE","3.CARRERA","4.VOLVER"};
    String op;
    do {
        do {
    op=(String)JOptionPane.showInputDialog(null,"¿QUE DESEA MODIFICAR?","Menu de Modificacion",JOptionPane.DEFAULT_OPTION,img2,menu,menu[0]);
    if(op==null)
    {
        princi();
    }
    else

    switch (op.charAt(0)) 
    {
        case '1':

            String N_matri="";

            N_matri = JOptionPane.showInputDialog(null, "Ingrese nueva matricula: ","",JOptionPane.PLAIN_MESSAGE);
            int N=Integer.parseInt(N_matri);
            boolean contenido2=struct.contains(N_matri);

            for( i=0;i<struct.size();i++)
            {
             if(struct.get(i).getMatricula()==N)
                {
                contenido2=true;
                break;
                }
            }   
            if(contenido2==true)
                {
                    JOptionPane.showMessageDialog(null,"MATRICULA EXISTENTE","Error",JOptionPane.ERROR_MESSAGE);
                    princi();
                }
            if(contenido2==false)
                {
                    JOptionPane.showMessageDialog(null,"MODIFICACION EXITOSA","Bien",JOptionPane.PLAIN_MESSAGE);
                    for(int i=0; i<struct.size(); i++)
                    {
                        if(struct.get(i).matricula==mat)
                        {
                          struct.get(i).setMatricula(N);
                          guarda();
                        }
                    }
                }
            break;

        case '2':

            String N_nom="";
            for(int i=0; i<struct.size(); i++)
            {
                if(struct.get(i).matricula==mat)
                {
                    N_nom = JOptionPane.showInputDialog(null, "Ingrese nuevo Nombre: ","",JOptionPane.PLAIN_MESSAGE);
                    struct.get(i).setNombre(N_nom);
                    guarda();
                } 
            }
            break;
        case '3':
            String N_carre="";
            for(int i=0; i<struct.size(); i++)
            {
                if(struct.get(i).matricula==mat)
                {
                    N_carre = JOptionPane.showInputDialog(null, "Ingrese nueva Carrera: ","",JOptionPane.PLAIN_MESSAGE);
                    struct.get(i).setCarrera(N_carre);
                    guarda();
                }
            }
            break;
        case '4': 
            salida=JOptionPane.showConfirmDialog(null, "¿Esta seguro?", "Alerta!", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
            if(salida==0){
            princi();
            }
            if(salida!=0){
            Modificar();
            }
            break;
    }
        } while (salida == 1);
    } while(op.charAt(0) != '4');

    }
    if(contenido==false)
    {
        JOptionPane.showMessageDialog(null,"MATRICULA NO EXISTENTE","Error",JOptionPane.ERROR_MESSAGE);
    } 

}
/*********************************************************************************************/

void eliminar() throws IOException
{
    int op;
    String[] menu= { "ELIMINAR TODO","ELIMINAR REGISTRO","VOLVER"}; 
    do {

    op = JOptionPane.showOptionDialog(null, "Seleccione la Opcion que desee", "Menu Consultar", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE,img3, menu, menu[0]);

    do {

    switch (op) 
    {
        case 0:      

            struct.removeAll(struct);
            JOptionPane.showMessageDialog(null,"ELIMINADO CON EXITO","BIEN",JOptionPane.PLAIN_MESSAGE);
            break;

        case 1:

        String matri = JOptionPane.showInputDialog (null, "Matricula: ","Busqueda",JOptionPane.PLAIN_MESSAGE);
        int mat=Integer.parseInt(matri);
        boolean contenido=struct.contains(mat);
        for( i=0;i<struct.size();i++)
        {
            if(mat==struct.get(i).getMatricula())
            {
                contenido=true;
                break;
            }
        }
        if(contenido==true)
        {
            JOptionPane.showMessageDialog(null,"Matricula: "+struct.get(i).getMatricula()+"\nNombre: "+struct.get(i).getNombre()
             +"\nCarrera: "+struct.get(i).getCarrera(),"Registro "+(i+1),JOptionPane.PLAIN_MESSAGE);

            for(i=0;i<struct.size();i++)
            {
                if(struct.get(i).matricula==mat)
                {
                struct.remove(i);
                JOptionPane.showMessageDialog(null,"ELIMINADO CON EXITO","BIEN",JOptionPane.PLAIN_MESSAGE);
                }
            }
            break;
        } 
        if(contenido==false)
        {
            JOptionPane.showMessageDialog(null,"MATRICULA NO EXISTENTE","Error",JOptionPane.ERROR_MESSAGE);
        }
        break;

        case 2: 
            salida=JOptionPane.showConfirmDialog(null, "¿Esta seguro?", "Alerta!", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
            if(salida==0){
            princi();
            }
            if(salida!=0){
            eliminar();
            }
            break;
        }
      } while (salida == 1);
    } while(op!= 3);      
}

void guarda() {

  try
    {
      //FileWriter re=new FileWriter("archi.txt");
      //for(int i=0;i<struct.size();i++)
      //{
      FileWriter re = new FileWriter("archi.txt", true);
      re.write(struct.get(i).matricula+" "+struct.get(i).nombre+" "+struct.get(i).carrera+"\r\n");
      //}
    re.close();
    }
    catch(Exception e){
        e.printStackTrace();
    }
  /*File TextFile = new File("EstadoVentanilla.txt"); 
    FileWriter TextOut = new FileWriter(TextFile, true);
    //TextOut.write("Prueba de Grabación de Archivo_4\r\n");
    TextOut.write("Prueba de Grabación de Archivo_2\r\n");
    TextOut.close();*/

}

void lee() throws FileNotFoundException, IOException { BufferedReader bf = new BufferedReader(new FileReader("archi.txt"));

    String sCadena;
    while ((sCadena = bf.readLine())!=null) {
    System.out.println(sCadena);
    }

} }