unit UEstoqueReajusteD;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 
  FMX.Types, FMX.Graphics, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.StdCtrls,
  FMX.ScrollBox, FMX.Memo, FMX.ListBox, FMX.DateTimeCtrls, FMX.Edit,
  FMX.Layouts, FMX.TabControl, FMX.Controls.Presentation, System.Actions,
  FMX.ActnList, FMX.Gestures, Data.Bind.EngExt, Fmx.Bind.DBEngExt, System.Rtti,
  System.Bindings.Outputs, Fmx.Bind.Editors, FMX.ListView.Types,
  FMX.ListView.Appearances, FMX.ListView.Adapters.Base, FMX.ListView,
  Data.Bind.Components, Data.Bind.DBScope, Data.DB, Datasnap.DBClient,
  Fmx.Bind.Navigator, FireDAC.Stan.Intf, FireDAC.Stan.Option,
  FireDAC.Stan.Param, FireDAC.Stan.Error, FireDAC.DatS, FireDAC.Phys.Intf,
  FireDAC.DApt.Intf, uDWAbout, uRESTDWPoolerDB, FireDAC.Comp.DataSet,
  FireDAC.Comp.Client, uDWConstsData, FMX.Menus, Data.Bind.Controls,
  UEstoqueReajusteM;

type
  TFEstoqueReajusteD = class(TFrame)
    VertScrollBox1: TVertScrollBox;
    MainLayout1: TLayout;
    ToolBar1: TToolBar;
    Button2: TButton;
    Label2: TLabel;
    Button1: TButton;
    GestureManager1: TGestureManager;
    ActionList1: TActionList;
    PreviousTabAction: TPreviousTabAction;
    NextTabAction: TNextTabAction;
    TitleAction: TControlAction;
    RESTDWClientSQL1: TRESTDWClientSQL;
    Button6: TButton;
    TabControl1: TTabControl;
    TabItem3: TTabItem;
    SterlingStyleBook: TStyleBook;
    ListView1: TListView;
    StyleBook1: TStyleBook;
    TabItem1: TTabItem;
    NameList: TListBox;
    ListBoxItem1: TListBoxItem;
    Layout2: TLayout;
    Edit1: TEdit;
    ListBoxItem2: TListBoxItem;
    Edit2: TEdit;
    ListBoxItem3: TListBoxItem;
    Edit3: TEdit;
    Panel2: TPanel;
    BindSourceDB1: TBindSourceDB;
    LinkControlToFieldVALOR_ORIGINAL: TLinkControlToField;
    BindingsList1: TBindingsList;
    LinkControlToField1: TLinkControlToField;
    LinkListControlToField1: TLinkListControlToField;
    Button4: TButton;
    procedure ActionList1Update(Action: TBasicAction; var Handled: Boolean);
    procedure ListView1ItemClick(const Sender: TObject;
      const AItem: TListViewItem);
    procedure Button6Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
  private
  public
    { Public declarations }
  end;

implementation

{$R *.fmx}

uses UDataModule, UPegaSubGrupo, UPegaUnidade, UPegaProduto, MainFrmCompras,
  MainFrmEstoque;

procedure TFEstoqueReajusteD.Button4Click(Sender: TObject);
begin
  TabControl1.SetActiveTabWithTransition(TabItem3, TTabTransition.Slide);
end;

procedure TFEstoqueReajusteD.Button6Click(Sender: TObject);
begin
  RESTDWClientSQL1.Active := False;
  RESTDWClientSQL1.SQL.Clear;
  RESTDWClientSQL1.SQL.Add('select * from estoque_reajuste_detalhe where ID_ESTOQUE_REAJUSTE_CABECALHO = ' + (MainFrmEstoque.FrameAtual as TFEstoqueReajusteM).IDSelecionado);
  try
    RESTDWClientSQL1.Active := True;
  except
    on E: Exception do
    begin
      raise Exception.Create('Erro ao executar a consulta: ' + sLineBreak + E.Message);
    end;
  end;
end;

procedure TFEstoqueReajusteD.ListView1ItemClick(const Sender: TObject; const AItem: TListViewItem);
begin
  //pega dados produto
  FPegaProduto.RESTDWClientSQL1.Active := False;
  FPegaProduto.RESTDWClientSQL1.SQL.Clear;
  FPegaProduto.RESTDWClientSQL1.SQL.Add('select * from produto where id=' + RESTDWClientSQL1.FieldByName('ID_PRODUTO').AsString);
  try
    FPegaProduto.RESTDWClientSQL1.Active := True;
  except
    on E: Exception do
    begin
      raise Exception.Create('Erro ao executar a consulta: ' + sLineBreak + E.Message);
    end;
  end;
  Edit1.Text := FPegaProduto.RESTDWClientSQL1.FieldByName('ID').AsString + '|' + FPegaProduto.RESTDWClientSQL1.FieldByName('NOME').AsString;

  TabControl1.SetActiveTabWithTransition(TabItem1, TTabTransition.Slide);
end;

procedure TFEstoqueReajusteD.ActionList1Update(Action: TBasicAction; var Handled: Boolean);
var
  LTab: TTabItem;
  LList: TListBox;
begin
  LTab := TabControl1.ActiveTab;

  if Action = TitleAction then
    TitleAction.Text := LTab.Text;

  if LTab.Name = 'TabItem3' then
  begin
    Button1.Visible := False;
    Button6.Visible := True;
  end
  else
  begin
    Button1.Visible := True;
    Button6.Visible := False;
  end;
end;

end.
