-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathemployee_management_system.py
More file actions
167 lines (116 loc) · 3.04 KB
/
Copy pathemployee_management_system.py
File metadata and controls
167 lines (116 loc) · 3.04 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
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
import sqlite3
# Database Connection
conn = sqlite3.connect("employees.db")
cursor = conn.cursor()
# Create Table
cursor.execute("""
CREATE TABLE IF NOT EXISTS employees (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
department TEXT NOT NULL,
salary REAL NOT NULL
)
""")
conn.commit()
# Add Employee
def add_employee():
name = input("Enter Name: ")
department = input("Enter Department: ")
salary = float(input("Enter Salary: "))
cursor.execute("""
INSERT INTO employees(name, department, salary)
VALUES (?, ?, ?)
""", (name, department, salary))
conn.commit()
print("Employee Added Successfully")
# View Employees
def view_employees():
cursor.execute("SELECT * FROM employees")
employees = cursor.fetchall()
print("\n===== Employee Records =====")
for emp in employees:
print(
f"ID: {emp[0]} | "
f"Name: {emp[1]} | "
f"Department: {emp[2]} | "
f"Salary: ₹{emp[3]}"
)
# Search Employee
def search_employee():
emp_id = int(input("Enter Employee ID: "))
cursor.execute(
"SELECT * FROM employees WHERE id=?",
(emp_id,)
)
emp = cursor.fetchone()
if emp:
print("\nEmployee Found")
print(emp)
else:
print("Employee Not Found")
# Update Employee Salary
def update_salary():
emp_id = int(input("Enter Employee ID: "))
new_salary = float(input("Enter New Salary: "))
cursor.execute("""
UPDATE employees
SET salary=?
WHERE id=?
""", (new_salary, emp_id))
conn.commit()
print("Salary Updated Successfully")
# Delete Employee
def delete_employee():
emp_id = int(input("Enter Employee ID: "))
cursor.execute(
"DELETE FROM employees WHERE id=?",
(emp_id,)
)
conn.commit()
print("Employee Deleted Successfully")
# Department Wise Report
def department_report():
cursor.execute("""
SELECT department,
COUNT(*),
AVG(salary)
FROM employees
GROUP BY department
""")
report = cursor.fetchall()
print("\n===== Department Report =====")
for dept in report:
print(
f"Department: {dept[0]}"
f" | Employees: {dept[1]}"
f" | Avg Salary: ₹{round(dept[2],2)}"
)
# Main Menu
while True:
print("\n===== Employee Management System =====")
print("1. Add Employee")
print("2. View Employees")
print("3. Search Employee")
print("4. Update Salary")
print("5. Delete Employee")
print("6. Department Report")
print("7. Exit")
choice = input("Enter Choice: ")
if choice == "1":
add_employee()
elif choice == "2":
view_employees()
elif choice == "3":
search_employee()
elif choice == "4":
update_salary()
elif choice == "5":
delete_employee()
elif choice == "6":
department_report()
elif choice == "7":
print("Exiting...")
break
else:
print("Invalid Choice")
conn.close()