unit stgGatherControlGcl;

interface

uses
  Classes, stgGatherGclCacheData, stgGatherGclDm, stgGclResultFrm,
  stgGclGather;

type
  TstgGatherControlGcl = class
  private
    FProjects: TList;

    FGatherGclCacheData: TstgGatherGclCacheData;
    FGatherGclData: TstgGatherGclData;

    FHintPosition: Integer;

    procedure LoadHint(const ATenderName: string);

    procedure GatherSubTenderFiles;
    procedure SaveGatherResult;
    procedure ShowGatherResult;
  public
    constructor Create;
    destructor Destroy; override;

    procedure Gather;

    property Projects: TList read FProjects;
  end;

implementation

uses
  ProgressHintFrm, SysUtils;

{ TstgGatherControl }

constructor TstgGatherControlGcl.Create;
begin
  FProjects := TList.Create;
  FGatherGclCacheData := TstgGatherGclCacheData.Create;
  FGatherGclData := TstgGatherGclData.Create(nil);
end;

destructor TstgGatherControlGcl.Destroy;
begin
  FGatherGclData.Free;
  FGatherGclCacheData.Free;
  FProjects.Free;
  inherited;
end;

procedure TstgGatherControlGcl.Gather;
begin
  FHintPosition := 0;
  ShowProgressHint('正在准备数据...', FProjects.Count + 1);
  GatherSubTenderFiles;
  UpdateProgressHint('正在检查汇总结果...');
  UpdateProgressPosition(FProjects.Count + 1);
  SaveGatherResult;
  CloseProgressHint;
  ShowGatherResult;
end;

procedure TstgGatherControlGcl.GatherSubTenderFiles;
var
  vGather: TstgSubTenderFileGatherGcl;
begin
  vGather := TstgSubTenderFileGatherGcl.Create;
  try
    vGather.LoadHint := LoadHint;
    vGather.GatherTo(FGatherGclCacheData, FProjects);
  finally
    vGather.Free;
  end;
end;

procedure TstgGatherControlGcl.LoadHint(const ATenderName: string);
begin
  Inc(FHintPosition);
  UpdateProgressHint(Format('正在汇总分包标段"%s"...', [ATenderName]));
  UpdateProgressPosition(FHintPosition);
end;

procedure TstgGatherControlGcl.SaveGatherResult;
begin
  FGatherGclData.LoadGatherData(FGatherGclCacheData);
end;

procedure TstgGatherControlGcl.ShowGatherResult;
var
  Form: TstgGclResultForm;
begin
  Form := TstgGclResultForm.Create(nil);
  try
    Form.SetGatherData(FGatherGclData);
    Form.ShowModal;
  finally
    Form.Free;
  end;
end;

end.
