Пример #1
0
class TableBuildForm(QWidget):
    def __init__(self):
        super(TableBuildForm, self).__init__()
        self.initUi()

    def initUi(self):
        # 获取显示器分辨率
        self.desktop = QApplication.desktop()
        self.screenRect = self.desktop.screenGeometry()
        self.height = self.screenRect.height()
        self.width = self.screenRect.width()
        self.resize(self.width, self.height)
        self.setWindowTitle("数据表定义")

        mainLayout = QHBoxLayout()
        centerLayout = QVBoxLayout()
        rightLayout = QVBoxLayout()

        mainLayout.addLayout(centerLayout)
        mainLayout.addLayout(rightLayout)
        self.setLayout(mainLayout)

        centerTopLayout = QHBoxLayout()
        centerCenterLayout = QVBoxLayout()
        centerBottomLayout = QHBoxLayout()

        centerLayout.addLayout(centerTopLayout)
        centerLayout.addLayout(centerCenterLayout)
        centerLayout.addLayout(centerBottomLayout)

        zlkmcLabel = QLabel("资料库名称")
        self.zlkmcLineEdit = QLineEdit()
        bmcLabel = QLabel('数据表名称')
        self.bmcLineEdit = QLineEdit()
        bjxLabel = QLabel('内部名称')
        self.bjxLineText = QLineEdit()

        centerTopLayout.addWidget(zlkmcLabel)
        centerTopLayout.addWidget(self.zlkmcLineEdit)
        centerTopLayout.addWidget(bmcLabel)
        centerTopLayout.addWidget(self.bmcLineEdit)
        centerTopLayout.addWidget(bjxLabel)
        centerTopLayout.addWidget(self.bjxLineText)

        self.dataTableWidget = QTableWidget()
        centerCenterLayout.addWidget(self.dataTableWidget)

        self.dataTableWidget.setColumnCount(7)
        self.dataTableWidget.setHorizontalHeaderLabels(
            ['数据项名称', '字段名称', '数据类型', '数据大小', '数据来源', '主键', '是否为空'])
        self.dataTableWidget.horizontalHeader().setSectionResizeMode(
            QHeaderView.Stretch)
        self.dataTableWidget.setEditTriggers(QAbstractItemView.NoEditTriggers)
        self.dataTableWidget.setSelectionBehavior(QAbstractItemView.SelectRows)

        centerCenterLayout.addWidget(self.dataTableWidget)

        testTableExistButton = QPushButton("数据表检测")
        reBuildTabelButton = QPushButton("替换数据表")
        addTableButton = QPushButton("添加数据表")
        replaceTableButton = QPushButton("替换数据表")

        centerBottomLayout.addWidget(testTableExistButton)
        centerBottomLayout.addWidget(reBuildTabelButton)
        centerBottomLayout.addWidget(addTableButton)
        centerBottomLayout.addWidget(replaceTableButton)

        self.m_db = DBUtil()
        self.dataTableWidget.setContextMenuPolicy(Qt.CustomContextMenu)
        self.dataTableWidget.customContextMenuRequested.connect(
            self.GenerateRightMenu)
        self.fieldBuildForm = FieldBuildForm()
        self.fieldBuildForm.AddButton.clicked.connect(self.EditTableRow)
        testTableExistButton.clicked.connect(self.TestTableExist)
        reBuildTabelButton.clicked.connect(self.ReBuildTable)
        addTableButton.clicked.connect(self.AddTable)
        replaceTableButton.clicked.connect(self.ReplaceTable)

    def table_init(self, tbid, tbmc, tbjx):
        self.tbid = tbid
        self.tbmc = tbmc
        self.tbjx = tbjx
        self.bmcLineEdit.setText(tbmc)
        self.bjxLineText.setText(tbjx)
        #读取数据表信息
        field_info = self.m_db.GetFieldValueToStrGroupsFromDb(
            "ZDMC,MCJX,ZDLX,ZDDX,KZLX", "XTGLK.ZLFL_MSFF_FIELD",
            "where TBID='" + self.tbid + "'")
        if field_info != None:
            if len(field_info[0]) > 0:
                self.dataTableWidget.setRowCount(len(field_info[0]))
                for index in range(0, len(field_info[0])):
                    zdmc = field_info[0][index]
                    mcjx = field_info[1][index]
                    zdlx = field_info[2][index]
                    zddx = str(field_info[3][index])
                    kzlx = field_info[4][index]

                    if kzlx == '0':
                        kzlx = "0-用户输入"
                    elif kzlx == '1':
                        kzlx = "1-用户选择"
                    elif kzlx == '2':
                        kzlx = "2-系统生成"
                    elif kzlx == '3':
                        kzlx = "3-系统默认"
                    else:
                        kzlx = ""

                    zjs = self.m_db.GetFieldValueToStrListFromDb(
                        "ZDMC", "XTGLK.ZLFL_MSFF_FIELD_KEY",
                        "where TBID='" + self.tbid + "'")
                    zj = ''
                    if len(zjs) > 0:
                        if zjs.index(mcjx) >= 0:
                            zj = "主键"
                        else:
                            zj = "非主键"
                    else:
                        zj = "非主键"

                    sfwk = self.m_db.GetFieldValueToSingleStrFromDb(
                        "SFWK", "XTGLK.ZLFL_MSFF_FIELD_INFO", "where TBID='" +
                        self.tbid + "' and ZDMC='" + mcjx + "'")
                    if sfwk == "0":
                        sfwk = "可以为空"
                    else:
                        sfwk = "不能为空"

                    newitem = QTableWidgetItem(zdmc)
                    self.dataTableWidget.setItem(index, 0, newitem)
                    newitem = QTableWidgetItem(mcjx)
                    self.dataTableWidget.setItem(index, 1, newitem)
                    newitem = QTableWidgetItem(zdlx)
                    self.dataTableWidget.setItem(index, 2, newitem)
                    newitem = QTableWidgetItem(zddx)
                    self.dataTableWidget.setItem(index, 3, newitem)
                    newitem = QTableWidgetItem(kzlx)
                    self.dataTableWidget.setItem(index, 4, newitem)
                    newitem = QTableWidgetItem(zj)
                    self.dataTableWidget.setItem(index, 5, newitem)
                    newitem = QTableWidgetItem(sfwk)
                    self.dataTableWidget.setItem(index, 6, newitem)

    def GenerateRightMenu(self, pos):
        menu = QMenu()
        editItem = menu.addAction(u'编辑')
        preInsertItem = menu.addAction(u'前置插入')
        backInsertItem = menu.addAction(u'后置插入')
        deleteItem = menu.addAction(u'删除数据项')
        clearItem = menu.addAction(u'清除数据项')
        deleteMrItem = menu.addAction(u'删除默认数据项')

        action = menu.exec_(QCursor.pos())
        if action == editItem:
            self.ShowEditItemForm()
        elif action == preInsertItem:
            pass
        elif action == backInsertItem:
            pass
        elif action == deleteItem:
            pass
        elif action == clearItem:
            pass
        elif action == deleteMrItem:
            pass

    def ShowEditItemForm(self):
        selectedRow = self.dataTableWidget.currentIndex().row()
        if selectedRow != None:
            zdmc = self.dataTableWidget.item(selectedRow, 0).text()
            mcjx = self.dataTableWidget.item(selectedRow, 1).text()
            zdlx = self.dataTableWidget.item(selectedRow, 2).text()
            zddx = self.dataTableWidget.item(selectedRow, 3).text()
            kzlx = self.dataTableWidget.item(selectedRow, 4).text()
            zj = self.dataTableWidget.item(selectedRow, 5).text()
            sfwk = self.dataTableWidget.item(selectedRow, 6).text()
            self.fieldBuildForm.fieldInit(zdmc, mcjx, zdlx, zddx, kzlx, zj,
                                          sfwk)
            self.fieldBuildForm.setWindowModality(Qt.ApplicationModal)
            self.fieldBuildForm.show()

    def EditTableRow(self):
        self.fieldinfo = [
            self.fieldBuildForm.zdmcLineEdit.text(),
            self.fieldBuildForm.mcjxLineEdit.text(),
            self.fieldBuildForm.zdlxComboBox.currentText(),
            self.fieldBuildForm.zddxComboBox.currentText(),
            self.fieldBuildForm.kzlxComboBox.currentText(),
            self.fieldBuildForm.zjComboBox.currentText(),
            self.fieldBuildForm.sfwkComboBox.currentText()
        ]
        self.fieldBuildForm.hide()
        selectedRow = self.dataTableWidget.currentIndex().row()
        if selectedRow != None:
            for index in range(0, len(self.fieldinfo)):
                newitem = QTableWidgetItem(self.fieldinfo[index])
                self.dataTableWidget.setItem(selectedRow, index, newitem)

    def TestTableExist(self):
        tbinfos = self.tbjx.split('.')
        bExistTable = self.m_db.TestDataExist(
            "select count(*) from dba_tables where Owner='" + tbinfos[0] +
            "' and table_name='" + tbinfos[1] + "'")
        if bExistTable > 0:
            QMessageBox.information(self, "数据表检测", "数据表存在!", QMessageBox.Yes)
        else:
            QMessageBox.information(self, "数据表检测", "数据表存在!", QMessageBox.Yes)

    def ReBuildTable(self):
        pass

    def AddTable(self):
        pass

    def ReplaceTable(self):
        pass
Пример #2
0
class PaperEditForm(Ui_PaperEditForm, QWidget):
    parentclicked = pyqtSignal(str)

    def __init__(self, parent=None):
        super(PaperEditForm, self).__init__(parent)
        self.setupUi(self)
        self.m_db = DBUtil()
        kms = self.m_db.GetFieldValueToStrListFromDb(
            "SJMC", "XXFZK.SJBM", "where SJLX=1 order by SXH")
        for km in kms:
            self.comboBox_km.addItem(km)
        stlxs = self.m_db.GetFieldValueToStrListFromDb(
            "SJMC", "XXFZK.SJBM", "where SJLX=2 order by SXH")
        for sjlx in stlxs:
            self.comboBox_stlx.addItem(sjlx)

        self.pushButton_addItem.clicked.connect(self.AddPaperItem)
        self.pushButton_EditPictureTitle.clicked.connect(self.AddTitlePticture)
        self.pushButton_titilepicture_zooout.clicked.connect(
            self.TitlePictureZoomout)
        self.pushButton_titelpicture_zoomin.clicked.connect(
            self.TitlePictureZoomin)
        self.pushButton_AddTitleSubPicture.clicked.connect(
            self.AddTitleSubPicture)
        self.pushButton_titilesubpicture_zooout.clicked.connect(
            self.TitleSubPictureZoomout)
        self.pushButton_titelsubpicture_zoomin.clicked.connect(
            self.TitleSubPictureZoomin)

        self.toolButton_da1.clicked.connect(self.AddPictureAnswer1)
        self.toolButton_da2.clicked.connect(self.AddPictureAnswer2)
        self.toolButton_da3.clicked.connect(self.AddPictureAnswer3)
        self.toolButton_da4.clicked.connect(self.AddPictureAnswer4)
        self.toolButton_da5.clicked.connect(self.AddPictureAnswer5)
        self.toolButton_da6.clicked.connect(self.AddPictureAnswer6)

        self.pushButton_answer_zoomout_1.clicked.connect(
            self.PictureAnswerZoomout1)
        self.pushButton_answer_zoomout_2.clicked.connect(
            self.PictureAnswerZoomout2)
        self.pushButton_answer_zoomout_3.clicked.connect(
            self.PictureAnswerZoomout3)
        self.pushButton_answer_zoomout_4.clicked.connect(
            self.PictureAnswerZoomout4)
        self.pushButton_answer_zoomout_5.clicked.connect(
            self.PictureAnswerZoomout5)
        self.pushButton_answer_zoomout_6.clicked.connect(
            self.PictureAnswerZoomout6)

        self.pushButton_answer_zoomin_1.clicked.connect(
            self.PictureAnswerZoomin1)
        self.pushButton_answer_zoomin_2.clicked.connect(
            self.PictureAnswerZoomin2)
        self.pushButton_answer_zoomin_3.clicked.connect(
            self.PictureAnswerZoomin3)
        self.pushButton_answer_zoomin_4.clicked.connect(
            self.PictureAnswerZoomin4)
        self.pushButton_answer_zoomin_5.clicked.connect(
            self.PictureAnswerZoomin5)
        self.pushButton_answer_zoomin_6.clicked.connect(
            self.PictureAnswerZoomin6)
        self.pushButton_saveanswer.clicked.connect(self.SaveAnswer)
        self.pushButton_saveTitle.clicked.connect(self.SaveTitle)
        self.pushButton_saveRightAnswer.clicked.connect(self.SaveRightAnswer)
        self.pushButton_EditRightPictureAnswer.clicked.connect(
            self.EditPictureAnswer)

        self.editPictureAnswerForm = EditPictureAnswerForm()
        self.parentclicked.connect(self.SendEditPictureAnswerID)
        self.pushButton_testitem.clicked.connect(self.TestItem)

    def AddPaperItem(self):
        try:
            km = self.comboBox_km.currentText()
            stlx = self.comboBox_stlx.currentText()
            bh = self.m_db.GetFieldValueToSingleStrFromDb(
                "max(BH)", "XXFZK.TKB", "")
            if bh == None:
                bh = 0
            fieldnames = ['BH', 'KM', 'STLX']
            fieldvalues = []
            fieldvalues.append(str(bh + 1))
            fieldvalues.append(km)
            fieldvalues.append(stlx)
            id = self.m_db.InsertToTable_NotFullField("XXFZK.TKB", fieldnames,
                                                      fieldvalues)
            self.lineEdit_tmbs.setText(id)
        except:
            print("添加题目时发生错误")

    def AddTitlePticture(self):
        try:
            id = self.lineEdit_tmbs.text()
            if id == "":
                reply = QMessageBox.information(
                    self, "标题", "消息", QMessageBox.Yes | QMessageBox.No)
                return
            else:
                fileName, filetype = QFileDialog.getOpenFileName(
                    self, "QFileDialog.getOpenFileName()", "", "图片文件(*.jpg);")
                #将选中的文件入库
                self.m_db.WriteFileToBlob("TMTP", "XXFZK.TKB",
                                          "where ID='" + id + "'", fileName)
                #修改题目类型为“图片”
                self.m_db.UpdateTable(
                    "update XXFZK.TKB set TMLX='图片' where ID='" + id + "'")
                #显示图片
                image = QPixmap()
                image.load(fileName)
                scene = QGraphicsScene()
                self.title_picture_item = QGraphicsPixmapItem(image)
                scene.addItem(self.title_picture_item)
                self.graphicsView_titlepicture.setScene(scene)
                self.title_picture_zoomscale = 1
        except:
            print("添加题目图片时发生错误")

    def TitlePictureZoomout(self):
        self.title_picture_zoomscale = self.title_picture_zoomscale + 0.05
        if self.title_picture_zoomscale >= 1.2:
            self.title_picture_zoomscale = 1.2
        self.title_picture_item.setScale(self.title_picture_zoomscale)

    def TitlePictureZoomin(self):
        self.title_picture_zoomscale = self.title_picture_zoomscale - 0.05
        if self.title_picture_zoomscale <= 0:
            self.title_picture_zoomscale = 0.2
        self.title_picture_item.setScale(self.title_picture_zoomscale)

    def AddTitleSubPicture(self):
        try:
            id = self.lineEdit_tmbs.text()
            if id == "":
                reply = QMessageBox.information(self, "标题", "试题标识不能为空,请先添加试题!",
                                                QMessageBox.Yes)
                return
            else:
                fileName, filetype = QFileDialog.getOpenFileName(
                    self, "QFileDialog.getOpenFileName()", "", "图片文件(*.jpg);")
                #将选中的文件入库
                self.m_db.WriteFileToBlob("TMPT", "XXFZK.TKB",
                                          "where ID='" + id + "'", fileName)
                #修改题目类型为“图片”
                self.m_db.UpdateTable(
                    "update XXFZK.TKB set YWPT='1' where ID='" + id + "'")
                #显示图片
                image = QPixmap()
                image.load(fileName)
                scene = QGraphicsScene()
                self.title_sub_picture_item = QGraphicsPixmapItem(image)
                scene.addItem(self.title_sub_picture_item)
                self.graphicsView_titlesubpicture.setScene(scene)
                self.title_sub_picture_zoomscale = 1
        except:
            print("添加题目配图时发错误!")

    def TitleSubPictureZoomout(self):
        self.title_sub_picture_zoomscale = self.title_sub_picture_zoomscale + 0.05
        if self.title_sub_picture_zoomscale >= 1.2:
            self.title_sub_picture_zoomscale = 1.2
        self.title_sub_picture_item.setScale(self.title_sub_picture_zoomscale)

    def TitleSubPictureZoomin(self):
        self.title_sub_picture_zoomscale = self.title_sub_picture_zoomscale - 0.05
        if self.title_sub_picture_zoomscale <= 0:
            self.title_sub_picture_zoomscale = 0.2
        self.title_sub_picture_item.setScale(self.title_sub_picture_zoomscale)

    def SaveAnswer(self):
        try:
            id = self.lineEdit_tmbs.text()
            if id == "":
                reply = QMessageBox.information(self, "标题", "试题标识不能为空,请先添加试题!",
                                                QMessageBox.Yes)
                return
            else:
                da1 = self.lineEdit_da1.text()
                da2 = self.lineEdit_da2.text()
                da3 = self.lineEdit_da3.text()
                da4 = self.lineEdit_da4.text()
                da5 = self.lineEdit_da5.text()
                da6 = self.lineEdit_da6.text()
                if da1 == "" and da2 == "" and da3 == "" and da4 == "" and da5 == "" and da6 == "":
                    MESSAGE = "答案不能为空!"
                    reply = QMessageBox.information(self, "标题", MESSAGE,
                                                    QMessageBox.Yes)
                    return
                else:
                    if da1 == "" or da2 == "" or da3 == "" or da4 == "" or da5 == "" or da6 == "":
                        MESSAGE = "部分答案为空,继续保存吗!"
                        reply = QMessageBox.question(
                            None, "QMessageBox.question()", MESSAGE,
                            QMessageBox.Yes | QMessageBox.No)
                        if reply == QMessageBox.No:
                            return
                #保存答案到数据库
                sql = "update XXFZK.TKB set WZDA1='" + da1 + "',WZDA2='" + da2 + "',WZDA3='" + da3 + "',WZDA4='" + da4 + "',WZDA5='" + da5 + "',WZDA6='" + da6 + "' where ID='" + id + "'"
                if (self.m_db.UpdateTable(sql) == None):
                    reply = QErrorMessage(self).showMessage("保存答案失败!")
                else:
                    reply = QMessageBox.information(self, "标题", "保存答案成功!",
                                                    QMessageBox.Yes)
        except:
            print("保存文本答案时发生错误")

    def AddPictureAnswer1(self):
        try:
            id = self.lineEdit_tmbs.text()
            if id == "":
                reply = QMessageBox.information(self, "标题", "试题标识不能为空,请先添加试题!",
                                                QMessageBox.Yes)
                return
            else:
                fileName, filetype = QFileDialog.getOpenFileName(
                    self, "QFileDialog.getOpenFileName()", "", "图片文件(*.jpg);")
                #将选中的文件入库
                self.m_db.WriteFileToBlob("TPDA1", "XXFZK.TKB",
                                          "where ID='" + id + "'", fileName)

                #显示图片
                image = QPixmap()
                image.load(fileName)
                scene = QGraphicsScene()
                self.picture_answer_item1 = QGraphicsPixmapItem(image)
                scene.addItem(self.picture_answer_item1)
                self.graphicsView_da1.setScene(scene)
                self.picture_answer_zoomscale1 = 1
        except:
            print("添加图片答案1时发错误!")

    def AddPictureAnswer2(self):
        try:
            id = self.lineEdit_tmbs.text()
            if id == "":
                reply = QMessageBox.information(self, "标题", "试题标识不能为空,请先添加试题!",
                                                QMessageBox.Yes)
                return
            else:
                fileName, filetype = QFileDialog.getOpenFileName(
                    self, "QFileDialog.getOpenFileName()", "", "图片文件(*.jpg);")
                # 将选中的文件入库
                self.m_db.WriteFileToBlob("TPDA2", "XXFZK.TKB",
                                          "where ID='" + id + "'", fileName)

                # 显示图片
                image = QPixmap()
                image.load(fileName)
                scene = QGraphicsScene()
                self.picture_answer_item2 = QGraphicsPixmapItem(image)
                scene.addItem(self.picture_answer_item2)
                self.graphicsView_da2.setScene(scene)
                self.picture_answer_zoomscale2 = 1
        except:
            print("添加图片答案2时发错误!")

    def AddPictureAnswer3(self):
        try:
            id = self.lineEdit_tmbs.text()
            if id == "":
                reply = QMessageBox.information(self, "标题", "试题标识不能为空,请先添加试题!",
                                                QMessageBox.Yes)
                return
            else:
                fileName, filetype = QFileDialog.getOpenFileName(
                    self, "QFileDialog.getOpenFileName()", "", "图片文件(*.jpg);")
                # 将选中的文件入库
                self.m_db.WriteFileToBlob("TPDA3", "XXFZK.TKB",
                                          "where ID='" + id + "'", fileName)

                # 显示图片
                image = QPixmap()
                image.load(fileName)
                scene = QGraphicsScene()
                self.picture_answer_item3 = QGraphicsPixmapItem(image)
                scene.addItem(self.picture_answer_item3)
                self.graphicsView_da3.setScene(scene)
                self.picture_answer_zoomscale3 = 1
        except:
            print("添加图片答案3时发错误!")

    def AddPictureAnswer4(self):
        try:
            id = self.lineEdit_tmbs.text()
            if id == "":
                reply = QMessageBox.information(self, "标题", "试题标识不能为空,请先添加试题!",
                                                QMessageBox.Yes)
                return
            else:
                fileName, filetype = QFileDialog.getOpenFileName(
                    self, "QFileDialog.getOpenFileName()", "", "图片文件(*.jpg);")
                # 将选中的文件入库
                self.m_db.WriteFileToBlob("TPDA4", "XXFZK.TKB",
                                          "where ID='" + id + "'", fileName)

                # 显示图片
                image = QPixmap()
                image.load(fileName)
                scene = QGraphicsScene()
                self.picture_answer_item4 = QGraphicsPixmapItem(image)
                scene.addItem(self.picture_answer_item4)
                self.graphicsView_da4.setScene(scene)
                self.picture_answer_zoomscale4 = 1
        except:
            print("添加图片答案4时发错误!")

    def AddPictureAnswer5(self):
        try:
            id = self.lineEdit_tmbs.text()
            if id == "":
                reply = QMessageBox.information(self, "标题", "试题标识不能为空,请先添加试题!",
                                                QMessageBox.Yes)
                return
            else:
                fileName, filetype = QFileDialog.getOpenFileName(
                    self, "QFileDialog.getOpenFileName()", "", "图片文件(*.jpg);")
                # 将选中的文件入库
                self.m_db.WriteFileToBlob("TPDA5", "XXFZK.TKB",
                                          "where ID='" + id + "'", fileName)

                # 显示图片
                image = QPixmap()
                image.load(fileName)
                scene = QGraphicsScene()
                self.picture_answer_item5 = QGraphicsPixmapItem(image)
                scene.addItem(self.picture_answer_item5)
                self.graphicsView_da5.setScene(scene)
                self.picture_answer_zoomscale5 = 1
        except:
            print("添加图片答案5时发错误!")

    def AddPictureAnswer6(self):
        try:
            id = self.lineEdit_tmbs.text()
            if id == "":
                reply = QMessageBox.information(self, "标题", "试题标识不能为空,请先添加试题!",
                                                QMessageBox.Yes)
                return
            else:
                fileName, filetype = QFileDialog.getOpenFileName(
                    self, "QFileDialog.getOpenFileName()", "", "图片文件(*.jpg);")
                # 将选中的文件入库
                self.m_db.WriteFileToBlob("TPDA6", "XXFZK.TKB",
                                          "where ID='" + id + "'", fileName)

                # 显示图片
                image = QPixmap()
                image.load(fileName)
                scene = QGraphicsScene()
                self.picture_answer_item6 = QGraphicsPixmapItem(image)
                scene.addItem(self.picture_answer_item6)
                self.graphicsView_da6.setScene(scene)
                self.picture_answer_zoomscale6 = 1
        except:
            print("添加图片答案6时发错误!")

    def PictureAnswerZoomout1(self):
        self.picture_answer_zoomscale1 = self.picture_answer_zoomscale1 + 0.05
        if self.picture_answer_zoomscale1 >= 1.2:
            self.picture_answer_zoomscale1 = 1.2
        self.picture_answer_item1.setScale(self.picture_answer_zoomscale1)

    def PictureAnswerZoomin1(self):
        try:
            self.picture_answer_zoomscale1 = self.picture_answer_zoomscale1 - 0.05
            if self.picture_answer_zoomscale1 <= 0:
                self.picture_answer_zoomscale1 = 0.2
            self.picture_answer_item1.setScale(self.picture_answer_zoomscale1)
        except:
            print("缩小图片答案1时发生错误")

    def PictureAnswerZoomout2(self):
        self.picture_answer_zoomscale2 = self.picture_answer_zoomscale2 + 0.05
        if self.picture_answer_zoomscale2 >= 1.2:
            self.picture_answer_zoomscale2 = 1.2
        self.picture_answer_item2.setScale(self.picture_answer_zoomscale2)

    def PictureAnswerZoomin2(self):
        self.picture_answer_zoomscale2 = self.picture_answer_zoomscale2 - 0.05
        if self.picture_answer_zoomscale2 <= 0:
            self.picture_answer_zoomscale2 = 0.2
        self.picture_answer_item2.setScale(self.picture_answer_zoomscale2)

    def PictureAnswerZoomout3(self):
        self.picture_answer_zoomscale3 = self.picture_answer_zoomscale3 + 0.05
        if self.picture_answer_zoomscale3 >= 1.2:
            self.picture_answer_zoomscale3 = 1.2
        self.picture_answer_item3.setScale(self.picture_answer_zoomscale3)

    def PictureAnswerZoomin3(self):
        self.picture_answer_zoomscale3 = self.picture_answer_zoomscale3 - 0.05
        if self.picture_answer_zoomscale3 <= 0:
            self.picture_answer_zoomscale3 = 0.2
        self.picture_answer_item3.setScale(self.picture_answer_zoomscale3)

    def PictureAnswerZoomout4(self):
        self.picture_answer_zoomscale4 = self.picture_answer_zoomscale4 + 0.05
        if self.picture_answer_zoomscale4 >= 1.2:
            self.picture_answer_zoomscale4 = 1.2
        self.picture_answer_item4.setScale(self.picture_answer_zoomscale4)

    def PictureAnswerZoomin4(self):
        self.picture_answer_zoomscale4 = self.picture_answer_zoomscale4 - 0.05
        if self.picture_answer_zoomscale4 <= 0:
            self.picture_answer_zoomscale4 = 0.2
        self.picture_answer_item4.setScale(self.picture_answer_zoomscale4)

    def PictureAnswerZoomout5(self):
        self.picture_answer_zoomscale5 = self.picture_answer_zoomscale5 + 0.05
        if self.picture_answer_zoomscale5 >= 1.2:
            self.picture_answer_zoomscale5 = 1.2
        self.picture_answer_item5.setScale(self.picture_answer_zoomscale5)

    def PictureAnswerZoomin5(self):
        self.picture_answer_zoomscale5 = self.picture_answer_zoomscale5 - 0.05
        if self.picture_answer_zoomscale5 <= 0:
            self.picture_answer_zoomscale5 = 0.2
        self.picture_answer_item5.setScale(self.picture_answer_zoomscale5)

    def PictureAnswerZoomout6(self):
        self.picture_answer_zoomscale6 = self.picture_answer_zoomscale6 + 0.05
        if self.picture_answer_zoomscale6 >= 1.2:
            self.picture_answer_zoomscale6 = 1.2
        self.picture_answer_item6.setScale(self.picture_answer_zoomscale6)

    def PictureAnswerZoomin6(self):
        self.picture_answer_zoomscale6 = self.picture_answer_zoomscale6 - 0.05
        if self.picture_answer_zoomscale6 <= 0:
            self.picture_answer_zoomscale6 = 0.2
        self.picture_answer_item6.setScale(self.picture_answer_zoomscale6)

    def SaveTitle(self):
        try:
            title = self.lineEdit_tmnr.text()
            if title == "":
                reply = QMessageBox.information(self, "标题", "试题标题不能为空!",
                                                QMessageBox.Yes)
                return
            self.m_db.UpdateTable("update XXFZK.TKB set TMNR='" + title +
                                  "' where ID='" + id + "'")
        except:
            print("保存题目内容时发生错误")

    def SaveRightAnswer(self):
        try:
            righttitle = self.lineEdit_zqda.text()

            if righttitle == "":
                reply = QMessageBox.information(self, "标题", "试题标题不能为空!",
                                                QMessageBox.Yes)
                return
            self.m_db.UpdateTable("update XXFZK.TKB set WZDA='" + righttitle +
                                  "',ZQDALX='文字'  where ID='" + id + "'")
        except:
            print("保存试题正确答案时发生错误")

    def EditPictureAnswer(self):
        try:
            id = self.lineEdit_tmbs.text()
            if id == "":
                reply = QMessageBox.information(self, "标题", "试题标识不能为空,请先添加试题!",
                                                QMessageBox.Yes)
                return
            self.editPictureAnswerForm.show()
            self.parentclicked.emit(id)
        except:
            print("调用图片正确答案时发生错误!")

    def SendEditPictureAnswerID(self, s):
        try:
            self.editPictureAnswerForm.id = s
        except:
            print("发送试题ID发生错误")

    def TestItem(self):
        try:
            id = self.lineEdit_tmbs.text()
            if id == "":
                reply = QMessageBox.information(self, "标题", "试题标识不能为空,请先添加试题!",
                                                QMessageBox.Yes)
                return
            #试题类型、科目不能为空
            stlx = self.m_db.GetFieldValueToSingleStrFromDb(
                "STLX", "XXFZK.TKB", "where ID='" + id + "'")
            km = self.m_db.GetFieldValueToSingleStrFromDb(
                "KM", "XXFZK.TKB", "where ID='" + id + "'")
            if stlx == "":
                reply = QMessageBox.information(self, "错误", "试题类型不能为空!",
                                                QMessageBox.Yes)
                return
            if km == "":
                reply = QMessageBox.information(self, "错误", "科目不能为空!",
                                                QMessageBox.Yes)
                return
            #如果题目类型是文字,题目内容不能为空,如果是图片,检查图片是否存在
            tmlx = self.m_db.GetFieldValueToSingleStrFromDb(
                "TMLX", "XXFZK.TKB", "where ID='" + id + "'")
            if tmlx == "文字":
                tmnr = self.m_db.GetFieldValueToSingleStrFromDb(
                    "TMNR", "XXFZK.TKB", "where ID='" + id + "'")
                if tmnr == "":
                    reply = QMessageBox.information(self, "错误", "题目内容不能为空!",
                                                    QMessageBox.Yes)
                    return
            elif tmlx == "图片":
                pass
            #检查答案

        except Exception as e:
            print("检查试题信息时发生错误" + e.Message)
Пример #3
0
class DataManagerForm(QWidget):
    def __init__(self):
        super(DataManagerForm,self).__init__()
        self.initUi()
    def initUi(self):
        # 获取显示器分辨率
        self.desktop = QApplication.desktop()
        self.screenRect = self.desktop.screenGeometry()
        self.height = self.screenRect.height()
        self.width = self.screenRect.width()
        self.resize(self.width, self.height)
        self.setWindowTitle("数据管理")

        mainLayout=QVBoxLayout()
        centerLayout=QVBoxLayout()
        self.bottomLayout=QHBoxLayout()
        mainLayout.addLayout(centerLayout)
        mainLayout.addLayout(self.bottomLayout)

        self.dataTableWidget = QTableWidget()
        centerLayout.addWidget(self.dataTableWidget)

        self.m_db=DBUtil()
        self.setLayout(mainLayout)

        self.dataTableWidget.setContextMenuPolicy(Qt.CustomContextMenu)
        self.dataTableWidget.customContextMenuRequested.connect(self.GenerateMenu)


    def data_init(self,tbid,tbmc,tbjx):
        self.tbid=tbid
        self.tbjx=tbjx
        self.tbmc=tbmc
        self.fieldnamelist=self.m_db.GetFieldValueToStrListFromDb("ZDMC","XTGLK.ZLFL_MSFF_FIELD","where TBID='"+tbid+"' and MCJX not in('FLID','MJ','SJLY','SJSJ','LRSJ') order by SXH")
        self.fieldlist=self.m_db.GetFieldValueToStrListFromDb("MCJX","XTGLK.ZLFL_MSFF_FIELD","where TBID='"+tbid+"' and MCJX not in('FLID','MJ','SJLY','SJSJ','LRSJ') order by SXH")
        self.field_kzlx_list=self.m_db.GetFieldValueToStrListFromDb("KZLX","XTGLK.ZLFL_MSFF_FIELD","where TBID='"+tbid+"' and MCJX not in('FLID','ID','MJ','SJLY','SJSJ','LRSJ') order by SXH")
        self.field_zdlx_list = self.m_db.GetFieldValueToStrListFromDb("ZDLX", "XTGLK.ZLFL_MSFF_FIELD", "where TBID='" + tbid + "' and MCJX not in('FLID','ID','MJ','SJLY','SJSJ','LRSJ') order by SXH")
        self.link_field_list=[]
        for fieldindex in range(0,len(self.fieldlist)):
            link_field=self.m_db.GetFieldValueToSingleStrFromDb('NBGLZD','XTGLK.ZLFL_MSFF_FIELD_INFO',"where TBID='" + tbid + "' and ZDMC='"+self.fieldlist[fieldindex]+"'")
            if link_field==None:
                link_field=''
            self.link_field_list.append(link_field)
        mrzinfo_list=self.m_db.GetFieldValueToStrGroupsFromDb('ZDMC,MRZ',"XTGLK.ZLFL_MSFF_FIELD_INFO", "where TBID='" + tbid + "'")
        self.mrzd_list=mrzinfo_list[0]
        self.mrz_list=mrzinfo_list[1]
        self.fieldvalue_list=[]
        for fieldindex in range(0,len(self.fieldlist)):
            self.fieldvalue_list.append('')
        for fieldindex in range(0,len(self.fieldlist)):
            fieldname=self.fieldlist[fieldindex]
            mrzd_index=self.mrzd_list.index(fieldname)
            if mrzd_index!=None:
                mrz=self.mrz_list[mrzd_index]
                if mrz!=None:
                    self.fieldvalue_list[fieldindex]=mrz

        fieldcount=len(self.fieldnamelist)
        self.dataTableWidget.setColumnCount(fieldcount)
        self.dataTableWidget.setHorizontalHeaderLabels(self.fieldnamelist)
        self.dataTableWidget.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
        self.dataTableWidget.setEditTriggers(QAbstractItemView.NoEditTriggers)
        self.dataTableWidget.setSelectionBehavior(QAbstractItemView.SelectRows)

        self.dataCount=self.m_db.GetRowCount("select * from "+tbjx)
        self.setWindowTitle(self.tbmc+"(共有"+str(self.dataCount)+"条记录)")
        self.rowcount_page=5
        self.page_count=self.dataCount//self.rowcount_page
        self.currentPageIndex=1
        page_rest=self.dataCount%self.rowcount_page
        if page_rest>0:
            self.page_count+=1
        self.page10_count=self.page_count//10
        page10_rest=self.page_count%10
        if page10_rest>0:
            self.page10_count+=1
        self.current_10PageIndex=1

        self.pageButton_forword=QPushButton(str("<<"))
        self.bottomLayout.addWidget(self.pageButton_forword)
        self.pageButton_forword.clicked.connect(lambda :self.readData(self.pageButton_forword))
        self.pageButton_forword.setFixedWidth(30)

        self.pageButton_first=QPushButton(str("|<"))
        self.bottomLayout.addWidget(self.pageButton_first)
        self.pageButton_first.clicked.connect(lambda :self.readData(self.pageButton_first))
        self.pageButton_first.setFixedWidth(30)

        self.pageButton_before=QPushButton(str("<"))
        self.bottomLayout.addWidget(self.pageButton_before)
        self.pageButton_before.clicked.connect(lambda :self.readData(self.pageButton_before))
        self.pageButton_before.setFixedWidth(30)


        self.pageButton1=QPushButton(str("1"))
        self.bottomLayout.addWidget(self.pageButton1)
        self.pageButton1.clicked.connect(lambda :self.readData(self.pageButton1))
        self.pageButton1.setFixedWidth(30)

        self.pageButton2=QPushButton(str("2"))
        self.bottomLayout.addWidget(self.pageButton2)
        self.pageButton2.clicked.connect(lambda :self.readData(self.pageButton2))
        self.pageButton2.setFixedWidth(30)

        self.pageButton3=QPushButton(str("3"))
        self.bottomLayout.addWidget(self.pageButton3)
        self.pageButton3.clicked.connect(lambda :self.readData(self.pageButton3))
        self.pageButton3.setFixedWidth(30)

        self.pageButton4=QPushButton(str("4"))
        self.bottomLayout.addWidget(self.pageButton4)
        self.pageButton4.clicked.connect(lambda :self.readData(self.pageButton4))
        self.pageButton4.setFixedWidth(30)

        self.pageButton5=QPushButton(str("5"))
        self.bottomLayout.addWidget(self.pageButton5)
        self.pageButton5.clicked.connect(lambda :self.readData(self.pageButton5))
        self.pageButton5.setFixedWidth(30)

        self.pageButton6=QPushButton(str("6"))
        self.bottomLayout.addWidget(self.pageButton6)
        self.pageButton6.clicked.connect(lambda :self.readData(self.pageButton6))
        self.pageButton6.setFixedWidth(30)

        self.pageButton7=QPushButton(str("7"))
        self.bottomLayout.addWidget(self.pageButton7)
        self.pageButton7.clicked.connect(lambda :self.readData(self.pageButton7))
        self.pageButton7.setFixedWidth(30)

        self.pageButton8=QPushButton(str("8"))
        self.bottomLayout.addWidget(self.pageButton8)
        self.pageButton8.clicked.connect(lambda :self.readData(self.pageButton8))
        self.pageButton8.setFixedWidth(30)

        self.pageButton9=QPushButton(str("9"))
        self.bottomLayout.addWidget(self.pageButton9)
        self.pageButton9.clicked.connect(lambda :self.readData(self.pageButton9))
        self.pageButton9.setFixedWidth(30)

        self.pageButton10=QPushButton(str("10"))
        self.bottomLayout.addWidget(self.pageButton10)
        self.pageButton10.clicked.connect(lambda :self.readData(self.pageButton10))
        self.pageButton10.setFixedWidth(30)

        self.pageButton_next=QPushButton(str(">"))
        self.bottomLayout.addWidget(self.pageButton_next)
        self.pageButton_next.clicked.connect(lambda :self.readData(self.pageButton_next))
        self.pageButton_next.setFixedWidth(30)

        self.pageButton_end=QPushButton(str(">|"))
        self.bottomLayout.addWidget(self.pageButton_end)
        self.pageButton_end.clicked.connect(lambda :self.readData(self.pageButton_end))
        self.pageButton_end.setFixedWidth(30)

        self.pageButton_backword=QPushButton(str(">>"))
        self.bottomLayout.addWidget(self.pageButton_backword)
        self.pageButton_backword.clicked.connect(lambda :self.readData(self.pageButton_backword))
        self.pageButton_backword.setFixedWidth(30)

        self.pageButtons=[self.pageButton1,self.pageButton2,self.pageButton3,self.pageButton4,self.pageButton5,self.pageButton6,self.pageButton7,self.pageButton8,self.pageButton9,self.pageButton10]

        for page_index in range(0,11):
            if self.page_count>=page_index:
                self.pageButtons[page_index-1].setEnabled(1)
            else:
                self.pageButtons[page_index-1].setEnabled(0)

        perPageLabel=QLabel("每页")
        self.perPageLineEdit=QLineEdit()
        perPageRowLabel=QLabel("行")

        self.bottomLayout.addWidget(perPageLabel)
        self.bottomLayout.addWidget(self.perPageLineEdit)
        self.bottomLayout.addWidget(perPageRowLabel)
        self.perPageLineEdit.textChanged.connect(self.RowPerPageChanged)
        self.perPageLineEdit.setText('5')

        pIntValidator=QIntValidator(self)
        pIntValidator.setRange(1,100)
        self.perPageLineEdit.setValidator(pIntValidator)
        self.perPageLineEdit.setFixedWidth(40)


        whichPageLabel=QLabel("第")
        self.whichPageComboBox=QComboBox()
        whichPageRowLabel=QLabel("页")

        self.bottomLayout.addWidget(whichPageLabel)
        self.bottomLayout.addWidget(self.whichPageComboBox)
        self.bottomLayout.addWidget(whichPageRowLabel)
        self.whichPageComboBox.currentIndexChanged.connect(self.PageSelectChanged)

        for page in range(1,self.page_count+1):
            self.whichPageComboBox.addItem(str(page))

        pIntValidator=QIntValidator(self)
        pIntValidator.setRange(1,100)
        self.perPageLineEdit.setValidator(pIntValidator)
        self.perPageLineEdit.setFixedWidth(40)

        self.addRowButton=QPushButton("添加")
        self.delRowButton=QPushButton("删除")
        self.editRowButton=QPushButton("编辑")
        self.clearRowButton=QPushButton("清空")

        self.bottomLayout.addWidget(self.addRowButton)
        self.bottomLayout.addWidget(self.editRowButton)
        self.bottomLayout.addWidget(self.delRowButton)
        self.bottomLayout.addWidget(self.clearRowButton)

        self.addRowButton.clicked.connect(self.AddNewRow)
        self.editRowButton.clicked.connect(self.EditRow)
        self.delRowButton.clicked.connect(self.DelRow)
        self.clearRowButton.clicked.connect(self.ClearRows)



    def readData(self,btn):
        try:
            self.dataTableWidget.setRowCount(0)
            page=btn.text()
            #转到上一个10页
            if page=="<<":
                self.Go_Forward()
            elif page=="|<":
                self.Go_First()
            elif page=="<":
                if self.currentPageIndex>1:
                    self.currentPageIndex-=1
                    start_page=(self.current_10PageIndex-1)*10+1
                    end_page=self.current_10PageIndex*10
                    if self.currentPageIndex<start_page:
                        self.current_10PageIndex-=1
                        start_page=(self.current_10PageIndex-1)*10+1
                        end_page=self.current_10PageIndex*10
                        for page_index in range(start_page,end_page):
                            self.pageButtons[page_index-1].setText(str(page_index))
                        for page_index in range(0,11):
                            if self.page_count>=page_index:
                                self.pageButtons[page_index-1].setEnabled(1)
                            else:
                                self.pageButtons[page_index-1].setEnabled(0)
                    self.ReadDataInPage(str(self.currentPageIndex))
            elif page==">>":
                self.Go_Backward()
            elif page==">|":
                self.Go_Last()
            elif page==">":
                if self.currentPageIndex<self.page_count:
                    self.currentPageIndex+=1
                    start_page=(self.current_10PageIndex-1)*10+1
                    end_page=self.current_10PageIndex*10
                    if self.currentPageIndex>end_page:
                        self.current_10PageIndex+=1
                        start_page=(self.current_10PageIndex-1)*10+1
                        end_page=self.current_10PageIndex*10

                        for page_index in range(start_page,end_page):
                            self.pageButtons[page_index-1].setText(str(page_index))
                        for page_index in range(0,11):
                            if self.page_count>=page_index:
                                self.pageButtons[page_index-1].setEnabled(1)
                            else:
                                self.pageButtons[page_index-1].setEnabled(0)
                    self.ReadDataInPage(str(self.currentPageIndex))
            else:
                self.ReadDataInPage(page)
        except Exception as e:
            print("读取数据发生错误",e)
    def ReadDataInPage(self,page):
        iPage=int(page)
        self.currentPageIndex=iPage
        field=','.join(self.fieldlist)
        minrow=(iPage-1)*self.rowcount_page

        maxrow=iPage*self.rowcount_page
        fieldinfo=self.m_db.GetFieldValueToStrGroupsFromDbByRange(field,self.tbjx,"",minrow,maxrow)
        if fieldinfo!=None:
            if len(fieldinfo)>0:
                if len(fieldinfo[0])>0:
                    self.dataTableWidget.setRowCount(len(fieldinfo[0]))
                    for fieldvalueindex in range(0,len(fieldinfo[0])):
                        for fieldindex in range(0,len(self.fieldlist)):
                            fieldvalues=fieldinfo[fieldindex]
                            if len(fieldvalues)>0:
                                newitem=QTableWidgetItem(str(fieldvalues[fieldvalueindex]))
                                self.dataTableWidget.setItem(fieldvalueindex,fieldindex,newitem)

    def Go_Forward(self):
        try:
            if self.page_count<=10:
                    return
            else:
                if self.page10_count-self.current_10PageIndex>0:
                    self.current_10PageIndex+=1
                    start_page=(self.current_10PageIndex-1)*10+1
                    end_page=self.current_10PageIndex*10
                    for page_index in range(start_page,end_page):
                        self.pageButtons[page_index-1].setText(str(page_index))
                    for page_index in range(0,11):
                        if self.page_count>=page_index:
                            self.pageButtons[page_index-1].setEnabled(1)
                        else:
                            self.pageButtons[page_index-1].setEnabled(0)
                else:
                    return
        except Exception as e:
            print("向前翻页发生错误!")

    def Go_Backward(self):
        try:
            if self.page_count<=10:
                    return
            else:
                if self.current_10PageIndex>1:
                    self.current_10PageIndex-=1
                    start_page=(self.current_10PageIndex-1)*10+1
                    end_page=self.current_10PageIndex*10
                    for page_index in range(start_page,end_page):
                        self.pageButtons[page_index-1].setText(str(page_index))
                    for page_index in range(0,11):
                        if self.page_count>=page_index:
                            self.pageButtons[page_index-1].setEnabled(1)
                        else:
                            self.pageButtons[page_index-1].setEnabled(0)
                else:
                    return
        except Exception as e:
            print("向前翻页发生错误!")
    def Go_Last(self):
        self.ReadDataInPage(str(self.page_count))
        self.currentPageIndex=self.page_count
        self.current_10PageIndex=self.page10_count
        start_page=(self.current_10PageIndex-1)*10+1
        end_page=self.current_10PageIndex*10

        for page_index in range(start_page,end_page):
            self.pageButtons[page_index-1].setText(str(page_index))
        for page_index in range(0,11):
            if self.page_count>=page_index:
                self.pageButtons[page_index-1].setEnabled(1)
            else:
                self.pageButtons[page_index-1].setEnabled(0)
    def Go_First(self):
        self.ReadDataInPage("1")
        self.currentPageIndex=1
        self.current_10PageIndex=1
        start_page=(self.current_10PageIndex-1)*10+1
        end_page=self.current_10PageIndex*10

        for page_index in range(start_page,end_page):
            self.pageButtons[page_index-1].setText(str(page_index))
        for page_index in range(0,11):
            if self.page_count>=page_index:
                self.pageButtons[page_index-1].setEnabled(1)
            else:
                self.pageButtons[page_index-1].setEnabled(0)
    def RowPerPageChanged(self):
        try:
            rowperpage=self.perPageLineEdit.text()
            if rowperpage!='':
                self.rowcount_page=int(self.perPageLineEdit.text())
                self.page_count=self.dataCount//self.rowcount_page
                self.currentPageIndex=1
                page_rest=self.dataCount%self.rowcount_page
                if page_rest>0:
                    self.page_count+=1
                self.page10_count=self.page_count//10
                page10_rest=self.page_count%10
                if page10_rest>0:
                    self.page10_count+=1
                self.current_10PageIndex=1
                start_page=(self.current_10PageIndex-1)*10+1
                end_page=self.current_10PageIndex*10
                for page_index in range(start_page,end_page):
                    self.pageButtons[page_index-1].setText(str(page_index))
                for page_index in range(0,11):
                    if self.page_count>=page_index:
                        self.pageButtons[page_index-1].setEnabled(1)
                    else:
                        self.pageButtons[page_index-1].setEnabled(0)
        except Exception as e:
            print("更改每页行数发生错误",e)
    def PageSelectChanged(self):
        page=self.whichPageComboBox.currentText()
        if page!='':
            self.ReadDataInPage(page)
    def AddNewRow(self):
        try:
            fieldnames=[]
            for field in self.fieldlist:
                if field!='ID':
                    fieldnames.append(field)
            rowid=self.m_db.InsertToTable_NotFullField(self.tbjx,fieldnames,self.fieldvalue_list)
            if rowid!=None or rowid!='':
                self.refreshDataInfo()
                self.Go_First()
            else:
                print("数据添加失败!")
        except Exception as e:
            print("添加数据行时发生错误!",e)
    def EditRow(self):
        try:
            selectedRow=self.dataTableWidget.currentIndex().row()
            if selectedRow==None:
                return
            fieldvalues=[]
            for fieldindex in range(0,len(self.fieldnamelist)):
                rowvalue=self.dataTableWidget.item(selectedRow,fieldindex).text()
                fieldvalues.append(rowvalue)
            self.rowEditForm=RowEditForm()
            self.rowEditForm.row_init(self.fieldnamelist,self.fieldlist,self.field_zdlx_list,fieldvalues,self.field_kzlx_list,self.tbjx,self.tbid)
            self.rowEditForm.showMaximized()

        except Exception as e:
            print("编辑数据行时发生错误!",e)
    def DelRow(self):
        try:
            selectedRow=self.dataTableWidget.currentIndex().row()
            if selectedRow==None:
                return
            rowid=self.dataTableWidget.item(selectedRow,len(self.fieldlist)-1).text()

            MESSAGE = "疑问"
            reply = QMessageBox.question(None,MESSAGE, "确认删除当前选中的数据行吗?",QMessageBox.Yes | QMessageBox.No)
            if reply == QMessageBox.Yes:
                self.m_db.UpdateTable("delete from "+self.tbjx+" where ID='"+rowid+"'")
                self.refreshDataInfo()
                self.Go_Last()

        except Exception as e:
            print("删除数据行时发生错误!",e)
    def ClearRows(self):
        try:
            MESSAGE = "疑问"
            reply = QMessageBox.question(None, "确认删除所有数据吗?",MESSAGE,QMessageBox.Yes | QMessageBox.No)
            if reply == QMessageBox.Yes:
                self.m_db.UpdateTable("delete from "+self.tbjx)
                self.refreshDataInfo()
                self.dataTableWidget.setRowCount(0)

        except Exception as e:
            print("清空数据行时发生错误!",e)
    def refreshDataInfo(self):
        self.dataCount=self.m_db.GetRowCount("select * from "+self.tbjx)
        self.setWindowTitle(self.tbmc+"(共有"+str(self.dataCount)+"条记录)")
        self.page_count=self.dataCount//self.rowcount_page
        self.currentPageIndex=1
        page_rest=self.dataCount%self.rowcount_page
        if page_rest>0:
            self.page_count+=1
        self.page10_count=self.page_count//10
        page10_rest=self.page_count%10
        if page10_rest>0:
            self.page10_count+=1
        self.current_10PageIndex=1

        for page_index in range(0,11):
            if self.page_count>=page_index:
                self.pageButtons[page_index-1].setEnabled(1)
            else:
                self.pageButtons[page_index-1].setEnabled(0)
        self.whichPageComboBox.clear()
        for page_count in range(0,self.page_count):
            self.whichPageComboBox.addItem(str(page_count+1))
    def GenerateMenu(self,pos):
        menu=QMenu()
        addMenuItem=menu.addAction(u"添加")
        editMenuItem=menu.addAction(u"编辑")
        delMenuItem=menu.addAction(u"删除")
        action=menu.exec_(self.dataTableWidget.mapToGlobal(pos))
        if action==addMenuItem:
            self.AddNewRow()
        elif action==delMenuItem:
            self.DelRow()
        elif action==editMenuItem:
            self.EditRow()
        else:
            return
Пример #4
0
class PaperManagerForm(QWidget):
    def __init__(self):
        super(PaperManagerForm, self).__init__()
        self.initUi()

    def initUi(self):
        try:
            # 获取显示器分辨率
            self.desktop = QApplication.desktop()
            self.screenRect = self.desktop.screenGeometry()
            self.height = self.screenRect.height()
            self.width = self.screenRect.width()
            self.resize(self.width, self.height)
            self.setWindowTitle("试题管理")

            #layout_init
            mainLayout = QHBoxLayout()
            self.setLayout(mainLayout)
            leftLayout = QVBoxLayout()
            self.subjectListGroupBox = QGroupBox("科目列表")
            self.subjectlistLayout = QVBoxLayout()
            self.subjectListGroupBox.setLayout(self.subjectlistLayout)
            self.subjectListTree = QTreeWidget()
            self.subjectlistLayout.addWidget(self.subjectListTree)

            self.readSubejctButton = QPushButton("读取科目")
            self.readQuestionButton = QPushButton("读取试题")
            self.dataClassButton = QPushButton("DataClss")
            leftLayout.addWidget(self.subjectListGroupBox)

            leftBottomLayout = QHBoxLayout()

            leftBottomLayout.addWidget(self.readSubejctButton)
            leftBottomLayout.addWidget(self.readQuestionButton)
            leftBottomLayout.addWidget(self.dataClassButton)
            leftLayout.addLayout(leftBottomLayout)

            centerLayout = QVBoxLayout()
            self.questionListGroupBox = QGroupBox("试题列表")
            self.questionlistLayout = QVBoxLayout()

            self.questionListGroupBox.setLayout(self.questionlistLayout)
            self.questionTable = QTableWidget()
            self.questionlistLayout.addWidget(self.questionTable)
            centerLayout.addWidget(self.questionListGroupBox)

            mainLayout.addLayout(leftLayout)
            mainLayout.addLayout(centerLayout)

            #tree_init
            self.m_db = DBUtil()
            # 设置列数
            self.subjectListTree.setColumnCount(2)
            self.subjectListTree.setHeaderLabels(['科目', 'ID'])
            # 设置树形控件的列的宽度
            self.subjectListTree.setColumnWidth(0, 150)

            # 设置根节点

            # TODO 优化3 给节点添加响应事件
            #self.subjectListTree.clicked.connect(self.onClicked)

            self.createRightMenu()
            self.readSubejctButton.clicked.connect(self.ReadSubject)
            self.readQuestionButton.clicked.connect(self.ReadQuestion)

            self.dataClassButton.clicked.connect(self.DataClassManage)
            self.dataClassForm = DataClassForm()

        except Exception as e:
            print(e.Message)

    def ReadSubject(self):
        try:
            self.subjectListTree.clear()
            kms = self.m_db.GetFieldValueToStrListFromDb(
                "SJMC", "XXFZK.SJBM", "where SJLX=1 order by SXH")
            for km in kms:
                root = QTreeWidgetItem(self.subjectListTree)
                root.setText(0, km)
                root.setText(1, km + '_root')
                # root.setIcon(0, QIcon('./images/root.png'))
                # todo 优化2 设置根节点的背景颜色
                brush_red = QBrush(Qt.red)
                root.setBackground(0, brush_red)
                brush_blue = QBrush(Qt.white)
                root.setBackground(1, brush_blue)
                # 加载根节点的所有属性与子控件
                self.subjectListTree.addTopLevelItem(root)
                self.BuildSubjectTree(km + '_root', root)
            # 节点全部展开
            self.subjectListTree.expandAll()

        except Exception as e:
            print("读取科目信息时发生错误", e.Message)

    def createRightMenu(self):
        self.subjectListTree.setContextMenuPolicy(Qt.CustomContextMenu)
        self.subjectListTree.customContextMenuRequested.connect(
            self.showRightMenu)
        self.rightMenu = QMenu(self.subjectListTree)

        addChapterMenuItem = self.rightMenu.addAction("添加科目")
        addChapterMenuItem.triggered.connect(self.AddSubjectAct)
        addChapterMenuItem = self.rightMenu.addAction("添加章节")
        addChapterMenuItem.triggered.connect(self.AddChapterAct)
        addChapterMenuItem = self.rightMenu.addAction("删除")
        addChapterMenuItem.triggered.connect(self.DelChapterAct)

    def showRightMenu(self, pos):
        try:
            self.rightMenu.exec(QCursor.pos())
            self.rightMenu.show()
        except:
            print("error")

    def AddChapterAct(self):
        selectItem = self.subjectListTree.currentItem()
        nodeID = selectItem.text(1)
        nodeText = selectItem.text(0)
        parentItem = selectItem.parent()
        while 1:
            if parentItem == None:
                break
            parentItem = selectItem.parent()
        if parentItem == None:
            km = nodeText
        else:
            km = parentItem.text(0)

        text, ok = QInputDialog.getText(None, "输入章节名称", "章节名称:",
                                        QLineEdit.Normal, "")
        if ok and text:
            bExist = self.m_db.TestDataExist(
                "select * from XXFZK.ZJ where KM='" + km + "' and MC='" +
                text + "'")
            if bExist > 0:
                QMessageBox.information(self, "添加章节", "章节已经存在",
                                        QMessageBox.Yes | QMessageBox.No)
                return
            fieldvaluelist = [text, km, nodeID]
            id = self.m_db.InsertToOracle("XXFZK.ZJ", fieldvaluelist)

            child = QTreeWidgetItem(selectItem)
            child.setText(0, text)
            child.setText(1, id)

    def AddSubjectAct(self):
        text, ok = QInputDialog.getText(None, "输入科目名称", "科目名称:",
                                        QLineEdit.Normal, "")
        if ok and text:
            #判断是否存在科目
            bExist = self.m_db.TestDataExist(
                "select * from XXFZK.SJBM where SJLX=1 and SJMC='" + text +
                "'")
            if bExist > 0:
                QMessageBox.information(self, "添加科目", "科目已经存在",
                                        QMessageBox.Yes | QMessageBox.No)
                return

            sxh = self.m_db.GetFieldValueToSingleStrFromDb(
                'max(SXH)', 'XXFZK.SJBM', 'where SJLX=1')
            if sxh == None:
                sxh = 0
            sxh += 1
            fieldvaluelist = ['1', '科目', str(sxh), text, '']
            self.m_db.InsertToOracle("XXFZK.SJBM", fieldvaluelist)

            root = QTreeWidgetItem(self.subjectListTree)
            root.setText(0, text)
            root.setText(1, text + '_root')
            # root.setIcon(0, QIcon('./images/root.png'))
            # todo 优化2 设置根节点的背景颜色
            brush_red = QBrush(Qt.red)
            root.setBackground(0, brush_red)
            brush_blue = QBrush(Qt.white)
            root.setBackground(1, brush_blue)
            # 加载根节点的所有属性与子控件
            self.subjectListTree.addTopLevelItem(root)

    def BuildSubjectTree(self, sjid, parentItem):
        try:
            zjs = self.m_db.GetFieldValueToStrGroupsFromDb(
                "MC,ID", "XXFZK.ZJ", "where SJID='" + sjid + "'")
            if len(zjs) != 0:
                mcs = zjs[0]
                ids = zjs[1]
                if len(mcs) != 0:
                    for index in range(0, len(mcs)):
                        mc = mcs[index]
                        id = ids[index]
                        # 设置子节点3
                        child = QTreeWidgetItem(parentItem)
                        child.setText(0, mc)
                        child.setText(1, id)
                        #child.setIcon(0, QIcon('./images/music.png'))
                        self.BuildSubjectTree(id, child)
        except Exception as e:
            print(e.Message)

    def DelChapterAct(self):
        try:
            selectItem = self.subjectListTree.currentItem()
            nodeID = selectItem.text(1)
            nodeText = selectItem.text(0)
            if nodeID == nodeText + "_root":
                MESSAGE = "确认删除当前的科目吗?"
                reply = QMessageBox.question(None, "QMessageBox.question()",
                                             MESSAGE,
                                             QMessageBox.Yes | QMessageBox.No)
                if reply == QMessageBox.No:
                    return
                self.m_db.UpdateTable(
                    "delete from XXFZK.SJBM where SJLX=1 and SJMC='" +
                    nodeText + "'")
                index = self.subjectListTree.indexOfTopLevelItem(selectItem)
                selectItem.takeChildren()
                self.subjectListTree.takeTopLevelItem(index)
                #删除此根节点下所有章节
                self.m_db.UpdateTable("delete from XXFZK.ZJ where KM='" +
                                      nodeText + "'")
            else:
                MESSAGE = "确认删除当前的章节吗?"
                reply = QMessageBox.question(None, "QMessageBox.question()",
                                             MESSAGE,
                                             QMessageBox.Yes | QMessageBox.No)
                if reply == QMessageBox.No:
                    return
                self.m_db.UpdateTable("delete from XXFZK.ZJ where MC='" +
                                      nodeText + "'")
                index = selectItem.parent().indexOfChild(selectItem)
                selectItem.parent().takeChild(index)
                #删除此节点下所有节点

        except Exception as e:
            print(e.Message)

    def ReadQuestion(self):
        try:
            selectItem = self.subjectListTree.currentItem()
            nodeID = selectItem.text(1)
            nodeText = selectItem.text(0)
            #获取父节点
            parentItem = selectItem.parent()
            while 1:
                if parentItem == None:
                    break
                parentItem = selectItem.parent()
            if parentItem == None:
                km = nodeText
            else:
                km = parentItem.text(0)

            child_ids = self.ReadChildIDs(nodeID)
            child_ids.append(nodeID)
            condition = StringUtil.ChangeListToCondition(child_ids)
            #if condition=="":

        except Exception as e:
            print("读取试题发生错误:" + e.Message)

    def ReadChildIDs(self, sjid):
        try:
            childIDs = []
            ids = self.m_db.GetFieldValueToStrListFromDb(
                "ID", "XXFZK.ZJ", "where SJID='" + sjid + "'")
            if len(ids) > 0:
                childIDs.append(ids)
                for id in ids:
                    subIDs = self.ReadChildIDs(id)
                    if len(subIDs) > 0:
                        childIDs.append(subIDs)
            return childIDs
        except Exception as e:
            print("获取子节点时发生错误:" + e.Message)

    def DataClassManage(self):
        self.dataClassForm.show()