unit tpNoPegDm;

interface

uses
  SysUtils, Classes, sdDB, sdProvider, sdIDTree, tpGatherTree;

type
  TtpNoPegData = class(TDataModule)
    smpNoPegBills: TsdMemoryProvider;
    sddNoPegBills: TsdDataSet;
    sdvNoPegBills: TsdDataView;
    procedure sdvNoPegBillsGetText(var Text: String;
      ARecord: TsdDataRecord; AValue: TsdValue; AColumn: TsdViewColumn;
      DisplayText: Boolean);
  private
    FNoPegTree: TsdIDTree;
  public
    constructor Create;
    destructor Destroy; override;

    procedure LoadData(ATree: TtpGatherTree);

    property NoPegTree: TsdIDTree read FNoPegTree;
  end;

implementation

{$R *.dfm}

{ TtpNoPegData }

constructor TtpNoPegData.Create;
begin
  inherited Create(nil);
  FNoPegTree := TsdIDTree.Create;
  FNoPegTree.KeyFieldName := 'ID';
  FNoPegTree.ParentFieldName := 'ParentID';
  FNoPegTree.NextSiblingFieldName := 'NextSiblingID';
  FNoPegTree.AutoCreateKeyID := True;
  FNoPegTree.AutoExpand := True;
  FNoPegTree.DataView := sdvNoPegBills;
end;

destructor TtpNoPegData.Destroy;
begin
  FNoPegTree.Free;
  inherited;
end;

procedure TtpNoPegData.LoadData(ATree: TtpGatherTree);
begin
  FNoPegTree.Active := False;
  try
    ATree.WriteData(sddNoPegBills);
  finally
    FNoPegTree.DataView := nil;
    FNoPegTree.DataView := sdvNoPegBills;
  end;
end;

procedure TtpNoPegData.sdvNoPegBillsGetText(var Text: String;
  ARecord: TsdDataRecord; AValue: TsdValue; AColumn: TsdViewColumn;
  DisplayText: Boolean);

  procedure GetDisplayText;
  begin
    if (Pos('TotalPrice', AColumn.FieldName) > 0) or
       (Pos('Quantity', AColumn.FieldName) > 0) or
       (Pos('Price', AColumn.FieldName) > 0) then
    begin
      if AValue.AsFloat = 0 then
        Text := '';
    end;
  end;

begin
  if DisplayText then
    GetDisplayText;
end;

end.
