ADIF import: implement filter by date range

This commit is contained in:
Gleb Baryshev 2018-10-15 18:35:47 +02:00
parent 82c00d0c71
commit 2b36956554
3 changed files with 170 additions and 5 deletions

View File

@ -1,13 +1,13 @@
object frmAdifImport: TfrmAdifImport
Left = 425
Height = 280
Height = 367
Top = 252
Width = 444
ActiveControl = chkLotOfQSO
BorderIcons = [biSystemMenu]
BorderStyle = bsDialog
Caption = 'Importing ADIF file'
ClientHeight = 280
ClientHeight = 367
ClientWidth = 444
Icon.Data = {
BE0C00000000010001002020000001001800A80C000016000000280000002000
@ -238,8 +238,8 @@ object frmAdifImport: TfrmAdifImport
end
object sb: TStatusBar
Left = 0
Height = 21
Top = 259
Height = 20
Top = 347
Width = 444
Panels = <
item
@ -256,6 +256,109 @@ object frmAdifImport: TfrmAdifImport
ModalResult = 2
TabOrder = 5
end
object chkFilterDateRange: TCheckBox
AnchorSideTop.Control = cmbProfiles
AnchorSideTop.Side = asrBottom
Left = 8
Height = 21
Top = 264
Width = 198
BorderSpacing.Top = 18
Caption = 'Filter: only import date range'
OnChange = chkFilterDateRangeChange
TabOrder = 6
end
object pnlFilterDateRange: TPanel
AnchorSideTop.Control = chkFilterDateRange
AnchorSideTop.Side = asrBottom
Left = 8
Height = 45
Top = 291
Width = 334
BorderSpacing.Top = 6
BevelOuter = bvNone
ClientHeight = 45
ClientWidth = 334
Enabled = False
TabOrder = 7
object lblDateFrom: TLabel
AnchorSideTop.Control = edtDateFrom
AnchorSideTop.Side = asrCenter
Left = 6
Height = 18
Top = 9
Width = 29
Caption = 'from'
ParentColor = False
end
object lblDateTo: TLabel
AnchorSideLeft.Control = edtDateFrom
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = edtDateTo
AnchorSideTop.Side = asrCenter
Left = 156
Height = 18
Top = 9
Width = 13
BorderSpacing.Left = 12
Caption = 'to'
ParentColor = False
end
object edtDateFrom: TDateEdit
AnchorSideLeft.Control = lblDateFrom
AnchorSideLeft.Side = asrBottom
Left = 41
Height = 24
Top = 6
Width = 103
CalendarDisplaySettings = [dsShowHeadings, dsShowDayNames]
DateOrder = doYMd
ButtonWidth = 23
BorderSpacing.Left = 6
NumGlyphs = 1
MaxLength = 10
TabOrder = 0
Text = ' . . '
end
object edtDateTo: TDateEdit
AnchorSideLeft.Control = lblDateTo
AnchorSideLeft.Side = asrBottom
Left = 175
Height = 24
Top = 6
Width = 103
CalendarDisplaySettings = [dsShowHeadings, dsShowDayNames]
DateOrder = doYMd
ButtonWidth = 23
BorderSpacing.Left = 6
NumGlyphs = 1
MaxLength = 10
TabOrder = 1
Text = ' . . '
end
end
object lblFilteredOut: TLabel
AnchorSideTop.Side = asrBottom
Left = 298
Height = 18
Top = 30
Width = 72
BorderSpacing.Top = 6
Caption = 'Filtered out:'
ParentColor = False
end
object lblFilteredOutCount: TLabel
AnchorSideLeft.Control = lblFilteredOut
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = lblFilteredOut
Left = 388
Height = 18
Top = 30
Width = 119
BorderSpacing.Left = 18
Caption = 'lblFilteredOutCount'
ParentColor = False
end
object tr: TSQLTransaction
Active = False
Action = caNone

View File

@ -17,10 +17,14 @@ interface
uses
Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, StdCtrls,
Buttons, lcltype, ComCtrls, iniFiles, sqldb, dateutils;
Buttons, lcltype, ComCtrls, ExtCtrls, EditBtn, iniFiles, sqldb, dateutils,
strutils;
{$include uADIFhash.pas}
type
TDateString = string[10]; //Date in yyyy-mm-dd format
type Tnejakyzaznam=record
st:longint; // pocet pridanych polozek;
BAND:string[10];
@ -85,25 +89,34 @@ type
TfrmAdifImport = class(TForm)
btnImport: TButton;
btnClose: TButton;
chkFilterDateRange: TCheckBox;
chkLotOfQSO: TCheckBox;
cmbProfiles: TComboBox;
edtDateFrom: TDateEdit;
edtDateTo: TDateEdit;
edtRemarks: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
lblFilteredOut: TLabel;
lblFilteredOutCount: TLabel;
lblDateFrom: TLabel;
lblDateTo: TLabel;
lblErrorLog: TLabel;
lblComplete: TLabel;
lblCount: TLabel;
lblErrors: TLabel;
lblFileName: TLabel;
pnlFilterDateRange: TPanel;
Q1: TSQLQuery;
Q2: TSQLQuery;
Q3: TSQLQuery;
Q4: TSQLQuery;
sb: TStatusBar;
tr: TSQLTransaction;
procedure chkFilterDateRangeChange(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure btnImportClick(Sender: TObject);
@ -113,6 +126,10 @@ type
RecNR : Integer;
GlobalProfile : Integer;
NowDate : String;
FFilteredOutRecNr: integer;
FFilterByDate: boolean;
FFilterDateRange: array [0..1] of TDateString;
function ValidateFilter: boolean;
procedure WriteWrongADIF(lines : Array of String; error : String);
function pochash(aaa:String):longint;
@ -134,6 +151,10 @@ implementation
uses dData, dUtils, dDXCC, fMain, uMyIni, uVersion;
resourcestring
INVALID_DATE_RANGE_ENTERED = 'Invalid date range is entered';
function TfrmAdifImport.pochash(aaa:String):longint;
var z,x:longint;
begin
@ -282,6 +303,13 @@ var
dxcc_adif : Integer;
len : Integer=0;
RxFreq : Double = 0;
function IsQsoDateInRange: boolean;
begin
Result := (not FFilterByDate) or
((FFilterDateRange[0] <= d.QSO_DATE) and (d.QSO_DATE <= FFilterDateRange[1]));
end;
begin
Result := True;
if (d.st>0) and (d.CALL <> '') and (d.QSO_DATE <> '') then
@ -298,6 +326,11 @@ begin
d.FREQ := dmUtils.FreqFromBand(d.BAND,d.MODE);
d.QSO_DATE := dmUtils.ADIFDateToDate(d.QSO_DATE);
if not IsQsoDateInRange then
begin
Inc(FFilteredOutRecNr);
exit;
end;
d.LOTW_QSLSDATE := dmUtils.ADIFDateToDate(d.LOTW_QSLSDATE);
d.LOTW_QSLRDATE := dmUtils.ADIFDateToDate(d.LOTW_QSLRDATE);
d.QSLSDATE := dmUtils.ADIFDateToDate(d.QSLSDATE);
@ -643,6 +676,9 @@ begin
GlobalProfile := dmData.GetNRFromProfile(cmbProfiles.Text);
RecNR := 0;
WrongRecNr := 0;
FFilteredOutRecNr := 0;
if not ValidateFilter then
exit;
try try
system.assign(sou,lblFileName.Caption);
system.reset(sou);
@ -694,6 +730,9 @@ begin
dt := dt - now;
DecodeTime(dt,hh,m,s,ms);
WriteLn('It takes about ',m,' minutes and ',s,' seconds ',ms,' milliseconds');
lblFilteredOut.Visible := FFilterByDate;
lblFilteredOutCount.Visible := FFilterByDate;
lblFilteredOutCount.Caption := IntToStr(FFilteredOutRecNr);
if chkLotOfQSO.Checked then
begin
sb.Panels[0].Text := 'Recreating indexes ...';
@ -706,6 +745,23 @@ begin
end
end;
function TfrmAdifImport.ValidateFilter: boolean;
begin
Result := true;
FFilterByDate := chkFilterDateRange.Checked;
if FFilterByDate then
begin
FFilterDateRange[0] := IfThen(edtDateFrom.Date <> NullDate, dmUtils.MyDateToStr(edtDateFrom.Date));
FFilterDateRange[1] := IfThen(edtDateTo.Date <> NullDate, dmUtils.MyDateToStr(edtDateTo.Date));
if not ((Length(FFilterDateRange[0]) > 0) and (Length(FFilterDateRange[1]) > 0) and
(FFilterDateRange[0] <= FFilterDateRange[1])) then
begin
MessageDlg(Caption, INVALID_DATE_RANGE_ENTERED, mtError, [mbOK], 0);
Result := false;
end;
end;
end;
procedure TfrmAdifImport.FormCreate(Sender: TObject);
var
tmp : Char;
@ -729,6 +785,11 @@ begin
end
end;
procedure TfrmAdifImport.chkFilterDateRangeChange(Sender: TObject);
begin
pnlFilterDateRange.Enabled := chkFilterDateRange.Checked;
end;
procedure TfrmAdifImport.FormShow(Sender: TObject);
begin
lblComplete.Visible := False;

View File

@ -1757,6 +1757,7 @@ begin
lblFileName.Caption := dlgOpen.FileName;
lblErrors.Caption := '0';
lblCount.Caption := '0';
lblFilteredOutCount.Caption := '0';
ShowModal
finally
Free