예제 #1
0
def edit_student(request):
    if request.method == "GET":
        id = request.GET.get("id")
        obj = SQLHelper()
        class_list = obj.get_list("select id,name from class", [])
        student = obj.get_one(
            "select student.id,student.sname,student.cid,class.name from student left join class on  student.cid = class.id where student.id = %s",
            id)
        obj.close()
        return render(request, "edit_student.html", {
            "student": student,
            "class_list": class_list
        })
    else:
        id = request.POST.get("id")
        sname = request.POST.get("sname")
        cid = request.POST.get("class_id")
        obj = SQLHelper()
        obj.modify("update student set sname = %s,cid = %s where id = %s", [
            sname,
            cid,
            id,
        ])
        obj.close()
        return redirect("/students/")
예제 #2
0
def deleteTearcher(request):
    tid = request.GET.get('tid')
    obj = SQLHelper()
    obj.modify('delete from tearcher  where tid = %s', tid)
    obj.modify('delete from tearch2class  where tid = %s', tid)
    obj.close()
    return redirect('/tearchers/')
예제 #3
0
def tearchers(request):
    obj = SQLHelper()
    tearcher_list = obj.get_list(
        '''
        SELECT tearcher.tid,tearcher.tname,tearch2class.cid,class.name from tearcher  
        LEFT JOIN tearch2class on tearcher.tid = tearch2class.tid    
        LEFT JOIN class ON class.id = tearch2class.cid;
    ''', [])
    result = {}
    for tearcher in tearcher_list:
        tid = tearcher['tid']
        if tid in result:
            result[tid]['classes'].append({
                'cid': tearcher['cid'],
                'name': tearcher['name']
            })
        else:
            result[tid] = {
                'tid': tearcher['tid'],
                'tname': tearcher['tname'],
                'classes': [{
                    'cid': tearcher['cid'],
                    'name': tearcher['name']
                }],
            }
    class_list = obj.get_list('select * from class')
    obj.close()
    return render(request, 'tearchers.html', {
        'result': result.values(),
        "class_list": class_list
    })
예제 #4
0
def deleteStudent(request):
    id = request.GET.get("id")

    obj = SQLHelper()
    obj.modify("delete from student  where id = %s", id)
    obj.close()

    return redirect("/students/")
예제 #5
0
def delete_class(request):
    id = request.GET.get('id')
    # ###删除班级老师对应表
    # cursor.execute('delete from tearch2class  where cid = %s', id)
    obj = SQLHelper()
    obj.modify("delete from class where id=%s", id)
    obj.close()
    return redirect('/class/')
예제 #6
0
def students(request):
    obj = SQLHelper()
    student_list = obj.get_list(
        "select student.id,student.sname,class.name,student.cid from student left join class on student.cid = class.id",
        [])
    class_list = obj.get_list('select id,name from class', [])
    obj.close()
    return render(request, "students.html", {
        "student_list": student_list,
        'class_list': class_list
    })
예제 #7
0
class ThreadInitDB(QThread):

    result = pyqtSignal(int)

    def __init__(self):
        super(ThreadInitDB, self).__init__()

    def run(self):
        self.SQLHelper = SQLHelper()
        if not self.SQLHelper.isDBFailed():
            self.syncSchedule()
            self.SQLHelper.close()
            self.result.emit(0)
        else:
            self.result.emit(1)

    def syncSchedule(self):
        try:
            lastSyncedDate = datetime.strptime(
                self.SQLHelper.getSyncSchedule(), "%Y-%m-%d")
        except:
            lastSyncedDate = None

        now = datetime.now()

        if lastSyncedDate is None:
            period = self.SQLHelper.getPeriodByDate(now.strftime("%Y-%m-%d"))
            if len(period) != 0:
                periodId = period[0][0]
                weekday = now.weekday()
                arrangements = self.SQLHelper.getArrangementByPeriodAndWeek(
                    periodId, weekday)
                self.SQLHelper.newSchedules(now.strftime("%Y-%m-%d"),
                                            arrangements)

            self.SQLHelper.updateSyncSchedule(now.strftime("%Y-%m-%d"))
        else:
            while lastSyncedDate.date() != now.date():
                lastSyncedDate += timedelta(days=1)

                period = self.SQLHelper.getPeriodByDate(
                    lastSyncedDate.strftime("%Y-%m-%d"))
                if len(period) != 0:
                    periodId = period[0][0]
                    weekday = now.weekday()
                    arrangements = self.SQLHelper.getArrangementByPeriodAndWeek(
                        periodId, weekday)
                    self.SQLHelper.newSchedules(
                        lastSyncedDate.strftime("%Y-%m-%d"), arrangements)

                self.SQLHelper.updateSyncSchedule(
                    lastSyncedDate.strftime("%Y-%m-%d"))
예제 #8
0
def add_class(request):
    if request.method == 'GET':
        return render(request, 'addclass.html')
    else:
        v = request.POST.get('name')
        if len(v) > 0:
            obj = SQLHelper()
            obj.modify("insert into class(name) values(%s)", [
                v,
            ])
            obj.close()
            return redirect('/class/')
        else:
            return render(request, 'addclass.html', {"msg": "班级名称不能为空"})
예제 #9
0
def addStudent(request):
    if request.method == "GET":
        obj = SQLHelper()
        classes = obj.get_list("select id,name from class")
        obj.close()
        return render(request, "addStudent.html", {'classes': classes})
    else:

        class_id = request.POST.get("class_id")
        sname = request.POST.get("sname")

        obj = SQLHelper()
        obj.modify("insert into student( sname, cid) value (%s,%s)",
                   [sname, class_id])
        obj.close()
        return redirect("/students/")
예제 #10
0
def edit_class(request):
    if request.method == "GET":
        id = request.GET.get("id")
        obj = SQLHelper()
        result = obj.get_one("select id,name from class where id = %s", id)
        obj.close()
        return render(request, 'edit_class.html', {"result": result})
    else:
        id = request.GET.get("id")
        # id = request.POST.get("id")
        name = request.POST.get("name")
        obj = SQLHelper()
        obj.modify("update class set name = %s where id = %s", [
            name,
            id,
        ])
        obj.close()
        return redirect("/class/")
예제 #11
0
def editTearcher(request):

    if request.method == 'GET':
        tid = request.GET.get('tid')
        obj = SQLHelper()
        tearcher_info = obj.get_one(
            'select tid,tname from tearcher where tid = %s', [tid])
        tearcher_class_list = obj.get_list(
            'select cid from tearch2class where tearch2class.tid = %s', [
                tid,
            ])
        class_list = obj.get_list('select id,name from class')
        obj.close()
        temp = []
        for i in tearcher_class_list:
            temp.append(i['cid'])
        return render(
            request, 'edit_tearcher.html', {
                'info': tearcher_info,
                'tearcher_class_list': temp,
                'class_list': class_list
            })
    else:
        tid = request.GET.get('tid')
        class_ids = request.POST.getlist('class_ids')
        tname = request.POST.get('tname')
        #更新老师表
        obj = SQLHelper()
        obj.modify('update tearcher set tname=%s where tid = %s', [tname, tid])
        #更细老师班级关系表
        # 方案一:先删除老师和班级的对应关系删除,之后再做添加
        obj.modify('delete from tearch2class where tid = %s', [tid])
        sql_args = []
        for cid in class_ids:
            temp = (tid, cid)
            sql_args.append(temp)
        obj.multiple_modify(
            'insert into tearch2class(tid, cid) values (%s,%s)', sql_args)
        obj.close()
        # 方案二:把新的班级数据和老的数据做对比进行删除和增加
        return redirect('/tearchers/')
예제 #12
0
def addtearchers(request):
    if request.method == 'GET':
        obj = SQLHelper()
        class_list = obj.get_list('select * from class')
        obj.close()
        return render(request, 'addTearcher.html', {"class_list": class_list})
    else:
        tname = request.POST.get('tname')
        clds = request.POST.getlist('class_ids')
        obj = SQLHelper()
        #老师表中添加数据 #获取老师id
        tearcher_id = obj.create('insert into tearcher(tname) values (%s)',
                                 [tname])
        #老师班级表中插入数据
        sql_args = []
        for cid in clds:
            temp = (tearcher_id, cid)
            sql_args.append(temp)
        obj.multiple_modify(
            'insert into tearch2class(tid, cid) values (%s,%s)', sql_args)
        obj.close()

        return redirect('/tearchers/')
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)
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)
예제 #15
0
class EditTodayScheduleDialog(QDialog):
    def __init__(self):
        super(EditTodayScheduleDialog, self).__init__()
        self.init()
        self.loading()

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

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

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

    def initOther(self):
        self.moveFlag = False
        self.ShiftHelper = ShiftHelper()

    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.loadingTodaySchedule()

    def loadingTodaySchedule(self):
        now = datetime.now()

        schedules = self.SQLHelper.getScheduleDetailByDate(
            now.strftime("%Y-%m-%d"))
        result = []

        for schedule in schedules:
            scheduleStatus = self.ShiftHelper.getShiftStatus(
                schedule[4], schedule[3], schedule[8], schedule[9])
            result.append([
                schedule[0], f'{schedule[1]:03d}', schedule[2], schedule[5],
                schedule[7], schedule[8], schedule[9], scheduleStatus
            ])

        self.ui.loadingList(result)

    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():
                scheduleId = self.ui.listArea.selectedItems()[0].data(
                    0, Qt.UserRole)
                self.SQLHelper.delScheduleById(scheduleId)

                self.loadingTodaySchedule()

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

    def addClicked(self):
        dialog = EditTodayScheduleCellDialog(None)
        if dialog.exec():
            self.loadingTodaySchedule()

    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)
class ImportStaffDialog(QDialog):

    list = []

    def __init__(self):
        super(ImportStaffDialog, self).__init__()
        self.init()

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

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

    def initInteraction(self):
        self.ui.dialogNavClose.clicked.connect(self.dialogNavCloseClicked)
        self.ui.cancel.clicked.connect(self.cancelCliecked)
        self.ui.pickFile.clicked.connect(self.pickFileClicked)
        self.ui.comfirm.clicked.connect(self.comfirmClicked)

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

    def initOther(self):
        self.moveFlag = False

    def pickFileClicked(self):
        fileUrls = QFileDialog.getOpenFileUrl(self, "選取工讀生資料",
                                              QUrl(os.getcwd()),
                                              "Excel檔案 (*.xlsx)")
        fileUrl = fileUrls[0].toLocalFile()

        if fileUrl != "":
            excel = pandas.read_excel(fileUrl,
                                      sheet_name=0,
                                      header=None,
                                      converters={
                                          0: str,
                                          1: str,
                                          2: str
                                      })
            self.list = excel.values.tolist()

            self.ui.loadingList(self.list)

    def comfirmClicked(self):
        self.SQLHelper.delAllStaff()
        self.SQLHelper.newAllStaff(self.list)
        self.SQLHelper.close()
        self.accept()

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

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

    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)
예제 #17
0
def classes(request):
    obj = SQLHelper()
    class_list = obj.get_list("select id,name from class")
    obj.close()
    return render(request, 'classes.html', {"class_list": class_list})
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)
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)
class ImportArrangementDialog(QDialog):

    list = []

    def __init__(self):
        super(ImportArrangementDialog, self).__init__()
        self.init()
        self.loading()

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

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

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

        self.ui.periodSelection.currentTextChanged.connect(
            self.periodSelectionChanged)

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

    def initOther(self):
        self.moveFlag = False

    def loading(self):
        self.loadingPeriod()
        self.loadingDate()

    def loadingPeriod(self):
        periods = self.SQLHelper.getPeriodNotVacation()
        data = []
        for period in periods:
            data.append(period[1])
        self.ui.loadingPeriodSelection(data)

    def loadingDate(self):
        periodName = self.ui.periodSelection.currentText()
        period = self.SQLHelper.getPeriodByName(periodName)

        startDate = datetime.strptime(period[0][2], "%Y-%m-%d")
        start = QDate(startDate.year, startDate.month, startDate.day)

        endDate = datetime.strptime(period[0][3], "%Y-%m-%d")
        end = QDate(endDate.year, endDate.month, endDate.day)

        self.ui.loadingPeriodDate(start, end)

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

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

    def pickFileClicked(self):
        fileUrls = QFileDialog.getOpenFileUrl(self, "選取工讀生資料",
                                              QUrl(os.getcwd()),
                                              "Excel檔案 (*.xlsx)")
        fileUrl = fileUrls[0].toLocalFile()

        if fileUrl != "":
            excel = pandas.read_excel(fileUrl,
                                      sheet_name=0,
                                      header=None,
                                      converters={
                                          0: str,
                                          1: str,
                                          2: str,
                                          3: str
                                      })
            self.list = excel.values.tolist()

            self.ui.loadingList(self.list)

    def comfirmClicked(self):
        period = self.SQLHelper.getPeriodByName(
            self.ui.periodSelection.currentText())[0]

        start = self.ui.dateStart.date()
        end = self.ui.dateEnd.date()
        self.SQLHelper.updatePeriodStartAndEndById(
            f"{start.year():04d}-{start.month():02d}-{start.day():02d}",
            f"{end.year():04d}-{end.month():02d}-{end.day():02d}", period[0])

        data = []
        weekTrans = {
            "星期一": 0,
            "星期二": 1,
            "星期三": 2,
            "星期四": 3,
            "星期五": 4,
            "星期六": 5,
            "星期日": 6
        }
        for item in self.list:
            room = self.SQLHelper.getRoomByName(item[4])
            shift = self.SQLHelper.getShiftByName(item[3])
            data.append([
                int(item[0]), weekTrans[item[2]], shift[0][0], room[0][0],
                period[0]
            ])
        self.SQLHelper.delArrangementByPeriod(period[0])
        self.SQLHelper.newArrangements(data)

        self.reloadTodaySchedules(period)

        self.SQLHelper.close()
        self.accept()

    def periodSelectionChanged(self, text):
        self.loadingDate()

    def setPeriodSelection(self, period: str):
        self.ui.periodSelection.setCurrentText(period)

    def reloadTodaySchedules(self, updatePeriod):

        now = datetime.now()
        todayPeriod = self.SQLHelper.getPeriodByDate(now.strftime("%Y-%m-%d"))

        if len(todayPeriod) != 0:
            todayPeriod = todayPeriod[0]

            if todayPeriod[0] == updatePeriod[0]:
                dialog = MessageDialog("提示訊息", "請問是否重新載入今日所有已執行及未執行之班表")
                if dialog.exec():
                    self.SQLHelper.delScheduleByDate(now.strftime("%Y-%m-%d"))
                    arrangements = self.SQLHelper.getArrangementByPeriodAndWeek(
                        todayPeriod[0], now.weekday())
                    self.SQLHelper.newSchedules(now.strftime("%Y-%m-%d"),
                                                arrangements)

    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)
예제 #21
0
class EditStaffDialog(QDialog):
    def __init__(self):
        super(EditStaffDialog, self).__init__()
        self.init()
        self.loading()

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

    def initUI(self):
        self.ui = Ui_EditStaffDialog()
        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.loadingStaff()

    def loadingStaff(self):
        staffs = self.SQLHelper.getAllStaff()

        result = []

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

        self.ui.loadingList(result)

    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():
                staffId = self.ui.listArea.selectedItems()[0].data(0, Qt.UserRole)
                self.SQLHelper.delStaffById(staffId)

                self.loadingStaff()

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

    def addClicked(self):

        dialog = EditStaffCellDialog(None)
        if dialog.exec():
            self.loadingStaff()




    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)
예제 #22
0
class EditShiftCellDialog(QDialog):
    def __init__(self, shiftId):
        super(EditShiftCellDialog, self).__init__()
        self.init(shiftId)
        self.loading()

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

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

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

    def initOther(self):
        self.moveFlag = False

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

    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)
        self.ui.hourLineEdit.returnPressed.connect(
            self.hourLineEditReturnPressed)
        self.ui.payHourLineEdit.returnPressed.connect(
            self.payHourLineEditReturnPressed)

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

    def loadingData(self):
        now = datetime.now()

        if not self.shiftId is None:
            shift = self.SQLHelper.getShiftById(self.shiftId)[0]

            shiftStartTime = datetime.strptime(shift[2], "%H:%M:%S")
            shiftEndTime = datetime.strptime(shift[3], "%H:%M:%S")

            self.ui.nameLineEdit.setText(shift[1])
            self.ui.hourLineEdit.setText(str(shift[4]))
            self.ui.timeStart.setTime(
                QTime(shiftStartTime.hour, shiftStartTime.minute,
                      shiftStartTime.second))
            self.ui.timeEnd.setTime(
                QTime(shiftEndTime.hour, shiftEndTime.minute,
                      shiftEndTime.second))
            self.ui.payHourLineEdit.setText(str(shift[5]))
        else:
            self.ui.timeStart.setTime(QTime(now.hour, now.minute, now.second))
            self.ui.timeEnd.setTime(QTime(now.hour, now.minute, now.second))

    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):
        startTime = self.ui.timeStart.time()
        endTime = self.ui.timeEnd.time()

        name = self.ui.nameLineEdit.text()
        start = f'{startTime.hour():02d}:{startTime.minute():02d}:{startTime.second():02d}'
        end = f'{endTime.hour():02d}:{endTime.minute():02d}:{endTime.second():02d}'
        hour = self.ui.hourLineEdit.text()
        payHour = self.ui.payHourLineEdit.text()

        if name == '' or hour == '' or payHour == '':
            dialog = MessageDialog("錯誤訊息", "請確認表單內容填寫完整")
            dialog.exec()
        else:
            if self.shiftId is None:
                dialog = MessageDialog("提示訊息", "請確認是否新增該筆班別資料")
                if dialog.exec():
                    self.SQLHelper.newShift(name, start, end, float(hour),
                                            float(payHour))
                    self.accept()

            else:
                dialog = MessageDialog("提示訊息", "請確認是否修改該筆班別資料")
                if dialog.exec():
                    self.SQLHelper.updateShiftById(self.shiftId, name, start,
                                                   end, float(hour),
                                                   float(payHour))
                    self.accept()

    def nameLineEditReturnPressed(self):
        self.ui.timeStart.setFocus(True)

    def hourLineEditReturnPressed(self):
        self.ui.payHourLineEdit.setFocus(True)

    def payHourLineEditReturnPressed(self):
        self.comfirmClicked()

    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)
예제 #23
0
class EditArrangementDialog(QDialog):
    def __init__(self):
        super(EditArrangementDialog, self).__init__()
        self.init()
        self.loading()

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

    def initUI(self):
        self.ui = Ui_EditArrangementDialog()
        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.loadingArrangement()

    def loadingArrangement(self):
        arrangements = self.SQLHelper.getAllArrangementDetail()

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

        for arrangement in arrangements:
            result.append([
                arrangement[0], weekTrans[arrangement[3]],
                f'{arrangement[1]:03d}', arrangement[2], arrangement[5],
                arrangement[7], arrangement[9]
            ])

        self.ui.loadingList(result)

    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():
                arrangementId = self.ui.listArea.selectedItems()[0].data(
                    0, Qt.UserRole)
                self.SQLHelper.delArrangementById(arrangementId)

                self.loadingArrangement()

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

    def addClicked(self):
        dialog = EditArrangementCellDialog(None)
        if dialog.exec():
            self.loadingArrangement()

    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)
class EditVacationDialog(QDialog):
    def __init__(self):
        super(EditVacationDialog, self).__init__()
        self.init()
        self.loading()

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

    def initUI(self):
        self.ui = Ui_EditVacationDialog()
        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.loadingVacation()

    def loadingVacation(self):
        vacations = self.SQLHelper.getPeriodVacation()

        result = []
        for vacation in vacations:
            result.append(vacation[0:-1])

        self.ui.loadingList(result)


    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():
                periodId = self.ui.listArea.selectedItems()[0].data(0, Qt.UserRole)
                self.SQLHelper.delPeriodById(periodId)

                self.loadingVacation()

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

    def addClicked(self):
        dialog = EditVacationCellDialog(None)
        if dialog.exec():
            self.loadingVacation()




    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)
class EditStaffCellDialog(QDialog):
    def __init__(self, staffId):
        super(EditStaffCellDialog, self).__init__()
        self.init(staffId)
        self.loading()

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

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

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

    def initOther(self):
        self.moveFlag = False

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

    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):
        if not self.staffId is None:
            staff = self.SQLHelper.getStaffById(self.staffId)[0]

            self.ui.staffNumLineEdit.setText(str(staff[0]))
            self.ui.staffNumLineEdit.setEnabled(False)
            self.ui.stuNumLineEdit.setText(staff[1])
            self.ui.nameLineEdit.setText(staff[2])

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

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

    def comfirmClicked(self):

        staffNum = self.ui.staffNumLineEdit.text()
        stuNum = self.ui.stuNumLineEdit.text()
        name = self.ui.nameLineEdit.text()

        if staffNum == '' or stuNum == '' or name == '':
            dialog = MessageDialog("錯誤訊息", "請確認表單資料填寫完整")
            dialog.exec()
        else:
            staffNum = int(staffNum)
            if self.staffId is None:
                staffs = self.SQLHelper.getStaffById(staffNum)
                if len(staffs) != 0:
                    dialog = MessageDialog("錯誤訊息",
                                           f'已有工讀生編號{staffNum}號的工讀生,請查核後重試')
                    dialog.exec()
                else:
                    dialog = MessageDialog("提示訊息", "請確認是否新增工讀生")
                    if dialog.exec():
                        self.SQLHelper.newStaff(staffNum, stuNum, name)
                        self.accept()
            else:
                dialog = MessageDialog("提示訊息", "請確認是否修改工讀生")
                if dialog.exec():
                    self.SQLHelper.updateStaffById(staffNum, stuNum, name)
                    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)
class EditScheduleDialog(QDialog):
    def __init__(self):
        super(EditScheduleDialog, self).__init__()
        self.init()
        self.loading()

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

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

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

    def initOther(self):
        self.moveFlag = False
        self.ShiftHelper = ShiftHelper()

    def initInteraction(self):
        self.ui.dialogNavClose.clicked.connect(self.dialogNavCloseClicked)
        self.ui.cancel.clicked.connect(self.cancelClicked)
        self.ui.query.clicked.connect(self.queryClicked)
        self.ui.editOnTimeCheckIn.clicked.connect(
            self.editOnTimeCheckInClicked)
        self.ui.editOnTimeCheckOut.clicked.connect(
            self.editOnTimeCheckOutClicked)
        self.ui.editLate.clicked.connect(self.editLateClicked)
        self.ui.editExcused.clicked.connect(self.editExcusedClicked)
        self.ui.clearCheckIn.clicked.connect(self.clearCheckInClicked)
        self.ui.clearCheckOut.clicked.connect(self.clearCheckOutClicked)

    def loading(self):
        self.loadingDate()

    def loadingDate(self):
        now = datetime.now()

        self.ui.dateStart.setDate(QDate(now.year, now.month, now.day))
        self.ui.dateEnd.setDate(QDate(now.year, now.month, now.day))

    def query(self):
        startDate = self.ui.dateStart.date()
        endDate = self.ui.dateEnd.date()
        start = f'{startDate.year():04d}-{startDate.month():02d}-{startDate.day():02d}'
        end = f'{endDate.year():04d}-{endDate.month():02d}-{endDate.day():02d}'

        if datetime.strptime(start, "%Y-%m-%d") > datetime.strptime(
                end, "%Y-%m-%d"):
            dialog = MessageDialog("錯誤訊息", "查詢時間區間設定錯誤,請查核後重試")
            dialog.exec()
        else:
            schedules = self.SQLHelper.getScheduleDetailByDateInterval(
                start, end)

            result = []

            for schedule in schedules:
                scheduleStatus = self.ShiftHelper.getShiftStatus(
                    schedule[4], schedule[1], schedule[8], schedule[9])
                scheduleCheckIn = ''
                scheduleCheckOut = ''
                if not schedule[8] is None:
                    scheduleCheckIn = schedule[8]
                if not schedule[9] is None:
                    scheduleCheckOut = schedule[9]

                result.append([
                    schedule[0], f'{schedule[2]:03d}', schedule[3],
                    schedule[1], schedule[5], schedule[7], scheduleCheckIn,
                    scheduleCheckOut, scheduleStatus
                ])

            self.ui.loadingList(result)

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

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

    def queryClicked(self):
        self.query()

    def editOnTimeCheckInClicked(self):
        if len(self.ui.listArea.selectedItems()) != 0:
            scheduleId = self.ui.listArea.selectedItems()[0].data(
                0, Qt.UserRole)

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

            dialog = MessageDialog("提示訊息", "請確認是否將該筆資料之簽到時間設定為準時")
            if dialog.exec():
                onTimeCheckIn = datetime.strptime(
                    f'{schedule[1]} {schedule[6]}',
                    "%Y-%m-%d %H:%M:%S") - timedelta(seconds=1)

                self.SQLHelper.updateScheduleCheckInById(
                    onTimeCheckIn.strftime("%Y-%m-%d %H:%M:%S"), schedule[0])
                self.query()
        else:
            dialog = MessageDialog("錯誤訊息", "請先選擇項目後再執行操作")
            dialog.exec()

    def editOnTimeCheckOutClicked(self):

        if len(self.ui.listArea.selectedItems()) != 0:
            scheduleId = self.ui.listArea.selectedItems()[0].data(
                0, Qt.UserRole)

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

            if schedule[12] is None:
                dialog = MessageDialog("錯誤訊息", "無法設定無簽到記錄之項目,請先設定簽到記錄")
                dialog.exec()
            else:
                dialog = MessageDialog("提示訊息", "請確認是否將該筆資料之簽退時間設定為準時")
                if dialog.exec():
                    onTimeCheckIn = datetime.strptime(
                        f'{schedule[1]} {schedule[6]}', "%Y-%m-%d %H:%M:%S")
                    onTimeCheckOut = datetime.strptime(
                        f'{schedule[1]} {schedule[7]}', "%Y-%m-%d %H:%M:%S")

                    if onTimeCheckIn > onTimeCheckOut:
                        onTimeCheckOut += timedelta(days=1)

                    self.SQLHelper.updateScheduleCheckOutById(
                        onTimeCheckOut.strftime("%Y-%m-%d %H:%M:%S"),
                        schedule[0])
                    self.query()

        else:
            dialog = MessageDialog("錯誤訊息", "請先選擇項目後再執行操作")
            dialog.exec()

    def editLateClicked(self):
        if len(self.ui.listArea.selectedItems()) != 0:
            schedule = self.SQLHelper.getScheduleDetailWithShiftById(
                self.ui.listArea.selectedItems()[0].data(0, Qt.UserRole))[0]

            dialog = MessageDialog("提示訊息", "請確認是否將該筆資料設為遲到")
            if dialog.exec():
                lateCheckIn = datetime.strptime(f'{schedule[1]} {schedule[6]}',
                                                "%Y-%m-%d %H:%M:%S")

                self.SQLHelper.updateScheduleCheckInById(
                    lateCheckIn.strftime("%Y-%m-%d %H:%M:%S"), schedule[0])
                self.query()
        else:
            dialog = MessageDialog("錯誤訊息", "請先選擇項目後再執行操作")
            dialog.exec()

    def editExcusedClicked(self):
        if len(self.ui.listArea.selectedItems()) != 0:
            schedule = self.SQLHelper.getScheduleDetailWithShiftById(
                self.ui.listArea.selectedItems()[0].data(0, Qt.UserRole))[0]

            dialog = MessageDialog("提示訊息", "請確認是否將該筆資料設為早退")
            if dialog.exec():
                if schedule[12] is None:
                    dialog = MessageDialog("錯誤訊息", "無法設定無簽到記錄之項目,請先設定簽到記錄")
                    dialog.exec()
                else:
                    excusedCheckOut = datetime.strptime(
                        f'{schedule[1]} {schedule[7]}',
                        "%Y-%m-%d %H:%M:%S") - timedelta(seconds=1)

                    self.SQLHelper.updateScheduleCheckOutById(
                        excusedCheckOut.strftime("%Y-%m-%d %H:%M:%S"),
                        schedule[0])
                    self.query()
        else:
            dialog = MessageDialog("錯誤訊息", "請先選擇項目後再執行操作")
            dialog.exec()

    def clearCheckInClicked(self):
        if len(self.ui.listArea.selectedItems()) != 0:
            schedule = self.SQLHelper.getScheduleDetailWithShiftById(
                self.ui.listArea.selectedItems()[0].data(0, Qt.UserRole))[0]

            if not schedule[13] is None:
                dialog = MessageDialog("錯誤訊息", "無法清除有簽退紀錄之簽到記錄,請先清除簽退紀錄")
                dialog.exec()
            else:
                dialog = MessageDialog("提示訊息", "請確認是否清除簽到紀錄")
                if dialog.exec():
                    self.SQLHelper.updateScheduleCheckInNullById(schedule[0])
                    self.query()
        else:
            dialog = MessageDialog("錯誤訊息", "請先選擇項目後再執行操作")
            dialog.exec()

    def clearCheckOutClicked(self):
        if len(self.ui.listArea.selectedItems()) != 0:
            schedule = self.SQLHelper.getScheduleDetailWithShiftById(
                self.ui.listArea.selectedItems()[0].data(0, Qt.UserRole))[0]

            dialog = MessageDialog("提示訊息", "請確認是否清除簽退紀錄")
            if dialog.exec():
                self.SQLHelper.updateScheduleCheckOutNullById(schedule[0])
                self.query()

        else:
            dialog = MessageDialog("錯誤訊息", "請先選擇項目後再執行操作")
            dialog.exec()

    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)
class EditVacationCellDialog(QDialog):
    def __init__(self, periodId):
        super(EditVacationCellDialog, self).__init__()
        self.init(periodId)
        self.loading()

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

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

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

    def initOther(self):
        self.moveFlag = False

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

    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):
        if not self.periodId is None:
            period = self.SQLHelper.getPeriodById(self.periodId)[0]
            periodStartDate = datetime.strptime(period[2], "%Y-%m-%d")
            periodEndDate = datetime.strptime(period[3], "%Y-%m-%d")

            self.ui.nameLineEdit.setText(period[1])
            self.ui.dateStart.setDate(
                QDate(periodStartDate.year, periodStartDate.month,
                      periodStartDate.day))
            self.ui.dateEnd.setDate(
                QDate(periodEndDate.year, periodEndDate.month,
                      periodEndDate.day))

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

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

    def comfirmClicked(self):

        startDate = self.ui.dateStart.date()
        endDate = self.ui.dateEnd.date()

        name = self.ui.nameLineEdit.text().strip()
        start = f'{startDate.year():04d}-{startDate.month():02d}-{startDate.day():02d}'
        end = f'{endDate.year():04d}-{endDate.month():02d}-{endDate.day():02d}'

        if name == '':
            dialog = MessageDialog("錯誤訊息", "請確認表單內容填寫完整")
            dialog.exec()
        else:
            if self.periodId is None:
                dialog = MessageDialog("提示訊息", "請確認是否新增該筆假日項目")
                if dialog.exec():
                    self.SQLHelper.newPeriodVacation(name, start, end)
                    self.accept()
            else:
                dialog = MessageDialog("提示訊息", "請確認是否修改該筆假日項目")
                if dialog.exec():
                    self.SQLHelper.updatePeriodById(self.periodId, name, start,
                                                    end)
                    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)
예제 #28
0
class AuthDialog(QDialog):
    def __init__(self):
        super(AuthDialog, self).__init__()
        self.init()
        self.loading()

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

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

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

    def initOther(self):
        self.moveFlag = False

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

    def loading(self):
        self.loadingFocus()

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

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

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

    def comfirmClicked(self):
        password = self.ui.passwordLineEdit.text()
        hashPassword = HMACSHA256Helper.HMACSHA256Hash(password)
        sysPassword = self.SQLHelper.getPWD()

        if hashPassword == sysPassword:
            self.SQLHelper.close()
            self.accept()
        else:
            self.hide()
            dialog = MessageDialog("錯誤提示", "管理員密碼錯誤,請重試")
            dialog.exec()
            self.reject()

    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)
예제 #29
0
class CheckAuthDialog(QDialog):
    def __init__(self, staffNum):
        super(CheckAuthDialog, self).__init__()
        self.init(staffNum)
        self.loadingFocus()

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

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

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

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

    def initOther(self):
        self.moveFlag = False

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

    def loading(self):
        self.loadingFocus()

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

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

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

    def comfirmClicked(self):

        staff = self.SQLHelper.getStaffById(self.staffNum)[0]

        if self.ui.stuNumLineEdit.text() == staff[1]:
            self.accept()
        else:
            self.hide()
            dialog = MessageDialog("錯誤提示", "操作人員驗證錯誤,請重試")
            dialog.exec()
            self.reject()

    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)