-
Notifications
You must be signed in to change notification settings - Fork 0
/
dmSCM.pas
176 lines (152 loc) · 4.37 KB
/
dmSCM.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
unit dmSCM;
interface
uses
System.SysUtils, System.Classes, FireDAC.Stan.Intf, FireDAC.Stan.Option,
FireDAC.Stan.Error, FireDAC.UI.Intf, FireDAC.Phys.Intf, FireDAC.Stan.Def,
FireDAC.Stan.Pool, FireDAC.Stan.Async, FireDAC.Phys, FireDAC.Phys.MSSQL,
FireDAC.Phys.MSSQLDef, FireDAC.VCLUI.Wait, Data.DB, FireDAC.Comp.Client,
FireDAC.Stan.Param, FireDAC.DatS, FireDAC.DApt.Intf, FireDAC.DApt,
FireDAC.Comp.DataSet;
type
TSCM = class(TDataModule)
scmConnection: TFDConnection;
qrySwimClub: TFDQuery;
dsSwimClub: TDataSource;
qryMetersSwum: TFDQuery;
dsMetersSwum: TDataSource;
dsRaceTime: TDataSource;
qryRaceTime: TFDQuery;
qryHistory: TFDQuery;
dsHistory: TDataSource;
dsPersonalBest: TDataSource;
qryPersonalBest: TFDQuery;
qryMemberList: TFDQuery;
qryMetersSwumTot: TFDQuery;
MetersSwumTot: TDataSource;
qryMemberStat: TFDQuery;
dsMemberStat: TDataSource;
procedure DataModuleCreate(Sender: TObject);
private
{ Private declarations }
FIsActive: boolean;
function GetStartOfSwimmingSeason(SwimClubID: integer): TDateTime;
public
{ Public declarations }
procedure ActivateTable();
// procedure SimpleLoadSettingString(Section, Name: string; var Value: string);
// procedure SimpleMakeTemporyFDConnection(Server, User, Password: string;
// OsAuthent: boolean);
// procedure SimpleSaveSettingString(Section, Name, Value: string);
property IsActive: boolean read FIsActive write FIsActive;
end;
const
SCMCONFIGFILENAME = 'SCMConfig.ini';
var
SCM: TSCM;
implementation
{%CLASSGROUP 'Vcl.Controls.TControl'}
{$R *.dfm}
{ TSCM }
uses
System.IOUtils, IniFiles, DateUtils;
procedure TSCM.ActivateTable;
begin
FIsActive := true;
qrySwimClub.Connection := scmConnection;
qryMetersSwum.Connection := scmConnection;
end;
procedure TSCM.DataModuleCreate(Sender: TObject);
begin
ActivateTable;
end;
function TSCM.GetStartOfSwimmingSeason(SwimClubID: integer): TDateTime;
var
dt: TDateTime;
begin
result := Date();
if SwimClubID > 0 then
begin
if qrySwimClub.active then
qrySwimClub.Close;
qrySwimClub.ParamByName('SWIMCLUBID').AsInteger := SwimClubID;
qrySwimClub.Prepare;
qrySwimClub.Open;
if qrySwimClub.active then
begin
if not qrySwimClub.IsEmpty then
begin
dt := qrySwimClub.FieldByName('StartOfSwimSeason').AsDateTime;
// If ANow and AThen are two and a half years apart,
// calling WithinPastYears with AYears set to 2 returns True.
if WithinPastYears(result, dt, 1) then
result := dt;
end;
end;
end;
end;
{
procedure TSCM.SimpleLoadSettingString(Section, Name: string;
var Value: string);
var
ini: TIniFile;
begin
ini := TIniFile.Create(TPath.GetDocumentsPath + PathDelim +
SCMCONFIGFILENAME);
try
Value := ini.ReadString(Section, name, '');
finally
ini.Free;
end;
end;
procedure TSCM.SimpleMakeTemporyFDConnection(Server, User, Password: string;
OsAuthent: boolean);
var
Value, Section: string;
begin
if (scmConnection.Connected) then
begin
scmConnection.Close();
end;
scmConnection.Params.Add('Server=' + Server);
scmConnection.Params.Add('DriverID=MSSQL');
scmConnection.Params.Add('Database=SwimClubMeet');
scmConnection.Params.Add('User_name=' + User);
scmConnection.Params.Add('Password=' + Password);
if (OsAuthent) then
Value := 'Yes'
else
Value := 'No';
scmConnection.Params.Add('OSAuthent=' + Value);
scmConnection.Params.Add('Mars=yes');
scmConnection.Params.Add('MetaDefSchema=dbo');
scmConnection.Params.Add('ExtendedMetadata=False');
scmConnection.Params.Add('ApplicationName=scmTimeKeeper');
scmConnection.Connected := true;
// ON SUCCESS - Save connection details.
if (scmConnection.Connected) then
begin
Section := 'MSSQL_SwimClubMeet';
Name := 'Server';
SimpleSaveSettingString(Section, Name, Server);
Name := 'User';
SimpleSaveSettingString(Section, Name, User);
Name := 'Password';
SimpleSaveSettingString(Section, Name, Password);
Name := 'OSAuthent';
SimpleSaveSettingString(Section, Name, Value);
end
end;
procedure TSCM.SimpleSaveSettingString(Section, Name, Value: string);
var
ini: TIniFile;
begin
ini := TIniFile.Create(TPath.GetDocumentsPath + PathDelim +
SCMCONFIGFILENAME);
try
ini.WriteString(Section, Name, Value);
finally
ini.Free;
end;
end;
}
end.