-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEmployee.py
208 lines (166 loc) · 5.29 KB
/
Employee.py
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#*******************************************PYTHON PROJECT ON EMPLOYEE DATABASE********************************************************************
print('\t\t\t\t\t\t\tWELCOME TO THE DATABASE')
print('********************************************************************************************************************************************')
def Menu():
print('\n')
print('\t\t\t\tMAIN MENU')
print('1.Create Record')
print('2.Enter New Record')
print('3.Display Record')
print('4.Search Record')
print('5.Update Record')
print('6.Delete Record')
print('7.Exit')
Menu()
import pickle,os,sys
#*********************************************Consent Of The User***********************************************************************************
def Consent():
k=input('Want To Continue Working With File(Y/y):')
if k in 'Yy':
Choice()
else:
print('Thanks For Working')
sys.exit()
#*********************************Creating the Database and Entering the 1st Record*******************************************************************
def Create():
f=open('Employee.dat','wb')
a=int(input('Enter Employee ID:'))
b=input('Enter name:')
c=input('Enter Department:')
d=input('Enter Designation:')
L=[a,b,c,d]
pickle.dump(L,f)
print('Database Created Successfully and Written The Record')
f.close()
Consent()
#*******************************Entering Record To The Database*****************************************************************************************
def Append():
f=open('Employee.dat','ab')
while True:
a=int(input('Enter Employee ID:'))
b=input('Enter name:')
c=input('Enter Department:')
d=input('Enter Designation:')
L=[a,b,c,d]
pickle.dump(L,f)
print('Data Entered Successfully')
v=input('Want to input more data(Y/N):')
if v in 'Yy':
continue
else:
break
f.close()
Consent()
#******************************Displaying Record To User******************************************************************************************************
def Display():
try:
f=open('Employee.dat','rb')
except:
print('File not found')
return
try:
while True:
r=pickle.load(f)
print(r)
except:
f.close()
Consent()
#****************************Searching A Particular Record*****************************************************************************************************
def Search():
try:
f=open('Employee.dat','rb')
except:
print('File not Found')
return
try:
x=int(input('Enter Employee ID To Search:'))
fl=0
while True:
r=pickle.load(f)
if r[0]==x:
fl=1
print(r)
break
except:
pass
f.close()
if fl==0:
print('Record Not Found')
Consent()
#*********************************Modifying a Record***********************************************************************************************************
def Modify():
try:
f=open('Employee.dat','rb+')
except:
print('File not found')
return
x=int(input('Employee ID for modifying:'))
p,fl=0,0
try:
while True:
r=pickle.load(f)
if r[0]==x:
print('Enter the previous data if no change in the respective field')
r[1]=input(' Enter Name:')
r[2]=input('Enter Department:')
r[3]=input('Enter Designation:')
f.seek(p)
pickle.dump(r,f)
print('Record updated')
fl=1
p=f.tell()
except:
f.close()
if fl==0:
print('Record not found')
Consent()
#********************************Deleting A Particular Record*************************************************************************************************
def Delete():
try:
f=open('Employee.dat','rb')
except:
print('No file')
return
f1=open('New.dat','wb')
x=int(input('Enter EmpID to delete:'))
fl=0
try:
while True:
r=pickle.load(f)
if r[0]==x:
fl=1
continue
pickle.dump(r,f1)
except:
f.close()
f1.close()
os.remove('Employee.dat')
os.rename('New.dat','Employee.dat')
if fl==0:
print('Record not found')
else:
print('Record Deleted')
Consent()
#**************************Choices For The User*****************************************************************************************************************
def Choice():
ch=int(input('Enter your choice between 1 to 7:'))
if ch==1:
Create()
elif ch==2:
Append()
elif ch==3:
Display()
elif ch==4:
Search()
elif ch==5:
Modify()
elif ch==6:
Delete()
elif ch==7:
print('Thank You')
sys.exit()
else:
print('Invalid Input')
sys.exit()
Choice()
#*************************************************************************END OF PROJECT***************************************************************************