-
Notifications
You must be signed in to change notification settings - Fork 0
/
insert.pl
75 lines (68 loc) · 2.38 KB
/
insert.pl
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
:- use_module(library(pce)).
:- dynamic(employee/5).
load :-
seeing(S),
see('database.txt'),
load_data,
seen,
see(S).
insert :-
new(Point, point(100, 100)),
new(Frame, frame('Inserisci impiegato')),
new(Dialog, dialog),
send_list(Dialog, append,
[ new(N1, text_item(nome)),
new(N2, text_item(cognome)),
new(S, menu(sesso)),
new(A, int_item(età, low := 18, high := 70)),
new(D, menu(dipartimento, cycle)),
button(chiudi, message(Frame, destroy)),
button(inserisci, (message(@prolog,
assert_employee,
N1?selection,
N2?selection,
S?selection,
A?selection,
D?selection))),
button(rimuovi, (message(@prolog,
remove_employee,
N1?selection,
N2?selection))),
button(salva, (message(@prolog,
save_data)))
]),
send_list(S, append, [male, female]),
send_list(D, append, [research, it_solutions, sales, marketing, human_resources]),
send(Frame, append(Dialog)),
send(Frame, open(position := Point)).
load_data :-
read(Term),
( Term == end_of_file
-> true
; assertz(Term), load_data
).
assert_employee(Name, Family, Sex, Age, Dept) :-
downcase_atom(Name, Newname),
downcase_atom(Family, Newfamily),
assertz(employee(Newname, Newfamily, Sex, Age, Dept)),
format('Adding ~w ~w to the database ~n',
[Name, Family]).
remove_employee(Name, Family) :-
downcase_atom(Name, Newname),
downcase_atom(Family, Newfamily),
retract(employee(Newname, Newfamily, _, _, _)),
format('Removing ~w ~w from the database ~n', [Name, Family]).
save_data :-
telling(S),
tell('database.txt'),
update,
told,
tell(S),
format('Successfully updated the database file! ~n').
update :-
employee(Name, Family, Sex, Age, Dept),
write(employee(Name, Family, Sex, Age, Dept)),
put(46),
nl,
fail.
update.