Ver Mensaje Individual
  #7  
Antiguo 28-11-2014
Delphitest Delphitest is offline
Miembro
 
Registrado: sep 2006
Ubicación: Salamanca-España
Posts: 249
Reputación: 18
Delphitest Va por buen camino
Adjunto un pantallazo del form y el código que estoy probando porque me estoy liando un poco.

Por un lado tengo el formulario para buscar un cliente

Tiene unos edits donde meto lo que quiero buscar y a medida que escribo el dbgrid que hay por debajo se va filtrando con lo que corresponda.

Lo que pretendo es que al poner el nombre, ademas de buscar en el nombre de la tabla clientes, lo haga también en la tabla contactos de tal manera que el grid vaya mostrando el o los clientes cuyo nombre sea el que estoy escribiendo en el edit correspondiente o el cliente que tenga un contacto cuyo nombre coincida también con la búsqueda.

Con este código solo veo el cliente cuyo nombre contenga lo que escribo en el edit pero no está buscando en contactos por las pruebas que he hecho.

También he notado que si el cliente no tienen ningún contacto relacionado, tampoco se lista.

Código Delphi [-]
procedure TFBuscaCliente.Edit1Change(Sender: TObject);

var bOtraCondicion :boolean;

begin
  bOtraCondicion:=false;
  with TBuscarCliente do
  begin
    Close;
    SQL.Clear;
    SQL.Add('SELECT * FROM CLIENTES');

    if ( (Edit1.Text <>'') or  (Edit2.Text <>'') or (Edit3.Text <>'') or  (Edit4.Text <>'') or (Edit5.Text <>'') ) then
    begin
  Close;
    SQL.Clear;
    SQL.Add('SELECT cli.IDCLIENTE,cli.NOMBRE, cli.APELLIDOS, cli.DNI, cli.TELEFONO_FIJO, cli.PROVINCIA FROM CLIENTES AS CLI INNER JOIN Contactos AS C ON C.IDCLIENTE = CLI.IDCLIENTE');
    SQL.Add('WHERE');

      if  Edit1.Text <>'' then
      begin
        SQL.Add('CLI.NOMBRE LIKE :PNOM OR C.NOMBRE LIKE :PNOM');
        bOtraCondicion:= true;
        Parameters.ParamByName('PNOM').Value:= '%'+Edit1.Text+'%';
      end;

      if  Edit2.Text <>'' then
      begin
        if bOtraCondicion then
        SQL.Add('AND');
        SQL.Add('CLI.APELLIDOS LIKE :PAPE OR C.APELLIDOS LIKE :PAPE');
        bOtraCondicion:= true;
        Parameters.ParamByName('PAPE').Value:= '%'+Edit2.Text+'%';
      end;

      if  Edit3.Text <>'' then
      begin
        if bOtraCondicion then
        SQL.Add('AND');
        SQL.Add('CLI.DNI LIKE :PDNI OR C.DNI LIKE :PDNI');
        Parameters.ParamByName('PDNI').Value:= '%'+Edit3.Text+'%';
      end;

      if  Edit4.Text <>'' then
      begin
        if bOtraCondicion then
        SQL.Add('AND');
        SQL.Add('CLI.PROVINCIA LIKE :PPROV OR C.PROVINCIA LIKE :PPROV');
        Parameters.ParamByName('PPROV').Value:= '%'+Edit4.Text+'%';
      end;

      if  Edit5.Text <>'' then
      begin
        if bOtraCondicion then
        SQL.Add('AND');
        SQL.Add('CLI.TELEFONO_FIJO LIKE :PTFNO OR C.TELEFONO_FIJO LIKE :PTFNO');
        Parameters.ParamByName('PTFNO').Value:= '%'+Edit5.Text+'%';
      end;

    end;
    Open;
  end;
end;

Las tablas están en un Data Modulo a parte pero los campos se leen sin problemas y TBuscarCliente es una query que esta en este Form y que esta relacionada con el DBGrid, igual tengo el problema ahí...
Imágenes Adjuntas
Tipo de Archivo: jpg BuscarCliente.jpg (28,0 KB, 3 visitas)
__________________
Mi proyecto paso a paso (Parte I)
Responder Con Cita