def onCellChoosen(self, evt):
        if evt.GetCol() == 5:
            # 修改事件
            self.groupIdInput.SetValue(self.grid.GetCellValue(evt.GetRow(), 0))
            self.groupNameInput.SetValue(self.grid.GetCellValue(evt.GetRow(), 1))
            self.groupMemoInput.SetValue(self.grid.GetCellValue(evt.GetRow(), 2))
            self.workingHourInput.SetValue(self.grid.GetCellValue(evt.GetRow(), 3))
            self.workLoadInput.SetValue(self.grid.GetCellValue(evt.GetRow(), 4))
            self.modifyGroupBtn.Show()
            self.vBox.Layout()
            # TODO 高亮编辑区
        elif evt.GetCol() == 6:
            # 删除事件
            # wx.MessageBox(str(self.grid.GetCellValue(evt.GetRow(), 0)))
            dlg = wx.MessageDialog(None, u'确认要删除班组 [' + self.grid.GetCellValue(evt.GetRow(), 1) + u'] 吗?',
                                   'MessageDialog', wx.OK | wx.CANCEL)
            result = dlg.ShowModal()
            if result == wx.ID_OK:
                # 确认删除
                controller = GroupController()
                result = controller.deleteGroup(int(self.grid.GetCellValue(evt.GetRow(), 0)))
                if result:
                    userController = UserController()
                    userController.removeGroup(int(self.grid.GetCellValue(evt.GetRow(), 0)))
                    self.grid.DeleteRows(pos=evt.GetRow())

                if result:
                    wx.MessageBox(u'删除成功')
                else:
                    wx.MessageBox(u'删除失败')
            dlg.Destroy()
    def displayTodayData(self):
        gridSizer = wx.GridBagSizer(4, 4)
        self.grid = wx.grid.Grid(self)
        self.grid.CreateGrid(0, 6)
        self.grid.SetColLabelValue(0, u'员工编号')
        self.grid.SetColLabelValue(1, u'员工名')
        self.grid.SetColLabelValue(2, u'所属班组')
        self.grid.SetColLabelValue(3, u'备注')
        self.grid.SetColLabelValue(4, u'修改操作')
        self.grid.SetColLabelValue(5, u'删除操作')
        self.grid.HideCol(0)
        self.grid.HideCol(4)
        self.grid.HideCol(5)
        self.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK, self.onCellChoosen, self.grid)
        controller = UserController()
        users = controller.getAllUser()
        groupController = GroupController()

        rows = list(
            map(lambda x: [x.userId, x.userName, groupController.getGroupName(x.userGroup), x.userDesc], users))
        self.updateGrid(rows)
        self.grid.AutoSize()
        gridSizer.Add(self.grid, pos=(1, 1), span=(1, 1), flag=wx.EXPAND | wx.TOP | wx.RIGHT, border=15)

        self.vBox.Add(gridSizer, wx.ALIGN_BOTTOM | wx.ALIGN_LEFT, 10)
 def refreshGrid(self):
     controller = UserController()
     users = controller.getAllUser()
     groupController = GroupController()
     rows = list(
         map(lambda x: [x.userId, x.userName, groupController.getGroupName(x.userGroup), x.userDesc], users))
     self.updateGrid(rows)
     self.grid.AutoSize()
 def insertSingleUserIntoGrid(self, user):
     self.grid.InsertRows(0, 1)
     self.grid.SetCellValue(0, 0, str(user.userId))
     self.grid.SetCellValue(0, 1, user.userName)
     groupController = GroupController()
     self.grid.SetCellValue(0, 2, groupController.getGroupName(user.userGroup))
     self.grid.SetCellValue(0, 3, user.userDesc)
     self.grid.SetCellValue(0, 4, u'修改')
     self.grid.SetCellValue(0, 5, u'删除')
     self.grid.AutoSize()
     self.vBox.Layout()
 def onCreate(self, evt):
     newGroup = Group(self.groupNameInput.GetValue().strip(), self.groupMemoInput.GetValue().strip(),
                      self.workingHourInput.GetValue().strip(), self.workLoadInput.GetValue().strip())
     if self.validateGroup(newGroup):
         controller = GroupController()
         eid = controller.createGroup(newGroup)
         if eid == -1:
             wx.MessageBox(u'创建班组失败')
             return
         newGroup.groupId = eid
         self.insertSingleUserIntoGrid(newGroup)
         self.groupNameInput.Clear()
         self.groupMemoInput.Clear()
         self.workingHourInput.Clear()
         self.workLoadInput.Clear()
    def onModifyGroup(self, evt):
        if self.validateGroup(Group(self.groupNameInput.GetValue().strip(), self.groupMemoInput.GetValue().strip(),
                                    self.workingHourInput.GetValue().strip())):
            dlg = wx.MessageDialog(None, u'确认要修改班组 [' + self.groupNameInput.GetValue().strip() + u'] 吗?',
                                   'MessageDialog', wx.OK | wx.CANCEL)
            result = dlg.ShowModal()
            if result == wx.ID_OK:
                # 确认修改
                controller = GroupController()
                result = controller.editGroup(int(self.groupIdInput.GetValue()),
                                              self.groupNameInput.GetValue().strip(),
                                              self.groupMemoInput.GetValue().strip(),
                                              self.workingHourInput.GetValue().strip(),
                                              self.workLoadInput.GetValue().strip())
                if result:
                    wx.MessageBox(u'修改成功')
                    self.refreshGrid()

                else:
                    wx.MessageBox(u'修改失败')
            self.resetModify()
            dlg.Destroy()
    def displayTodayData(self):
        gridSizer = wx.GridBagSizer(4, 4)
        self.grid = wx.grid.Grid(self)
        self.grid.CreateGrid(0, 7)
        self.grid.SetColLabelValue(0, u'班组编号')
        self.grid.SetColLabelValue(1, u'班组名')
        self.grid.SetColLabelValue(2, u'备注')
        self.grid.SetColLabelValue(3, u'每日工时')
        self.grid.SetColLabelValue(4, u'每日出勤人数')
        self.grid.SetColLabelValue(5, u'修改操作')
        self.grid.SetColLabelValue(6, u'删除操作')
        controller = GroupController()
        groups = controller.getAllGroup()
        self.updateGrid(list(map(lambda x: [str(x.groupId), x.groupName, x.groupDesc, str(x.workHour), str(x.workLoad)], groups)))
        # 编号用来进行组操作,不用显示
        self.grid.HideCol(0)
        self.grid.HideCol(5)
        self.grid.HideCol(6)
        self.grid.AutoSize()
        self.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK, self.onCellChoosen, self.grid)
        gridSizer.Add(self.grid, pos=(1, 1), span=(1, 1), flag=wx.EXPAND | wx.TOP | wx.RIGHT, border=15)

        self.vBox.Add(gridSizer, wx.ALIGN_BOTTOM | wx.ALIGN_LEFT, 10)
 def refreshGrid(self):
     controller = GroupController()
     groups = controller.getAllGroup()
     self.updateGrid(
         list(map(lambda x: [str(x.groupId), x.groupName, x.groupDesc, str(x.workHour), str(x.workLoad)], groups)))