def clickSearch(self): if not Validator.isEmpty(self.txtEntry) and \ Validator.isSanitized(self.txtEntry): dbm=DatabaseModel() lineItems= dbm.getAllLineItemObjects() if self.radioVar == 1: text = self.txtEntry.get() #self.cursor.execute('SELECT * FROM lineItems WHERE variable1=?', text) for stuff in lineItems: if text in str(stuff): print(stuff)
class AddRemoveView(Frame): db = None MAXLENGTH20 = 20 def __init__(self, master=None): Frame.__init__(self, master) self.db = DatabaseModel() self.grid() self.master.title("Add/Remove") #add widgets self.widgetsAddNewGame() self.widgetsRemoveGame() self.widgetsAddMerchandise() self.widgetsRemoveMerchandise() self.widgetsAddLineItem() self.widgetsRemoveLineItem() #add back to menu button self.btnMenu = Button(self) self.btnMenu["text"] = "Return" self.btnMenu["command"] = self.clickBackToMenu self.btnMenu.grid(row=9, column=3, sticky=W+S) #add quit button self.btnQuit = Button(self) self.btnQuit["text"] = "QUIT" self.btnQuit["command"] = self.clickQuit self.btnQuit.grid(row=10, column=3, sticky=W+S) def clickBackToMenu(self): States.selection = States.MAINVIEW self.quit() def clickQuit(self): States.selection = States.QUIT self.quit() def widgetsAddNewGame(self): self.lblfrmAddNewGame = LabelFrame(self, text="Add New Game") self.lblfrmAddNewGame.grid(row=0, column=0, sticky='WE', padx=5, pady=5, ipadx=5, ipady=5) self.lblAddGameOpponentName = Label(self.lblfrmAddNewGame, text="Opponent: ") self.lblAddGameOpponentName.grid(row=0, column=0) self.txtAddGameOpponentName = Entry(self.lblfrmAddNewGame, bg="beige", width=30) self.txtAddGameOpponentName.grid(row=0, column=1) self.lblAddGameOpponentDate = Label(self.lblfrmAddNewGame, text="Date(xx/xx/xxxx): ") self.lblAddGameOpponentDate.grid(row=1, column=0) self.txtAddGameOpponentDate = Entry(self.lblfrmAddNewGame, bg="beige", width=15) self.txtAddGameOpponentDate.grid(row=1, column=1) self.lblAddGameOpponentHome = Label(self.lblfrmAddNewGame, text="Home: ") self.lblAddGameOpponentHome.grid(row=2, column=0) self.varChkBxAddGameOpponentHome = IntVar() self.chkBxAddGameOpponentHome = Checkbutton(self.lblfrmAddNewGame, text="", var=self.varChkBxAddGameOpponentHome) self.chkBxAddGameOpponentHome.grid(row=2, column=1) self.btnAddGame = Button(self.lblfrmAddNewGame, text="Add Game") self.btnAddGame.grid(row=1, column=3) self.btnAddGame["command"] = self.clickAddGame def widgetsRemoveGame(self): self.lblfrmRemoveGame = LabelFrame(self, text="Remove Game") self.lblfrmRemoveGame.grid(row=1, column=0, sticky='WE', padx=5, pady=5, ipadx=5, ipady=5) self.lstBxRemoveGame = Listbox(self.lblfrmRemoveGame, width=50, height=5, exportselection=0) self.lstBxRemoveGame.grid(row=0, column=0, columnspan=2) self.btnRemoveGame = Button(self.lblfrmRemoveGame, text="Delete Game") self.btnRemoveGame.grid(row=0, column=3) self.btnRemoveGame["command"] = self.clickRemoveGame self.scrllbrRemoveGame = Scrollbar(self.lblfrmRemoveGame, orient=VERTICAL) self.scrllbrRemoveGame.grid(row=0, column=2, sticky=N+S) self.lstBxRemoveGame.config(yscrollcommand=self.scrllbrRemoveGame.set) self.scrllbrRemoveGame.config(command=self.lstBxRemoveGame.yview) self.updateListBoxGames(self.lstBxRemoveGame) def widgetsAddMerchandise(self): self.lblfrmAddMerchandise = LabelFrame(self, text="Add Merchandise") self.lblfrmAddMerchandise.grid(row=2, column=0, sticky='WE', padx=5, pady=5, ipadx=5, ipady=5) self.lblAddMerchandiseName = Label(self.lblfrmAddMerchandise, text="Name: ") self.lblAddMerchandiseName.grid(row=0, column=0) self.txtAddMerchandiseName = Entry(self.lblfrmAddMerchandise, bg="beige", width=20) self.txtAddMerchandiseName.grid(row=0, column=1) self.lblAddMerchandiseDescription = Label(self.lblfrmAddMerchandise, text="Description: ") self.lblAddMerchandiseDescription.grid(row=1, column=0) self.txtAddMerchandiseDescription = Entry(self.lblfrmAddMerchandise, bg="beige", width=30) self.txtAddMerchandiseDescription.grid(row=1, column=1) self.lblAddMerchandisePrice = Label(self.lblfrmAddMerchandise, text="Price (xx.xx): ") self.lblAddMerchandisePrice.grid(row=2, column=0) self.txtAddMerchandisePrice = Entry(self.lblfrmAddMerchandise, bg="beige", width=10) self.txtAddMerchandisePrice.grid(row=2, column=1) self.btnAddMerchandise = Button(self.lblfrmAddMerchandise, text="Add Merchandise") self.btnAddMerchandise.grid(row=1, column=3) self.btnAddMerchandise["command"] = self.clickAddMerchandise def widgetsRemoveMerchandise(self): self.lblfrmRemoveMerchandise = LabelFrame(self, text="Remove Merchandise") self.lblfrmRemoveMerchandise.grid(row=3, column=0, sticky='WE', padx=5, pady=5, ipadx=5, ipady=5) self.lstBxRemoveMerchandise = Listbox(self.lblfrmRemoveMerchandise, width=50, height=5, exportselection=0) self.lstBxRemoveMerchandise.grid(row=0, column=0, columnspan=2) self.btnRemoveMerchandise = Button(self.lblfrmRemoveMerchandise, text="Delete Merchandise") self.btnRemoveMerchandise.grid(row=0, column=3) self.btnRemoveMerchandise["command"] = self.clickRemoveMerchandise self.scrllbrRemoveMerchandise = Scrollbar(self.lblfrmRemoveMerchandise, orient=VERTICAL) self.scrllbrRemoveMerchandise.grid(row=0, column=2, sticky=N+S) self.lstBxRemoveMerchandise.config(yscrollcommand=self.scrllbrRemoveMerchandise.set) self.scrllbrRemoveMerchandise.config(command=self.lstBxRemoveMerchandise.yview) self.updateListBoxMerchandises(self.lstBxRemoveMerchandise) def widgetsAddLineItem(self): self.lblfrmAddLineItem = LabelFrame(self, text="Add Line Item") self.lblfrmAddLineItem.grid(row=0, column=1, sticky='WE', padx=5, pady=5, ipadx=5, ipady=5, rowspan=2) #Games self.lstBxAddLineItemGame = Listbox(self.lblfrmAddLineItem, width=50, height=5, exportselection=0) self.lstBxAddLineItemGame.grid(row=0, column=0, columnspan=2) self.scrllbrAddLineItemGame = Scrollbar(self.lblfrmAddLineItem, orient=VERTICAL) self.scrllbrAddLineItemGame.grid(row=0, column=2, sticky=N+S) self.lstBxAddLineItemGame.config(yscrollcommand=self.scrllbrAddLineItemGame.set) self.scrllbrAddLineItemGame.config(command=self.lstBxAddLineItemGame.yview) self.updateListBoxGames(self.lstBxAddLineItemGame) #Merchandise self.lstbxAddLineItemMerchandise = Listbox(self.lblfrmAddLineItem, width=50, height=5, exportselection=0) self.lstbxAddLineItemMerchandise.grid(row=1, column=0, columnspan=2) self.scrllbrAddLineItemMerchandise = Scrollbar(self.lblfrmAddLineItem, orient=VERTICAL) self.scrllbrAddLineItemMerchandise.grid(row=1, column=2, sticky=N+S) self.lstbxAddLineItemMerchandise.config(yscrollcommand=self.scrllbrAddLineItemMerchandise.set) self.scrllbrAddLineItemMerchandise.config(command=self.lstbxAddLineItemMerchandise.yview) self.updateListBoxMerchandises(self.lstbxAddLineItemMerchandise) #Button self.btnAddLineItem = Button(self.lblfrmAddLineItem, text="AddLineItem") self.btnAddLineItem.grid(row=0, column=4) self.btnAddLineItem["command"] = self.clickAddLineItem def widgetsRemoveLineItem(self): self.lblfrmRemoveLineItem = LabelFrame(self, text="Remove LineItem") self.lblfrmRemoveLineItem.grid(row=2, column=1, sticky='WE', padx=5, pady=5, ipadx=5, ipady=5) self.lstbxRemoveLineItem = Listbox(self.lblfrmRemoveLineItem, width=50, height=5, exportselection=0) self.lstbxRemoveLineItem.grid(row=0, column=0, columnspan=2) self.btnRemoveLineItem = Button(self.lblfrmRemoveLineItem, text="Delete Line Item") self.btnRemoveLineItem.grid(row=0, column=3) self.btnRemoveLineItem["command"] = self.clickRemoveLineItem self.scrllbrRemoveMerchandise = Scrollbar(self.lblfrmRemoveLineItem, orient=VERTICAL) self.scrllbrRemoveMerchandise.grid(row=0, column=2, sticky=N+S) self.lstbxRemoveLineItem.config(yscrollcommand=self.scrllbrRemoveMerchandise.set) self.scrllbrRemoveMerchandise.config(command=self.lstbxRemoveLineItem.yview) self.updateListBoxLineItems(self.lstbxRemoveLineItem) def clickAddGame(self): if not Validator.isEmpty(self.txtAddGameOpponentName) and \ Validator.isLessThanNCharacters(self.txtAddGameOpponentName, self.MAXLENGTH20) and \ not Validator.isEmpty(self.txtAddGameOpponentDate) and \ Validator.isDate(self.txtAddGameOpponentDate) and \ Validator.isSanitized(self.txtAddGameOpponentName) and \ Validator.isSanitized(self.txtAddGameOpponentDate): opponentName = self.txtAddGameOpponentName.get() dateOfGame = self.txtAddGameOpponentDate.get() home = self.varChkBxAddGameOpponentHome.get() self.db.insertGame(opponentName, dateOfGame, home) self.refreshGameListBoxes() def clickRemoveGame(self): gameSelection = self.lstBxRemoveGame.curselection() if(len(gameSelection) > 0 ): gameSelection = gameSelection[0] selectedGame = self.lstBxAddLineItemGame.get(gameSelection) gameID = int(str(selectedGame).split(' ')[0][1]) self.db.deleteGame(gameID) self.refreshGameListBoxes() self.refreshAllListboxes() def clickAddMerchandise(self): #Validate if not Validator.isEmpty(self.txtAddMerchandisePrice) and \ not Validator.isEmpty(self.txtAddMerchandiseDescription) and \ not Validator.isEmpty(self.txtAddMerchandiseName) and \ Validator.isCurrency(self.txtAddMerchandisePrice) and \ Validator.isLessThanNCharacters(self.txtAddMerchandiseName, self.MAXLENGTH20) and \ Validator.isLessThanNCharacters(self.txtAddMerchandiseDescription, self.MAXLENGTH20) and \ Validator.isSanitized(self.txtAddMerchandiseDescription) and \ Validator.isSanitized(self.txtAddMerchandiseName) and \ Validator.isSanitized(self.txtAddMerchandisePrice): #get values name = self.txtAddMerchandiseName.get() description = self.txtAddMerchandiseDescription.get() price = float(self.txtAddMerchandisePrice.get()) #Insert into Database self.db.insertMerchandise(name, description, price) #refresh views self.refreshMerchandiseListBoxes() def clickRemoveMerchandise(self): merchSelection = self.lstBxRemoveMerchandise.curselection() if(len(merchSelection) > 0 ): merchSelection = merchSelection[0] selectdMerch = self.lstBxRemoveMerchandise.get(merchSelection) merchID = int(str(selectdMerch).split(' ')[0][1]) #update DB self.db.deleteMerchandise(merchID) #refresh all things self.refreshAllListboxes() def clickAddLineItem(self): #validate that both text boxes have selections gameSelection = self.lstBxAddLineItemGame.curselection() merchandiseSelection = self.lstbxAddLineItemMerchandise.curselection() if(len(gameSelection) > 0 and len(merchandiseSelection) > 0): gameSelection = gameSelection[0] merchandiseSelection = merchandiseSelection[0] selectedGame = self.lstBxAddLineItemGame.get(gameSelection) selectedMerchandise = self.lstbxAddLineItemMerchandise.get(merchandiseSelection) gameID = int(str(selectedGame).split(' ')[0][1]) merchandiseID = int(str(selectedMerchandise).split(' ')[0][1]) #send new line item information to db self.db.insertLineItem(gameID, merchandiseID) #refresh views self.refreshLineItemListBox() def clickRemoveLineItem(self): lineItemSelection = self.lstbxRemoveLineItem.curselection() if(len(lineItemSelection) > 0): lineItemSelection = lineItemSelection[0] selectedLineItem = self.lstbxRemoveLineItem.get(lineItemSelection) lineItemID = int(str(selectedLineItem).split(' ')[0][1]) #update DB self.db.deleteLineItem(lineItemID) #refresh all things self.refreshAllListboxes() def updateListBoxGames(self, listBox): listBox.delete(0, END) games = self.db.getAllGamesObjects() for game in games: listBox.insert(END, game) def updateListBoxMerchandises(self, listBox): listBox.delete(0, END) merchandises = self.db.getAllMerchandiseObjects() for merch in merchandises: listBox.insert(END, merch) def updateListBoxLineItems(self, listBox): listBox.delete(0, END) lineItems = self.db.getAllLineItemObjects() for lineitem in lineItems: listBox.insert(END, lineitem) def refreshGameListBoxes(self): self.updateListBoxGames(self.lstBxRemoveGame) self.updateListBoxGames(self.lstBxAddLineItemGame) def refreshMerchandiseListBoxes(self): self.updateListBoxMerchandises(self.lstBxRemoveMerchandise) self.updateListBoxMerchandises(self.lstbxAddLineItemMerchandise) def refreshLineItemListBox(self): self.updateListBoxLineItems(self.lstbxRemoveLineItem) def refreshAllListboxes(self): self.refreshGameListBoxes() self.refreshMerchandiseListBoxes() self.refreshLineItemListBox()