⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qexport3.pas

📁 DELPHI开发VCL
💻 PAS
📖 第 1 页 / 共 5 页
字号:
  protected
    property Title: string read FTitle write FTitle;
    property AllowCaptions: boolean read FAllowCaptions
      write FAllowCaptions default true;
    property AutoCalcColWidth: boolean read FAutoCalcColWidth
      write FAutoCalcColWidth default false;
    property ColumnsWidth: TStrings read FColumnsWidth write SetColumnsWidth;
    property ColumnsAlign: TStrings read FColumnsAlign write SetColumnsAlign;
    property ColumnsLength: TStrings read FColumnsLength write SetColumnsLength;

    property OnGetCellParams: TGetCellParamsEvent read FOnGetCellParams
      write FOnGetCellParams;
    property OnFetchedRecord: TExportedRecordEvent read FOnFetchedRecord
      write FOnFetchedRecord;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;

    procedure Execute; virtual;
    procedure ExportToStream(AStream: TStream);
    procedure Abort; virtual;
    function NormalString(const S: string): string; virtual;

    procedure SavePropertiesToFile(const FileName: string);
    procedure LoadPropertiesFromFile(const FileName: string);

    property Aborted: boolean read FAborted write FAborted;

    property Header: TStrings read FHeader write SetHeader;
    property Captions: TStrings read FCaptions write SetCaptions;
    property Footer: TStrings read FFooter write SetFooter;
    property Formats: TQExportFormats read FFormats write SetFormats;
    property UserFormats: TStrings read FUserFormats write SetUserFormats;
  published
    property ExportSource: TQExportSource read FExportSource
      write FExportSource default esDataSet;
    property DataSet: TDataSet read FDataSet write FDataSet;
    property CustomSource: TqeCustomSource read FCustomSource
      write FCustomSource; 
    {$IFNDEF NOGUI}
    property ListView: TListView read FListView write FListView;
    property DBGrid: TDBGrid read FDBGrid write FDBGrid;
    property StringGrid: TStringGrid read FStringGrid write FStringGrid;
    {$ENDIF}
    property ExportedFields: TStrings read FExportedFields
      write SetExportedFields;

    property CurrentRecordOnly: boolean read FCurrentRecordOnly
      write FCurrentRecordOnly default false;
    property GoToFirstRecord: boolean read FGoToFirstRecord
      write FGoToFirstRecord default true;
    property ExportRecCount: integer read FExportRecCount
      write FExportRecCount default 0;
    property SkipRecCount: integer read FSkipRecCount
      write FSkipRecCount default 0;
    property OnlyVisibleFields: boolean read FOnlyVisibleFields
      write FOnlyVisibleFields default false;
    property AutoCalcStrType: boolean read FAutoCalcStrType
      write FAutoCalcStrType default false;
    property CaptionRow: integer read FCaptionRow write FCaptionRow default -1;
    property ExportEmpty: boolean read FExportEmpty
      write FExportEmpty default true;

    property About: string read FAbout write FAbout;
    property _Version: string read F_Version write F_Version;

    property OnBeginExport: TNotifyEvent read FOnBeginExport
      write FOnBeginExport;
    property OnEndExport: TNotifyEvent read FOnEndExport write FOnEndExport;
    property OnSkippedRecord: TExportedRecordEvent read FOnSkippedRecord
      write FOnSkippedRecord;
    property OnExportedRecord: TExportedRecordEvent read FOnExportedRecord
      write FOnExportedRecord;
    property OnStopExport: TQExportStopEvent read FOnStopExport
      write FOnStopExport;
    property OnGetExportText: TGetExportTextEvent read FOnGetExportText
      write FOnGetExportText;
    property OnBeforeExportRow: TBeforeExportRowEvent read FOnBeforeExportRow
      write FOnBeforeExportRow; 
  end;

  TQExport3Text = class(TQExport3)
  private
    FFileName: string;
    {$IFDEF WIN32}
    FShowFile: boolean;
    FPrintFile: boolean;
    {$ENDIF}
  protected
    procedure ShowResult; virtual;
    procedure SaveProperties(IniFile: TIniFile); override;
    procedure LoadProperties(IniFile: TIniFile); override;
    function GetShowedFileName: string; virtual;
    function GetPrintedFileName: string; virtual;
  public
    constructor Create(AOwner: TComponent); override;
    procedure Execute; override;
  published
    property FileName: string read FFileName write FFileName;
    {$IFDEF WIN32}
    property ShowFile: boolean read FShowFile write FShowFile default false;
    property PrintFile: boolean read FPrintFile write FPrintFile default false;
    {$ENDIF}
  end;

  TQExport3AdvancedText = class(TQExport3Text)
  protected
    procedure SaveProperties(IniFile: TIniFile); override;
    procedure LoadProperties(IniFile: TIniFile); override;
  published
    property Header;
    property Footer;
  end;

  TQExport3FormatTextSQL = class(TQExport3AdvancedText)
  protected
    procedure SaveProperties(IniFile: TIniFile); override;
    procedure LoadProperties(IniFile: TIniFile); override;
  published
    property Formats;
    property UserFormats;
  end;

  TQExport3FormatText = class(TQExport3AdvancedText)
  protected
    procedure SaveProperties(IniFile: TIniFile); override;
    procedure LoadProperties(IniFile: TIniFile); override;
  published
    property AllowCaptions;
    property Captions;
    property Formats;
    property UserFormats;
  end;

  TQExport3Memory = class(TQExport3)
  public
    {$IFNDEF NOGUI}
    procedure Execute; override;
    {$ENDIF}
  end;

function DataType2QExportColType(Field: TField): TQExportColType;
function DataType2SQLType(Field: TField): string;
function QExportType2SQLType(Column: TQExportColumn): string;
function QExportColTypeAsString(ExportColType: TQExportColType): string;
function QExportSourceAsString(ExportSource: TQExportSource): string;

{$IFDEF WIN32}
function QExportLocale: TQExportLocale;
function QExportLoadStr(ID: Integer): string;
{$ENDIF}

implementation

uses SysUtils, QExport3Common, TypInfo
     {$IFDEF WIN32}
       , Windows, ShellAPI, ClipBrd, QExport3StrIDs,
       {$IFDEF TRIAL}fuQExport3About,{$ENDIF} FileCtrl
     {$ENDIF}
     {$IFDEF LINUX}
       {$IFNDEF NOGUI}, QClipbrd, Types, QExport3Consts {$ENDIF}
     {$ENDIF};

{$IFDEF WIN32}
var
  Locale: TQExportLocale = nil;
{$ENDIF}

{$IFDEF WIN32}
function QExportLocale: TQExportLocale;
begin
  if Locale = nil then
    Locale := TQExportLocale.Create;
  Result := Locale;
end;

function QExportLoadStr(ID: Integer): string;
begin
  Result := QExportLocale.LoadStr(ID);
end;
{$ENDIF}

function DataType2QExportColType(Field: TField): TQExportColType;
begin
  Result := ectUnknown;
  if not Assigned(Field) then Exit;
  case Field.DataType of
    ftBlob, ftMemo,
    {$IFNDEF VCL3}
    ftWideString,
    {$ENDIF}
    ftString: Result := ectString;
    ftSmallint, ftInteger,
    ftWord, ftAutoInc: Result := ectInteger;
    {$IFNDEF VCL3}
    ftLargeInt: Result := ectBigint;
    {$ENDIF}
    ftBoolean: Result := ectBoolean;
    ftFloat,
    {$IFDEF VCL6}
    ftFMTBcd,
    {$ENDIF}
    ftBCD: Result := ectFloat;
    ftCurrency: Result := ectCurrency;
    ftDate: Result := ectDate;
    ftTime: Result := ectTime;
    {$IFDEF VCL6}
    ftTimeStamp,
    {$ENDIF}
    ftDateTime: Result := ectDateTime;
    ftGuid	: Result := ectString;
  end;
end;

function DataType2SQLType(Field: TField): string;
begin
  Result := 'UNKNOWN';
  case Field.DataType of
    ftOraBlob, ftBlob, ftMemo, ftGraphic, ftFmtMemo: Result := 'BLOB';
    {$IFNDEF VCL3} ftWideString, {$ENDIF}
    ftString: Result := Format('CHAR(%d)', [Field.Size]);
    ftSmallint, ftInteger, {$IFNDEF VCL3} ftLargeInt, {$ENDIF}
    ftWord, ftBoolean: Result := 'INTEGER';
    ftFloat, ftBCD, {$IFDEF VCL6} ftFMTBcd, {$ENDIF} ftCurrency: Result := 'DOUBLE PRECISION';
    ftDate, ftTime, ftDateTime: Result := 'DATE';
    ftOraClob: Result := 'CLOB'
  end;
end;

function QExportType2SQLType(Column: TQExportColumn): string;
begin
  case Column.ColType of
    ectInteger, ectBigint, ectBoolean: Result := 'INTEGER';
    ectFloat, ectCurrency: Result := 'DOUBLE PRECISSION';
    ectDate, ectTime, ectDateTime: Result := 'DATE';
    ectString: Result := Format('CHAR(%d)', [Column.Width]);
  end;
end;

function QExportColTypeAsString(ExportColType: TQExportColType): string;
begin
  case ExportColType of
    ectInteger, ectBigint: Result := 'Integer';
    ectFloat: Result := 'Float';
    ectCurrency: Result := 'Currency';
    ectDate: Result := 'Date';
    ectTime: Result := 'Time';
    ectDateTime: Result := 'DateTime';
    ectString: Result := 'String';
    ectBoolean: Result := 'Boolean';
    else Result := 'Unknown';
  end;
end;

function QExportSourceAsString(ExportSource: TQExportSource): string;
begin
  case ExportSource of
    esDataSet: Result := 'DataSet';
    esCustom: Result := 'CustomSource';
    esDBGrid: Result := 'DBGrid';
    esListView: Result := 'ListView';
    esStringGrid: Result := 'StringGrid';
    else Result := EmptyStr;
  end;
end;

{$IFDEF TRIAL}
{$IFDEF WIN32}
function IsIDERuning: Boolean;
begin
  Result := (FindWindow('TAppBuilder', nil) <> 0) or
            (FindWindow('TPropertyInspector', nil) <> 0) or
            (FindWindow('TAlignPalette', nil) <> 0);
end;
{$ENDIF}
{$ENDIF}

procedure CheckTrial;
begin
{$IFDEF TRIAL}
{$IFDEF WIN32}
  if not IsIDERuning then
    ShowAboutForm;
{$ENDIF}
{$ENDIF}
end;

{ TQExportFormats }

constructor TQExportFormats.Create;
begin
  inherited;
  ResetFormats;
end;

procedure TQExportFormats.Assign(Source: TPersistent);
begin
  if Source is TQExportFormats then begin
    IntegerFormat := (Source as TQExportFormats).IntegerFormat;
    FloatFormat := (Source as TQExportFormats).FloatFormat;
    DateFormat := (Source as TQExportFormats).DateFormat;
    TimeFormat := (Source as TQExportFormats).TimeFormat;
    DateTimeFormat := (Source as TQExportFormats).DateTimeFormat;
    CurrencyFormat := (Source as TQExportFormats).CurrencyFormat;
    BooleanTrue := (Source as TQExportFormats).BooleanTrue;
    BooleanFalse := (Source as TQExportFormats).BooleanFalse;
    NullString := (Source as TQExportFormats).NullString;
    Exit;
  end;
  inherited;
end;

procedure TQExportFormats.ResetFormats;
begin
  FIntegerFormat := S_INTEGER_FORMAT;
  FFloatFormat := S_FLOAT_FORMAT;
  FDateFormat := DefaultDateFormat;
  FTimeFormat := DefaultTimeFormat;
  FDateTimeFormat := DefaultDateTimeFormat;
  FCurrencyFormat := DefaultCurrencyFormat;
  FBooleanTrue := S_BOOLEAN_TRUE;
  FBooleanFalse := S_BOOLEAN_FALSE;
end;

procedure TQExportFormats.SetIntegerFormat(const Value: string);
begin
  if FIntegerFormat <> Value then
    if Value = EmptyStr
      then FIntegerFormat := S_INTEGER_FORMAT
      else FIntegerFormat := Value;
end;

procedure TQExportFormats.SetFloatFormat(const Value: string);
begin
  if FFloatFormat <> Value then
    {if Value = EmptyStr
      then FFloatFormat := S_FLOAT_FORMAT
      else FFloatFormat := Value;}
    FFloatFormat := Value; // ab
end;

procedure TQExportFormats.SetDateFormat(const Value: string);
begin
  if FDateFormat <> Value then
    if Value = EmptyStr
      then FDateFormat := DefaultDateFormat
      else FdateFormat := Value;
end;

procedure TQExportFormats.SetTimeFormat(const Value: string);
begin
  if FTimeFormat <> Value then
    if Value = EmptyStr
      then FTimeFormat := DefaultTimeFormat
      else FTimeFormat := Value;
end;

procedure TQExportFormats.SetDateTimeFormat(const Value: string);
begin
  if FDateTimeFormat <> Value then
    if Value = EmptyStr
      then FDateTimeFormat := DefaultDateTimeFormat
      else FDateTimeFormat := Value;
end;

procedure TQExportFormats.SetCurrencyFormat(const Value: string);
begin
  if FCurrencyFormat <> Value then
    if Value = EmptyStr
      then FCurrencyFormat := DefaultCurrencyFormat
      else FCurrencyFormat := Value;
end;

procedure TQExportFormats.SetBooleanTrue(const Value: string);
begin
  if FBooleanTrue <> Value then
    if Value = EmptyStr
      then FBooleanTrue := S_BOOLEAN_TRUE
      else FBooleanTrue := Value;
end;

procedure TQExportFormats.SetBooleanFalse(const Value: string);
begin
  if FBooleanFalse <> Value then
    if Value = EmptyStr
      then FBooleanFalse := S_BOOLEAN_FALSE
      else FBooleanFalse := Value;
end;

procedure TQExportFormats.SetNullString(const Value: string);
begin
  FNullString := Trim(Value);
end;

function TQExportFormats.IsIntegerFormatStored: boolean;
begin
  Result := AnsiCompareStr(FIntegerFormat, S_INTEGER_FORMAT) <> 0;
end;

function TQExportFormats.IsFloatFormatStored: boolean;
begin
  Result := AnsiCompareStr(FFloatFormat, S_FLOAT_FORMAT) <> 0;
end;

function TQExportFormats.IsDateFormatStored: boolean;
begin
  Result := AnsiCompareStr(FDateFormat, DefaultDateFormat) <> 0;
end;

function TQExportFormats.IsTimeFormatStored: boolean;
begin
  Result := AnsiCompareStr(FTimeFormat, DefaultTimeFormat) <> 0;
end;

function TQExportFormats.IsDateTimeFormatStored: boolean;
begin
  Result := AnsiCompareStr(FDateTimeFormat, DefaultDateTimeFormat) <> 0;
end;

function TQExportFormats.IsCurrencyFormatStored: boolean;
begin
  Result := AnsiCompareStr(FCurrencyFormat, DefaultCurrencyFormat) <> 0;
end;

function TQExportFormats.IsBooleanTrueStored: boolean;
begin
  Result := AnsiCompareStr(FBooleanTrue, S_BOOLEAN_TRUE) <> 0;
end;

function TQExportFormats.IsBooleanFalseStored: boolean;
begin
  Result := AnsiCompareStr(FBooleanFalse, S_BOOLEAN_FALSE) <> 0;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -