All pastes #400629 Raw Edit

Unnamed

public text v1 · immutable
·published 2007-03-18 20:37 UTC
rendered paste body
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;

//package PkgFicticia;

public class ClassProveedores{
    public String Nit,Empresa,Apel,Nom,Tel,Mail,Dir,Nac;
//    public Date Nac= new Date();
    public char Sexo;
    public int ProvIndex=0;
    public int ProvMax=0;

    public JFrame FrmProveedores = new JFrame(" Proveedores");
    public JLabel lblTitulo = new JLabel("Control de Proveedores",JLabel.CENTER);
    public JLabel lblIndex = new JLabel(" #/# ");

    public JLabel lblNit = new JLabel("Nit: ");
    public JLabel lblEmpresa= new JLabel("Empresa: ");
    public JLabel lblApel= new JLabel("Apellido: ");
    public JLabel lblNom = new JLabel("Nombre: ");
    public JLabel lblTel = new JLabel("Telefono: ");
    public JLabel lblMail= new JLabel("Mail: ");
    public JLabel lblDir = new JLabel("Direccion: ");
    public JLabel lblNac = new JLabel("Nacimiento: ");
    public JLabel lblSexo= new JLabel("Sexo: ");

    public JTextField txtNit   = new JTextField();
    public JTextField txtEmpresa = new JTextField();
    public JTextField txtApel  = new JTextField(15);
    public JTextField txtNom   = new JTextField();
    public JTextField txtTel   = new JTextField();
    public JTextField txtMail  = new JTextField();
    public JTextField txtDir   = new JTextField();
    public JTextField txtNac   = new JTextField();
    public JTextField txtSexo  = new JTextField();
    
    public JButton btnInicio  = new JButton("<<");
    public JButton btnAtras   = new JButton("<");
    public JButton btnUltimo  = new JButton(">>");
    public JButton btnAdelante= new JButton(">");
    public JButton btnGuardar = new JButton("Guardar");
    public JButton btnNuevo   = new JButton("Nuevo");
    public JButton btnBorrar = new JButton("Borrar");
    public JButton btnMenu    = new JButton("Ir al Menu");

    public int GetMaxIndex(){
    	int MaxTemp=-1;
    	for (int cont=0; cont<=50;cont=cont+1){
	    if(ClassFicticia.ArrProveedores[cont].Nit.trim()!=""){
		MaxTemp++;
	    }
	}
	return(MaxTemp);
    }

    public void SortProveedores(){     // NOOOO!!!!!!! no quiero hacerlo manualmente
        for(int conta=0; conta<=50; conta++){
	    for(int contb=0; contb<=50; contb++){
	    	if(ClassFicticia.ArrProveedores[conta].Nit.compareTo(ClassFicticia.ArrProveedores[contb].Nit)>=0 ){
		    String StrTemp=ClassFicticia.ArrProveedores[conta].Nit;
		    ClassFicticia.ArrProveedores[conta].Nit=ClassFicticia.ArrProveedores[contb].Nit;
		    ClassFicticia.ArrProveedores[contb].Nit=StrTemp;

		    StrTemp=ClassFicticia.ArrProveedores[conta].Empresa;
		    ClassFicticia.ArrProveedores[conta].Empresa=ClassFicticia.ArrProveedores[contb].Empresa;
		    ClassFicticia.ArrProveedores[contb].Empresa=StrTemp;

		    StrTemp=ClassFicticia.ArrProveedores[conta].Apel;
		    ClassFicticia.ArrProveedores[conta].Apel= ClassFicticia.ArrProveedores[contb].Apel;
		    ClassFicticia.ArrProveedores[contb].Apel=StrTemp;

		    StrTemp=ClassFicticia.ArrProveedores[conta].Nom;
		    ClassFicticia.ArrProveedores[conta].Nom = ClassFicticia.ArrProveedores[contb].Nom;
		    ClassFicticia.ArrProveedores[contb].Nom = StrTemp;

		    StrTemp=ClassFicticia.ArrProveedores[conta].Tel;
		    ClassFicticia.ArrProveedores[conta].Tel=ClassFicticia.ArrProveedores[contb].Tel;
		    ClassFicticia.ArrProveedores[contb].Tel=StrTemp;

		    StrTemp=ClassFicticia.ArrProveedores[conta].Mail;
		    ClassFicticia.ArrProveedores[conta].Mail=ClassFicticia.ArrProveedores[contb].Mail;
		    ClassFicticia.ArrProveedores[contb].Mail=StrTemp;

		    StrTemp=ClassFicticia.ArrProveedores[conta].Dir;
		    ClassFicticia.ArrProveedores[conta].Dir=ClassFicticia.ArrProveedores[contb].Dir;
		    ClassFicticia.ArrProveedores[contb].Dir=StrTemp;

		    StrTemp=ClassFicticia.ArrProveedores[conta].Nac;
		    ClassFicticia.ArrProveedores[conta].Nac=ClassFicticia.ArrProveedores[contb].Nac;
		    ClassFicticia.ArrProveedores[contb].Nac=StrTemp;

		    
		    char CharTemp=ClassFicticia.ArrProveedores[conta].Sexo;
		    ClassFicticia.ArrProveedores[conta].Sexo=ClassFicticia.ArrProveedores[contb].Sexo;
		    ClassFicticia.ArrProveedores[contb].Sexo=CharTemp;
		}
	    }
	}
	for(int conta=0; conta<=50; conta++){
	    System.out.println( ClassFicticia.ArrProveedores[conta].Nit );
	}

    }
    public void GoBottom(){
    	if (GetMaxIndex()==-1){
	    lblIndex.setText("0/0");
	    ProvIndex=0;
	    ProvMax=0;
	}else{
	    ProvMax=GetMaxIndex();
	    ProvIndex=GetMaxIndex();
	    lblIndex.setText((ProvMax+1)+"/"+(ProvIndex+1));
	}
	MostrarProveedor(ProvIndex);
    }

    public void GoTop(){
    	if(GetMaxIndex()==-1){
		lblIndex.setText("0/0");
		ProvIndex=0;
		ProvMax=0;
	}else{
		ProvIndex=0;
		ProvMax=GetMaxIndex();
		lblIndex.setText((ProvIndex+1)+"/"+(ProvMax+1));
	}
	MostrarProveedor(ProvIndex);
    }
    public void GoUp(){
    	if(ProvIndex>0){
	    ProvIndex--;
	    lblIndex.setText((ProvIndex+1)+"/"+(GetMaxIndex()+1));
	}
	MostrarProveedor(ProvIndex);
    }
    public void GoDown(){
    	if(ProvIndex<GetMaxIndex()){
	    ProvIndex++;
	    lblIndex.setText((ProvIndex+1)+"/"+(GetMaxIndex()+1));
	}
	MostrarProveedor(ProvIndex);
    }

    public int BusquedaNit(String pNitBusqueda){
        int Retornar=-1;
    	for(int cont=0;cont<=50;cont++){
		if( pNitBusqueda.equals( ClassFicticia.ArrProveedores[cont].Nit ) ){
			Retornar=cont;
		}
	}
	return(Retornar);
    }

    public void MostrarProveedor(int pIndex){
	txtNit.setText    ( ClassFicticia.ArrProveedores[pIndex].Nit.trim());
	txtEmpresa.setText( ClassFicticia.ArrProveedores[pIndex].Empresa.trim());
	txtNom.setText    ( ClassFicticia.ArrProveedores[pIndex].Nom.trim());
	txtApel.setText   ( ClassFicticia.ArrProveedores[pIndex].Apel.trim());
	txtTel.setText    ( ClassFicticia.ArrProveedores[pIndex].Tel.trim());
	txtMail.setText   ( ClassFicticia.ArrProveedores[pIndex].Mail.trim());
	txtNac.setText    ( ClassFicticia.ArrProveedores[pIndex].Nac.trim());
	txtDir.setText    ( ClassFicticia.ArrProveedores[pIndex].Dir.trim() );
    }
    public void AgregarProveedor(){
	if (GetMaxIndex()==-1){
		ClassFicticia.ArrProveedores[0].Nit    = txtNit.getText().trim();
		ClassFicticia.ArrProveedores[0].Empresa= txtEmpresa.getText().trim();
		ClassFicticia.ArrProveedores[0].Nom    = txtNom.getText().trim();
		ClassFicticia.ArrProveedores[0].Apel   = txtApel.getText().trim();
		ClassFicticia.ArrProveedores[0].Tel    = txtTel.getText().trim();
		ClassFicticia.ArrProveedores[0].Mail   = txtMail.getText().trim();
		ClassFicticia.ArrProveedores[0].Dir    = txtDir.getText().trim();
		ClassFicticia.ArrProveedores[0].Nac    = txtNac.getText().trim();
		SortProveedores();
		GoBottom();
		JOptionPane.showMessageDialog(FrmProveedores,"Datos Grabados","Los Datos han sido grabados correctamente",JOptionPane.INFORMATION_MESSAGE);
	}else{
		if (BusquedaNit( txtNit.getText().trim() )==-1){
			if( GetMaxIndex()<50 ){
			   System.out.println(GetMaxIndex());
			   ProvIndex=GetMaxIndex()+2;
		    	   ClassFicticia.ArrProveedores[ProvIndex].Nit     = txtNit.getText();
			   ClassFicticia.ArrProveedores[ProvIndex].Empresa = txtEmpresa.getText();
			   ClassFicticia.ArrProveedores[ProvIndex].Nom     = txtNom.getText();
			   ClassFicticia.ArrProveedores[ProvIndex].Apel    = txtApel.getText();
			   ClassFicticia.ArrProveedores[ProvIndex].Tel     = txtTel.getText();
			   ClassFicticia.ArrProveedores[ProvIndex].Mail    = txtMail.getText();
			   ClassFicticia.ArrProveedores[ProvIndex].Dir     = txtDir.getText();
			   ClassFicticia.ArrProveedores[ProvIndex].Nac     = txtNac.getText();
			   JOptionPane.showMessageDialog(FrmProveedores,"Datos Grabados",
			   "Los Datos han sido grabados correctamente",JOptionPane.INFORMATION_MESSAGE);
			   SortProveedores();
			   GoBottom();
			}else{
			   JOptionPane.showMessageDialog(FrmProveedores, "El Numero maximo es 50", "Demasiados Proveedores", JOptionPane.ERROR_MESSAGE);
			}
		}else{
		    if(txtNit.getText().equals(ClassFicticia.ArrProveedores[ProvIndex].Nit)){
		    	ClassFicticia.ArrProveedores[ProvIndex].Nit     = txtNit.getText().trim();
			ClassFicticia.ArrProveedores[ProvIndex].Empresa = txtEmpresa.getText().trim();
			ClassFicticia.ArrProveedores[ProvIndex].Nom     = txtNom.getText().trim();
			ClassFicticia.ArrProveedores[ProvIndex].Apel    = txtApel.getText().trim();
			ClassFicticia.ArrProveedores[ProvIndex].Tel     = txtTel.getText().trim();
			ClassFicticia.ArrProveedores[ProvIndex].Mail    = txtMail.getText().trim();
			ClassFicticia.ArrProveedores[ProvIndex].Dir     = txtDir.getText().trim();
			ClassFicticia.ArrProveedores[ProvIndex].Nac     = txtNac.getText().trim();
			JOptionPane.showMessageDialog(FrmProveedores," Datos Grabados ","Actualizacion Exitosa",JOptionPane.INFORMATION_MESSAGE);
			SortProveedores();
		    }else{
		    	
		    }
		}	
		lblNit.setText( String.valueOf(BusquedaNit(txtNit.getText() ) ));
	}
	MostrarProveedor(ProvIndex);
	txtNit.requestFocus();
    }
    public void TextClean(){
    	txtNit.setText("");
	txtEmpresa.setText("");
	txtNom.setText("");
	txtApel.setText("");
	txtTel.setText("");
	txtMail.setText("");
	txtDir.setText("");
	txtNac.setText("");
    }

    public void NuevoProveedor(){
    	TextClean();

	lblIndex.setText( (GetMaxIndex()+2)+"/"+(GetMaxIndex()+1) );
	ProvIndex=GetMaxIndex()+2;
    }
    public void BorrarProveedor(){
    	String BusquedaNit=txtNit.getText();

	if( ClassFicticia.ArrProveedores[ProvIndex].Nit.equals( BusquedaNit ) ){
		ClassFicticia.ArrProveedores[ProvIndex].Nit="";
		ClassFicticia.ArrProveedores[ProvIndex].Empresa="";
		ClassFicticia.ArrProveedores[ProvIndex].Nom="";
		ClassFicticia.ArrProveedores[ProvIndex].Apel="";
		ClassFicticia.ArrProveedores[ProvIndex].Tel="";
		ClassFicticia.ArrProveedores[ProvIndex].Mail="";
		ClassFicticia.ArrProveedores[ProvIndex].Nac="";
		ClassFicticia.ArrProveedores[ProvIndex].Dir="";
		SortProveedores();
	}
	if(ProvIndex>=0 ){
		if(ProvIndex<GetMaxIndex()){
			MostrarProveedor(ProvIndex);
		}else{
			GoBottom();
		}
	}else{
		GoTop();
	}
    }

    public void CheckNit(){
        int NumNit=BusquedaNit( txtNit.getText() );
    	if(NumNit==-1){
		NuevoProveedor();
	}else{
		MostrarProveedor(NumNit);
		lblIndex.setText( (NumNit+1)+"/"+(GetMaxIndex()+1)  );
	}
	System.out.println("evento");
	lblIndex.setText("pudrete!");
    }

    public void GuiProveedores(){
        SortProveedores();
        FrmProveedores.setLayout(new BorderLayout());
	btnInicio.addActionListener(new ActionListener(){
		public void actionPerformed(ActionEvent e){
			GoTop();
		}
	});
	btnUltimo.addActionListener(new ActionListener(){
		public void actionPerformed(ActionEvent e){
			GoBottom();
		}
	});
	btnGuardar.addActionListener(new ActionListener(){
		public void actionPerformed(ActionEvent e){
			AgregarProveedor();
		}
	});
	btnAdelante.addActionListener(new ActionListener(){
		public void actionPerformed(ActionEvent e){
			GoDown();
		}
	});
	btnAtras.addActionListener(new ActionListener(){
		public void actionPerformed(ActionEvent e){
			GoUp();
		}
	});
	btnBorrar.addActionListener(new ActionListener(){
		public void actionPerformed(ActionEvent e){
			BorrarProveedor();
		}
	});
	btnNuevo.addActionListener(new ActionListener(){
		public void actionPerformed(ActionEvent e){
			NuevoProveedor();
		}
	});

	/**   :- /  evento que se acciona al cambiar el texto
	txtNit.addTextListener(new TextListener(){
		public void textValueChanged(TextEvent e){
			System.out.println("cosaco");
		}
	});
	**/
	GoTop();

	JPanel panel1 = new JPanel();	panel1.setLayout(new GridLayout(0,4));
	JPanel panel2 = new JPanel();	panel2.setLayout(new GridLayout(0,7));
	JPanel panel3 = new JPanel();	panel3.setLayout(new GridLayout(5,2));

	panel1.add(lblNit);	panel1.add(txtNit);
	panel1.add(lblEmpresa);	panel1.add(txtEmpresa);
	panel1.add(lblNom);	panel1.add(txtNom);
	panel1.add(lblApel);	panel1.add(txtApel);
	panel1.add(lblTel);	panel1.add(txtTel);
	panel1.add(lblMail);	panel1.add(txtMail);
	panel1.add(lblDir);	panel1.add(txtDir);
	panel1.add(lblNac);	panel1.add(txtNac);
	panel1.add(new JLabel(""));

	panel2.add(btnInicio);
	panel2.add(btnAtras);
	panel2.add(lblIndex);
	panel2.add(btnAdelante);
	panel2.add(btnUltimo);

	panel3.add(new JLabel(""));
	panel3.add(btnGuardar);	panel3.add(new JLabel(""));
	panel3.add(btnNuevo);	panel3.add(new JLabel(""));
	panel3.add(btnBorrar); panel3.add(new JLabel(""));
	panel3.add(btnMenu);	panel3.add(new JLabel(""));
	

	FrmProveedores.add(lblTitulo,BorderLayout.NORTH);
	FrmProveedores.add(panel1,BorderLayout.CENTER);
	FrmProveedores.add(panel2,BorderLayout.SOUTH);
	FrmProveedores.add(panel3,BorderLayout.EAST);
	FrmProveedores.pack();
	FrmProveedores.setVisible(true);

    }
    public ClassProveedores(){
        Nit="";
	Empresa="";
	Apel="";
	Nom="";
	Tel="";
	Mail="";
	Dir="";
	Sexo=' ';
	Nac="";
    }

    public static void main(String[] pArgs){
        
    }
}