-
Notifications
You must be signed in to change notification settings - Fork 1
/
Unit7.pas
277 lines (236 loc) · 6.92 KB
/
Unit7.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
unit Unit7;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, pngimage,dbConn_u,db_management, ComCtrls;
type
TForm7 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Edit4: TEdit;
Edit5: TEdit;
edtPassword: TEdit;
CheckBox1: TCheckBox;
CheckBox2: TCheckBox;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label12: TLabel;
Panel2: TPanel;
Button2: TButton;
Button3: TButton;
Label8: TLabel;
ComboBox1: TComboBox;
imgBtnTogglePassword: TImage;
Label9: TLabel;
edtWage: TEdit;
Label7: TLabel;
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure togglePassword;
procedure imgBtnTogglePasswordClick(Sender: TObject);
procedure clearAll;
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure FormCanResize(Sender: TObject; var NewWidth, NewHeight: Integer;
var Resize: Boolean);
procedure Edit4KeyPress(Sender: TObject; var Key: Char);
procedure Edit4KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
private
{ Private declarations }
public
{ Public declarations }
empID : String;
end;
var
Form7: TForm7;
passwordShowing : Boolean;
POSQuery : TPOSQuery;
oldString : String;
arrEdits : array[1..5] of TEdit;
implementation
uses unit6;
{$R *.dfm}
procedure TForm7.Button2Click(Sender: TObject);
var
fName, surname, gender, email, said,
password: String; AccStat, Admin: Boolean;
resp : string;
hwage : Real;
x,n : integer;
begin
//EXTRACTING USER DATA
fName:= Edit1.Text;
surname:=Edit2.Text;
gender:=ComboBox1.Items[ComboBox1.ItemIndex];
email:=Edit4.Text;
said:=Edit5.Text;
password:=edtPassword.Text;
AccStat:= CheckBox1.Checked;
Admin:= CheckBox2.Checked;
try
hwage := StrToFloat(edtWage.Text);
except on E: Exception do
begin
ShowMessage('You have entered an invalid Number for your salary. Make sure you enter the numbers correctly.');
edtWage.Clear;
Exit;
end;
end;
if Length(said)<>13 then
begin
ShowMessage('South African ID is of invalid length. Enter correct value.');
edit5.Clear;
Exit;
end;
//validate that the employeeID consists of valid digits only.
n := 0;//no of chars that are digits
for x := 1 to length(said) do
begin
if said[x] in ['0'..'9'] then
n := n+ 1;
end;
if n <> length(said) then
//meaning that the no of chars that are digits are not equal to the
//no of chars entered by user
begin
ShowMessage('Error with your South African ID. Make sure that you are only entering digits');
edit5.Clear;
Exit;
end;
if Not(Length(password) in [8..20]) then
//minimum password length is 8 chars, max is 20. if anything other than that
//is entered then it's considered an invalid password.
begin
ShowMessage('minimum password length is 8 chars, max is 20. You have entered an Invalid Password. Correct that first.');
edtPassword.Clear;
Exit;
end;
if not (Pos('@', email)>0) then
//if there's no @ sign in email, then it's invalid.
//incase if you're wondering, what if user tries to enter more than one @ sign.
//well, in the onpress and onkeyup event for the edit that captures emails,
//i have written code that only allows one @ sign to be entered.
begin
ShowMessage('You have entered an invalid email. It should be of the format below : [email protected]');
Edit4.Clear;
Exit;
end;
//check that data is correct- Validation
if not (
(fName<>'') and (surname<>'') and (gender<>'') and (email<>'') and (said<>'') and
(password<>'') and (hwage>0)
) then
POSQuery := TPOSQuery.create;
if Panel2.Caption = 'CREATE NEW EMPLOYEE' then
begin
resp:= POSQuery.createEmployee(fName,surname,gender,email,said,password,AccStat, Admin,hwage);
if resp<>'' then
ShowMessage('Employee Account Has been created. The Employee ID is '+resp)
else
ShowMessage('Error while creating Employee Account. If error persists, please contact admin.');
//also have a profile for vendors, like from vendors page, manager can view all products supplied
end
else
begin
resp:= POSQuery.updateEmployee(empID,fName,surname,gender,email,said,password,AccStat, Admin,hwage);
ShowMessage(resp);
end;
clearAll;
unit6.Form6.Enabled:=true;
Form7.hide;
end;
procedure TForm7.Button3Click(Sender: TObject);
begin
clearAll;
end;
procedure TForm7.clearAll;
var i:integer;
obj : TObject;
begin
for i := 0 to Form7.ComponentCount-1 do
begin
obj := (Form7.Components[i] as TObject);
if (obj is TEdit) then
(obj as TEdit).Text:=''
else
if (obj is TComboBox) then
(obj as TComboBox).ItemIndex:=0
else
if (obj is TCheckBox) then
(obj as TCheckBox).Checked:=false;
end;
passwordShowing:=false;
togglePassword;
i:=1;
arrEdits[i].setFocus;
unit6.Form6.Enabled:=true;
Form7.hide;
end;
procedure TForm7.Edit4KeyPress(Sender: TObject; var Key: Char);
begin
//
if key = '@' then
if pos('@', oldString)>0 then key := chr(0);
oldString:= Edit4.Text;
end;
procedure TForm7.Edit4KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
if ord('@') = Key then
if pos('@', oldString)>0 then key := 0;
oldString:= Edit4.Text;
end;
procedure TForm7.FormCanResize(Sender: TObject; var NewWidth,
NewHeight: Integer; var Resize: Boolean);
begin
Resize := False;
end;
procedure TForm7.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
CanClose := False;
Button3Click(self);
end;
procedure TForm7.FormCreate(Sender: TObject);
begin
oldString := edit4.Text;
(Sender as TForm).Position:=poScreenCenter;
(Sender as TForm).DefaultMonitor := dmMainForm;
passwordShowing := False;
togglePassword;
POSQuery:=TPOSQuery.create;
arrEdits[1]:=Edit1;
arrEdits[2]:=Edit2;
arrEdits[3]:=Edit4;
arrEdits[4]:=Edit5;
arrEdits[5]:=edtPassword;
end;
procedure TForm7.imgBtnTogglePasswordClick(Sender: TObject);
begin
togglePassword;
end;
procedure TForm7.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.
{ code that might be useful
for i := 1 to length(arrEdits) do
arrEdits[i].clear;
ComboBox1.ItemIndex:=0;
CheckBox1.Checked:=false;
CheckBox2.Checked:=false;
}