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 onCellChoosen(self, evt):
     if evt.GetCol() == 4:
         # 修改事件
         self.userIdInput.SetValue(self.grid.GetCellValue(evt.GetRow(), 0))
         self.userNameInput.SetValue(self.grid.GetCellValue(evt.GetRow(), 1))
         items = self.userGroupDropDown.GetItems()
         userGroupName = self.grid.GetCellValue(evt.GetRow(), 2)
         if userGroupName in items:
             self.userGroupDropDown.SetStringSelection(userGroupName)
         self.userDescInput.SetValue(self.grid.GetCellValue(evt.GetRow(), 3))
         self.modifyGroupBtn.Show()
         self.vBox.Layout()
     elif evt.GetCol() == 5:
         # 删除事件
         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 = UserController()
             result = controller.deleteUser(int(self.grid.GetCellValue(evt.GetRow(), 0)))
             if result:
                 wx.MessageBox(u'删除成功')
                 self.refreshGrid()
             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 onCreate(self, evt):
        if self.userNameInput.GetValue().strip() == '':
            wx.MessageBox(u'员工名不能为空')
            return

        controller = UserController()
        newUser = User(self.userNameInput.GetValue(),
                       self.groupInnerMap.get(self.userGroupDropDown.GetSelection(), Group(groupId=0)).groupId,
                       self.userDescInput.GetValue())
        eid = controller.createUser(newUser)
        if eid == -1:
            wx.MessageBox(u'创建用户失败')
            return

        newUser.userId = eid
        self.insertSingleUserIntoGrid(newUser)
        self.userNameInput.Clear()
        self.userGroupDropDown.SetSelection(-1)
    def onModifyGroup(self, evt):
        dlg = wx.MessageDialog(None, u'确认要修改员工 [' + self.userNameInput.GetValue().strip() + u'] 吗?',
                               'MessageDialog', wx.OK | wx.CANCEL)
        result = dlg.ShowModal()
        if result == wx.ID_OK:
            # 确认修改
            groupId = self.groupInnerMap.get(self.userGroupDropDown.GetSelection(), Group(groupId=0)).groupId
            controller = UserController()
            result = controller.editUser(int(self.userIdInput.GetValue()),
                                         self.userNameInput.GetValue().strip(),
                                         groupId,
                                         self.userDescInput.GetValue().strip())
            if result:
                wx.MessageBox(u'修改成功')
                self.refreshGrid()

            else:
                wx.MessageBox(u'修改失败')
        self.resetModify()
        dlg.Destroy()