Skip to content

Commit da92cf4

Browse files
committed
Completed editemployee file
1 parent d778cbd commit da92cf4

File tree

5 files changed

+268
-40
lines changed

5 files changed

+268
-40
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
__pycache__/
22
firsttime.txt
33
cred.dat
4-
links.txt
4+
links.txt
5+
tempCodeRunnerFile.py

adminpanel.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import hireemployee
22
import fireemployee
3-
4-
def ap3():
5-
print("ap3")
3+
import editemployee
64

75
def ap():
86
print("\nWelcome Admin!!")
@@ -19,7 +17,7 @@ def ap():
1917
elif a=='2':
2018
fireemployee.ap2()
2119
elif a=='3':
22-
ap3()
20+
editemployee.ap3()
2321
elif a=='0':
2422
print("Quit Admin Panel.")
2523
break

editemployee.py

Lines changed: 244 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,31 @@
11
import mysql.connector
22
import pickle
3+
from datetime import date
34

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()
5+
def age(birthdate):
6+
today = date.today()
7+
age = today.year - birthdate.year - ((today.month, today.day) < (birthdate.month, birthdate.day))
8+
return age
119

10+
cur=None
11+
conn=None
12+
emp_no=0
13+
hire_date=None
14+
birth_date=None
1215
def ap3():
16+
global cur
17+
global conn
18+
cred = open("cred.dat","rb")
19+
dat=pickle.load(cred)
20+
cred.close()
21+
Passwo=dat[0]
22+
Databa=dat[1]
23+
conn=mysql.connector.connect(host="localhost",user="root",password=Passwo,database=Databa)
24+
cur=conn.cursor()
25+
26+
global emp_no
27+
global birth_date
28+
global hire_date
1329
print("---------Edit employee process----------\n")
1430
while True:
1531
emp_no=input(("Enter emp_no of the employee to edit the details: "))
@@ -26,17 +42,229 @@ def ap3():
2642
cur.execute("select * from employees where emp_no={}".format(emp_no))
2743
results=cur.fetchall()
2844
if results == []:
45+
print(results)
2946
print("That employee number does not exist.")
3047
else:
31-
print(results)
32-
ap3()
48+
results1=results[0]
49+
print("1.emp_no:",results1[0])
50+
print("2.birth_date:",results1[1])
51+
print("3.first_name:",results1[2])
52+
print("4.last-name:",results1[3])
53+
print("5.gender:",results1[4])
54+
print("6.hire_date:",results1[5])
55+
birth_date=results1[1]
56+
hire_date=results1[5]
57+
f2()
3358

3459
def f2():
35-
print("1.emp_no")
36-
print("2.birth_date")
37-
print("3.first_name")
38-
print("4.last-name")
39-
print("5.gender")
40-
print("6.hire_date")
60+
global emp_no
61+
global birth_date
62+
global hire_date
4163
print("0 to quit.")
42-
a=input("What would you like to change from the above:")
64+
a=input("What would you like to change from the above:")
65+
if a == '1':
66+
while True:
67+
en=input("Enter emp_no (max 5 int): ")
68+
if len(en) <= 5:
69+
try:
70+
en=int(en)
71+
print("Done OK")
72+
except ValueError:
73+
print("emp_no should be an integer!!")
74+
else:
75+
try:
76+
cur.execute("update employees set emp_no={} where emp_no={}".format(en,emp_no))
77+
conn.commit()
78+
except mysql.connector.Error as err:
79+
print(err.msg)
80+
print("-----------Value addition was unsuccessful!!!!-------------")
81+
else:
82+
print("Updated employee number...")
83+
break
84+
else:
85+
print("Maximum length is 5!")
86+
if a == '2':
87+
while True:
88+
while True:
89+
year=input("Enter birth year (4 int): ")
90+
if len(year) == 4:
91+
try:
92+
year=int(year)
93+
print("Done OK")
94+
except ValueError:
95+
print("year should be an integer!!")
96+
else:
97+
break
98+
else:
99+
print("Year consists of 4 integers!!")
100+
101+
while True:
102+
month=input("Enter birth month (2 int) (01 to 12): ")
103+
if len(month) == 2:
104+
try:
105+
month=int(month)
106+
print("Done OK")
107+
except ValueError:
108+
print("month should be an integer!!")
109+
else:
110+
break
111+
else:
112+
print("Month consists of 2 integers!!")
113+
114+
while True:
115+
day=input("Enter birth day (2 int) : ")
116+
if len(day) == 2:
117+
try:
118+
day=int(day)
119+
print("Done OK")
120+
except ValueError:
121+
print("Date should be an integer!!")
122+
else:
123+
break
124+
else:
125+
print("Date consists of 2 integers!!")
126+
127+
try:
128+
birth_date=date(year,month,day)
129+
except ValueError:
130+
import traceback
131+
traceback.print_exc()
132+
else:
133+
if age(birth_date)>=20:
134+
if age(birth_date)-age(hire_date)>=20:
135+
try:
136+
cur.execute("update employees set birth_date='{}' where emp_no={}".format(birth_date,emp_no))
137+
conn.commit()
138+
except mysql.connector.Error as err:
139+
print(err.msg)
140+
print("-----------Value addition was unsuccessful!!!!-------------")
141+
break
142+
else:
143+
print("Updated birth date...")
144+
break
145+
else:
146+
print("Employee must be atleast 20 years of age when hired!!")
147+
print(birth_date,": birth_date")
148+
print(hire_date,":hire date you entered")
149+
else:
150+
print("Employee must be atleast 20 years of age!!")
151+
if a == '3':
152+
while True:
153+
first_name=input("Enter first name (max 15 char): ")
154+
if len(first_name)<= 15:
155+
try:
156+
cur.execute("update employees set first_name={} where emp_no={}".format(first_name,emp_no))
157+
conn.commit()
158+
except mysql.connector.Error as err:
159+
print(err.msg)
160+
print("-----------Value addition was unsuccessful!!!!-------------")
161+
break
162+
else:
163+
print("Updated first name...")
164+
break
165+
else:
166+
print("Max 15 characters")
167+
168+
if a == '4':
169+
while True:
170+
last_name=input("Enter last name (max 15 char): ")
171+
if len(last_name)<= 15:
172+
try:
173+
cur.execute("update employees set last_name={} where emp_no={}".format(last_name,emp_no))
174+
conn.commit()
175+
except mysql.connector.Error as err:
176+
print(err.msg)
177+
print("-----------Value addition was unsuccessful!!!!-------------")
178+
break
179+
else:
180+
print("Updated last name...")
181+
break
182+
else:
183+
print("Max 15 characters")
184+
if a == '5':
185+
while True:
186+
print("1.Male")
187+
print("2.Female")
188+
a=input("Enter choice (1 or 2):")
189+
if a== '1':
190+
try:
191+
cur.execute("update employees set gender='M' where emp_no={}".format(emp_no))
192+
conn.commit()
193+
except mysql.connector.Error as err:
194+
print(err.msg)
195+
print("-----------Value addition was unsuccessful!!!!-------------")
196+
break
197+
else:
198+
print("Updated first name...")
199+
break
200+
201+
elif a=='2':
202+
gender='F'
203+
try:
204+
cur.execute("update employees set gender='F' where emp_no={}".format(emp_no))
205+
conn.commit()
206+
except mysql.connector.Error as err:
207+
print(err.msg)
208+
print("-----------Value addition was unsuccessful!!!!-------------")
209+
break
210+
else:
211+
print("Updated first name...")
212+
break
213+
214+
else:
215+
print("Wrong input!!")
216+
217+
if a == '6':
218+
while True:
219+
while True:
220+
hyear=input("Enter hire year (4 int): ")
221+
if len(hyear) == 4:
222+
try:
223+
hyear=int(hyear)
224+
print("Done OK")
225+
except ValueError:
226+
print("year should be an integer!!")
227+
else:
228+
break
229+
else:
230+
print("Year consists of 4 integers!!")
231+
232+
while True:
233+
hmonth=input("Enter hire month (2 int) (01 to 12): ")
234+
if len(hmonth) == 2:
235+
try:
236+
hmonth=int(hmonth)
237+
print("Done OK")
238+
except ValueError:
239+
print("month should be an integer!!")
240+
else:
241+
break
242+
else:
243+
print("Month consists of 2 integers!!")
244+
245+
while True:
246+
hday=input("Enter hire day (2 int) (01 to 31): ")
247+
if len(hday) == 2:
248+
try:
249+
hday=int(hday)
250+
print("Done OK")
251+
except ValueError:
252+
print("Date should be an integer!!")
253+
else:
254+
break
255+
else:
256+
print("Date consists of 2 integers!!")
257+
258+
try:
259+
hire_date=date(hyear,hmonth,hday)
260+
except ValueError:
261+
import traceback
262+
traceback.print_exc()
263+
else:
264+
if age(birth_date)-age(hire_date)>=20:
265+
break
266+
else:
267+
print("Employee must atleast be 20 years of age!!")
268+
269+
cur.close()
270+
conn.close()

fireemployee.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
import mysql.connector
22
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-
123
def ap2():
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()
1311
print("---------Fire employee process----------\n")
1412
while True:
1513
emp_no=input(("Enter emp_no of the employee to fire them: "))
@@ -41,4 +39,6 @@ def ap2():
4139
print("Employee fired successfully...\n")
4240
if not changed:
4341
print("The employee number does not exist.")
44-
print("------------Could not fire employee-----------\n")
42+
print("------------Could not fire employee-----------\n")
43+
cur.close()
44+
conn.close()

hireemployee.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,14 @@ def age(birthdate):
77
age = today.year - birthdate.year - ((today.month, today.day) < (birthdate.month, birthdate.day))
88
return age
99

10-
cred = open("cred.dat","rb")
11-
dat=pickle.load(cred)
12-
cred.close()
13-
Passwo=dat[0]
14-
Databa=dat[1]
15-
query=mysql.connector.connect(host="localhost",user="root",password=Passwo,database=Databa)
16-
cur=query.cursor()
17-
1810
def ap1():
11+
cred = open("cred.dat","rb")
12+
dat=pickle.load(cred)
13+
cred.close()
14+
Passwo=dat[0]
15+
Databa=dat[1]
16+
query=mysql.connector.connect(host="localhost",user="root",password=Passwo,database=Databa)
17+
cur=query.cursor()
1918
print("-------------Hire Employee Process-------------")
2019

2120
#Employee number
@@ -175,4 +174,6 @@ def ap1():
175174
print(err.msg)
176175
print("-----------Value addition was unsuccessful!!!!-------------")
177176
else:
178-
print("Values added successfully!!")
177+
print("Values added successfully!!")
178+
cur.close()
179+
query.close()

0 commit comments

Comments
 (0)