diff --git a/MEMBERS/dmManageMemberData.dfm b/MEMBERS/dmManageMemberData.dfm index 95068c8..a799c29 100644 --- a/MEMBERS/dmManageMemberData.dfm +++ b/MEMBERS/dmManageMemberData.dfm @@ -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' @@ -967,7 +971,7 @@ object ManageMemberData: TManageMemberData Name = 'STROKEID' DataType = ftInteger ParamType = ptInput - Value = 1 + Value = 2 end item Name = 'DISTANCEID' @@ -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 diff --git a/MEMBERS/dmManageMemberData.pas b/MEMBERS/dmManageMemberData.pas index 62150c7..4b3b374 100644 --- a/MEMBERS/dmManageMemberData.pas +++ b/MEMBERS/dmManageMemberData.pas @@ -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 @@ -123,6 +120,7 @@ TManageMemberData = class(TDataModule) fManageMemberDataActive: Boolean; fRecordCount: Integer; fHandle: HWND; + prefChartMaxRecords: Integer; procedure UpdateMembersPersonalBest; @@ -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 @@ -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; @@ -176,6 +176,7 @@ constructor TManageMemberData.Create(AOwner: TComponent); begin inherited; fHandle := AllocateHWnd(WndProc); + prefChartMaxRecords := CHARTMAXRECORDS; end; constructor TManageMemberData.CreateWithConnection(AOwner: TComponent; @@ -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 @@ -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 diff --git a/MEMBERS/frmManageMember.dfm b/MEMBERS/frmManageMember.dfm index 3aab330..05c0e3e 100644 --- a/MEMBERS/frmManageMember.dfm +++ b/MEMBERS/frmManageMember.dfm @@ -1057,6 +1057,9 @@ object ManageMember: TManageMember BevelOuter = bvNone TabOrder = 0 ExplicitWidth = 1351 + DesignSize = ( + 1355 + 41) object Label27: TLabel Left = 24 Top = 11 @@ -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 diff --git a/MEMBERS/frmManageMember.pas b/MEMBERS/frmManageMember.pas index 18c636e..593176b 100644 --- a/MEMBERS/frmManageMember.pas +++ b/MEMBERS/frmManageMember.pas @@ -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); @@ -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); @@ -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 @@ -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; @@ -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); @@ -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 @@ -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; @@ -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 @@ -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; @@ -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; diff --git a/REPORTS/rptMemberChart.dfm b/REPORTS/rptMemberChart.dfm index b007020..aebea71 100644 --- a/REPORTS/rptMemberChart.dfm +++ b/REPORTS/rptMemberChart.dfm @@ -12,7 +12,7 @@ object MemberChart: TMemberChart PrintOptions.Printer = 'Default' PrintOptions.PrintOnSheet = 0 ReportOptions.CreateDate = 43428.811813125000000000 - ReportOptions.LastChange = 43434.512179675900000000 + ReportOptions.LastChange = 45369.586622858800000000 ScriptLanguage = 'PascalScript' ScriptText.Strings = ( 'begin' @@ -33,8 +33,9 @@ object MemberChart: TMemberChart Width = 1000.000000000000000000 end object Page1: TfrxReportPage - PaperWidth = 210.000000000000000000 - PaperHeight = 297.000000000000000000 + Orientation = poLandscape + PaperWidth = 297.000000000000000000 + PaperHeight = 210.000000000000000000 PaperSize = 9 LeftMargin = 10.000000000000000000 RightMargin = 10.000000000000000000 @@ -47,7 +48,7 @@ object MemberChart: TMemberChart Frame.Typ = [] Height = 71.811070000000000000 Top = 18.897650000000000000 - Width = 718.110700000000000000 + Width = 1046.929810000000000000 object FDQuery1cSwimClub: TfrxMemoView AllowVectorExport = True Width = 1043.150280000000000000 @@ -113,7 +114,7 @@ object MemberChart: TMemberChart Height = 33.881880000000000000 ParentFont = False Top = 151.181200000000000000 - Width = 718.110700000000000000 + Width = 1046.929810000000000000 Condition = 'frxDS."MemberID"' object Line1: TfrxLineView AllowVectorExport = True @@ -169,7 +170,7 @@ object MemberChart: TMemberChart Height = 396.850650000000000000 ParentFont = False Top = 207.874150000000000000 - Width = 718.110700000000000000 + Width = 1046.929810000000000000 DataSet = frxDSReport DataSetName = 'frxDS' KeepTogether = True @@ -177,7 +178,7 @@ object MemberChart: TMemberChart object Picture1: TfrxPictureView Align = baClient AllowVectorExport = True - Width = 718.110700000000000000 + Width = 1046.929810000000000000 Height = 396.850650000000000000 Frame.Typ = [] HightQuality = False @@ -190,7 +191,7 @@ object MemberChart: TMemberChart Frame.Typ = [] Height = 22.677180000000000000 Top = 665.197280000000000000 - Width = 718.110700000000000000 + Width = 1046.929810000000000000 object TotalPages: TfrxMemoView AllowVectorExport = True Left = 430.866420000000000000 @@ -227,12 +228,12 @@ object MemberChart: TMemberChart end object qryReport: TFDQuery ActiveStoredUsage = [auDesignTime] - IndexFieldNames = 'SessionID' + Active = True + IndexFieldNames = 'MemberID' Connection = SCM.scmConnection FormatOptions.AssignedValues = [fvFmtDisplayTime] FormatOptions.FmtDisplayTime = 'hh:nn' SQL.Strings = ( - 'USE SwimClubMeet' 'USE SwimClubMeet' '' 'DECLARE @MemberID AS INT' @@ -243,19 +244,21 @@ object MemberChart: TMemberChart #9',SwimClub.SwimClubID' #9',SwimClub.NickName AS ClubNickName' #9',SwimClub.Caption AS ClubName' - ',CONCAT([FirstName] , '#39' '#39' , UPPER([LastName])) AS FName' + ' ,CONCAT([FirstName] , '#39' '#39' , UPPER([LastName])) AS FName' 'FROM Member' 'INNER JOIN SwimClub ON Member.SwimClubID = SwimClub.SwimClubID' 'WHERE MemberID = @MemberID' '' '' '') - Left = 160 - Top = 272 + Left = 48 + Top = 280 ParamData = < item Name = 'MEMEBERID' + DataType = ftInteger ParamType = ptInput + Value = 9 end> end object frxXLSExport1: TfrxXLSExport @@ -320,7 +323,7 @@ object MemberChart: TMemberChart CloseDataSource = False DataSet = qryReport BCDToCurrency = False - Left = 64 - Top = 272 + Left = 160 + Top = 280 end end diff --git a/REPORTS/rptMemberChart.pas b/REPORTS/rptMemberChart.pas index 976c79a..de42f19 100644 --- a/REPORTS/rptMemberChart.pas +++ b/REPORTS/rptMemberChart.pas @@ -7,7 +7,8 @@ interface FireDAC.Stan.Param, FireDAC.Stan.Error, FireDAC.DatS, FireDAC.Phys.Intf, FireDAC.DApt.Intf, FireDAC.Stan.Async, FireDAC.DApt, frxClass, frxDBSet, frxExportPDF, frxExportHTML, frxExportBaseDialog, frxExportXLS, Data.DB, - FireDAC.Comp.DataSet, FireDAC.Comp.Client, VclTee.DBChart; + FireDAC.Comp.DataSet, FireDAC.Comp.Client, VclTee.DBChart, dmSCM + , System.Types; type TMemberChart = class(TDataModule) @@ -21,6 +22,9 @@ TMemberChart = class(TDataModule) procedure frxReport1BeforePrint(Sender: TfrxReportComponent); private { Private declarations } + fDBChart: TDBChart; + fDistanceStr: string; + fStrokeStr: string; public { Public declarations } procedure RunReport(aMemberID: integer; aDBChart: TDBChart; @@ -33,67 +37,64 @@ TMemberChart = class(TDataModule) implementation {%CLASSGROUP 'Vcl.Controls.TControl'} - {$R *.dfm} procedure TMemberChart.DataModuleCreate(Sender: TObject); begin -(* - (void)Sender; - // As SCM is a TEMPORY connection - ASSERT assignment for FireDAC. - if (SCM != nullptr) { - qryReport->Connection = SCM->scmConnection; - } - fDBChart = nullptr; -*) + // Assert connection + if Assigned (SCM) then + qryReport.Connection := SCM.scmConnection; + fDBChart := nil; end; procedure TMemberChart.frxReport1BeforePrint(Sender: TfrxReportComponent); +var + myRect: TRect; begin -(* - if (fDBChart != nullptr) { - if (Sender->Name == "Picture1") { - reinterpret_cast(Sender)->Picture->Assign( - - fDBChart->TeeCreateMetafile(False, - Rect(0, 0, int(Sender->Width), int(Sender->Height)))); - } - if (Sender->Name == "memDistance") { - reinterpret_cast(Sender)->Memo->Clear(); - reinterpret_cast(Sender)->Memo->Add - ("Distance: " + fDistanceStr); - } - if (Sender->Name == "memStroke") { - reinterpret_cast(Sender)->Memo->Clear(); - reinterpret_cast(Sender)->Memo->Add - ("Stroke: " + fStrokeStr); - } - } -*) + if Assigned(fDBChart) then + begin + if (Sender.Name = 'Picture1') then + begin + myRect := Rect(0, 0, Round(TfrxPictureView(Sender).Width), + Round(TfrxPictureView(Sender).Height)); + TfrxPictureView(Sender).Picture.Assign + (fDBChart.TeeCreateMetafile(False, myRect)); + TfrxPictureView(Sender).Picture.Assign + (fDBChart.TeeCreateMetafile(False, myRect)); + end; + if (Sender.Name = 'memDistance') then + begin + TfrxMemoView(Sender).Memo.Clear(); + TfrxMemoView(Sender).Memo.Add('Distance: ' + fDistanceStr); + end; + if (Sender.Name = 'memStroke') then + begin + TfrxMemoView(Sender).Memo.Clear(); + TfrxMemoView(Sender).Memo.Add('Stroke: ' + fStrokeStr); + end; + end; end; procedure TMemberChart.RunReport(aMemberID: integer; aDBChart: TDBChart; aDistanceStr, aStrokeStr: string); begin -(* - fDBChart = aDBChart; - fDistanceStr = aDistanceStr; - fStrokeStr = aStrokeStr; - if (qryReport->Active) - qryReport->Close(); - qryReport->ParamByName("MEMEBERID")->AsInteger = aMemberID; - // changes to params will set Prepared to false - qryReport->Prepare(); - qryReport->Open(); - if (qryReport->Active) { + fDBChart := aDBChart; + fDistanceStr := aDistanceStr; + fStrokeStr := aStrokeStr; + + if (qryReport.Active) then qryReport.Close(); + qryReport.ParamByName('MEMEBERID').AsInteger := aMemberID; + qryReport.Prepare(); + qryReport.Open(); + if (qryReport.Active) then // this is no longer required ... // qryReport->Refresh(); - frxReport1->ShowReport(); - } - qryReport->Close(); -*) + frxReport1.ShowReport(); + + qryReport.Close(); + end; end. diff --git a/SwimClubMeet.dpr b/SwimClubMeet.dpr index 1c769fe..4c733c4 100644 --- a/SwimClubMeet.dpr +++ b/SwimClubMeet.dpr @@ -89,5 +89,6 @@ begin Application.MainFormOnTaskbar := True; TStyleManager.TrySetStyle('Windows10 SlateGray'); Application.CreateForm(TMain, Main); + Application.CreateForm(TMemberChart, MemberChart); Application.Run; end.