-
Notifications
You must be signed in to change notification settings - Fork 0
/
onlineshopping.py
174 lines (146 loc) · 5.29 KB
/
onlineshopping.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
import random
from tkinter import Tk, messagebox
from controller import Controller
from registerUser import RegisteredUser
from order import Order
from datetime import datetime
from address import Address
from payment import Payment
from orderline import OrderLine
from product import Product
from customer import Customer
from guest import Guest
from member import Member
from shoppingcart import ShoppingCart
from creditcard import CreditCard
from bank import Bank
class OnlineShopping():
def __init__(self) -> None:
# 初始化所有类别
# 从文件中读取出来
self.staffList = self.readStaff()
self.memberList = self.readMember()
# self.guestList = self.readGuest()
self.productList = self.readProduct()
self.cardList = self.readCard()
self.addList = self.readAddress()
self.bankList = self.readBank()
print('This is OnlineShopping class')
def getProductList(self):
return self.productList
def readStaff(self):
# init
file = './dataset/Staff.txt'
staffList = []
with open(file=file, encoding='utf-8') as f:
for line in f.readlines():
user = []
line = line.replace('\n', '').split(',')
for item in line:
item = item.replace(' ', '')
user.append(item)
staffList.append(user)
return staffList
def readMember(self):
# init
file = './dataset/Member.txt'
memberList = []
with open(file=file, encoding='utf-8') as f:
for line in f.readlines():
user = []
line = line.replace('\n', '').split(',')
for item in line:
user.append(item)
memberList.append(user)
return memberList
# def readGuest(self):
# # init
# file = './dataset/Guest.txt'
# guestList = []
# with open(file=file, encoding='utf-8') as f:
# for line in f.readlines():
# user = []
# line = line.replace('\n', '').split(',')
# for item in line:
# item = item.replace(' ', '')
# user.append(item)
# guestList.append(user)
# return guestList
def readProduct(self):
# init
file = './dataset/Product.txt'
productList = []
with open(file=file, encoding='utf-8') as f:
for line in f.readlines():
user = []
line = line.replace('\n', '').split(',')
for item in line:
item = item.replace(' ', '')
user.append(item)
productList.append(user)
return productList
def readCard(self):
# init
file = './dataset/Card.txt'
cartList = []
with open(file=file, encoding='utf-8') as f:
for line in f.readlines():
user = []
line = line.replace('\n', '').split(',')
for item in line:
item = item.replace(' ', '')
user.append(item)
cartList.append(user)
return cartList
def readBank(self):
# init
file = './dataset/Bank.txt'
bankList = []
with open(file=file, encoding='utf-8') as f:
for line in f.readlines():
user = []
line = line.replace('\n', '').split(',')
for item in line:
item = item.replace(' ', '')
user.append(item)
bankList.append(user)
return bankList
def readAddress(self):
# init
file = './dataset/Address.txt'
addressList = []
with open(file=file, encoding='utf-8') as f:
for line in f.readlines():
user = []
line = line.replace('\n', '').split(',')
for item in line:
item = item.replace(' ', '')
user.append(item)
addressList.append(user)
return addressList
def loginInfo(self, username, password, flag):
# 检查账号密码是否正确无误
if Controller.login(username, password, flag) == True:
messagebox.showinfo("Login", username + ' login successful')
# self指的是GUI
self.memberMenue()
return True
messagebox.showinfo("Login", username + ' login failed!')
return False
def logoutInfo(username, flag):
# 检查账号密码是否正确无误
if Controller.logout(username, flag) == True:
messagebox.showinfo("Logout", username + ' logout successful')
# memberMenue
return True
return False
def viewProduct(productList):
Controller.viewProduct(productList)
if __name__ == '__main__':
os = OnlineShopping()
staff = os.staffList
member = os.memberList
guest = os.guestList
product = os.productList
card = os.cardList
address = os.addList