unit rmGridHeaderDm;

interface

uses
  SysUtils, Classes, ProjectData, DB, DBClient;

type
  TrmGridHeaderData = class(TDataModule)
    cdsGridHeader: TClientDataSet;
    cdsGridHeaderProjectName: TWideStringField;
    cdsGridHeaderDealCode: TWideStringField;
    cdsGridHeaderCName: TWideStringField;
    cdsGridHeaderSName: TWideStringField;
    cdsGridHeaderPhaseIndex: TWideStringField;
    cdsGridHeaderDealName: TWideStringField;
    cdsGridHeaderFlowIndex: TIntegerField;
    cdsGridHeaderSName_2: TWideStringField;
    cdsGridHeaderDeadline: TWideStringField;
    cdsGridHeaderDealType: TWideStringField;
    cdsGridHeaderPhaseStr: TWideStringField;
    cdsGridHeaderCurTime: TWideStringField;
    cdsGridHeaderDeadlineFormat: TWideStringField;
  private
  public
    function AssginData(AProjectData: TProjectData): TDataSet;
  end;

implementation

uses ProjectProperty;

{$R *.dfm}

{ TrmGridHeaderData }

function TrmGridHeaderData.AssginData(
  AProjectData: TProjectData): TDataSet;
var
  sgs: TStringList;
begin
  cdsGridHeader.Active := True;
  cdsGridHeader.EmptyDataSet;
  cdsGridHeader.Append;
  cdsGridHeaderProjectName.AsString := AProjectData.ProjProperties.ProjectName;
  cdsGridHeaderDealCode.AsString := AProjectData.ProjProperties.DealIndex;
  cdsGridHeaderCName.AsString := AProjectData.ProjProperties.CName;
  cdsGridHeaderSName.AsString := AProjectData.ProjProperties.SName;
  cdsGridHeaderPhaseIndex.AsString := Format('%d ĘŚ', [AProjectData.PhaseIndex]);
  cdsGridHeaderDealName.AsString := AProjectData.ProjProperties.DealName;
  cdsGridHeaderFlowIndex.AsInteger := 0;
  cdsGridHeaderSName_2.AsString := AProjectData.ProjProperties.SName_2;
  cdsGridHeaderDeadline.AsString := AProjectData.ProjProperties.Deadline;
  cdsGridHeaderDealType.AsString := AProjectData.Projproperties.DealType;
  cdsGridHeaderPhaseStr.AsString := Format('%.2d', [AProjectData.PhaseIndex]);
  cdsGridHeaderCurTime.AsString := FormatDateTime('yyyymm', Now);
  sgs := TStringList.Create;
  try
    sgs.Delimiter := '-';
    sgs.DelimitedText := AProjectData.ProjProperties.Deadline;
    if (sgs.Count = 3) then
      cdsGridHeaderDeadlineFormat.AsString := sgs.Strings[0] + sgs.Strings[1];
  finally
    sgs.free;
  end;
  cdsGridHeader.Post;
  Result := cdsGridHeader;
end;

end.
