-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomerManagement.py
More file actions
143 lines (123 loc) · 3.89 KB
/
Copy pathCustomerManagement.py
File metadata and controls
143 lines (123 loc) · 3.89 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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 9 17:29:57 2023
@author: vboxuser
"""
import mysql.connector as sqltor
import random
def InputID():
while True:
idn = input("Enter Customer ID : ")
if CheckID(idn):
return idn
else:
print("Customer ID can only contain numeric digits")
def CheckID(idn):
for e in idn:
if not ('0' <= e <= '9'):
return 0
return 1
def InputName():
while True:
name = input("Enter Name: ")
if CheckName(name):
return name
else:
print("Name Should only Contain Alphabets and Space, Enter again")
def CheckName(name):
for e in name:
if not (('a' <= e <= 'z') or ('A' <= e <= 'Z') or e == ' '):
return 0
return 1
def InputPhone():
while True:
phNum = input("Enter Phone Number: ")
if CheckPhone(phNum):
return phNum
else:
print("Phone Number should be of 10 digits and should only consists of numeric digits, Enter again")
def CheckPhone(num):
if str.len() != 10:
return 0
for e in num:
if not ('0' <= e <= '9'):
return 0
return 1
def ConnectServer():
mycon=sqltor.connect(host="localhost",user="root",passwd="changeme",database="sample")
if not mycon.is_connected():
print('Error connecting to MySQL database')
# else:
# print("Connected to MySQL server successfully, You can begin operation now ")
return mycon
# Before Unit Testing
# def AddCustomer():
# mycon = ConnectServer()
# cursor=mycon.cursor(buffered=True)
# print("----------Enter New Member Details----------")
# name = input("Enter Name: ")
# phNum = input("Enter Phone Number: ")
# custID = random.randint(100, 100000)
# comm = "INSERT INTO customer VALUES('{}','{}','{}');".format(name, phNum, custID)
# cursor.execute(comm)
# print("Customer ID = ", custID)
# mycon.commit()
# mycon.close()
# After Unit Testing and error correction
def AddCustomer():
mycon = ConnectServer()
cursor=mycon.cursor(buffered=True)
print("----------Enter New Member Details----------")
name = InputName()
phNum = InputPhone()
custID = random.randint(100, 100000)
comm = "INSERT INTO customer VALUES('{}','{}','{}');".format(name, phNum, custID)
cursor.execute(comm)
print("Customer ID = ", custID)
mycon.commit()
mycon.close()
def DeleteCustomer():
mycon = ConnectServer()
cursor = mycon.cursor(buffered=True)
cid = InputID()
comm = "DELETE FROM customer WHERE Customer_ID = '{}';".format(cid)
cursor.execute(comm)
mycon.commit()
mycon.close()
def ViewAllCustomer():
mycon = ConnectServer()
cursor = mycon.cursor(buffered=True)
comm = "SELECT * FROM customer;"
cursor.execute(comm)
mycon.commit()
for row in cursor:
print(row)
mycon.close()
def ViewACustomer():
mycon = ConnectServer()
cursor = mycon.cursor(buffered=True)
cid = InputID()
comm = "SELECT * FROM customer WHERE Customer_ID = '{}';".format(cid)
cursor.execute(comm)
mycon.commit()
for row in cursor:
print(row)
mycon.close()
def UpdateCustomer():
mycon = ConnectServer()
cursor = mycon.cursor(buffered=True)
cid = InputID()
c1 = input("Do You want to change Name? (y/n) ")
if(c1 == 'y' or c1 == 'Y'):
name = InputName()
comm = "UPDATE customer SET Name = '{}' WHERE Customer_ID = '{}';".format(name, cid)
cursor.execute(comm)
mycon.commit()
c1 = input("Do You want to change Phone Number? (y/n) ")
if(c1 == 'y' or c1 == 'Y'):
num = InputPhone()
comm = "UPDATE customer SET Phone_No = '{}' WHERE Customer_ID = '{}';".format(num, cid)
cursor.execute(comm)
mycon.commit()
mycon.close()