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

📄 qimport2.pas

📁 EMS Advanced.Import.Component.Suite.v2.43
💻 PAS
📖 第 1 页 / 共 5 页
字号:
  FBooleanFalse.Free;
  FNullValues.Free;
  inherited;
end;

procedure TQImportFormats.Assign(Source: TPersistent);
begin
  if Source is TQImportFormats then begin
    DecimalSeparator := (Source as TQImportFormats).DecimalSeparator;
    ThousandSeparator := (Source as TQImportFormats).ThousandSeparator;
    ShortDateFormat := (Source as TQImportFormats).ShortDateFormat;
    LongDateFormat := (Source as TQImportFormats).LongDateFormat;
    DateSeparator := (Source as TQImportFormats).DateSeparator;
    ShortTimeFormat := (Source as TQImportFormats).ShortTimeFormat;
    LongTimeFormat := (Source as TQImportFormats).LongTimeFormat;
    TimeSeparator := (Source as TQImportFormats).TimeSeparator;
    BooleanTrue := (Source as TQImportFormats).BooleanTrue;
    BooleanFalse := (Source as TQImportFormats).BooleanFalse;
    NullValues := (Source as TQImportFormats).NullValues;
    Exit;
  end;
  inherited Assign(Source);
end;

procedure TQImportFormats.StoreFormats;
begin
  FOldDecimalSeparator := SysUtils.DecimalSeparator;
  FOldThousandSeparator := SysUtils.ThousandSeparator;
  FOldShortDateFormat := SysUtils.ShortDateFormat;
  FOldLongDateFormat := SysUtils.LongDateFormat;
  FOldDateSeparator := SysUtils.DateSeparator;
  FOldShortTimeFormat := SysUtils.ShortTimeFormat;
  FOldLongTimeFormat := SysUtils.LongTimeFormat;
  FOldTimeSeparator := SysUtils.TimeSeparator;
end;

procedure TQImportFormats.RestoreFormats;
begin
  SysUtils.DecimalSeparator := FOldDecimalSeparator;
  SysUtils.ThousandSeparator := FOldThousandSeparator;
  SysUtils.ShortDateFormat := FOldShortDateFormat;
  SysUtils.LongDateFormat := FOldLongDateFormat;
  SysUtils.DateSeparator := FOldDateSeparator;
  SysUtils.ShortTimeFormat := FOldShortTimeFormat;
  SysUtils.LongTimeFormat := FOldLongTimeFormat;
  SysUtils.TimeSeparator := FOldTimeSeparator;
end;

procedure TQImportFormats.ApplyParams;
begin
  SysUtils.DecimalSeparator := FDecimalSeparator;
  SysUtils.ThousandSeparator := FThousandSeparator;
  SysUtils.ShortDateFormat := FShortDateFormat;
  SysUtils.LongDateFormat := FLongDateFormat;
  SysUtils.DateSeparator := FDateSeparator;
  SysUtils.ShortTimeFormat := FShortTimeFormat;
  SysUtils.LongTimeFormat := FLongTimeFormat;
  SysUtils.TimeSeparator := FTimeSeparator;
end;

function TQImportFormats.IsDecimalSeparator: boolean;
begin
  Result := FDecimalSeparator <> SysUtils.DecimalSeparator;
end;

function TQImportFormats.IsThousandSeparator: boolean;
begin
  Result := FThousandSeparator <> SysUtils.ThousandSeparator;
end;

function TQImportFormats.IsShortDateFormat: Boolean;
begin
  Result := FShortDateFormat <> SysUtils.ShortDateFormat;
end;

function TQImportFormats.IsLongDateFormat: Boolean;
begin
  Result := FLongDateFormat <> SysUtils.LongDateFormat;
end;

function TQImportFormats.IsDateSeparator: Boolean;
begin
  Result := FDateSeparator <> SysUtils.DateSeparator;
end;

function TQImportFormats.IsShortTimeFormat: Boolean;
begin
  Result := FShortTimeFormat <> SysUtils.ShortTimeFormat;
end;

function TQImportFormats.IsLongTimeFormat: Boolean;
begin
  Result := FLongTimeFormat <> SysUtils.LongTimeFormat;
end;

function TQImportFormats.IsTimeSeparator: Boolean;
begin
  Result := FTimeSeparator <> SysUtils.TimeSeparator;
end;

procedure TQImportFormats.SetBooleanTrue(const Value: TStrings);
begin
  FBooleanTrue.Assign(Value);
end;

procedure TQImportFormats.SetBooleanFalse(const Value: TStrings);
begin
  FBooleanFalse.Assign(Value);
end;

procedure TQImportFormats.SetNullValues(const Value: TStrings);
begin
  FNullValues.Assign(Value);
end;

{ TQImport2 }

constructor TQImport2.Create(AOwner: TComponent);
begin
  inherited;
  {$IFNDEF NOGUI}
  FGridCaptionRow := -1;
  FGridStartRow := -1;
  {$ENDIF}

  FErrors := TStringList.Create;
  FMap := TStringList.Create;
  FFormats := TQImportFormats.Create;
  FFieldFormats := TQImportFieldFormats.Create(Self);
  FImportRow := TQImportRow.Create(Self);
  FImportGenerators := TQImportGenerators.Create;

  FImportRecCount := 0;
  FCommitRecCount := 100;
  FCommitAfterDone := true;
  FSkipFirstRows := 0;
  FSkipFirstCols := 0;
  FImportedRecs := 0;
  FCanceled := false;
  FErrorLog := false;
  FErrorLogFileName:= 'error.log';
  FRewriteErrorLogFile := true;
  FShowErrorLog := false;
//  FSQLLog := false;
//  FSQLLogFileRewrite := true;
//  FSQL := nil;
  FTotalRecCount := 0;
  FAddType := qatInsert;
  FImportDestination := qidDataSet;
  FImportMode := qimInsertAll;
  FKeyColumns := TStringList.Create;
  FMappedColumns := TStringList.Create;

  FIsCSV := false;
  FLastAction := qiaNone;

  FCurrentLineNumber := 1;
  FAllowDuplicates := True;
end;

destructor TQImport2.Destroy;
begin
  FImportGenerators.Free;
  FImportRow.Free;
  FFieldFormats.Free;
  FFormats.Free;
  FMap.Free;
  FErrors.Free;
  FKeyColumns.Free;
  FMappedColumns.Free;
  inherited;
end;

function TQImport2.Execute: boolean;
begin
  {$IFDEF TRIAL}
  {$IFDEF WIN32}
    if not IsIDERuning then
      ShowAboutForm;
  {$ENDIF}
  {$ENDIF}
  Result := CheckProperties;

  BeforeImport;
  try
    DoBeginImport;
    DoImport;
  finally
    try
      DoEndImport
    finally
      AfterImport;
    end;
  end;
end;

procedure TQImport2.ImportToCSV(Stream: TStream; Comma, Quote: char);
begin
  {$IFDEF TRIAL}
  {$IFDEF WIN32}
    if not IsIDERuning then
      ShowAboutForm;
  {$ENDIF}
  {$ENDIF}
  FIsCSV := true;
  try
    CheckProperties;
    if not Assigned(Stream) then
      raise Exception.Create('Stream must be assigned');
    FStream := Stream;
    FComma := Comma;
    FQuote := Quote;
    BeforeImport;
    DoBeginImport;
    DoImport;
  finally
    try
      DoEndImport;
      AfterImport;
    finally
      FIsCSV := false;
    end;
  end;
end;

procedure TQImport2.Cancel;
begin
  FCanceled := true;
end;

procedure TQImport2.LoadConfiguration(const FileName: string);
var
  FIniFile: TIniFile;
begin
  if not FileExists(FileName) then Exit;
  FIniFile := TIniFile.Create(FileName);
  try
    DoLoadConfiguration(FIniFile);
  finally
    FIniFile.Free;
  end;
end;

procedure TQImport2.SaveConfiguration(const FileName: string);
var
  FIniFile: TIniFile;
begin
  if Trim(FileName) = EmptyStr then Exit;
  FIniFile := TIniFile.Create(FileName);
  try
    DoSaveConfiguration(FIniFile);
  finally
    FIniFile.Free;
  end;
end;

procedure TQImport2.DoLoadConfiguration(IniFile: TIniFile);
var
  i: integer;
  AStrings: TStrings;
  str: string;
begin
  with IniFile do
  begin
    AStrings := TStringList.Create;
    try
      Self.FileName := ReadString(QI_BASE, QI_FILE_NAME, Self.FileName);
      AStrings.Clear;
      Map.Clear;
      ReadSection(QI_MAP, AStrings);
      for i := 0 to AStrings.Count - 1 do
        Map.Values[AStrings[i]] := ReadString(QI_MAP, AStrings[i], EmptyStr);
      Formats.DecimalSeparator := ReadString(BASE_FORMATS, BF_DECIMAL_SEPARATOR,
        Formats.DecimalSeparator)[1];
      Formats.ThousandSeparator := ReadString(BASE_FORMATS,
        BF_THOUSAND_SEPARATOR, Formats.ThousandSeparator)[1];
      Formats.ShortDateFormat := ReadString(BASE_FORMATS, BF_SHORT_DATE_FORMAT,
        Formats.ShortDateFormat);
      Formats.LongDateFormat := ReadString(BASE_FORMATS, BF_LONG_DATE_FORMAT,
        Formats.LongDateFormat);
      Formats.ShortTimeFormat := ReadString(BASE_FORMATS, BF_SHORT_TIME_FORMAT,
        Formats.ShortTimeFormat);
      Formats.LongTimeFormat := ReadString(BASE_FORMATS, BF_LONG_TIME_FORMAT,
        Formats.LongTimeFormat);
      AStrings.Clear;
      Formats.BooleanTrue.Clear;
      ReadSection(BOOLEAN_TRUE, AStrings);
      for i := 0 to AStrings.Count - 1 do
        Formats.BooleanTrue.Add(AStrings[i]);
      AStrings.Clear;
      Formats.BooleanFalse.Clear;
      ReadSection(BOOLEAN_FALSE, AStrings);
      for i := 0 to AStrings.Count - 1 do
        Formats.BooleanFalse.Add(AStrings[i]);
      AStrings.Clear;
      Formats.NullValues.Clear;
      ReadSection(NULL_VALUES, AStrings);
      for i := 0 to AStrings.Count - 1 do
        Formats.NullValues.Add(AStrings[i]);
      AStrings.Clear;
      FieldFormats.Clear;
      for i := 0 to DestinationColCount - 1 do
      begin
        str := DATA_FORMATS + DestinationColName(i);
        ReadSection(str, AStrings);
        if AStrings.Count = 0 then
          Continue;
        with FieldFormats.Add do
        begin
          FieldName := DestinationColName(i);
          GeneratorValue := ReadInteger(str, DF_GENERATOR_VALUE, 0);
          GeneratorStep := ReadInteger(str, DF_GENERATOR_STEP, 0);
          ConstantValue := ReadString(str, DF_CONSTANT_VALUE, EmptyStr);
          NullValue := ReadString(str, DF_NULL_VALUE, EmptyStr);
          DefaultValue := ReadString(str, DF_DEFAULT_VALUE, EmptyStr);
          LeftQuote := ReadString(str, DF_LEFT_QUOTE, EmptyStr);
          RightQuote := ReadString(str, DF_RIGHT_QUOTE, EmptyStr);
          QuoteAction := TQuoteAction(ReadInteger(str, DF_QUOTE_ACTION, 0));
          CharCase := TQImportCharCase(ReadInteger(str, DF_CHAR_CASE, 0));
          CharSet := TQImportCharSet(ReadInteger(str, DF_CHAR_SET, 0));
        end;
      end;
      CommitAfterDone := ReadBool(QI_BASE, QI_COMMIT_AFTER_DONE,
        CommitAfterDone);
      CommitRecCount := ReadInteger(QI_BASE, QI_COMMIT_REC_COUNT,
        CommitRecCount);
      ImportRecCount := ReadInteger(QI_BASE, QI_IMPORT_REC_COUNT,
        ImportRecCount);
      ErrorLog := ReadBool(QI_BASE, QI_ENABLE_ERROR_LOG, ErrorLog);
      ErrorLogFileName := ReadString(QI_BASE, QI_ERROR_LOG_FILE_NAME,
        ErrorLogFileName);
      RewriteErrorLogFile := ReadBool(QI_BASE, QI_REWRITE_ERROR_LOG_FILE,
        RewriteErrorLogFile);
      ShowErrorLog := ReadBool(QI_BASE, QI_SHOW_ERROR_LOG, ShowErrorLog);
//      SQLLog := ReadBool(QI_BASE, QI_ENABLE_SQL_LOG, SQLLog);
//      SQLLogFileName := ReadString(QI_BASE, QI_SQL_LOG_FILE_NAME,
//        SQLLogFileName);
//      SQLLogFileRewrite := ReadBool(QI_BASE, QI_SQL_LOG_FILE_REWRITE,
//        SQLLogFileRewrite);

      ImportDestination := TQImportDestination(ReadInteger(QI_BASE,
        QI_IMPORT_DESTINATION, Integer(qidDataSet)));
      ImportMode := TQImportMode(ReadInteger(QI_BASE, QI_IMPORT_MODE,
        Integer(qimInsertAll)));
      AStrings.Clear;
      KeyColumns.Clear;
      ReadSection(QI_KEY_COLUMNS, AStrings);
      for i := 0 to AStrings.Count - 1 do
        KeyColumns.Add(AStrings[i]);
      {$IFNDEF NOGUI}
      GridCaptionRow := ReadInteger(QI_BASE, QI_GRID_CAPTION_ROW, -1);
      GridStartRow := ReadInteger(QI_BASE, QI_GRID_START_ROW, -1);
      {$ENDIF}
    finally
      AStrings.Free;
    end;
  end;
end;

procedure TQImport2.DoSaveConfiguration(IniFile: TIniFile);
var
  i: integer;
  str: string;
begin
  with IniFile do
  begin
    WriteString(QI_BASE, QI_FILE_NAME, Self.FileName);
    EraseSection(QI_MAP);
    for i := 0 to Map.Count - 1 do
      WriteString(QI_MAP, Map.Names[i], Map.Values[Map.Names[i]]);
    WriteString(BASE_FORMATS, BF_DECIMAL_SEPARATOR, Formats.DecimalSeparator);
    WriteString(BASE_FORMATS, BF_THOUSAND_SEPARATOR, Formats.ThousandSeparator);
    WriteString(BASE_FORMATS, BF_SHORT_DATE_FORMAT, Formats.ShortDateFormat);
    WriteString(BASE_FORMATS, BF_LONG_DATE_FORMAT, Formats.LongDateFormat);
    WriteString(BASE_FORMATS, BF_SHORT_TIME_FORMAT, Formats.ShortTimeFormat);
    WriteString(BASE_FORMATS, BF_LONG_TIME_FORMAT, Formats.LongTimeFormat);
    EraseSection(BOOLEAN_TRUE);
    for i := 0 to Formats.BooleanTrue.Count - 1 do
      WriteString(BOOLEAN_TRUE, Formats.BooleanTrue[i], EmptyStr);
    EraseSection(BOOLEAN_FALSE);
    for i := 0 to Formats.BooleanFalse.Count - 1 do
      WriteString(BOOLEAN_FALSE, Formats.BooleanFalse[i], EmptyStr);
    EraseSection(NULL_VALUES);
    for i := 0 to Formats.NullValues.Count - 1 do
      WriteString(NULL_VALUES, Formats.NullValues[i], EmptyStr);
    for i := 0 to FieldFormats.Count - 1 do begin
      str := FieldFormats[i].FieldName;
      if Trim(str) = EmptyStr then Continue;
      WriteString(str, DF_GENERATOR_VALUE, FieldFormats[i].FieldName);
      WriteInteger(str, DF_GENERATOR_VALUE, FieldFormats[i].GeneratorValue);
      WriteInteger(str, DF_GENERATOR_STEP, FieldFormats[i].GeneratorStep);
      WriteString(str, DF_CONSTANT_VALUE, FieldFormats[i].ConstantValue);
      WriteString(str, DF_NULL_VALUE, FieldFormats[i].NullValue);
      WriteString(str, DF_DEFAULT_VALUE, FieldFormats[i].DefaultValue);
      WriteString(str, DF_LEFT_QUOTE, FieldFormats[i].LeftQuote);
      WriteString(str, DF_RIGHT_QUOTE, FieldFormats[i].RightQuote);
      WriteInteger(str, DF_QUOTE_ACTION, Integer(FieldFormats[i].QuoteAction));
      WriteInteger(str, DF_CHAR_CASE, Integer(FieldFormats[i].CharCase));
      WriteInteger(str, DF_CHAR_SET, Integer(FieldFormats[i].CharSet));
    end;
    WriteBool(QI_BASE, QI_COMMIT_AFTER_DONE, CommitAfterDone);
    WriteInteger(QI_BASE, QI_COMMIT_REC_COUNT, CommitRecCount);
    WriteInteger(QI_BASE, QI_IMPORT_REC_COUNT, ImportRecCount);
    WriteBool(QI_BASE, QI_ENABLE_ERROR_LOG, ErrorLog);
    WriteString(QI_BASE, QI_ERROR_LOG_FILE_NAME, ErrorLogFileName);
    WriteBool(QI_BASE, QI_REWRITE_ERROR_LOG_FILE, RewriteErrorLogFile);
    WriteBool(QI_BASE, QI_SHOW_ERROR_LOG, ShowErrorLog);
//    WriteBool(QI_BASE, QI_ENABLE_SQL_LOG, SQLLog);
//    WriteString(QI_BASE, QI_SQL_LOG_FILE_NAME, SQLLogFileName);
//    WriteBool(QI_BASE, QI_SQL_LOG_FILE_REWRITE, SQLLogFileRewrite);

    WriteInteger(QI_BASE, QI_IMPORT_DESTINATION, Integer(ImportDestination));
    WriteInteger(QI_BASE, QI_IMPORT_MODE, Integer(ImportMode));

⌨️ 快捷键说明

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