class DeleteBook:
    def __init__(self, book_table, issue_table):
        self.book_table = book_table
        self.issue_table = issue_table

    def create_gui(self):
        self.GUI = GUI(page_title="Library", page_width=1000, page_height=500)
        self.GUI.create_canvas(img=None, bg="#006B38")
        head_frame = self.GUI.create_frame(location=(0.25, 0.1, 0.5, 0.13))
        head_label = self.GUI.create_label(frame=head_frame,
                                           text="Delete Book",
                                           bg="black",
                                           fg="white",
                                           font_size=15,
                                           location=(0, 0, 1, 1))

        delete_frame = self.GUI.create_frame(location=(0.25, 0.3, 0.5, 0.5),
                                             bg="black")

        delete_body = self.GUI.create_label(delete_frame,
                                            text="Book ID",
                                            bg="black",
                                            fg="white",
                                            font_size=11,
                                            location=(0.05, 0.5, 0.3, 0.1))
        self.delete_entry = self.GUI.create_entry(delete_frame,
                                                  location=(0.4, 0.5, 0.3,
                                                            0.13))

        self.GUI.create_button(text="SUBMIT",
                               command=self.delete_book,
                               location=(0.28, 0.9, 0.18, 0.08))
        self.GUI.create_button(text="Quit",
                               command=self.GUI.root.destroy,
                               location=(0.53, 0.9, 0.18, 0.08))

    def delete_book(self):
        bid = self.delete_entry.get()

        deleteSql = "delete from " + self.book_table + " where bid = '" + bid + "'"
        deleteIssue = "delete from " + self.issue_table + " where bid = '" + bid + "'"

        con, cur = connectServer()
        try:
            cur.execute(deleteSql)
            con.commit()
            cur.execute(deleteIssue)
            con.commit()
            messagebox.showinfo('Success', "Book Record Deleted Successfully")
        except:
            messagebox.showinfo("Please check Book ID")

        self.delete_entry.delete(0, END)

    def delete(self):

        self.create_gui()

        self.GUI.root.mainloop()
Пример #2
0
class ViewBook:
    def __init__(self, book_table, issue_table):
        self.book_table = book_table
        self.issue_table = issue_table
        self.GUI = None

    def create_gui(self):
        self.GUI = GUI(page_title="Library", page_width=1000, page_height=500)
        self.GUI.create_canvas(img=None, bg="#12a4d9")
        head_frame = self.GUI.create_frame(location=(0.25, 0.1, 0.5, 0.13),
                                           bg="#FFBB00")
        self.GUI.create_label(head_frame, "Books", "black", "white",
                              (0, 0, 1, 1), 15)

        details_frame = self.GUI.create_frame(location=(0.1, 0.3, 0.8, 0.6),
                                              bg="black")
        columns = "BID\t\tTitle\t\tAuthor\t\t\tStatus"
        self.GUI.create_label(details_frame,
                              text=columns,
                              location=(0.07, 0.1),
                              bg="black",
                              fg="white",
                              font_size=11)
        columns = "-----------------------------------------------------------------------------"
        self.GUI.create_label(details_frame,
                              text=columns,
                              location=(0.05, 0.2),
                              bg="black",
                              fg="white",
                              font_size=11)
        y = 0.25

        con, cur = connectServer()
        query = "SELECT * FROM " + self.book_table
        print(query)
        try:
            cur.execute(query)
            con.commit()
            for i in cur:
                text = self.format_string(i)
                self.GUI.create_label(details_frame,
                                      text,
                                      location=(0.07, y),
                                      bg="black",
                                      fg="white",
                                      font_size=11)
                y += 0.05
        except:
            messagebox.showinfo("Failed to fetch data from database")

        self.GUI.create_button(text="Quit",
                               command=self.GUI.root.destroy,
                               location=(0.1, 0.9, 0.18, 0.08))
        self.GUI.create_button(text="Refresh",
                               command=self.refresh,
                               location=(0.4, 0.9, 0.18, 0.08))

    def refresh(self):
        if self.GUI:
            self.GUI.root.destroy()
        self.view()

    def format_string(self, i):
        text = f"{i[0]} {' ' * (12 - len(i[0]))}"
        text += f"{i[1]} {' ' * (17 - len(i[1]))}"
        text += f"{i[2]}  {' ' * (25 - len(i[2]))}"
        text += f"{i[3]}  {' ' * (17 - len(i[1]))}"
        return text

    def view(self):
        self.create_gui()
        self.GUI.root.mainloop()
class AddBook:
    """ a class that handles book adding"""
    def __init__(self, bookTableName, bookIssuedTableName):

        self.bookTableName = bookTableName
        self.bookIssuedTableName = bookIssuedTableName

    def book_register(self, ):

        bid = self.entry_bid.get()
        title = self.entry_title.get()
        author = self.entry_author.get()
        status = self.entry_status.get()
        status = status.lower()

        con, cur = connectServer()

        insert_books = "insert into " + self.bookTableName + " values('" + bid + "','" + title + "','" + author + "','" + status + "')"
        try:
            cur.execute(insert_books)
            con.commit()
            messagebox.showinfo('Success', "Book added successfully")
        except:
            messagebox.showinfo("Error", "Can't add data into Database")

        self.entry_bid.delete(0, END)
        self.entry_title.delete(0, END)
        self.entry_author.delete(0, END)

    def create_gui(self):
        self.GUI = GUI(page_title="Library", page_width=1500, page_height=750)

        # canvas
        self.GUI.create_canvas(img=None, bg="#ff6e40")

        # head_frame
        # location at (x,y) = (0.2,0.1) and (width, height)=(0.6,0.16)
        head_frame = self.GUI.create_frame(location=(0.2, 0.1, 0.6, 0.16))
        label = self.GUI.create_label(head_frame,
                                      text="Add Books",
                                      bg=self.GUI.button_background,
                                      fg=self.GUI.button_foreground,
                                      location=(0, 0, 1, 1),
                                      font_size=15)

        # books details frame
        # location at (x,y) = (0.1,0.4), (width, height) = (0.8,0.4)
        books_frame = self.GUI.create_frame(location=(0.1, 0.4, 0.8, 0.4),
                                            bg="black")

        # take input from user
        # bid, title, author, status

        label_bid = self.GUI.create_label(frame=books_frame,
                                          text="Book ID : ",
                                          bg="black",
                                          fg="white",
                                          location=(0.05, 0.2, 0.08, 0.08),
                                          font_size=11)

        self.entry_bid = self.GUI.create_entry(frame=books_frame,
                                               location=(0.3, 0.2, 0.62, 0.08))

        label_title = self.GUI.create_label(frame=books_frame,
                                            text="Title: ",
                                            bg="black",
                                            fg="white",
                                            location=(0.05, 0.35, 0.08, 0.08),
                                            font_size=11)
        self.entry_title = self.GUI.create_entry(frame=books_frame,
                                                 location=(0.3, 0.35, 0.62,
                                                           0.08))

        label_author = self.GUI.create_label(frame=books_frame,
                                             text="Author: ",
                                             bg="black",
                                             fg="white",
                                             location=(0.05, 0.50, 0.08, 0.08),
                                             font_size=11)
        self.entry_author = self.GUI.create_entry(frame=books_frame,
                                                  location=(0.3, 0.5, 0.62,
                                                            0.08))

        label_status = self.GUI.create_label(frame=books_frame,
                                             text="Status(Avail/issued): ",
                                             bg="black",
                                             fg="white",
                                             location=(0.05, 0.65, 0.08, 0.08),
                                             font_size=11)
        self.entry_status = self.GUI.create_entry(frame=books_frame,
                                                  location=(0.3, 0.65, 0.62,
                                                            0.08))
        self.entry_status.insert(0, "Available")

    def add_book(self):
        self.create_gui()
        # Submit Button
        self.GUI.create_button(text="SUBMIT",
                               command=self.book_register,
                               location=(0.28, 0.9, 0.18, 0.08))
        self.GUI.create_button(text="Quit",
                               command=self.GUI.root.destroy,
                               location=(0.53, 0.9, 0.18, 0.08))
        self.GUI.root.mainloop()
Пример #4
0
class ReturnBook:
    """ issue book"""
    def __init__(self,
                 book_table_name,
                 book_issued_table_name,
                 image_path=None):
        self.book_table_name = book_table_name
        self.book_issued_table_name = book_issued_table_name
        self.image_path = image_path

    def create_gui(self):
        self.GUI = GUI(page_title="Library", page_width=800, page_height=400)
        self.GUI.create_canvas(img=None, bg="#FFBB00")

        head_frame = self.GUI.create_frame(location=(0.25, 0.1, 0.5, 0.13),
                                           bg="#FFBB00")
        self.GUI.create_label(head_frame,
                              text="Return Book",
                              bg="black",
                              fg="white",
                              font_size=15,
                              location=(0, 0, 1, 1))

        # details frame
        details_frame = self.GUI.create_frame(location=(0.1, 0.3, 0.8, 0.5),
                                              bg="black")

        label_bid = self.GUI.create_label(details_frame, "Book ID: ", "black",
                                          "white", (0.05, 0.02), 11)
        self.entry_bid = self.GUI.create_entry(details_frame,
                                               (0.3, 0.02, 0.5, 0.1))

        self.GUI.create_button(text="Return",
                               command=self.return_,
                               location=(0.28, 0.9, 0.18, 0.08))
        self.GUI.create_button(text="Quit",
                               command=self.GUI.root.destroy,
                               location=(0.53, 0.9, 0.18, 0.08))

    def return_(self):

        bid = self.entry_bid.get()
        bid_query = "select bid from " + self.book_issued_table_name
        status_query = "select status from " + self.book_table_name + " where bid = '" + bid + "'"
        update_sql = f"update {self.book_table_name} set status = 'available' where bid = {bid}"
        delete_sql = "delete from " + self.book_issued_table_name + " where bid = '" + bid + "'"
        # print(status_query)

        try:
            con, cur = connectServer()

            cur.execute(bid_query)
            con.commit()
            all_bids = [x[0] for x in cur]

            if bid in all_bids:
                cur.execute(status_query)
                con.commit()
                all_status = [x[0] for x in cur]
                index = all_bids.index(bid)

                if all_status[index] == 'issued':
                    cur.execute(delete_sql)
                    con.commit()
                    cur.execute(update_sql)
                    con.commit()
                    messagebox.showinfo('Success',
                                        "Book returned Successfully")

                else:
                    messagebox.showinfo('Message', "Book Already returned.")

            else:
                messagebox.showinfo("Error", "Book ID not present")
        except:
            messagebox.showinfo("Error", "Can't fetch Book IDs")

        self.entry_bid.delete(0, END)

    def return_book(self):
        self.create_gui()
        self.GUI.root.mainloop()