-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEditCard_u.pas
94 lines (82 loc) · 2.82 KB
/
EditCard_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
unit EditCard_u;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Data.Win.ADODB, Data.DB, Vcl.StdCtrls,
Vcl.ExtCtrls, DM_u, clsLogging;
type
TfrmEditCard = class(TForm)
lbledtCardNumber: TLabeledEdit;
lbledtOwnerName: TLabeledEdit;
lbledtCardOwnerSurname: TLabeledEdit;
lbledtCardBal: TLabeledEdit;
btnCreateCard: TButton;
qryEditCard: TADOQuery;
tblEditCard: TADOTable;
procedure btnUpdateCardClick(Sender: TObject);
procedure FormShow(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmEditCard: TfrmEditCard;
objLog : TLog;
implementation
uses
GiftCard_u;
{$R *.dfm}
// This function of here is for updating the Gift Card with the new infomation the user
// Has entered
procedure TfrmEditCard.btnUpdateCardClick(Sender: TObject);
begin
try
// Here we try and locate the record that matches the Gift Card number that we want to edit
// If then goes and updates all the changed information to the database
with tblEditCard do
begin
Locate('GiftCardNum', frmGiftCards.sCardNum, []);
Edit;
FieldByName('GiftCardNum').AsString := lbledtCardNumber.Text;
FieldByName('OwnerName').AsString := lbledtOwnerName.Text;
FieldByName('OwnerSurname').AsString := lbledtCardOwnerSurname.Text;
FieldByName('CardBalance').AsCurrency:= StrToFloat(lbledtCardBal.Text);
Post;
ShowMessage('Updating Done');
Hide;
// Write to the application log that a gift card was updated.
objLog:= TLog.Create;
objLog.WriteLog('INFO','Updating Gift Card : Successfull');
objLog.Free;
end;
except
on E : Exception do
begin
// Write to the log that the gift card could not be updated and add the reason why
objLog:= TLog.Create;
objLog.WriteLog('ERROR','Updating Gift Card : Failed');
objLog.WriteLog('ERROR','Reason For Failure : See Message Below');
objLog.WriteLog('ERROR',E.ClassName+' : '+E.Message);
objLog.Free;
end;
end;
end;
// When this form is first activated it goes and fecthes the Gifc Card we are going to edit
procedure TfrmEditCard.FormShow(Sender: TObject);
begin
qryEditCard.Active:= True;
tblEditCard.Active:= True;
with qryEditCard do
begin
SQL.Text := ' select * from GiftCard where GiftCardNum=:CardNum ';
Parameters.ParamByName('CardNum').Value := frmGiftCards.sCardNum;
ExecSQL;
Open;
lbledtCardNumber.Text := FieldByName('GiftCardNum').AsString;
lbledtOwnerName.Text := FieldByName('OwnerName').AsString;
lbledtCardOwnerSurname.Text := FieldByName('OwnerSurname').AsString;
lbledtCardBal.Text := FieldByName('CardBalance').AsString;
end;
end;
end.