From 2cf4625444e6c258ed98b9f2d869c075cc925060 Mon Sep 17 00:00:00 2001 From: Artanemus <69775305+Artanemus@users.noreply.github.com> Date: Sun, 17 Mar 2024 13:47:43 +1000 Subject: [PATCH] Member Chart WIP running --- MEMBERS/dmManageMemberData.dfm | 43 +++++++--- MEMBERS/dmManageMemberData.pas | 17 ++++ MEMBERS/frmManageMember.dfm | 6 ++ MEMBERS/frmManageMember.pas | 145 +++++++++++---------------------- 4 files changed, 104 insertions(+), 107 deletions(-) diff --git a/MEMBERS/dmManageMemberData.dfm b/MEMBERS/dmManageMemberData.dfm index 2656527..95068c8 100644 --- a/MEMBERS/dmManageMemberData.dfm +++ b/MEMBERS/dmManageMemberData.dfm @@ -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];' '' @@ -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)) ' @@ -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' + @@ -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 = < @@ -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 diff --git a/MEMBERS/dmManageMemberData.pas b/MEMBERS/dmManageMemberData.pas index 2de539b..62150c7 100644 --- a/MEMBERS/dmManageMemberData.pas +++ b/MEMBERS/dmManageMemberData.pas @@ -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); @@ -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; diff --git a/MEMBERS/frmManageMember.dfm b/MEMBERS/frmManageMember.dfm index c995ed4..3aab330 100644 --- a/MEMBERS/frmManageMember.dfm +++ b/MEMBERS/frmManageMember.dfm @@ -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 @@ -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 diff --git a/MEMBERS/frmManageMember.pas b/MEMBERS/frmManageMember.pas index 88d8750..18c636e 100644 --- a/MEMBERS/frmManageMember.pas +++ b/MEMBERS/frmManageMember.pas @@ -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); @@ -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: @@ -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 @@ -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); @@ -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;