-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEmployeeManagementSystem.sh
407 lines (397 loc) · 13.9 KB
/
EmployeeManagementSystem.sh
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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
#!/bin/bash
logged_in=false
database_file="employee.db"
function create_tables() {
sqlite3 "$database_file" <<EOF
PRAGMA foreign_keys = ON;
CREATE TABLE IF NOT EXISTS employees (
ID INTEGER PRIMARY KEY,
Name TEXT NOT NULL,
Gender TEXT,
Location TEXT,
Phone TEXT,
Email TEXT,
Education TEXT,
Designation TEXT,
Salary INTEGER
);
EOF
}
function add_employee() {
while true; do
read -p "Enter the name of the employee: " empName
if [[ "$empName" =~ ^[a-zA-Z0-9[:space:]]+$ ]]; then
break
else
echo "INVALID EMPLOYEE NAME. ONLY ALPHANUMERIC CHARACTERS AND SPACES ARE ALLOWED."
fi
done
while true; do
read -p "Enter the gender of the employee: " empGen
if [[ "$empGen" =~ ^[Mm][Aa][Ll][Ee]$ || "$empGen" =~ ^[Ff][Ee][Mm][Aa][Ll][Ee]$ ]]; then
break
else
echo "INVALID GENDER. PLEASE ENTER 'MALE' or 'FEMALE'"
fi
done
while true; do
read -p "Enter the location of the employee: " empLoc
if [[ -n $empLoc ]]; then
break
else
echo "EMPLOYEE LOCATION CANNOT BE EMPTY"
fi
done
while true; do
read -p "Enter the phone number of the employee: " empPhn
if [[ $empPhn =~ ^[0-9]{10}$ ]]; then
break
else
echo "INVALID PHONE NUMBER. PLEASE ENTER A 10-digit NUMERIC VALUE."
fi
done
while true; do
read -p "Enter the email address of the employee: " empMail
if [[ $empMail =~ ^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$ ]]; then
break
else
echo "INVALID Email ADDRESS FORMAT. PLEASE ENTER A VALID Email ADDRESS."
fi
done
while true; do
read -p "Enter the education qualification of the employee: " empEdu
if [[ -n $empEdu ]]; then
break
else
echo "EDUCATION QUALIFICATION CANNOT BE EMPTY."
fi
done
while true; do
read -p "Enter the designation of the employee: " empRole
if [[ -n $empRole ]]; then
break
else
echo "EMPLOYEE DESIGNATION CANNOT BE EMPTY."
fi
done
while true; do
read -p "Enter the salary of the employee: " empSal
if [[ $empSal =~ ^[1-9][0-9]*$ ]]; then
break
else
echo "INVALID SALAY. PLEASE ENTER A POSITIVE NUMERIC VALUE."
fi
done
sqlite3 "$database_file" <<EOF
INSERT INTO employees (Name, Gender, Location, Phone, Email, Education, Designation, Salary)
VALUES ('$empName', '$empGen', '$empLoc', '$empPhn', '$empMail', '$empEdu', '$empRole', $empSal);
EOF
echo
echo "ADDING..."
sleep 2
echo "Employee details added successfully."
}
function view_employee() {
echo -e "1. View all employees\n2. Enter the ID of the employee to view details"
read -p "Enter your choice: " view_choice
case "$view_choice" in
1)
echo
sleep 0.5
echo "VIEWING ALL EMPLOYEES..."
sleep 1
echo
if [ -f "$database_file" ]; then
sqlite3 -column -header "$database_file" <<EOF
SELECT ID, Name, Gender, Location, Phone, Email, Education, Designation, Salary FROM employees;
EOF
else
echo "No employee details found."
fi
;;
2)
echo
read -p "Enter the ID of the employee to view details: " empID
if [ -f "$database_file" ]; then
employee_data=$(sqlite3 "$database_file" "SELECT * FROM employees WHERE ID = $empID;")
if [ -n "$employee_data" ]; then
IFS="|" read -ra employee_fields <<< "$employee_data"
empName=${employee_fields[1]}
empGen=${employee_fields[2]}
empLoc=${employee_fields[3]}
empPhn=${employee_fields[4]}
empMail=${employee_fields[5]}
empEdu=${employee_fields[6]}
empRole=${employee_fields[7]}
empSal=${employee_fields[8]}
echo
echo "FETCHING..."
sleep 3
echo
echo "-----------------------------------------------------------------------------"
echo "Employee details:"
echo
echo "Employee name is: $empName"
echo "Employee gender is: $empGen"
echo "Employee location is: $empLoc"
echo "Employee phone number is: $empPhn"
echo "Employee email address is: $empMail"
echo "Employee education qualification is: $empEdu"
echo "Employee designation is: $empRole"
echo "Employee salary is: $empSal"
echo "-----------------------------------------------------------------------------"
else
echo
sleep 1
echo "Employee with ID $empID not found."
fi
else
echo
sleep 1
echo "Employee details not found."
fi
;;
*)
echo
sleep 1
echo "Invalid choice. Please enter 1 or 2."
;;
esac
}
function update_employee() {
read -p "Enter the ID of the employee to update: " empID
if [ -f "$database_file" ]; then
existing_data=$(sqlite3 "$database_file" "SELECT * FROM employees WHERE id = $empID;")
if [ -n "$existing_data" ]; then
IFS="|" read -ra existing_fields <<< "$existing_data"
empName=${existing_fields[1]}
empGen=${existing_fields[2]}
empLoc=${existing_fields[3]}
empPhn=${existing_fields[4]}
empMail=${existing_fields[5]}
empEdu=${existing_fields[6]}
empRole=${existing_fields[7]}
empSal=${existing_fields[8]}
echo "Employee details: $existing_data"
sleep 0.5
echo
while true; do
read -p "Enter the new name of the employee (Press Enter to leave unchanged): " new_empName
if [[ -z $new_empName || "$new_empName" =~ ^[a-zA-Z0-9[:space:]]+$ ]]; then
break
else
echo "INVALID EMPLOYEE NAME. ONLY ALPHANUMERIC CHARACTERS AND SPACES ARE ALLOWED."
fi
done
while true; do
read -p "Enter the new gender of the employee (Press Enter to leave unchanged): " new_empGen
if [[ -z $new_empGen || "$new_empGen" =~ ^[Mm][Aa][Ll][Ee]$ || "$new_empGen" =~ ^[Ff][Ee][Mm][Aa][Ll][Ee]$ ]]; then
break
else
echo "INVALID GENDER. PLEASE ENTER 'MALE' or 'FEMALE'."
fi
done
while true; do
read -p "Enter the new location of the employee (Press Enter to leave unchanged): " new_empLoc
if [[ -z $new_empLoc || -n $new_empLoc ]]; then
break
else
echo "EMPLOYEE LOCATION CANNOT BE EMPTY."
fi
done
while true; do
read -p "Enter the new phone number of the employee (Press Enter to leave unchanged): " new_empPhn
if [[ -z $new_empPhn || "$new_empPhn" =~ ^[0-9]{10}$ ]]; then
break
else
echo "INVALID PHONE NUMBER. PLEASE ENTER A 10-digit NUMERIC VALUE."
fi
done
while true; do
read -p "Enter the new email address of the employee (Press Enter to leave unchanged): " new_empMail
if [[ -z $new_empMail || "$new_empMail" =~ ^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$ ]]; then
break
else
echo "INVALID Email ADDRESS FORMAT. PLEASE ENTER A VALID Email ADDRESS."
fi
done
while true; do
read -p "Enter the new education qualification of the employee (Press Enter to leave unchanged): " new_empEdu
if [[ -z $new_empEdu || -n $new_empEdu ]]; then
break
else
echo "EDUCATION QUALIFICATION CANNOT BE EMPTY."
fi
done
while true; do
read -p "Enter the new designation of the employee (Press Enter to leave unchanged): " new_empRole
if [[ -z $new_empRole || -n $new_empRole ]]; then
break
else
echo "EMPLOYEE DESIGNATION CANNOT BE EMPTY."
fi
done
while true; do
read -p "Enter the new salary of the employee (Press Enter to leave unchanged): " new_empSal
if [[ -z $new_empSal || "$new_empSal" =~ ^[1-9][0-9]*$ ]]; then
break
else
echo "INVALID SALARY. PLEASE ENTER A POSTIVE NUMERIC VALUE."
fi
done
new_empName=${new_empName:-$empName}
new_empGen=${new_empGen:-$empGen}
new_empLoc=${new_empLoc:-$empLoc}
new_empPhn=${new_empPhn:-$empPhn}
new_empMail=${new_empMail:-$empMail}
new_empEdu=${new_empEdu:-$empEdu}
new_empRole=${new_empRole:-$empRole}
new_empSal=${new_empSal:-$empSal}
sqlite3 "$database_file" <<EOF
UPDATE employees
SET Name = '$new_empName', Gender = '$new_empGen', Location = '$new_empLoc',
Phone = '$new_empPhn', Email = '$new_empMail', Education = '$new_empEdu',
Designation = '$new_empRole', Salary = $new_empSal
WHERE ID = $empID;
EOF
echo
sleep 2
echo "UPDATING..."
echo
sleep 2
echo "Employee with ID $empID updated successfully."
echo
sleep 0.5
echo "Updated Employee Details:"
echo "Employee name is: $new_empName"
echo "Employee gender is: $new_empGen"
echo "Employee location is: $new_empLoc"
echo "Employee phone number is: $new_empPhn"
echo "Employee email address is: $new_empMail"
echo "Employee education qualification is: $new_empEdu"
echo "Employee designation is: $new_empRole"
echo "Employee salary is: $new_empSal"
else
echo
sleep 1
echo "Employee with ID $empID not found."
fi
else
echo
sleep 1
echo "No employee details found."
fi
}
function delete_employee() {
read -p "Enter the ID of the employee to delete: " empID
sqlite3 "$database_file" <<EOF
SELECT * FROM employees WHERE ID = $empID;
EOF
if [ $? -eq 0 ]; then
echo
echo "DELETING..."
echo
sleep 2
sqlite3 "$database_file" <<EOF
DELETE FROM employees WHERE ID = $empID;
EOF
echo "Employee with ID $empID deleted successfully."
else
echo "Employee with ID $empID not found."
fi
}
function logout() {
echo
echo "LOGGING OUT..."
echo
sleep 2
logged_in=false
echo "Logged Out Successfully."
echo
}
create_tables
while true; do
if [ "$logged_in" = false ]; then
echo
sleep 1.5
echo "---------------------------"
echo -e "EMPLOYEE MANAGEMENT SYSTEM\n1. Login\n2. Exit"
echo "---------------------------"
read -p "Enter your choice: " login_choice
echo "---------------------------"
case "$login_choice" in
1)
echo "Login to Continue"
read -p "Enter Username: " username
read -sp "Enter Password: " pwd
echo
if [ "$username" = "admin" ] && [ "$pwd" = "dbadmin" ]; then
echo "----------------------------"
echo "LOGGING IN..."
echo
sleep 2
echo "WELCOME TO EMPLOYEE MANAGEMENT SYSTEM"
logged_in=true
else
echo "Please enter correct Username/Password"
fi
;;
2)
sleep 2
echo
echo "Exiting Employee Management System...."
sleep 2
echo "Exited."
exit
;;
*)
echo "Invalid choice. Please enter 1 to login or 2 to exit."
;;
esac
fi
if [ "$logged_in" = true ]; then
echo "----------------------------"
echo -e "1. Add Employee details\n2. View Employee details\n3. Update Employee details\n4. Delete Employee details\n5. LogOut\n6. Exit"
echo "----------------------------"
read -p "Enter your choice: " num
echo "----------------------------"
case "$num" in
1)
sleep 1
echo "Add Employee details"
add_employee
;;
2)
sleep 1
echo "View Employee details"
view_employee
;;
3)
sleep 1
echo "Update Employee details"
update_employee
;;
4)
sleep 1
echo "Delete Employee details"
delete_employee
;;
5)
sleep 1
logout
;;
6)
sleep 2
echo
echo "Exiting Employee Management System...."
echo
sleep 2
echo "Exited."
exit
;;
*)
echo "Invalid choice. Please enter a valid option (1-4)."
;;
esac
fi
done