unit stgGclResultFrm;

interface

uses
  stgGclGatherDm, UtilMethods, ExportExcel, stgGclSubGatherFile,
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, JimTabs, JimPages, sdGridDBA, ZJGrid, ExtCtrls,
  StdCtrls, dxBar, ActnList;

type
  TstgGclResultForm = class(TForm)
    jpsResult: TJimPages;
    jpsResultBillsDetail: TJimPage;
    jtsGatherData: TJimTabSet;
    pnlGatherTree: TPanel;
    zgGatherGcl: TZJGrid;
    pnlDetail: TPanel;
    zgBillsDetail: TZJGrid;
    Splitter1: TSplitter;
    sdBillsDetail: TsdGridDBA;
    pnlResult: TPanel;
    lblResult: TLabel;
    dxpmGatherTree: TdxBarPopupMenu;
    alStgResult: TActionList;
    actnExportStgResultExcel: TAction;
    actnExportStgResult: TAction;
    saGatherGcl: TsdGridDBA;
    procedure zgGatherGclMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure dxpmGatherTreePopup(Sender: TObject);
    procedure actnExportStgResultExcelExecute(Sender: TObject);
    procedure actnExportStgResultExecute(Sender: TObject);
  private
    FGatherData: TstgGclGatherData;
  public
    destructor Destroy; override;

    procedure SetGatherData(AGatherData: TstgGclGatherData);
  end;

implementation

uses
  MainFrm;

{$R *.dfm}

procedure TstgGclResultForm.SetGatherData(AGatherData: TstgGclGatherData);
begin
  FGatherData := AGatherData;
  saGatherGcl.DataView := AGatherData.sdvGatherGcl;
  sdBillsDetail.DataView := AGatherData.sdvBillsDetail;
end;

procedure TstgGclResultForm.zgGatherGclMouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  if Button = mbRight then
    dxpmGatherTree.PopupFromCursorPos;
end;

destructor TstgGclResultForm.Destroy;
begin
  inherited;
end;

procedure TstgGclResultForm.dxpmGatherTreePopup(Sender: TObject);
begin
  SetDxBtnAction(actnExportStgResult, MainForm.dxbtnExportStgResult);
  SetDxBtnAction(actnExportStgResultExcel, MainForm.dxbtnExportStgResultExcel);
end;

procedure TstgGclResultForm.actnExportStgResultExcelExecute(Sender: TObject);
var
  sFileName: string;
  ExcelExportor: TExcelExportor;
begin
  if SaveExcelFile(sFileName) then
  begin
    ExcelExportor := TExcelExportor.Create;
    try
      ExcelExportor.ExportToFile(zgGatherGcl, sFileName);
    finally
      ExcelExportor.Free;
    end;
  end;
end;

procedure TstgGclResultForm.actnExportStgResultExecute(Sender: TObject);
var
  sFileName: string;
  vExportor: TstgGclSubGatherFileExportor;
begin
  if SaveFile(sFileName, '.sgfg') then
  begin
    vExportor := TstgGclSubGatherFileExportor.Create;
    try
      vExportor.ExportGatherDataTo(FGatherData, sFileName);
    finally
      vExportor.Free;
    end;
  end;
end;

end.
