Skip to content

Commit

Permalink
display chart report for export FastReport running
Browse files Browse the repository at this point in the history
  • Loading branch information
Artanemus committed Mar 18, 2024
1 parent 2cf4625 commit 89d2b91
Show file tree
Hide file tree
Showing 7 changed files with 173 additions and 98 deletions.
18 changes: 14 additions & 4 deletions MEMBERS/dmManageMemberData.dfm
Original file line number Diff line number Diff line change
Expand Up @@ -898,23 +898,27 @@ object ManageMemberData: TManageMemberData
'DECLARE @DistanceID AS INT;'
'DECLARE @MemberID AS INT;'
'DECLARE @DoCurrSeason AS BIT;'
'DECLARE @MaxRecords AS INT;'
''
'SET @StrokeID = :STROKEID;'
'SET @DistanceID = :DISTANCEID;'
'SET @MemberID = :MEMBERID;'
'SET @DoCurrSeason = :DOCURRSEASON;'
'SET @MaxRecords = :MAXRECORDS;'
''
'IF OBJECT_ID('#39'tempdb..#charttemp'#39') IS NOT NULL'
' DROP TABLE #charttemp;'
' '
'IF @MaxRecords IS NULL SET @MaxRecords = 26;'
''
''

'SELECT TOP 26 [dbo].[SwimTimeToString](Entrant.RaceTime) AS Race' +
'TimeAsString'
'SELECT TOP (@MaxRecords) [dbo].[SwimTimeToString](Entrant.RaceTi' +
'me) AS RaceTimeAsString'
#9',(DATEPART(MILLISECOND, Entrant.RaceTime) / 1000.0) '
' + (DATEPART(SECOND, Entrant.RaceTime)) '

' + (DATEPART(MINUTE, Entrant.RaceTime) / 60.0) AS' +
' + (DATEPART(MINUTE, Entrant.RaceTime) * 60.0) AS' +
' Seconds'
''
#9',Session.SessionStart'
Expand Down Expand Up @@ -967,7 +971,7 @@ object ManageMemberData: TManageMemberData
Name = 'STROKEID'
DataType = ftInteger
ParamType = ptInput
Value = 1
Value = 2
end
item
Name = 'DISTANCEID'
Expand All @@ -986,6 +990,12 @@ object ManageMemberData: TManageMemberData
DataType = ftBoolean
ParamType = ptInput
Value = False
end
item
Name = 'MAXRECORDS'
DataType = ftInteger
ParamType = ptInput
Value = 26
end>
end
object dsChart: TDataSource
Expand Down
23 changes: 20 additions & 3 deletions MEMBERS/dmManageMemberData.pas
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ interface
Data.DB, FireDAC.Comp.Client, FireDAC.Stan.Param, FireDAC.DatS,
FireDAC.DApt.Intf, FireDAC.DApt, FireDAC.Comp.DataSet, FireDAC.Phys.MSSQL,
FireDAC.Phys.MSSQLDef, dmSCM, Windows, Winapi.Messages, SCMDefines
// ,VclTee.TeEngine,
// VclTee.TeeSpline, VclTee.Series, VclTee.TeeProcs, VclTee.Chart,
// VclTee.DBChart
;

type
Expand Down Expand Up @@ -123,6 +120,7 @@ TManageMemberData = class(TDataModule)
fManageMemberDataActive: Boolean;
fRecordCount: Integer;
fHandle: HWND;
prefChartMaxRecords: Integer;

procedure UpdateMembersPersonalBest;

Expand All @@ -147,6 +145,7 @@ TManageMemberData = class(TDataModule)
procedure UpdateElectedOn(aDate: TDate);
procedure UpdateRetiredOn(aDate: TDate);
procedure UpdateChart(aMemberID, aDistanceID, aStrokeID: integer; DoCurrSeason: boolean = true);
procedure ReadPreferences(aIniFileName: string);

property Connection: TFDConnection read FConnection write FConnection;
property ManageMemberDataActive: Boolean read fManageMemberDataActive
Expand All @@ -159,6 +158,7 @@ TManageMemberData = class(TDataModule)
const
SCMMEMBERPREF = 'SCM_MemberPref.ini';
USEDSHAREDINIFILE = True; // NOTE: Always true. 26/09/2022
CHARTMAXRECORDS = 26; // max number of events show in TDBChart

var
ManageMemberData: TManageMemberData;
Expand All @@ -176,6 +176,7 @@ constructor TManageMemberData.Create(AOwner: TComponent);
begin
inherited;
fHandle := AllocateHWnd(WndProc);
prefChartMaxRecords := CHARTMAXRECORDS;
end;

constructor TManageMemberData.CreateWithConnection(AOwner: TComponent;
Expand Down Expand Up @@ -613,6 +614,21 @@ procedure TManageMemberData.qryMemberRoleLnkNewRecord(DataSet: TDataSet);
// end;
end;

procedure TManageMemberData.ReadPreferences(aIniFileName: string);
var
i: Integer;
iFile: TIniFile;
begin
// ---------------------------------------------------------
// R E A D P R E F E R E N C E S ...
// ---------------------------------------------------------
if not FileExists(aIniFileName) then exit;
iFile := TIniFile.Create(aIniFileName);
// 2024.03.18
prefChartMaxRecords := iFile.ReadInteger('ManageMemberData', 'ChartMaxRecords', CHARTMAXRECORDS);
iFile.Free;
end;

procedure TManageMemberData.UpdateChart(aMemberID, aDistanceID, aStrokeID: integer; DoCurrSeason: boolean = true);
begin
if not Assigned(FConnection) then
Expand All @@ -629,6 +645,7 @@ procedure TManageMemberData.UpdateChart(aMemberID, aDistanceID, aStrokeID: integ
qryChart.ParamByName('DISTANCEID').AsInteger := aDistanceID;
qryChart.ParamByName('STROKEID').AsInteger := aStrokeID;
qryChart.ParamByName('DOCURRSEASON').AsBoolean:= DoCurrSeason;
qryChart.ParamByName('MAXRECORDS').AsInteger:= prefChartMaxRecords;
qryChart.Prepare;
qryChart.Open;
if qryChart.Active then
Expand Down
13 changes: 13 additions & 0 deletions MEMBERS/frmManageMember.dfm
Original file line number Diff line number Diff line change
Expand Up @@ -1057,6 +1057,9 @@ object ManageMember: TManageMember
BevelOuter = bvNone
TabOrder = 0
ExplicitWidth = 1351
DesignSize = (
1355
41)
object Label27: TLabel
Left = 24
Top = 11
Expand Down Expand Up @@ -1102,6 +1105,16 @@ object ManageMember: TManageMember
TabOrder = 2
OnClick = chkbDoCurrSeasonClick
end
object btmPrintChart: TButton
Left = 1223
Top = 10
Width = 129
Height = 25
Anchors = [akTop, akRight]
Caption = 'Print Chart'
TabOrder = 3
OnClick = btmPrintChartClick
end
end
object DBChart1: TDBChart
Left = 0
Expand Down
92 changes: 61 additions & 31 deletions MEMBERS/frmManageMember.pas
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,10 @@ TManageMember = class(TForm)
DBChart1: TDBChart;
Series2: TLineSeries;
chkbDoCurrSeason: TCheckBox;
btmPrintChart: TButton;
procedure About2Click(Sender: TObject);
procedure actnFilterExecute(Sender: TObject);
procedure btmPrintChartClick(Sender: TObject);
procedure btnClearClick(Sender: TObject);
procedure btnClearDOBClick(Sender: TObject);
procedure btnClubMembersDetailedClick(Sender: TObject);
Expand Down Expand Up @@ -180,13 +182,14 @@ TManageMember = class(TForm)
function AssertConnection: Boolean;
function FindMember(MemberID: Integer): Boolean;
function GetMembersAge(aMemberID: Integer; aDate: TDate): Integer;
procedure ReadPreferences();
procedure ReadPreferences(aIniFileName: string);
procedure WritePreferences();
procedure UpdateFilterCount();
procedure UpdateMembersAge();
procedure UpdateChart();
procedure ChartReport();


protected
// windows messages ....
procedure ManageMemberAfterScroll(var Msg: TMessage);
Expand Down Expand Up @@ -218,7 +221,7 @@ implementation
dlgDOBPicker, dlgFindMember, dlgGotoMember, dlgGotoMembership,
System.IOUtils, Winapi.ShellAPI, dlgDeleteMember, Vcl.Themes, rptMemberDetail,
rptMemberHistory, rptMembersList, rptMembersDetail, rptMembersSummary,
System.DateUtils;
System.DateUtils, rptMemberChart;

procedure TManageMember.About2Click(Sender: TObject);
var
Expand Down Expand Up @@ -262,6 +265,11 @@ function TManageMember.AssertConnection: Boolean;
end;
end;

procedure TManageMember.btmPrintChartClick(Sender: TObject);
begin
ChartReport;
end;

procedure TManageMember.btnClearClick(Sender: TObject);
begin
if not assigned(ManageMemberData) then exit;
Expand Down Expand Up @@ -469,22 +477,20 @@ procedure TManageMember.btnMemberHistoryClick(Sender: TObject);
end;

procedure TManageMember.ChartReport;
var
aMemberID: integer;
s, s2: string;
rpt: TMemberChart;
begin
(*
(void)Sender;
int aMemberID;
String s, s2;
TMemberChart *rpt;
// Distance
s = cmboDistance->Items->Strings[cmboDistance->ItemIndex];
s := cmboDistance.Text;
// Stroke
s2 = cmboStroke->Items->Strings[cmboStroke->ItemIndex];
rpt = new TMemberChart(this);
aMemberID = dsMember->DataSet->FieldByName("MemberID")->AsInteger;
s2 := cmboStroke.Text;
rpt := TMemberChart.Create(self);
aMemberID := ManageMemberData.dsMember.DataSet.FieldByName('MemberID').AsInteger;
// params ... SwimClubID, MemberID
rpt->RunReport(aMemberID, DBChart1, s, s2);
delete rpt;
*)
rpt.RunReport(aMemberID, DBChart1, s, s2);
rpt.free;
end;

procedure TManageMember.chkbDoCurrSeasonClick(Sender: TObject);
Expand Down Expand Up @@ -917,11 +923,14 @@ procedure TManageMember.FormDestroy(Sender: TObject);
end;

procedure TManageMember.FormShow(Sender: TObject);
var
iniFileName: string;
begin
// ----------------------------------------------------
// R E A D P R E F E R E N C E S .
// ----------------------------------------------------
ReadPreferences;
iniFileName := SCMUtility.GetSCMPreferenceFileName;
ReadPreferences(iniFileName);
if not AssertConnection then exit;

// run filter
Expand Down Expand Up @@ -961,6 +970,29 @@ function TManageMember.GetMembersAge(aMemberID: Integer; aDate: TDate): Integer;
end;


procedure TManageMember.ReadPreferences(aIniFileName: string);
var
i: Integer;
iFile: TIniFile;
begin
// ---------------------------------------------------------
// A S S I G N MANAGEMEMBER P R E F E R E N C E S ...
// ---------------------------------------------------------
if not FileExists(aIniFileName) then exit;
iFile := TIniFile.Create(aIniFileName);
fHideArchived := iFile.ReadBool(INIFILE_SECTION, 'HideArchived', true);
fHideInActive := iFile.ReadBool(INIFILE_SECTION, 'HideInActive', false);
fHideNonSwimmer := iFile.ReadBool(INIFILE_SECTION, 'HideNonSwimmer', false);
// 2024.03.18
i := iFile.ReadInteger('ManageMember', 'cmboDistanceItemIndex', 0);
if i < cmboDistance.Items.Count then cmboDistance.ItemIndex := i;
i := iFile.ReadInteger('ManageMember', 'cmboStrokeItemIndex', 0);
if i < cmboStroke.Items.Count then cmboStroke.ItemIndex := i;
chkbDoCurrSeason.Checked := iFile.ReadBool('ManageMember',
'chkbDoCurrSeason', false);
iFile.Free;
end;

procedure TManageMember.ManageMemberAfterPost(var Msg: TMessage);
begin
UpdateMembersAge;
Expand Down Expand Up @@ -1082,19 +1114,6 @@ procedure TManageMember.Prepare(AConnection: TFDConnection;

end;

procedure TManageMember.ReadPreferences;
var
iFile: TIniFile;
iniFileName: string;
begin
iniFileName := SCMUtility.GetSCMPreferenceFileName;
if not FileExists(iniFileName) then exit;
iFile := TIniFile.Create(iniFileName);
fHideArchived := iFile.ReadBool(INIFILE_SECTION, 'HideArchived', true);
fHideInActive := iFile.ReadBool(INIFILE_SECTION, 'HideInActive', false);
fHideNonSwimmer := iFile.ReadBool(INIFILE_SECTION, 'HideNonSwimmer', false);
iFile.Free;
end;

procedure TManageMember.SCMwebsite1Click(Sender: TObject);
var
Expand Down Expand Up @@ -1126,12 +1145,13 @@ procedure TManageMember.UpdateChart;
ManageMemberData.UpdateChart(0, d, s, docurrseason);
// Chart title
DBChart1.Title.Text.Clear;
str := cmboDistance.Text + ' ' + cmboStroke.Text;
str := ManageMemberData.dsMember.DataSet.FieldByName('FName').AsString;
str := str + ' ' +cmboDistance.Text + ' ' + cmboStroke.Text;
if docurrseason then
str := str + ' start of swiming season '
str := str + ' - Start of season '
+ ManageMemberData.dsSwimClub.DataSet.FieldByName('StartOfSwimSeason').AsString
else
str := str + ' (Maximum: 26 events)';
str := str + ' - (Max 26 events)';
DBChart1.Title.Text.Add(str);
// Reload chart data
DBChart1.RefreshData;
Expand Down Expand Up @@ -1176,6 +1196,16 @@ procedure TManageMember.WritePreferences;
iFile.WriteBool(INIFILE_SECTION, 'HideArchived', fHideArchived);
iFile.WriteBool(INIFILE_SECTION, 'HideInActive', fHideInActive);
iFile.WriteBool(INIFILE_SECTION, 'HideNonSwimmer', fHideNonSwimmer);

// 2024 03 18
if (cmboDistance.ItemIndex > -1) then
iFile.WriteInteger('ManageMember', 'cmboDistanceItemIndex', cmboDistance.ItemIndex);

if (cmboStroke.ItemIndex > -1) then
iFile.WriteInteger('ManageMember', 'cmboStrokeItemIndex', cmboStroke.ItemIndex);

iFile.WriteBool('ManageMember', 'chkbDoCurrSeason', chkbDoCurrSeason.Checked);

iFile.Free;
end;

Expand Down
Loading

0 comments on commit 89d2b91

Please sign in to comment.