Professional Documents
Culture Documents
selected_sport = self.cbsport.currentText()
date = self.dateEdit.date().toString("yyyy-MM-dd")
time = self.timeEdit.time().toString("hh:mm")
remaining_teams = self.teamnum.text()
db_host = 'localhost'
db_name = 'sport'
db_user = 'postgres'
db_password = '123456'
try:
conn = psycopg2.connect(
host=db_host,
database=db_name,
user=db_user,
password=db_password
)
cursor = conn.cursor()
if self.sender() == self.savebtn_2:
# Save button clicked, perform save functionality
home_team = self.home.currentText()
against_team = self.against.currentText()
location = self.cblocation.currentText()
while True:
cursor.execute("SELECT 1 FROM SCHEDULE WHERE SCHED_ID = %s",
(sched,))
if cursor.fetchone() is None:
break
sched = random.randint(1111, 1999)
# Insert data into the MATCH table with the retrieved TEAM_IDs
querymatch = "INSERT INTO MATCH (MATCH_ID, MATCH_GAME_TYPE,
MATCH_STATUS, TEAM_ID, MATCH_DESCRIPTION, SCHED_ID, RES_ID) VALUES (%s, %s, %s, %s,
%s, %s, %s)"
cursor.execute(querymatch,
(res_match, selected_sport, 'Upcoming',
home_team_id, match_des, sched, res_match))
querynumber = """
SELECT COUNT(TEAM_ID)
FROM TEAM
WHERE TEAM_LEAGUE = %s
AND TEAM_ID NOT IN (
SELECT TEAM_ID
FROM MATCH
WHERE MATCH_ID IS NOT NULL
AND MATCH_GAME_TYPE = %s
)
"""
cursor.execute(querynumber, (selected_sport, selected_sport))
remaining_teams = cursor.fetchone()[0]
conn.commit()
conn.close()
if remaining_teams == 0:
QMessageBox.warning(self, "No Teams", "No teams available for
matches.")
else:
# Update the remaining teams count in the GUI
self.teamnum.setText(str(remaining_teams))