-
Notifications
You must be signed in to change notification settings - Fork 1
/
Unit16.pas
203 lines (174 loc) · 5.19 KB
/
Unit16.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
unit Unit16;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, pngimage,dbConn_u, ExtCtrls, unit12, db_management, userAcc, unit17;
type
TForm16 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Image1: TImage;
imgBtnTogglePassword: TImage;
btnLogin: TButton;
edtUName: TEdit;
edtPassword: TEdit;
dateTime: TTimer;
dateItem: TLabel;
Label4: TLabel;
procedure imgBtnTogglePasswordClick(Sender: TObject);
procedure btnLoginClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure dateTimeTimer(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure FormCanResize(Sender: TObject; var NewWidth, NewHeight: Integer;
var Resize: Boolean);
private
{ Private declarations }
defaultLocation : string;
procedure togglePassword;
procedure logIn;
public
{ Public declarations }
callerID : TObject;
DestinationID: TObject;
end;
var
Form16: TForm16;
passwordShowing : Boolean;
prevPos, currPos : Integer;
POSQuery : TPOSQuery;
implementation
uses dashboard_u, unit14;
{$R *.dfm}
procedure TForm16.btnLoginClick(Sender: TObject);
var uName , uPass : String;
begin
uName := edtUName.Text;
uPass := edtPassword.Text;
if (uName='') or (uPass='') then
begin
ShowMessage('You need to enter both your Username and Password');
exit;
end;
if POSQuery.userExists(uName , uPass) then
begin
ShowMessage('Welcome '+ uName);
Form16.Hide;
logIn;
dashboard_u.Form2.Enabled:=True;
dashboard_u.Form2.Show;
edtPassword.Clear;
edtUName.Clear;
end
else
begin
ShowMessage('Your username or password does not match'+#13+
' any record in our database');
dashboard_u.Form2.clockedIn := False;
dashboard_u.Form2.Enabled:=True;
Form16.Hide;
edtPassword.Clear;
end;
end;
procedure TForm16.dateTimeTimer(Sender: TObject);
begin
dateItem.Caption := DateTimeToStr(now);
end;
procedure TForm16.FormCanResize(Sender: TObject; var NewWidth,
NewHeight: Integer; var Resize: Boolean);
begin
Resize := False;
end;
procedure TForm16.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
CanClose := False;
dashboard_u.Form2.clockedIn := False;
dashboard_u.Form2.Enabled:=True;
Form16.Hide;
end;
procedure TForm16.FormCreate(Sender: TObject);
begin
(Sender as TForm).Position:=poScreenCenter;
(Sender as TForm).DefaultMonitor := dmMainForm;
self.Position:=poDesktopCenter;
passwordShowing := False;
togglePassword;
POSQuery := TPOSQuery.create;
POSQuery.maintainDB;
edtUName.Text := POSQuery.lastUser;
end;
procedure TForm16.FormShow(Sender: TObject);
begin
edtUName.Text := POSQuery.lastUser;
edtPassword.SetFocus;
end;
procedure TForm16.imgBtnTogglePasswordClick(Sender: TObject);
begin
togglePassword;
end;
procedure TForm16.logIn;
var
EmployeeID : string;
firstName : string;
Surname : string;
Gender : string;
Email : string;
SAID : string;
Password : string;
ACCOUNT_STATUS : Boolean;
DateHired : TDate;
DateFired : TDate;
Admin : boolean;
hWage : Real;
begin
dashboard_u.Form2.clockedIn := True;
with dbConn_u.DataModule1 do
begin
qryLogin.close;
qryLogin.SQL.Text:='SELECT * FROM tblEmployees WHERE EmployeeID';
qryLogin.SQL.Add(' LIKE '+QuotedStr('%'+ edtUName.Text+'%')+
' AND Password LIKE '+QuotedStr('%'+edtPassword.Text+'%'));
qryLogin.open;
EmployeeID := qryLogin['EmployeeID'];
dashboard_u.Form2.Caption:='You are logged in '+ EmployeeID;
firstName := qryLogin['firstName'];
Surname := qryLogin['Surname'];
Gender := qryLogin['Gender'];
Email := qryLogin['Email'];
SAID := qryLogin['SAID'];
Password := qryLogin['Password'];
ACCOUNT_STATUS := qryLogin['ACCOUNT_STATUS'];
Admin := qryLogin['Admin'];
hWage := qryLogin['HourlyWage'];
DateHired := qryLogin['DateHired'];
if qryLogin['DateFired']<>Null then
DateFired := qryLogin['DateFired']
else DateHired := 0;
dashboard_u.Form2.Account := TAccount.Create(
EmployeeID,firstName,Surname,Gender,EmployeeID,SAID,
Password,ACCOUNT_STATUS,Admin,DateHired,DateFired, hWage);
qryLogin.Close;
qryLogin.SQL.Text:='INSERT INTO tblAttendance(EmployeeID,DateOfDay,ClockInTime, Paid)';
qryLogin.SQL.Add(' VALUES('+QuotedStr(EmployeeID)+', #'+DateToStr(Now)+'#, Now(), False)');
qryLogin.ExecSQL;
dashboard_u.Form2.distributeAll;
end;
end;
procedure TForm16.togglePassword;
begin
if passwordShowing = True then
begin
passwordShowing := False;
edtPassword.PasswordChar := chr(0);
imgBtnTogglePassword.Picture.LoadFromFile(ExtractFilePath(ParamStr(0))+ 'media\icons\lock-128.png');
end
else
begin
passwordShowing := True;
edtPassword.PasswordChar := '•';
imgBtnTogglePassword.Picture.LoadFromFile(ExtractFilePath(ParamStr(0))+ 'media\icons\unlocked-128.png');
end;
end;
end.