unit Consulta_Dados_Cadastrais_Resultado;

interface

uses
  Windows, system.UItypes, IB_Access, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, TelaComum, ExtCtrls, StdCtrls, Buttons, DB, IBODataset, DBClient,
  cxGraphics, cxControls, cxLookAndFeels, cxLookAndFeelPainters, cxStyles,
  cxCustomData, cxFilter, cxData, cxDataStorage,
  cxEdit, cxDBData, cxImageComboBox, cxGridLevel, cxGridCustomTableView,
  cxGridTableView, cxGridDBTableView, cxClasses, cxGridCustomView, cxGrid,
  cxCheckBox, DBCtrls, ImgList, Menus, cxButtons, cxNavigator, System.ImageList,
  dxSkinsCore, dxSkinOffice2010Blue,
  cxDataControllerConditionalFormattingRulesManagerDialog, cxImageList;

type
  TfrmConsulta_Dados_Cadastrais_Resultado = class(TfrmTelaComum)
    cdsConsulta: TClientDataSet;
    grdGridResultado: TcxGrid;
    grdGridResultadoDBTableView1: TcxGridDBTableView;
    grdGridResultadoLevel1: TcxGridLevel;
    dsrConsulta: TDataSource;
    viwSelecionado: TcxGridDBColumn;
    viwValorConsulta: TcxGridDBColumn;
    viwCampo_descritivo: TcxGridDBColumn;
    cxStyleRepository1: TcxStyleRepository;
    TituloGrid: TcxStyle;
    mmoConsulta: TDBMemo;
    mmoValor_base_de_dados: TDBMemo;
    Label1: TLabel;
    Label2: TLabel;
    grdGridResultadoDBTableView1Column1: TcxGridDBColumn;
    imgImagens: TcxImageList;
    btnGuiaEndereco: TcxButton;
    cxButton1: TcxButton;
    cxButton2: TcxButton;
    procedure BtGravarClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure grdGridResultadoDBTableView1Column1GetCellHint(
      Sender: TcxCustomGridTableItem; ARecord: TcxCustomGridRecord;
      ACellViewInfo: TcxGridTableDataCellViewInfo; const AMousePos: TPoint;
      var AHintText: TCaption; var AIsHintMultiLine: Boolean;
      var AHintTextRect: TRect);
    procedure btnGuiaEnderecoClick(Sender: TObject);
    procedure cxButton1Click(Sender: TObject);
    procedure cxButton2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmConsulta_Dados_Cadastrais_Resultado: TfrmConsulta_Dados_Cadastrais_Resultado;

implementation


{$R *.dfm}

procedure TfrmConsulta_Dados_Cadastrais_Resultado.BtGravarClick(
  Sender: TObject);
begin
   ModalResult := mrOk;
end;

procedure TfrmConsulta_Dados_Cadastrais_Resultado.FormShow(
  Sender: TObject);
begin
  inherited;
   if cdsConsulta.IsEmpty then
    Exit;

   cdsConsulta.First;

   while not cdsConsulta.Eof do
   begin
      cdsConsulta.Edit;

      if cdsConsulta.FieldByName('Valor_consulta').AsString <> cdsConsulta.FieldByName('Valor_base_de_dados').AsString then
      begin
         cdsConsulta.FieldByName('Diferente').Value   := True;
         cdsConsulta.FieldByName('selecionado').Value := True;
      end
      else
      begin
         cdsConsulta.FieldByName('Diferente').Value   := False;
         cdsConsulta.FieldByName('selecionado').Value := False;;
      end;
      cdsConsulta.Post;

      cdsConsulta.Next;
   end;

   cdsConsulta.first;
end;

procedure TfrmConsulta_Dados_Cadastrais_Resultado.grdGridResultadoDBTableView1Column1GetCellHint(
  Sender: TcxCustomGridTableItem; ARecord: TcxCustomGridRecord;
  ACellViewInfo: TcxGridTableDataCellViewInfo; const AMousePos: TPoint;
  var AHintText: TCaption; var AIsHintMultiLine: Boolean;
  var AHintTextRect: TRect);
begin
  inherited;
    AHintText := '';
    if ACellViewInfo.Value = True then
      AHintText := 'Existem diferenças das informações'
end;

procedure TfrmConsulta_Dados_Cadastrais_Resultado.btnGuiaEnderecoClick(
  Sender: TObject);
begin
  inherited;
   if cdsConsulta.IsEmpty then
      Exit;

    cdsConsulta.DisableControls;
    cdsConsulta.First;
    while not cdsConsulta.Eof do
    begin
       cdsConsulta.Edit;
       cdsConsulta.FieldByName('selecionado').Value := True;
       cdsConsulta.Post;
       cdsConsulta.Next;
    end;

    cdsConsulta.EnableControls;
    cdsConsulta.First;
end;

procedure TfrmConsulta_Dados_Cadastrais_Resultado.cxButton1Click(
  Sender: TObject);
begin
  inherited;
   if cdsConsulta.IsEmpty then
      Exit;

    cdsConsulta.DisableControls;
    cdsConsulta.First;
    while not cdsConsulta.Eof do
    begin
       cdsConsulta.Edit;
       cdsConsulta.FieldByName('selecionado').Value := False;
       cdsConsulta.Post;
       cdsConsulta.Next;
    end;

    cdsConsulta.EnableControls;
    cdsConsulta.First;

end;

procedure TfrmConsulta_Dados_Cadastrais_Resultado.cxButton2Click(
  Sender: TObject);
begin
  inherited;
   if cdsConsulta.IsEmpty then
      Exit;

    cdsConsulta.DisableControls;
    cdsConsulta.First;
    while not cdsConsulta.Eof do
    begin
       cdsConsulta.Edit;
       cdsConsulta.FieldByName('selecionado').Value := False;

       if cdsConsulta.FieldByName('diferente').Value = True then
          cdsConsulta.FieldByName('selecionado').Value := True;

       cdsConsulta.Post;
       cdsConsulta.Next;
    end;

    cdsConsulta.EnableControls;

    cdsConsulta.First;
end;

end.
