unit ADO_QExport4Database;
{$I QExport4VerCtrl.inc}
interface

uses
  {$IFDEF VCL16}
    System.Classes,
  {$ELSE}
    Classes,
  {$ENDIF}
  QExport4,
  QExport4IniFiles;

type

  TQExport4Database = class(TQExport4)
  private
    FDatabaseName,
    FOldDatabaseName,
    FExportedDatabaseName: string;
    FTableName: string;
    FAutoCreateDatabase: boolean;
    FAutoCreateTable: boolean;
    FShowFile: boolean;
    FPrintFile: boolean;
    FAppendDateTimeToDatabaseName: Boolean;
  protected
    property TableName:string read FTableName write FTableName;
    property AutoCreateDatabase:boolean read FAutoCreateDatabase write FAutoCreateDatabase;
    property AutoCreateTable:boolean read FAutoCreateTable write FAutoCreateTable;
    procedure SaveProperties(IniFile: TQIniFile); override;
    procedure LoadProperties(IniFile: TQIniFile); override;
  public
    constructor Create(AOwner: TComponent); override;
    procedure Execute; override;
    property AppendDateTimeToDatabaseName: Boolean read
        FAppendDateTimeToDatabaseName write FAppendDateTimeToDatabaseName;
    property ShowFile: boolean read FShowFile write FShowFile;
    property PrintFile: boolean read FPrintFile write FPrintFile;
    property ExportedDatabaseName: String read FExportedDatabaseName
      write FExportedDatabaseName;
  published
    property DatabaseName: string read FDatabaseName write FDatabaseName;
    property Captions;
    property AllowCaptions;
    property ColumnsLength;
    property Formats;
    property UserFormats;
  end;

implementation

uses
  {$IFDEF VCL16}
    Winapi.ShellAPI,
  {$ELSE}
    ShellAPI,
  {$ENDIF}
  QExport4Common;

constructor TQExport4Database.Create(AOwner: TComponent);
begin
  inherited;
  FAppendDateTimeToDatabaseName := False;
end;

procedure TQExport4Database.Execute;
begin
  if FAppendDateTimeToDatabaseName then
  begin
    FOldDatabaseName := FDatabaseName;
    FDatabaseName := GetDateTimeFileName(FDatabaseName);
  end;
  try
    FWriter := GetWriterClass.Create(Self, nil);
    try
      DoExport;
    finally
      FWriter.Free;
    end;
    ShowResult;
  finally
    FExportedDatabaseName := FDatabaseName;
    if FAppendDateTimeToDatabaseName then
      FDatabaseName := FOldDatabaseName;
  end;
end;

procedure TQExport4Database.LoadProperties(IniFile: TQIniFile);
begin
  inherited;
  FDatabaseName := IniFile.ReadString(S_DATABASE, S_DATABASE_DatabaseName,
    FDatabaseName);
  FTableName := IniFile.ReadString(S_DATABASE, S_DATABASE_TableName,
    FTableName);
  FAutoCreateDatabase := IniFile.ReadBool(S_DATABASE,
    S_DATABASE_AutoCreateDatabase, FAutoCreateDatabase);
  FAutoCreateTable := IniFile.ReadBool(S_DATABASE,
    S_DATABASE_AutoCreateTable, FAutoCreateTable);
  FShowFile := IniFile.ReadBool(S_DATABASE, S_DATABASE_ShowFile, FShowFile);
  FPrintFile := IniFile.ReadBool(S_DATABASE, S_DATABASE_PrintFile, FPrintFile);
  FAppendDateTimeToDatabaseName := IniFile.ReadBool(S_DATABASE,
    S_DATABASE_AppendDateTimeToDatabaseName, FAppendDateTimeToDatabaseName);
end;

procedure TQExport4Database.SaveProperties(IniFile: TQIniFile);
begin
  inherited;
  IniFile.WriteString(S_DATABASE, S_DATABASE_DatabaseName, FDatabaseName);
  IniFile.WriteString(S_DATABASE, S_DATABASE_TableName, FTableName);
  IniFile.WriteBool(S_DATABASE, S_DATABASE_AutoCreateDatabase,
    FAutoCreateDatabase);
  IniFile.WriteBool(S_DATABASE, S_DATABASE_AutoCreateTable, FAutoCreateTable);
  IniFile.WriteBool(S_DATABASE, S_DATABASE_ShowFile, FShowFile);
  IniFile.WriteBool(S_DATABASE, S_DATABASE_PrintFile, FPrintFile);
  IniFile.WriteBool(S_DATABASE, S_DATABASE_AppendDateTimeToDatabaseName,
    FAppendDateTimeToDatabaseName);
end;

end.
