Ver Mensaje Individual
  #7  
Antiguo 24-12-2009
Avatar de Caral
[Caral] Caral is offline
Miembro Premium
 
Registrado: ago 2006
Posts: 7.659
Reputación: 25
Caral Va por buen camino
Hola
Lo que haces es una inserción con un botón, en ese mismo momento se hace la comparación:
Coloca un query nuevo en el form, lo enlazas a la tabla.
Supongo que tendras un edit o dbedit donde escribes el ID, entonces lo haces asi:

Código Delphi [-]
procedure TF_Importa.BitBtn1Click(Sender: TObject);
var
F:TIBInputDelimitedFile;
i:integer;
begin
     // aqui empieza la comparacion
    If dit1.Text <> '' then    // si el edit esta lleno entonces:
   Begin
     TuQuery.Active:= false;
     TuQuery.SQL.Text:= 'Select ID from TuTabla Where ID = :cod ';
     TuQuery.Parameters.ParamByName('cod').Value := Edit1.Text;  // esto depende del componente que uses
     TuQuery.Active := true;
     IF TuQueryID.AsString = Edit1.Text then  //puede ser tambien value
     begin
     MessageDlg('ID ya existe, favor seleccionar otro',mtError,[mbOK],0);
     Edit1.Text:= '';
     end
     else
        F_Confirmacio := TF_Confirmacio.Create(self);
        F_Confirmacio.Label1.Caption:= 'Importem arxiu';
        try
        If F_Confirmacio.ShowModal = mrok then
        begin
                F_ModulDades.Act_Girona_Hist.Close;
                F_ModulDades.Act_Girona_Hist.Open;
                F_ModulDades.Act_Girona_Hist.Last;
                i:=F_ModulDades.Act_Girona_HistID.Value+1;
                F_ModulDades.Act_Girona_Hist.Append;
                F_ModulDades.Act_Girona_HistID.Value:=i;
                F_Importa.IBSQLImporta.SQL.Text := 'Insert into RE0006AGT values(:ID, :ID_REBUT, :ID_ARBITRE, :NOM, ATA, :TITOL, :CODI_CLUB, :CANON, :PASSADA)';
                F := TIBInputDelimitedFile.Create;
                try
                        F.ColDelimiter:=';';
                        If OpenDialog1.Execute then
                        begin
                                F.Filename:=OpenDialog1.FileName;
                        end;
                        F_Importa.IBSQLImporta.BatchInput(F);
                finally
                        F.Free;
                end;
                Posa_S.ExecSQL;
        end;
        finally
                F_Confirmacio.Free;
        end;
        Showmessage('Procés finalitzat');
end;
Si el ID ya existe no guardara nada y dara el foco al edit, de lo contrario lo grabara.
Saludos
__________________
Siempre Novato
Responder Con Cita