unit rpgGatherProjDm;

interface

uses
  SysUtils, Classes, sdProvider, sdDB, GatherProjInfo, ADODB;

type
  TrpgGatherProjData = class(TDataModule)
    sdpGatherProj: TsdADOProvider;
    sddGatherProj: TsdDataSet;
  private
    procedure SaveGatherInfo(AProjs: TList);
  public
    constructor Create(AConnection: TADOConnection);

    procedure SaveDataTo(AProjs: TList; const ATableName: string);
  end;

implementation

{$R *.dfm}

{ TrpgGatherProjData }

constructor TrpgGatherProjData.Create(AConnection: TADOConnection);
begin
  inherited Create(nil);
  sdpGatherProj.Connection := AConnection;
end;

procedure TrpgGatherProjData.SaveDataTo(AProjs: TList; const ATableName: string);
begin
  sdpGatherProj.TableName := ATableName;
  sddGatherProj.Open;
  sddGatherProj.BeginUpdate;
  try
    SaveGatherInfo(AProjs);
  finally
    sddGatherProj.EndUpdate;
    sddGatherProj.Save;
  end;
end;

procedure TrpgGatherProjData.SaveGatherInfo(AProjs: TList);
var
  i: Integer;
  Rec: TsdDataRecord;
  ProjInfo: TGatherProjInfo;
begin
  for i := 0 to AProjs.Count - 1 do
  begin
    ProjInfo := TGatherProjInfo(AProjs.Items[i]);
    Rec := sddGatherProj.Add;
    Rec.ValueByName('ID').AsInteger := i;
    Rec.ValueByName('ProjectID').AsInteger := ProjInfo.ProjectID;
    Rec.ValueByName('ProjectName').AsString := ProjInfo.ProjectName;
  end;
end;

end.
