def OnPurchasedItemNumberChoice(self, event): indexToDelete = event.GetSelection() purchasedItemNumber = event.GetString() try: row = self.purchases.fetchPurchase \ (self.samdb, purchasedItemNumber) buyerNumber = row[0] winningBid = str(row[1]) if not dialogs.displayYesNoDialog( 'Delete purchase:' + '\n Item number ' + purchasedItemNumber + '\n Buyer number ' + buyerNumber + '\n Winning bid ' + '$' + winningBid): return self.purchases.deletePurchase(self.samdb, purchasedItemNumber) self.purchasedItemNumberList.pop(indexToDelete) self.purchasedItemNumberChoice.SetItems \ (self.purchasedItemNumberList) indexToDelete = \ self.FindItemNumberInItemDescriptionList \ (purchasedItemNumber) self.purchasedItemDescriptionList.pop(indexToDelete) self.purchasedItemDescriptionChoice.SetItems \ (self.purchasedItemDescriptionList) self.con.displayAllPurchases(self.samdb) except MySQLdb.Error, e: dialogs.displayErrorDialog(e.args[1]) return
def OnPurchasedItemDescriptionChoice(self, event): indexToDelete = event.GetSelection() purchasedItemString = event.GetString() purchasedItemNumber = purchasedItemString[:3] if dialogs.displayYesNoDialog('Delete purchase for item number ' + \ purchasedItemNumber + '?'): # Positive buyer number implies that item has been purchased buyerNumber = self.items.checkItemHasBuyer \ (purchasedItemNumber, self.samdb) print 'IN ONPURCHASEDITEMDESCRIPTIONLIST buyerNumber = ', buyerNumber if buyerNumber is None: dialogs.displayErrorDialog \ ('This item has not been purchased.') return else: self.purchases.deletePurchase \ (self.samdb, purchasedItemNumber) self.purchasedItemDescriptionList.pop(indexToDelete) self.purchasedItemDescriptionChoice.SetItems \ (self.purchasedItemDescriptionList) self.purchasedItemNumberList.remove(purchasedItemNumber) self.purchasedItemNumberChoice.SetItems \ (self.purchasedItemNumberList) self.con.displayAllPurchases(self.samdb) else: return
def OnBuyerNameChoice(self, event): indexToDelete = event.GetSelection() buyerString = event.GetString() buyerNumber = buyerString[:3] if dialogs.displayYesNoDialog('Delete buyer number ' + \ buyerNumber + '?'): try: purchasedItems = self.buyers.getBuyersItems \ (self.samdb, buyerNumber) if len(purchasedItems) > 0: errorMessage = self.BuildErrorMessage(buyerNumber,\ purchasedItems) dialogs.displayErrorDialog(errorMessage) return else: self.buyers.DeleteBuyer(self.samdb, buyerNumber) self.buyerNameList.pop(indexToDelete) self.buyerNameChoice.SetItems(self.buyerNameList) self.buyerNumberList.remove(buyerNumber) self.buyerNumberChoice.SetItems(self.buyerNumberList) self.buyerNumberChoice.SetItems(self.buyerNumberList) self.con.displayBuyers(self.samdb) except MySQLdb.Error, e: dialogs.displayErrorDialog(e.args[1]) return except MySQLdb.Warning, e: print("Warning ", e)
def OnDonorNumberChoice(self, event): indexToDelete = event.GetSelection() donorNumber = event.GetString() if dialogs.displayYesNoDialog('Delete donor number ' + \ donorNumber + '?'): try: donatedItems = self.donors.getDonorsItems \ (donorNumber, self.samdb) if len(donatedItems) > 0: errorMessage = self.BuildErrorMessage( donorNumber, donatedItems) dialogs.displayErrorDialog(errorMessage) return else: self.donors.deleteDonor(self.samdb, donorNumber) self.donorNumberList.pop(indexToDelete) self.donorNumberChoice.SetItems(self.donorNumberList) self.DeleteDonorNumberInDonorNameList(donorNumber) self.donorNameChoice.SetItems(self.donorNameList) self.con.displayDonors(self.samdb) return except MySQLdb.Error, e: dialogs.displayErrorDialog(e.args[1]) return except MySQLdb.Warning, e: print("Warning ", e)
def OnItemNumberChoice(self, event): indexToDelete = event.GetSelection() itemNumber = event.GetString() if dialogs.displayYesNoDialog('Delete item number ' + \ itemNumber + '?'): try: buyerNumber = self.items.checkItemHasBuyer \ (itemNumber, self.samdb) # If the item hasn't been purchased, # then the buyerNumber is None if buyerNumber is not None: dialogs.displayErrorDialog \ ('This item has been purchased by ' \ + 'buyer number ' + buyerNumber + '.') return else: self.items.deleteItem(self.samdb, itemNumber) self.itemNumberList.pop(indexToDelete) self.itemNumberChoice.SetItems(self.itemNumberList) indexToDelete = \ self.FindItemNumberInItemDescriptionList(itemNumber) self.itemDescriptionList.pop(indexToDelete) self.itemDescriptionChoice.SetItems \ (self.itemDescriptionList) self.con.displayItems(self.samdb) return except MySQLdb.Error, e: dialogs.displayErrorDialog(e.args[1]) return except MySQLdb.Warning, e: print("Warning ", e)
def __init__(self): wx.Frame.__init__(self, None, -1, title="SAM: the Silent Auction Manager", size=(700, 450)) #self.manePanel = pnl = wx.Panel(self) self.CreateStatusBar() fileMenu = wx.Menu() exitItem = fileMenu.Append(-1, "Exit the program") self.Bind(wx.EVT_MENU, self.onExit, exitItem) aboutMenu = wx.Menu() aboutItem = aboutMenu.Append(-1, "About SAM") self.Bind(wx.EVT_MENU, self.OnAboutDialog, aboutItem) menuBar = wx.MenuBar() menuBar.Append(fileMenu, "File") menuBar.Append(aboutMenu, "About") self.SetMenuBar(menuBar) # Connect to the database connected = False while not connected: connectDialog = connectdialog.ConnectDialog() result = connectDialog.ShowModal() connectDialog.Destroy() if result == wx.ID_OK: try: profile = connectDialog.getProfile() samdb = dbservices.Samdb( dbname = profile['dbName'], \ hostname = profile["hostName"], \ portnumber = int(profile['portNumber']), \ username = profile["userName"], \ password = profile["password"]) connected = True manetoolbook.manetoolbook(self, -1, samdb) except MySQLdb.Error, e: connected = False dialogs.displayErrorDialog("Error %d: %s" % (e.args[0], \ e.args[1])) if not dialogs.displayYesNoDialog("Want to try again?"): exit() else: exit()
def OnDonorNameChoice(self, event): indexToDelete = event.GetSelection() donorString = event.GetString() donorNumber = donorString[:3] if dialogs.displayYesNoDialog('Delete donor number ' + \ donorNumber + '?'): donatedItems = self.donors.getDonorsItems \ (donorNumber, self.samdb) if len(donatedItems) > 0: errorMessage = self.BuildErrorMessage(donorNumber, donatedItems) dialogs.displayErrorDialog(errorMessage) return else: self.donors.deleteDonor(self.samdb, donorNumber) self.donorNameList.pop(indexToDelete) self.donorNameChoice.SetItems(self.donorNameList) self.donorNumberList.remove(donorNumber) self.donorNumberChoice.SetItems(self.donorNumberList) self.donorNumberChoice.SetItems(self.donorNumberList) self.con.displayDonors(self.samdb) else: return
def OnItemDescriptionChoice(self, event): indexToDelete = event.GetSelection() itemString = event.GetString() itemNumber = itemString[:3] if dialogs.displayYesNoDialog('Delete item number ' + \ itemNumber + '?'): # Positive buyer number implies that item has been purchased buyerNumber = self.items.checkItemHasBuyer \ (itemNumber, self.samdb) if buyerNumber is not None: dialogs.displayErrorDialog \ ('This item has been purchased by ' \ + 'buyer number ' + buyerNumber + '.') return else: self.items.deleteItem(self.samdb, itemNumber) self.itemDescriptionList.pop(indexToDelete) self.itemDescriptionChoice.SetItems(self.itemDescriptionList) self.itemNumberList.remove(itemNumber) self.itemNumberChoice.SetItems(self.itemNumberList) #self.itemNumberChoice.SetItems(self.itemNumberList) self.con.displayItems(self.samdb) else: return
def OnExitButton(self, event): if dialogs.displayYesNoDialog('Are you sure you want to exit?'): sys.exit() else: okayButton.SetDefault() return
def onSaveButton(self, event): try: itemNumber = self.itemNumberTC.GetValue() if len(itemNumber) != 3 or \ regularexpression.checkItemNumber(itemNumber) is None: dialogs.displayErrorDialog( "The Item number must be a three-digit decimal number.") return ## Can't add or change the item number to a value ## not in the database. if not self.items.isValidItemNumber(self.samdb, itemNumber): dialogs.displayErrorDialog ('Item number ' + \ itemNumber + ' is not registered.') if self.function == 'edit': self.itemNumberTC.SetValue(self.oldItemNumber) return buyerNumber = self.buyerNumberTC.GetValue() if len(buyerNumber) != 3 or \ regularexpression.checkBuyerNumber(buyerNumber) \ is None: dialogs.displayErrorDialog \ ("The buyer number must be a three-digit decimal number.") return # Can't change buyer number to a value thats not in the database. if not self.buyers.isValidBuyerNumber(self.samdb, buyerNumber): dialogs.displayErrorDialog ('Buyer number ' + \ buyerNumber + ' is not registered.') if self.function == 'edit': self.buyerNumberTC.SetValue(self.oldBuyerNumber) return ### ENSURE THAT THE SAME ITEM CANt BE PURCHASED BY TWO BUYERS!!! if self.function == 'add': otherBuyerNumber = self.items.checkItemHasBuyer \ (itemNumber, self.samdb) if otherBuyerNumber is not None: dialogs.displayErrorDialog ('Item number ' + itemNumber + \ ' has already been purchased by buyer ' + \ otherBuyerNumber) self.itemNumberTC.Clear() return ''' Don't know why this is here elif self.function == 'edit': self.buyerNumberTC.SetValue(self.oldBuyerNumber) ''' winningBid = self.winningBidTC.GetValue() if len(winningBid) == 0 or \ regularexpression.checkMoney(winningBid) == False: dialogs.displayErrorDialog \ ("The winning bid must be a decimal number "\ + "greater than zero.") return ''' Now that all the data are valid, we can do the most straightforward task, which is to purchase the item. ''' if self.function == 'add': self.purchases.purchaseItem(self.samdb, itemNumber, \ buyerNumber, winningBid) self.clearAll() return ## It's a bit trickier for editing because we can't change ## the item number to a nonexistent value (already chaecked) ## or to the number of an item already purchased if self.function == 'edit': if not itemNumber == self.oldItemNumber: ## if new item number is registered and not purchased, ## then it's okay to change to new item number if self.purchases.hasBeenPurchased \ (self.samdb, itemNumber): dialogs.displayErrorDialog \ ('Item number ' + itemNumber + \ ' has already been purchased.') self.itemNumberTC = self.oldItemNumber return if not dialogs.displayYesNoDialog( 'Change purchase to ' + '\n Item number ' + itemNumber + '\n Buyer number ' + buyerNumber + '\n Winning bid ' + '$' + winningBid): self.clearAll() return if self.function == 'edit' and \ itemNumber == self.oldItemNumber: self.purchases.purchaseItem(self.samdb, itemNumber, \ buyerNumber, winningBid) else: ### Item number changes so delete, add, and update chooser self.purchases.deletePurchase(self.samdb, self.oldItemNumber) self.purchases.purchaseItem(self.samdb, itemNumber, \ buyerNumber, winningBid) self.parent.buildPurchasedItemChooser(self.samdb) # Write all fields for the affected item number. self.clearAll() self.con.displayAllPurchases(self.samdb) except MySQLdb.Error, e: dialogs.displayErrorDialog(e.args[1]) return