Employ Management System
Employ Management System
# Salary Information
basic_salary = input("Enter Basic Salary: ")
allowances = input("Enter Allowances: ")
deductions = input("Enter Deductions: ")
bonus = input("Enter Bonus (0 if no bonus): ")
# Step 1: Read the original CSV and write updates to the temporary file
with open(file_name, mode='r', newline='') as file, open(temp_file, mode='w', newline='') as
temp:
reader = csv.reader(file)
writer = csv.writer(temp)
# Function to read data from a CSV file and return it as a list of dictionaries
def read_csv(file_name):
with open(file_name, mode='r', newline='') as file:
reader = csv.DictReader(file)
return list(reader)
# Function to view all employees with details from all three CSV files
def view_all_employees():
# Read data from all files
employees = read_csv('D:\Computer sc\employees.csv')
departments = read_csv('D:\Computer sc\departments.csv')
salaries = read_csv('D:\Computer sc\salaries.csv')
# Merge employees.csv
for emp in employees:
emp_id = emp['Employee ID']
all_details[emp_id] = {
'Employee ID': emp_id,
'Name': emp['Name'],
'Age': emp['Age'],
'Address': emp['Address'],
'Phone': emp['Contact Number'],
'Email': emp['Email']
}
# Merge departments.csv
for dept in departments:
emp_id = dept['Employee ID']
if emp_id in all_details:
all_details[emp_id].update({
'Department ID': dept['Department ID'],
'Department Name': dept['Department Name'],
'Manager': dept['Manager']
})
# Merge salaries.csv
for salary in salaries:
emp_id = salary['Employee ID']
if emp_id in all_details:
all_details[emp_id].update({
'Basic Salary': salary['Basic Salary'],
'Allowances': salary['Allowances'],
'Deductions': salary['Deductions'],
'Bonus': salary['Bonus']
})
# Step 1: Read the original file and write non-deleted rows to the temporary file
with open(file_name, mode='r', newline='') as file, open(temp_file, mode='w', newline='') as
temp:
reader = csv.reader(file)
writer = csv.writer(temp)
# Search for the department and salary information using the same Employee ID
department = next((dept for dept in departments if dept['Employee ID'] == emp_id), None)
salary = next((sal for sal in salaries if sal['Employee ID'] == emp_id), None)
if department:
print(f"Department ID: {department['Department ID']}")
print(f"Department Name: {department['Department Name']}")
print(f"Manager: {department['Manager']}")
else:
print("No department information found.")
if salary:
print(f"Basic Salary: {salary['Basic Salary']}")
print(f"Allowances: {salary['Allowances']}")
print(f"Deductions: {salary['Deductions']}")
print(f"Bonus: {salary['Bonus']}")
else:
print("No salary information found.")
print("-" * 40)
if not dept_employees:
print(f"No employees found in Department ID {dept_id}.")
return
if employee:
print(f"\nEmployee ID: {employee['Employee ID']}")
print(f"Name: {employee['Name']}")
print(f"Age: {employee['Age']}")
print(f"Address: {employee['Address']}")
print(f"Phone: {employee['Contact Number']}")
print(f"Email: {employee['Email']}")
print(f"Department Name: {dept['Department Name']}")
print(f"Manager: {dept['Manager']}")
print("-" * 40)
else:
print(f"Details for Employee ID {emp_id} not found in employees.csv.")
# Read and store all data from employees.csv, departments.csv, and salaries.csv
with open(employees_file, mode='r', newline='') as emp_file, \
open(departments_file, mode='r', newline='') as dept_file, \
open(salaries_file, mode='r', newline='') as sal_file:
if not salaries:
print(f"No employees found with a bonus of {bonus_amount}.")
return
if employee:
print(f"\nEmployee ID: {employee['Employee ID']}")
print(f"Name: {employee['Name']}")
print(f"Age: {employee['Age']}")
print(f"Address: {employee['Address']}")
print(f"Phone: {employee['Phone']}")
print(f"Email: {employee['Email']}")
if department:
print(f"Department ID: {department['Department ID']}")
print(f"Department Name: {department['Department Name']}")
print(f"Manager: {department['Manager']}")
# Read and store all data from employees.csv, departments.csv, and salaries.csv
with open(employees_file, mode='r', newline='') as emp_file, \
open(departments_file, mode='r', newline='') as dept_file, \
open(salaries_file, mode='r', newline='') as sal_file:
# Read the salaries.csv and filter employees within the salary range
sal_reader = csv.DictReader(sal_file)
salaries = [sal for sal in sal_reader if min_salary <= float(sal['Basic Salary']) <= max_salary]
if not salaries:
print(f"No employees found with a salary between {min_salary} and {max_salary}.")
return
if employee:
print(f"\nEmployee ID: {employee['Employee ID']}")
print(f"Name: {employee['Name']}")
print(f"Age: {employee['Age']}")
print(f"Address: {employee['Address']}")
print(f"Phone: {employee['Contact Number']}")
print(f"Email: {employee['Email']}")
if department:
print(f"Department ID: {department['Department ID']}")
print(f"Department Name: {department['Department Name']}")
print(f"Manager: {department['Manager']}")
print(f"Basic Salary: {sal['Basic Salary']}")
print(f"Allowances: {sal['Allowances']}")
print(f"Deductions: {sal['Deductions']}")
print(f"Bonus: {sal['Bonus']}")
print("-" * 40)
else:
print(f"Details for Employee ID {emp_id} not found in employees.csv.")
if employee:
print(f"\nEmployee ID: {employee['Employee ID']}")
print(f"Name: {employee['Name']}")
print(f"Age: {employee['Age']}")
print(f"Address: {employee['Address']}")
print(f"Phone: {employee['Contact Number']}")
print(f"Email: {employee['Email']}")
print(f"Department ID: {dept['Department ID']}")
print(f"Department Name: {dept['Department Name']}")
print(f"Manager: {dept['Manager']}")
print("-" * 40)
else:
print(f"Details for Employee ID {emp_id} not found in employees.csv.")
return
#Main Program
Add Employee
Update employee
View All Employee
Search Employee by ID
Delete Employee