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 __init__(self): self.buy = BuyBooks() self.log_in() self.data_base = MyDb() self.ab = AddBooks() self.see = SeeBooks() self.fetch = FetchBill()
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]))
def bookid(self,book, price): self.db = MyDb() book = self.book_ent.get() price = self.pr_ent.get() print(book) print(price) qry = '''select id from booksdetail where name=%s and price=%s''' values = (book,price) get= self.db.get_data_i(qry, values) print(type(get)) bipin =int(get[0]) print(type(bipin)) return bipin
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 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)
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 databill(self,cus_name,cus_phone,bookid,price,discount, total,date,book,billby): self.db = MyDb() qry = "INSERT INTO bill (cus_name, cus_phone, book, price, discount, total,date,bookname,bill_by) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s)" values = (cus_name,cus_phone,bookid,price,discount, total,date,book,billby) return self.db.iud(qry, values)
def __init__(self): super().__init__() self.see=SeeBooks() self.db=MyDb()
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)
def __init__(self): self.db=MyDb() self.ab=AddBooks()
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)
def __init__(self): self.db = MyDb()
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]))
def __init__(self): self.db = MyDb() self.update_index = ""
class BuyBooks(SeeBooks): def __init__(self): super().__init__() self.see=SeeBooks() self.db=MyDb() #self.app = Guis() def buy_gui(self): self.buy_dis = Tk() self.buy_dis.title('BUY BOOKS') self.buy_dis.geometry('1920x1080') self.buy_dis.configure(bg='dark orange3') self.see = SeeBooks() self.lbl111 = Label(self.buy_dis, bg='dark orange1', width=600, height=4, font=('Ariel', 15, 'bold')) self.lbl111.place(x=1, y=20) self.lbl113 = Label(self.buy_dis, bg='dark orange1', width=60, height=12) self.lbl113.place(x=60, y=250) self.lbl116 = Label(self.buy_dis, bg='dark orange1', width=60, height=14) self.lbl116.place(x=60, y=460) self.lbl115 = Label(self.buy_dis, bg='dark orange1', width=68, height=4) self.lbl115.place(x=1, y=160) self.lbl113 = Label(self.buy_dis, bg='dark orange1', width=40, height=4) self.lbl113.place(x=600, y=160) self.lbl118 = Label(self.buy_dis, bg='dark orange1', width=600, height=4) self.lbl118.place(x=600, y=600) self.lbl112 = Label(self.buy_dis, text='ORIENTAL BOOK HOUSE', bg='dark orange1', fg='black', font=('Ariel', 19, 'bold')) self.lbl112.place(x=560, y=30) self.lbl112 = Label(self.buy_dis, text='Bagbazar, Kathmandu', bg='dark orange1', fg='black', font=('Ariel', 13, 'bold')) self.lbl112.place(x=620, y=75) self.sort_lbl = Label(self.buy_dis, text='Search and Sort Books', bg='dark orange1', font=('Ariel', 16, 'bold')) self.sort_lbl.place(x=110, y=180) self.sortby_lbl = Label(self.buy_dis, text='Search by :', font=('Ariel', 13, 'bold')) self.sortby_lbl.place(x=130, y=270) self.cat = ttk.Combobox(self.buy_dis, text="Category",font=('Ariel', 13),width=16) self.cat.place(x=230, y=270) 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 = ['Name', 'Writer', 'Publisher', 'Catagory'] self.cat['values'] = sortby self.selectbut = Button(self.buy_dis, text='Select', command=self.select,font=('Ariel', 11, 'bold')) self.selectbut.place(x=340, y=300) self.lbl33=Label(self.buy_dis,text='Results:',bg='dark orange1', font=('Ariel', 16, 'bold')) self.lbl33.place(x=650, y=180) self.add_tree = ttk.Treeview(self.buy_dis, column=('n', 'w', 'p', 'm', 'c')) self.add_tree.place(x=600, 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.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.start_tree() self.lbl22 = Label(self.buy_dis, text='*Selected', bg='dark orange1', font=('Ariel', 10, 'bold')) self.lbl22.place(x=130, y=470) self.get1 = Label(self.buy_dis, text='Book :', font=('Ariel', 13, 'bold'), width=9) self.get1.place(x=130, y=500) self.get1 = Label(self.buy_dis, text='Price :', font=('Ariel', 13, 'bold'), width=9) self.get1.place(x=130, y=540) self.get1 = Label(self.buy_dis, text='Dis % :', font=('Ariel', 13, 'bold'), width=9) self.get1.place(x=130, y=580) self.nament = Entry(self.buy_dis, font=('Ariel', 13, 'bold'), width=18) self.nament.place(x=230, y=500) self.priceent = Entry(self.buy_dis, font=('Ariel', 13, 'bold'), width=18) self.priceent.place(x=230, y=540) self.disent = Entry(self.buy_dis, font=('Ariel', 13, 'bold'), width=18) self.disent.place(x=230, y=580) self.addbill = Button(self.buy_dis, text="Calculate", command=self.bills, font=('Ariel', 11, 'bold')) self.addbill.place(x=390, y=620) self.back=Button(self.buy_dis, text="Back", command=self.backbut, bg='green', font=('Ariel', 9, 'bold')) self.back.place(x=1290,y=620) self.buy_dis.mainloop() def select(self): self.ab = AddBooks() user_chosen = self.cat.get() if user_chosen == '': messagebox.showerror('Error', 'Select first') elif user_chosen == 'Name': self.search_ent = Entry(self.buy_dis, text='Keyword', font=('Ariel', 13, 'bold'), width=18) self.search_ent.place(x=230, y=350) self.selectbut = Button(self.buy_dis, text='Search', command=self.tree_byname, font=('Ariel', 11, 'bold')) self.selectbut.place(x=335, y=380) self.search_lbl = Label(self.buy_dis, text='Keyword :', font=('Ariel', 13, 'bold')) self.search_lbl.place(x=130, y=350) # self.lbl22=Label (self.buy_dis, text='*Selected',bg='dark orange1', font=('Ariel', 10, 'bold')) # self.lbl22.place(x=130, y=470) # # self.get1=Label(self.buy_dis, text='Book :',font=('Ariel', 13, 'bold'),width=9) # self.get1.place(x=130, y=500) # # self.get1 = Label(self.buy_dis, text='Price :',font=('Ariel', 13, 'bold'),width=9) # self.get1.place(x=130, y=540) # # self.get1 = Label(self.buy_dis, text='Dis % :',font=('Ariel', 13, 'bold'),width=9) # self.get1.place(x=130, y=580) # # self.nament=Entry(self.buy_dis,font=('Ariel', 13, 'bold'), width=18) # self.nament.place(x=230, y=500) # # # self.priceent = Entry(self.buy_dis,font=('Ariel', 13, 'bold'), width=18) # self.priceent.place(x=230, y=540) # # # self.disent = Entry(self.buy_dis,font=('Ariel', 13, 'bold'), width=18) # self.disent.place(x=230, y=580) # # self.addbill= Button(self.buy_dis, text="Calculate", command=self.bills, font=('Ariel', 11, 'bold')) # self.addbill.place(x=390, y=620) elif user_chosen == 'Writer': self.search_ent = Entry(self.buy_dis, text='Keyword', font=('Ariel', 13, 'bold'), width=18) self.search_ent.place(x=230, y=350) self.selectbut = Button(self.buy_dis, text='Search', command=self.tree_bywriter, font=('Ariel', 11, 'bold')) self.selectbut.place(x=335, y=380) self.search_lbl = Label(self.buy_dis, text='Keyword :', font=('Ariel', 13, 'bold')) self.search_lbl.place(x=130, y=350) # self.lbl22 = Label(self.buy_dis, text='*Selected', bg='dark orange1', font=('Ariel', 10, 'bold')) # self.lbl22.place(x=130, y=470) # # self.get1 = Label(self.buy_dis, text='Book :', font=('Ariel', 13, 'bold'), width=9) # self.get1.place(x=130, y=500) # # self.get1 = Label(self.buy_dis, text='Price :', font=('Ariel', 13, 'bold'), width=9) # self.get1.place(x=130, y=540) # # self.get1 = Label(self.buy_dis, text='Dis % :', font=('Ariel', 13, 'bold'), width=9) # self.get1.place(x=130, y=580) # # self.nament = Entry(self.buy_dis, font=('Ariel', 13, 'bold'), width=18) # self.nament.place(x=230, y=500) # # self.priceent = Entry(self.buy_dis, font=('Ariel', 13, 'bold'), width=18) # self.priceent.place(x=230, y=540) # # self.disent = Entry(self.buy_dis, font=('Ariel', 13, 'bold'), width=18) # self.disent.place(x=230, y=580) # # self.addbill = Button(self.buy_dis, text="Calculate", command=self.bills, font=('Ariel', 11, 'bold')) # self.addbill.place(x=390, y=620) elif user_chosen == 'Publisher': self.search_ent = Entry(self.buy_dis, text='Keyword', font=('Ariel', 13, 'bold'), width=18) self.search_ent.place(x=230, y=350) self.selectbut = Button(self.buy_dis, text='Search', command=self.tree_bypublisher, font=('Ariel', 11, 'bold')) self.selectbut.place(x=335, y=380) self.search_lbl = Label(self.buy_dis, text='Keyword :', font=('Ariel', 13, 'bold')) self.search_lbl.place(x=130, y=350) # self.lbl22 = Label(self.buy_dis, text='*Selected', bg='dark orange1', font=('Ariel', 10, 'bold')) # self.lbl22.place(x=130, y=470) # # self.get1 = Label(self.buy_dis, text='Book :', font=('Ariel', 13, 'bold'), width=9) # self.get1.place(x=130, y=500) # # self.get1 = Label(self.buy_dis, text='Price :', font=('Ariel', 13, 'bold'), width=9) # self.get1.place(x=130, y=540) # # self.get1 = Label(self.buy_dis, text='Dis % :', font=('Ariel', 13, 'bold'), width=9) # self.get1.place(x=130, y=580) # # self.nament = Entry(self.buy_dis, font=('Ariel', 13, 'bold'), width=18) # self.nament.place(x=230, y=500) # # self.priceent = Entry(self.buy_dis, font=('Ariel', 13, 'bold'), width=18) # self.priceent.place(x=230, y=540) # # self.disent = Entry(self.buy_dis, font=('Ariel', 13, 'bold'), width=18) # self.disent.place(x=230, y=580) # # self.addbill = Button(self.buy_dis, text="Calculate", command=self.bills, font=('Ariel', 11, 'bold')) # self.addbill.place(x=390, y=620) elif user_chosen == 'Catagory': values = self.ab.combo() self.search_ent = ttk.Combobox(self.buy_dis, text='Keyword', font=('Ariel', 13, 'bold'), width=16,values=values) self.search_ent.place(x=230, y=350) self.selectbut = Button(self.buy_dis, text='Search', command=self.tree_bycatagory, font=('Ariel', 11, 'bold')) self.selectbut.place(x=335, y=380) self.search_lbl = Label(self.buy_dis, text='Keyword :', font=('Ariel', 13, 'bold')) self.search_lbl.place(x=130, y=350) # self.lbl22 = Label(self.buy_dis, text='*Selected', bg='dark orange1', font=('Ariel', 10, 'bold')) # self.lbl22.place(x=130, y=470) # # self.get1 = Label(self.buy_dis, text='Book :', font=('Ariel', 13, 'bold'), width=9) # self.get1.place(x=130, y=500) # # self.get1 = Label(self.buy_dis, text='Price :', font=('Ariel', 13, 'bold'), width=9) # self.get1.place(x=130, y=540) # # self.get1 = Label(self.buy_dis, text='Dis % :', font=('Ariel', 13, 'bold'), width=9) # self.get1.place(x=130, y=580) # # self.nament = Entry(self.buy_dis, font=('Ariel', 13, 'bold'), width=18) # self.nament.place(x=230, y=500) # # self.priceent = Entry(self.buy_dis, font=('Ariel', 13, 'bold'), width=18) # self.priceent.place(x=230, y=540) # # self.disent = Entry(self.buy_dis, font=('Ariel', 13, 'bold'), width=18) # self.disent.place(x=230, y=580) # # self.addbill = Button(self.buy_dis, text="Calculate", command=self.bills, font=('Ariel', 11, 'bold')) # self.addbill.place(x=390, y=620) else: messagebox.showinfo("No Selection",'Select First!!') def start_tree(self): all_items= self.db.all_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])) self.add_tree.bind("<Double-1>", self.select_item) def tree_byname(self): name = self.search_ent.get() all_items= self.db.searchbyname(name) 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])) self.add_tree.bind("<Double-1>", self.select_item) def tree_bywriter(self): writer = self.search_ent.get() all_items= self.db.searchbywriter(writer) 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])) self.add_tree.bind("<Double-1>", self.select_item) def tree_bypublisher(self): publisher = self.search_ent.get() all_items= self.db.searchbypublisher(publisher) 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])) self.add_tree.bind("<Double-1>", self.select_item) def tree_bycatagory(self): catagory = self.search_ent.get() all_items= self.db.searchbycatagory(catagory) 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])) self.add_tree.bind("<Double-1>", self.select_item) 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.nament.delete(0, 'end') self.nament.insert(0, selected_data[0]) self.priceent.delete(0, 'end') self.priceent.insert(0, selected_data[2]) def bills(self): discount=self.disent.get() if discount == '': messagebox.showerror('Error','Enter discount percentage first!') else: money = float(self.priceent.get()) discount = float(self.disent.get()) self.addbilllbl = Label(self.buy_dis, text='TOTAL: ',font=('Ariel', 15, 'bold'),fg='dark green') self.addbilllbl.place(x=680, y=620) self.addbillent = Entry(self.buy_dis, width=10, bg='black',fg='white',font=('Ariel', 15, 'bold')) self.addbillent.place(x=770, y=620) dis= discount/100 tt= money * dis global total total= money - tt print(total) self.addbillent.insert(0, total) self.bill_button= Button(self.buy_dis, bg='blue', fg='white', command=self.bill_gui, text='Add to Bills',font=('Ariel', 11, 'bold')) self.bill_button.place(x=1100,y=618) def bill_gui(self): self.bill_dis = Tk() self.bill_dis.title('BILLING') self.bill_dis.geometry('600x350') self.bill_dis.configure(bg='sky blue2') self.lbl_ = Label(self.bill_dis, text='ORIENTAL BOOK HOUSE', fg='maroon', bg='sky blue2',font=('Ariel', 15, 'bold')) self.lbl_.place(x=200, y=30) self._lbl = Label(self.bill_dis, text='Estimate Bill', bg='sky blue2', font=('Ariel', 12, 'bold')) self._lbl.place(x=270, y=70) self.date_lbl=Label(self.bill_dis, text='Date: ', bg='sky blue2') self.date_lbl.place(x=445, y=100) self.date_ent = Entry(self.bill_dis, width=10) self.date_ent.place(x=480, y=100) self.cust_name = Label(self.bill_dis, text="Customer's Name ", bg='sky blue2',font=('Ariel', 8, 'bold') ) self.cust_name.place(x=30, y=140) self.cust_phone = Label(self.bill_dis, text="Customer's Phone ", bg='sky blue2', font=('Ariel', 8, 'bold')) self.cust_phone.place(x=150, y=140) self.booki = Label(self.bill_dis, text="Book ", bg='sky blue2', font=('Ariel', 8, 'bold')) self.booki.place(x=295, y=140) self.prici = Label(self.bill_dis, text="Price ", bg='sky blue2', font=('Ariel', 8, 'bold')) self.prici.place(x=390, y=140) self.disc = Label(self.bill_dis, text="discount %", bg='sky blue2', font=('Ariel', 8, 'bold')) self.disc.place(x=430, y=140) self.amt = Label(self.bill_dis, text="Tot. Amount", bg='sky blue2', font=('Ariel', 8, 'bold')) self.amt.place(x=500, y=140) self.cus_name=Entry(self.bill_dis, width=15) self.cus_name.place(x=30, y=170) self.cus_phn = Entry(self.bill_dis, width=15) self.cus_phn.place(x=150, y=170) self.book_ent = Entry(self.bill_dis) self.book_ent.place(x=260, y=170) self.pr_ent = Entry(self.bill_dis,width=6) self.pr_ent.place(x=390, y=170) self.dis_ent = Entry(self.bill_dis,width=6) self.dis_ent.place(x=440, y=170) self.tot_ent = Entry(self.bill_dis,width=10) self.tot_ent.place(x=500, y=170) com=['Bipin','Kishan','Badri','Hari'] self.billby = ttk.Combobox(self.bill_dis, font=('Ariel', 9),width=8, values=com) self.billby.place(x=420, y=270) self.billby_lbl=Label(self.bill_dis,text="Bill by: ") self.billby_lbl.place(x=360,y=270) self.st_button = Button(self.bill_dis, bg='black', fg='white',text='Store',command=self.billdb, font=('Ariel', 10, 'bold')) self.st_button.place(x=520, y=270) money = float(self.priceent.get()) bookss=self.nament.get() discount = float(self.disent.get()) today = date.today() #billcutter= self.app.getname() self.book_ent.insert(0, bookss) self.pr_ent.insert(0, money) self.dis_ent.insert(0, discount) self.tot_ent.insert(0, total) self.date_ent.insert(0,today) #self.billby.insert(0,billcutter) self.bill_dis.mainloop() def billdb(self): cus_name = self.cus_name.get() print(cus_name) cus_phone = self.cus_phn.get() booko = self.book_ent.get() #bookid----methoddatabase price = self.pr_ent.get() bookido = self.bookid(booko, price) discount = self.dis_ent.get() total = self.tot_ent.get() date = self.date_ent.get() book = self.book_ent.get() billby=self.billby.get() if cus_name == '' or cus_phone == '' or price == '' or discount == '' or total== ''or date == '' or billby=='': messagebox.showerror('Error', 'Fill all the entries !!') return False else: self.databill(cus_name,cus_phone,bookido,price,discount, total,date,book,billby) messagebox.showinfo("Done", "Bill Added 😊") def databill(self,cus_name,cus_phone,bookid,price,discount, total,date,book,billby): self.db = MyDb() qry = "INSERT INTO bill (cus_name, cus_phone, book, price, discount, total,date,bookname,bill_by) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s)" values = (cus_name,cus_phone,bookid,price,discount, total,date,book,billby) return self.db.iud(qry, values) def bookid(self,book, price): self.db = MyDb() book = self.book_ent.get() price = self.pr_ent.get() print(book) print(price) qry = '''select id from booksdetail where name=%s and price=%s''' values = (book,price) get= self.db.get_data_i(qry, values) print(type(get)) bipin =int(get[0]) print(type(bipin)) return bipin def backbut(self): self.buy_dis.destroy() # a=BuyBooks() # a.buy_gui()
class SeeBooks: def __init__(self): self.db=MyDb() self.ab=AddBooks() def see_gui(self): self.see_dis = Tk() self.see_dis.title('SEE BOOKS') self.see_dis.geometry('1920x1080+0+0') self.see_dis.configure(bg='purple3') self.lbl111 = Label(self.see_dis, bg='medium purple1', width=600, height=4, font=('Ariel', 15, 'bold')) self.lbl111.place(x=1, y=20) self.lbl113 = Label(self.see_dis, bg='medium purple2', width=60, height=21) self.lbl113.place(x=60, y=250) self.lbl115 = Label(self.see_dis, bg='medium purple1', width=68, height=4) self.lbl115.place(x=1, y=160) self.lbl112 = Label(self.see_dis, text='ORIENTAL BOOK HOUSE',bg='medium purple1',fg='black', font=('Ariel', 19, 'bold')) self.lbl112.place(x=560, y=30) self.lbl112 = Label(self.see_dis, text='Bagbazar, Kathmandu', bg='medium purple1', fg='black', font=('Ariel', 12, 'bold')) self.lbl112.place(x=620, y=75) self.lbl113 = Label(self.see_dis, bg='medium purple1', width=30, height=4) self.lbl113.place(x=580, y=160) self.sort_lbl = Label(self.see_dis, text='Search and Sort Books', bg='medium purple1', 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=['Name', 'Writer', 'Publisher', 'Catagory'] self.cat['values'] = sortby self.selectbut= Button(self.see_dis, text='Select', command=self.select,font=('Ariel', 11, 'bold')) self.selectbut.place(x=340, y=360) self.lbl33 = Label(self.see_dis, text='Results', bg='medium purple1', font=('Ariel', 16, 'bold')) self.lbl33.place(x=650, y=180) self.add_tree = ttk.Treeview(self.see_dis, column=('n', 'w', 'p', 'm', 'c','e','r'),height=15) self.add_tree.place(x=580, 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.start_tree() self.see_dis.mainloop() def select(self): self.ab = AddBooks() user_chosen = self.cat.get() if user_chosen == '': messagebox.showerror('Error', 'Select first') elif user_chosen == 'Name': 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.tree_byname, 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) elif user_chosen == 'Writer': 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.tree_bywriter,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) elif user_chosen == 'Publisher': 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.tree_bypublisher, 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) elif user_chosen == 'Catagory': values=self.ab.combo() self.search_ent = ttk.Combobox(self.see_dis, values=values,font=('Ariel', 13), width=16) self.search_ent.set('--Choose--') self.search_ent.place(x=230, y=400) self.selectbut = Button(self.see_dis, text='Search 🔎', command=self.tree_bycatagory, 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) else: messagebox.showinfo("No Selection",'Select First!!') def tree_byname(self): name = self.search_ent.get() all_items= self.db.searchbyname(name) 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])) def tree_bywriter(self): writer = self.search_ent.get() all_items= self.db.searchbywriter(writer) 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])) def tree_bypublisher(self): publisher = self.search_ent.get() all_items= self.db.searchbypublisher(publisher) 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])) def tree_bycatagory(self): catagory = self.search_ent.get() all_items= self.db.searchbycatagory(catagory) 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])) def start_tree(self): try: all_items=self.db.all_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])) except Exception as e: print(e)