unit ReportHistoryFrm;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, StdCtrls, Buttons, ReportManagerDM,
  cxLookAndFeelPainters, cxButtons;

type
  TReportHistoryForm = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    lblReportName: TLabel;
    tcHistory: TTabControl;
    mmMemo: TMemo;
    btnDown: TSpeedButton;
    procedure tcHistoryChange(Sender: TObject);
    procedure btnDownClick(Sender: TObject);
  private
    FReport: TReport;
    procedure SetReport(const Value: TReport);
    { Private declarations }
  public
    { Public declarations }
    constructor Create(AReport: TReport);
    procedure Init;
    property Report: TReport read FReport write SetReport;
  end;

implementation

{$R *.dfm}

procedure TReportHistoryForm.tcHistoryChange(Sender: TObject);
begin
  case tcHistory.TabIndex of
    0: mmMemo.Text := FReport.NewestMemo;
    1: mmMemo.Text := FReport.HistoryMemo1;
    2: mmMemo.Text := FReport.HistoryMemo2;
  end;
  btnDown.Enabled := (tcHistory.Tabs[tcHistory.TabIndex] <> '') and (tcHistory.Tabs[tcHistory.TabIndex] <> FReport.LocalVer);

  if (tcHistory.Tabs[tcHistory.TabIndex] <> '') and (tcHistory.Tabs[tcHistory.TabIndex] = FReport.LocalVer) then
    btnDown.Caption := '正在使用'
  else
    btnDown.Caption := '下载此版本';
end;

constructor TReportHistoryForm.Create(AReport: TReport);
begin
  inherited create(nil);
  FReport := AReport;
  Init;
end;

procedure TReportHistoryForm.SetReport(const Value: TReport);
begin
  FReport := Value;
end;

procedure TReportHistoryForm.Init;
begin
  lblReportName.Caption := FReport.FileName;
  lblReportName.Update;

  tcHistory.Tabs.Delete(0);
  tcHistory.Tabs.Delete(0);
  tcHistory.Tabs.Delete(0);

  if FReport.NewestVer <> '' then
    tcHistory.Tabs.Add(FReport.NewestVer);

  if FReport.HistoryVer1 <> '' then
    tcHistory.Tabs.Add(FReport.HistoryVer1);

  if FReport.HistoryVer2 <> '' then
    tcHistory.Tabs.Add(FReport.HistoryVer2);

//  tcHistory.Tabs[0] := FReport.NewestVer;
//  tcHistory.Tabs[1] := FReport.HistoryVer1;
//  tcHistory.Tabs[2] := FReport.HistoryVer2;

  tcHistory.OnChange(nil);
end;

procedure TReportHistoryForm.btnDownClick(Sender: TObject);
begin
  if FReport.Update(tcHistory.Tabs[tcHistory.TabIndex]) then
  begin
    btnDown.Caption := '正在使用';
    btnDown.Enabled := False;
  end
  else
  begin
    btnDown.Caption := '下载此版本';
    btnDown.Enabled := True;
  end;
end;

end.
