From a7941d69c8781bd728e6f8a1f5de15b1a9ace417 Mon Sep 17 00:00:00 2001 From: "weiye.wang" Date: Wed, 1 May 2024 16:17:25 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E7=9B=AE=E6=A0=87=E5=85=B3=E7=B3=BB=20=E5=8A=9F=E8=83=BD(?= =?UTF-8?q?=E5=BD=95=E5=85=A5=E5=89=8D=E5=BA=8F=E5=85=B3=E7=B3=BB)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 工具v4/Ui_tool_panel.py | 20 +++-- 工具v4/Ui_新增目标关系.py | 86 +++++++++++++++++++++ 工具v4/tool_panel.py | 8 +- 工具v4/tool_panel.ui | 21 ++++-- 工具v4/新增目标关系.py | 104 ++++++++++++++++++++++++++ 工具v4/新增目标关系.ui | 152 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 374 insertions(+), 17 deletions(-) create mode 100644 工具v4/Ui_新增目标关系.py create mode 100644 工具v4/新增目标关系.py create mode 100644 工具v4/新增目标关系.ui diff --git a/工具v4/Ui_tool_panel.py b/工具v4/Ui_tool_panel.py index 3860064c..769d10c1 100644 --- a/工具v4/Ui_tool_panel.py +++ b/工具v4/Ui_tool_panel.py @@ -142,6 +142,9 @@ class Ui_MainWindow(object): self.tab_xgmb = QWidget() self.tab_xgmb.setObjectName(u"tab_xgmb") self.tabWidget_mubiaojichu.addTab(self.tab_xgmb, "") + self.tab_xzgx = QWidget() + self.tab_xzgx.setObjectName(u"tab_xzgx") + self.tabWidget_mubiaojichu.addTab(self.tab_xzgx, "") self.tab_scgx = QWidget() self.tab_scgx.setObjectName(u"tab_scgx") self.tabWidget_mubiaojichu.addTab(self.tab_scgx, "") @@ -199,14 +202,14 @@ class Ui_MainWindow(object): self.retranslateUi(MainWindow) - self.tabWidget_main.setCurrentIndex(5) - self.tabWidget_luru.setCurrentIndex(2) - self.tabWidget_weihu.setCurrentIndex(3) - self.tabWidget_shiyong.setCurrentIndex(1) - self.tabWidget_beikezu.setCurrentIndex(2) - self.tabWidget_latex.setCurrentIndex(1) - self.tabWidget_mubiaojichu.setCurrentIndex(3) - self.tabWidget_syjl.setCurrentIndex(5) + self.tabWidget_main.setCurrentIndex(0) + self.tabWidget_luru.setCurrentIndex(0) + self.tabWidget_weihu.setCurrentIndex(0) + self.tabWidget_shiyong.setCurrentIndex(0) + self.tabWidget_beikezu.setCurrentIndex(0) + self.tabWidget_latex.setCurrentIndex(0) + self.tabWidget_mubiaojichu.setCurrentIndex(0) + self.tabWidget_syjl.setCurrentIndex(0) QMetaObject.connectSlotsByName(MainWindow) @@ -239,6 +242,7 @@ class Ui_MainWindow(object): self.tabWidget_mubiaojichu.setTabText(self.tabWidget_mubiaojichu.indexOf(self.tab_tjjc), QCoreApplication.translate("MainWindow", u"\u65b0\u589e\u57fa\u7840", None)) self.tabWidget_mubiaojichu.setTabText(self.tabWidget_mubiaojichu.indexOf(self.tab_bjjc), QCoreApplication.translate("MainWindow", u"\u57fa\u7840\u7f16\u8f91", None)) self.tabWidget_mubiaojichu.setTabText(self.tabWidget_mubiaojichu.indexOf(self.tab_xgmb), QCoreApplication.translate("MainWindow", u"\u4fee\u6539\u76ee\u6807", None)) + self.tabWidget_mubiaojichu.setTabText(self.tabWidget_mubiaojichu.indexOf(self.tab_xzgx), QCoreApplication.translate("MainWindow", u"\u65b0\u589e\u76ee\u6807\u5173\u7cfb", None)) self.tabWidget_mubiaojichu.setTabText(self.tabWidget_mubiaojichu.indexOf(self.tab_scgx), QCoreApplication.translate("MainWindow", u"\u5220\u9664\u76ee\u6807\u5173\u7cfb", None)) self.tabWidget_main.setTabText(self.tabWidget_main.indexOf(self.tab_mubiaojichu), QCoreApplication.translate("MainWindow", u"\u76ee\u6807\u4e0e\u57fa\u7840\u77e5\u8bc6", None)) self.tabWidget_syjl.setTabText(self.tabWidget_syjl.indexOf(self.tab_xxdr), QCoreApplication.translate("MainWindow", u"\u5c0f\u95f2\u5bfc\u5165", None)) diff --git a/工具v4/Ui_新增目标关系.py b/工具v4/Ui_新增目标关系.py new file mode 100644 index 00000000..c9e4bb4a --- /dev/null +++ b/工具v4/Ui_新增目标关系.py @@ -0,0 +1,86 @@ +# -*- coding: utf-8 -*- + +################################################################################ +## Form generated from reading UI file '新增目标关系.ui' +## +## Created by: Qt User Interface Compiler version 6.6.2 +## +## WARNING! All changes made in this file will be lost when recompiling UI file! +################################################################################ + +from PySide6.QtCore import (QCoreApplication, QDate, QDateTime, QLocale, + QMetaObject, QObject, QPoint, QRect, + QSize, QTime, QUrl, Qt) +from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor, + QFont, QFontDatabase, QGradient, QIcon, + QImage, QKeySequence, QLinearGradient, QPainter, + QPalette, QPixmap, QRadialGradient, QTransform) +from PySide6.QtWidgets import (QApplication, QLabel, QPlainTextEdit, QPushButton, + QSizePolicy, QTextBrowser, QWidget) + +class Ui_Form(object): + def setupUi(self, Form): + if not Form.objectName(): + Form.setObjectName(u"Form") + Form.resize(760, 490) + self.label = QLabel(Form) + self.label.setObjectName(u"label") + self.label.setGeometry(QRect(20, 20, 121, 16)) + self.plainTextEdit_data = QPlainTextEdit(Form) + self.plainTextEdit_data.setObjectName(u"plainTextEdit_data") + self.plainTextEdit_data.setGeometry(QRect(20, 40, 351, 421)) + self.label_2 = QLabel(Form) + self.label_2.setObjectName(u"label_2") + self.label_2.setGeometry(QRect(390, 20, 54, 16)) + self.textBrowser = QTextBrowser(Form) + self.textBrowser.setObjectName(u"textBrowser") + self.textBrowser.setGeometry(QRect(390, 40, 351, 141)) + self.pushButton_checkvalidity = QPushButton(Form) + self.pushButton_checkvalidity.setObjectName(u"pushButton_checkvalidity") + self.pushButton_checkvalidity.setGeometry(QRect(670, 190, 71, 51)) + self.pushButton_import = QPushButton(Form) + self.pushButton_import.setObjectName(u"pushButton_import") + self.pushButton_import.setGeometry(QRect(670, 250, 71, 51)) + self.pushButton_commit = QPushButton(Form) + self.pushButton_commit.setObjectName(u"pushButton_commit") + self.pushButton_commit.setGeometry(QRect(670, 310, 71, 151)) + font = QFont() + font.setBold(True) + self.pushButton_commit.setFont(font) + self.pushButton_commit.setStyleSheet(u"background-color: rgb(255, 255, 127);") + self.label_3 = QLabel(Form) + self.label_3.setObjectName(u"label_3") + self.label_3.setGeometry(QRect(390, 190, 101, 16)) + self.plainTextEdit_validity = QPlainTextEdit(Form) + self.plainTextEdit_validity.setObjectName(u"plainTextEdit_validity") + self.plainTextEdit_validity.setGeometry(QRect(390, 210, 271, 251)) + self.plainTextEdit_validity.setReadOnly(True) + + self.retranslateUi(Form) + + QMetaObject.connectSlotsByName(Form) + # setupUi + + def retranslateUi(self, Form): + Form.setWindowTitle(QCoreApplication.translate("Form", u"\u65b0\u589e\u76ee\u6807\u5173\u7cfb", None)) + self.label.setText(QCoreApplication.translate("Form", u"\u524d\u7f6e\u76ee\u6807\u5173\u7cfb\u6570\u636e", None)) + self.label_2.setText(QCoreApplication.translate("Form", u"\u8bf4\u660e", None)) + self.textBrowser.setHtml(QCoreApplication.translate("Form", u"\n" +"\n" +"

\u5148\u5728"\u524d\u7f6e\u76ee\u6807\u5173\u7cfb\u6570\u636e"\u4e2d\u7c98\u8d34\u76ee\u6807\u4ee3\u7801\u4e4b\u95f4\u7684\u5bf9\u5e94\u5173\u7cfb, \u89c4\u5219\u5982\u4e0b:

\n" +"

1. \u6bcf\u4e00\u884c\u4ee3\u8868\u4e00\u4e2a\u76ee\u6807\u4e0e\u5176\u524d\u7f6e" + "\u76ee\u6807\u7684\u5bf9\u5e94\u5173\u7cfb.

\n" +"

2. \u6bcf\u4e00\u884c\u7684\u7b2c\u4e00\u4e2a\u7f16\u53f7\u662f\u539f\u59cb\u76ee\u6807\u7684\u7f16\u53f7, \u540e\u7eed\u7684\u7f16\u53f7\u662f\u539f\u59cb\u76ee\u6807\u7684\u524d\u7f6e\u76ee\u6807\u7684\u7f16\u53f7.

\n" +"

3. \u6bcf\u4e00\u884c\u4e0d\u540c\u7684\u7f16\u53f7\u4e4b\u95f4\u7528"\\t"\u9694\u5f00(Excel\u590d\u5236\u51fa\u6765\u4e4b\u540e\u5c31\u662f\u7528"\\t"\u4f5c\u4e3a\u5206\u9694\u7684)

", None)) + self.pushButton_checkvalidity.setText(QCoreApplication.translate("Form", u"\u68c0\u67e5\u6709\u6548\u6027", None)) + self.pushButton_import.setText(QCoreApplication.translate("Form", u"\u9884\u5bfc\u5165", None)) + self.pushButton_commit.setText(QCoreApplication.translate("Form", u"\u5bfc\u5165\n" +"(\u4e0d\u53ef\u9006)", None)) + self.label_3.setText(QCoreApplication.translate("Form", u"\u6709\u6548\u6027\u68c0\u67e5\u7ed3\u679c", None)) + # retranslateUi + diff --git a/工具v4/tool_panel.py b/工具v4/tool_panel.py index 6555b790..7e38c850 100644 --- a/工具v4/tool_panel.py +++ b/工具v4/tool_panel.py @@ -28,6 +28,7 @@ from 基础知识编辑 import MyWindow_bjjc from 修改目标内容 import MyWindow_xgmb from 删除使用记录 import MyWindow_scjl from 删除课时目标关系 import MyWindow_scgx +from 新增目标关系 import MyWindow_xzgx from database_tools_2 import * class MyWindow(QMainWindow,Ui_MainWindow): @@ -152,6 +153,10 @@ class MyWindow(QMainWindow,Ui_MainWindow): self.scgx = MyWindow_scgx(self.database) self.layout_scgx.addWidget(self.scgx) #以上三行为初始化"删除课时目标关系"tab + self.layout_xzgx = QVBoxLayout(self.tab_xzgx) + self.xzgx = MyWindow_xzgx(self.database) + self.layout_xzgx.addWidget(self.xzgx) #以上三行为初始化"新增课时目标关系"tab + for func in [ @@ -172,7 +177,8 @@ class MyWindow(QMainWindow,Ui_MainWindow): self.wbzh.setdbname, self.xgmb.setdbname, self.scjl.setdbname, - self.scgx.setdbname + self.scgx.setdbname, + self.xzgx.setdbname ]: #在列表中的tab里传送数据库名的连接 self.sendDBname.connect(func) def sendValue(self): diff --git a/工具v4/tool_panel.ui b/工具v4/tool_panel.ui index c90a433f..f22f591f 100644 --- a/工具v4/tool_panel.ui +++ b/工具v4/tool_panel.ui @@ -27,7 +27,7 @@ QTabWidget::Triangular - 5 + 0 @@ -49,7 +49,7 @@ QTabWidget::Triangular - 2 + 0 @@ -94,7 +94,7 @@ QTabWidget::Triangular - 3 + 0 @@ -138,7 +138,7 @@ QTabWidget::Triangular - 1 + 0 @@ -187,7 +187,7 @@ QTabWidget::Triangular - 2 + 0 @@ -226,7 +226,7 @@ QTabWidget::Triangular - 1 + 0 @@ -260,7 +260,7 @@ QTabWidget::Triangular - 3 + 0 @@ -277,6 +277,11 @@ 修改目标 + + + 新增目标关系 + + 删除目标关系 @@ -304,7 +309,7 @@ QTabWidget::Triangular - 5 + 0 diff --git a/工具v4/新增目标关系.py b/工具v4/新增目标关系.py new file mode 100644 index 00000000..7d5d4458 --- /dev/null +++ b/工具v4/新增目标关系.py @@ -0,0 +1,104 @@ +from PySide6.QtWidgets import QWidget, QApplication, QFileDialog, QTableWidgetItem +from Ui_新增目标关系 import Ui_Form +from database_tools_2 import * + +class MyWindow_xzgx(QWidget,Ui_Form): + def __init__(self,database_name): + super().__init__() + self.database_name = database_name + self.current_database_name = database_name + self.setupUi(self) + self.bind() + def setdbname(self,string): + self.database_name = string + self.pushButton_import.setDisabled(True) + self.pushButton_commit.setDisabled(True) + try: + self.db.close() + except: + pass + self.db = connect(hostname=db_host, port=db_port, username= db_user, pwd= db_pwd, db=self.database_name) + # print(self.database_name) + def bind(self): + self.pushButton_import.setDisabled(True) + self.pushButton_commit.setDisabled(True) + self.pushButton_checkvalidity.clicked.connect(self.checkvalidity) + self.pushButton_import.clicked.connect(self.importdata) + self.pushButton_commit.clicked.connect(self.commit) + self.plainTextEdit_data.textChanged.connect(self.disable_import) + self.db = connect(hostname=db_host, port=db_port, username= db_user, pwd= db_pwd, db=self.database_name) + self.mycursor = self.db.cursor() + self.mycursor.execute("SELECT objid from lessonobj;") + self.objids = [item[0] for item in self.mycursor.fetchall()] + # print(self.objids) + + def checkvalidity(self): + self.data_raw = self.plainTextEdit_data.toPlainText().strip() + self.data = re.sub(r"[ \t]+","\t",self.data_raw) + self.datalines = [line.strip() for line in self.data.split("\n") if not line.strip() == ""] + output = f"一共有 {len(self.datalines)} 行数据.\n" + self.valid_lines = [] + validstatus = True + for line in self.datalines: + linevalidflag = True + objids = line.split("\t") + mainid = objids.pop(0) + if not mainid in self.objids: + linevalidflag = False + for objid in objids: + if not objid in self.objids: + linevalidflag = False + break + if linevalidflag == False: + output += f"首个id为 {mainid} 的行数据有误\n" + validstatus = False + else: + self.valid_lines.append((mainid,objids)) + if validstatus == True: + output += "数据全部为有效数据" + self.pushButton_import.setEnabled(True) + # print(self.valid_lines) + self.plainTextEdit_validity.setPlainText(output) + + + + def disable_import(self): + self.pushButton_import.setDisabled(True) + def importdata(self): + self.mycursor = self.db.cursor() + output = "导入记录:\n" + for line in tqdm.tqdm(self.valid_lines): + mainid = line[0] + for precid in line[1]: + self.mycursor.execute("SELECT * FROM objinherit WHERE objid = %s AND inherit_from = %s;",(mainid,precid)) + ret_list = self.mycursor.fetchall() + if len(ret_list) >= 1: + output += f"*** {mainid} 以 {precid} 为前序的记录已在数据库 {self.database_name} 中\n" + else: + output += f"--- {mainid} 与 {precid} 的前序关系已被记录\n" + sql1 = "INSERT INTO objinherit (objid,inherit_from) VALUE (%s,%s);" + val1 = (mainid,precid) + self.mycursor.execute(sql1,val1) + sql2 = "INSERT INTO logs (DATE,TIME,username,action,db_content) VALUE (%s,%s,%s,%s,%s);" + val2 = (GetDate(),GetTime(),get_git_username(),"新增目标前序",f"{mainid} <- {precid}") + self.mycursor.execute(sql2,val2) + self.plainTextEdit_validity.setPlainText(output) + self.pushButton_commit.setEnabled(True) + def commit(self): + self.db.commit() + self.pushButton_import.setDisabled(True) + self.pushButton_commit.setDisabled(True) + + + + + + + + +if __name__ == '__main__': + app = QApplication([]) + windows = MyWindow_xzgx("tikutest") + windows.show() + app.exec() + diff --git a/工具v4/新增目标关系.ui b/工具v4/新增目标关系.ui new file mode 100644 index 00000000..9af8823e --- /dev/null +++ b/工具v4/新增目标关系.ui @@ -0,0 +1,152 @@ + + + Form + + + + 0 + 0 + 760 + 490 + + + + 新增目标关系 + + + + + 20 + 20 + 121 + 16 + + + + 前置目标关系数据 + + + + + + 20 + 40 + 351 + 421 + + + + + + + 390 + 20 + 54 + 16 + + + + 说明 + + + + + + 390 + 40 + 351 + 141 + + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><meta charset="utf-8" /><style type="text/css"> +p, li { white-space: pre-wrap; } +hr { height: 1px; border-width: 0; } +li.unchecked::marker { content: "\2610"; } +li.checked::marker { content: "\2612"; } +</style></head><body style=" font-family:'Microsoft YaHei UI'; font-size:9pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">先在&quot;前置目标关系数据&quot;中粘贴目标代码之间的对应关系, 规则如下:</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">1. 每一行代表一个目标与其前置目标的对应关系.</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">2. 每一行的第一个编号是原始目标的编号, 后续的编号是原始目标的前置目标的编号.</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">3. 每一行不同的编号之间用&quot;\t&quot;隔开(Excel复制出来之后就是用&quot;\t&quot;作为分隔的)</p></body></html> + + + + + + 670 + 190 + 71 + 51 + + + + 检查有效性 + + + + + + 670 + 250 + 71 + 51 + + + + 预导入 + + + + + + 670 + 310 + 71 + 151 + + + + + true + + + + background-color: rgb(255, 255, 127); + + + 导入 +(不可逆) + + + + + + 390 + 190 + 101 + 16 + + + + 有效性检查结果 + + + + + + 390 + 210 + 271 + 251 + + + + true + + + + + +