Skip to content

Commit

Permalink
Member Chart WIP running
Browse files Browse the repository at this point in the history
  • Loading branch information
Artanemus committed Mar 17, 2024
1 parent 1a44cf3 commit 2cf4625
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 107 deletions.
43 changes: 32 additions & 11 deletions MEMBERS/dmManageMemberData.dfm
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,10 @@ object ManageMemberData: TManageMemberData
end
object qryChart: TFDQuery
ActiveStoredUsage = [auDesignTime]
Active = True
Connection = SCM.scmConnection
FormatOptions.AssignedValues = [fvFmtDisplayDateTime]
FormatOptions.FmtDisplayDateTime = 'dd/mmm/yyyy'
SQL.Strings = (
'USE [SwimClubMeet];'
''
Expand All @@ -900,9 +903,13 @@ object ManageMemberData: TManageMemberData
'SET @DistanceID = :DISTANCEID;'
'SET @MemberID = :MEMBERID;'
'SET @DoCurrSeason = :DOCURRSEASON;'
''
'IF OBJECT_ID('#39'tempdb..#charttemp'#39') IS NOT NULL'
' DROP TABLE #charttemp;'
''
''

'SELECT TOP 25 [dbo].[SwimTimeToString](Entrant.RaceTime) AS Race' +
'SELECT TOP 26 [dbo].[SwimTimeToString](Entrant.RaceTime) AS Race' +
'TimeAsString'
#9',(DATEPART(MILLISECOND, Entrant.RaceTime) / 1000.0) '
' + (DATEPART(SECOND, Entrant.RaceTime)) '
Expand All @@ -913,9 +920,8 @@ object ManageMemberData: TManageMemberData
#9',Session.SessionStart'
#9',Distance.Caption AS cDistance'
#9',Stroke.Caption AS cStroke'

',ROW_NUMBER()OVER (PARTITION BY 1 ORDER BY SessionStart ) AS Ch' +
'artX'
''
'INTO #charttemp'
'FROM Entrant'

'INNER JOIN HeatIndividual ON Entrant.HeatID = HeatIndividual.Hea' +
Expand All @@ -929,16 +935,31 @@ object ManageMemberData: TManageMemberData
#9'AND (Event.DistanceID = @DistanceID) '
' AND (Entrant.MemberID = @MemberID) '
' AND Entrant.RaceTime IS NOT NULL'
' AND Entrant.RaceTime > '#39'00:00:00'#39
#9#9'-- playing it extra careful'
#9#9'AND CONVERT(time(0), Entrant.RaceTime) > '#39'00:00:00'#39
' AND ('

' (@DoCurrSeason = 1 AND Session.SessionStart >= SwimCl' +
'ub.StartOfSwimSeason)'
' OR'
' (@DoCurrSeason = 0 AND Session.SessionStart > 0)'
' )'
' (@DoCurrSeason = 0)'
#9#9' )'
' '
'ORDER BY SessionStart')
'ORDER BY SessionStart DESC;'
''
'SELECT '
#9'RaceTimeAsString'
#9',Seconds'
#9',SessionStart'
#9',cDistance'
#9',cStroke'

',ROW_NUMBER()OVER (PARTITION BY 1 ORDER BY SessionStart ) AS Ch' +
'artX'
'FROM'
'#charttemp'
'ORDER BY SessionStart ASC;'
'')
Left = 496
Top = 592
ParamData = <
Expand All @@ -952,19 +973,19 @@ object ManageMemberData: TManageMemberData
Name = 'DISTANCEID'
DataType = ftInteger
ParamType = ptInput
Value = 1
Value = 2
end
item
Name = 'MEMBERID'
DataType = ftInteger
ParamType = ptInput
Value = 100
Value = 9
end
item
Name = 'DOCURRSEASON'
DataType = ftBoolean
ParamType = ptInput
Value = True
Value = False
end>
end
object dsChart: TDataSource
Expand Down
17 changes: 17 additions & 0 deletions MEMBERS/dmManageMemberData.pas
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ TManageMemberData = class(TDataModule)
procedure ActivateTable();
procedure FixNullBooleans();
function LocateMember(MemberID: Integer): Boolean;
function LocateChart(ChartX: Integer): Boolean;
procedure UpdateDOB(DOB: TDateTime);
procedure UpdateMember(SwimClubID: Integer;
hideArchived, hideInactive, hideNonSwimmer: Boolean);
Expand Down Expand Up @@ -256,6 +257,22 @@ procedure TManageMemberData.FixNullBooleans;
end;
end;

function TManageMemberData.LocateChart(ChartX: Integer): Boolean;
var
SearchOptions: TLocateOptions;
begin
result := false;
SearchOptions := [loPartialKey];
try
begin
result := qryChart.Locate('ChartX', ChartX, SearchOptions);
end
except
on E: Exception do
// lblErrMsg.Caption := 'SCM DB access error.';
end;
end;

function TManageMemberData.LocateMember(MemberID: Integer): Boolean;
var
SearchOptions: TLocateOptions;
Expand Down
6 changes: 6 additions & 0 deletions MEMBERS/frmManageMember.dfm
Original file line number Diff line number Diff line change
Expand Up @@ -1112,7 +1112,11 @@ object ManageMember: TManageMember
'TDBChart')
BottomAxis.ExactDateTime = False
BottomAxis.Increment = 1.000000000000000000
Legend.Title.Alignment = taCenter
Legend.Title.Text.Strings = (
'Race Time & Date')
View3D = False
OnGetLegendText = DBChart1GetLegendText
Align = alClient
TabOrder = 1
ExplicitWidth = 1351
Expand All @@ -1124,6 +1128,8 @@ object ManageMember: TManageMember
DataSource = ManageMemberData.qryChart
XLabelsSource = 'ChartX'
Brush.BackColor = clDefault
Pointer.Brush.Gradient.EndColor = 10708548
Pointer.Gradient.EndColor = 10708548
Pointer.InflateMargins = True
Pointer.Style = psRectangle
Pointer.Visible = True
Expand Down
145 changes: 49 additions & 96 deletions MEMBERS/frmManageMember.pas
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ TManageMember = class(TForm)
procedure cmboStrokeChange(Sender: TObject);
procedure DBChart1GetAxisLabel(Sender: TChartAxis; Series: TChartSeries;
ValueIndex: Integer; var LabelText: string);
procedure DBChart1GetLegendText(Sender: TCustomAxisPanel; LegendStyle:
TLegendStyle; Index: Integer; var LegendText: string);
procedure DBGridCellClick(Column: TColumn);
procedure DBGridColEnter(Sender: TObject);
procedure DBGridColExit(Sender: TObject);
Expand Down Expand Up @@ -486,68 +488,18 @@ procedure TManageMember.ChartReport;
end;

procedure TManageMember.chkbDoCurrSeasonClick(Sender: TObject);
var
d,s: integer;
docurrseason: boolean;
begin
// Requery Chart
if not AssertConnection then exit;
if cmboDistance.ItemIndex <> -1 then
d := cmboDistance.ItemIndex + 1 else d := 1;
if cmboStroke.ItemIndex <> -1 then
s := cmboStroke.ItemIndex + 1 else s := 1;

if chkbDoCurrSeason.Checked then
docurrseason := true
else
docurrseason := false;

ManageMemberData.UpdateChart(0,d,s,docurrseason);

DBChart1.RefreshData;
UpdateChart;
end;

procedure TManageMember.cmboDistanceChange(Sender: TObject);
var
d,s: integer;
docurrseason: boolean;
begin
// Requery Chart
if not AssertConnection then exit;
if cmboDistance.ItemIndex <> -1 then
d := cmboDistance.ItemIndex + 1 else d := 1;
if cmboStroke.ItemIndex <> -1 then
s := cmboStroke.ItemIndex + 1 else s := 1;

if chkbDoCurrSeason.Checked then
docurrseason := true
else
docurrseason := false;

ManageMemberData.UpdateChart(0,d,s,docurrseason);

DBChart1.RefreshData;
UpdateChart;
end;

procedure TManageMember.cmboStrokeChange(Sender: TObject);
var
d,s: integer;
docurrseason: boolean;
begin
// Requery Chart
if not AssertConnection then exit;
if cmboDistance.ItemIndex <> -1 then
d := cmboDistance.ItemIndex + 1 else d := 1;
if cmboStroke.ItemIndex <> -1 then
s := cmboStroke.ItemIndex + 1 else s := 1;

if chkbDoCurrSeason.Checked then
docurrseason := true
else
docurrseason := false;

ManageMemberData.UpdateChart(0,d,s,docurrseason);
DBChart1.RefreshData;
UpdateChart;
end;

procedure TManageMember.DBChart1GetAxisLabel(Sender: TChartAxis; Series:
Expand Down Expand Up @@ -585,6 +537,23 @@ procedure TManageMember.DBChart1GetAxisLabel(Sender: TChartAxis; Series:
*)
end;

procedure TManageMember.DBChart1GetLegendText(Sender: TCustomAxisPanel;
LegendStyle: TLegendStyle; Index: Integer; var LegendText: string);
var
s: string;
LFormatSettings: TFormatSettings;
begin
if not AssertConnection then exit;
LFormatSettings := TFormatSettings.Create;
ManageMemberData.LocateChart((Index+1));
s := FormatDateTime(LFormatSettings.ShortDateFormat,
ManageMemberData.dsChart.DataSet.FieldByName('SessionStart').AsDateTime,
LFormatSettings) ;
LegendText :=
ManageMemberData.dsChart.DataSet.FieldByName('RaceTimeAsString').AsString
+ ' ' + s;
end;

procedure TManageMember.DBGridCellClick(Column: TColumn);
begin
if assigned(Column.Field) and (Column.Field.DataType = ftBoolean) then
Expand Down Expand Up @@ -998,25 +967,10 @@ procedure TManageMember.ManageMemberAfterPost(var Msg: TMessage);
end;

procedure TManageMember.ManageMemberAfterScroll(var Msg: TMessage);
var
d, s: integer;
docurrseason: boolean;

begin
UpdateMembersAge;
// Requery Chart
if not AssertConnection then exit;
if cmboDistance.ItemIndex <> -1 then
d := cmboDistance.ItemIndex + 1 else d := 1;
if cmboStroke.ItemIndex <> -1 then
s := cmboStroke.ItemIndex + 1 else s := 1;
if chkbDoCurrSeason.Checked then
docurrseason := true
else
docurrseason := false;

ManageMemberData.UpdateChart(0,d,s,docurrseason);
DBChart1.RefreshData;

UpdateChart;
end;

procedure TManageMember.FilterDlgUpdated(var Msg: TMessage);
Expand Down Expand Up @@ -1155,33 +1109,32 @@ procedure TManageMember.SCMwebsite1Click(Sender: TObject);
end;

procedure TManageMember.UpdateChart;
var
d, s: Integer;
docurrseason: Boolean;
str: string;
begin
(*
int DistanceID, StrokeID;
String s;
if (qryChart->Active)
qryChart->Close();
DistanceID = fArrayDistance[cmboDistance->ItemIndex];
qryChart->ParamByName("DISTANCEID")->AsInteger = DistanceID;
StrokeID = fArrayStroke[cmboStroke->ItemIndex];
qryChart->ParamByName("STROKEID")->AsInteger = StrokeID;
qryChart->ParamByName("MEMBERID")->AsInteger =
qryMember->FieldByName("MemberID")->AsInteger;
qryChart->Prepare();
qryChart->Open();
DBChart1->Title->Text->Clear();
DBChart1->Title->Text->Add(qryMember->FieldByName("FName")->AsString);
DBChart1->SubTitle->Text->Clear();
if (qryChart->IsEmpty()) {
DBChart1->SubTitle->Text->Add("No data for this distance and stroke");
}
else {
s = qryChart->FieldByName("cDistance")->AsString + " - " +
qryChart->FieldByName("cStroke")->AsString;
DBChart1->SubTitle->Text->Add(s);
}
DBChart1->RefreshData();
*)
// Gather UI state
if not AssertConnection then exit;
if cmboDistance.ItemIndex <> -1 then d := cmboDistance.ItemIndex + 1
else d := 1;
if cmboStroke.ItemIndex <> -1 then s := cmboStroke.ItemIndex + 1
else s := 1;
if chkbDoCurrSeason.Checked then docurrseason := true
else docurrseason := false;
// Requery FireDAC Chart
ManageMemberData.UpdateChart(0, d, s, docurrseason);
// Chart title
DBChart1.Title.Text.Clear;
str := cmboDistance.Text + ' ' + cmboStroke.Text;
if docurrseason then
str := str + ' start of swiming season '
+ ManageMemberData.dsSwimClub.DataSet.FieldByName('StartOfSwimSeason').AsString
else
str := str + ' (Maximum: 26 events)';
DBChart1.Title.Text.Add(str);
// Reload chart data
DBChart1.RefreshData;
end;

procedure TManageMember.UpdateFilterCount;
Expand Down

0 comments on commit 2cf4625

Please sign in to comment.