unit MainDataListDm;
// 各期主要数据一览表，与项目管理界面更新有关
// 切换最新一期数据与其他各期数据时，保存最新一期数据
// 保存时，如当前期为最新一期数据，保存最新一期数据
// 往期数据只做历史数据备用，不做修改

interface

uses
  SysUtils, Classes, sdDB, sdProvider, ADODB;

type
  TMainListData = class(TDataModule)
    sdpMainDataList: TsdADOProvider;
    sddMainDataList: TsdDataSet;
  private
    FProjectData: TObject;
  public
    constructor Create(AProjectData: TObject);
    destructor Destroy; override;

    procedure Open(AConnection: TADOConnection);
    procedure Close;
    procedure Save;

    function GetPhaseMainRecord(APhaseIndex: Integer): TsdDataRecord;

    property ProjectData: TObject read FProjectData;
  end;

implementation

{$R *.dfm}

{ TMainListData }

procedure TMainListData.Close;
begin
  sddMainDataList.Close;
end;

constructor TMainListData.Create(AProjectData: TObject);
begin
  inherited Create(nil);
  FProjectData := AProjectData;
end;

destructor TMainListData.Destroy;
begin
  inherited;
end;

function TMainListData.GetPhaseMainRecord(
  APhaseIndex: Integer): TsdDataRecord;
begin
  Result := sddMainDataList.Locate('PhaseID', APhaseIndex);
  if not Assigned(Result) then
  begin
    Result := sddMainDataList.Add;
    Result.ValueByName('PhaseID').AsInteger := APhaseIndex;
  end;
end;

procedure TMainListData.Open(AConnection: TADOConnection);
begin
  sdpMainDataList.Connection := AConnection;
  sddMainDataList.Open;
end;

procedure TMainListData.Save;
begin
  sddMainDataList.Save;
end;

end.
