예제 #1
0
    def search_top(self):

        if self.ui.radio_seven.isChecked():
            sql = "SELECT nota, artista, disco FROM metal WHERE nota >= 7 ORDER BY nota ASC"
        elif self.ui.radio_eight.isChecked():
            sql = "SELECT nota, artista, disco FROM metal WHERE nota >= 8 ORDER BY nota ASC"
        elif self.ui.radio_nine.isChecked():
            sql = "SELECT nota, artista, disco FROM metal WHERE nota >= 9 ORDER BY nota ASC"
        elif self.ui.radio_ten.isChecked():
            sql = "SELECT nota, artista, disco FROM metal WHERE nota = 10"
        else:
            sql = "SELECT nota, artista, disco FROM metal ORDER BY nota DESC"

        with db_connect() as db:
            try:
                cursor = db.cursor()
                cursor.execute(sql)
                self.top = cursor.fetchall()

                if self.top == []:
                    self.error()

            except ProgrammingError as e:
                self.error()

        self.set_table()
        self.create_rows(("Nota", "Artista", "Disco"), (60, 130, 245))
        self.display_rows()
예제 #2
0
    def search_record(self):
        record = str(self.ui.search_input.text())
        sql = f"""SELECT disco, artista, duracao, faixas, gravadora, nota, goat FROM metal WHERE disco = '{record}'"""

        with db_connect() as db:
            try:
                cursor = db.cursor()
                cursor.execute(sql)
                update_query = cursor.fetchall()

                if len(update_query) == 0:
                    msg = QMessageBox()
                    msg.setWindowTitle("Erro:")
                    msg.setText("Nenhum disco encontrado com este nome.")
                    msg.setIcon(QMessageBox.Critical)
                    msg.exec_()
                    return

                self.ui.artist_show.setText(str(update_query[0][1]))
                self.ui.record_show.setText(str(update_query[0][0]))
                self.ui.track_show.setText(str(update_query[0][3]))
                self.ui.duration_show.setText(str(update_query[0][2]))
                self.ui.score_show.setText(str(update_query[0][5]))
                self.ui.record_label_show.setText(str(update_query[0][4]))
                if update_query[0][6] == "1":
                    self.ui.goat_box.toggle()

            except ProgrammingError as e:
                msg = QMessageBox()
                msg.setWindowTitle("Erro:")
                msg.setText("Nenhum disco com foi encontrado.")
                msg.setIcon(QMessageBox.Critical)
                msg.exec_()
                return
예제 #3
0
    def load_graph(self):
        sql = "SELECT disco, artista, duracao, faixas, gravadora, nota, goat FROM metal"

        with db_connect() as db:
            try:
                cursor = db.cursor()
                cursor.execute(sql)
                self.graph = cursor.fetchall()
            except ProgrammingError as e:
                msg = QMessageBox()
                msg.setWindowTitle("Erro:")
                msg.setText("Dados insuficientes para exibir o gráfico.")
                msg.setIcon(QMessageBox.Critical)
                msg.exec_()
                return
예제 #4
0
    def sql_query(self, str):
        sql = str
        with db_connect() as db:
            try:
                cursor = db.cursor()
                cursor.execute(sql)
                self.db_data = cursor.fetchall()

            except ProgrammingError as e:
                msg = QMessageBox()
                msg.setWindowTitle("Erro:")
                msg.setText("Base de dados vazia: nenhum dado para ser apresentado.")
                msg.setIcon(QMessageBox.Critical)
                msg.exec_()
                return
예제 #5
0
    def search_goat(self):
        sql = "SELECT artista, disco FROM metal WHERE goat=true"

        with db_connect() as db:
            try:
                cursor = db.cursor()
                cursor.execute(sql)
                self.goats = cursor.fetchall()

                if self.goats == []:
                    self.error()

            except ProgrammingError as e:
                self.error()

        self.set_table()
        self.create_rows(("Artista", "Disco"), (149, 300))
        self.display_rows()
예제 #6
0
    def remove_artist(self):
        remove = self.ui.remove_input.text()
        sql_show = f'SELECT * FROM metal WHERE disco="{remove}"'
        sql_delete = f'DELETE FROM metal WHERE disco="{remove}"'

        if not remove:
            msg = QMessageBox()
            msg.setWindowTitle("Erro:")
            msg.setText("Preencha o campo para remover um disco.")
            msg.setIcon(QMessageBox.Critical)
            msg.exec_()
            return

        with db_connect() as db:
            try:
                cursor = db.cursor()
                cursor.execute(sql_show)
                if cursor.fetchall() is []:
                    msg = QMessageBox()
                    msg.setWindowTitle("Erro:")
                    msg.setText("Nenhum disco encontrado com este nome.")
                    msg.setIcon(QMessageBox.Critical)
                    msg.exec_()
                    return
                else:
                    cursor.execute(sql_delete)
                    db.commit()
            except ProgrammingError as e:
                msg = QMessageBox()
                msg.setWindowTitle("Erro:")
                msg.setText(e)
                msg.setIcon(QMessageBox.Critical)
                msg.exec_()
                return
            else:
                msg = QMessageBox()
                msg.setWindowTitle("Sucesso!")
                msg.setText("Disco removido com sucesso.")
                msg.setIcon(QMessageBox.Critical)
                msg.exec_()
                return
예제 #7
0
    def remove_all(self):
        sql = "TRUNCATE TABLE metal"

        with db_connect() as db:
            try:
                cursor = db.cursor()
                cursor.execute(sql)

                msg = QMessageBox()
                msg.setWindowTitle("Sucesso")
                msg.setText("Base de dados reiniciada.")
                msg.setIcon(QMessageBox.Critical)
                msg.exec_()
                return

            except ProgrammingError as e:
                msg = QMessageBox()
                msg.setWindowTitle("Erro:")
                msg.setText(e.msg)
                msg.setIcon(QMessageBox.Critical)
                msg.exec_()
                return
예제 #8
0
    def search_artist(self):
        search = self.ui.search_input.text()

        if search == "":
            sql = "SELECT artista, disco FROM metal"
        else:
            sql = f'SELECT artista, disco FROM metal WHERE artista="{search}"'

        with db_connect() as db:
            try:
                cursor = db.cursor()
                cursor.execute(sql)
                self.records = cursor.fetchall()

                if self.records == []:
                    self.error()

            except ProgrammingError as e:
                self.error()

        self.set_table()
        self.create_rows(("Artista", "Disco"), (150, 294))
        self.display_rows()
예제 #9
0
    def update_artist(self):
        record = str(self.ui.update_input.text())
        artista = self.ui.artist_input.text()
        disco = self.ui.record_input.text()
        faixas = self.ui.track_input.text()
        duracao = self.ui.duration_input.text()
        nota = self.ui.score_input.text()
        gravadora = self.ui.record_label_input.text()
        goat = self.ui.goat_box.isChecked()

        goat_result = False

        if goat:
            goat_result = True

        sql = f"""UPDATE metal SET disco = '{disco}', artista = '{artista}', duracao = '{duracao}', faixas = {faixas}, gravadora = '{gravadora}', nota = {nota}, goat = {goat} WHERE disco = '{record}'"""
        print(sql)

        if (
            not artista
            or not disco
            or not faixas
            or not duracao
            or not nota
            or not gravadora
        ):
            msg = QMessageBox()
            msg.setWindowTitle("Erro:")
            msg.setText(
                "Campos disco, artista, gravadora, duração, número de faixas e nota são de preenchimento obrigatório."
            )
            msg.setIcon(QMessageBox.Critical)
            msg.exec_()
            return

        with db_connect() as db:
            try:
                cursor = db.cursor()
                cursor.execute(
                    sql,
                    (disco, artista, duracao, int(faixas), gravadora, int(nota), goat),
                )
                db.commit()
            except ProgrammingError as e:
                msg = QMessageBox()
                msg.setWindowTitle("Erro:")
                msg.setText(e.msg)
                msg.setIcon(QMessageBox.Critical)
                msg.exec_()
                return
            else:
                msg = QMessageBox()
                msg.setWindowTitle("Sucesso!")
                msg.setText("Disco alterado com sucesso.")
                msg.setIcon(QMessageBox.Critical)
                msg.exec_()
                return

        self.ui.artist_input.setText("")
        self.ui.record_input.setText("")
        self.ui.track_input.setText("")
        self.ui.duration_input.setText("")
        self.ui.score_input.setText("")
        self.ui.record_label_input.setText("")

        if self.ui.goat_box.isChecked():
            self.ui.goat_box.setChecked(False)
예제 #10
0
    def add_artist(self):
        sql = "INSERT INTO metal(disco, artista, duracao, faixas, gravadora, nota, goat) VALUES (%s, %s, %s, %s, %s, %s, %s);"

        artista = self.ui.artist_input.text()
        disco = self.ui.record_input.text()
        faixas = self.ui.track_input.text()
        duracao = self.ui.duration_input.text()
        nota = self.ui.score_input.text()
        gravadora = self.ui.record_label_input.text()
        goat = self.ui.goat_box.isChecked()

        goat_result = False

        if goat:
            goat_result = True

        if (
            not artista
            or not disco
            or not faixas
            or not duracao
            or not nota
            or not gravadora
        ):
            msg = QMessageBox()
            msg.setWindowTitle("Erro:")
            msg.setText(
                "Campos disco, artista, gravadora, duração, número de faixas e nota são de preenchimento obrigatório."
            )
            msg.setIcon(QMessageBox.Critical)
            msg.exec_()
            return

        with db_connect() as db:
            try:
                cursor = db.cursor()
                cursor.execute(
                    sql,
                    (disco, artista, duracao, int(faixas), gravadora, int(nota), goat),
                )
                db.commit()
            except ProgrammingError as e:
                msg = QMessageBox()
                msg.setWindowTitle("Erro:")
                msg.setText(e.msg)
                msg.setIcon(QMessageBox.Critical)
                msg.exec_()
                return
            else:
                msg = QMessageBox()
                msg.setWindowTitle("Sucesso!")
                msg.setText("Disco adicionado com sucesso.")
                msg.setIcon(QMessageBox.Critical)
                msg.exec_()
                return

        self.ui.artist_input.setText("")
        self.ui.record_input.setText("")
        self.ui.track_input.setText("")
        self.ui.duration_input.setText("")
        self.ui.score_input.setText("")
        self.ui.record_label_input.setText("")

        if self.ui.goat_box.isChecked():
            self.ui.goat_box.setChecked()