-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMS.py
122 lines (101 loc) · 3.77 KB
/
CMS.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
#All Global Variables
class Customer:
list_cus=[]#Static Member it has only one memory blocks.
def __init__(self):
self.id=0
self.name=""
self.address=""
self.mobile_no=""
self.age=0
def __str__(self):
return "Id:{0},Name:{1},'Address:{2},Mobile No:{3},Age:{4}".format(self.id,self.name,self.address,self.mobile_no,self.age)
def add_customer(self):
Customer.list_cus.append(self)
def search_customer(self,cus_id):
for e in Customer.list_cus:
if e.id==cus_id:
self.id=e.id
self.name=e.name
self.address=e.address
self.mobile_no=e.mobile_no
self.age=e.age
return True
return False
# BLL Code Start from Here
def delete_customer(self,cus_id):
for i in range(len(Customer.list_cus)):
if Customer.list_cus[i].id==cus_id:
Customer.list_cus.pop(i)
return True
return False
def update_customer(self,cus_id):
for e in Customer.list_cus:
if e.id==cus_id:
e.id=self.id
e.name=self.name
e.address=self.address
e.mobile_no=self.mobile_no
e.age=self.age
return True
return False
# BLL Code Ends Here
# PL Code Start from Here
def show_all_customer():
for cus in Customer.list_cus:
details="Id:{0},Name:{1},address:{2},mobile no:{3},age:{4}".format(cus.id,cus.name,cus.address,cus.mobile_no,cus.age)
print(details)
# def show_all_customer():
# for i in range(len(Customer.list_cus)):
# details="Id:{0},Name:{1},address:{2},mobile no:{3},age:{4}".format(list_cus[i].id,list_cus[i].name,list_cus[i].address,list_cus[i].mobile_no,list_cus[i].age)
# print(details)
while(True):
print('1.Add Customer.\n2.Search Customer.\n3.Modify Customer.\n4.Delete Customer.\n5.Show All Customer.\n0.Exit')
ch=input('Enter Your Choice')
if ch=='1':
cus=Customer()
cus.id=int(input('Enter id'))
cus.name=input('Enter Name')
cus.address=input('Enter Address')
cus.mobile_no=input('Enter Mobile No')
cus.age=int(input('Enter Age'))
cus.add_customer()
print('Customer Added Sucessfully')
#Write code to add a customer
elif ch=='2':
cus=Customer()
cus_id=int(input('Enter ID'))
check=cus.search_customer(cus_id)
if(check==False):
print("Id Not Found")
else:
print("Id",cus.id,"Name",cus.name,"Address",cus.address,"Mobile No",cus.mobile_no,"Age",cus.age)
#Write code to Search a customer
elif ch=='3':
cus=Customer()
cus.id=int(input('Enter ID for update'))
cus.name=input('Enter Name for Update')
cus.address=input('Enter Address for Update')
cus.mobile_no=input('Enter Mobile No for Update')
cus.age=input('Enter Age for Update')
check=cus.update_customer(cus.id)
if(check==False):
print("Id Not Found")
else:
print('Customer Updated Successfully')
#Write code to Modify a customer
elif ch=='4':
id=int(input('Enter ID'))
cus=Customer()
check=cus.delete_customer(id)
if(check==False):
print("Id Not Found")
else:
print('Customer Deeted Sucessfully')
#Write code to Delete a customer
elif ch=='5':
show_all_customer()
#Write code to Show All a customer
elif ch=='0':
break
#Write code to Exit
# PL Code Ends Here