完整代码、数据库资源:资源下载
20220520_002105
车次管理(车次、起止地点、到达时间、开车时间)
每一车次的车票管理(车厢号、座位号)
售票
退票
查询(按车次,按起止地点,按发车时间等)
开发语言:python(pycharm)、mysql(navicat)
开发工具:QT Designer、pyqt5、pymysql
主函数:实现页面跳转关系,以及部分逻辑关系
import sys
import os
import string
from PyQt5 import QtCore, QtWidgets
from PyQt5.QtWidgets import QMessageBox
from PyQt5.QtCore import pyqtSlot, QDate
import datetime
from loginUI import Ui_MainWindow as login_ui#登录界面
from Register import Ui_MainWindow as register_ui #注册页面
from User_homeUI import Ui_MainWindow as user_ui#用户主页界面
from Admin_homeUI import Ui_MainWindow as admin_ui#管理员主页界面
from p_informationUI import Ui_MainWindow as p_infor_ui#个人信息页面
from modify_passwdUI import Ui_MainWindow as modify_pwui#修改密码页面
from voucher_centerUI import Ui_MainWindow as voucher_ui #充值页面
from Ticket_hallUI import Ui_MainWindow as tickethall_ui #购票大厅
from buy_ticketUI import Ui_MainWindow as buytickethall_ui#购票页面
from my_orderUI import Ui_MainWindow as myorder_ui#我的订单页面
from user_manageUI import Ui_MainWindow as usermanage_ui #用户管理页面
from ticket_informationUI import Ui_MainWindow as ticketinformation_ui #票务信息页面
from update_trainUI import Ui_MainWindow as updatetrain_ui #更新列车状态
from train_manageUI import Ui_MainWindow as trainmanage_ui #列车管理页面
from add_trainUI import Ui_MainWindow as addtrain_ui #添加列车
import pymysql
import time
class loginWindow(QtWidgets.QMainWindow,login_ui):
switch_window1 = QtCore.pyqtSignal()
switch_window2 = QtCore.pyqtSignal()
switch_window3 = QtCore.pyqtSignal() #注册信号
def __init__(self):
super(loginWindow,self).__init__()
self.setupUi(self)
self.L_button.clicked.connect(self.goUser)
self.S_button.clicked.connect(self.goRegister)
def goUser(self):
conn = pymysql.connect(
host='localhost',
port=3306,
user='root',
passwd='111111',
db='train',
charset='utf8'
)
id = self.id_choice.currentText()
ac = self.Laccount.text()
pw = self.Lpasswd.text()
if ac=='' or pw=='':
QMessageBox.critical(self,"错误","请输入完整信息!!!")
else:
if id == '用户':
print("%s 用户:%s 在尝试登录" % (datetime.datetime.now(), self.Laccount.text()))
user = conn.cursor()
sql = "select * from 用户表 where 手机号='%s' and 密码='%s'" % (ac, pw)
user.execute(sql)
if len(user.fetchall()) == 0:
print("%s 登录失败" % datetime.datetime.now())
self.error_reminder.show()
else:
print("%s 登录成功,进入用户主页" % datetime.datetime.now())
self.switch_window1.emit()
self.error_reminder.hide()
user.close()
if id == '管理员':
print("%s 管理员:%s 在尝试登录" % (datetime.datetime.now(), self.Laccount.text()))
admin = conn.cursor()
sql = "select * from 管理员表 where 管理员账号='%s' and 密码='%s'" % (ac, pw)
admin.execute(sql)
if len(admin.fetchall()) == 0:
print("%s 登录失败" % datetime.datetime.now())
self.error_reminder.show()
else:
print("%s 登录成功,进入管理员主页" % datetime.datetime.now())
self.switch_window2.emit()
self.error_reminder.hide()
admin.close()
conn.close()
def goRegister(self):
self.switch_window3.emit()
self.hide()
class registerWindow(QtWidgets.QMainWindow,register_ui):
switch_window1 = QtCore.pyqtSignal()
def __init__(self):
super(registerWindow, self).__init__()
self.setupUi(self)
self.pushButton_2.clicked.connect(self.goLogin1)
def goLogin1(self):
self.switch_window1.emit()
self.close()
class userWindow(QtWidgets.QMainWindow,user_ui):
switch_window1 = QtCore.pyqtSignal() #退出信号
switch_window2 = QtCore.pyqtSignal() #个人信息信号
switch_window3 = QtCore.pyqtSignal() #购票大厅
switch_window4 = QtCore.pyqtSignal()#我的订单
def __init__(self):
super(userWindow,self).__init__()
self.setupUi(self)
self.L_out.clicked.connect(self.goLogin)
self.P_information.clicked.connect(self.goInformation)
self.M_order.clicked.connect(self.gomyorder)
self.T_hall.clicked.connect(self.goHall)
def goLogin(self):
print("%s 退出登录" %datetime.datetime.now())
self.switch_window1.emit()
self.hide()
def goInformation(self):
print("%s 进入个人信息页面" %datetime.datetime.now())
self.switch_window2.emit()
self.hide()
def goHall(self):
print("%s 进入购票大厅页面" % datetime.datetime.now())
self.switch_window3.emit()
self.hide()
def gomyorder(self):
print("%s 进入我的订单页面" % datetime.datetime.now())
self.switch_window4.emit()
self.hide()
class adminWindow(QtWidgets.QMainWindow,admin_ui):
switch_window1 = QtCore.pyqtSignal()#退出管理员页面信号
switch_window2 = QtCore.pyqtSignal()#进入用户管理页面信号
switch_window3 = QtCore.pyqtSignal()#进入票务信息页面信号
switch_window4 = QtCore.pyqtSignal()#进入更新列车状态页面信号
switch_window5 = QtCore.pyqtSignal()#进入列车管理页面信号
def __init__(self):
super(adminWindow,self).__init__()
self.setupUi(self)
self.L_out.clicked.connect(self.goLogin)
self.User_manage.clicked.connect(self.gousermanage)
self.ticket_informations.clicked.connect(self.goticketInformation)
self.update_train.clicked.connect(self.goupdatetrain)
self.train_manage.clicked.connect(self.gotrainmanage)
def goLogin(self):
print("%s 退出登录" % datetime.datetime.now())
self.switch_window1.emit()
self.close()
def gousermanage(self):
print("%s 进入用户管理页面" % datetime.datetime.now())
self.switch_window2.emit()
self.close()
def goticketInformation(self):
print("%s 进入票务信息页面" % datetime.datetime.now())
self.switch_window3.emit()
self.close()
def goupdatetrain(self):
print("%s 进入更新列车状态页面" % datetime.datetime.now())
self.switch_window4.emit()
self.close()
def gotrainmanage(self):
print("%s 进入列车管理页面" % datetime.datetime.now())
self.switch_window5.emit()
self.close()
class pinfromationWindow(QtWidgets.QMainWindow,p_infor_ui):
switch_window1 = QtCore.pyqtSignal()
switch_window2 = QtCore.pyqtSignal()
switch_window3 = QtCore.pyqtSignal()
def __init__(self):
super(pinfromationWindow,self).__init__()
self.setupUi(self)
self.e_p_informstion.clicked.connect(self.goUser)
self.M_pwbutton.clicked.connect(self.goModify)
self.add_moneybutton.clicked.connect(self.goVoucher)
def goUser(self):
print("%s 退出个人信息页面" % datetime.datetime.now())
self.switch_window1.emit()
self.close()
def goModify(self):
print("%s 进入修改密码页面" % datetime.datetime.now())
self.switch_window2.emit()
self.close()
def goVoucher(self):
print("%s 进入充值中心页面" % datetime.datetime.now())
self.switch_window3.emit()
self.close()
class modifyWindow(QtWidgets.QMainWindow,modify_pwui):#修改密码
switch_window1 = QtCore.pyqtSignal()
def __init__(self):
super(modifyWindow,self).__init__()
self.setupUi(self)
self.exitButton.clicked.connect(self.goInformation)
def goInformation(self):
print("%s 退出修改密码页面" % datetime.datetime.now())
self.switch_window1.emit()
self.close()
class voucherWindow(QtWidgets.QMainWindow,voucher_ui):#充值页面
switch_window1 = QtCore.pyqtSignal()
def __init__(self):
super(voucherWindow,self).__init__()
self.setupUi(self)
self.exitButton.clicked.connect(self.goinformation)
def goinformation(self):
print("%s 退出充值中心页面" % datetime.datetime.now())
self.switch_window1.emit()
self.close()
class ticketWindow(QtWidgets.QMainWindow,tickethall_ui):#购票大厅
switch_window1 = QtCore.pyqtSignal()
switch_window2 = QtCore.pyqtSignal()
def __init__(self):
super(ticketWindow,self).__init__()
self.setupUi(self)
place = ["广州", "深圳", "佛山", "东莞","中山","珠海","江门","肇庆","惠州","汕头","潮州","揭阳","汕尾","湛江","茂名","阳江","云浮","韶关","清远","梅州", "河源"]
self.comboBox.addItems(place)
place.remove('广州')
self.comboBox_2.addItems(place)
self.comboBox.currentTextChanged.connect(self.update5)
self.exitbutton.clicked.connect(self.gouser1)
def gouser1(self):
print("%s 退出购票大厅页面" % datetime.datetime.now())
self.switch_window1.emit()
self.close()
def update5(self): #终点和起始点列表不同
place1 = ["广州", "深圳", "佛山", "东莞","中山","珠海","江门","肇庆","惠州","汕头","潮州","揭阳","汕尾","湛江","茂名","阳江","云浮","韶关","清远","梅州", "河源"]
n = self.comboBox.currentText()
place1.remove(n)
self.comboBox_2.clear()
self.comboBox_2.addItems(place1)
def pr(self):
s = self.sender().objectName()
y = s.strip('buyButton')
y1 = int(y)
exec('''
self.train.clear()
self.train_no.clear()
self.b_station.clear()
self.e_station.clear()
self.b_date.clear()
self.b_time.clear()
self.e_date.clear()
self.e_time.clear()
self.first_p.clear()
self.second_p.clear()
self.train.setText(self.train{i}.text())
self.train_no.setText(self.train_no{i}.text())
self.b_station.setText(self.b_station{i}.text())
self.e_station.setText(self.e_station{i}.text())
self.b_date.setText(self.b_date{i}.text())
self.e_date.setText(self.e_date{i}.text())
self.b_time.setText(self.b_time{i}.text())
self.e_time.setText(self.e_time{i}.text())
self.first_p.setText(self.first_p{i}.text())
self.second_p.setText(self.second_p{i}.text())
'''.format(i=y1))
self.switch_window2.emit()
self.hide()
class buyticketWindow(QtWidgets.QMainWindow,buytickethall_ui): # 购票页面
switch_window1 = QtCore.pyqtSignal()
switch_window2 = QtCore.pyqtSignal()#切换等级刷新金额/车厢号
def __init__(self):
super(buyticketWindow, self).__init__()
self.setupUi(self)
self.exitButton.clicked.connect(self.gotickethall)
self.comboBox.addItems(["一等座","二等座"])
self.comboBox.currentTextChanged.connect(self.update1)
self.comboBox_1.currentTextChanged.connect(self.update2)
def gotickethall(self):
self.switch_window1.emit()
self.close()
def update1(self):
self.switch_window2.emit()
def update2(self):
self.comboBox_2.clear()
train = int(self.T_date.text())
items = ['1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20']
chexian = self.comboBox_1.currentText()
chexian1 = chexian.strip('号车厢')
chexian2 = 0
if chexian1=='':
return
else:
chexian2 = int(chexian1)
conn = pymysql.connect(
host='localhost',
port=3306,
user='root',
passwd='111111',
db='train',
charset='utf8'
)
cursor = conn.cursor()
cursor.execute("select 座位 from 座位表 where 列车编号=%s and 车厢=%s"%(train,chexian2))
zuowei = cursor.fetchall()
for i in zuowei:
for j in i:
print("%s %s号座位已售出"%(chexian,j))
items.remove(str(j))
self.comboBox_2.addItems(items)
cursor.close()
conn.close()
class myorderWindow(QtWidgets.QMainWindow,myorder_ui): # 个人订单页面
switch_window1 = QtCore.pyqtSignal() #去用户个人中心
def __init__(self):
super(myorderWindow, self).__init__()
self.setupUi(self)
self.exitButton.clicked.connect(self.gouser2)
def gouser2(self):
print("%s 退出我的订单页面" % datetime.datetime.now())
self.switch_window1.emit()
self.close()
class usermanageWindow(QtWidgets.QMainWindow,usermanage_ui):#用户管理页面
switch_window1 = QtCore.pyqtSignal()
def __init__(self):
super(usermanageWindow, self).__init__()
self.setupUi(self)
self.exitButton.clicked.connect(self.goadmin)
def goadmin(self):
print("%s 退出用户管理页面" % datetime.datetime.now())
self.switch_window1.emit()
self.close()
class ticketInformationWindow(QtWidgets.QMainWindow,ticketinformation_ui):#用户管理页面
switch_window1 = QtCore.pyqtSignal()
def __init__(self):
super(ticketInformationWindow, self).__init__()
self.setupUi(self)
self.exitButton.clicked.connect(self.goAdmin)
def goAdmin(self):
print("%s 退出票务信息页面" % datetime.datetime.now())
self.switch_window1.emit()
self.close()
class updatetrainWindow(QtWidgets.QMainWindow,updatetrain_ui):#更新列车状态页面
switch_window1 = QtCore.pyqtSignal()
def __init__(self):
super(updatetrainWindow, self).__init__()
self.setupUi(self)
self.exitButton.clicked.connect(self.goAdmin)
def goAdmin(self):
print("%s 退出更新列车状态页面" % datetime.datetime.now())
self.switch_window1.emit()
self.close()
class trainManageWindow(QtWidgets.QMainWindow,trainmanage_ui):#列车管理页面
switch_window1 = QtCore.pyqtSignal()
switch_window2 = QtCore.pyqtSignal()
def __init__(self):
super(trainManageWindow, self).__init__()
self.setupUi(self)
self.exitButton.clicked.connect(self.goAdmin)
self.add_trainButton.clicked.connect(self.goAddtrain)
def goAdmin(self):
print("%s 退出列车管理页面" % datetime.datetime.now())
self.switch_window1.emit()
self.close()
def goAddtrain(self):
print("%s 进入添加列车页面" % datetime.datetime.now())
self.switch_window2.emit()
self.close()
class addTrainWindow(QtWidgets.QMainWindow,addtrain_ui):#列车管理页面
switch_window1 = QtCore.pyqtSignal()
def __init__(self):
super(addTrainWindow, self).__init__()
self.setupUi(self)
self.exitButton.clicked.connect(self.gotrainManage)
def gotrainManage(self):
print("%s 退出添加列车页面" % datetime.datetime.now())
self.switch_window1.emit()
self.close()
class Controller:
def __init__(self):
pass
self.login = loginWindow()
def show_login(self):
self.login = loginWindow()
self.login.switch_window1.connect(self.show_user)
self.login.switch_window2.connect(self.show_admin)
self.login.switch_window3.connect(self.show_register)
self.login.show()
def show_register(self):#注册界面
self.register = registerWindow()
self.register.switch_window1.connect(self.show_login)
self.register.show()
self.login.hide()
def show_user(self):#用户页面
self.user = userWindow()
self.user.switch_window1.connect(self.show_login1)
self.user.switch_window2.connect(self.show_information)
self.user.switch_window3.connect(self.show_tickethall)
self.user.switch_window4.connect(self.show_myorder)
u = self.login.Laccount.text()#传输账号信息
self.user.U_date.setText(str(u))#写到用户页面
self.user.show()
self.login.hide()
def show_admin(self):#管理员页面
self.admin = adminWindow()
self.admin.switch_window1.connect(self.show_login1)
self.admin.switch_window2.connect(self.show_usermanage)
self.admin.switch_window3.connect(self.show_ticketinformation)
self.admin.switch_window4.connect(self.show_updatetrain)
self.admin.switch_window5.connect(self.show_trainmanage)
s = self.login.Laccount.text()
self.admin.A_date.setText(str(s))
self.admin.show()
self.login.hide()
def show_login1(self):
self.login.Lpasswd.clear()
self.login.show()
def show_information(self):#个人信息页面
conn = pymysql.connect(
host='localhost',
port=3306,
user='root',
passwd='111111',
db='train',
charset='utf8'
)
self.infromation = pinfromationWindow()
self.infromation.switch_window1.connect(self.show_user)
self.infromation.switch_window2.connect(self.show_modifypw)
self.infromation.switch_window3.connect(self.show_voucher)
self.infromation.show()
u = self.user.U_date.text()#获取用户信息
self.infromation.U_date.setText(u)
infor = conn.cursor()
infor.execute("select * from 用户表 where 手机号='%s'" %u)
ud = []
for i in infor.fetchall():
for t in i:
ud.insert(0,str(t))
infor.close()
conn.close()
self.infromation.U_phonenumber.setText(ud[4])
self.infromation.U_password.setText(ud[3])
self.infromation.U_name.setText(ud[2])
self.infromation.U_id.setText(ud[1])
self.infromation.U_balance.setText(ud[0])
self.user.hide()
def show_modifypw(self):#修改密码页面
self.modifypw = modifyWindow()
self.modifypw.switch_window1.connect(self.show_information)
u = self.infromation.U_date.text()
self.modifypw.U_date.setText(u)
self.modifypw.show()
self.infromation.hide()
def show_voucher(self):#充值中心页面
self.voucher = voucherWindow()
self.voucher.switch_window1.connect(self.show_information)
u = self.infromation.U_date.text()
self.voucher.U_date.setText(u)
self.voucher.show()
self.infromation.hide()
def show_tickethall(self):
self.tickethall = ticketWindow()
self.tickethall.switch_window1.connect(self.show_user)
self.tickethall.switch_window2.connect(self.show_buyticket)
u = self.user.U_date.text()
self.tickethall.U_data.setText(u)
self.tickethall.show()
self.user.hide()
def db(self,amount):
conn = pymysql.connect(
host='localhost',
port=3306,
user='root',
passwd='111111',
db='train',
charset='utf8'
)
cursor = conn.cursor()
cursor.execute("select 一等座数量,二等座数量 from 列车表 where 列车编号=%s" %int(self.tickethall.train.text()))
amount = []
for i in cursor.fetchall():
for j in i:
amount.append(j)
cursor.close()
conn.close()
return amount
def show_buyticket(self):
self.buyticket = buyticketWindow()
self.buyticket.switch_window1.connect(self.show_tickethall1)
self.buyticket.switch_window2.connect(self.show_updatemoney)
u = self.tickethall.U_data.text()
self.buyticket.U_date.setText(u)
l = self.tickethall.train.text()
self.buyticket.T_date.setText(l)
self.buyticket.B_time.setText("%s
"%self.tickethall.b_time.text())
self.buyticket.B_station.setText("%s
"%self.tickethall.b_station.text())
self.buyticket.label_4.setText("————————————————————>
")
self.buyticket.E_time.setText("%s
"%self.tickethall.e_time.text())
self.buyticket.E_station.setText( "%s
"%self.tickethall.e_station.text())
self.buyticket.train_No.setText("%s
"%self.tickethall.train_no.text())
self.buyticket.B_date.setText("%s
"%self.tickethall.b_date.text())
self.buyticket.E_date.setText("%s
" % self.tickethall.e_date.text())
amount = []
self.buyticket.money.setText("¥%s
"%self.tickethall.first_p.text())
self.buyticket.M_date.setText(self.tickethall.first_p.text())
m = 0
if self.db(amount)[0]%20>=1 :
m = int(self.db(amount)[0]/20+1)
else:
m = int(self.db(amount)[0]/20)
for n in range(m):
self.buyticket.comboBox_1.addItem(str(n+1)+"号车厢")
conn = pymysql.connect(
host='localhost',
port=3306,
user='root',
passwd='111111',
db='train',
charset='utf8'
)
cursor = conn.cursor()
cursor.execute("select 途径站 from 列车表 where 列车编号='%s'"%self.buyticket.T_date.text())
for x in cursor.fetchall():
for y in x:
self.buyticket.by_date.setText(y)
self.buyticket.show()
self.tickethall.hide()
def show_tickethall1(self):#退出购票,大厅刷新票数,但是起始站和终点站不刷新
self.tickethall.checkButton.click()
self.buyticket.close()
self.tickethall.show()
def show_updatemoney(self):#刷新金额/车厢号
amount = 0
if self.buyticket.comboBox.currentText() =="一等座":
self.buyticket.comboBox_1.clear()
m = 0
if self.db(amount)[0] % 20 >= 1:
m = int(self.db(amount)[0] / 20 + 1)
else:
m = int(self.db(amount)[0] / 20)
for n in range(m):
self.buyticket.comboBox_1.addItem(str(n + 1) + '号车厢')
self.buyticket.M_date.clear()
self.buyticket.money.clear()
self.buyticket.money.setText("¥%s
" % self.tickethall.first_p.text())
self.buyticket.M_date.setText(self.tickethall.first_p.text())
else:
self.buyticket.comboBox_1.clear()
m = 0
se = 0
if self.db(amount)[0] % 20 >= 1:
m = int(self.db(amount)[0] / 20 + 1)
else:
m = int(self.db(amount)[0] / 20)
if self.db(amount)[1] % 20 >= 1:
se = int(self.db(amount)[1] / 20 + 1)
else:
se = int(self.db(amount)[1] / 20)
for t in range(se):
self.buyticket.comboBox_1.addItem(str(m + 1) + '号车厢')
m = m + 1
self.buyticket.M_date.clear()
self.buyticket.money.clear()
self.buyticket.money.setText( "¥%s
" % self.tickethall.second_p.text())
self.buyticket.M_date.setText(self.tickethall.second_p.text())
def show_myorder(self):
self.myorder = myorderWindow()
self.myorder.switch_window1.connect(self.show_user)
self.myorder.U_date.setText(self.user.U_date.text())
self.myorder.updateButton.click()
self.myorder.show()
self.user.close()
def show_usermanage(self):
self.usermanage = usermanageWindow()
self.usermanage.switch_window1.connect(self.show_admin)
self.usermanage.searchButton.click()
self.usermanage.A_date.setText(self.admin.A_date.text())
self.usermanage.show()
self.admin.close()
def show_ticketinformation(self):
self.ticketinformation = ticketInformationWindow()
self.ticketinformation.switch_window1.connect(self.show_admin)
self.ticketinformation.A_date.setText(self.admin.A_date.text())
self.ticketinformation.show()
self.admin.close()
def show_updatetrain(self):
self.updatetrain = updatetrainWindow()
self.updatetrain.switch_window1.connect(self.show_admin)
self.updatetrain.A_date.setText(self.admin.A_date.text())
self.updatetrain.searchButton.click()
self.updatetrain.show()
self.admin.close()
def show_trainmanage(self):
self.trainManage = trainManageWindow()
self.trainManage.switch_window1.connect(self.show_admin)
self.trainManage.switch_window2.connect(self.show_addtrain)
self.trainManage.A_date.setText(self.admin.A_date.text())
self.trainManage.updateButton.click()
self.trainManage.show()
self.admin.close()
def show_addtrain(self):
self.addTrain = addTrainWindow()
self.addTrain.switch_window1.connect(self.show_trainmanage)
self.addTrain.A_date.setText(self.trainManage.A_date.text())
self.addTrain.show()
self.trainManage.close()
def main():
app = QtWidgets.QApplication(sys.argv)
controller = Controller() #控制器实例
controller.show_login() #默认展示的是登录页面
sys.exit(app.exec_())
if __name__ == '__main__':
main()
登录界面UI设计:包含管理员和用户登录选择、以及注册功能
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'loginUI.ui'
#
# Created by: PyQt5 UI code generator 5.15.6
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
import pymysql
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QMessageBox
import datetime
conn = pymysql.connect(
host='localhost',
port=3306,
user='root',
passwd='111111',
db='train',
charset='utf8'
)
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(800, 600)
MainWindow.setStyleSheet("#MainWindow{border-image: url(:/thpic/60.jpg);}")
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.id_choice = QtWidgets.QComboBox(self.centralwidget)
self.id_choice.setGeometry(QtCore.QRect(330, 250, 120, 22))
self.id_choice.setObjectName("id_choice")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(250, 20, 281, 41))
self.label.setObjectName("label")
self.label_2 = QtWidgets.QLabel(self.centralwidget)
self.label_2.setGeometry(QtCore.QRect(280, 160, 51, 16))
self.label_2.setObjectName("label_2")
self.label_3 = QtWidgets.QLabel(self.centralwidget)
self.label_3.setGeometry(QtCore.QRect(280, 200, 51, 16))
self.label_3.setObjectName("label_3")
self.Laccount = QtWidgets.QLineEdit(self.centralwidget)
self.Laccount.setGeometry(QtCore.QRect(330, 160, 120, 21))
self.Laccount.setObjectName("Laccount")
self.Lpasswd = QtWidgets.QLineEdit(self.centralwidget)
self.Lpasswd.setGeometry(QtCore.QRect(330, 200, 120, 21))
self.Lpasswd.setEchoMode(QtWidgets.QLineEdit.Password)
self.Lpasswd.setObjectName("Lpasswd")
self.label_4 = QtWidgets.QLabel(self.centralwidget)
self.label_4.setGeometry(QtCore.QRect(240, 250, 81, 20))
self.label_4.setObjectName("label_4")
self.L_button = QtWidgets.QPushButton(self.centralwidget)
self.L_button.setGeometry(QtCore.QRect(280, 330, 101, 28))
self.L_button.setObjectName("L_button")
self.S_button = QtWidgets.QPushButton(self.centralwidget)
self.S_button.setGeometry(QtCore.QRect(400, 330, 93, 28))
self.S_button.setObjectName("S_button")
#self.F_passwd = QtWidgets.QLabel(self.centralwidget)
#self.F_passwd.setGeometry(QtCore.QRect(460, 200, 101, 16))
#self.F_passwd.setObjectName("F_passwd")
self.error_reminder = QtWidgets.QLabel(self.centralwidget)
self.error_reminder.setGeometry(QtCore.QRect(260, 110, 301, 16))
self.error_reminder.setObjectName("error_reminder")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 26))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.id_choice.addItems(['用户','管理员'])#身份选择列表
# self.L_button.clicked.connect(self.login)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
'''def login(self):
id = self.id_choice.currentText()
ac = self.Laccount.text()
pw = self.Lpasswd.text()
if id=='用户':
print("%s 用户:%s 在尝试登录" %(datetime.datetime.now(),self.Laccount.text()))
user = conn.cursor()
sql = "select * from 用户表 where 手机号='%s' and 密码='%s'"%(ac,pw)
user.execute(sql)
if len(user.fetchall())==0:
print("%s 登录失败"%datetime.datetime.now())
self.error_reminder.show()
else:
print("%s 登录成功,进入用户主页" % datetime.datetime.now())
self.error_reminder.hide()
user.close()
if id=='管理员':
print("%s 管理员:%s 在尝试登录" % (datetime.datetime.now(), self.Laccount.text()))
admin = conn.cursor()
sql = "select * from 管理员表 where 管理员账号='%s' and 密码='%s'" %(ac,pw)
admin.execute(sql)
if len(admin.fetchall())==0:
print("%s 登录失败" % datetime.datetime.now())
self.error_reminder.show()
else:
print("%s 登录成功,进入管理员主页" % datetime.datetime.now())
self.error_reminder.hide()
admin.close()'''
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "登录界面"))
self.label.setText(_translate("MainWindow", "火车售票管理信息系统
"))
self.label_2.setText(_translate("MainWindow", "账号:"))
self.Laccount.setPlaceholderText(_translate("MainWindow", "请输入手机号"))
self.Lpasswd.setPlaceholderText(_translate("MainWindow", "请输入密码"))
self.label_3.setText(_translate("MainWindow", "密码:"))
self.label_4.setText(_translate("MainWindow", "请选择身份:"))
self.L_button.setText(_translate("MainWindow", "登录"))
self.S_button.setText(_translate("MainWindow", "注册"))
#self.F_passwd.setText(_translate("MainWindow", "忘记密码?"))
self.error_reminder.setText(_translate("MainWindow", "密码或账号错误,请重新输入!!!
"))
self.error_reminder.hide()
import thp
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
注册UI实现:通过显示验证码的方式来实现验证
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'register.ui'
#
# Created by: PyQt5 UI code generator 5.15.4
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QMessageBox
import random
import pymysql
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(800, 600)
font = QtGui.QFont()
font.setFamily("Arial")
MainWindow.setFont(font)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(300, 460, 121, 51))
font = QtGui.QFont()
font.setFamily("Arial")
font.setPointSize(24)
self.pushButton.setFont(font)
self.pushButton.setObjectName("pushButton")
self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_2.setGeometry(QtCore.QRect(620, 20, 101, 41))
font = QtGui.QFont()
font.setFamily("Arial")
font.setPointSize(18)
self.pushButton_2.setFont(font)
self.pushButton_2.setObjectName("pushButton_2")
self.pushButton_3 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_3.setGeometry(QtCore.QRect(390, 360, 81, 41))
font = QtGui.QFont()
font.setFamily("Arial")
font.setPointSize(18)
self.pushButton_3.setFont(font)
self.pushButton_3.setObjectName("pushButton_3")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(470, 90, 171, 31))
palette = QtGui.QPalette()
brush = QtGui.QBrush(QtGui.QColor(231, 56, 13))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(231, 56, 13))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(120, 120, 120))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.WindowText, brush)
self.label.setPalette(palette)
self.label.setObjectName("label")
self.label_2 = QtWidgets.QLabel(self.centralwidget)
self.label_2.setGeometry(QtCore.QRect(470, 140, 171, 31))
palette = QtGui.QPalette()
brush = QtGui.QBrush(QtGui.QColor(234, 6, 41))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(234, 6, 41))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(120, 120, 120))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.WindowText, brush)
self.label_2.setPalette(palette)
self.label_2.setObjectName("label_2")
self.label_3 = QtWidgets.QLabel(self.centralwidget)
self.label_3.setGeometry(QtCore.QRect(470, 200, 171, 31))
palette = QtGui.QPalette()
brush = QtGui.QBrush(QtGui.QColor(232, 9, 50))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(232, 9, 50))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(120, 120, 120))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.WindowText, brush)
self.label_3.setPalette(palette)
self.label_3.setObjectName("label_3")
self.label_4 = QtWidgets.QLabel(self.centralwidget)
self.label_4.setGeometry(QtCore.QRect(470, 250, 171, 31))
palette = QtGui.QPalette()
brush = QtGui.QBrush(QtGui.QColor(239, 7, 61))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(239, 7, 61))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(120, 120, 120))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.WindowText, brush)
self.label_4.setPalette(palette)
self.label_4.setObjectName("label_4")
self.label_5 = QtWidgets.QLabel(self.centralwidget)
self.label_5.setGeometry(QtCore.QRect(470, 300, 171, 31))
palette = QtGui.QPalette()
brush = QtGui.QBrush(QtGui.QColor(239, 13, 43))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(239, 13, 43))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(120, 120, 120))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.WindowText, brush)
self.label_5.setPalette(palette)
self.label_5.setObjectName("label_5")
self.label_6 = QtWidgets.QLabel(self.centralwidget)
self.label_6.setGeometry(QtCore.QRect(230, 410, 171, 31))
palette = QtGui.QPalette()
brush = QtGui.QBrush(QtGui.QColor(239, 11, 34))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(239, 11, 34))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(120, 120, 120))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.WindowText, brush)
self.label_6.setPalette(palette)
self.label_6.setTextFormat(QtCore.Qt.AutoText)
self.label_6.setObjectName("label_6")
self.widget = QtWidgets.QWidget(self.centralwidget)
self.widget.setGeometry(QtCore.QRect(220, 80, 241, 261))
self.widget.setObjectName("widget")
self.verticalLayout = QtWidgets.QVBoxLayout(self.widget)
self.verticalLayout.setContentsMargins(0, 0, 0, 0)
self.verticalLayout.setSpacing(10)
self.verticalLayout.setObjectName("verticalLayout")
self.lineEdit_6 = QtWidgets.QLineEdit(self.widget)
font = QtGui.QFont()
font.setFamily("Arial")
font.setPointSize(18)
self.lineEdit_6.setFont(font)
self.lineEdit_6.setObjectName("lineEdit_6")
self.verticalLayout.addWidget(self.lineEdit_6)
self.lineEdit = QtWidgets.QLineEdit(self.widget)
font = QtGui.QFont()
font.setFamily("Arial")
font.setPointSize(18)
self.lineEdit.setFont(font)
self.lineEdit.setObjectName("lineEdit")
self.verticalLayout.addWidget(self.lineEdit)
self.lineEdit_2 = QtWidgets.QLineEdit(self.widget)
font = QtGui.QFont()
font.setFamily("Arial")
font.setPointSize(18)
self.lineEdit_2.setFont(font)
self.lineEdit_2.setObjectName("lineEdit_2")
self.verticalLayout.addWidget(self.lineEdit_2)
self.lineEdit_3 = QtWidgets.QLineEdit(self.widget)
font = QtGui.QFont()
font.setFamily("Arial")
font.setPointSize(18)
self.lineEdit_3.setFont(font)
self.lineEdit_3.setObjectName("lineEdit_3")
self.verticalLayout.addWidget(self.lineEdit_3)
self.lineEdit_4 = QtWidgets.QLineEdit(self.widget)
font = QtGui.QFont()
font.setFamily("Arial")
font.setPointSize(18)
self.lineEdit_4.setFont(font)
self.lineEdit_4.setObjectName("lineEdit_4")
self.verticalLayout.addWidget(self.lineEdit_4)
self.widget1 = QtWidgets.QWidget(self.centralwidget)
self.widget1.setGeometry(QtCore.QRect(220, 350, 161, 61))
self.widget1.setObjectName("widget1")
self.horizontalLayout = QtWidgets.QHBoxLayout(self.widget1)
self.horizontalLayout.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout.setObjectName("horizontalLayout")
self.lineEdit_5 = QtWidgets.QLineEdit(self.widget1)
font = QtGui.QFont()
font.setFamily("Arial")
font.setPointSize(18)
self.lineEdit_5.setFont(font)
self.lineEdit_5.setObjectName("lineEdit_5")
self.horizontalLayout.addWidget(self.lineEdit_5)
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 21))
self.menubar.setObjectName("menubar")
self.menu = QtWidgets.QMenu(self.menubar)
self.menu.setObjectName("menu")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.menubar.addAction(self.menu.menuAction())
self.pushButton.clicked.connect(self.go_Log2)
a = self.random_num()
self.pushButton_3.setText(a)
self.pushButton_3.clicked.connect(self.yzm)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
self.label_2.setVisible(False)
self.label_3.setVisible(False)
self.label.setVisible(False) #手机号
self.label_4.setVisible(False) #密码
self.label_5.setVisible(False) #身份证
self.label_6.setVisible(False) #验证码
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.pushButton.setText(_translate("MainWindow", "确认"))
self.pushButton_2.setText(_translate("MainWindow", "返回"))
self.label.setText(_translate("MainWindow", "当前手机号已存在"))
self.label_2.setText(_translate("MainWindow", "当前用户名已存在"))
self.label_3.setText(_translate("MainWindow", "请输入全部的信息"))
self.label_4.setText(_translate("MainWindow", "密码不一致,请重新输入"))
self.label_5.setText(_translate("MainWindow", "当身份证号已被绑定"))
self.label_6.setText(_translate("MainWindow", "请重新输入验证码"))
self.lineEdit_6.setPlaceholderText(_translate("MainWindow", "请输入手机号"))
self.lineEdit.setPlaceholderText(_translate("MainWindow", "请输入用户名"))
self.lineEdit_2.setPlaceholderText(_translate("MainWindow", "请输入密码"))
self.lineEdit_3.setPlaceholderText(_translate("MainWindow", "再次输入确认密码"))
self.lineEdit_4.setPlaceholderText(_translate("MainWindow", "请输入身份证号"))
self.lineEdit_5.setPlaceholderText(_translate("MainWindow", "请输入验证码"))
self.menu.setTitle(_translate("MainWindow", "账号注册"))
#在进入注册界面时先生成一个随机验证码
def yzm(self):
b = self.random_num()
self.pushButton_3.setText(b)
def random_num(self):
temp = ''
check_num = 4 #验证码位数
for i in range(check_num): # check_num为需要循环的次数,也就是需要生成验证码的个数,默认为4
choice = random.randint(1, 3) # 生成1到3的随机数
if choice == 1: # 如果choice为1,则随机验证码的值为数字
temp += random.choice('0123456789')
elif choice == 2: # 如果choice为2,则随机验证码的值为大写字母
num = random.randint(65, 90)
temp += chr(num)
elif choice == 3: # 如果choice为3,则随机验证码的值为小写字母
num = random.randint(97, 122)
temp += chr(num)
return temp
def go_Log2(self):
conn = pymysql.connect(host='localhost',
port=3306,
user='root',
password='111111',
database='train',
charset='utf8')
cursor = conn.cursor()
success = 0 #用于确保全部注册信息都正确
#每次点击确认出错后,下一次点击时先清空错误提示
self.label.setVisible(False) #手机号
self.label_4.setVisible(False) #密码
self.label_5.setVisible(False) #身份证
self.label_6.setVisible(False) #验证码
tel = self.lineEdit_6.text()
usr = self.lineEdit.text()
pas1 = self.lineEdit_2.text()
pas2 = self.lineEdit_3.text()
ide = self.lineEdit_4.text()
code = self.lineEdit_5.text()
if tel != '' and usr != '' and pas1 != '' and pas2 != '' and ide != '' and code != '' :
sql1 = "select * from 用户表 where 手机号 = '%s' " %(tel)
cursor.execute(sql1)
r = cursor.fetchall()
lr = len(r)
sql2 = "select * from 用户表 where 身份证号 = '%s' " %(ide)
cursor.execute(sql2)
r2 = cursor.fetchall()
lr2 = len(r2)
if lr != 0:
self.label.setVisible(True)
success = 1
if lr2 != 0:
self.label_5.setVisible(True)
success = 1
#获取当前的验证码的值
c = self.pushButton_3.text()
if code != c :
#验证码输入错误时,自动刷新生成新的验证码
self.yzm()
self.label_6.setVisible(True)
success = 1
if pas1 != pas2 :
self.label_4.setVisible(True)
success = 1
checkID = "select * from 身份表 where 姓名='%s' and 身份证号码='%s'" % (usr, ide)
cursor.execute(checkID)
if cursor.rowcount == 0:
success = 1
QMessageBox.critical(self, "身份信息错误", "请重新输入正确的身份信息")
checkPhone = "select * from 手机号表 where 手机号码='%s'" % (tel)
cursor.execute(checkPhone)
if cursor.rowcount == 0:
success = 1
QMessageBox.critical(self, "手机号码错误", "请重新输入正确的手机号码信息")
if success == 0:
sql3 = "insert into 用户表 (手机号,密码,姓名,身份证号,余额) values ('%s','%s','%s','%s',0)" % (tel,pas1,usr,ide)
cursor.execute(sql3)
conn.commit() #提交数据
QMessageBox.information(self, "注册", "注册成功!!!")
self.pushButton_2.click()
else:
self.label_3.setVisible(True)
QMessageBox.critical(self, "错误", "请输入完整信息!!!")
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
用户主页UI功能设计:个人信息、购票大厅、我的订单三个功能模块、内含部分逻辑设计
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'User_homeUI.ui'
#
# Created by: PyQt5 UI code generator 5.15.6
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
import thp
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(800, 600)
MainWindow.setStyleSheet("#MainWindow{border-image: url(:/thpic/60.jpg);}")
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(250, 20, 281, 41))
self.label.setObjectName("label")
self.L_out = QtWidgets.QPushButton(self.centralwidget)
self.L_out.setGeometry(QtCore.QRect(630, 70, 93, 28))
self.L_out.setObjectName("L_out")
self.U_date = QtWidgets.QLabel(self.centralwidget)
self.U_date.setGeometry(QtCore.QRect(30, 510, 72, 15))
self.U_date.setObjectName("U_date")
self.P_information = QtWidgets.QPushButton(self.centralwidget)
self.P_information.setGeometry(QtCore.QRect(80, 290, 211, 141))
self.P_information.setObjectName("P_information")
self.M_order = QtWidgets.QPushButton(self.centralwidget)
self.M_order.setGeometry(QtCore.QRect(520, 290, 211, 141))
self.M_order.setObjectName("M_order")
self.T_hall = QtWidgets.QPushButton(self.centralwidget)
self.T_hall.setGeometry(QtCore.QRect(300, 290, 211, 141))
self.T_hall.setObjectName("T_hall")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 26))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "用户主页"))
self.label.setText(_translate("MainWindow", "火车售票管理信息系统
"))
self.L_out.setText(_translate("MainWindow", "退出登录"))
self.U_date.setText(_translate("MainWindow", "TextLabel"))
self.P_information.setText(_translate("MainWindow", "个人信息"))
self.M_order.setText(_translate("MainWindow", "我的订单"))
self.T_hall.setText(_translate("MainWindow", "购票大厅"))
self.U_date.hide()
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
用户-个人信息UI设计:展示用户的信息,内含充值以及修改密码的功能
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'p_informationUI.ui'
#
# Created by: PyQt5 UI code generator 5.15.6
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
import pymysql
import thp
conn = pymysql.connect(
host='localhost',
port=3306,
user='root',
passwd='111111',
db='train',
charset='utf8'
)
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(800, 600)
MainWindow.setStyleSheet("#MainWindow{border-image: url(:/thpic/60.jpg);}")
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(330, 20, 131, 41))
self.label.setObjectName("label")
self.U_date = QtWidgets.QLabel(self.centralwidget)
self.U_date.setGeometry(QtCore.QRect(30, 510, 72, 15))
self.U_date.setObjectName("U_date")
self.label_2 = QtWidgets.QLabel(self.centralwidget)
self.label_2.setGeometry(QtCore.QRect(270, 130, 71, 21))
self.label_2.setObjectName("label_2")
self.U_phonenumber = QtWidgets.QLabel(self.centralwidget)
self.U_phonenumber.setGeometry(QtCore.QRect(340, 130, 151, 21))
self.U_phonenumber.setObjectName("U_phonenumber")
self.label_4 = QtWidgets.QLabel(self.centralwidget)
self.label_4.setGeometry(QtCore.QRect(290, 170, 51, 21))
self.label_4.setObjectName("label_4")
self.U_password = QtWidgets.QLabel(self.centralwidget)
self.U_password.setGeometry(QtCore.QRect(340, 170, 151, 21))
self.U_password.setObjectName("U_password")
self.label_6 = QtWidgets.QLabel(self.centralwidget)
self.label_6.setGeometry(QtCore.QRect(290, 210, 41, 21))
self.label_6.setObjectName("label_6")
self.U_name = QtWidgets.QLabel(self.centralwidget)
self.U_name.setGeometry(QtCore.QRect(340, 210, 151, 21))
self.U_name.setObjectName("U_name")
self.label_8 = QtWidgets.QLabel(self.centralwidget)
self.label_8.setGeometry(QtCore.QRect(240, 250, 101, 21))
self.label_8.setObjectName("label_8")
self.U_id = QtWidgets.QLabel(self.centralwidget)
self.U_id.setGeometry(QtCore.QRect(340, 250, 151, 21))
self.U_id.setObjectName("U_id")
self.label_10 = QtWidgets.QLabel(self.centralwidget)
self.label_10.setGeometry(QtCore.QRect(290, 290, 51, 21))
self.label_10.setObjectName("label_10")
self.U_balance = QtWidgets.QLabel(self.centralwidget)
self.U_balance.setGeometry(QtCore.QRect(340, 290, 151, 21))
self.U_balance.setObjectName("U_balance")
self.M_pwbutton = QtWidgets.QPushButton(self.centralwidget)
self.M_pwbutton.setGeometry(QtCore.QRect(280, 360, 93, 28))
self.M_pwbutton.setObjectName("M_pwbutton")
self.add_moneybutton = QtWidgets.QPushButton(self.centralwidget)
self.add_moneybutton.setGeometry(QtCore.QRect(380, 360, 93, 28))
self.add_moneybutton.setObjectName("add_moneybutton")
self.e_p_informstion = QtWidgets.QPushButton(self.centralwidget)
self.e_p_informstion.setGeometry(QtCore.QRect(280, 410, 191, 28))
self.e_p_informstion.setObjectName("e_p_informstion")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 26))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "个人信息"))
self.label.setText(_translate("MainWindow", "个人信息
"))
self.U_date.setText(_translate("MainWindow", "TextLabel"))
self.label_2.setText(_translate("MainWindow", "手机号:
"))
self.label_4.setText(_translate("MainWindow", "密码:
"))
self.label_6.setText(_translate("MainWindow", "姓名:
"))
self.label_8.setText(_translate("MainWindow", "身份证号码:
"))
self.label_10.setText(_translate("MainWindow", "余额:
"))
self.M_pwbutton.setText(_translate("MainWindow", "修改密码"))
self.add_moneybutton.setText(_translate("MainWindow", "充值"))
self.e_p_informstion.setText(_translate("MainWindow", "返回"))
self.U_date.hide()
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
用户-个人信息-修改密码UI设计
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'modify_passwdUI.ui'
#
# Created by: PyQt5 UI code generator 5.15.6
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
import pymysql
import datetime
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QMessageBox
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(800, 600)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(330, 20, 131, 41))
self.label.setObjectName("label")
self.ensureButton = QtWidgets.QPushButton(self.centralwidget)
self.ensureButton.setGeometry(QtCore.QRect(330, 230, 141, 28))
self.ensureButton.setObjectName("ensureButton")
self.exitButton = QtWidgets.QPushButton(self.centralwidget)
self.exitButton.setGeometry(QtCore.QRect(330, 270, 141, 28))
self.exitButton.setObjectName("exitButton")
self.M_passwd = QtWidgets.QLineEdit(self.centralwidget)
self.M_passwd.setGeometry(QtCore.QRect(330, 120, 141, 31))
self.M_passwd.setObjectName("M_passwd")
self.M_passwd1 = QtWidgets.QLineEdit(self.centralwidget)
self.M_passwd1.setGeometry(QtCore.QRect(330, 160, 141, 31))
self.M_passwd1.setObjectName("M_passwd1")
self.error_reminder = QtWidgets.QLabel(self.centralwidget)
self.error_reminder.setGeometry(QtCore.QRect(330, 200, 141, 20))
self.error_reminder.setObjectName("error_reminder")
self.U_date = QtWidgets.QLabel(self.centralwidget)
self.U_date.setGeometry(QtCore.QRect(40, 510, 72, 15))
self.U_date.setObjectName("U_date")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 26))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.ensureButton.clicked.connect(self.modify)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "修改密码"))
self.label.setText(_translate("MainWindow", "修改密码
"))
self.ensureButton.setText(_translate("MainWindow", "确定修改"))
self.exitButton.setText(_translate("MainWindow", "退出修改"))
self.M_passwd.setPlaceholderText(_translate("MainWindow", "请输入新的密码"))
self.M_passwd1.setPlaceholderText(_translate("MainWindow", "请再次输入新的密码"))
self.U_date.setText(_translate("MainWindow", "TextLabel"))
self.U_date.hide()
def modify(self):
self.error_reminder.setText("密码不一致!!!
")
self.error_reminder.hide()
conn = pymysql.connect(
host='localhost',
port=3306,
user='root',
passwd='111111',
db='train',
charset='utf8'
)
u = self.U_date.text()
p = self.M_passwd.text()
p1 = self.M_passwd1.text()
if p!=p1:
print("%s 修改密码失败"%datetime.datetime.now())
self.error_reminder.show()
else:
cursor = conn.cursor()
sql = "update 用户表 set 密码='%s' where 手机号='%s' "%(p,u)
cursor.execute(sql)
conn.commit()
cursor.close()
conn.close()
QMessageBox.information(self,"成功","成功修改密码!")
self.exitButton.click()
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
用户-个人信息-充值中心UI设计
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'voucher_centerUI.ui'
#
# Created by: PyQt5 UI code generator 5.15.6
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QMessageBox
from PyQt5 import QtCore, QtGui, QtWidgets
import string
import pymysql
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(800, 600)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(330, 20, 131, 41))
self.label.setObjectName("label")
self.ensureButton = QtWidgets.QPushButton(self.centralwidget)
self.ensureButton.setGeometry(QtCore.QRect(330, 230, 141, 28))
self.ensureButton.setObjectName("ensureButton")
self.exitButton = QtWidgets.QPushButton(self.centralwidget)
self.exitButton.setGeometry(QtCore.QRect(330, 270, 141, 28))
self.exitButton.setObjectName("exitButton")
self.re_amount = QtWidgets.QLineEdit(self.centralwidget)
self.re_amount.setGeometry(QtCore.QRect(330, 160, 141, 31))
self.re_amount.setObjectName("re_amount")
self.U_date = QtWidgets.QLabel(self.centralwidget)
self.U_date.setGeometry(QtCore.QRect(40, 510, 72, 15))
self.U_date.setObjectName("U_date")
self.label_2 = QtWidgets.QLabel(self.centralwidget)
self.label_2.setGeometry(QtCore.QRect(240, 160, 81, 41))
self.label_2.setObjectName("label_2")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 26))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.ensureButton.clicked.connect(self.addmoney)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "充值中心"))
self.label.setText(_translate("MainWindow", "充值中心
"))
self.ensureButton.setText(_translate("MainWindow", "确定充值"))
self.exitButton.setText(_translate("MainWindow", "关闭充值窗口"))
self.re_amount.setPlaceholderText(_translate("MainWindow", "请输入金额"))
self.U_date.setText(_translate("MainWindow", "TextLabel"))
self.label_2.setText(_translate("MainWindow", "充值金额:
"))
self.U_date.hide()
def addmoney(self):
user = self.U_date.text()
money = self.re_amount.text()
m = int(money)
conn = pymysql.connect(
host='localhost',
port=3306,
user='root',
passwd='111111',
db='train',
charset='utf8'
)
cursor = conn.cursor()
sql = "update 用户表 set 余额=余额+%s where 手机号='%s'"%(m,user)
cursor.execute(sql)
conn.commit()
cursor.close()
conn.close()
re = "成功充值"+money+"元!!!"
QMessageBox.information(self,"充值",re)
self.exitButton.click()
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
用户-购票大厅UI设计:通过时间、起始站和终点站进行检索,以列表的方式展示列车信息,这里需要熟悉python的exec()函数,还需要注意列表中的功能键绑定
exec()函数的使用可以参考其他博主的介绍,例如:添加链接描述
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'Ticket_hallUI.ui'
#
# Created by: PyQt5 UI code generator 5.15.6
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
import datetime
import pymysql
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtCore import pyqtSlot, QDate
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QMessageBox
import time
import string
import thp
class Ui_MainWindow(object):
numb = 0
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(800, 600)
MainWindow.setStyleSheet("#MainWindow{border-image: url(:/thpic/60.jpg);}")
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.comboBox = QtWidgets.QComboBox(self.centralwidget)
self.comboBox.setGeometry(QtCore.QRect(120, 70, 87, 22))
self.comboBox.setObjectName("comboBox")
self.dateEdit = QtWidgets.QDateEdit(self.centralwidget)
self.dateEdit.setGeometry(QtCore.QRect(300, 70, 110, 22))
self.dateEdit.setObjectName("dateEdit")
self.comboBox_2 = QtWidgets.QComboBox(self.centralwidget)
self.comboBox_2.setGeometry(QtCore.QRect(530, 70, 87, 22))
self.comboBox_2.setObjectName("comboBox_2")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(140, 40, 72, 15))
self.label.setObjectName("label")
self.label_2 = QtWidgets.QLabel(self.centralwidget)
self.label_2.setGeometry(QtCore.QRect(320, 40, 72, 15))
self.label_2.setObjectName("label_2")
self.label_3 = QtWidgets.QLabel(self.centralwidget)
self.label_3.setGeometry(QtCore.QRect(530, 40, 72, 15))
self.label_3.setObjectName("label_3")
self.scrollArea = QtWidgets.QScrollArea(self.centralwidget)
self.scrollArea.setGeometry(QtCore.QRect(10, 130, 761, 381))
self.scrollArea.setWidgetResizable(False)
self.scrollArea.setObjectName("scrollArea")
self.scrollAreaWidgetContents = QtWidgets.QWidget()
self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 749, 349))
self.scrollAreaWidgetContents.setObjectName("scrollAreaWidgetContents")
self.train_no0 = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.train_no0.setGeometry(QtCore.QRect(10, 10, 51, 16))
self.train_no0.setObjectName("train_no0")
self.b_station0 = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.b_station0.setGeometry(QtCore.QRect(80, 10, 51, 16))
self.b_station0.setObjectName("b_station0")
self.e_station0 = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.e_station0.setGeometry(QtCore.QRect(150, 10, 72, 15))
self.e_station0.setObjectName("e_station0")
self.b_date0 = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.b_date0.setGeometry(QtCore.QRect(230, 10, 72, 15))
self.b_date0.setObjectName("b_date0")
self.b_time0 = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.b_time0.setGeometry(QtCore.QRect(320, 10, 72, 15))
self.b_time0.setObjectName("b_time0")
self.line0 = QtWidgets.QFrame(self.scrollAreaWidgetContents)
self.line0.setGeometry(QtCore.QRect(0, 30, 741, 20))
self.line0.setFrameShape(QtWidgets.QFrame.HLine)
self.line0.setFrameShadow(QtWidgets.QFrame.Sunken)
self.line0.setObjectName("line0")
self.e_time0 = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.e_time0.setGeometry(QtCore.QRect(520, 10, 72, 15))
self.e_time0.setObjectName("e_time0")
self.e_date0 = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.e_date0.setGeometry(QtCore.QRect(430, 10, 72, 15))
self.e_date0.setObjectName("e_date0")
self.scrollArea.setWidget(self.scrollAreaWidgetContents)
self.checkButton = QtWidgets.QPushButton(self.centralwidget)
self.checkButton.setGeometry(QtCore.QRect(650, 70, 93, 28))
self.checkButton.setObjectName("checkButton")
self.exitbutton = QtWidgets.QPushButton(self.centralwidget)
self.exitbutton.setGeometry(QtCore.QRect(320, 520, 93, 28))
self.exitbutton.setObjectName("exitbutton")
self.U_data = QtWidgets.QLabel(self.centralwidget)
self.U_data.setGeometry(QtCore.QRect(40, 520, 72, 15))
self.U_data.setObjectName("U_data")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 26))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.dateEdit.setDate(QDate.fromString(str(datetime.date.today()),1)) #定义时间,获取当天时间
self.dateEdit.setMinimumDateTime(QtCore.QDateTime(QDate.fromString(str(datetime.date.today()), 1), QtCore.QTime(0, 0, 0)))#最小时间
self.dateEdit.setCalendarPopup(True)#开启日历
self.dateEdit.dateTimeChanged.connect(self.check)#日期更新的时候查询
self.train= QtWidgets.QLabel(self.centralwidget)
self.train.setGeometry(QtCore.QRect(10, 10 ,72, 15))
self.train.setObjectName("train")
self.train_no = QtWidgets.QLabel(self.centralwidget)
self.train_no.setGeometry(QtCore.QRect(90, 10 , 72, 15))
self.train_no.setObjectName("train_no")
self.b_station = QtWidgets.QLabel(self.centralwidget)
self.b_station.setGeometry(QtCore.QRect(170, 10 , 72, 15))
self.b_station.setObjectName("b_station")
self.e_station = QtWidgets.QLabel(self.centralwidget)
self.e_station.setGeometry(QtCore.QRect(250, 10 , 72, 15))
self.e_station.setObjectName("e_station")
self.b_date = QtWidgets.QLabel(self.centralwidget)
self.b_date.setGeometry(QtCore.QRect(340, 10, 72, 15))
self.b_date.setObjectName("b_date")
self.e_date = QtWidgets.QLabel(self.centralwidget)
self.e_date.setGeometry(QtCore.QRect(340, 5, 72, 15))
self.e_date.setObjectName("e_date")
self.b_time= QtWidgets.QLabel(self.centralwidget)
self.b_time.setGeometry(QtCore.QRect(430, 10 , 72, 15))
self.b_time.setObjectName("b_time")
self.e_time = QtWidgets.QLabel(self.centralwidget)
self.e_time.setGeometry(QtCore.QRect(520, 10, 72, 15))
self.e_time.setObjectName("b_time")
self.first_p = QtWidgets.QLabel(self.centralwidget)
self.first_p.setGeometry(QtCore.QRect(610, 10 , 72, 15))
self.first_p.setObjectName("first_p")
self.second_p = QtWidgets.QLabel(self.centralwidget)
self.second_p.setGeometry(QtCore.QRect(700, 10, 72, 15))
self.second_p.setObjectName("second_p")
conn = pymysql.connect(
host='localhost',
port=3306,
user='root',
passwd='111111',
db='train',
charset='utf8'
)
cursor = conn.cursor()
cursor.execute("select * from 列车表 where 列车状态='运行'")
self.numb = cursor.rowcount
cursor.close()
conn.close()
for i in range(self.numb):
exec('''
self.train{j} = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.train{j}.setGeometry(QtCore.QRect(650, 100+{y}, 51, 16))
self.train{j}.setObjectName("train0")
self.train_no{j} = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.train_no{j}.setGeometry(QtCore.QRect(10, 60+{y}, 51, 16))
self.train_no{j}.setObjectName("train_no0")
self.b_station{j} = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.b_station{j}.setGeometry(QtCore.QRect(80, 60+{y}, 51, 16))
self.b_station{j}.setObjectName("b_station0")
self.e_station{j} = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.e_station{j}.setGeometry(QtCore.QRect(150, 60+{y}, 72, 15))
self.e_station{j}.setObjectName("e_station0")
self.b_date{j} = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.b_date{j}.setGeometry(QtCore.QRect(230, 60+{y}, 72, 15))
self.b_date{j}.setObjectName("b_date0")
self.b_time{j} = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.b_time{j}.setGeometry(QtCore.QRect(320, 60+{y}, 72, 15))
self.b_time{j}.setObjectName("b_time0")
self.line{j} = QtWidgets.QFrame(self.scrollAreaWidgetContents)
self.line{j}.setGeometry(QtCore.QRect(0, 120+{y}, 741, 20))
self.line{j}.setFrameShape(QtWidgets.QFrame.HLine)
self.line{j}.setFrameShadow(QtWidgets.QFrame.Sunken)
self.line{j}.setObjectName("line")
self.buyButton{j} = QtWidgets.QPushButton(self.scrollAreaWidgetContents)
self.buyButton{j}.setGeometry(QtCore.QRect(640, 70+{y}, 93, 28))
self.buyButton{j}.setObjectName("buyButton{j}")
self.e_time{j} = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.e_time{j}.setGeometry(QtCore.QRect(520, 60+{y}, 72, 15))
self.e_time{j}.setObjectName("e_time")
self.e_date{j} = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.e_date{j}.setGeometry(QtCore.QRect(430, 60+{y}, 72, 15))
self.e_date{j}.setObjectName("e_date0")
self.first_txt{j} = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.first_txt{j}.setGeometry(QtCore.QRect(10, 100+{y}, 91, 16))
self.first_txt{j}.setObjectName("first_txt0")
self.first{j} = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.first{j}.setGeometry(QtCore.QRect(100, 100+{y}, 51, 16))
self.first{j}.setObjectName("first0")
self.first_p{j} = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.first_p{j}.setGeometry(QtCore.QRect(260, 100+{y}, 51, 16))
self.first_p{j}.setObjectName("first_p0")
self.first_p_txt{j} = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.first_p_txt{j}.setGeometry(QtCore.QRect(170, 100+{y}, 91, 16))
self.first_p_txt{j}.setObjectName("first_p_txt")
self.second_p_txt{j} = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.second_p_txt{j}.setGeometry(QtCore.QRect(520, 100+{y}, 91, 16))
self.second_p_txt{j}.setObjectName("second_p_txt0")
self.second{j} = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.second{j}.setGeometry(QtCore.QRect(450, 100+{y}, 51, 16))
self.second{j}.setObjectName("second0")
self.second_p{j} = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.second_p{j}.setGeometry(QtCore.QRect(610, 100+{y}, 51, 16))
self.second_p{j}.setObjectName("second_p0")
self.second_txt{j} = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.second_txt{j}.setGeometry(QtCore.QRect(360, 100+{y}, 91, 16))
self.second_txt{j}.setObjectName("second_txt0")
self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 749, 349+{y}))
self.buyButton{j}.clicked.connect(self.pr)
'''.format(j=i + 1, y=90 * i))
self.checkButton.clicked.connect(self.check)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "购票大厅"))
self.label.setText(_translate("MainWindow", "出发站"))
self.label_2.setText(_translate("MainWindow", "出发日期"))
self.label_3.setText(_translate("MainWindow", "终点站"))
self.train_no0.setText(_translate("MainWindow", "列车号"))
self.b_station0.setText(_translate("MainWindow", "出发站"))
self.e_station0.setText(_translate("MainWindow", "终点站"))
self.b_date0.setText(_translate("MainWindow", "发车日期"))
self.b_time0.setText(_translate("MainWindow", "发车时间"))
self.e_time0.setText(_translate("MainWindow", "到达时间"))
self.e_date0.setText(_translate("MainWindow", "到达日期"))
self.checkButton.setText(_translate("MainWindow", "查询车票"))
self.exitbutton.setText(_translate("MainWindow", "返回"))
self.U_data.setText(_translate("MainWindow", "TextLabel"))
self.U_data.hide()
for i in range(self.numb):
exec('''
self.train{j}.hide()
self.train_no{j}.hide()
self.b_station{j}.hide()
self.e_station{j}.hide()
self.b_date{j}.hide()
self.b_time{j}.hide()
self.e_date{j}.hide()
self.e_time{j}.hide()
self.first_txt{j}.hide()
self.first{j}.hide()
self.first_p_txt{j}.hide()
self.first_p{j}.hide()
self.second_txt{j}.hide()
self.second{j}.hide()
self.second_p_txt{j}.hide()
self.second_p{j}.hide()
self.line{j}.hide()
self.buyButton{j}.hide()
self.buyButton{j}.setText("购买")
'''.format(j=i + 1))
def check(self):
for i in range(self.numb):
exec('''
self.train_no{j}.hide()
self.b_station{j}.hide()
self.e_station{j}.hide()
self.b_date{j}.hide()
self.b_time{j}.hide()
self.e_date{j}.hide()
self.e_time{j}.hide()
self.first_txt{j}.hide()
self.first{j}.hide()
self.first_p_txt{j}.hide()
self.first_p{j}.hide()
self.second_txt{j}.hide()
self.second{j}.hide()
self.second_p_txt{j}.hide()
self.second_p{j}.hide()
self.line{j}.hide()
self.buyButton{j}.hide()
'''.format(j=i + 1))
b = self.comboBox.currentText()#出发站
e = self.comboBox_2.currentText()#终点站
day1 = self.dateEdit.text()
day = str(day1)
print("账号:%s" % self.U_data.text())
print("%s->%s,日期:%s" % (b, e, day))
print("%s 查询列车" % datetime.datetime.now())
conn = pymysql.connect(
host='localhost',
port=3306,
user='root',
passwd='111111',
db='train',
charset='utf8'
)
cursor = conn.cursor()
z = "%" + b + "%" + e + "%"
sql = "select 列车编号 from 列车表 where 途径站 like '%s' and 列车编号 in (select 车站表.列车编号 from 车站表 where 车站名='%s' and date(车站表.发车日期)='%s'and 状态='未抵达')" % (z, b, day)
# sql = "select * from 列车表,车站表 where 车站表.列车编号 in (select 列车编号 from 列车表 where 途径站 like '%s') and 车站表.车站名 in ('%s','%s') "%(z,s,e)
cursor.execute(sql)
c = cursor.fetchall()
date = []
for i in c:
for j in i:
date2 = []
date2.append(j)
sql2 = "select 车次号,一等座数量,一等座价格,二等座数量,二等座价格 from 列车表 where 列车编号='%s'" % j
cursor.execute(sql2)
p = cursor.fetchall()
for a in p:
for b1 in a:
date2.append(b1)
sql1 = "select 车站名,发车日期,发车时间 from 车站表 where 列车编号='%s' and 车站名 in ('%s','%s') and date(发车日期)>='%s'" % (j, b, e, day)
cursor.execute(sql1)
y = cursor.fetchall()
for n in y:
for m in n:
date2.append(m)
sql3 = "select count(列车编号) from 座位表 where 列车编号='%s' and 座位级别='一等座'"%j
cursor.execute(sql3)
num = cursor.fetchall()
for c in num:
for d in c:
date2[2] = date2[2]-d
sql4 = "select count(列车编号) from 座位表 where 列车编号='%s' and 座位级别='二等座'" % j
cursor.execute(sql4)
num1 = cursor.fetchall()
for c1 in num1:
for d1 in c1:
date2[4] = date2[4] -d1
d1 = datetime.datetime.now().strftime("%Y/%m/%d %H:%M")
d = date2[7]+" "+date2[8]
d2 = datetime.datetime.strptime(d1,"%Y/%m/%d %H:%M")
d3 = datetime.datetime.strptime(d,"%Y/%m/%d %H:%M")
if d2<d3:
date.append(date2)
for i in range(len(date)):
exec('''
self.train_no{j}.show()
self.b_station{j}.show()
self.e_station{j}.show()
self.b_date{j}.show()
self.b_time{j}.show()
self.e_date{j}.show()
self.e_time{j}.show()
self.first_txt{j}.show()
self.first{j}.show()
self.first_p_txt{j}.show()
self.first_p{j}.show()
self.second_txt{j}.show()
self.second{j}.show()
self.second_p_txt{j}.show()
self.second_p{j}.show()
self.buyButton{j}.show()
self.line{j}.show()
self.train{j}.clear()
self.train_no{j}.clear()
self.b_station{j}.clear()
self.e_station{j}.clear()
self.b_date{j}.clear()
self.b_time{j}.clear()
self.e_date{j}.clear()
self.e_time{j}.clear()
self.first_txt{j}.clear()
self.first{j}.clear()
self.first_p_txt{j}.clear()
self.first_p{j}.clear()
self.second_txt{j}.clear()
self.second{j}.clear()
self.second_p_txt{j}.clear()
self.second_p{j}.clear()
self.train{j}.setText(str(date[{m}][0]))
self.train_no{j}.setText(str(date[{m}][1]))
self.b_station{j}.setText(str(date[{m}][6]))
self.e_station{j}.setText(str(date[{m}][9]))
self.b_date{j}.setText(str(date[{m}][7]))
self.b_time{j}.setText(str(date[{m}][8]))
self.e_date{j}.setText(str(date[{m}][10]))
self.e_time{j}.setText(str(date[{m}][11]))
self.first_txt{j}.setText("一等座余票:")
self.first{j}.setText(str(date[{m}][2]))
self.first_p_txt{j}.setText("一等座价格:")
self.first_p{j}.setText(str(date[{m}][3]))
self.second_txt{j}.setText("二等座余票:")
self.second{j}.setText(str(date[{m}][4]))
self.second_p_txt{j}.setText("二等座价格:")
self.second_p{j}.setText(str(date[{m}][5]))
'''.format(j=i + 1, y=30 * (i + 1), m=i))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
Form = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
用户-购票大厅-购票UI设计:这里可以选择座位所属的级别、车厢号以及座位号,购票时需要输入乘客的信息
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'buy_ticketUI.ui'
#
# Created by: PyQt5 UI code generator 5.15.6
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
import pymysql
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QMessageBox, QInputDialog, QLineEdit
import thp
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(800, 600)
MainWindow.setStyleSheet("#MainWindow{border-image: url(:/thpic/60.jpg);}")
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(330, 20, 131, 41))
self.label.setObjectName("label")
self.B_time = QtWidgets.QLabel(self.centralwidget)
self.B_time.setGeometry(QtCore.QRect(101, 114, 101, 31))
self.B_time.setObjectName("B_time")
self.B_station = QtWidgets.QLabel(self.centralwidget)
self.B_station.setGeometry(QtCore.QRect(130, 150, 41, 21))
self.B_station.setObjectName("B_station")
self.label_4 = QtWidgets.QLabel(self.centralwidget)
self.label_4.setGeometry(QtCore.QRect(230, 130, 331, 16))
self.label_4.setObjectName("label_4")
self.E_time = QtWidgets.QLabel(self.centralwidget)
self.E_time.setGeometry(QtCore.QRect(591, 114, 101, 31))
self.E_time.setObjectName("E_time")
self.E_station = QtWidgets.QLabel(self.centralwidget)
self.E_station.setGeometry(QtCore.QRect(620, 150, 41, 21))
self.E_station.setObjectName("E_station")
self.train_No = QtWidgets.QLabel(self.centralwidget)
self.train_No.setGeometry(QtCore.QRect(370, 110, 51, 20))
self.train_No.setObjectName("train_No")
self.B_date = QtWidgets.QLabel(self.centralwidget)
self.B_date.setGeometry(QtCore.QRect(100, 80, 101, 20))
self.B_date.setObjectName("B_date")
self.E_date = QtWidgets.QLabel(self.centralwidget)
self.E_date.setGeometry(QtCore.QRect(590, 80, 101, 20))
self.E_date.setObjectName("E_date")
self.horizontalLayoutWidget = QtWidgets.QWidget(self.centralwidget)
self.horizontalLayoutWidget.setGeometry(QtCore.QRect(160, 280, 451, 23))
self.horizontalLayoutWidget.setObjectName("horizontalLayoutWidget")
self.horizontalLayout = QtWidgets.QHBoxLayout(self.horizontalLayoutWidget)
self.horizontalLayout.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout.setObjectName("horizontalLayout")
self.comboBox = QtWidgets.QComboBox(self.horizontalLayoutWidget)
self.comboBox.setObjectName("comboBox")
self.horizontalLayout.addWidget(self.comboBox)
self.comboBox_1 = QtWidgets.QComboBox(self.horizontalLayoutWidget)
self.comboBox_1.setObjectName("comboBox_1")
self.horizontalLayout.addWidget(self.comboBox_1)
self.comboBox_2 = QtWidgets.QComboBox(self.horizontalLayoutWidget)
self.comboBox_2.setObjectName("comboBox_2")
self.horizontalLayout.addWidget(self.comboBox_2)
self.horizontalLayoutWidget_2 = QtWidgets.QWidget(self.centralwidget)
self.horizontalLayoutWidget_2.setGeometry(QtCore.QRect(160, 360, 451, 31))
self.horizontalLayoutWidget_2.setObjectName("horizontalLayoutWidget_2")
self.horizontalLayout_2 = QtWidgets.QHBoxLayout(self.horizontalLayoutWidget_2)
self.horizontalLayout_2.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout_2.setObjectName("horizontalLayout_2")
self.lineEdit = QtWidgets.QLineEdit(self.horizontalLayoutWidget_2)
self.lineEdit.setObjectName("lineEdit")
self.horizontalLayout_2.addWidget(self.lineEdit)
self.lineEdit_2 = QtWidgets.QLineEdit(self.horizontalLayoutWidget_2)
self.lineEdit_2.setObjectName("lineEdit_2")
self.horizontalLayout_2.addWidget(self.lineEdit_2)
self.horizontalLayoutWidget_3 = QtWidgets.QWidget(self.centralwidget)
self.horizontalLayoutWidget_3.setGeometry(QtCore.QRect(240, 470, 301, 31))
self.horizontalLayoutWidget_3.setObjectName("horizontalLayoutWidget_3")
self.horizontalLayout_3 = QtWidgets.QHBoxLayout(self.horizontalLayoutWidget_3)
self.horizontalLayout_3.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout_3.setObjectName("horizontalLayout_3")
self.buyButton = QtWidgets.QPushButton(self.horizontalLayoutWidget_3)
self.buyButton.setObjectName("buyButton")
self.horizontalLayout_3.addWidget(self.buyButton)
self.exitButton = QtWidgets.QPushButton(self.horizontalLayoutWidget_3)
self.exitButton.setObjectName("exitButton")
self.horizontalLayout_3.addWidget(self.exitButton)
self.U_date = QtWidgets.QLabel(self.centralwidget)
self.U_date.setGeometry(QtCore.QRect(30, 500, 72, 15))
self.U_date.setObjectName("U_date")
self.by_date = QtWidgets.QLabel(self.centralwidget)
self.by_date.setGeometry(QtCore.QRect(220, 150, 351, 20))
self.by_date.setObjectName("by_date")
self.T_date = QtWidgets.QLabel(self.centralwidget)
self.T_date.setGeometry(QtCore.QRect(20, 530, 72, 15))
self.T_date.setObjectName("U_date")
self.M_date = QtWidgets.QLabel(self.centralwidget)
self.M_date.setGeometry(QtCore.QRect(30, 530, 72, 15))
self.M_date.setObjectName("M_date")
self.horizontalLayoutWidget_4 = QtWidgets.QWidget(self.centralwidget)
self.horizontalLayoutWidget_4.setGeometry(QtCore.QRect(160, 250, 451, 21))
self.horizontalLayoutWidget_4.setObjectName("horizontalLayoutWidget_4")
self.horizontalLayout_4 = QtWidgets.QHBoxLayout(self.horizontalLayoutWidget_4)
self.horizontalLayout_4.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout_4.setObjectName("horizontalLayout_4")
self.label_8 = QtWidgets.QLabel(self.horizontalLayoutWidget_4)
self.label_8.setObjectName("label_8")
self.horizontalLayout_4.addWidget(self.label_8)
self.label_7 = QtWidgets.QLabel(self.horizontalLayoutWidget_4)
self.label_7.setObjectName("label_7")
self.horizontalLayout_4.addWidget(self.label_7)
self.label_5 = QtWidgets.QLabel(self.horizontalLayoutWidget_4)
self.label_5.setObjectName("label_5")
self.horizontalLayout_4.addWidget(self.label_5)
self.horizontalLayoutWidget_5 = QtWidgets.QWidget(self.centralwidget)
self.horizontalLayoutWidget_5.setGeometry(QtCore.QRect(160, 340, 451, 21))
self.horizontalLayoutWidget_5.setObjectName("horizontalLayoutWidget_5")
self.horizontalLayout_5 = QtWidgets.QHBoxLayout(self.horizontalLayoutWidget_5)
self.horizontalLayout_5.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout_5.setObjectName("horizontalLayout_5")
self.label_9 = QtWidgets.QLabel(self.horizontalLayoutWidget_5)
self.label_9.setObjectName("label_9")
self.horizontalLayout_5.addWidget(self.label_9)
self.label_11 = QtWidgets.QLabel(self.horizontalLayoutWidget_5)
self.label_11.setObjectName("label_11")
self.horizontalLayout_5.addWidget(self.label_11)
self.money = QtWidgets.QLabel(self.centralwidget)
self.money.setGeometry(QtCore.QRect(350, 200, 81, 31))
self.money.setObjectName("money")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 26))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.buyButton.clicked.connect(self.buy)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "修改密码"))
self.label.setText(_translate("MainWindow", "购票页面
"))
self.buyButton.setText(_translate("MainWindow", "提交订单"))
self.exitButton.setText(_translate("MainWindow", "退出"))
self.U_date.setText(_translate("MainWindow", "U_date"))
self.label_8.setText(_translate("MainWindow", "请选择等级"))
self.label_7.setText(_translate("MainWindow", "请选择车厢"))
self.label_5.setText(_translate("MainWindow", "请选择座位"))
self.label_9.setText(_translate("MainWindow", "请输入乘车人姓名"))
self.label_11.setText(_translate("MainWindow", "请输入乘车人身份证号码"))
self.U_date.hide()
self.T_date.hide()
self.M_date.hide()
def buy(self):
date =[]
success = 0
seat_no = self.comboBox_2.currentText()
by_name = self.lineEdit.text()
by_id = self.lineEdit_2.text()
if seat_no =='':
QMessageBox.critical(self,'座位','请选择座位!')
success=1
return
if by_id=='' or by_name=='':
QMessageBox.critical(self, '乘车人', '请输入乘车人的完整信息!')
success=1
conn = pymysql.connect(
host='localhost',
port=3306,
user='root',
passwd='111111',
db='train',
charset='utf8'
)
cursor = conn.cursor()
station1 = self.B_station.text()
station = station1.strip("")
estation1 = self.E_station.text()
estation = estation1.strip("
")
sql = "select 车站编号 from 车站表 where 车站名='%s' and 列车编号='%s'"%(station,self.T_date.text())
cursor.execute(sql)
train_station_no = 0
for i in cursor.fetchall():
for j in i:
train_station_no = j
sql1 ="select max(座位编号) from 座位表"
cursor.execute(sql1)
seatno = 0
ss = cursor.fetchall()
for i in ss:
for j in i:
if j==None:
seatno = 0
else:
seatno = j+1
level = self.comboBox.currentText()
trunk1 = self.comboBox_1.currentText()
trunk = trunk1.strip('号车厢')
t_no = self.U_date.text()
train1 = self.T_date.text()
train2 =int(train1)
price1 = self.M_date.text()
price = int(price1)
sql1 ="select 余额 from 用户表 where 手机号='%s'"%t_no
cursor.execute(sql1)
for i in cursor.fetchall():
for j in i:
if j<price:
QMessageBox.critical(self, '余额', '余额不足,请前往充值中心充值!!!')
success=1
checkID = "select * from 身份表 where 姓名='%s' and 身份证号码='%s'" % (by_name, by_id)
cursor.execute(checkID)
if cursor.rowcount == 0:
success = 1
QMessageBox.critical(self, "乘车人信息错误", "请重新输入正确的乘车人的身份信息")
checkID2 = "select * from 座位表 where 列车编号='%s' and 乘车人姓名='%s' and 乘车人身份证='%s'" % (train2,by_name, by_id)
cursor.execute(checkID2)
if cursor.rowcount !=0:
success = 1
QMessageBox.critical(self, "无法购票", "该乘客已经购买本趟列车,无法继续购买!!!")
if success==0:
success1 = 0
passwd, bool1 = QInputDialog.getText(self, '密码', '请输入密码', QLineEdit.EchoMode.Password)
if passwd != '' and bool1:
sql = "select 密码 from 用户表 where 手机号='%s'" % self.U_date.text()
cursor.execute(sql)
for i in cursor.fetchall():
for j in i:
if j == passwd:
success1 = 1
else:
QMessageBox.critical(self, "密码错误", "请重新输入密码!!")
if passwd == '' and bool1:
success = 0
QMessageBox.critical(self, "错误", "请输入密码!!")
if success1==1:
sql2 = "insert into 座位表(座位编号,车站编号,列车编号,出发站,终点站,座位级别,车厢,座位,价格,手机号,乘车人姓名,乘车人身份证) values (%s,%s,%s,'%s','%s','%s','%s','%s',%s,'%s','%s','%s')"%(seatno,train_station_no,train2,station,estation,level,trunk,seat_no,price,t_no,by_name,by_id)
#sql3 = "update 用户表 set 余额=余额-%s where 手机号='%s'"%(price,t_no)
cursor.execute(sql2)
#cursor.execute(sql3)
conn.commit()
QMessageBox.information(self, '座位', '购票成功!!!')
self.exitButton.click()
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
用户-我的订单UI设计:只有某列车未经过的某站才可以退票,已经过的车站的票无法退票
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'my_orderUI.ui'
#
# Created by: PyQt5 UI code generator 5.15.6
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QMessageBox,QInputDialog, QLineEdit
from PyQt5 import QtCore, QtGui, QtWidgets
import pymysql
from PyQt5.QtCore import pyqtSlot, QDate
import string
import thp
class Ui_MainWindow(object):
numb = 0
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(800, 600)
MainWindow.setStyleSheet("#MainWindow{border-image: url(:/thpic/60.jpg);}")
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(330, 20, 131, 41))
self.label.setObjectName("label")
self.U_date = QtWidgets.QLabel(self.centralwidget)
self.U_date.setGeometry(QtCore.QRect(40, 510, 72, 15))
self.U_date.setObjectName("U_date")
self.scrollArea = QtWidgets.QScrollArea(self.centralwidget)
self.scrollArea.setGeometry(QtCore.QRect(40, 130, 701, 351))
self.scrollArea.setWidgetResizable(False)
self.scrollArea.setObjectName("scrollArea")
self.scrollAreaWidgetContents = QtWidgets.QWidget()
self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 699, 349))
self.scrollAreaWidgetContents.setObjectName("scrollAreaWidgetContents")
self.scrollArea.setWidget(self.scrollAreaWidgetContents)
self.exitButton = QtWidgets.QPushButton(self.centralwidget)
self.exitButton.setGeometry(QtCore.QRect(340, 485, 93, 28))
self.exitButton.setObjectName("exitButton")
self.updateButton = QtWidgets.QPushButton(self.centralwidget)
self.updateButton.setGeometry(QtCore.QRect(340, 520, 93, 28))
self.updateButton.setObjectName("updateButton")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 26))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
conn = pymysql.connect(
host='localhost',
port=3306,
user='root',
passwd='111111',
db='train',
charset='utf8'
)
cursor = conn.cursor()
cursor.execute("select * from 座位表")
self.numb = cursor.rowcount
for i in range(self.numb):
exec('''
self.line{j} = QtWidgets.QFrame(self.scrollAreaWidgetContents)
self.line{j}.setGeometry(QtCore.QRect(0, 110+{y}, 701, 16))
self.line{j}.setFrameShape(QtWidgets.QFrame.HLine)
self.line{j}.setFrameShadow(QtWidgets.QFrame.Sunken)
self.line{j}.setObjectName("line{j}")
self.begin_station{j} = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.begin_station{j}.setGeometry(QtCore.QRect(20, 20+{y}, 41, 16))
self.begin_station{j}.setObjectName("begin_station{j}")
self.arrow{j} = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.arrow{j}.setGeometry(QtCore.QRect(60, 20+{y}, 71, 16))
self.arrow{j}.setObjectName("arrow{j}")
self.end_station{j} = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.end_station{j}.setGeometry(QtCore.QRect(140, 20+{y}, 41, 16))
self.end_station{j}.setObjectName("end_station{j}")
self.begin_data{j} = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.begin_data{j}.setGeometry(QtCore.QRect(20, 60+{y}, 72, 15))
self.begin_data{j}.setObjectName("begin_data{j}")
self.end_data{j} = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.end_data{j}.setGeometry(QtCore.QRect(140, 60+{y}, 72, 15))
self.end_data{j}.setObjectName("end_data{j}")
self.begin_time{j} = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.begin_time{j}.setGeometry(QtCore.QRect(20, 40+{y}, 51, 16))
self.begin_time{j}.setObjectName("begin_time{j}")
self.end_time{j} = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.end_time{j}.setGeometry(QtCore.QRect(140, 40+{y}, 51, 16))
self.end_time{j}.setObjectName("end_time{j}")
self.trainNO{j} = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.trainNO{j}.setGeometry(QtCore.QRect(70, 10+{y}, 41, 16))
self.trainNO{j}.setObjectName("trainNO{j}")
self.level{j} = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.level{j}.setGeometry(QtCore.QRect(10, 90+{y}, 61, 16))
self.level{j}.setObjectName("level{j}")
self.trunk{j} = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.trunk{j}.setGeometry(QtCore.QRect(80, 90+{y}, 61, 16))
self.trunk{j}.setObjectName("trunk{j}")
self.seat{j} = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.seat{j}.setGeometry(QtCore.QRect(150, 90+{y}, 72, 15))
self.seat{j}.setObjectName("seat{j}")
self.seatno{j} = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.seatno{j}.setGeometry(QtCore.QRect(470, 90+{y}, 72, 15))
self.seatno{j}.setObjectName("seatno{j}")
self.by_name{j} = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.by_name{j}.setGeometry(QtCore.QRect(320, 30+{y}, 72, 15))
self.by_name{j}.setObjectName("by_name{j}")
self.by_id{j} = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.by_id{j}.setGeometry(QtCore.QRect(320, 60+{y}, 211, 16))
self.by_id{j}.setObjectName("by_id")
self.refundButton{j} = QtWidgets.QPushButton(self.scrollAreaWidgetContents)
self.refundButton{j}.setGeometry(QtCore.QRect(590, 40+{y}, 80, 28))
self.refundButton{j}.setObjectName("refundButton{j}")
self.by_name_txt{j} = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.by_name_txt{j}.setGeometry(QtCore.QRect(260, 30+{y}, 51, 16))
self.by_name_txt{j}.setObjectName("by_name_txt{j}")
self.by_id_txt{j} = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.by_id_txt{j}.setGeometry(QtCore.QRect(260, 60+{y}, 51, 16))
self.by_id_txt{j}.setObjectName("by_id_txt{j}")
self.price{j} = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.price{j}.setGeometry(QtCore.QRect(490, 50+{y}, 72, 16))
self.price{j}.setObjectName("price{j}")
self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 699, 349+{y}))
self.refundButton{j}.clicked.connect(self.refund)
'''.format(j=i+1,y=115 * i))
self.updateButton.clicked.connect(self.updatemyorder)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "我的订单"))
self.label.setText(_translate("MainWindow", "我的订单
"))
self.U_date.setText(_translate("MainWindow", "TextLabel"))
self.exitButton.setText(_translate("MainWindow", "返回"))
self.updateButton.setText(_translate("MainWindow", "刷新"))
self.U_date.hide()
for i in range(self.numb):
exec('''
self.arrow{j}.setText("-------->")
self.refundButton{j}.setText("退票")
self.by_name_txt{j}.setText("乘车人:")
self.by_id_txt{j}.setText("身份证:")
'''.format(j=i+1))
def updatemyorder(self):
for i in range(self.numb):
exec('''
self.seatno{j}.hide()
self.line{j}.hide()
self.arrow{j}.hide()
self.refundButton{j}.hide()
self.by_name_txt{j}.hide()
self.by_id_txt{j}.hide()
self.begin_station{j}.hide()
self.end_station{j}.hide()
self.begin_time{j}.hide()
self.begin_data{j}.hide()
self.end_time{j}.hide()
self.end_data{j}.hide()
self.trainNO{j}.hide()
self.level{j}.hide()
self.trunk{j}.hide()
self.seat{j}.hide()
self.by_name{j}.hide()
self.by_id{j}.hide()
self.price{j}.hide()
'''.format(j=i + 1))
conn = pymysql.connect(
host='localhost',
port=3306,
user='root',
passwd='111111',
db='train',
charset='utf8'
)
cursor = conn.cursor()
sql = "select 座位编号,列车编号,出发站,终点站,座位级别,车厢,座位,价格,乘车人姓名,乘车人身份证 from 座位表 where 手机号='%s'"%self.U_date.text()
cursor.execute(sql)
infor = cursor.fetchall()
row = cursor.rowcount
date = []
for a in infor:
date1 = []
for b in a:
date1.append(b)
sql1 = "select 发车日期,发车时间 from 车站表 where 列车编号=%s and 车站名 in ('%s','%s')"%(date1[1],date1[2],date1[3])
cursor.execute(sql1)
day = cursor.fetchall()
for m in day:
for n in m:
date1.append(n)
sql2 = "select 车次号 from 列车表 where 列车编号=%s"%date1[1]
cursor.execute(sql2)
for c in cursor.fetchall():
for d in c:
date1.append(d)
sql3 = "select 状态 from 车站表 where 列车编号=%s and 车站名 ='%s'"%(date1[1],date1[2])
cursor.execute(sql3)
for e in cursor.fetchall():
for f in e:
date1.append(f)
date.append(date1)
for i in range(len(date)):
exec('''
self.line{j}.show()
self.arrow{j}.show()
self.by_name_txt{j}.show()
self.by_id_txt{j}.show()
self.begin_station{j}.show()
self.end_station{j}.show()
self.begin_time{j}.show()
self.begin_data{j}.show()
self.end_time{j}.show()
self.end_data{j}.show()
self.trainNO{j}.show()
self.level{j}.show()
self.trunk{j}.show()
self.seat{j}.show()
self.by_name{j}.show()
self.by_id{j}.show()
self.price{j}.show()
self.begin_station{j}.clear()
self.seatno{j}.clear()
self.end_station{j}.clear()
self.begin_time{j}.clear()
self.begin_data{j}.clear()
self.end_time{j}.clear()
self.end_data{j}.clear()
self.trainNO{j}.clear()
self.level{j}.clear()
self.trunk{j}.clear()
self.seat{j}.clear()
self.by_name{j}.clear()
self.by_id{j}.clear()
self.price{j}.clear()
self.seatno{j}.setText(str(date[{t}][0]))
self.begin_station{j}.setText(str(date[{t}][2]))
self.end_station{j}.setText(str(date[{t}][3]))
self.begin_time{j}.setText(str(date[{t}][11]))
self.begin_data{j}.setText(str(date[{t}][10]))
self.end_time{j}.setText(str(date[{t}][13]))
self.end_data{j}.setText(str(date[{t}][12]))
self.trainNO{j}.setText(str(date[{t}][14]))
self.level{j}.setText(str(date[{t}][4]))
self.trunk{j}.setText(str(date[{t}][5])+"号车厢")
self.seat{j}.setText(str(date[{t}][6])+"号座位")
self.by_name{j}.setText(str(date[{t}][8]))
self.by_id{j}.setText(str(date[{t}][9]))
self.price{j}.setText(str(date[{t}][7])+"元")
if date[{t}][15]=='未抵达':self.refundButton{j}.show()
if date[{t}][15]=='抵达':self.refundButton{j}.hide()
'''.format(j=i+1,t=i))
cursor.close()
conn.close()
def refund(self):
conn = pymysql.connect(
host='localhost',
port=3306,
user='root',
passwd='111111',
db='train',
charset='utf8'
)
cursor = conn.cursor()
s = self.sender().objectName()
ss = s.strip('refundButton')
ss1 = int(ss)
success = 0
sn = []
exec('''
sn.append(self.seatno{k}.text())
sn.append(self.price{k}.text())
'''.format(k=ss1))
print(ss1)
sn1 = int(sn[0])
money1 = sn[1].strip('元')
money = int(money1)
passwd,bool1= QInputDialog.getText(self,'密码','请输入密码',QLineEdit.EchoMode.Password)
if passwd!='' and bool1:
sql = "select 密码 from 用户表 where 手机号='%s'"%self.U_date.text()
cursor.execute(sql)
for i in cursor.fetchall():
for j in i:
if j==passwd:
success = 1
else:
QMessageBox.critical(self,"错误","请重新输入密码!!")
if passwd=='' and bool1:
success = 0
QMessageBox.critical(self, "错误", "请输入密码!!")
if success==1:
cursor.execute("delete from 座位表 where 座位编号=%s"%sn1)
#cursor.execute("update 用户表 set 余额=余额+%s where 手机号='%s'"%(money,self.U_date.text()))
conn.commit()
QMessageBox.information(self, "正确", "退票成功!!!")
self.updateButton.click()
cursor.close()
conn.close()
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
管理员主页UI设计:包含更新列车状态(手动更新列车状态)、用户管理(初始化用户的密码)、票务信息(乘务员查看某列车某车厢的乘客的信息)和列车管理(显示历史列车的信息和添加列车)四个功能模块
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'Admin_homeUI.ui'
#
# Created by: PyQt5 UI code generator 5.15.6
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
import thp
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(800, 600)
MainWindow.setStyleSheet("#MainWindow{border-image: url(:/thpic/60.jpg);}")
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(250, 20, 281, 41))
self.label.setObjectName("label")
self.L_out = QtWidgets.QPushButton(self.centralwidget)
self.L_out.setGeometry(QtCore.QRect(630, 70, 93, 28))
self.L_out.setObjectName("L_out")
self.A_date = QtWidgets.QLabel(self.centralwidget)
self.A_date.setGeometry(QtCore.QRect(30, 510, 72, 15))
self.A_date.setObjectName("A_date")
self.train_manage = QtWidgets.QPushButton(self.centralwidget)
self.train_manage.setGeometry(QtCore.QRect(180, 150, 211, 141))
self.train_manage.setObjectName("train_manage")
self.update_train = QtWidgets.QPushButton(self.centralwidget)
self.update_train.setGeometry(QtCore.QRect(400, 150, 211, 141))
self.update_train.setObjectName("update_train")
self.User_manage = QtWidgets.QPushButton(self.centralwidget)
self.User_manage.setGeometry(QtCore.QRect(400, 300, 211, 141))
self.User_manage.setObjectName("User_manage")
self.ticket_informations = QtWidgets.QPushButton(self.centralwidget)
self.ticket_informations.setGeometry(QtCore.QRect(180, 300, 211, 141))
self.ticket_informations.setObjectName("ticket_informations")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 26))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "管理员主页"))
self.label.setText(_translate("MainWindow", "火车售票管理信息系统
"))
self.L_out.setText(_translate("MainWindow", "退出登录"))
self.A_date.setText(_translate("MainWindow", "TextLabel"))
self.train_manage.setText(_translate("MainWindow", "列车管理"))
self.update_train.setText(_translate("MainWindow", "更新列车状态"))
self.User_manage.setText(_translate("MainWindow", "用户管理"))
self.ticket_informations.setText(_translate("MainWindow", "票务信息"))
self.A_date.hide()
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
管理员-用户管理UI设计:管理员有权限初始化某个用户的密码
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'user_manageUI.ui'
#
# Created by: PyQt5 UI code generator 5.15.6
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QMessageBox,QInputDialog, QLineEdit
from PyQt5 import QtCore, QtGui, QtWidgets
import pymysql
from PyQt5.QtCore import pyqtSlot, QDate
import string
import datetime
import thp
class Ui_MainWindow(object):
numb = 0
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(800, 600)
MainWindow.setStyleSheet("#MainWindow{border-image: url(:/thpic/60.jpg);}")
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(330, 20, 131, 41))
self.label.setObjectName("label")
self.A_date = QtWidgets.QLabel(self.centralwidget)
self.A_date.setGeometry(QtCore.QRect(40, 510, 72, 15))
self.A_date.setObjectName("A_date")
self.scrollArea = QtWidgets.QScrollArea(self.centralwidget)
self.scrollArea.setGeometry(QtCore.QRect(40, 130, 701, 331))
self.scrollArea.setWidgetResizable(False)
self.scrollArea.setObjectName("scrollArea")
self.scrollAreaWidgetContents = QtWidgets.QWidget()
self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 699, 329))
self.scrollAreaWidgetContents.setObjectName("scrollAreaWidgetContents")
self.scrollArea.setWidget(self.scrollAreaWidgetContents)
self.exitButton = QtWidgets.QPushButton(self.centralwidget)
self.exitButton.setGeometry(QtCore.QRect(340, 480, 93, 28))
self.exitButton.setObjectName("exitButton")
self.label_2 = QtWidgets.QLabel(self.centralwidget)
self.label_2.setGeometry(QtCore.QRect(50, 90, 191, 16))
self.label_2.setObjectName("label_2")
self.lineEdit = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit.setGeometry(QtCore.QRect(240, 90, 113, 21))
self.lineEdit.setObjectName("lineEdit")
self.searchButton = QtWidgets.QPushButton(self.centralwidget)
self.searchButton.setGeometry(QtCore.QRect(650, 90, 93, 28))
self.searchButton.setObjectName("searchButton")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 26))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
conn = pymysql.connect(
host='localhost',
port=3306,
user='root',
passwd='111111',
db='train',
charset='utf8'
)
cursor = conn.cursor()
cursor.execute("select * from 用户表")
self.numb = cursor.rowcount
for i in range(self.numb):
exec('''
self.user_txt{j} = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.user_txt{j}.setGeometry(QtCore.QRect(10, 10+{y}, 51, 16))
self.user_txt{j}.setObjectName("user_txt")
self.user{j} = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.user{j}.setGeometry(QtCore.QRect(60, 10+{y}, 190, 15))
self.user{j}.setObjectName("user")
self.resetButton{j} = QtWidgets.QPushButton(self.scrollAreaWidgetContents)
self.resetButton{j}.setGeometry(QtCore.QRect(580, 10+{y}, 81, 28))
self.resetButton{j}.setObjectName("resetButton{j}")
self.line{j} = QtWidgets.QFrame(self.scrollAreaWidgetContents)
self.line{j}.setGeometry(QtCore.QRect(0, 40+{y}, 701, 16))
self.line{j}.setFrameShape(QtWidgets.QFrame.HLine)
self.line{j}.setFrameShadow(QtWidgets.QFrame.Sunken)
self.line{j}.setObjectName("line")
self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 699, 329+{y}))
self.resetButton{j}.clicked.connect(self.reset)
'''.format(j=i+1,y=40*i))
self.searchButton.clicked.connect(self.searchuser)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "用户管理"))
self.label.setText(_translate("MainWindow", "用户管理
"))
self.A_date.setText(_translate("MainWindow", "TextLabel"))
self.exitButton.setText(_translate("MainWindow", "返回"))
self.label_2.setText(_translate("MainWindow", "请输入需要查找的用户账号:"))
self.searchButton.setText(_translate("MainWindow", "查找"))
self.A_date.hide()
for i in range(self.numb):
exec('''
self.user_txt{j}.setText("账号:")
self.resetButton{j}.setText("重置密码")
'''.format(j=i+1))
def searchuser(self):
conn = pymysql.connect(
host='localhost',
port=3306,
user='root',
passwd='111111',
db='train',
charset='utf8'
)
cursor = conn.cursor()
for i in range(self.numb):
exec('''
self.user_txt{j}.hide()
self.user{j}.hide()
self.resetButton{j}.hide()
self.line{j}.hide()
'''.format(j=i+1))
if self.lineEdit.text()=='':
cursor.execute("select 手机号 from 用户表")
date = []
for a in cursor.fetchall():
for b in a:
date.append(b)
for i in range(len(date)):
exec('''
self.user_txt{j}.show()
self.user{j}.show()
self.resetButton{j}.show()
self.line{j}.show()
self.user{j}.clear()
self.user{j}.setText(date[{k}])
'''.format(j=i+1,k=i))
else:
cursor.execute("select 手机号 from 用户表 where 手机号='%s'"%self.lineEdit.text())
row = cursor.rowcount
u = cursor.fetchall()
if row ==0:
QMessageBox.critical(self,"错误","没有该账号!!!")
self.lineEdit.clear()
self.searchButton.click()
else:
u1 = ''
for c in u:
for d in c:
u1 = d
for i in range(row):
exec('''
self.user_txt{j}.show()
self.user{j}.show()
self.resetButton{j}.show()
self.line{j}.show()
self.user{j}.clear()
self.user{j}.setText(u1)
'''.format(j=i + 1))
cursor.close()
conn.close()
def reset(self):
conn = pymysql.connect(
host='localhost',
port=3306,
user='root',
passwd='111111',
db='train',
charset='utf8'
)
cursor = conn.cursor()
success =0
s = self.sender().objectName()
ss = s.strip('resetButton')
ss1 = int(ss)
unum = []
exec('''
unum.append(self.user{j}.text())
'''.format(j=ss1))
passwd, bool1 = QInputDialog.getText(self, '密码', '请输入管理员密码', QLineEdit.EchoMode.Password)
if passwd and bool1:
sql = "select 密码 from 管理员表 where 管理员账号='%s'" % self.A_date.text()
cursor.execute(sql)
for i in cursor.fetchall():
for j in i:
if j == passwd:
success = 1
else:
success = 0
QMessageBox.critical(self, "错误", "请重新输入管理员密码!!")
if passwd=='' and bool1:
success = 0
QMessageBox.critical(self, "错误", "请输入管理员密码!!")
if success==1:
cursor.execute("update 用户表 set 密码='123456' where 手机号='%s'"%unum[0])
conn.commit()
QMessageBox.information(self, "正确", "该用户的密码已经初始化为123456!!!")
print("%s 管理员:%s 将用户:%s 重置密码"%(datetime.datetime.now(),self.A_date.text(),unum[0]))
self.lineEdit.clear()
self.searchButton.click()
cursor.close()
conn.close()
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
管理员-更新列车状态UI设计:管理员可以手动更新列车的状态
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'update_trainUI.ui'
#
# Created by: PyQt5 UI code generator 5.15.6
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
import datetime
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QMessageBox,QInputDialog, QLineEdit
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtCore import pyqtSlot, QDate
import pymysql
import thp
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(800, 600)
MainWindow.setStyleSheet("#MainWindow{border-image: url(:/thpic/60.jpg);}")
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(290, 20, 181, 41))
self.label.setObjectName("label")
self.A_date = QtWidgets.QLabel(self.centralwidget)
self.A_date.setGeometry(QtCore.QRect(40, 510, 72, 15))
self.A_date.setObjectName("A_date")
self.scrollArea = QtWidgets.QScrollArea(self.centralwidget)
self.scrollArea.setGeometry(QtCore.QRect(40, 120, 701, 331))
self.scrollArea.setWidgetResizable(False)
self.scrollArea.setObjectName("scrollArea")
self.scrollAreaWidgetContents = QtWidgets.QWidget()
self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 699, 329))
self.scrollAreaWidgetContents.setObjectName("scrollAreaWidgetContents")
self.scrollArea.setWidget(self.scrollAreaWidgetContents)
self.exitButton = QtWidgets.QPushButton(self.centralwidget)
self.exitButton.setGeometry(QtCore.QRect(340, 480, 93, 28))
self.exitButton.setObjectName("exitButton")
self.label_txt1 = QtWidgets.QLabel(self.centralwidget)
self.label_txt1.setGeometry(QtCore.QRect(50, 90, 91, 16))
self.label_txt1.setObjectName("label_txt1")
self.searchButton = QtWidgets.QPushButton(self.centralwidget)
self.searchButton.setGeometry(QtCore.QRect(650, 90, 93, 28))
self.searchButton.setObjectName("searchButton")
self.comboBox = QtWidgets.QComboBox(self.centralwidget)
self.comboBox.setGeometry(QtCore.QRect(140, 90, 87, 22))
self.comboBox.setObjectName("comboBox")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 26))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.train_select()
for i in range(10):
exec('''
self.line{j} = QtWidgets.QFrame(self.scrollAreaWidgetContents)
self.line{j}.setGeometry(QtCore.QRect(0, 40+{y}, 701, 16))
self.line{j}.setFrameShape(QtWidgets.QFrame.HLine)
self.line{j}.setFrameShadow(QtWidgets.QFrame.Sunken)
self.line{j}.setObjectName("line{j}")
self.train_txt{j} = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.train_txt{j}.setGeometry(QtCore.QRect(10, 10+{y}, 51, 16))
self.train_txt{j}.setObjectName("train_txt{j}")
self.train{j} = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.train{j}.setGeometry(QtCore.QRect(60, 10+{y}, 72, 15))
self.train{j}.setObjectName("train{j}")
self.train_NO{j} = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.train_NO{j}.setGeometry(QtCore.QRect(20, 26+{y}, 72, 15))
self.train_NO{j}.setObjectName("train_NO{j}")
self.station_txt{j} = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.station_txt{j}.setGeometry(QtCore.QRect(150, 10+{y}, 51, 16))
self.station_txt{j}.setObjectName("station_txt{j}")
self.station{j} = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.station{j}.setGeometry(QtCore.QRect(200, 10+{y}, 72, 15))
self.station{j}.setObjectName("station{j}")
self.state_chose{j} = QtWidgets.QComboBox(self.scrollAreaWidgetContents)
self.state_chose{j}.setGeometry(QtCore.QRect(470, 10+{y}, 87, 22))
self.state_chose{j}.setObjectName("state_chose{j}")
self.station_state{j} = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.station_state{j}.setGeometry(QtCore.QRect(360, 10+{y}, 72, 15))
self.station_state{j}.setObjectName("station_state{j}")
self.station_state_txt{j} = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.station_state_txt{j}.setGeometry(QtCore.QRect(300, 10+{y}, 51, 16))
self.station_state_txt{j}.setObjectName("station_state_txt{j}")
self.modify_state{j} = QtWidgets.QPushButton(self.scrollAreaWidgetContents)
self.modify_state{j}.setGeometry(QtCore.QRect(570, 10+{y}, 93, 28))
self.modify_state{j}.setObjectName("modify_state{j}")
self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 699, 329+{y}))
self.modify_state{j}.clicked.connect(self.modify)
'''.format(j=i+1,y=40*i))
self.searchButton.clicked.connect(self.search)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "更新列车状态"))
self.label.setText(_translate("MainWindow", "更新列车状态
"))
self.A_date.setText(_translate("MainWindow", "TextLabel"))
self.exitButton.setText(_translate("MainWindow", "返回"))
self.label_txt1.setText(_translate("MainWindow", "请选择列车:"))
self.searchButton.setText(_translate("MainWindow", "查看"))
self.A_date.hide()
for i in range(10):
exec('''
self.train_txt{j}.setText("列车:")
self.station_txt{j}.setText("车站:")
self.station_state_txt{j}.setText( "状态:")
self.modify_state{j}.setText("修改状态")
self.state_chose{j}.addItems(['抵达','未抵达'])
'''.format(j=i+1))
def train_select(self):
conn = pymysql.connect(
host='localhost',
port=3306,
user='root',
passwd='111111',
db='train',
charset='utf8'
)
cursor = conn.cursor()
cursor.execute("select 车次号 from 列车表 where 列车状态='运行'")
items = []
for i in cursor.fetchall():
for j in i:
items.append(j)
self.comboBox.clear()
self.comboBox.addItems(items)
cursor.close()
conn.close()
def search(self):
for i in range(10):
exec('''
self.line{j}.hide()
self.train_txt{j}.hide()
self.train{j}.hide()
self.station_txt{j}.hide()
self.station_state_txt{j}.hide()
self.modify_state{j}.hide()
self.state_chose{j}.hide()
self.station{j}.hide()
self.station_state{j}.hide()
self.modify_state{j}.hide()
self.train_NO{j}.hide()
'''.format(j=i + 1))
train = self.comboBox.currentText()
conn = pymysql.connect(
host='localhost',
port=3306,
user='root',
passwd='111111',
db='train',
charset='utf8'
)
cursor = conn.cursor()
cursor.execute("select 列车编号 from 列车表 where 车次号='%s' and 列车状态='运行'" % train)
trainNO = 0
for i in cursor.fetchall():
for j in i:
trainNO = j
cursor.execute("select 车站编号,车站名,状态 from 车站表 where 列车编号=%s"%trainNO)
infor = cursor.fetchall()
date = []
for a in infor:
date1 = []
for b in a:
date1.append(b)
date.append(date1)
cursor.close()
conn.close()
for i in range(len(date)):
exec('''
self.line{j}.show()
self.train_txt{j}.show()
self.train{j}.show()
self.station_txt{j}.show()
self.station_state_txt{j}.show()
self.modify_state{j}.show()
self.state_chose{j}.show()
self.station{j}.show()
self.station_state{j}.show()
self.modify_state{j}.show()
self.train{j}.clear()
self.station{j}.clear()
self.train_NO{j}.clear()
self.station_state{j}.clear()
self.train_NO{j}.setText(str(date[{k}][0]))
self.train{j}.setText(train)
self.station{j}.setText(str(date[{k}][1]))
self.station_state{j}.setText(str(date[{k}][2]))
'''.format(j=i+1,k=i))
def modify(self):
conn = pymysql.connect(
host='localhost',
port=3306,
user='root',
passwd='111111',
db='train',
charset='utf8'
)
cursor = conn.cursor()
success = 0
s = self.sender().objectName()
ss = s.strip('modify_state')
ss1 = int(ss)
unum = []
exec('''
unum.append(self.train_NO{j}.text())
unum.append(self.state_chose{j}.currentText())
'''.format(j=ss1))
passwd, bool1 = QInputDialog.getText(self, '密码', '请输入管理员密码', QLineEdit.EchoMode.Password)
if passwd and bool1:
sql = "select 密码 from 管理员表 where 管理员账号='%s'" % self.A_date.text()
cursor.execute(sql)
for i in cursor.fetchall():
for j in i:
if j == passwd:
success = 1
else:
success = 0
QMessageBox.critical(self, "错误", "请重新输入管理员密码!!")
if passwd == '' and bool1:
success = 0
QMessageBox.critical(self, "错误", "请输入管理员密码!!")
if success == 1:
tra = int(unum[0])
state1 = unum[1]
cursor.execute("update 车站表 set 状态='%s' where 车站编号=%s"%(state1,tra))
conn.commit()
QMessageBox.information(self, "正确", "状态修改成功!!!")
cursor.execute("select * from 列车表,车站表 where 列车表.列车编号=车站表.列车编号 and 列车表.车次号='%s' and 列车表.列车状态='运行' and 车站表.状态='未抵达'" % self.comboBox.currentText())
row = cursor.rowcount
if row==0:
cursor.execute("update 列车表 set 列车状态='已完成' where 车次号='%s' and 列车状态='运行'"%self.comboBox.currentText())
conn.commit()
print("%s列车:%s已完成行程"%(datetime.datetime.now(),self.comboBox.currentText()))
self.train_select()
self.searchButton.click()
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
管理员-票务信息UI设计:查看某运行中的列车某车厢的乘客信息
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'ticket_informationUI.ui'
#
# Created by: PyQt5 UI code generator 5.15.6
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QMessageBox
from PyQt5 import QtCore, QtGui, QtWidgets
import pymysql
import thp
class Ui_MainWindow(object):
numb = 0
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(800, 600)
MainWindow.setStyleSheet("#MainWindow{border-image: url(:/thpic/60.jpg);}")
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(330, 20, 131, 41))
self.label.setObjectName("label")
self.A_date = QtWidgets.QLabel(self.centralwidget)
self.A_date.setGeometry(QtCore.QRect(40, 510, 72, 15))
self.A_date.setObjectName("A_date")
self.scrollArea = QtWidgets.QScrollArea(self.centralwidget)
self.scrollArea.setGeometry(QtCore.QRect(40, 130, 701, 331))
self.scrollArea.setWidgetResizable(False)
self.scrollArea.setObjectName("scrollArea")
self.scrollAreaWidgetContents = QtWidgets.QWidget()
self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 699, 329))
self.scrollAreaWidgetContents.setObjectName("scrollAreaWidgetContents")
self.scrollArea.setWidget(self.scrollAreaWidgetContents)
self.exitButton = QtWidgets.QPushButton(self.centralwidget)
self.exitButton.setGeometry(QtCore.QRect(340, 480, 93, 28))
self.exitButton.setObjectName("exitButton")
self.label_txt1 = QtWidgets.QLabel(self.centralwidget)
self.label_txt1.setGeometry(QtCore.QRect(50, 90, 91, 16))
self.label_txt1.setObjectName("label_txt1")
self.searchButton = QtWidgets.QPushButton(self.centralwidget)
self.searchButton.setGeometry(QtCore.QRect(650, 90, 93, 28))
self.searchButton.setObjectName("searchButton")
self.comboBox = QtWidgets.QComboBox(self.centralwidget)
self.comboBox.setGeometry(QtCore.QRect(140, 90, 87, 22))
self.comboBox.setObjectName("comboBox")
self.label_txt2 = QtWidgets.QLabel(self.centralwidget)
self.label_txt2.setGeometry(QtCore.QRect(440, 90, 91, 16))
self.label_txt2.setObjectName("label_txt2")
self.comboBox_1 = QtWidgets.QComboBox(self.centralwidget)
self.comboBox_1.setGeometry(QtCore.QRect(530, 90, 87, 22))
self.comboBox_1.setObjectName("comboBox_1")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 26))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
conn = pymysql.connect(
host='localhost',
port=3306,
user='root',
passwd='111111',
db='train',
charset='utf8'
)
cursor = conn.cursor()
cursor.execute("select 车次号 from 列车表 where 列车状态='运行'")
items = []
for i in cursor.fetchall():
for j in i:
items.append(j)
cursor.execute("select * from 座位表")
self.numb = cursor.rowcount
cursor.close()
conn.close()
for i in range(self.numb):
exec('''
self.line{j} = QtWidgets.QFrame(self.scrollAreaWidgetContents)
self.line{j}.setGeometry(QtCore.QRect(0, 80+{y}, 701, 16))
self.line{j}.setFrameShape(QtWidgets.QFrame.HLine)
self.line{j}.setFrameShadow(QtWidgets.QFrame.Sunken)
self.line{j}.setObjectName("line{j}")
self.train_txt{j} = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.train_txt{j}.setGeometry(QtCore.QRect(10, 10+{y}, 51, 16))
self.train_txt{j}.setObjectName("train_txt{j}")
self.train{j} = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.train{j}.setGeometry(QtCore.QRect(60, 10+{y}, 72, 15))
self.train{j}.setObjectName("train{j}")
self.station_txt{j} = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.station_txt{j}.setGeometry(QtCore.QRect(170, 10+{y}, 51, 16))
self.station_txt{j}.setObjectName("station_txt{j}")
self.station{j} = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.station{j}.setGeometry(QtCore.QRect(220, 10+{y}, 72, 15))
self.station{j}.setObjectName("station")
self.trunk_txt{j} = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.trunk_txt{j}.setGeometry(QtCore.QRect(320, 10+{y}, 51, 16))
self.trunk_txt{j}.setObjectName("trunk_txt")
self.trunk{j} = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.trunk{j}.setGeometry(QtCore.QRect(380, 10+{y}, 72, 15))
self.trunk{j}.setObjectName("trunk{j}")
self.seat{j} = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.seat{j}.setGeometry(QtCore.QRect(540, 10+{y}, 72, 15))
self.seat{j}.setObjectName("seat")
self.seat_txt{j} = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.seat_txt{j}.setGeometry(QtCore.QRect(480, 10+{y}, 51, 16))
self.seat_txt{j}.setObjectName("seat_txt{j}")
self.by_name_txt{j} = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.by_name_txt{j}.setGeometry(QtCore.QRect(10, 50+{y}, 91, 16))
self.by_name_txt{j}.setObjectName("by_name_txt{j}")
self.by_name{j} = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.by_name{j}.setGeometry(QtCore.QRect(100, 50+{y}, 141, 16))
self.by_name{j}.setObjectName("by_name{j}")
self.by_id{j} = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.by_id{j}.setGeometry(QtCore.QRect(440, 50+{y}, 181, 16))
self.by_id{j}.setObjectName("by_id{j}")
self.by_id_txt{j} = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.by_id_txt{j}.setGeometry(QtCore.QRect(320, 50+{y}, 111, 16))
self.by_id_txt{j}.setObjectName("by_id_txt{j}")
self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 699, 329+{y}))
'''.format(j=i+1,y=90*i))
self.comboBox.currentTextChanged.connect(self.updatetrunk)
self.searchButton.clicked.connect(self.searchticket)
self.comboBox.addItems(items)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "票务信息"))
self.label.setText(_translate("MainWindow", "票务信息
"))
self.A_date.setText(_translate("MainWindow", "TextLabel"))
self.exitButton.setText(_translate("MainWindow", "返回"))
self.label_txt1.setText(_translate("MainWindow", "请选择列车:"))
self.searchButton.setText(_translate("MainWindow", "查看"))
self.label_txt2.setText(_translate("MainWindow", "请选择车厢:"))
self.A_date.hide()
for i in range(self.numb):
exec('''
self.train_txt{j}.setText("列车:")
self.station_txt{j}.setText("车站:")
self.trunk_txt{j}.setText("车厢号:")
self.seat_txt{j}.setText("座位号:")
self.by_name_txt{j}.setText("乘车人姓名:")
self.by_id_txt{j}.setText("乘车人身份证:")
self.line{j}.hide()
self.train_txt{j}.hide()
self.train{j}.hide()
self.station_txt{j}.hide()
self.station{j}.hide()
self.trunk_txt{j}.hide()
self.trunk{j}.hide()
self.seat_txt{j}.hide()
self.seat{j}.hide()
self.by_name_txt{j}.hide()
self.by_name{j}.hide()
self.by_id_txt{j}.hide()
self.by_id{j}.hide()
'''.format(j=i+1))
def updatetrunk(self):
self.comboBox_1.clear()
train_no = self.comboBox.currentText()#获取列车号
conn = pymysql.connect(
host='localhost',
port=3306,
user='root',
passwd='111111',
db='train',
charset='utf8'
)
cursor = conn.cursor()
sql = "select 一等座数量,二等座数量 from 列车表 where 车次号='%s' and 列车状态='运行'"%train_no
cursor.execute(sql)
num = []
for i in cursor.fetchall():
for j in i:
num.append(j)
num1 = 0
num2 = 0
if num[0]%20>=1:
num1 = int(num[0]/20+1)
if num[0]%20==0:
num1 = int(num[0]/20)
if num[1]%20>=1:
num2 = int(num[1]/20+1)
if num[1]%20==0:
num2 = int(num[1]/20)
for i in range(num1+num2):
self.comboBox_1.addItem(str(i+1))
cursor.close()
conn.close()
def searchticket(self):
for i in range(self.numb):
exec('''
self.line{j}.hide()
self.train_txt{j}.hide()
self.train{j}.hide()
self.station_txt{j}.hide()
self.station{j}.hide()
self.trunk_txt{j}.hide()
self.trunk{j}.hide()
self.seat_txt{j}.hide()
self.seat{j}.hide()
self.by_name_txt{j}.hide()
self.by_name{j}.hide()
self.by_id_txt{j}.hide()
self.by_id{j}.hide()
'''.format(j=i + 1))
trainno = self.comboBox.currentText()
trunkno = self.comboBox_1.currentText()
conn = pymysql.connect(
host='localhost',
port=3306,
user='root',
passwd='111111',
db='train',
charset='utf8'
)
cursor = conn.cursor()
cursor.execute("select 列车编号 from 列车表 where 车次号='%s' and 列车状态='运行'"%trainno)
trainNO = 0
for i in cursor.fetchall():
for j in i:
trainNO = j
cursor.execute("select 出发站,车厢,座位,乘车人姓名,乘车人身份证 from 座位表 where 列车编号=%s and 车厢='%s'"%(trainNO,trunkno))
row = cursor.rowcount
infor = cursor.fetchall()
if row == 0:
QMessageBox.warning(self, "警告", "该车箱暂无乘客!!!")
else:
date = []
for a in infor:
date1 = []
for b in a:
date1.append(b)
date.append(date1)
for c in range(len(date)):
exec('''
self.line{j}.show()
self.train_txt{j}.show()
self.train{j}.show()
self.station_txt{j}.show()
self.station{j}.show()
self.trunk_txt{j}.show()
self.trunk{j}.show()
self.seat_txt{j}.show()
self.seat{j}.show()
self.by_name_txt{j}.show()
self.by_name{j}.show()
self.by_id_txt{j}.show()
self.by_id{j}.show()
self.train{j}.clear()
self.station{j}.clear()
self.trunk{j}.clear()
self.seat{j}.clear()
self.by_name{j}.clear()
self.by_id{j}.clear()
self.train{j}.setText(trainno)
self.station{j}.setText(str(date[{k}][0]))
self.trunk{j}.setText(str(date[{k}][1]))
self.seat{j}.setText(str(date[{k}][2]))
self.by_name{j}.setText(str(date[{k}][3]))
self.by_id{j}.setText(str(date[{k}][4]))
'''.format(j=c+1,k=c))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
管理员-列车管理UI设计:可以展示历史列车的信息以及添加列车的功能模块
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'train_manageUI.ui'
#
# Created by: PyQt5 UI code generator 5.15.6
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
import pymysql
import thp
class Ui_MainWindow(object):
numb = 0
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(800, 600)
MainWindow.setStyleSheet("#MainWindow{border-image: url(:/thpic/60.jpg);}")
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(320, 20, 181, 41))
self.label.setObjectName("label")
self.A_date = QtWidgets.QLabel(self.centralwidget)
self.A_date.setGeometry(QtCore.QRect(40, 510, 72, 15))
self.A_date.setObjectName("A_date")
self.scrollArea = QtWidgets.QScrollArea(self.centralwidget)
self.scrollArea.setGeometry(QtCore.QRect(40, 130, 701, 331))
self.scrollArea.setWidgetResizable(False)
self.scrollArea.setObjectName("scrollArea")
self.scrollAreaWidgetContents = QtWidgets.QWidget()
self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 699, 329))
self.scrollAreaWidgetContents.setObjectName("scrollAreaWidgetContents")
self.scrollArea.setWidget(self.scrollAreaWidgetContents)
self.exitButton = QtWidgets.QPushButton(self.centralwidget)
self.exitButton.setGeometry(QtCore.QRect(380, 500, 93, 28))
self.exitButton.setObjectName("exitButton")
self.updateButton = QtWidgets.QPushButton(self.centralwidget)
self.updateButton.setGeometry(QtCore.QRect(280, 500, 93, 28))
self.updateButton.setObjectName("updateButton")
self.add_trainButton = QtWidgets.QPushButton(self.centralwidget)
self.add_trainButton.setGeometry(QtCore.QRect(280, 470, 191, 28))
self.add_trainButton.setObjectName("add_trainButton")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 26))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
conn = pymysql.connect(
host='localhost',
port=3306,
user='root',
passwd='111111',
db='train',
charset='utf8'
)
cursor = conn.cursor()
cursor.execute("select * from 列车表")
self.numb = cursor.rowcount
for i in range(self.numb):
exec('''
self.line{j} = QtWidgets.QFrame(self.scrollAreaWidgetContents)
self.line{j}.setGeometry(QtCore.QRect(0, 150+{y}, 701, 16))
self.line{j}.setFrameShape(QtWidgets.QFrame.HLine)
self.line{j}.setFrameShadow(QtWidgets.QFrame.Sunken)
self.line{j}.setObjectName("line{j}")
self.train_txt{j} = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.train_txt{j}.setGeometry(QtCore.QRect(10, 10+{y}, 51, 16))
self.train_txt{j}.setObjectName("train_txt{j}")
self.train{j} = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.train{j}.setGeometry(QtCore.QRect(60, 10+{y}, 72, 15))
self.train{j}.setObjectName("train{j}")
self.begin_txt{j} = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.begin_txt{j}.setGeometry(QtCore.QRect(10, 40+{y}, 72, 15))
self.begin_txt{j}.setObjectName("begin_txt{j}")
self.begin{j} = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.begin{j}.setGeometry(QtCore.QRect(90, 40+{y}, 161, 16))
self.begin{j}.setObjectName("begin{j}")
self.end_txt{j} = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.end_txt{j}.setGeometry(QtCore.QRect(310, 40+{y}, 72, 15))
self.end_txt{j}.setObjectName("end_txt{j}")
self.end{j} = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.end{j}.setGeometry(QtCore.QRect(390, 40+{y}, 161, 16))
self.end{j}.setObjectName("end{j}")
self.via_station_txt{j} = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.via_station_txt{j}.setGeometry(QtCore.QRect(10, 70+{y}, 61, 16))
self.via_station_txt{j}.setObjectName("via_station_txt{j}")
self.via_station{j} = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.via_station{j}.setGeometry(QtCore.QRect(70, 70+{y}, 621, 16))
self.via_station{j}.setObjectName("via_station{j}")
self.first_txt{j} = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.first_txt{j}.setGeometry(QtCore.QRect(10, 100+{y}, 91, 16))
self.first_txt{j}.setObjectName("first_txt{j}")
self.first{j} = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.first{j}.setGeometry(QtCore.QRect(100, 100+{y}, 72, 15))
self.first{j}.setObjectName("first{j}")
self.first_p{j} = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.first_p{j}.setGeometry(QtCore.QRect(300, 100+{y}, 72, 15))
self.first_p{j}.setObjectName("first_p{j}")
self.first_p_txt{j} = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.first_p_txt{j}.setGeometry(QtCore.QRect(210, 100+{y}, 91, 16))
self.first_p_txt{j}.setObjectName("first_p_txt{j}")
self.first_s_txt{j} = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.first_s_txt{j}.setGeometry(QtCore.QRect(440, 100+{y}, 91, 16))
self.first_s_txt{j}.setObjectName("first_s_txt{j}")
self.first_s{j} = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.first_s{j}.setGeometry(QtCore.QRect(530, 100+{y}, 72, 15))
self.first_s{j}.setObjectName("first_s{j}")
self.second_p_txt{j} = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.second_p_txt{j}.setGeometry(QtCore.QRect(210, 130+{y}, 91, 16))
self.second_p_txt{j}.setObjectName("second_p_txt{j}")
self.second{j} = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.second{j}.setGeometry(QtCore.QRect(100, 130+{y}, 72, 15))
self.second{j}.setObjectName("second{j}")
self.second_s{j} = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.second_s{j}.setGeometry(QtCore.QRect(530, 130+{y}, 72, 15))
self.second_s{j}.setObjectName("second_s{j}")
self.second_p{j} = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.second_p{j}.setGeometry(QtCore.QRect(300, 130+{y}, 72, 15))
self.second_p{j}.setObjectName("second_p{j}")
self.second_txt{j} = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.second_txt{j}.setGeometry(QtCore.QRect(10, 130+{y}, 91, 16))
self.second_txt{j}.setObjectName("second_txt{j}")
self.second_s_txt{j} = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.second_s_txt{j}.setGeometry(QtCore.QRect(440, 130+{y}, 91, 16))
self.second_s_txt{j}.setObjectName("second_s_txt{j}")
self.train_state_txt{j} = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.train_state_txt{j}.setGeometry(QtCore.QRect(310, 10+{y}, 72, 15))
self.train_state_txt{j}.setObjectName("train_state_txt{j}")
self.train_state{j} = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.train_state{j}.setGeometry(QtCore.QRect(400, 10+{y}, 72, 15))
self.train_state{j}.setObjectName("train_state{j}")
self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 699, 329+{y}))
'''.format(j=i+1,y=155*i))
self.updateButton.clicked.connect(self.updateTrain)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "列车管理"))
self.label.setText(_translate("MainWindow", "列车管理
"))
self.A_date.setText(_translate("MainWindow", "TextLabel"))
self.exitButton.setText(_translate("MainWindow", "返回"))
self.updateButton.setText(_translate("MainWindow", "刷新"))
self.add_trainButton.setText(_translate("MainWindow", "添加列车"))
self.A_date.hide()
for i in range(self.numb):
exec('''
self.train_txt{j}.setText(_translate("MainWindow", "列车:"))
self.begin_txt{j}.setText(_translate("MainWindow", "发车时间:"))
self.via_station_txt{j}.setText(_translate("MainWindow", "途径站:"))
self.first_txt{j}.setText(_translate("MainWindow", "一等座数量:"))
self.first_p_txt{j}.setText(_translate("MainWindow", "一等座价格:"))
self.first_s_txt{j}.setText(_translate("MainWindow", "一等座售量:"))
self.second_p_txt{j}.setText(_translate("MainWindow", "二等座价格:"))
self.second_txt{j}.setText(_translate("MainWindow", "二等座数量:"))
self.second_s_txt{j}.setText(_translate("MainWindow", "二等座售量:"))
self.train_state_txt{j}.setText(_translate("MainWindow", "列车状态:"))
self.end_txt{j}.setText(_translate("MainWindow", "抵达时间:"))
'''.format(j=i+1))
def updateTrain(self):
for i in range(self.numb):
exec('''
self.end_txt{j}.hide()
self.end{j}.hide()
self.line{j}.hide()
self.train_txt{j}.hide()
self.train{j}.hide()
self.begin_txt{j}.hide()
self.begin{j}.hide()
self.via_station_txt{j}.hide()
self.via_station{j}.hide()
self.first_txt{j}.hide()
self.first{j}.hide()
self.first_p{j}.hide()
self.first_p_txt{j}.hide()
self.first_s_txt{j}.hide()
self.first_s{j}.hide()
self.second_p_txt{j}.hide()
self.second{j}.hide()
self.second_s{j}.hide()
self.second_p{j}.hide()
self.second_txt{j}.hide()
self.second_s_txt{j}.hide()
self.train_state_txt{j}.hide()
self.train_state{j}.hide()
'''.format(j=i + 1, k=i))
conn = pymysql.connect(
host='localhost',
port=3306,
user='root',
passwd='111111',
db='train',
charset='utf8'
)
cursor = conn.cursor()
cursor.execute("select * from 列车表")
date = []
for a in cursor.fetchall():
date1 = []
for b in a:
date1.append(b)
date.append(date1)
for i in range(len(date)):
cursor.execute("select count(*) from 座位表 where 列车编号=%s and 座位级别='一等座'"%date[i][0])
for c in cursor.fetchall():
for d in c:
date[i].append(d)
cursor.execute("select count(*) from 座位表 where 列车编号=%s and 座位级别='二等座'" % date[i][0])
for c in cursor.fetchall():
for d in c:
date[i].append(d)
for i in range(len(date)):
exec('''
self.end_txt{j}.show()
self.end{j}.show()
self.line{j}.show()
self.train_txt{j}.show()
self.train{j}.show()
self.begin_txt{j}.show()
self.begin{j}.show()
self.via_station_txt{j}.show()
self.via_station{j}.show()
self.first_txt{j}.show()
self.first{j}.show()
self.first_p{j}.show()
self.first_p_txt{j}.show()
self.first_s_txt{j}.show()
self.first_s{j}.show()
self.second_p_txt{j}.show()
self.second{j}.show()
self.second_s{j}.show()
self.second_p{j}.show()
self.second_txt{j}.show()
self.second_s_txt{j}.show()
self.train_state_txt{j}.show()
self.train_state{j}.show()
self.train{j}.clear()
self.begin{j}.clear()
self.via_station{j}.clear()
self.first{j}.clear()
self.first_p{j}.clear()
self.first_s{j}.clear()
self.second{j}.clear()
self.second_s{j}.clear()
self.second_p{j}.clear()
self.train_state{j}.clear()
self.end{j}.clear()
self.train{j}.setText(str(date[{k}][1]))
self.begin{j}.setText(str(date[{k}][2]))
self.end{j}.setText(str(date[{k}][3]))
self.via_station{j}.setText(str(date[{k}][4]))
self.first{j}.setText(str(date[{k}][5]))
self.first_p{j}.setText(str(date[{k}][6]))
self.first_s{j}.setText(str(date[{k}][10]))
self.second{j}.setText(str(date[{k}][7]))
self.second_s{j}.setText(str(date[{k}][11]))
self.second_p{j}.setText(str(date[{k}][8]))
self.train_state{j}.setText(str(date[{k}][9]))
'''.format(j=i+1,k=i))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
管理员-列车管理-添加列车UI设计:实现添加列车功能、以逐一添加途径站的方式来实现
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'add_trainUI.ui'
#
# Created by: PyQt5 UI code generator 5.15.6
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtCore import pyqtSlot, QDate
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QMessageBox, QInputDialog, QLineEdit
import pymysql
import datetime
import thp
class Ui_MainWindow(object):
data = []
state1 = ''
state2 = ''
touch = 0
place2 = ["广州", "深圳", "佛山", "东莞","中山","珠海","江门","肇庆","惠州","汕头","潮州","揭阳","汕尾","湛江","茂名","阳江","云浮","韶关","清远","梅州", "河源"]
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(800, 600)
#MainWindow.setStyleSheet("#MainWindow{border-image: url(:/thpic/60.jpg);}")
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(320, 20, 181, 41))
self.label.setObjectName("label")
self.A_date = QtWidgets.QLabel(self.centralwidget)
self.A_date.setGeometry(QtCore.QRect(40, 510, 72, 15))
self.A_date.setObjectName("A_date")
self.exitButton = QtWidgets.QPushButton(self.centralwidget)
self.exitButton.setGeometry(QtCore.QRect(390, 490, 121, 28))
self.exitButton.setObjectName("exitButton")
self.ensureButton = QtWidgets.QPushButton(self.centralwidget)
self.ensureButton.setGeometry(QtCore.QRect(270, 490, 121, 28))
self.ensureButton.setObjectName("ensureButton")
self.train_txt = QtWidgets.QLabel(self.centralwidget)
self.train_txt.setGeometry(QtCore.QRect(50, 90, 61, 16))
self.train_txt.setObjectName("train_txt")
self.train = QtWidgets.QLineEdit(self.centralwidget)
self.train.setGeometry(QtCore.QRect(110, 90, 141, 21))
self.train.setObjectName("train")
self.via_Station_txt = QtWidgets.QLabel(self.centralwidget)
self.via_Station_txt.setGeometry(QtCore.QRect(50, 140, 61, 16))
self.via_Station_txt.setObjectName("via_Station_txt")
self.comboBox = QtWidgets.QComboBox(self.centralwidget)
self.comboBox.setGeometry(QtCore.QRect(110, 140, 141, 22))
self.comboBox.setObjectName("comboBox")
self.begin_date = QtWidgets.QLabel(self.centralwidget)
self.begin_date.setGeometry(QtCore.QRect(30, 180, 72, 21))
self.begin_date.setObjectName("begin_date")
self.dateEdit = QtWidgets.QDateEdit(self.centralwidget)
self.dateEdit.setGeometry(QtCore.QRect(110, 180, 141, 22))
self.dateEdit.setObjectName("dateEdit")
self.begin_time = QtWidgets.QLabel(self.centralwidget)
self.begin_time.setGeometry(QtCore.QRect(30, 220, 72, 15))
self.begin_time.setObjectName("begin_time")
self.addButton = QtWidgets.QPushButton(self.centralwidget)
self.addButton.setGeometry(QtCore.QRect(270, 210, 93, 31))
self.addButton.setObjectName("addButton")
self.timeEdit = QtWidgets.QTimeEdit(self.centralwidget)
self.timeEdit.setGeometry(QtCore.QRect(110, 220, 141, 22))
self.timeEdit.setObjectName("timeEdit")
self.state_list = QtWidgets.QTextBrowser(self.centralwidget)
self.state_list.setGeometry(QtCore.QRect(490, 60, 241, 371))
self.state_list.setObjectName("state_list")
self.label_2 = QtWidgets.QLabel(self.centralwidget)
self.label_2.setGeometry(QtCore.QRect(490, 40, 241, 20))
self.label_2.setObjectName("label_2")
self.clearButton = QtWidgets.QPushButton(self.centralwidget)
self.clearButton.setGeometry(QtCore.QRect(570, 440, 93, 28))
self.clearButton.setObjectName("clearButton")
self.label_3 = QtWidgets.QLabel(self.centralwidget)
self.label_3.setGeometry(QtCore.QRect(20, 350, 91, 16))
self.label_3.setObjectName("label_3")
self.first = QtWidgets.QLineEdit(self.centralwidget)
self.first.setGeometry(QtCore.QRect(110, 350, 71, 21))
self.first.setObjectName("first")
self.label_4 = QtWidgets.QLabel(self.centralwidget)
self.label_4.setGeometry(QtCore.QRect(210, 350, 91, 16))
self.label_4.setObjectName("label_4")
self.first_p = QtWidgets.QLineEdit(self.centralwidget)
self.first_p.setGeometry(QtCore.QRect(300, 350, 71, 21))
self.first_p.setObjectName("first_p")
self.label_5 = QtWidgets.QLabel(self.centralwidget)
self.label_5.setGeometry(QtCore.QRect(20, 390, 91, 16))
self.label_5.setObjectName("label_5")
self.second_p = QtWidgets.QLineEdit(self.centralwidget)
self.second_p.setGeometry(QtCore.QRect(300, 390, 71, 21))
self.second_p.setObjectName("second_p")
self.label_6 = QtWidgets.QLabel(self.centralwidget)
self.label_6.setGeometry(QtCore.QRect(210, 390, 91, 16))
self.label_6.setObjectName("label_6")
self.second = QtWidgets.QLineEdit(self.centralwidget)
self.second.setGeometry(QtCore.QRect(110, 390, 71, 21))
self.second.setObjectName("second")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 26))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.dateEdit.setCalendarPopup(True)
self.dateEdit.setDate(QDate.fromString(str(datetime.date.today()), 1))
self.dateEdit.setMinimumDateTime(QtCore.QDateTime(QDate.fromString(str(datetime.date.today()), 1), QtCore.QTime(0, 0, 0)))
self.addButton.clicked.connect(self.addStation)
self.comboBox.addItems(self.place2)
self.clearButton.clicked.connect(self.clearState)
self.ensureButton.clicked.connect(self.ensure_addTrain)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "添加列车"))
self.label.setText(_translate("MainWindow", "添加列车
"))
self.A_date.setText(_translate("MainWindow", "TextLabel"))
self.exitButton.setText(_translate("MainWindow", "返回"))
self.ensureButton.setText(_translate("MainWindow", "确定添加"))
self.train_txt.setText(_translate("MainWindow", "车次号:"))
self.via_Station_txt.setText(_translate("MainWindow", "途径站:"))
self.begin_date.setText(_translate("MainWindow", "出发日期:"))
self.begin_time.setText(_translate("MainWindow", "出发时间:"))
self.addButton.setText(_translate("MainWindow", "添加途径站"))
self.timeEdit.setDisplayFormat(_translate("MainWindow", "HH:mm"))
self.label_2.setText(_translate("MainWindow", " 途径站展示框"))
self.clearButton.setText(_translate("MainWindow", "一键清空"))
self.label_3.setText(_translate("MainWindow", "一等座数量:"))
self.label_4.setText(_translate("MainWindow", "一等座价格:"))
self.label_5.setText(_translate("MainWindow", "二等座数量:"))
self.label_6.setText(_translate("MainWindow", "二等座价格:"))
self.A_date.hide()
def addStation(self):
data1 = []
data2 = []
success = 0
if self.train.text()=='' or self.first.text()=='' or self.first_p.text()=='' or self.second.text()=='' or self.second_p.text()=='':
self.touch = 0
QMessageBox.critical(self,"错误","请输入完整的列车信息!!!")
return
if int(self.first.text()) % 20 != 0 or int(self.second.text()) % 20 != 0:
self.touch = 0
QMessageBox.critical(self,"错误","座位数量需要输入20的整数倍!!!")
return
conn = pymysql.connect(
host='localhost',
port=3306,
user='root',
passwd='111111',
db='train',
charset='utf8'
)
cursor = conn.cursor()
date1 = self.dateEdit.text()+' '+self.timeEdit.text()
cursor.execute("select 抵达时间 from 列车表 where 车次号='%s'"%self.train.text())
row = cursor.rowcount
if row == 0:
success=1
else:
for i in cursor.fetchall():
for j in i:
date2 = datetime.datetime.strptime(j,"%Y/%m/%d %H:%M")
date3 = datetime.datetime.strptime(date1,"%Y/%m/%d %H:%M")
day = (date3-date2).days
print(date3,date2,day)
if day>=1:
success = 1
else:
success = 0
QMessageBox.critical(self, "错误", "无法添加列车,该列车在运行或维护中!!!")
'''if self.state2.find(self.comboBox.currentText()) != -1:
success = 0
QMessageBox.critical(self, "错误", "途径站不能出现相同地址!!!")'''
if success == 1:
self.touch = self.touch + 1
self.train.setEnabled(False)
self.first.setEnabled(False)
self.first_p.setEnabled(False)
self.second.setEnabled(False)
self.second_p.setEnabled(False)
print("成功添加列车途径站:%s"%self.comboBox.currentText())
data2.append(self.comboBox.currentText())
data2.append(self.dateEdit.text())
data2.append(self.timeEdit.text())
self.data.append(data2)
if self.touch==1:
self.state1 = self.state1 + ""
+ self.comboBox.currentText() +"("+date1+")"+""
self.state2 = self.state2 + self.comboBox.currentText()
else:
self.state1 = self.state1 +"|
" +""
+ self.comboBox.currentText() +"("+date1+")"+ ""
self.state2 = self.state2 +"-"+ self.comboBox.currentText()
self.state_list.setHtml(self.state1)
self.place2.remove(self.comboBox.currentText())
self.comboBox.clear()
self.comboBox.addItems(self.place2)
def clearState(self):
print("清空途径站")
self.place2=["广州", "深圳", "佛山", "东莞","中山","珠海","江门","肇庆","惠州","汕头","潮州","揭阳","汕尾","湛江","茂名","阳江","云浮","韶关","清远","梅州", "河源"]
self.comboBox.clear()
self.comboBox.addItems(self.place2)
self.touch = 0
self.train.setEnabled(True)
self.first.setEnabled(True)
self.first_p.setEnabled(True)
self.second.setEnabled(True)
self.second_p.setEnabled(True)
self.state1=''
self.state2=''
self.data.clear()
self.state_list.clear()
def ensure_addTrain(self):
success = 0
if self.touch<2:
QMessageBox.critical(self, "错误", "途径站需要两个以上!!!")
return
conn = pymysql.connect(
host='localhost',
port=3306,
user='root',
passwd='111111',
db='train',
charset='utf8'
)
cursor = conn.cursor()
passwd, bool1 = QInputDialog.getText(self, '密码', '请输入管理员密码', QLineEdit.EchoMode.Password)
if passwd and bool1:
sql = "select 密码 from 管理员表 where 管理员账号='%s'" % self.A_date.text()
cursor.execute(sql)
for i in cursor.fetchall():
for j in i:
if j == passwd:
success = 1
else:
success = 0
QMessageBox.critical(self, "错误", "请重新输入管理员密码!!")
if passwd == '' and bool1:
success = 0
QMessageBox.critical(self, "错误", "请输入管理员密码!!")
cursor.execute("select max(列车编号) from 列车表")
m = 0
for i in cursor.fetchall():
for j in i:
if j == None:
m = 0
else:
m = j + 1
a = len(self.data)
b_t = self.data[0][1] + ' ' +self.data[0][2]
e_t = self.data[a-1][1] + ' ' +self.data[a-1][2]
if success ==1:
sql = "insert into 列车表(列车编号,车次号,发车时间,抵达时间,途径站,一等座数量,一等座价格,二等座数量,二等座价格,列车状态) values (%s,'%s','%s','%s','%s',%s,%s,%s,%s,'运行')"%(m,self.train.text(),b_t,e_t,self.state2,int(self.first.text()),int(self.first_p.text()),int(self.second.text()),int(self.second_p.text()))
cursor.execute(sql)
conn.commit()
cursor.execute("select max(车站编号) from 车站表")
t_m = 0
for q in cursor.fetchall():
for w in q:
if w == None:
t_m = 0
else:
t_m = w+1
print(t_m)
for c in range(a):
cursor.execute("insert into 车站表(车站编号,列车编号,车站名,发车日期,发车时间,状态) values(%s,%s,'%s','%s','%s','未抵达')"%(t_m,m,self.data[c][0],self.data[c][1],self.data[c][2]))
conn.commit()
t_m = t_m + 1
QMessageBox.information(self,"成功","添加列车成功!!!")
self.exitButton.click()
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
所有UI的背景实现:代码太长不挂出来了,不影响程序运行,具体可以查阅QT的背景制作,可以去掉代码里的背景代码调用
20220520_002105