def load_saved_players(self): players = QSqlQueryModel() players_query = QSqlQuery("select * from players where aktiv=1") players.setQuery(players_query) self.saved_players.clear() for i in range(players.rowCount()): item = QListWidgetItem(players.record(i).value(1)) item.setData(Qt.UserRole, players.record(i).value(0)) self.saved_players.addItem(item)
def load_torna(self): torna = QSqlQueryModel() query = QSqlQuery("select * from torna_settings where aktiv=2") torna.setQuery(query) if torna.record(0).value(0): for i in range(torna.rowCount()): self.tournaments.addItem( torna.record(i).value(1), torna.record(i).value(0)) # a value(0) a torna_id
def load_torna_players(self): players = QSqlQueryModel() players_query = QSqlQuery( "select * from torna_resztvevok where 1 group by player_id, player_name" ) players.setQuery(players_query) self.torna_players.clear() for i in range(players.rowCount()): item = QListWidgetItem(players.record(i).value(1)) item.setData(Qt.UserRole, players.record(i).value(0)) self.torna_players.addItem(item)
def torna_valasztas(self, i): self.torna_id = self.tournaments.itemData(i) players = QSqlQueryModel() players_query = QSqlQuery( f"select * from torna_resztvevok where torna_id={self.torna_id}") players.setQuery(players_query) self.current_players.clear() for i in range(players.rowCount()): item = QListWidgetItem(players.record(i).value(1)) item.setData(Qt.UserRole, players.record(i).value(0)) self.current_players.addItem(item)
def stat_game(self): # Az átvett adatok: para = self.merkozesek.currentItem().text().rsplit("\t") # Összegyűjtjük egy listába a szükséges infókat self.get_adatok(para) self.szumma.change_data(self.adatok) for x in reversed(range(self.history_layout.count())): self.history_layout.itemAt(x).widget().deleteLater() # kiszedjük az adott meccs összes set és leg esetére a dobásokat sor = 0 for s in range(1, self.adatok[8] + 1): # s: a set-ek száma if self.adatok[8] != 1: self.history_layout.addWidget(QLabel("Set: " + str(s)), sor, 0, 1, 2) sor += 1 for l in range(1, self.adatok[7][s-1] + 1): sl1_model = QSqlQueryModel() p1_data_list = [] p1_data_list.append(self.adatok[4]) # start_score1 sl1_query = QSqlQuery(f"select * from dobas where match_id ={self.adatok[6]} and set_id={s} and leg_id={l} and player_id='{self.adatok[0]}'", db=db) sl1_model.setQuery(sl1_query) for i in range(sl1_model.rowCount()): # Itt a model már tartalmazza a p1 összes dobását az adott leg-ben. p1_data_row = [] p1_data_row.append(sl1_model.record(i).value(1)) p1_data_row.append(sl1_model.record(i).value(2)) p1_data_list.append(p1_data_row) self.history_layout.addWidget(PlayerLegWidget(self, p1_data_list), sor, 0, Qt.AlignTop) sl2_model = QSqlQueryModel() p2_data_list = [] p2_data_list.append(self.adatok[5]) # start_score2 sl2_query = QSqlQuery(f"select * from dobas where match_id ={self.adatok[6]} and set_id={s} and leg_id={l} and player_id='{self.adatok[2]}'", db=db) sl2_model.setQuery(sl2_query) for j in range(sl2_model.rowCount()): p2_data_row = [] p2_data_row.append(sl2_model.record(j).value(1)) p2_data_row.append(sl2_model.record(j).value(2)) p2_data_list.append(p2_data_row) self.history_layout.addWidget(PlayerLegWidget(self, p2_data_list), sor, 1, Qt.AlignTop) sor += 1
def change_data(self, szum=None): self.data = None self.data = szum self.name1 = self.data[1] self.name2 = self.data[3] match_id = self.data[6] p1_id = self.data[0] p2_id = self.data[2] # Végeredmény self.won1 = 0 self.won2 = 0 self.avg1 = self.avg2 = 0 eredmenyek_model = QSqlQueryModel() eredmenyek_query = QSqlQuery(f"select * from matches where match_id={match_id}", db=db) eredmenyek_model.setQuery(eredmenyek_query) for x in range(1, self.data[8] + 1): l1 = l2 = 0 for i in range(eredmenyek_model.rowCount()): # csak set-eket összesítünk if eredmenyek_model.record(i).value(2) == x: if eredmenyek_model.record(i).value(3) == p1_id: l1 += 1 else: l2 += 1 # print("Set: ", x, "L1: ", l1, "L2: ", l2) if self.data[8] == 1: self.won1 = l1 self.won2 = l2 else: if l1 > l2: self.won1 += 1 else: self.won2 += 1 # Átlagok db1 = db2 = sum1 = sum2 = 0 for x in range(1, self.data[8] + 1): for leg in range(1, self.data[7][x - 1] + 1): query = QSqlQuery(f"select max(round_number) as maxround, sum(points) as sumpont from dobas where leg_id={leg} and set_id={x} and match_id={match_id} and player_id={p1_id}") query.exec_() while query.next(): db1 += query.value(0) sum1 += query.value(1) query2 = QSqlQuery(f"select max(round_number) as maxround, sum(points) as sumpont from dobas where leg_id={leg} and set_id={x} and match_id={match_id} and player_id={p2_id}") query2.exec_() while query2.next(): db2 += query2.value(0) sum2 += query2.value(1) self.avg1 = round(sum1 / db1 * 3, 2) self.avg2 = round(sum2 / db2 * 3, 2) self.update()
def jogcim_selected(self): napidij_model = QSqlQueryModel() query = QSqlQuery( "SELECT kulcs, ertek FROM settings WHERE kulcs LIKE '%napidij%'") napidij_model.setQuery(query) for i in range(napidij_model.rowCount()): if (napidij_model.record(i).value(0) == 'ar_ifjusagi_napidij') and (self.jogcim.text() == 'Ifjúsági napidíj'): self.osszeg.setText(str(napidij_model.record(i).value(1))) if (napidij_model.record(i).value(0) == 'ar_napidij') and (self.jogcim.text() == 'Napidíj'): self.osszeg.setText(str(napidij_model.record(i).value(1)))
def jogcim_selected(self): berlet_model = QSqlQueryModel() query = QSqlQuery( "SELECT kulcs, ertek FROM settings WHERE kulcs LIKE '%berlet%'") berlet_model.setQuery(query) for i in range(berlet_model.rowCount()): if (berlet_model.record(i).value(0) == 'ar_gyermek_berlet') and (self.jogcim.text() == 'Gyermek bérlet'): self.osszeg.setText(str(berlet_model.record(i).value(1))) if (berlet_model.record(i).value(0) == 'ar_ifjusagi_berlet') and (self.jogcim.text() == 'Ifjúsági bérlet'): self.osszeg.setText(str(berlet_model.record(i).value(1))) if (berlet_model.record(i).value(0) == 'ar_berlet') and (self.jogcim.text() == 'Bérlet'): self.osszeg.setText(str(berlet_model.record(i).value(1)))
def torna_valasztas(self, i): print(self.tournaments.itemData(i)) # matches = QSqlRelationalTableModel() # matches.setTable("torna_match") # matches.setFilter(f'a.torna_id=8889 and a.player1_id=c.player_id and a.player2_id=d.player_id and c.torna_id=a.torna_id and d.torna_id=a.torna_id and a.torna_id=b.torna_id') # matches.setFilter(f'torna_name = "{self.tournaments.currentText()}" and torna_resztvevok.torna_id=torna_settings.torna_id and station_id = "{self.station_id}"') # matches.setRelation(0, QSqlRelation("torna_settings", "torna_id", "torna_name")) # matches.setRelation(2, QSqlRelation("torna_resztvevok", "player_id", "player_name")) # matches.setRelation(3, QSqlRelation("torna_resztvevok", "player_id", "player_name")) # matches.setRelation(7, QSqlRelation("reged_station", "id", "station_id")) # matches.select() # print(matches) # self.merkozesek.clear() # for i in range(matches.rowCount()): # self.merkozesek.addItem(matches.record(i).value(0) + "\t" + # str(matches.record(i).value(1)) + "\t" + # matches.record(i).value(2) + "\t" + # matches.record(i).value(3) + "\t" + # matches.record(i).value(4) + "\t" + # str(matches.record(i).value(5))+ "\t" + # str(matches.record(i).value(6))) matches = QSqlQueryModel() # todo itt még nincs táblához kötve a lekérés matches_query = QSqlQuery( f'SELECT a.match_id, b.torna_name, c.player_name as nev1, \ d.player_name as nev2, a.variant, a.sets, a.legsperset FROM `torna_match` a, torna_settings b, torna_resztvevok c, \ torna_resztvevok d WHERE a.torna_id={self.tournaments.itemData(i)} and a.player1_id=c.player_id and a.player2_id=d.player_id \ and c.torna_id=a.torna_id and d.torna_id=a.torna_id and a.torna_id=b.torna_id and a.match_status<2' ) matches.setQuery(matches_query) self.merkozesek.clear() for i in range(matches.rowCount()): self.merkozesek.addItem( str(matches.record(i).value(0)) + "\t" + matches.record(i).value(1) + "\t" + matches.record(i).value(2) + "\t" + matches.record(i).value(3) + "\t" + matches.record(i).value(4) + "\t" + str(matches.record(i).value(5)) + "\t" + str(matches.record(i).value(6)))
class Main(QWidget): def __init__(self): super().__init__() self.user_entry = QLineEdit("user5301") # self.user_entry.setStyleSheet("font: corbel; font-size: 12px;") self.pass_entry = QLineEdit("e", self) self.odbc = "" self.bars = "" self.table_query = "" self.pass_entry.setEchoMode(QLineEdit.PasswordEchoOnEdit) self.ru_entry = QLineEdit("328845", self) # self.ru_entry.setStyleSheet("font: corbel; font-size: 12px;") self.cur_entry = QLineEdit("840") # self.cur_entry.setStyleSheet("font: corbel; font-size: 12px;") self.balance_entry = QLineEdit("213000001") # self.balance_entry.setStyleSheet("font: corbel; font-size: 12px;") self.ok_button = QPushButton("Запустить") self.ok_button.setStyleSheet( "font: corbel; font-size: 12px; color: rgb(0, 0, 255)") # self.ok_button.setStyleSheet("color: rgb(160, 70, 70)") self.error_label = QLabel("Ошибки будут тут") self.error_label.setStyleSheet("color: rgb(255, 0, 0)") self.start_button1 = QPushButton("Старт") self.stop_button1 = QPushButton("Стоп") self.start_button1.setEnabled(True) self.stop_button1.setEnabled(False) self.start_button1.setStyleSheet("background-color: rgb(81,142,144)") self.interval_l = QLabel("Интервал") # self.interval_l.setStyleSheet("font: corbel; font-size: 12px; color: rgb(0, 0, 255)") self.interval_e = QLineEdit() self.timer_id = 0 self.table = QTableView() # Create model self.sqm = QSqlQueryModel(parent=self.table) self.init_ui() def on_start(self): password = self.pass_entry.text() if password == "e": self.print_and_label("Вы не ввели пароль!") else: self.timer_id = self.startTimer(int(self.interval_e.text())) self.start_button1.setEnabled(False) self.stop_button1.setEnabled(True) def on_stop(self): print("Таймер остановлен.", self.timer_id) if self.timer_id: self.killTimer(self.timer_id) self.timer_id = 0 self.start_button1.setEnabled(True) self.stop_button1.setEnabled(False) def print_and_label(self, text): print(text) self.error_label.setText(text) def run(self): ## print(getpass.getuser(), self.user_entry.text()) e = WorkWithOCI( "XE", self.user_entry.text(), keyring.get_password(getpass.getuser(), self.user_entry.text())) #print("Name of database:", e.name) # print("Host :", e.host) conn = e.open_db() if conn: self.error_label.setText("Ошибок уже/пока нет") query = QSqlQuery() query2 = QSqlQuery() # Доступность if query.exec_(self.bars): #print("Q1 done!") query.finish() # Create model self.sqm = QSqlQueryModel(parent=self.table) # Сам запрос self.sqm.setQuery( self.table_query.format(self.ru_entry.text().strip(), self.cur_entry.text().strip(), self.balance_entry.text().strip())) if query2.exec_( self.table_query.format( self.ru_entry.text().strip(), self.cur_entry.text().strip(), int(self.balance_entry.text().strip()))): #print("Q2 done!") self.sqm.setQuery(query2) else: self.print_and_label("Ошибка 2-го запроса") print( "2-й запрос (", self.table_query.format( self.ru_entry.text().strip(), self.cur_entry.text().strip(), int(self.balance_entry.text().strip())), ") :", query.lastError().text()) # Задаем заголовки для столбцов модели self.sqm.setHeaderData(0, Qt.Horizontal, "Счет") self.sqm.setHeaderData(1, Qt.Horizontal, "РУ") self.sqm.setHeaderData(2, Qt.Horizontal, "Валюта") self.sqm.setHeaderData(3, Qt.Horizontal, "Остаток") # self.print_and_label(sqm.lastError().text()) # Задаем для таблицы только что созданную модель self.table.setModel(self.sqm) # Not)Скрываем первый столбец, в котором выводится идентификатор # self.table.hideColumn(0) self.table.setColumnWidth(0, 150) self.table.setColumnWidth(1, 60) self.table.setColumnWidth(2, 80) self.table.setColumnWidth(3, 150) # print("sqm.rowCount()", self.sqm.rowCount()) if self.sqm.rowCount() > 0: frequency = 2500 duration = 2000 winsound.Beep(frequency, duration) conn.close() #conn.removeDatabase('qt_sql_default_connection') else: self.print_and_label("Ошибка первого запроса (", self.bars, ") :", query.lastError().text()) else: self.print_and_label("Ошибка открытия базы данных") def timerEvent(self, event): # self.error_label.setText("Сработал таймер" + str(event.timerId())) print("Сработал таймер", str(event.timerId())) self.run() def init_ui(self): file_name = 'ini_balance' with open(file_name) as f: lines = f.readlines() try: self.interval_e.setText(lines[0]) except: self.error_label.setText( ' Возможно в первой строке файла ini_balance нет времени таймера!' ) try: self.bars = lines[1] except: self.error_label.setText( ' Возможно во второй строке файла ini_balance нет запроса!' ) try: self.table_query = lines[2] except: self.error_label.setText( ' Возможно в третьей строке файла ini_balance нет запроса!' ) label = QLabel(self) label.setAlignment(Qt.AlignRight) label.resize(30, 30) image = QPixmap("b.jfif", format="JPG").scaled(label.width(), label.height()) #image = QPixmap("mon.png", format="PNG") label.setPixmap(image) self.group = QGroupBox("Таймер остатка") self.group.setStyleSheet("font: corbel; font-size: 14px;") v_group = QVBoxLayout() # Контейнер для группы v_group.addWidget(self.start_button1) v_group.addWidget(self.stop_button1) v_group.addWidget(self.interval_l) v_group.addWidget(self.interval_e) self.group.setLayout(v_group) form = QFormLayout() form.addRow("", label) form.addRow("По&льзователь", self.user_entry) form.addRow("&Пароль", self.pass_entry) form.addRow("&МФО области", self.ru_entry) form.addRow("&Валюта", self.cur_entry) form.addRow("&Необходимый остаток", self.balance_entry) form.addRow("", self.ok_button) form.addRow("", self.group) form.addRow("&Результат", self.table) form.addRow("&Ошибки", self.error_label) self.setLayout(form) # k10 - work with password # is_right in - hash, return - T/F; set_p in - pass return - hash hash_pass = hashlib.md5(self.pass_entry.text().encode('utf-8')) # print("hash", hash_pass) # keyring.set_password(getpass.getuser(), self.user_entry.text(), self.pass_entry.text()) self.pass_entry.editingFinished.connect( lambda: k10.keyring_pass(getpass.getuser(), self.user_entry.text( ), self.pass_entry, hash_pass, self.ru_entry)) self.ok_button.clicked.connect(lambda: self.run()) self.start_button1.clicked.connect(self.on_start) self.stop_button1.clicked.connect(self.on_stop) self.setGeometry(300, 100, 650, 550) self.setWindowTitle('Ждем деньги') self.show()
def insert_torna_settings(self): van_ilyen_nev = False if len(self.torna_name.text()) != 0: torna_id_model = QSqlQueryModel() query = QSqlQuery( "select torna_id, torna_name from torna_settings", db=db) torna_id_model.setQuery(query) for i in range(torna_id_model.rowCount()): if torna_id_model.record(i).value(1) == self.torna_name.text(): msg = QMessageBox(self) msg.setStyleSheet("fonz-size: 20px") msg.setWindowTitle("Név ütközés!") msg.setText( '<html style="font-size: 14px; color: red">Már van ilyen nevű verseny!<br></html>' + '<html style="font-size: 16px">Kérem adjon a versenynek egyedi nevet!</html>' ) msg.exec_() van_ilyen_nev = True if not van_ilyen_nev: torna_settings_model = QSqlTableModel( db=db ) # !!!!!!! Ha több db van, akkor itt konkrétan meg kell adni torna_settings_model.setTable("torna_settings") record = torna_settings_model.record() record.setValue(1, self.torna_name.text()) if self.is_roundrobin.isChecked(): record.setValue(2, 1) else: record.setValue(2, 0) record.setValue(3, self.csoport_number.value()) record.setValue(4, self.jatekos_per_csoport.value()) record.setValue(5, self.variant.value()) if self.is_sets.isChecked(): record.setValue(6, 1) else: record.setValue(6, 0) record.setValue(7, self.sets_number.value()) record.setValue(8, self.legs_number.value()) # print(record.value(2)) if self.is_best.isChecked(): record.setValue(9, 1) else: record.setValue(9, 0) if self.is_draw.isChecked(): record.setValue(10, 1) else: record.setValue(10, 0) record.setValue(11, self.pont_win.value()) record.setValue(12, self.pont_draw.value()) record.setValue(13, self.pont_lost.value()) if self.is_single_elim.isChecked(): record.setValue(14, 1) else: record.setValue(14, 0) record.setValue(15, self.num_single.value()) if self.is_3place.isChecked(): record.setValue(16, 1) else: record.setValue(16, 0) record.setValue(17, self.leg_num_single.value()) record.setValue(18, self.leg_num_semifinal.value()) record.setValue(19, self.leg_num_3place.value()) record.setValue(20, self.leg_num_final.value()) record.setValue(21, 2) # aktiv flag: 0: vége, 1: folyamatban, 2: szerkesztés alatt # print(record) if torna_settings_model.insertRecord(-1, record): torna_settings_model.submitAll() else: db.rollback() torna_id_model2 = QSqlQueryModel() query2 = QSqlQuery( f"select torna_id from torna_settings where torna_name='{self.torna_name.text()}'", db=db) torna_id_model2.setQuery(query2) self.torna_id = int(torna_id_model2.record(0).value(0)) self.gomb_members.setDisabled(False) else: msg = QMessageBox(self) msg.setStyleSheet("fonz-size: 20px") msg.setWindowTitle("Hiányzik a verseny neve!") msg.setText( '<html style="font-size: 14px; color: red">A létrehozott versenynek kell egy elnevezés!<br></html>' + '<html style="font-size: 16px">Kérem adja meg a verseny nevét!</html>' ) msg.exec_()