-
Notifications
You must be signed in to change notification settings - Fork 1
/
Unit26.pas
321 lines (268 loc) · 8.45 KB
/
Unit26.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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
unit Unit26;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids, DBGrids, ADODB, DB, pngimage, ExtCtrls, dbConn_u, UserAcc,
jpeg;
type
TForm26 = class(TForm)
DBGrid1: TDBGrid;
Button2: TButton;
Button3: TButton;
Panel1: TPanel;
Image2: TImage;
Button4: TButton;
Button5: TButton;
Button6: TButton;
ADOQuery1: TADOQuery;
Button7: TButton;
Button8: TButton;
DataSource1: TDataSource;
Label4: TLabel;
Image3: TImage;
Image1: TImage;
qryBehindScenes: TADOQuery;
tblGift: TADOTable;
ADOQuery2: TADOQuery;
ADOQuery3: TADOQuery;
Panel2: TPanel;
Image4: TImage;
Label1: TLabel;
Label5: TLabel;
Label6: TLabel;
Button1: TButton;
procedure Button8Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Image2Click(Sender: TObject);
procedure FormCanResize(Sender: TObject; var NewWidth, NewHeight: Integer;
var Resize: Boolean);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure FormCreate(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure DBGrid1CellClick(Column: TColumn);
procedure Button7Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure DBGrid1ColEnter(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
Account : TAccount;
end;
var
Form26: TForm26;
implementation
uses Unit17;
{$R *.dfm}
procedure TForm26.Button1Click(Sender: TObject);
var heading, msg: string;
begin
//
try
heading := InputBox('','Enter Message of Notification','');
if heading<>'' then
begin
ADOQuery3.Connection.BeginTrans;
ADOQuery3.Close;
ADOQuery3.SQL.Text := 'INSERT into tblNotifications(By, ToWhom,Message) '+
'VALUES('+QuotedStr(Account.getEmployeeID)+','+QuotedStr('*')+','+QuotedStr(heading)+')';
if ADOQuery3.ExecSQL>0 then ADOQuery3.Connection.commitTrans;
end
else ShowMessage('You need to enter a message.');
except on E: Exception do
begin
ShowMessage('Error! Could not post message to customers.');
ADOQuery2.Connection.RollbackTrans;
exit;
end;
end;
end;
procedure TForm26.Button2Click(Sender: TObject);
begin
//
ADOQuery1.Close;
ADOQuery1.SQL.Text := 'SELECT CustomerID, DateOfTrans,LoyaltyPoints'+
' FROM tblLoyaltyPoints Where TYPE = "PURCHASE" ORDER BY LoyaltyPoints DESC ';
ADOQuery1.open;
DBGrid1.Columns[0].Width := 100;
DBGrid1.Columns[1].Width := 100;
DBGrid1.Columns[2].Width := 100;
end;
procedure TForm26.Button3Click(Sender: TObject);
begin
//
ADOQuery1.Close;
ADOQuery1.SQL.Text := 'SELECT Count(CustomerID) AS [No of Deposits],CustomerID from tblLoyaltyPoints'+
' Where Type = "DEPOSIT" GROUP by CustomerID ORDER BY Count(CustomerID) DESC';
ADOQuery1.Open;
DBGrid1.Columns[0].Width := 100;
DBGrid1.Columns[1].Width := 200;
end;
procedure TForm26.Button4Click(Sender: TObject);
var x : Real;
xx, numRec : integer;
y ,msg: string;
begin
//
y := ADOQuery1['CustomerID'];
try
x := StrToFloat(inputBox('GIFT','Enter Amount, in Points, to Gift Customer #'+
y,''));
except
ShowMessage('You have entered an invalid value.');
exit;
end;
xx := MessageDlg('Are you sure that you wish to Gift Customer #'+y +
' With '+ FloatToStr(x)+ ' Points.' ,mtConfirmation,[mbYes,mbNo],0);
if xx=6 then
begin
ADOQuery2.Connection.BeginTrans;
qryBehindScenes.Close;
qryBehindScenes.SQL.Text := 'INSERT INTO tblLoyaltyPoints(CUSTOMERID, LOYALTYPOINTS, TYPE)'+
' VALUES('+QuotedStr(y)+','+ FloatToStr(x) +' , '+ QuotedStr('BONUS') +')';
msg := 'HELLOW, YOU HAVE BEEN GIFTED WITH '+ FloatToStr(x)+ ' Points. Thanks for being a Loyal Customer.';
if qryBehindScenes.ExecSQL>0 then
begin
tblGift.Close;
tblGift.TableName := 'tblNotifications';
tblGift.Open;
numRec := tblGift.RecordCount;
tblGift.Insert;
tblGift['BY'] := Account.getEmployeeID;
tblGift['TOWHOM'] := y;
tblGift['MESSAGE'] := msg;
tblGift.Insert;
if numRec = tblGift.RecordCount then
begin
MessageDlg('An error occured while trying to gift A customer. try again later.',
mtError, [mbOk],0);
ADOQuery2.Connection.RollbackTrans;
end
else//if records have been inserted in both tblNotification and tblLoyalty points
begin
//then update the customers loyalty points
tblGift.Close;
tblGift.TableName := 'tblCustomers';
tblGift.Open;
tblGift.Locate('CustomerID', y, []);
tblGift.Edit;
tblGift['LoyaltyPoints'] := tblGift['LoyaltyPoints'] + x;
tblGift.Post;
ADOQuery2.Connection.CommitTrans;
ShowMessage('User has been successfully gifted.');
Button8Click(self);
end;
end;
end
else
ShowMessage('You have said No.');
end;
procedure TForm26.Button5Click(Sender: TObject);
var sID , stat: string;
begin
sID := ADOQuery1['CustomerId'];
tblGift.Close;
tblGift.TableName := 'tblCustomers';
tblGift.Open;
tblGift.Locate('CustomerID', sID, []);
tblGift.Edit;
if tblGift['ACCOUNT_STATUS'] then
stat := 'Blocked'
else stat := 'Unblocked';
tblGift['ACCOUNT_STATUS'] := Not(tblGift['ACCOUNT_STATUS']);
tblGift.Post;
ShowMessage('Account of '+sID+ ' has been ' + stat);
Button8Click(Self);
end;
procedure TForm26.Button6Click(Sender: TObject);
begin
ADOQuery1.Close;
ADOQuery1.SQL.Text := 'SELECT CustomerID, DateOfTrans, LoyaltyPoints from tblLoyaltyPoints'+
' Where TYPE = "BONUS" ORDER BY DateOfTrans DESC ';
ADOQuery1.Open;
DBGrid1.Columns[0].Width := 70;
DBGrid1.Columns[1].Width := 100;
DBGrid1.Columns[2].Width := 100;
end;
procedure TForm26.Button7Click(Sender: TObject);
begin
ADOQuery1.Close;
ADOQuery1.SQL.Text := 'SELECT CustomerID, firstName, Surname, IIF(DOB = Date(), "Today", DOB) AS BirthDate '+
' From tblCustomers ORDER by IIF(DOB = Date(), "Today", DOB)';
ADOQuery1.Open;
DBGrid1.Columns[0].Width := 70;
DBGrid1.Columns[1].Width := 100;
DBGrid1.Columns[2].Width := 100;
DBGrid1.Columns[3].Width := 150;
end;
procedure TForm26.Button8Click(Sender: TObject);
begin
//
DataSource1.DataSet := ADOQuery1;
ADOQuery1.Close;
ADOQuery1.SQL.Text := 'SELECT CustomerID, firstName, Surname, Gender, Email, ACCOUNT_STATUS from tblCustomers';
ADOQuery1.Open;
DBGrid1.Columns[0].Width := 70;
DBGrid1.Columns[1].Width := 100;
DBGrid1.Columns[2].Width := 100;
DBGrid1.Columns[3].Width := 50;
DBGrid1.Columns[4].Width := 150;
end;
procedure TForm26.DBGrid1CellClick(Column: TColumn);
begin
ADOQuery2.Close;
ADOQuery2.SQL.Text := 'SELECT * FROM tblCustomers Where CustomerID = '+
QuotedStr( ADOQuery1['CustomerID'] );
ADOQuery2.Open;
Image4.Picture.LoadFromFile(ExtractFilePath(ParamStr(0)) + ADOQuery2['ProfilePic']);
Label1.Caption := 'Name : '+ ADOQuery2['firstName'];
Label5.Caption := 'Surname : '+ ADOQuery2['Surname'];
//Last active
ADOQuery2.Close;
ADOQuery2.SQL.Text := 'SELECT * FROM tblLoyaltyPoints WHERE TYPE <> "BONUS" AND CustomerID = '+
QuotedStr(ADOQuery1['CustomerID'])+' ORDER by DateOfTrans DESC';
ADOQuery2.Open;
if (ADOQuery2.RecordCount >0) then
begin
ADOQuery2.First;
Label6.Caption := 'Last Active : '+ DateToStr(ADOQuery2['DateOfTrans']);
end
else
begin
Label6.Caption := 'Last Active : Never!';
end;
ADOQuery2.Close;
end;
procedure TForm26.DBGrid1ColEnter(Sender: TObject);
begin
DBGrid1CellClick(nil);
end;
procedure TForm26.FormCanResize(Sender: TObject; var NewWidth,
NewHeight: Integer; var Resize: Boolean);
begin
Resize := False;
end;
procedure TForm26.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
CanClose := False;
Image2Click(Self);
end;
procedure TForm26.FormCreate(Sender: TObject);
begin
Position := poDesktopCenter;
Button8Click(Self);
end;
procedure TForm26.FormShow(Sender: TObject);
begin
Button8Click(Self);
end;
procedure TForm26.Image2Click(Sender: TObject);
begin
self.Hide;
unit17.form15.show;
end;
end.