-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmployeeUpdate.py
More file actions
63 lines (56 loc) · 2.96 KB
/
EmployeeUpdate.py
File metadata and controls
63 lines (56 loc) · 2.96 KB
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
/*
====================================================================================================================
Update Employee Module: Key features
===================================================================================================================
1. Updates existing employee details using Employee ID
2. Reads all records from file using pickle.load()
3. Searches for matching ID using loop
4. Allows updating salary and company name
5. Applies name validation using custom validation module
6. Stores updated records in a list and rewrites file (wb mode)
7. Handles errors like invalid input, file not found, invalid names
8. Displays success message or "Employee not found" accordingly
====================================================================================================================
*/
import pickle
from NameValidException import ZeroNameLengthError, SpaceError, InvalidNameError
from NameValidateOperation import name_validate
def update_employee():
try:
with open("Employee.info", "rb") as ed:
emp_id = int(input("Enter employee id to update: "))
found = False
records = []
while True:
try:
record = pickle.load(ed)
if record["ID"] == emp_id:
print("-" * 80)
print(f"\tEmployee found with ID: \"{emp_id}\" And Employee Name: {record['Name']}")
print("-" * 80)
new_salary = float(input("Enter new employee salary: "))
new_company_name = input("Enter new employee company name: ")
new_company = name_validate(new_company_name)
record["Salary"] = new_salary
record["Company"] = new_company
found = True
records.append(record)
except EOFError:
break
if found:
with open("Employee.info", "wb") as ed:
for record in records:
pickle.dump(record, ed)
print("Employee record has been updated successfully.You must Verify the updated record by using view employee option.")
else:
print("Employee with the specified ID not found.")
except ValueError:
print("Don't Enter Alphanumeric, string, Symbols or special characters for Employee ID or Salary. Please try again.")
except FileNotFoundError:
print("File not found. Please Check the file name and try again.")
except ZeroNameLengthError:
print("You must fill Employee Name/Company Name... Try Again!")
except SpaceError:
print("Don't enter any space For Employee Name/Company Name.... Try Again!")
except InvalidNameError:
print("Invalid Employee Name/Company Name... Try Again!")