-
Notifications
You must be signed in to change notification settings - Fork 0
/
EMS.py
269 lines (244 loc) · 9.91 KB
/
EMS.py
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
import csv
import os
from tempfile import NamedTemporaryFile
from tabulate import tabulate
def logo():
print("""
==================================
EMPLOYEE MANAGEMENT SYSTEM
==================================
""")
def login_menu():
os.system("cls")
while True:
try:
logo()
print("""
********* LOGIN MENU **********
_______________________________
| |
|_______ 1) Login ______________|
| |
|_______ 2) Exit _______________|
| |
|_______________________________|
""")
choice0 = int(input("\n\n\t\t\tSelect any option: "))
if choice0 == 1:
login()
break
elif choice0 == 2:
os._exit(0)
else:
print("\n\n\t\t\tInvalid Input! Please Try Again.\n\n")
os.system("pause")
login_menu()
except ValueError:
print("\n\n\t\t\tInvalid Input! Please Try Again.\n\n")
os.system("pause")
login_menu()
def menu():
os.system("cls")
while True:
try:
print(
"""
*********** MAIN MENU ************
________________________________
| |
|____ 1) View Employees List ____|
| |
|____ 2) Edit Employees List ____|
| |
|____ 3) Search Record __________|
| |
|____ 4) Exit __________________ |
| |
|________________________________|
""")
choice1 = int(input("\n\n\t\t\tEnter your choice: "))
if choice1 == 1:
display()
os.system("pause")
menu()
break
elif choice1 == 2:
edit()
break
elif choice1 == 3:
os.system("cls")
search()
break
elif choice1 == 4:
return login_menu()
else:
print("\n\n\t\t\tInvalid Input! Please Try Again.\n\n")
os.system("pause")
menu()
except ValueError:
print("\n\n\t\t\tInvalid Input! Please Try Again.\n\n")
os.system("pause")
menu()
def display():
os.system("cls")
try:
with open('employees.csv', 'r') as file:
array = file.readlines()
array = [row.split(',') for row in array]
print(tabulate(array, headers="firstrow", tablefmt='fancy_grid'))
except FileNotFoundError:
print("\nFile Not Found!!")
def edit():
os.system("cls")
while True:
try:
print("""
**** EDIT EMPLOYEE LIST ****
__________________________
| |
|______ 1) Add ____________|
| |
|______ 2) Modify _________|
| |
|______ 3) Remove _________|
| |
|______ 4) Main Menu ______|
| |
|__________________________|
""")
choice2 = int(input("\n\n\t\t\tSelect any option: "))
if choice2 == 1:
add()
break
elif choice2 == 2:
modify()
break
elif choice2 == 3:
remove()
break
elif choice2 == 4:
return menu()
else:
print("\n\n\t\t\tInvalid Input! Please Try Again.\n\n")
os.system("pause")
edit()
except ValueError:
print("\n\n\t\t\tInvalid Input! Please Try Again.\n\n")
os.system("pause")
edit()
def add():
os.system("cls")
try:
file = open("employees.csv", "r")
file.close()
except FileNotFoundError:
header = ['Employee ID', 'First Name', 'Last Name', 'Age', 'Salary', 'Phone NO', 'Address']
with open('employees.csv', 'w', newline="") as file:
csvwriter = csv.writer(file)
csvwriter.writerow(header)
print("\n\t\t *** Add Employee Details ***\n")
empId = input("\n\t\tEmployee ID: ")
with open("employees.csv", "r") as csvfile:
csvreader = csv.DictReader(csvfile)
for row in csvreader:
if row["Employee ID"] == empId:
print("\n\t\tThis Employee ID already in use!\n")
os.system("pause")
edit()
else:
with open("employees.csv", "a", newline="") as file:
w = csv.writer(file)
ans = 'Y'
while ans.lower() == 'y':
fName = input("\n\t\tFirst Name: ")
lName = input("\n\t\tLast Name: ")
age = input("\n\t\tAge: ")
salary = input("\n\t\tSalary: ")
phoneNo = input("\n\t\tPhone NO: ")
address = input("\n\t\tAddress: ")
w.writerow([empId, fName, lName, age, salary, phoneNo, address])
print("\n\t\tRecord Added!!")
ans = input("\nDo you want add more employee?\nEnter[Y/N]: ")
os.system("cls")
edit()
def modify():
os.system("cls")
display()
tempfile = NamedTemporaryFile(mode='w', delete=False)
fields = ['Employee ID', 'First Name', 'Last Name', 'Age', 'Salary', 'Phone NO', 'Address']
with open("employees.csv", 'r') as csvfile, tempfile:
reader = csv.DictReader(csvfile, fieldnames=fields)
writer = csv.DictWriter(tempfile, fieldnames=fields)
emp_id = input("\n\tEnter Employee ID: ")
for row in reader:
if row['Employee ID'] == str(emp_id):
os.system("cls")
print("\n\t\t *** Enter New Details for Employee ID:", row['Employee ID'], "***")
fName = input("\n\t\tFirst Name: ")
lName = input("\n\t\tLast Name: ")
age = input("\n\t\tAge: ")
salary = input("\n\t\tSalary: ")
phoneNo = input("\n\t\tPhone NO: ")
address = input("\n\t\tAddress: ")
row['First Name'], row['Last Name'], row['Age'], row['Salary'], row['Phone NO'], row[
'Address'] = fName, lName, age, salary, phoneNo, address
row = {'Employee ID': row['Employee ID'], 'First Name': row['First Name'], 'Last Name': row['Last Name'],
'Age': row['Age'], 'Salary': row['Salary'], 'Phone NO': row['Phone NO'], 'Address': row['Address']}
writer.writerow(row)
with open(tempfile.name, newline='') as in_file:
with open("employees.csv", 'w', newline='') as out_file:
writer = csv.writer(out_file)
for row in csv.reader(in_file):
if row:
writer.writerow(row)
print("\n\t\tRecord Updated!!\n\n")
os.system("pause")
edit()
def remove():
os.system("cls")
display()
tempfile = NamedTemporaryFile(mode='w', delete=False)
fields = ['Employee ID', 'First Name', 'Last Name', 'Age', 'Salary', 'Phone NO', 'Address']
with open("employees.csv", 'r') as csvfile, tempfile:
reader = csv.DictReader(csvfile, fieldnames=fields)
writer = csv.DictWriter(tempfile, fieldnames=fields)
emp_id = input("\n\tEnter Employee ID: ")
for row in reader:
if row['Employee ID'] != str(emp_id):
writer.writerow(row)
with open(tempfile.name, newline='') as in_file:
with open("employees.csv", 'w', newline='') as out_file:
writer = csv.writer(out_file)
for row in csv.reader(in_file):
if row:
writer.writerow(row)
print("\n\tRecord Removed!!\n\n")
os.system("pause")
edit()
def search():
print("\n*** Search Record in Employees List ***\n")
keyword = input("Enter any detail of the employee to search: ")
fields = ['Employee ID', 'First Name', 'Last Name', 'Age', 'Salary', 'Phone NO', 'Address']
with open("employees.csv", 'r') as csvfile:
reader = csv.DictReader(csvfile, fieldnames=fields)
for row in reader:
if row['Employee ID'] == str(keyword) or row['First Name'] == str(keyword) or row['Last Name'] == str(keyword) or row['Age'] == str(keyword) or row['Salary'] == str(keyword) or row['Phone NO'] == str(keyword) or row['Address'] == str(keyword):
print("\n")
print(tabulate(row.items(), headers="firstrow", tablefmt='fancy_grid'))
print("\n\n")
os.system("pause")
menu()
def login():
password = "urssanjaysingh"
while True:
passw = input("\n\n\t\t\tEnter the password to login: ")
if passw == password:
menu()
else:
print("\n\n\t\t\tWrong Password! Please Try Again.\n\n");
os.system("pause")
login_menu()
def main():
os.system("cls")
login_menu()
main()