-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_rel.py
214 lines (171 loc) · 7.7 KB
/
main_rel.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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QPushButton, QLineEdit, QFormLayout, QCompleter, QLabel, QInputDialog
from PyQt5.QtCore import Qt, QSortFilterProxyModel
import mysql.connector
admin_password = "admin123"
# Функция для подключения к базе данных
def create_connection():
connection = mysql.connector.connect(
host="",
user="root",
password="",
database="main_db"
)
return connection
# Функция для получения жанров из базы данных
def get_genres():
connection = create_connection()
cursor = connection.cursor()
cursor.execute("SELECT genre_name FROM genres")
genres = [row[0] for row in cursor.fetchall()]
connection.close()
return genres
# Функция для получения издателей из базы данных
def get_publishers():
connection = create_connection()
cursor = connection.cursor()
cursor.execute("SELECT publisher_name FROM publishers")
publishers = [row[0] for row in cursor.fetchall()]
connection.close()
return publishers
# Функция для добавления новой игры в базу данных
def add_game(name, price, genre, publisher, release_date):
connection = create_connection()
cursor = connection.cursor()
cursor.execute("""
INSERT INTO games (game_name, game_price_dollar, game_genre, game_publisher, game_release_date)
VALUES (%s, %s, %s, %s, %s)
""", (name, price, genre, publisher, release_date))
connection.commit()
connection.close()
# Окно для ввода пароля
class LoginWindow(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("Вход")
layout = QVBoxLayout()
self.label = QLabel("Введите пароль для входа в админ-аккаунт или оставьте пустым для просмотра")
layout.addWidget(self.label)
self.password_input = QLineEdit()
self.password_input.setEchoMode(QLineEdit.Password)
layout.addWidget(self.password_input)
self.submit_button = QPushButton("Войти")
self.submit_button.clicked.connect(self.check_password)
layout.addWidget(self.submit_button)
self.setLayout(layout)
def check_password(self):
password = self.password_input.text()
if password == admin_password:
self.main_window = MainWindow(is_admin=True)
self.main_window.show()
else:
self.main_window = MainWindow(is_admin=False)
self.main_window.show()
self.close()
# Главное окно приложения
class MainWindow(QWidget):
def __init__(self, is_admin=False):
super().__init__()
self.setWindowTitle("Каталог компьютерных игр")
self.resize(600, 400)
layout = QVBoxLayout()
if is_admin:
self.add_game_button = QPushButton("Добавить игру")
self.add_game_button.clicked.connect(self.open_add_game_window)
layout.addWidget(self.add_game_button)
self.view_games_button = QPushButton("Просмотреть игры")
self.view_games_button.clicked.connect(self.open_view_games_window)
layout.addWidget(self.view_games_button)
self.setLayout(layout)
def open_add_game_window(self):
self.add_game_window = AddGameWindow()
self.add_game_window.show()
def open_view_games_window(self):
self.view_games_window = ViewGamesWindow()
self.view_games_window.show()
# Окно для добавления новой игры
class AddGameWindow(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("Добавить игру")
form_layout = QFormLayout()
self.name_input = QLineEdit()
form_layout.addRow("Название игры:", self.name_input)
self.price_input = QLineEdit()
form_layout.addRow("Цена игры ($):", self.price_input)
self.genre_input = QLineEdit()
completer = QCompleter(get_genres())
self.genre_input.setCompleter(completer)
form_layout.addRow("Жанр:", self.genre_input)
self.publisher_input = QLineEdit()
completer = QCompleter(get_publishers())
self.publisher_input.setCompleter(completer)
form_layout.addRow("Издатель:", self.publisher_input)
self.release_date_input = QLineEdit()
form_layout.addRow("Дата выпуска (YYYY-MM-DD):", self.release_date_input)
# Дополнительные системные требования
self.gpu_input = QLineEdit()
form_layout.addRow("GPU (опционально):", self.gpu_input)
self.cpu_input = QLineEdit()
form_layout.addRow("CPU (опционально):", self.cpu_input)
self.ram_input = QLineEdit()
form_layout.addRow("RAM (опционально):", self.ram_input)
self.os_input = QLineEdit()
form_layout.addRow("OS (опционально):", self.os_input)
self.submit_button = QPushButton("Добавить")
self.submit_button.clicked.connect(self.submit_game)
form_layout.addWidget(self.submit_button)
self.setLayout(form_layout)
def submit_game(self):
name = self.name_input.text()
price = float(self.price_input.text())
genre = self.genre_input.text()
publisher = self.publisher_input.text()
release_date = self.release_date_input.text()
# Проверка на ввод системных требований
sys_req = {
'GPU': self.gpu_input.text(),
'CPU': self.cpu_input.text(),
'RAM': self.ram_input.text(),
'OS': self.os_input.text()
}
if not all(sys_req.values()):
sys_req = None
add_game(name, price, genre, publisher, release_date)
self.close()
# Окно для просмотра списка игр
class ViewGamesWindow(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("Список игр")
layout = QVBoxLayout()
connection = create_connection()
cursor = connection.cursor()
cursor.execute("""
SELECT game_name, game_price_dollar, game_genre, game_publisher, game_release_date,
sys_GPU, sys_CPU, sys_RAM, sys_OS
FROM games
LEFT JOIN system_requirements ON game_ID = game
""")
games = cursor.fetchall()
connection.close()
for index, game in enumerate(games, start=1):
label = QLabel(f"{index} - {game[0]} | Цена: ${game[1]} | Жанр: {game[2]} | Издатель: {game[3]} | Дата выхода: {game[4]}")
layout.addWidget(label)
txt = str()
if game[5]:
txt += f" GPU: {game[5]}"
if game[6]:
txt += f" | CPU: {game[6]}"
if game[7]:
txt += f" | RAM: {game[7]}"
if game[8]:
txt += f" | OS: {game[8]}"
label2 = QLabel(txt)
layout.addWidget(label2)
self.setLayout(layout)
if __name__ == '__main__':
app = QApplication(sys.argv)
main_window = LoginWindow()
main_window.show()
sys.exit(app.exec_())