class AddBooks:
    def __init__(self):
        self.db = MyDb()
        self.update_index = ""

    def add_gui(self):
        try:
            self.display = Tk()
            self.display.title('ADD BOOKS')
            self.display.geometry('1920x1080+0+0')
            self.display.configure(bg='springgreen2')

            self.lbl111 = Label(self.display,
                                bg='Seagreen1',
                                width=600,
                                height=4,
                                font=('Ariel', 15, 'bold'))
            self.lbl111.place(x=1, y=20)

            self.lbl113 = Label(self.display,
                                bg='Seagreen1',
                                width=60,
                                height=24)
            self.lbl113.place(x=60, y=250)

            self.lbl115 = Label(self.display,
                                bg='Seagreen1',
                                width=68,
                                height=4)
            self.lbl115.place(x=1, y=160)

            self.lbl113 = Label(self.display,
                                bg='Seagreen1',
                                width=40,
                                height=4)
            self.lbl113.place(x=550, y=160)

            self.lbl112 = Label(self.display,
                                text='ORIENTAL BOOK HOUSE',
                                bg='Seagreen1',
                                fg='black',
                                font=('Ariel', 19, 'bold'))
            self.lbl112.place(x=560, y=30)

            self.lbl112 = Label(self.display,
                                text='Bagbazar, Kathmandu',
                                bg='Seagreen1',
                                fg='black',
                                font=('Ariel', 12, 'bold'))
            self.lbl112.place(x=620, y=75)

            self.top1_lbl = Label(self.display,
                                  bg='Seagreen1',
                                  text='Book Registry',
                                  font=('Ariel', 15, 'bold'))
            self.top1_lbl.place(x=190, y=180)

            self.add_name = Label(self.display,
                                  bg='Seagreen1',
                                  text='Book Name',
                                  font=('Ariel', 10, 'bold'))
            self.add_name.place(x=140, y=270)

            self.ent01 = Entry(self.display, font=('Ariel', 10))
            self.ent01.place(x=240, y=270)

            self.add_writer = Label(self.display,
                                    bg='Seagreen1',
                                    text='Writer',
                                    font=('Ariel', 10, 'bold'))
            self.add_writer.place(x=140, y=310)

            self.wn_ent = Entry(self.display, font=('Ariel', 10))
            self.wn_ent.place(x=240, y=310)

            self.add_pub = Label(self.display,
                                 bg='Seagreen1',
                                 text='Publisher',
                                 font=('Ariel', 10, 'bold'))
            self.add_pub.place(x=140, y=350)

            self.pub_ent = Entry(self.display, font=('Ariel', 10))
            self.pub_ent.place(x=240, y=350)

            self.add_price = Label(self.display,
                                   bg='Seagreen1',
                                   text='Price',
                                   font=('Ariel', 10, 'bold'))
            self.add_price.place(x=140, y=390)

            self.price_ent = Entry(self.display, font=('Ariel', 10))
            self.price_ent.place(x=240, y=390)

            self.add_cat = Label(self.display,
                                 bg='Seagreen1',
                                 text='Category',
                                 font=('Ariel', 10, 'bold'))
            self.add_cat.place(x=140, y=430)

            self.cat = ttk.Combobox(self.display,
                                    text="Category",
                                    font=('Ariel', 10))
            self.cat.set('--choose category--')
            self.cat['values'] = self.combo()
            self.cat.place(x=240, y=430)

            self.reg_book = Label(self.display,
                                  bg='Seagreen1',
                                  text='Added Piece',
                                  font=('Ariel', 10, 'bold'))
            self.reg_book.place(x=140, y=470)

            self.pie_ent = Entry(self.display, font=('Ariel', 10))
            self.pie_ent.place(x=240, y=470)

            self.rem_book = Label(self.display,
                                  bg='Seagreen1',
                                  text='Remain Piece',
                                  font=('Ariel', 10, 'bold'))
            self.rem_book.place(x=140, y=510)

            self.rem_ent = Entry(self.display, font=('Ariel', 10))
            self.rem_ent.place(x=240, y=510)

            self.ad_book = Button(self.display,
                                  text='Add',
                                  command=self.addbooks_hand,
                                  bg='black',
                                  fg='white',
                                  width=6,
                                  font=('Ariel', 11, 'bold'))
            self.ad_book.place(x=140, y=570)

            self.up_book = Button(self.display,
                                  text='Update',
                                  bg='black',
                                  fg='white',
                                  command=self.update_item,
                                  font=('Ariel', 11, 'bold'))
            self.up_book.place(x=240, y=570)

            self.del_book = Button(self.display,
                                   text='Delete',
                                   bg='black',
                                   fg='white',
                                   command=self.delete_item,
                                   font=('Ariel', 11, 'bold'))
            self.del_book.place(x=340, y=570)

            self.top_lbl = Label(self.display,
                                 bg='Seagreen1',
                                 text='Recently added books',
                                 font=('Ariel', 15, 'bold'))
            self.top_lbl.place(x=570, y=180)

            self.add_tree = ttk.Treeview(self.display,
                                         column=('n', 'w', 'p', 'm', 'c', 'e',
                                                 'r'),
                                         height=17)
            self.add_tree.place(x=550, y=250)
            self.add_tree['show'] = 'headings'
            self.add_tree.column('n', width=200)
            self.add_tree.column('w', width=100)
            self.add_tree.column('p', width=100)
            self.add_tree.column('m', width=100)
            self.add_tree.column('c', width=100)
            self.add_tree.column('e', width=70)
            self.add_tree.column('r', width=70)
            self.add_tree.heading('n', text='Book')
            self.add_tree.heading('w', text='Writer')
            self.add_tree.heading('p', text='Price')
            self.add_tree.heading('m', text='Publisher')
            self.add_tree.heading('c', text='Catagory')
            self.add_tree.heading('e', text='Reg-piece')
            self.add_tree.heading('r', text='Rem-piece')

            self.show_items_in_tree()

            self.ser_book = Button(self.display,
                                   bg='yellow',
                                   text='Search',
                                   font=('Ariel', 10, 'bold'),
                                   command=self.searchbook)
            self.ser_book.place(x=1270, y=85)

            self.search_book = Entry(self.display,
                                     text='Search',
                                     font=('Ariel', 10))
            self.search_book.place(x=1110, y=90)

            self.display.mainloop()
        except Exception as e:
            print(e)

    def addbooks_hand(self):
        try:
            name = self.ent01.get()
            print(name)
            writer = self.wn_ent.get()
            print(writer)
            price = self.price_ent.get()
            print(price)
            publisher = self.pub_ent.get()
            print(publisher)
            reg = self.pie_ent.get()
            rem = self.rem_ent.get()

            catagory = self.cat.get()

            if name == '' or writer == '' or price == '' or publisher == '' or catagory == '' or reg == '' or rem == '':
                messagebox.showerror('Error', 'Fill all the entries !!')
                return False
            elif not price.isdigit():
                messagebox.showerror("Error", "Invalid Price")
                return False

            else:
                self.add_books1(name, writer, price, publisher, catagory, reg,
                                rem)
                messagebox.showinfo("BOOKS", "BOOK Added 😊")
                self.show_items_in_tree()

        except Exception as e:
            print(e)

    def add_books1(self, name, writer, price, publisher, catagory, reg, rem):
        if name == '' or writer == '' or price == '' or publisher == '' or catagory == '' or reg == '' or rem == '':
            return False
        elif not price.isdigit():
            return False
        else:
            qry = "INSERT INTO booksdetail (name, writer, price, publisher,catagory,ent_book, rem_book) VALUES (%s,%s,%s,%s,%s,%s,%s)"
            values = (name, writer, price, publisher, catagory, reg, rem)
            return self.db.iud(qry, values)

    def combo(self):
        qry = '''SELECT catagory FROM catq'''
        combox = self.db.get_data(qry)
        return combox

    def show_items_in_tree(self):
        all_items = self.show_books()
        self.add_tree.delete(*self.add_tree.get_children())
        for i in all_items:
            self.add_tree.insert("",
                                 "end",
                                 text=i[0],
                                 value=(i[1], i[2], i[3], i[4], i[5], i[6],
                                        i[7]))
        self.add_tree.bind("<Double-1>", self.select_item)

    def show_books(self):
        qry = "SELECT * FROM booksdetail"
        all_books = self.db.get_data(qry)
        return all_books

    def select_item(self, event):
        sel_row = self.add_tree.selection()[0]
        sel_item = self.add_tree.item(sel_row)
        self.update_index = self.add_tree.item(sel_row, 'text')
        selected_data = self.add_tree.item(sel_row, 'values')
        self.ent01.delete(0, 'end')
        self.ent01.insert(0, selected_data[0])
        self.wn_ent.delete(0, 'end')
        self.wn_ent.insert(0, selected_data[1])
        self.price_ent.delete(0, 'end')
        self.price_ent.insert(0, selected_data[2])
        self.cat.delete(0, 'end')
        self.cat.insert(0, selected_data[4])
        self.pub_ent.delete(0, 'end')
        self.pub_ent.insert(0, selected_data[3])
        self.pie_ent.delete(0, 'end')
        self.pie_ent.insert(0, selected_data[5])
        self.rem_ent.delete(0, 'end')
        self.rem_ent.insert(0, selected_data[6])

    def update_books(self, index, name, writer, price, publisher, catagory,
                     reg, rem):
        try:
            qry = "UPDATE booksdetail SET name = %s, writer = %s, price = %s, publisher=%s, catagory=%s, ent_book =%s, rem_book=%s WHERE id = %s"
            values = (name, writer, price, publisher, catagory, reg, rem,
                      index)
            self.db.iud(qry, values)
            return True
        except Exception as e:
            print(e)
            return False

    def update_item(self):
        name = self.ent01.get()
        writer = self.wn_ent.get()
        price = self.price_ent.get()
        publisher = self.pub_ent.get()
        catagory = self.cat.get()
        reg = self.pie_ent.get()
        rem = self.rem_ent.get()

        if self.update_index == "":
            messagebox.showerror("Error", "Select Item first")
        elif not name == '' or writer == '' or price == '' or publisher == '' or catagory == '' or reg == '' or rem == '':

            if self.update_books(int(self.update_index), name, writer, price,
                                 publisher, catagory, reg, rem):
                messagebox.showinfo("Item", "Item Updated")
                self.show_items_in_tree()
                print(self.update_index)
            else:
                messagebox.showerror("Error", "Item can not be Updated")

    def delete_books(self, id):
        try:
            qry = "DELETE FROM booksdetail WHERE id = %s"
            values = (id)
            self.db.iud(qry, values)
            return True
        except Exception as e:
            print(e)
            return False

    def delete_item(self):

        name = self.ent01.get()
        writer = self.wn_ent.get()
        price = self.price_ent.get()
        publisher = self.pub_ent.get()
        catagory = self.cat.get()
        reg = self.pie_ent.get()
        rem = self.rem_ent.get()

        if self.update_index == "":
            messagebox.showerror("Error", "Select Item first")
        elif not name == '' or writer == '' or price == '' or publisher == '' or catagory == '' or reg == '' or rem == '':

            self.delete_books(self.del_help(name, publisher))
            messagebox.showinfo("Success", "Delete success")
            self.show_items_in_tree()

    def del_help(self, name, publisher):
        name = self.ent01.get()
        publisher = self.pub_ent.get()

        qry = '''select id from booksdetail where name= %s and publisher=%s'''
        values = (name, publisher)
        gett = self.db.get_data_i(qry, values)
        print(gett)
        return gett

    def searchbook(self):
        self.db = MyDb()
        searchbook = self.search_book.get()

        if searchbook == '':
            messagebox.showerror('Empty', 'Insert some keyword please!')
        else:
            qry = "SELECT * FROM booksdetail WHERE name LIKE '" + searchbook + "%'"
            values = (searchbook)
            result = self.db.get_data_p(qry, values)

            self.add_tree.delete(*self.add_tree.get_children())
            for i in result:
                self.add_tree.insert("",
                                     "end",
                                     text=i[0],
                                     value=(i[1], i[2], i[3], i[4], i[5], i[6],
                                            i[7]))
                self.add_tree.bind("<Double-1>", self.select_item)
class Guis:
    def __init__(self):
        self.buy = BuyBooks()
        self.log_in()
        self.data_base = MyDb()
        self.ab = AddBooks()
        self.see = SeeBooks()
        self.fetch = FetchBill()

    def log_in(self):
        try:
            self.main_dis = Tk()
            self.main_dis.title('Log-in')
            self.main_dis.geometry('1920x1080')
            self.main_dis.configure(bg='steelblue3')

            self.lbl111 = Label(self.main_dis,
                                bg='Steelblue1',
                                width=600,
                                height=4,
                                font=('Ariel', 15, 'bold'))
            self.lbl111.place(x=1, y=20)

            self.lbl112 = Label(self.main_dis,
                                text='ORIENTAL BOOK HOUSE',
                                bg='Steelblue1',
                                fg='black',
                                font=('Ariel', 19, 'bold'))
            self.lbl112.place(x=560, y=30)

            self.lbl112 = Label(self.main_dis,
                                text='Bagbazar, Kathmandu',
                                bg='Steelblue1',
                                fg='black',
                                font=('Ariel', 12, 'bold'))
            self.lbl112.place(x=620, y=75)

            self.lbl113 = Label(self.main_dis,
                                bg='Steelblue1',
                                width=40,
                                height=2)
            self.lbl113.place(x=560, y=160)

            self.lbl1131 = Label(self.main_dis,
                                 bg='Steelblue1',
                                 width=40,
                                 height=10)
            self.lbl1131.place(x=560, y=240)

            self.lbl11314 = Label(self.main_dis,
                                  bg='Steelblue1',
                                  width=40,
                                  height=3)
            self.lbl11314.place(x=560, y=440)

            self.lbl1 = Label(self.main_dis,
                              text='Log-In Portal',
                              bg='Steelblue1',
                              font=('Ariel', 15, 'bold'))
            self.lbl1.place(x=640, y=165)

            self.lbl2 = Label(self.main_dis,
                              text='Username',
                              bg='Steelblue1',
                              font=('Ariel', 11, 'bold'))
            self.lbl2.place(x=570, y=290)

            self.ent1 = Entry(self.main_dis, font=('Ariel', 11, 'bold'))
            self.ent1.place(x=670, y=290)

            self.lbl3 = Label(self.main_dis,
                              text='Password',
                              bg='Steelblue1',
                              font=('Ariel', 11, 'bold'))
            self.lbl3.place(x=570, y=330)

            self.ent2 = Entry(self.main_dis,
                              show='*',
                              font=('Ariel', 11, 'bold'))
            self.ent2.place(x=670, y=330)

            self.btn01 = Button(self.main_dis,
                                text='     Log-in     ',
                                bg='black',
                                fg='white',
                                command=self.do_login,
                                font=('Ariel', 13, 'bold'),
                                width=10)
            self.btn01.place(x=650, y=450)

            self.btn03 = Button(self.main_dis,
                                text='     Register for new    ',
                                bg='black',
                                fg='yellow',
                                font=('Ariel', 9, 'bold'),
                                command=self.reg_screen)
            self.btn03.place(x=1200, y=165)

            self.main_dis.mainloop()

        except Exception as e:
            print(e)

    def reg_screen(self):
        try:
            self.main_dis.destroy()
            self.reges = Tk()
            self.reges.title('User Registration')
            self.reges.geometry('1920x1080+0+0')
            self.reges.configure(bg='springgreen2')

            self.lbl111 = Label(self.reges,
                                bg='palegreen',
                                width=600,
                                height=4,
                                font=('Ariel', 15, 'bold'))
            self.lbl111.place(x=1, y=20)

            self.lbl112 = Label(self.reges,
                                text='ORIENTAL BOOK HOUSE',
                                bg='palegreen',
                                fg='black',
                                font=('Ariel', 19, 'bold'))
            self.lbl112.place(x=560, y=30)

            self.lbl112 = Label(self.reges,
                                text='Bagbazar, Kathmandu',
                                bg='palegreen',
                                fg='black',
                                font=('Ariel', 12, 'bold'))
            self.lbl112.place(x=620, y=75)

            self.lbl113 = Label(self.reges, bg='palegreen', width=40, height=2)
            self.lbl113.place(x=560, y=140)

            self.lbl1131 = Label(self.reges,
                                 bg='palegreen',
                                 width=40,
                                 height=13)
            self.lbl1131.place(x=560, y=190)

            self.lbl1131 = Label(self.reges,
                                 bg='palegreen',
                                 width=40,
                                 height=5)
            self.lbl1131.place(x=560, y=410)

            self.lbl11314 = Label(self.reges,
                                  bg='palegreen',
                                  width=190,
                                  height=3)
            self.lbl11314.place(x=560, y=530)

            self.lbl1 = Label(self.reges,
                              text='Admin Registration',
                              bg='palegreen',
                              font=('Ariel', 15, 'bold'))
            self.lbl1.place(x=615, y=145)

            self.lbl2 = Label(self.reges,
                              text='Name',
                              bg='palegreen',
                              font=('Ariel', 11, 'bold'))
            self.lbl2.place(x=570, y=210)

            self.ent1 = Entry(self.reges, font=('Ariel', 11, 'bold'))
            self.ent1.place(x=660, y=210)

            self.lbl3 = Label(self.reges,
                              text='Address',
                              bg='palegreen',
                              font=('Ariel', 11, 'bold'))
            self.lbl3.place(x=570, y=250)

            self.lbl21 = Label(self.reges,
                               text='Phone No.',
                               bg='palegreen',
                               font=('Ariel', 11, 'bold'))
            self.lbl21.place(x=570, y=290)

            self.ent3 = Entry(self.reges, font=('Ariel', 11, 'bold'))
            self.ent3.place(x=660, y=250)

            self.lbl29 = Label(self.reges,
                               text='Email',
                               bg='palegreen',
                               font=('Ariel', 11, 'bold'))
            self.lbl29.place(x=570, y=340)

            self.ent00 = Entry(self.reges, font=('Ariel', 11, 'bold'))
            self.ent00.place(x=660, y=290)

            self.ent2 = Entry(self.reges,
                              font=('Ariel', 10, 'bold'),
                              width='26')
            self.ent2.place(x=640, y=340)

            self.lbl22 = Label(self.reges,
                               text='Password',
                               bg='palegreen',
                               font=('Ariel', 11, 'bold'))
            self.lbl22.place(x=570, y=460)

            self.lbl23 = Label(self.reges,
                               text='Username',
                               bg='palegreen',
                               font=('Ariel', 11, 'bold'))
            self.lbl23.place(x=570, y=420)

            self.ent4 = Entry(self.reges, font=('Ariel', 11, 'bold'))
            self.ent4.place(x=660, y=420)

            self.ent5 = Entry(self.reges, font=('Ariel', 11, 'bold'))
            self.ent5.place(x=660, y=460)

            self.btn01 = Button(self.reges,
                                text='     Register     ',
                                bg='black',
                                fg='white',
                                font=('Ariel', 13, 'bold'),
                                command=self.do_register)
            self.btn01.place(x=640, y=540)

            self.btn03 = Button(self.reges,
                                text='Login Screen',
                                bg='yellow',
                                fg='black',
                                font=('Ariel', 12, 'bold'),
                                command=self.back1)
            self.btn03.place(x=1090, y=540)

            self.reges.mainloop()
        except Exception as e:
            print(e)

    def aft_log(self):

        self.update_index = ''
        username1 = self.ent1.get()
        password1 = self.ent2.get()
        self.window = Tk()
        self.window.title('BOOK CASE')
        self.window.geometry('1920x1080+0+0')
        self.window.configure(bg='darkslategray3')
        self.ab = AddBooks()
        self.see = SeeBooks()
        self.fetch = FetchBill()

        self.lbl111 = Label(self.window,
                            bg='darkslategray1',
                            width=600,
                            height=4,
                            font=('Ariel', 15, 'bold'))
        self.lbl111.place(x=1, y=20)

        self.lbl112 = Label(self.window,
                            text='ORIENTAL BOOK HOUSE',
                            bg='darkslategray1',
                            fg='black',
                            font=('Ariel', 19, 'bold'))
        self.lbl112.place(x=560, y=30)

        self.lbl113 = Label(self.window,
                            bg='darkslategray1',
                            width=40,
                            height=2)
        self.lbl113.place(x=560, y=140)

        self.lbl112 = Label(self.window,
                            text='Bagbazar, Kathmandu',
                            bg='darkslategray1',
                            fg='black',
                            font=('Ariel', 12, 'bold'))
        self.lbl112.place(x=620, y=75)

        self.lbl113 = Label(self.window,
                            bg='darkslategray1',
                            width=16,
                            height=4)
        self.lbl113.place(x=740, y=230)

        self.lbl1131 = Label(self.window,
                             bg='darkslategray1',
                             width=16,
                             height=4)
        self.lbl1131.place(x=540, y=230)

        self.lbl1131 = Label(self.window,
                             bg='darkslategray1',
                             width=16,
                             height=4)
        self.lbl1131.place(x=540, y=430)

        self.lbl1131 = Label(self.window,
                             bg='darkslategray1',
                             width=16,
                             height=4)
        self.lbl1131.place(x=740, y=430)

        self.lbl1 = Label(self.window,
                          text='Choose options',
                          bg='darkslategray1',
                          font=('Ariel', 15, 'bold'))
        self.lbl1.place(x=615, y=145)

        self.book_add = Button(self.window,
                               text="ADD BOOK",
                               command=self.ab.add_gui,
                               bg='black',
                               fg='white',
                               font=('Ariel', 11, 'bold'))
        self.book_add.place(x=550, y=250)

        self.book_buy = Button(self.window,
                               text="BUY BOOK",
                               command=self.buy.buy_gui,
                               bg='black',
                               fg='white',
                               font=('Ariel', 11, 'bold'))
        self.book_buy.place(x=550, y=450)

        self.see_buy = Button(self.window,
                              text="SEE BOOK",
                              command=self.see.see_gui,
                              bg='black',
                              fg='white',
                              font=('Ariel', 11, 'bold'))
        self.see_buy.place(x=750, y=250)

        self.see_bill = Button(self.window,
                               text="SEE BILL",
                               command=self.fetch.fgui,
                               bg='black',
                               fg='white',
                               font=('Ariel', 11, 'bold'),
                               width=9)
        self.see_bill.place(x=750, y=450)

        self.logst = Label(self.window,
                           text='👤',
                           font=('Ariel', 40),
                           bg='darkslategray1',
                           fg='blue')
        self.logst.place(x=1170, y=20)

        self.logname = Label(self.window,
                             text=self.data_base.get_name(
                                 username1, password1),
                             font=('Times New Roman', 12, 'italic'),
                             bg='darkslategray1',
                             fg='blue')
        self.logname.place(x=1150, y=90)
        self.main_dis.destroy()
        self.window.mainloop()

    def do_register(self):
        try:

            self.data_base = MyDb()

            username = self.ent4.get()
            password = self.ent5.get()
            name = self.ent1.get()
            address = self.ent3.get()
            phone = self.ent2.get()
            email = self.ent00.get()

            if username == " " or password == '' or name == '' or address == '' or phone == '' or email == '':
                messagebox.showerror("Error",
                                     "Enter everyboxes carefully 😒 ")
            else:
                qry = """INSERT INTO registers (username, password, name, address, phone, email)
                                VALUES (%s,%s,%s,%s,%s,%s)"""
                values = (username, password, name, address, phone, email)
                self.data_base.iud(qry, values)

                messagebox.showinfo("Success", "Registered Successfully 😊 ")
                self.send_mail(email)
        except Exception as e:
            print(e)

    def do_login(self):
        self.data_base = MyDb()
        username1 = self.ent1.get()
        password1 = self.ent2.get()
        qry = """SELECT * FROM registers WHERE username = %s and password = %s"""
        values = (username1, password1)
        user = self.data_base.get_data_p(qry, values)

        print(len(user))

        if username1 == " " or password1 == '':
            messagebox.showerror("Error", "Enter everyboxes carefully!")

        else:
            if len(user) == 1:
                messagebox.showinfo('Success', 'BOOM!!  Login successful!')
                self.aft_log()
                self.data_base.get_name(username1, password1)

            else:
                print("Wrong id or password")
                messagebox.showinfo('Sorry', 'INCORRECT Password or id')

    def back1(self):
        self.reges.destroy()
        self.log_in()

    def send_mail(self, email):

        try:

            server = smtplib.SMTP("smtp.gmail.com:587")
            server.ehlo()
            server.starttls()
            server.login('*****@*****.**', 'bagbazar')
            message = "Subject: {} {}".format(
                'Hello there!',
                "You've registered as an admin of ORIENTAL BOOK HOUSE. Thank You!"
            )
            server.sendmail('*****@*****.**', email, message)
            server.quit()
            print('Successful!')

        except Exception as e:
            print(e)
class FetchBill:
    def __init__(self):
        self.db = MyDb()

    def fgui(self):
        self.see_dis = Tk()
        self.see_dis.title('SEE BILLS')
        self.see_dis.geometry('1920x1080+0+0')
        self.see_dis.configure(bg='turquoise3')

        self.lbl111 = Label(self.see_dis,
                            bg='turquoise1',
                            width=600,
                            height=4,
                            font=('Ariel', 15, 'bold'))
        self.lbl111.place(x=1, y=20)

        self.lbl113 = Label(self.see_dis, bg='turquoise1', width=60, height=21)
        self.lbl113.place(x=60, y=250)

        self.lbl115 = Label(self.see_dis, bg='turquoise1', width=68, height=4)
        self.lbl115.place(x=1, y=160)

        self.lbl112 = Label(self.see_dis,
                            text='ORIENTAL BOOK HOUSE',
                            bg='turquoise1',
                            fg='black',
                            font=('Ariel', 19, 'bold'))
        self.lbl112.place(x=560, y=30)

        self.lbl112 = Label(self.see_dis,
                            text='Bagbazar, Kathmandu',
                            bg='turquoise1',
                            fg='black',
                            font=('Ariel', 12, 'bold'))
        self.lbl112.place(x=620, y=75)

        self.lbl113 = Label(self.see_dis, bg='turquoise1', width=30, height=4)
        self.lbl113.place(x=580, y=160)

        self.sort_lbl = Label(self.see_dis,
                              text='Search and Sort Bills',
                              bg='turquoise1',
                              font=('Ariel', 16, 'bold'))
        self.sort_lbl.place(x=150, y=180)

        self.sortby_lbl = Label(self.see_dis,
                                text='Search by :',
                                font=('Ariel', 13, 'bold'))
        self.sortby_lbl.place(x=130, y=330)

        self.cat = ttk.Combobox(self.see_dis,
                                text="Category",
                                font=('Ariel', 13),
                                width=16)
        self.cat.place(x=230, y=330)
        self.cat.set('--SELECT FIRST--')
        # opening above saved file to show it on combobox
        # access category from database here---
        # self.cat['values'] =
        # self.cat.grid()
        sortby = ['Book Name', 'Date (yyyy-mm-dd)', 'Bill by']

        self.cat['values'] = sortby

        # self.selectbut = Button(self.see_dis, text='Select', font=('Ariel', 11, 'bold'))
        # self.selectbut.place(x=340, y=360)

        self.search_ent = Entry(self.see_dis,
                                text='Keyword',
                                font=('Ariel', 13, 'bold'),
                                width=18)
        self.search_ent.place(x=230, y=400)

        self.selectbut = Button(self.see_dis,
                                text='Search 🔎',
                                command=self.select,
                                font=('Ariel', 15, 'bold'))
        self.selectbut.place(x=220, y=470)

        self.search_lbl = Label(self.see_dis,
                                text='Keyword :',
                                font=('Ariel', 13, 'bold'))
        self.search_lbl.place(x=130, y=400)

        self.lbl33 = Label(self.see_dis,
                           text='Results',
                           bg='turquoise1',
                           font=('Ariel', 16, 'bold'))
        self.lbl33.place(x=650, y=180)

        self.add_tree = ttk.Treeview(self.see_dis,
                                     column=('a', 'b', 'o', 'c', 'd', 'e', 'f',
                                             'g', 'h'),
                                     height=15)
        self.add_tree.place(x=580, y=250)
        self.add_tree['show'] = 'headings'
        self.add_tree.column('a', width=50)
        self.add_tree.column('b', width=70)
        self.add_tree.column('c', width=100)
        self.add_tree.column('d', width=100)
        self.add_tree.column('e', width=60)
        self.add_tree.column('f', width=60)
        self.add_tree.column('g', width=100)
        self.add_tree.column('h', width=70)
        self.add_tree.column('o', width=150)
        self.add_tree.heading('a', text='Bill Id')
        self.add_tree.heading('b', text='Date')
        self.add_tree.heading('o', text='Book')
        self.add_tree.heading('c', text='Customer Name')
        self.add_tree.heading('d', text='Customer Phone')
        self.add_tree.heading('e', text='Price')
        self.add_tree.heading('f', text='Discount')
        self.add_tree.heading('g', text='Total')
        self.add_tree.heading('h', text='Bill by')

        self.dataa()

        self.see_dis.mainloop()

    def select(self):
        self.db = MyDb()
        user_chosen = self.cat.get()

        if user_chosen == '':
            messagebox.showerror('Error', 'Select first')

        elif user_chosen == 'Book Name':
            keyword = self.search_ent.get()
            qry = "SELECT * FROM bill WHERE bookname LIKE '" + keyword + "%'"
            values = (keyword)
            result = self.db.get_data_p(qry, values)

            self.add_tree.delete(*self.add_tree.get_children())
            for i in result:
                self.add_tree.insert("",
                                     "end",
                                     text=i[0],
                                     value=(i[0], i[7], i[9], i[1], i[2], i[4],
                                            i[5], i[6], i[8]))

        elif user_chosen == 'Date (yyyy-mm-dd)':
            keyword = self.search_ent.get()
            qry = "SELECT * FROM bill WHERE date LIKE '" + keyword + "%'"
            values = (keyword)
            result = self.db.get_data_p(qry, values)

            self.add_tree.delete(*self.add_tree.get_children())
            for i in result:
                self.add_tree.insert("",
                                     "end",
                                     text=i[0],
                                     value=(i[0], i[7], i[9], i[1], i[2], i[4],
                                            i[5], i[6], i[8]))

        elif user_chosen == 'Bill by':
            keyword = self.search_ent.get()
            qry = "SELECT * FROM bill WHERE bill_by LIKE '" + keyword + "%'"
            values = (keyword)
            result = self.db.get_data_p(qry, values)

            self.add_tree.delete(*self.add_tree.get_children())
            for i in result:
                self.add_tree.insert("",
                                     "end",
                                     text=i[0],
                                     value=(i[0], i[7], i[9], i[1], i[2], i[4],
                                            i[5], i[6], i[8]))

    def dataa(self):
        self.db = MyDb()
        qry = '''select * from bill'''
        data = self.db.get_data(qry)

        self.add_tree.delete(*self.add_tree.get_children())
        for i in data:
            self.add_tree.insert("",
                                 "end",
                                 text=i[0],
                                 value=(i[0], i[7], i[9], i[1], i[2], i[4],
                                        i[5], i[6], i[8]))