-
Notifications
You must be signed in to change notification settings - Fork 0
/
frmAnalytics_u.pas
285 lines (249 loc) · 8.03 KB
/
frmAnalytics_u.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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
// ##################################
// ###### IT PAT 2018 #######
// ###### GrowCery #######
// ###### Tiaan van der Riel #######
// ##################################
unit frmAnalytics_u;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, TeEngine, TeeProcs, Chart, Grids, DBGrids,
pngimage, Buttons, ComCtrls, Mask, DBCtrls, Series, TeeDBEdit, TeeDBCrossTab,
clsAnalyticsCalculator_u;
type
TfrmAnalytics = class(TForm)
dbgAccounts: TDBGrid;
btnBack: TButton;
pnlInfo: TPanel;
lblSearchAccountID: TLabel;
lblChartStart: TLabel;
lblChartEnd: TLabel;
edtSearhAccountID: TEdit;
imgLogo: TImage;
btnHelp: TButton;
Label1: TLabel;
DBEdit1: TDBEdit;
Label2: TLabel;
DBEdit2: TDBEdit;
Label3: TLabel;
DBEdit3: TDBEdit;
dbgTransactionsByDate: TDBGrid;
pnlTop: TPanel;
lblAccounts: TLabel;
lblAccountsHeading: TLabel;
lblTransactionsWithinPeriod: TLabel;
edtDateStart: TEdit;
edtDtaeEnd: TEdit;
rgbStyleOfChart: TRadioGroup;
DBCrossTabSource1: TDBCrossTabSource;
DBCrossTabSource2: TDBCrossTabSource;
pnlAverageNumberSold: TPanel;
pnlInfoBorder: TPanel;
pnlTotalItems: TPanel;
pnlAverageValue: TPanel;
pnlTotalValue: TPanel;
lblTotalValue: TLabel;
lblAverageValue: TLabel;
lblTotalItems: TLabel;
lblAverageNumberSold: TLabel;
Chart1: TChart;
Series1: TBarSeries;
Series2: TLineSeries;
procedure FormActivate(Sender: TObject);
procedure btnBackClick(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure edtSearhAccountIDChange(Sender: TObject);
procedure dbgAccountsCellClick(Column: TColumn);
procedure rgbStyleOfChartClick(Sender: TObject);
procedure btnHelpClick(Sender: TObject);
procedure FormShow(Sender: TObject);
private
{ Private declarations }
objAnalyticsCalculator: TAnalyticsCalculator;
iStyleOfChartNumber: integer;
procedure UpdateChart;
{ Public declarations }
end;
var
frmAnalytics: TfrmAnalytics;
implementation
uses
frmAdminHomeScreen_u, dmDatabase_u;
{$R *.dfm}
/// ===================== User Clicks On A Different Cell =====================
procedure TfrmAnalytics.dbgAccountsCellClick(Column: TColumn);
var
sSelectedAccountID: string;
sStartDate: string;
sEndDate: string;
iCount: integer;
rTotalSales: real;
rAverageSalesValue: real;
iTotalNumberOfItemsSold: integer;
rAverageNumberOfItemsSold: real;
begin
Beep;
Screen.Cursor := crHourGlass;
Sleep(150);
// Determines what style of chart the user wants
if rgbStyleOfChart.ItemIndex = 0 then
begin
iStyleOfChartNumber := 1;
end;
if rgbStyleOfChart.ItemIndex = 1 then
begin
iStyleOfChartNumber := 2;
end;
// Gets the start and the end date
sStartDate := edtDateStart.Text;
sEndDate := edtDtaeEnd.Text;
// Determines what account is selected
with dmDatabase do
Begin
dsrTransactions.DataSet := qryTransactions;
sSelectedAccountID := tblAccounts['AccountID'];
End;
// Creates object and sends over paramaters
objAnalyticsCalculator := TAnalyticsCalculator.Create
(sSelectedAccountID, sStartDate, sEndDate);
// Calls the functions of the object in order to recieve processed data back
pnlTotalValue.Caption := FloatToStrF(objAnalyticsCalculator.CalcTotalSales,
ffCurrency, 8, 2);
pnlAverageValue.Caption := FloatToStrF
(objAnalyticsCalculator.CalcAverageSales, ffCurrency, 8, 2);
pnlTotalItems.Caption := IntToStr(objAnalyticsCalculator.CalcTotalItemsSold);
pnlAverageNumberSold.Caption := IntToStr
(objAnalyticsCalculator.CalcAverageItemsSold);
objAnalyticsCalculator.Free;
//
UpdateChart;
//
if pnlTotalItems.Caption = '0' then
Begin
Beep;
Dialogs.MessageDlg(
'No transactions where found within the period you selected.' + #13 +
'Please check the dates you entered to verify that they are correct.',
mtError, [mbOk], 0, mbOk);
End;
Screen.Cursor := crDefault;
end;
/// ============ User Eneters An AccountID Into The Search Field ==============
procedure TfrmAnalytics.edtSearhAccountIDChange(Sender: TObject);
{ This porcedure is used to search, and filter the table of accounts, to
display the smilar names, as the user types a name into the edit field }
begin
if (edtSearhAccountID.Text <> '') then
Begin
dmDatabase.tblAccounts.Filter := 'AccountID LIKE ''' +
(edtSearhAccountID.Text) + '%'' ';
dmDatabase.tblAccounts.Filtered := True;
End
else
begin
dmDatabase.tblAccounts.Filtered := False;
end;
end;
/// ====================== Form Gets Activated ================================
procedure TfrmAnalytics.FormActivate(Sender: TObject);
begin
//
pnlInfo.Color := rgb(139, 198, 99);
pnlTop.Color := rgb(139, 198, 99);
dmDatabase.tblAccounts.Filter := 'IsAdmin = False';
dmDatabase.tblAccounts.Filtered := True;
//
end;
/// =========================== Form Gets Closed ==============================
procedure TfrmAnalytics.FormClose(Sender: TObject; var Action: TCloseAction);
begin
frmAdminHomeScreen.Show;
end;
procedure TfrmAnalytics.FormShow(Sender: TObject);
begin
end;
/// ====================== User Selects A Style Of Chart ======================
procedure TfrmAnalytics.rgbStyleOfChartClick(Sender: TObject);
begin
if rgbStyleOfChart.ItemIndex = 0 then
begin
iStyleOfChartNumber := 1;
end;
if rgbStyleOfChart.ItemIndex = 1 then
begin
iStyleOfChartNumber := 2;
end;
UpdateChart;
end;
/// ====================== Procedure To Update Chart ==========================
procedure TfrmAnalytics.UpdateChart;
var
sNameOfSeries: string;
begin
Series1.Clear;
Series2.Clear;
sNameOfSeries := 'Series' + IntToStr(iStyleOfChartNumber);
Chart1.Title.Caption := dmDatabase.tblAccounts['Name']
+ ' ' + +dmDatabase.tblAccounts['Surname'];
{ User Selects to veiw 'Totals for the day', chart style 'Series2' will display
these values }
if sNameOfSeries = 'Series1' then
Begin
while NOT dmDatabase.qryTransactions.Eof do
Begin
Series1.Add(StrToFloat(dmDatabase.qryTransactions['Total For The Day']),
dmDatabase.qryTransactions['DateOfTransaction'], clGreen);
dmDatabase.qryTransactions.Next;
End;
End;
{ User Selects to veiw 'Number Of Items Sold', chart style 'Series2' will display
these values }
if sNameOfSeries = 'Series2' then
Begin
while NOT dmDatabase.qryTransactions.Eof do
Begin
Series1.Add(StrToFloat(dmDatabase.qryTransactions['Number Of Items Sold'])
, dmDatabase.qryTransactions['DateOfTransaction'], clGreen);
dmDatabase.qryTransactions.Next;
End;
End;
end;
/// ===================== User Clicks On Back Button ==========================
procedure TfrmAnalytics.btnBackClick(Sender: TObject);
begin
begin
if MessageDlg(' Are you sure you want to return to your home page ?',
mtConfirmation, [mbYes, mbCancel], 0) = mrYes then
begin
frmAnalytics.Close;
end
else
Exit
end;
end;
/// ============================ Help Button ==================================
procedure TfrmAnalytics.btnHelpClick(Sender: TObject);
var
tHelp: TextFile;
sLine: string;
sMessage: string;
begin
sMessage := '========================================';
AssignFile(tHelp, 'Help_Analytics.txt');
try { Code that checks to see if the file about the sponsors can be opened
- displays error if not }
reset(tHelp);
Except
ShowMessage('ERROR: The help file could not be opened.');
Exit;
end;
while NOT Eof(tHelp) do
begin
Readln(tHelp, sLine);
sMessage := sMessage + #13 + sLine;
end;
sMessage := sMessage + #13 + '========================================';
CloseFile(tHelp);
ShowMessage(sMessage);
end;
end.