import java.awt.*;
/** Dialogo de Inclusa de dados */
public class DialogIncl extends Panel   
{
  private TextField nome;
  private TextField rg;
  private TextField placa;

  public DialogIncl() {
    add(new Label("RG:"));
    add(rg = new TextField("", EP0.TamanhoMaxRG));
    add(new Label("Placa:"));
    add(placa = new TextField("", EP0.TamanhoMaxPlaca));
    add(new Label("Nome:"));
    add(nome = new TextField("",EP0.TamanhoMaxNome));
    add(new Button("Incluir"));
    add(new Button("OK"));
  }
  /** Trata os eventos desejados nos botoes */
  public boolean action(Event ev, Object arg) {
    if (ev.target instanceof Button) {
      String tmp = (String)arg;
      if(tmp.compareTo("OK") == 0){
	EP0.Label1.setText(EP0.test.InfoPointer() + " registros");
	EP0.EncheTexto();
	EP0.JIncl.dispose();
      }
      else if(tmp.compareTo("Incluir") == 0){
	String Nome = new String();
	String Placa = new String();
	String RG = new String();
	boolean OK = true;
	if (nome.getText().length() > 5) 
	  if (nome.getText().length() > EP0.TamanhoMaxNome)
	    Nome = nome.getText().substring(0,EP0.TamanhoMaxNome).trim();
	  else
	    Nome = nome.getText().trim();
	else{ 
	  EP0.Label1.setText("O nome deve ter no minimo 6 caracteres");
	  OK = false;
	}
	if (placa.getText().length() > 4) 
	  if (placa.getText().length() > EP0.TamanhoMaxPlaca)
	    Placa = placa.getText().substring(0,EP0.TamanhoMaxPlaca).trim();
	  else
	    Placa = placa.getText().trim();
	else{
	  EP0.Label1.setText("O numero da placa deve ter no minimo 5 caracteres.");
	  OK = false;
	}
	if (rg.getText().length() > 4) 
	  if (rg.getText().length() > EP0.TamanhoMaxRG)
	    RG = rg.getText().substring(0,EP0.TamanhoMaxRG).trim();
	  else
	    RG = rg.getText().trim();
	else{
	  EP0.Label1.setText("O numero do RG deve ter no minimo 5 caracteres.");
	  OK = false;
	}
	if(OK){ 
	  if(EP0.test.ExistePlaca(Placa.toUpperCase(),0,EP0.test.InfoPointer())>-1){
	    EP0.Label1.setText("Esta placa ja existe");
	  }
	  else{
	    EP0.Label1.setText("OK, registro incluido");
	    EP0.test.Add(RG.toUpperCase(),Placa.toUpperCase(),Nome);
	    EP0.Label1.setText("registro :'"+RG+" "+Placa+" "+Nome+"' incluido.");
	    rg.setText("");
	    nome.setText("");
	    placa.setText("");
	  }
	}
      }
    }
    return true;
  }
}




  
