使用python制作的简易自习室座位预约系统

Posted slandarer

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用python制作的简易自习室座位预约系统相关的知识,希望对你有一定的参考价值。

刚学习python不久,如有问题希望能得到指正

0 效果

座位选择框
在这里插入图片描述
在这里插入图片描述

1 关于所需库

Python 环境中需要安装下列 python 包:

  1. PySide2
  2. datetime
  3. json
  4. argparse

2 关于座位选择框

选择框内桌子数量,大小,样式以及每个椅子位置都是可变的,例如我们可以将桌子颜色和是否圆角改变:
在这里插入图片描述
这主要依靠seatInf.json内的信息,展示如下:

{
    "tableNum": 6,
    "tablePos": [
        [0.02,0.15],
        [0.35,0.15],
        [0.68,0.15],
        [0.02,0.65],
        [0.35,0.65],
        [0.68,0.65]
    ],
    "tableSize": [
        [0.25,0.2],
        [0.25,0.2],
        [0.25,0.2],
        [0.25,0.2],
        [0.25,0.2],
        [0.25,0.2]
    ],
    "tableType": [
        0,1,2,0,0,0
    ],
    "tableSS": [
        "QLabel{background: rgb(245,245,245);color:rgb(92,92,92);border-radius:50px;border: 3px solid rgb(142,142,142)}",
        "QLabel{background: rgb(245,245,245);color:rgb(92,92,92);border: 3px solid rgb(142,142,142)}",
        "QLabel{background: rgb(221,217,195);color:rgb(92,92,92);border: 3px solid rgb(142,142,142)}"
    ],
    "tableId": [
        "A","B","C","D","E","F"
    ],
    "chairNum": [
        6,6,6,6,6,6
    ],
    "chairPos": [
        [
            [0.04,-0.08],
            [0.105,-0.08],
            [0.17,-0.08],
            [0.04,0.21],
            [0.105,0.21],
            [0.17,0.21]
        ],
        [
            [0.04,-0.08],
            [0.105,-0.08],
            [0.17,-0.08],
            [0.04,0.21],
            [0.105,0.21],
            [0.17,0.21]
        ],[
            [0.04,-0.08],
            [0.105,-0.08],
            [0.17,-0.08],
            [0.04,0.21],
            [0.105,0.21],
            [0.17,0.21]
        ],[
            [0.04,-0.08],
            [0.105,-0.08],
            [0.17,-0.08],
            [0.04,0.21],
            [0.105,0.21],
            [0.17,0.21]
        ],[
            [0.04,-0.08],
            [0.105,-0.08],
            [0.17,-0.08],
            [0.04,0.21],
            [0.105,0.21],
            [0.17,0.21]
        ],[
            [0.04,-0.08],
            [0.105,-0.08],
            [0.17,-0.08],
            [0.04,0.21],
            [0.105,0.21],
            [0.17,0.21]
        ]
    ],
    "chairSize": [
        0.032,0.07
    ],
    "chairSS_W": "background: rgb(242,242,242);border-radius:15px;border: 3px solid rgb(74,69,42)",
    "chairSS_K": "background: rgb(64,64,64);border-radius:15px;border: 3px solid rgb(74,69,42)",
    "chairSS_R": "background: rgb(149,55,43);border-radius:15px;border: 3px solid rgb(74,69,42)",
    "mapSize": [
        2,2
    ]
}

3 关于申请表和座位被占情况

由于只是为了模拟过程,现申请表以及座位被占情况分别存储在orderList.json和occupied.json中:

3.1 orderList.json:

"[[\\"A1\\", \\"A2\\", \\"A3\\", \\"A4\\", \\"A5\\", \\"A6\\", \\"B1\\", \\"B2\\", \\"B3\\", \\"B4\\", \\"B5\\", \\"B6\\", \\"C1\\", \\"C2\\", \\"C3\\", \\"C4\\", \\"C5\\", \\"C6\\", \\"D1\\", \\"D2\\", \\"D3\\", \\"D4\\", \\"D5\\", \\"D6\\", \\"E1\\", \\"E2\\", \\"E3\\", \\"E4\\", \\"E5\\", \\"E6\\", \\"F1\\", \\"F2\\", \\"F3\\", \\"F4\\", \\"F5\\", \\"F6\\"], [\\"\\", \\"\\", \\"\\", \\"\\", \\"\\", \\"\\", \\"\\", \\"\\", \\"\\", \\"\\", \\"\\", \\"\\", \\"\\", \\"\\", \\"\\", \\"1816000XXXX\\", \\"\\", \\"\\", \\"\\", \\"\\", \\"\\", \\"\\", \\"\\", \\"\\", \\"\\", \\"\\", \\"\\", \\"\\", \\"\\", \\"\\", \\"\\", \\"\\", \\"\\", \\"\\", \\"\\", \\"\\"], [\\"\\", \\"\\", \\"\\", \\"\\", \\"\\", \\"\\", \\"\\", \\"\\", \\"\\", \\"\\", \\"\\", \\"\\", \\"\\", \\"\\", \\"\\", \\"temp\\", \\"\\", \\"\\", \\"\\", \\"\\", \\"\\", \\"\\", \\"\\", \\"\\", \\"\\", \\"\\", \\"\\", \\"\\", \\"\\", \\"\\", \\"\\", \\"\\", \\"\\", \\"\\", \\"\\", \\"\\"]]"

3.2 occupied.json:

"{\\"A1\\": false, \\"A2\\": false, \\"A3\\": false, \\"A4\\": false, \\"A5\\": false, \\"A6\\": false, \\"B1\\": false, \\"B2\\": false, \\"B3\\": false, \\"B4\\": false, \\"B5\\": false, \\"B6\\": false, \\"C1\\": false, \\"C2\\": false, \\"C3\\": false, \\"C4\\": true, \\"C5\\": false, \\"C6\\": false, \\"D1\\": false, \\"D2\\": false, \\"D3\\": false, \\"D4\\": false, \\"D5\\": false, \\"D6\\": false, \\"E1\\": false, \\"E2\\": false, \\"E3\\": false, \\"E4\\": false, \\"E5\\": false, \\"E6\\": false, \\"F1\\": false, \\"F2\\": false, \\"F3\\": false, \\"F4\\": false, \\"F5\\": false, \\"F6\\": false}"

4 关于命令行参数

我们使用命令行代码模拟刷卡过程,同时我们也设置了预约和申请暂离的命令行代码:

4.1 slotCard_in

Python slotCard_in.py -i="XXXXXXXXXXX"
Python slotCard_in.py --student-id="XXXXXXXXXXX"

4.2 slotCard_out

Python slotCard_out.py -i="XXXXXXXXXXX"
Python slotCard_out.py --student-id="XXXXXXXXXXX"

4.3 cmd_order

'''
TEST CODE:
--------------------------------
see Map:
Python cmd_order.py
--------------------------------
order seat: 
Python cmd_order.py -i="XXXXXXXXXXX" -n="xxx" -s="A1"

-h   --help         show the help message and exit
-i   --student-id   student id
-n   --student-name student name
-s   --seatPos      seat id  
'''

4.4 cmd_leave

'''
TEST CODE:
----------------------------------------------
leave for temp
Python cmd_leave.py -i="XXXXXXXXXXX" -t="temp"
----------------------------------------------
leave
Python cmd_leave.py -i="XXXXXXXXXXX" -t="free"  
[or]
Python cmd_leave.py -i="XXXXXXXXXXX" 

-h   --help         show the help message and exit
-i   --student-id   student id
-t   --leave-type   temp/free 
'''

5 关于命令行输出

5.1 cmd_order 预约

> Python cmd_order.py
[seat]============================
可预约座位:

 ▇ A2 A3 A4 A5 A6
 B1 B2 B3 B4 B5 B6
 C1 C2 C3 C4 C5 C6
 D1 D2 D3 D4 D5 D6
 E1 E2 E3 E4 E5 E6
 F1 F2 F3 F4 F5 F6

> Python cmd_order.py -i="18160000000" -n="xxx" -s="A1"
[book error]========================
座位已被占,请选择其他位置申请

> Python cmd_order.py -i="18160000000" -n="xxx" -s="A100"
[book error]========================
座位编号格式不正确

> Python cmd_order.py -i="18160000000" -n="xxx" -s="A2"
[book]===========================================
2021-05-31 18:04:35
姓名:xxx
学号:18160000000
座次:A2
预约成功!
-------------------------------------------------
注意事项:
1、预约成功后请在30分钟内到达,否则预约信息将失效。
2、进入自习室前请刷校园卡核验信息。
3、如要暂离请cmd运行如下代码:
   Python cmd_leave.py -i='XXXXXXXXXXX' -t='temp'
4、离开、取消预约请cmd运行如下代码:
   Python cmd_leave.py -i='XXXXXXXXXXX' -t='free'

> Python cmd_order.py -i="18160000000" -n="xxx" -s="A3"
[book error]========================
请勿重复预约

5.2 slotCard_in 刷卡进入

> Python slotCard_in.py -i="1816000XXXX"
[in error]==========================
非本校校园卡或已超时

> Python slotCard_in.py -i="18160000000"
[in]================================
预约时间:2021-05-31 18:04:35
校园卡号:18160000000
座次:A2

5.3 cmd_leave 申请离开或暂离

> Python cmd_leave.py -i="1816000XXXX" -t="temp"
[out error]=========================
可能输入了错误的校园卡号

> Python cmd_leave.py -i="18160000000" -t="temp"
[out]===============================
已进行暂离申请

> Python cmd_leave.py -i="18160000000" -t="free"
[out]===============================
已释放位置

5.4 slotCard_out 刷卡离开或暂离

> Python slotCard_out.py -i="18160000000"
[out]===============================
暂离时间:2021-05-31 18:23:09
校园卡号:18160000000
座次:A1

> Python slotCard_out.py -i="1816000XXXX"
[out error]=========================
请更换卡片再次尝试

6 关于界面代码

6.1 orderSystem.py

from PySide2.QtWidgets import QApplication, QWidget,QScrollArea
from PySide2.QtWidgets import QLabel,QPushButton,QLineEdit
from PySide2.QtGui import QIcon,QFont
from PySide2.QtCore import Qt
import sys
sys.path.append("...")
import json
import datetime
from orderDataDisplay import orderDisplay
from InfOperate import occupySeat,order,timeoutDetection,alreadyOreder


class Window_main(QWidget):
    def __init__(self,Width=700,Height=840):
        super().__init__() 
        self.setWindowTitle("book seat online")
        timeoutDetection()

        self.Width=Width
        self.Height=Height
        self.selectedId=""
        self.selectedBtn=[]
        self.icoPath="./gallery/icon.ico"

        # 字体标签
        title_qf=QFont()
        title_qf.setPointSize(11)
        title_qf.setBold(True)
        title_qf.setFamily("Cambria")
        main_qf=QFont()
        main_qf.setPointSize(27)
        main_qf.setBold(True)
        main_qf.setFamily("Cambria")
        Inf_qf=QFont()
        Inf_qf.setPointSize(10)
        Inf_qf.setBold(True)
        Inf_qf.setFamily("Cambria")
        table_qf=QFont()
        table_qf.setPointSize(16)
        table_qf.setBold(True)
        table_qf.setFamily("Cambria")
        # ---
        self.QF_part_title=title_qf         # 框标题字体标签
        self.QF_main_title=main_qf          # 主标题字体标签
        self.QF_state_explain=Inf_qf        # 状态标签解释文本字体标签
        self.QF_Inf_title=title_qf          # 信息标题字体标签
        self.QF_Inf_text=Inf_qf             # 信息文本字体标签
        self.QF_table_name=table_qf         # 桌子编号信息标签

        # 样式表
        self.SS_part_frame="QLabel{background: rgb(245,245,245);color:rgb(92,92,92);border-radius:8px;border: 2.5px solid rgb(122,122,122)}"
        self.SS_part_title="QLabel{background: rgb(245,245,245);color:rgb(92,92,92)}"
        self.SS_main_title="QLabel{background: rgb(245,245,245);color:rgb(92,92,92);border-radius:50px;border: 3px solid rgb(142,142,142)}"
        self.SS_state_frame="QLabel{background: rgb(245,245,245);border-radius:5px;border: 3px solid rgb(172,172,172)}"
        self.SS_W="QLabel{background: rgb(242,242,242);border-radius:9px;border: 3px solid rgb(74,69,42)}"
        self.SS_K="QLabel{background: rgb(64,64,64);border-radius:9px;border: 3px solid rgb(74,69,42)}"
        self.SS_R="QLabel{background: rgb(149,55,43);border-radius:9px;border: 3px solid rgb(74,69,42)}"
        self.SS_state_explain="QLabel{background: rgb(214,219,233);color:rgb(92,92,92)}"
        self.SS_Inf_title="QLabel{background: rgb(230,230,230);color:rgb(82,82,82);border-radius:8px}"
        self.SS_text_Line="QLineEdit{border-radius:3px;background: rgb(205,205,205);color:rgb(82,82,82)}"
        self.SS_book_btn="color:rgb(255,255,255);background: rgb(79,148,204)"

        # path=sys.argv[0]
        # path=path[0:path.rfind("/")]
        f=open("./config/seatInf.json","r")
        seatInf=json.load(f)
        f=open("./config/occupied.json","r")
        seatOccupied=json.load(f)
        self.seatInf=seatInf
        self.seatOccupied=json.loads(seatOccupied)

        self.setSize()
        self.setIcon()
        self.partition()
        self.setStateExp()
        self.setInfBox()
        self.setMap()
        self.setBookBtn()    
    # ================================================================================================
    # 回调函数部分:
    def selectedPos(self):# 座位选择回调
        btn=self.sender()
        tempSelectedId=btn.property("chairId")
        if not self.seatOccupied[tempSelectedId]:
            if len(self.selectedId)==0:
                self.selectedId=tempSelectedId
                self.selectedBtn=btn
                btn.setStyleSheet(self.seatInf["chairSS_R"])
                self.selectedBox.setText(" 当前选择:  "+tempSelectedId)
            else:
                self.selectedBtn.setStyleSheet(self.seatInf["chairSS_W"])
                self.selectedBtn=btn
                btn.setStyleSheet(self.seatInf["chairSS_R"])
                self.selectedId=tempSelectedId
                self.selectedBox.setText(" 当前选择:  "+tempSelectedId)

    def bookSeat(self):
        if not len(self.selectedId)==0:
            if alreadyOreder(self.InfBox_Id.text()):
                print("================================")
                print("请勿重复预约")
                print(" ")
            else:
                nowDate=datetime.datetime.now()
                nowDateStr=nowDate.strftime('%Y-%m-%d %H:%M:%S')
                print("================================")
                print(nowDateStr)
                print("姓名:"+self.InfBox_Name.text())
                print("学号:"+self.InfBox_Id.text())
                print("座次:"+self.selectedId)
                print(" ")
                # myapp.exit()
                # app = QApplication.instance()
                # if app is None: 
                #     app = QApplication(sys.argv)
                self.window_disp= orderDisplay(self.InfBox_Name.text(),
                            self.InfBox_Id.text(),
                            nowDateStr,
                            self.selectedId,700,840)
                self.window_disp.show()
                self.close()

                occupySeat(self.selectedId)
                order(self.InfBox_Id.text(),nowDateStr,self.selectedId)

            
            


    # ================================================================================================
    # 框架构造函数部分:
    def setSize(self):# 调整框架大小
        self.setGeometry(80,80,self.Width,self.Height)
        self.setMaximumSize(self.Width,self.Height)
        self.setMinimumSize(self.Width,self.Height)

    def setIcon基于SSM的自习室预约管理系统

基于SSM框架图书馆预约占座系统的设计与实现(附源码论文)

基于SSM框架图书馆预约占座系统的设计与实现(附源码论文)

基于Springboot实现共享自习室管理系统

基于Android自习室占座座位管理系统

计算机毕业设计ssm图书馆座位预约管理系统Java开发springspringmvcmybatiseasyui