コード例 #1
0
class EditRoomCellDialog(QDialog):
    def __init__(self, roomId):
        super(EditRoomCellDialog, self).__init__()
        self.init(roomId)
        self.loading()

    def init(self, roomId):
        self.initUI()
        self.initSQL()
        self.initOther()
        self.initInteraction()
        self.initValue(roomId)

    def initUI(self):
        self.ui = Ui_EditRoomCellDialog()
        self.ui.setupUi(self)

    def initSQL(self):
        self.SQLHelper = SQLHelper()

    def initOther(self):
        self.moveFlag = False

    def initValue(self, roomId):
        self.roomId = roomId

    def initInteraction(self):
        self.ui.cancel.clicked.connect(self.cancelClicked)
        self.ui.dialogNavClose.clicked.connect(self.dialogNavCloseClicked)
        self.ui.comfirm.clicked.connect(self.comfirmClicked)
        self.ui.nameLineEdit.returnPressed.connect(
            self.nameLineEditReturnPressed)

    def loading(self):
        self.loadingData()
        self.loadingData()

    def loadingData(self):
        if not self.roomId is None:
            room = self.SQLHelper.getRoomById(self.roomId)[0]
            self.ui.nameLineEdit.setText(room[1])

    def loadingFocus(self):
        self.ui.nameLineEdit.setFocus(True)

    def cancelClicked(self):
        self.SQLHelper.close()
        self.reject()

    def dialogNavCloseClicked(self):
        self.SQLHelper.close()
        self.reject()

    def comfirmClicked(self):

        name = self.ui.nameLineEdit.text()

        if name == '':
            dialog = MessageDialog("錯誤訊息", "請確認表單內容填寫完整")
            dialog.exec()
        else:
            if self.roomId is None:
                dialog = MessageDialog("提示訊息", "請確認是否新增該筆實習室資料")
                if dialog.exec():

                    if self.isDuplicatedRoom(name):
                        dialog = MessageDialog("錯誤訊息", "實習室名稱重複,請確認後重試")
                        dialog.exec()
                    else:
                        self.SQLHelper.newRoom(name)
                        self.SQLHelper.close()
                        self.accept()

            else:
                dialog = MessageDialog("提示訊息", "請確認是否修改該筆實習室資料")
                if dialog.exec():
                    if self.isDuplicatedRoom(name):
                        dialog = MessageDialog("錯誤訊息", "實習室名稱重複,請確認後重試")
                        dialog.exec()
                    else:
                        self.SQLHelper.updateRoomById(self.roomId, name)
                        self.SQLHelper.close()
                        self.accept()

    def nameLineEditReturnPressed(self):
        self.comfirmClicked()

    def isDuplicatedRoom(self, roomName):
        rooms = self.SQLHelper.getAllRoom()

        for room in rooms:
            if room[1] == roomName:
                return True

        return False

    def mousePressEvent(self, event):
        if event.button() == Qt.LeftButton:
            self.moveFlag = True
            self.movePosition = event.globalPos() - self.pos()
            self.setCursor(QCursor(Qt.OpenHandCursor))
            event.accept()

    def mouseMoveEvent(self, event):
        if Qt.LeftButton and self.moveFlag:
            self.move(event.globalPos() - self.movePosition)
            event.accept()

    def mouseReleaseEvent(self, event):
        self.moveFlag = False
        self.setCursor(Qt.ArrowCursor)
コード例 #2
0
class EditArrangementCellDialog(QDialog):
    def __init__(self, arrangementId):
        super(EditArrangementCellDialog, self).__init__()
        self.init()
        self.loading(arrangementId)

    def init(self):
        self.initUI()
        self.initSQL()
        self.initOther()
        self.initInteraction()

    def initUI(self):
        self.ui = Ui_EditArrangementCellDialog()
        self.ui.setupUi(self)

    def initSQL(self):
        self.SQLHelper = SQLHelper()

    def initOther(self):
        self.moveFlag = False

    def initInteraction(self):
        self.ui.cancel.clicked.connect(self.cancelClicked)
        self.ui.dialogNavClose.clicked.connect(self.dialogNavCloseClicked)
        self.ui.comfirm.clicked.connect(self.comfirmClicked)

    def loading(self, arrangementId):
        self.loadingWeek()
        self.loadingShift()
        self.loadingRoom()
        self.loadingPeriod()
        self.loadingStaff()
        self.loadingArrangement(arrangementId)

    def loadingWeek(self):
        result = [["星期一", 0], ["星期二", 1], ["星期三", 2], ["星期四", 3], ["星期五", 4],
                  ["星期六", 5], ["星期日", 6]]
        self.ui.loadingWeek(result)

    def loadingShift(self):
        shifts = self.SQLHelper.getAllShift()
        result = []

        for shift in shifts:
            result.append([shift[1], shift[0]])

        self.ui.loadingShift(result)

    def loadingRoom(self):
        rooms = self.SQLHelper.getAllRoom()
        result = []

        for room in rooms:
            result.append([room[1], room[0]])

        self.ui.loadingRoom(result)

    def loadingPeriod(self):
        periods = self.SQLHelper.getPeriodNotVacation()
        result = []

        for period in periods:
            result.append([period[1], period[0]])

        self.ui.loadingPeriod(result)

    def loadingStaff(self):
        staffs = self.SQLHelper.getAllStaff()
        result = []

        for staff in staffs:
            result.append([f'{staff[0]:03d}', staff[2], staff[0]])

        self.ui.loadingStaff(result)

    def loadingArrangement(self, arrangementId):
        self.arrangementId = arrangementId
        if not arrangementId is None:
            arrangement = self.SQLHelper.getArrangementDetailById(
                arrangementId)[0]

            weekTrans = {
                0: "星期一",
                1: "星期二",
                2: "星期三",
                3: "星期四",
                4: "星期五",
                5: "星期六",
                6: "星期日"
            }

            self.ui.weekSelection.setCurrentText(weekTrans[arrangement[3]])
            self.ui.shiftSelection.setCurrentText(arrangement[5])
            self.ui.roomSelection.setCurrentText(arrangement[7])
            self.ui.periodSelection.setCurrentText(arrangement[9])
            self.ui.staffSelection.setCurrentText(
                f'{arrangement[1]:03d} {arrangement[2]}')

    def cancelClicked(self):
        self.SQLHelper.close()
        self.reject()

    def dialogNavCloseClicked(self):
        self.SQLHelper.close()
        self.reject()

    def comfirmClicked(self):

        week = self.ui.weekSelection.currentData(Qt.UserRole)
        shiftId = self.ui.shiftSelection.currentData(Qt.UserRole)
        roomId = self.ui.roomSelection.currentData(Qt.UserRole)
        periodId = self.ui.periodSelection.currentData(Qt.UserRole)
        staffId = self.ui.staffSelection.currentData(Qt.UserRole)

        if self.arrangementId is None:
            dialog = MessageDialog("提示訊息", "請確認是否新增該筆排班資料")
            if dialog.exec():
                self.SQLHelper.newArrangement(staffId, week, shiftId, roomId,
                                              periodId)
                self.accept()
        else:
            dialog = MessageDialog("提示訊息", "請確認是否修改該筆排班資料")
            if dialog.exec():
                self.SQLHelper.updateArrangementById(self.arrangementId,
                                                     staffId, week, shiftId,
                                                     roomId, periodId)
                self.accept()

    def mousePressEvent(self, event):
        if event.button() == Qt.LeftButton:
            self.moveFlag = True
            self.movePosition = event.globalPos() - self.pos()
            self.setCursor(QCursor(Qt.OpenHandCursor))
            event.accept()

    def mouseMoveEvent(self, event):
        if Qt.LeftButton and self.moveFlag:
            self.move(event.globalPos() - self.movePosition)
            event.accept()

    def mouseReleaseEvent(self, event):
        self.moveFlag = False
        self.setCursor(Qt.ArrowCursor)
コード例 #3
0
class EditTodayScheduleCellDialog(QDialog):
    def __init__(self, scheduleId):
        super(EditTodayScheduleCellDialog, self).__init__()
        self.init()
        self.loading(scheduleId)

    def init(self):
        self.initUI()
        self.initSQL()
        self.initOther()
        self.initInteraction()

    def initUI(self):
        self.ui = Ui_EditTodayScheduleCellDialog()
        self.ui.setupUi(self)

    def initSQL(self):
        self.SQLHelper = SQLHelper()

    def initOther(self):
        self.moveFlag = False

    def initInteraction(self):
        self.ui.cancel.clicked.connect(self.cancelClicked)
        self.ui.dialogNavClose.clicked.connect(self.dialogNavCloseClicked)
        self.ui.comfirm.clicked.connect(self.comfirmClicked)

    def loading(self, scheduleId):
        self.loadingShift()
        self.loadingRoom()
        self.loadingStaff()
        self.loadingSchedule(scheduleId)

    def loadingShift(self):
        shifts = self.SQLHelper.getAllShift()
        result = []

        for shift in shifts:
            result.append([shift[1], shift[0]])

        self.ui.loadingShift(result)

    def loadingRoom(self):
        rooms = self.SQLHelper.getAllRoom()
        result = []

        for room in rooms:
            result.append([room[1], room[0]])

        self.ui.loadingRoom(result)

    def loadingStaff(self):
        staffs = self.SQLHelper.getAllStaff()
        result = []

        for staff in staffs:
            result.append([f'{staff[0]:03d}', staff[2], staff[0]])

        self.ui.loadingStaff(result)

    def loadingSchedule(self, scheduleId: int):
        self.scheduleId = scheduleId
        if not scheduleId is None:

            schedule = self.SQLHelper.getScheduleDetailById(scheduleId)[0]

            self.ui.shiftSelection.setCurrentText(schedule[5])
            self.ui.roomSelection.setCurrentText(schedule[7])
            self.ui.staffSelection.setCurrentText(
                f'{schedule[1]:03d} {schedule[2]}')

    def cancelClicked(self):
        self.SQLHelper.close()
        self.reject()

    def dialogNavCloseClicked(self):
        self.SQLHelper.close()
        self.reject()

    def comfirmClicked(self):

        shiftId = self.ui.shiftSelection.currentData(Qt.UserRole)
        roomId = self.ui.roomSelection.currentData(Qt.UserRole)
        staffId = self.ui.staffSelection.currentData(Qt.UserRole)
        date = datetime.now().strftime("%Y-%m-%d")

        if self.scheduleId is None:
            dialog = MessageDialog("提示訊息", "請確認是否新增該筆排班資料")
            if dialog.exec():
                self.SQLHelper.newSchedule(date, staffId, shiftId, roomId)
                self.accept()
        else:
            dialog = MessageDialog("提示訊息", "請確認是否修改該筆排班資料")
            if dialog.exec():
                self.SQLHelper.updateScheduleById(staffId, shiftId, roomId,
                                                  self.scheduleId)
                self.accept()

    def mousePressEvent(self, event):
        if event.button() == Qt.LeftButton:
            self.moveFlag = True
            self.movePosition = event.globalPos() - self.pos()
            self.setCursor(QCursor(Qt.OpenHandCursor))
            event.accept()

    def mouseMoveEvent(self, event):
        if Qt.LeftButton and self.moveFlag:
            self.move(event.globalPos() - self.movePosition)
            event.accept()

    def mouseReleaseEvent(self, event):
        self.moveFlag = False
        self.setCursor(Qt.ArrowCursor)
コード例 #4
0
class EditRoomDialog(QDialog):
    def __init__(self):
        super(EditRoomDialog, self).__init__()
        self.init()
        self.loading()

    def init(self):
        self.initUI()
        self.initSQL()
        self.initOther()
        self.initInteraction()

    def initUI(self):
        self.ui = Ui_EditRoomDialog()
        self.ui.setupUi(self)

    def initSQL(self):
        self.SQLHelper = SQLHelper()

    def initOther(self):
        self.moveFlag = False

    def initInteraction(self):
        self.ui.cancel.clicked.connect(self.cancelClicked)
        self.ui.dialogNavClose.clicked.connect(self.dialogNavCloseClicked)
        self.ui.delete.clicked.connect(self.deleteClicked)
        self.ui.edit.clicked.connect(self.editClicked)
        self.ui.add.clicked.connect(self.addClicked)

    def loading(self):
        self.loadingRoom()

    def loadingRoom(self):
        rooms = self.SQLHelper.getAllRoom()

        self.ui.loadingList(rooms)

    def cancelClicked(self):
        self.SQLHelper.close()
        self.reject()

    def dialogNavCloseClicked(self):
        self.SQLHelper.close()
        self.reject()

    def deleteClicked(self):
        if len(self.ui.listArea.selectedItems()) == 0:
            dialog = MessageDialog("錯誤訊息", "請先選擇項目後再進行相關操作")
            dialog.exec()
        else:
            dialog = MessageDialog("提示訊息", "請確認是否刪除該項實習室資料及其關聯的所有班表資訊")
            if dialog.exec():
                roomId = self.ui.listArea.selectedItems()[0].data(
                    0, Qt.UserRole)
                self.SQLHelper.delRoomById(roomId)
                self.loadingRoom()

    def editClicked(self):
        if len(self.ui.listArea.selectedItems()) == 0:
            dialog = MessageDialog("錯誤訊息", "請先選擇項目後再進行相關操作")
            dialog.exec()
        else:
            roomId = self.ui.listArea.selectedItems()[0].data(0, Qt.UserRole)
            dialog = EditRoomCellDialog(roomId)
            if dialog.exec():
                self.loadingRoom()

    def addClicked(self):
        dialog = EditRoomCellDialog(None)
        if dialog.exec():
            self.loadingRoom()

    def mousePressEvent(self, event):
        if event.button() == Qt.LeftButton:
            self.moveFlag = True
            self.movePosition = event.globalPos() - self.pos()
            self.setCursor(QCursor(Qt.OpenHandCursor))
            event.accept()

    def mouseMoveEvent(self, event):
        if Qt.LeftButton and self.moveFlag:
            self.move(event.globalPos() - self.movePosition)
            event.accept()

    def mouseReleaseEvent(self, event):
        self.moveFlag = False
        self.setCursor(Qt.ArrowCursor)