Skip to content

Commit c18b1a9

Browse files
committed
Added fire employee process...
1 parent 1440857 commit c18b1a9

File tree

2 files changed

+50
-6
lines changed

2 files changed

+50
-6
lines changed

fireemployee.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import mysql.connector
2+
import pickle
3+
4+
cred = open("cred.dat","rb")
5+
dat=pickle.load(cred)
6+
cred.close()
7+
Passwo=dat[0]
8+
Databa=dat[1]
9+
conn=mysql.connector.connect(host="localhost",user="root",password=Passwo,database=Databa)
10+
cur=conn.cursor()
11+
12+
def ap2():
13+
print("---------Fire employee process----------\n")
14+
while True:
15+
emp_no=input(("Enter emp_no of the employee to fire them: "))
16+
if len(emp_no) <= 5:
17+
try:
18+
emp_no=int(emp_no)
19+
print("Checking...")
20+
except ValueError:
21+
print("emp_no should be an integer!!")
22+
else:
23+
break
24+
else:
25+
print("Maximum length is 5!")
26+
27+
query="delete from employees where emp_no = {}".format(emp_no)
28+
cur.execute("select emp_no from employees")
29+
record=cur.fetchall()
30+
changed=False
31+
for r in record:
32+
if r[0]==emp_no:
33+
try:
34+
cur.execute(query)
35+
conn.commit()
36+
changed=True
37+
except mysql.connector.Error as err:
38+
print(err.msg)
39+
print("-----------Value addition was unsuccessful!!!!-------------\n")
40+
else:
41+
print("Employee fired successfully...\n")
42+
if not changed:
43+
print("The employee number does not exist.")
44+
print("------------Could not fire employee-----------\n")

hireemployee.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,14 @@ def ap1():
8484
print("Employee must be atleast 20 years of age!!")
8585
#Employee name
8686
while True:
87-
first_name=input("Enter first name (max 15 char)")
87+
first_name=input("Enter first name (max 15 char): ")
8888
if len(first_name)<= 15:
8989
break
9090
else:
9191
print("Max 15 characters")
9292

9393
while True:
94-
last_name=input("Enter last name (max 15 char)")
94+
last_name=input("Enter last name (max 15 char): ")
9595
if len(last_name)<= 15:
9696
break
9797
else:
@@ -171,9 +171,9 @@ def ap1():
171171
try:
172172
cur.execute(add_employee, data_employee)
173173
query.commit()
174-
cur.close()
175-
query.close()
176174
except mysql.connector.Error as err:
177-
print(err.msg())
175+
print(err.msg)
176+
print("-----------Value addition was unsuccessful!!!!-------------")
178177
else:
179-
print("Values added successfully!!")
178+
print("Values added successfully!!")
179+
ap1()

0 commit comments

Comments
 (0)