|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
------------main.py--------------
#登录界面,实现用户名登录的逻辑
import sys
from PySide6.QtWidgets import QApplication,QMainWindow,QWidget,QDialog,QMessageBox
from PyQt6.QtCore import Qt,QDateTime
import Login
import HSJCQueryWindow
import Dbconnect
# 创建Login类和HSJCQueryWindow类
class HSJCQueryWindow(HSJCQueryWindow.Ui_MainWindow, QMainWindow):
def __init__(self):
super(HSJCQueryWindow, self).__init__()
self.setupUi(self)
class Login(Login.Ui_MainWindow, QMainWindow):
def __init__(self):
super(Login, self).__init__()
self.setupUi(self)
# 登录验证
def login_check():
username = login.UserNameEdit.text()
password = login.PasswordEdit.text()
message = QMessageBox(login)
sql = "SELECT hrp_user_name,COMM.F_DESCRIPT(password) FROM staff_dict WHERE hrp_user_name = '{uname}' ".format(uname=username)
Dbconnect.cursor.execute(sql)
results = Dbconnect.cursor.fetchall()
for r in results:
if (len(r[0])==None):
message = QMessageBox.warning(login, "注意", "用户名不正确请检查")
else:
if (r[1]==password):
hsjcquery_window.show()
login.close()
else:
message = QMessageBox.critical(login,'注意','用户名或密码错误')
if __name__ == '__main__':
app = QApplication(sys.argv)
window = QMainWindow()
# 为Login类和HSJCQueryWindow类实例化对象
login = Login()
hsjcquery_window = HSJCQueryWindow()
# 显示登陆窗口
login.setupUi(window)
window.show()
# 将login_check函数与登录按钮绑定
login.LoginButton.clicked.connect(login_check)
app.exec()
sys.exit(app.exec())
-------DBConnect.py------------
#实现数据库登录配置,已成功连接
-------------Login.py----------------------
#登录界面的布局,已成功登录并跳转
--------------HSJCQueryWindow---------------------------
#查询界面的布局
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, QDateEdit, QFrame, QHeaderView,
QLabel, QLineEdit, QMainWindow, QMenuBar,
QPushButton, QSizePolicy, QStatusBar, QTabWidget,
QTableView, QTextEdit, QWidget)
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
if not MainWindow.objectName():
MainWindow.setObjectName(u"MainWindow")
MainWindow.resize(800, 543)
self.centralwidget = QWidget(MainWindow)
self.centralwidget.setObjectName(u"centralwidget")
self.frame = QFrame(self.centralwidget)
self.frame.setObjectName(u"frame")
self.frame.setGeometry(QRect(70, 40, 701, 91))
self.frame.setFrameShape(QFrame.StyledPanel)
self.frame.setFrameShadow(QFrame.Raised)
self.dateEdit_2 = QDateEdit(self.frame)
self.dateEdit_2.setObjectName(u"dateEdit_2")
self.dateEdit_2.setGeometry(QRect(446, 57, 200, 25))
self.StartDateTime = QLabel(self.frame)
self.StartDateTime.setObjectName(u"StartDateTime")
self.StartDateTime.setGeometry(QRect(20, 61, 70, 16))
font = QFont()
font.setPointSize(12)
self.StartDateTime.setFont(font)
self.EndDateTime = QLabel(self.frame)
self.EndDateTime.setObjectName(u"EndDateTime")
self.EndDateTime.setGeometry(QRect(370, 61, 70, 16))
self.EndDateTime.setFont(font)
self.EditTxt = QLabel(self.frame)
self.EditTxt.setObjectName(u"EditTxt")
self.EditTxt.setGeometry(QRect(20, 20, 70, 16))
self.EditTxt.setFont(font)
self.lineEdit = QLineEdit(self.frame)
self.lineEdit.setObjectName(u"lineEdit")
self.lineEdit.setGeometry(QRect(100, 14, 421, 30))
self.queryButton = QPushButton(self.frame)
self.queryButton.setObjectName(u"queryButton")
self.queryButton.setGeometry(QRect(556, 14, 90, 30))
self.queryButton.setFont(font)
self.dateEdit = QDateEdit(self.frame)
self.dateEdit.setObjectName(u"dateEdit")
self.dateEdit.setGeometry(QRect(100, 57, 200, 25))
self.frame_result = QFrame(self.centralwidget)
self.frame_result.setObjectName(u"frame_result")
self.frame_result.setGeometry(QRect(70, 150, 701, 361))
self.frame_result.setFrameShape(QFrame.StyledPanel)
self.frame_result.setFrameShadow(QFrame.Raised)
self.tableView = QTableView(self.frame_result)
self.tableView.setObjectName(u"tableView")
self.tableView.setGeometry(QRect(10, 10, 681, 331))
self.tab_result = QTabWidget(self.frame_result)
self.tab_result.setObjectName(u"tab_result")
self.tab_result.setGeometry(QRect(20, 62, 661, 270))
self.tab_result.setFont(font)
self.tab_outp = QWidget()
self.tab_outp.setObjectName(u"tab_outp")
self.tab_outp_text = QTextEdit(self.tab_outp)
self.tab_outp_text.setObjectName(u"tab_outp_text")
self.tab_outp_text.setEnabled(True)
self.tab_outp_text.setGeometry(QRect(10, 20, 630, 60))
font1 = QFont()
font1.setFamilies([u"Verdana"])
font1.setPointSize(24)
self.tab_outp_text.setFont(font1)
self.tab_outp_text.setReadOnly(True)
self.tab_result.addTab(self.tab_outp, "")
self.tab_inp = QWidget()
self.tab_inp.setObjectName(u"tab_inp")
self.tab_inp_text = QTextEdit(self.tab_inp)
self.tab_inp_text.setObjectName(u"tab_inp_text")
self.tab_inp_text.setEnabled(True)
self.tab_inp_text.setGeometry(QRect(10, 20, 630, 60))
self.tab_inp_text.setFont(font1)
self.tab_inp_text.setReadOnly(True)
self.tab_result.addTab(self.tab_inp, "")
self.label_result = QLabel(self.frame_result)
self.label_result.setObjectName(u"label_result")
self.label_result.setGeometry(QRect(22, 20, 650, 30))
self.label_result.setAlignment(Qt.AlignCenter)
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QMenuBar(MainWindow)
self.menubar.setObjectName(u"menubar")
self.menubar.setGeometry(QRect(0, 0, 800, 22))
MainWindow.setMenuBar(self.menubar)
self.statusbar = QStatusBar(MainWindow)
self.statusbar.setObjectName(u"statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
self.queryButton.clicked.connect(self.tab_outp_text.show)
self.queryButton.clicked.connect(self.tab_inp_text.show)
self.tab_result.setCurrentIndex(0)
self.dateEdit.setDate(QDate.currentDate())
self.dateEdit_2.setDate(QDate.currentDate())
# labelresult=self.label_result.setText(self.dateEdit.text() + '一' + self.dateEdit_2.text() + '总金额')
# self.tab_outp_text.setText('30000')
# self.tab_inp_text.setText('50000')
QMetaObject.connectSlotsByName(MainWindow)
# setupUi
def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(QCoreApplication.translate("MainWindow", u"HSJCQueryWindow", None))
self.StartDateTime.setText(QCoreApplication.translate("MainWindow", u"\u8d77\u59cb\u65f6\u95f4\uff1a", None))
self.EndDateTime.setText(QCoreApplication.translate("MainWindow", u"\u7ed3\u675f\u65f6\u95f4\uff1a", None))
self.EditTxt.setText(QCoreApplication.translate("MainWindow", u"\u67e5\u8be2\u5185\u5bb9\uff1a", None))
self.queryButton.setText(QCoreApplication.translate("MainWindow", u"\u67e5\u8be2", None))
self.tab_result.setTabText(self.tab_result.indexOf(self.tab_outp), QCoreApplication.translate("MainWindow", u"\u95e8\u8bca", None))
self.tab_result.setTabText(self.tab_result.indexOf(self.tab_inp), QCoreApplication.translate("MainWindow", u"\u4f4f\u9662", None))
self.label_result.setText(QCoreApplication.translate("MainWindow", u"Label_result", None))
# retranslateUi
--------------------HSJCQuery.py-------------------------------
#查询界面的业务逻辑
import sys
from PySide6.QtWidgets import (QApplication,QMainWindow,QWidget,QDialog,QMessageBox,QTableWidget, QTableWidgetItem)
from PyQt6.QtCore import Qt,QDateTime
import HSJCQueryWindow
import Dbconnect
# 定义HSJCQueryWindow类
class HSJCQueryWindow(HSJCQueryWindow.Ui_MainWindow, QMainWindow):
def __init__(self): #定义HSJCQueryWindow窗口
super(HSJCQueryWindow, self).__init__()
self.setupUi(self)
def hsjc_query(self): #定义查询功能
start_date = hsjcquery_window.dateTimeEdit.text()
end_date = hsjcquery_window.dateTimeEdit_2.text()
txt_query = hsjcquery_window.lineEdit.text()
sql_outp = "SELECT SUM(CHARGES) FROM OUTP_BILL_ITEMS WHERE VISIT_DATE >= {startdate} AND VISIT_DATE <= {enddate} AND PATTERN LIKE '%{txtquery}%'".format(startdate=start_date,enddate=end_date,txtquery=txt_query) #这里可能还有语法错误,到时候断点调试
Dbconnect.cursor.execute(sql_outp)
results_outp = Dbconnect.cursor.fetchall()
return results_outp
sql_inp = "SELECT SUM(CHARGES) FROM INP_BILL_DETAIL WHERE BILLING_DATE_TIME >= {startdate} AND BILLING_DATE_TIME <= {enddate} AND ITEM_NAME LIKE '%{txtquery}}%'".format(startdate=start_date,enddate=end_date,txtquery=txt_query)
Dbconnect.cursor.execute(sql_inp)
results_inp = Dbconnect.cursor.fetchall()
return results_inp
if __name__ == '__HSJCQuery__':
app = QApplication(sys.argv)
# 实例化HSJCQueryWindow类
hsjcquery_window = HSJCQueryWindow()
hsjcquery_window.show()
# 将hsjc_query函数与查询按钮绑定
hsjcquery_window.queryButton.clicked.connect(hsjc_query)
hsjcquery_window.tab_outp_text.setText(result_outp)
hsjcquery_window.tab_inp_text.setText(result_inp)
app.exec()
sys.exit(app.exec())
初学者,还请忽略我屎一般的代码逻辑,目前账号没有发图权限,目前只能用文字代替
project里目前有【main.py】 【login.py】 【Dbconnect.py】 【HSJCQueryWindow.py】 【HSJCQuery.py】5个文件
登录正常,跳转至查询界面后点击queryButton,设了断点后发现槽函数不接收信号。已经卡了2天了,我看书和上网搜索后对槽函数还是云里雾里的
然后我就进行不下去了,请大神们帮忙诊断一下。我问题到底出在哪了,怎么才能让它正确接收sql语句并查出结果返回给results_inp和results_outp
|
|