def register(self):
     username = self.username_lineEdit.text()
     password = self.password_lineEdit.text()
     confirm = self.confirm_password_lineEdit.text()
     if '' in [username, password, confirm]:
         msg_box(self, '提示', '关键信息不能为空!')
         return
     db = DBHelp()
     count, res = db.query_super(table_name='user',
                                 column_name='username',
                                 condition=username)
     if count != 0:
         msg_box(self, '提示', '用户名已存在!')
         return
     if password != confirm:
         msg_box(self, '错误', '两次输入密码不一致!')
         return
     user_info = [
         get_uuid(), username,
         get_md5(password), 1,
         get_current_time(), 0,
         get_current_time()
     ]
     db.add_user(user_info)
     db.db_commit()
     db.instance = None
     del db
     msg_box(self, '提示', '注册成功!')
     self.close()
Example #2
0
 def add(self):
     book_name = self.book_name_lineEdit.text()
     author = self.author_lineEdit.text()
     publish_company = self.publish_company_lineEdit.text()
     publish_date = self.publish_date_lineEdit.text()
     store_num = self.store_num_lineEdit.text()
     if '' in [book_name, author, publish_company, publish_date, store_num]:
         msg_box(self, '错误', '请输入图书的关键信息!')
         return
     db = DBHelp()
     count, res = db.query_super(table_name='book',
                                 column_name='book_name',
                                 condition=book_name)
     if count:
         msg_box(self, '错误', '已存在同名书籍!')
         return
     book_info = [
         get_uuid(), book_name, author, publish_company, store_num, 0,
         get_current_time(), publish_date
     ]
     db.add_book(data=book_info)
     db.db_commit()
     db.instance = None
     del db
     self.add_book_don_signal.emit()
     self.close()
     msg_box(self, '提示', '添加新图书成功!')
Example #3
0
 def borrow_book(self):
     borrow_day = self.borrow_day_lineEdit.text()
     if borrow_day == '':
         msg_box(self, '提示', '借阅天数不能为空!')
         return
     db = DBHelp()
     db.update_borrow(book_id=self.book_id)
     borrow_info = [
         get_uuid(), self.book_id, self.book_name, self.current_user, 1,
         borrow_day,
         get_current_time(),
         get_return_day(int(borrow_day)), 0
     ]
     db.insert_borrow_info(data=borrow_info)
     db.db_commit()
     db.instance = None
     del db
     self.close()
     msg_box(self, '提示', '借阅成功')
    def generate_menu(self, pos):
        row_num = -1
        for i in self.tableWidget.selectionModel().selection().indexes():
            row_num = i.row()
        if row_num == -1:
            return
        if self.user_role == '普通用户':
            menu = QMenu()
            return_action = QAction(u'还书')
            return_action.setIcon(QIcon(RETURN))
            menu.addAction(return_action)

            delay_borrow_action = QAction(u'续借')
            delay_borrow_action.setIcon(QIcon(DELAY_TIME))
            menu.addAction(delay_borrow_action)

            # 如果当前条目为已还则菜单栏为不可点击状态
            if self.return_flag[row_num] == 1:
                return_action.setEnabled(False)
                delay_borrow_action.setEnabled(False)
            action = menu.exec_(self.tableWidget.mapToGlobal(pos))

            if action == return_action:
                if accept_box(self, '提示', '确实归还当前书本吗?') == QMessageBox.Yes:
                    th = Thread(target=self.return_book,
                                args=(self.borrow_info_id[row_num], ))
                    th.start()

            if action == delay_borrow_action:
                self.renew_win = RenewWindow(
                    borrow_id=self.borrow_info_id[row_num])
                self.renew_win.show()
        else:
            menu = QMenu()
            del_record_action = QAction(u'删除记录')
            del_record_action.setIcon(QIcon(DELETE_ICON))
            menu.addAction(del_record_action)

            ask_return_action = QAction(u'催还')
            ask_return_action.setIcon(QIcon(PUSH_RETURN))
            menu.addAction(ask_return_action)

            # 根据是否已经归还来判断菜单是否为可点击状态
            if self.return_flag[row_num] == 1:
                ask_return_action.setEnabled(False)
            else:
                del_record_action.setEnabled(False)

            action = menu.exec_(self.tableWidget.mapToGlobal(pos))

            if action == del_record_action:
                rep = accept_box(self, '警告', '确定删除该条记录吗?')
                if rep == QMessageBox.Yes:
                    pass

            if action == ask_return_action:
                index = self.tableWidget.currentRow()
                borrow_id = self.borrow_info_id[index]
                borrow_user = self.tableWidget.item(index, 0).text()
                self.ask_win = AskReturnWindow(
                    data=[borrow_user, borrow_id, 0,
                          get_current_time()])
                self.ask_win.show()