EXPORTAÇÃO DE UMA TABELA PARA OUTRA DOS ISTENS SELECIONADOS NO DBGRID

07/01/2020

0

Boa tarde a todos
Como posso selecionar itens com o mult select de um dbgrid ligando a tabela A, clicar em um botao e importar para tabela B, so os itens selecionados no dbgrid da tabela A??

exemplo no dbgrid da tabela A, tem 10 registros, com mult select vou selecionar 5 aleatorio e no botao exportar para tabela B só os 5 selecionados.

alguem pode me ajudar, tentei assim mas nao deu
Wellington

Wellington

Responder

Posts

11/01/2020

Raimundo Pereira

Bom dia!
Na Tabela A, inserir um campo chamado _SELECIONADO_

No Grid relacionado a Tabela A, ao pressionar a tecla espace eu verifico o valor do campo se é = S
Esta rotina serve para selecionar vários registros e exportar para minha Tabela B posteriormente.

Imagem do exemplo
https://ibb.co/bQqLFmz

Fonte:

Tecla Space:
procedure TForm1.GRID_TABELA_AKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if Key = VK_SPACE then
  begin

    if (Tabela_A.Active = true) and (Tabela_A_NOME.Value <> '') then
    begin
      Tabela_A.Edit;
      if Tabela_A_SELECIONADO_.Value = 'S' then
      begin
        Tabela_A_SELECIONADO_.Value := 'N';
      end
      else
      begin
        Tabela_A_SELECIONADO_.Value := 'S';
      end;

       Tabela_A.post;
    end;
  end;

end;


Exportação:
procedure TForm1.Btn_Export_RegistrosClick(Sender: TObject);
begin

          Tabela_A.First;
          if Tabela_A.RecordCount=0 then
              begin
              ShowMessage('Nenhum registro para Importar');
              end
              else
              begin
              if not Tabela_A.Eof then
              repeat
                     if Tabela_A_SELECIONADO_.Value='S' then
                     BEGIN
                     if NOT Tabela_B.Locate('_NOME',Tabela_A.FieldByName('_NOME').Value,[]) then
                     BEGIN
                       //EXPORT
                       Tabela_B.Insert;
                       Tabela_B.FieldByName('_NOME').Value:=
                       Tabela_A_NOME.Value;
                       Tabela_B.Post;
                     END;

                     END;

                     Tabela_A.Next;
              until (Tabela_A.Eof);


              end;

end;


Espero que seja útil


Responder

Assista grátis a nossa aula inaugural

Assitir aula

Saiba por que programar é uma questão de
sobrevivência e como aprender sem riscos

Assistir agora

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar