O
O
Oleg Andreev2020-10-04 13:47:52
MySQL
Oleg Andreev, 2020-10-04 13:47:52

How to make two buttons call one function?

Guys have a function. it has two tables. It is necessary that when you click on one button, one table is processed, when you click on the second, another table. while I'm in a difficult situation. I click on one button, the data is taken from the database in accordance with the instructions, but placed in both tables in the function, the other button also takes the data, but puts it in one table in the function. maybe someone came across.
HERE ARE BUTTONS:
FIRST:

def addArmR(self):
    DoborName = self.ui.nameArm.text()
    DoborColor = self.ui.colorArm.currentText()
    DoborSize = self.ui.sizeArm.text()
    DoborCount = self.ui.countArm.text()
    DoborHeight = self.ui.heightArm.text()
    DoborPrice = self.ui.minPriceArm.text()
    raschet = str(self.raschetID)

    sqlAddArmR = "insert into items_to_raschet set `raschet_id` = '" + raschet + "', `name_Arm` = '" + DoborName + "',`count` = '" + DoborCount + "',`size_Arm` = '" + DoborSize + "',`height` = '" + DoborHeight + "',`price` = '" + DoborPrice + "', `color_id` = '" + DoborColor + "'"
    cur = mysqlUser.con_mysql(self.listToCfg[0], self.listToCfg[1], self.listToCfg[2], self.listToCfg[3])
    mysqlUser.query_mysql(cur, sqlAddArmR) 
#ВТОРАЯ:
def addMatR(self):
    sqlMatID = "select id from materials where `name` = '%s'" % (self.ui.selectMaterial.currentText())
    cur = mysqlUser.con_mysql(self.listToCfg[0], self.listToCfg[1], self.listToCfg[2], self.listToCfg[3])
    matTable = mysqlUser.query_mysql(cur, sqlMatID)
    for row in matTable:
        matID = row['id']

    sqlAddMatR = "insert into items_to_raschet set `raschet_id` = %s, `material_id` = %s, `count` = %s, `height` = %s, `price` = %s, `color_id` = %s, `depth_id` = %s" % (self.raschetID, matID, self.ui.countMaterial.text(), self.ui.heightMaterial.text(), self.ui.minPrice.text(), self.ui.selectColor.currentText(), self.ui.selectDepth.currentText())
    cur = mysqlUser.con_mysql(self.listToCfg[0], self.listToCfg[1], self.listToCfg[2], self.listToCfg[3])
    mysqlUser.query_mysql(cur, sqlAddMatR) 
#ВОТ САМА ФУНКЦИЯ:
def selectAllraschetListFromCreate(self):
    print(self.raschetID , "такая фигня  selectAllraschetListFromCreate")

    sqlToMaterials = "select items_to_raschet.raschet_id, materials.name as material_id, items_to_raschet.count, items_to_raschet.height, items_to_raschet.price, items_to_raschet.color_id, items_to_raschet.depth_id, materials.width from items_to_raschet inner join materials on (materials.id = items_to_raschet.material_id) where raschet_id = %s" % (self.raschetID)
    sqlToArmature = "select items_to_raschet.raschet_id, items_to_raschet.name_Arm, items_to_raschet.count, items_to_raschet.price, items_to_raschet.color_id, items_to_raschet.size_Arm, items_to_raschet.height from items_to_raschet where raschet_id = %s" % (self.raschetID)  #inner join armature on (armature.id = items_to_raschet.armature_id) where raschet_id = %s" % (self.raschetID)
    print(sqlToMaterials)
    self.ui.raschetList.setRowCount(0)
        
    print(sqlToArmature)
    cur = mysqlUser.con_mysql(self.listToCfg[0], self.listToCfg[1], self.listToCfg[2], self.listToCfg[3])

    tableMaterial = mysqlUser.query_mysql(cur, sqlToMaterials)
    for row in tableMaterial:
        print(row)
        a = self.ui.raschetList.rowCount()
        self.ui.raschetList.setRowCount(self.ui.raschetList.rowCount() + 1)
        self.ui.raschetList.setItem(a, 0, QtWidgets.QTableWidgetItem(row["material_id"]))
        self.ui.raschetList.setItem(a, 2, QtWidgets.QTableWidgetItem(row["count"]))
        self.ui.raschetList.setItem(a, 3, QtWidgets.QTableWidgetItem(row["height"]))
        self.ui.raschetList.setItem(a, 4, QtWidgets.QTableWidgetItem(row["price"]))
        self.ui.raschetList.setItem(a, 5, QtWidgets.QTableWidgetItem(row["color_id"]))
        self.ui.raschetList.setItem(a, 6, QtWidgets.QTableWidgetItem(row["depth_id"]))
    tableArmature = mysqlUser.query_mysql(cur, sqlToArmature)
    for row in tableArmature:
        print(row)
        a = self.ui.raschetList.rowCount()
        self.ui.raschetList.setItem(a, 1, QtWidgets.QTableWidgetItem(row["name_Arm"]))
        self.ui.raschetList.setItem(a, 2, QtWidgets.QTableWidgetItem(row["count"]))
        self.ui.raschetList.setItem(a, 4, QtWidgets.QTableWidgetItem(row["price"]))
        self.ui.raschetList.setItem(a, 5, QtWidgets.QTableWidgetItem(row["color_id"]))
        self.ui.raschetList.setItem(a, 7, QtWidgets.QTableWidgetItem(row["size_Arm"]))
        self.ui.raschetList.setItem(a, 8, QtWidgets.QTableWidgetItem(row["height"]))


With what it can be connected? why events behave differently? I just don't understand

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question