Beispiel #1
0
 def BorrowBook(self, uid, bid):
     # 获取系统时间当作借阅时间并计算出应该归还的时间
     borrow_time = datetime.datetime.now().strftime('%Y-%m-%d')
     return_time = (datetime.datetime.now() +
                    datetime.timedelta(days=90)).strftime('%Y-%m-%d')
     book = BookAPI()
     bo = Book()
     bo.set_bookid(bid)
     record = book.GetBookByField(bo)
     record = record[0]
     print(record.get_status())
     if (record.get_status() == '正常'):
         print("You can borrow this book!")
         if (input("Do you want to borrow this book?(press YES to borrow)")
                 == 'YES'):
             print("Successful borrowing!")
             addborr = BorrowAPI()
             obj = Borrow()
             # 获取borrowid的最大值
             borrowid = int(addborr.GetMaxBorrowid()) + 1
             print(borrowid)
             obj.set_borrowid(borrowid)
             obj.set_userid(uid)
             obj.set_bookid(bid)
             obj.set_borrowdate(borrow_time)
             obj.set_presretdate('0000-00-00')
             obj.set_actretdate(return_time)
             addborr.InsertBorrowRecord(obj)
             book2 = BookAPI()
             # 修改图书状态
             book2.UpdateRecord('book', 'status', '在借', 'bookid', bid)
         else:
             print("You don't want to borrow this book......OK")
     else:
         print("Abnormal book state,you can't borrow this book!")
class BookClient(object):
    def __init__(self):
        self.bookapi = BookAPI()

    def GetAllBookRecord(self):
        funcname = sys._getframe().f_back.f_code.co_name
        args = [5]
        DisplayResultSet(funcname, self.bookapi.GetAllBookRecord(args[0]),
                         args)

    def GetBookByDis(self):
        funcname = sys._getframe().f_back.f_code.co_name
        args = [u'数学', u'矿业技术']
        for item in args:
            DisplayResultSet(funcname, self.bookapi.GetBookByDis(item), item,
                             2)

    def GetBookByMaj(self):
        funcname = sys._getframe().f_back.f_code.co_name
        args = [u'工业技术', u'数理科学与化学']
        for item in args:
            DisplayResultSet(funcname, self.bookapi.GetBookByMaj(item), item,
                             2)

    def GetBookByName(self):
        funcname = sys._getframe().f_back.f_code.co_name
        args = [u'Java', u'Python', u'C++']
        for item in args:
            DisplayResultSet(funcname, self.bookapi.GetBookByName(item), item,
                             2)

    def GetBookByField(self):
        funcname = sys._getframe().f_back.f_code.co_name
        book1 = Book()
        funcname = sys._getframe().f_back.f_code.co_name
        book1.set_author(u'韩国')
        book2 = Book()
        book2.set_version(u'第一版')
        book2.set_booklanguage(u'英文')
        book3 = Book()
        book3.set_publisher(u'清华大学出版社')
        book3.set_stack(u'一层')
        book3.set_floor(3)
        args = [book1, book2, book3]
        for item in args:
            DisplayResultSet(funcname, self.bookapi.GetBookByField(item), item,
                             2)

    def InsertBookRecord(self):
        funcname = sys._getframe().f_back.f_code.co_name
        test = Book()
        test.set_bookid('300001')
        test.set_bookname('1')
        test.set_author('1')
        test.set_pages('1')
        test.set_collecttime('2010-09-17')
        test.set_version('1')
        test.set_major('1')
        test.set_discipline('1')
        test.set_isbn('133-314-2343-16-2')
        test.set_booklanguage('1')
        test.set_publisher('1')
        test.set_status('1')
        test.set_abstract('1')
        test.set_stack('1')
        test.set_shelf('1')
        test.set_floor('2')
        test.set_bookvalue('1')
        args = [test]
        DisplayResultSet(
            funcname,
            self.bookapi.InsertBookRecord(args[0]),
            args[0],
        )

    def UpdateRecord(self):
        funcname = sys._getframe().f_back.f_code.co_name
        args = ['book', 'bookid', '300000', 'bookid', '300001']
        DisplayResultSet(
            funcname,
            self.bookapi.UpdateRecord(args[0], args[1], args[2], args[3],
                                      args[4]), args)

    def DeleteRecord(self):
        funcname = sys._getframe().f_back.f_code.co_name
        args = ['book', 'bookid', '300000']
        DisplayResultSet(funcname,
                         self.bookapi.DeleteRecord(args[0], args[1], args[2]),
                         args)

    def TestBookClient(self):
        self.GetAllBookRecord()
        self.GetBookByDis()
        self.GetBookByMaj()
        self.GetBookByName()
        self.GetBookByField()
        self.InsertBookRecord()
        self.UpdateRecord()
        self.DeleteRecord()