コード例 #1
0
    def createBooking(self, tool, returnedUser):

        functionName = 'createBooking'

        try:
            
            # Connecting to the DB
            databaseConnection = DatabaseConnection.CreateDBConnection(self.databaseFilename)
            cursor = databaseConnection.cursor()

            # get IDs
            cust_id = UserManager.LoadUserId(self, returnedUser)
            tool_id = Tools.getId(tool)

            cursor.execute('INSERT INTO Bookings (tool_id, cust_id) VALUES (?, ?)', (tool_id, cust_id)) 

            databaseConnection.commit()

            book_id = cursor.lastrowid

            returnedBooking = Bookings(book_id, tool, returnedUser)
            
            # Diconnecting from the DB
            DatabaseConnection.CloseDBConnection(databaseConnection)

            return returnedBooking

        except Error as e:

            print(__name__, ':', functionName, ':', e)
            raise
コード例 #2
0
    def loadFutureTools(self, range_start, range_end_days = 42):

        functionName = 'loadFutureTools'

        # empty list
        returnedToolList = []
        
        try:
            
            # calculationg range_end
            range_end = range_start + timedelta(days = range_end_days)  

            userManager = UserManager(self.registeredUser, self.databaseFilename)

            # Connecting to the DB
            databaseConnection = DatabaseConnection.CreateDBConnection(self.databaseFilename)
            cursor = databaseConnection.cursor()

            cursor.execute("SELECT tool_id, duration FROM Bookings WHERE start_date BETWEEN ? AND ?", (range_start, range_end))

            tool_rows = cursor.fetchall()

            for tool in tool_rows:
                
                # Read our values from the record
                tool_id = tool[0]
                cust_id = tool[1]
                tool_name = tool[2]
                tool_cat = tool[3]
                tool_desc = tool[4]
                price = tool[5]
                halfDayPrice = tool[6]

                # get ID
                user = userManager.LoadUserId(cust_id)

                # create tool
                singleTool = Tools(tool_id, user, tool_name, tool_cat, tool_desc, price, halfDayPrice)

                returnedToolList.append(singleTool)
            
            # Disconnecting from the DB
            DatabaseConnection.CloseDBConnection(databaseConnection)

            return returnedToolList

        except Error as e:

            print(__name__, ':', functionName, ':', e)
            raise
コード例 #3
0
    def searchToolByCategory(self, search_criteria):

        functionName = 'searchToolByCategory'

        # empty list
        returnedToolList = []
        
        try:

            userManager = UserManager(self.registeredUser, self.databaseFilename)

            # Connecting to the DB
            databaseConnection = DatabaseConnection.CreateDBConnection(self.databaseFilename)
            cursor = databaseConnection.cursor()

            cursor.execute("SELECT tool_id, cust_id, tool_name, tool_cat, price, tool_desc, half_price FROM Tools WHERE tool_cat = ?", (search_criteria))

            tool_rows = cursor.fetchall()

            for tool in tool_rows:

                tool_id = tool[0]
                cust_id = tool[1]
                tool_name = tool[2]
                tool_cat = tool[3]
                price = tool[4]
                tool_desc = tool[5]
                half_price = tool[6]

                # get user
                user = userManager.LoadUserId(cust_id)

                # create tool
                single_tool = Tools(tool_id, user, tool_name, tool_cat, price, tool_desc, half_price)

                returnedToolList.append(single_tool)
            
            # Disconnecting from the DB
            DatabaseConnection.CloseDBConnection(databaseConnection)

            return returnedToolList

        except Error as e:

            print(__name__, ':', functionName, ':', e)
            raise