unit GatherProjInfo;

interface

uses
  sdIDTree, sdDB;

type
  TGatherProjInfo = class
  private
    FProjectID: Integer;
    FProjectName: string;
    FFileName: string;
    FParentName: string;
    FTopParentName: string;
    FGatherPhase: Integer;

    FProjRec: TsdDataRecord;
    FProjType: Integer;

    function GetParentName(ANode: TsdIDTreeNode): string;
    function GetTopParentName(ANode: TsdIDTreeNode): string;
  public
    constructor Create(ANode: TsdIDTreeNode; AGatherPhase: Integer; AProjType: Integer); virtual;
    destructor Destroy; override;

    property ProjectID: Integer read FProjectID;
    property ProjectName: string read FProjectName;
    property FileName: string read FFileName;
    property ParentName: string read FParentName;
    property TopParentName: string read FTopParentName;
    property GatherPhase: Integer read FGatherPhase;

    property ProjRec: TsdDataRecord read FProjRec;
    // 值为0 普通汇总项目，值非0 项目类型根据报表
    property ProjType: Integer read FProjType;
  end;

  TSelectProjInfo = class(TGatherProjInfo)
  private
    FIsTender: Boolean;
  public
    constructor Create(ANode: TsdIDTreeNode; AGatherPhase: Integer; AProjType: Integer); override;

    property IsTender: Boolean read FIsTender;
  end;

implementation

{ TGatherProjInfo }

constructor TGatherProjInfo.Create(ANode: TsdIDTreeNode; AGatherPhase: Integer; AProjType: Integer);
begin
  FProjRec := ANode.Rec;
  if Assigned(ANode) and Assigned(ANode.Rec) then
  begin
    FProjectID := FProjRec.ValueByName('ID').AsInteger;
    FProjectName := FProjRec.ValueByName('Name').AsString;
    FFileName := FProjRec.ValueByName('FileName').AsString;
    FParentName := GetParentName(ANode);
    FTopParentName := GetTopParentName(ANode);
  end
  else
    FProjectID := -1;
  FGatherPhase := AGatherPhase;
  FProjType := AProjType;
end;

destructor TGatherProjInfo.Destroy;
begin
  inherited;
end;

function TGatherProjInfo.GetParentName(ANode: TsdIDTreeNode): string;
begin
  Result := '';
  if Assigned(ANode.Parent) and Assigned(ANode.Parent.Rec) then
    Result := ANode.Parent.Rec.ValueByName('Name').AsString;
end;

function TGatherProjInfo.GetTopParentName(ANode: TsdIDTreeNode): string;
var
  vParent: TsdIDTreeNode;
begin
  Result := '';
  vParent := ANode.Parent;
  while Assigned(vParent) and Assigned(vParent.Rec) do
  begin
    Result := vParent.Rec.ValueByName('Name').AsString;
    vParent := vParent.Parent;
  end;
end;

{ TSelectProjInfo }

constructor TSelectProjInfo.Create(ANode: TsdIDTreeNode; AGatherPhase: Integer; AProjType: Integer);
begin
  inherited;
  FIsTender := FProjRec.ValueByName('Type').AsInteger = 1;
end;

end.
