-
Notifications
You must be signed in to change notification settings - Fork 0
/
Unit2.~pas
102 lines (86 loc) · 2.33 KB
/
Unit2.~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
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, ZAbstractRODataset, ZAbstractDataset, ZDataset;
type
Tlogin = class(TForm)
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
Label4: TLabel;
Label5: TLabel;
ZQuery1: TZQuery;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
login: Tlogin;
implementation
uses Unit1, Menu;
{$R *.dfm}
procedure Tlogin.Button1Click(Sender: TObject);
var
UserName, Password: string;
UserLevel: string;
begin
// Get the username and password entered by the user
UserName := Edit1.Text;
Password := Edit2.Text;
// Check if username or password is empty
if (UserName = '') or (Password = '') then
begin
ShowMessage('DATA TIDAK BOLEH KOSONG!');
end
else
begin
// Check the credentials against the database
if DataModule1.ZConnection1.Connected then
begin
// Query the user table for the provided username and password
ZQuery1.SQL.Text :=
'SELECT * FROM user WHERE username = :username AND password = :password';
ZQuery1.Params.ParamByName('username').AsString := UserName;
ZQuery1.Params.ParamByName('password').AsString := Password;
ZQuery1.Open;
// Check if a matching record is found
if not ZQuery1.IsEmpty then
begin
// Retrieve the user's level
UserLevel := ZQuery1.FieldByName('level').AsString;
// Successful login
ShowMessage('Login Success!');
if UserLevel = 'Admin' then
begin
MenuUtama.ShowModal; // Show the MenuUtama form for Admin level
end
else if UserLevel = 'User' then
begin
MenuUtamaUser.ShowModal; // Show the MenuUtamaAdmin form for User level
end
else
begin
ShowMessage('Invalid user level!');
end;
Close; // Close the login form
end
else
begin
// Invalid username or password
ShowMessage('Username or password is incorrect!');
end;
end
else
begin
// Database connection is not established
ShowMessage('Database connection is not established!');
end;
end;
end;
end.