Пример #1
0
def connect(argv):
    try:
        if len(sys.argv) == 6:
            samdb = dbservices.Samdb(dbname=argv[1],
                                     hostname=argv[2],
                                     portnumber=int(argv[3]),
                                     username=argv[4],
                                     password=argv[5])
        else:
            samdb = dbservices.Samdb(dbname=argv[1])
    except MySQLdb.Error, e:
        print "testConnectAndPopulate.Connect: Error %d: %s" % \
                (e.args[0], e.args[1])
        exit(1)
Пример #2
0
def testConnectAndPopulate():

    profile = profileservices.getProfile()
    samdb = dbservices.Samdb(profile['dbName'], profile['hostName'],
                             int(profile['portNumber']), profile['userName'],
                             profile['password'])
    samdb.useDatabase(profile['dbName'])
    ## Create objects for Auction, Donors, Buyers, Items, and Purchases
    da = auction.Auction()
    dd = donors.Donors()
    db = buyers.Buyers()
    di = items.Items()
    dp = purchases.Purchases()
    populate(samdb, da, dd, db, di, dp)
Пример #3
0
def createAuction(hname, pnumber, uname, pword, \
                  dbnam, title, subtitle, date):
    print 'ENTERED CREATE AUCTION'
    print hname, pnumber, uname, pword, dbnam, title, subtitle, date
    try:
        samdb = dbservices.Samdb(dbname='mysql',
                                 hostname=hname,
                                 portnumber=int(pnumber),
                                 username=uname,
                                 password=pword)
        doEverything(samdb, dbnam, title, subtitle, date)
    except MySQLdb.Error, e:
        print "createAuction.createAuction: Error %d: %s" % \
                (e.args[0], e.args[1])
        sys.exit(1)
Пример #4
0
    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()
Пример #5
0
    return


if __name__ == '__main__':
    if not (len(sys.argv) == 2 or len(sys.argv) == 6):
        print 'Usage: python createauction.py dbname ' + \
              '[hostname portnumber username password]'
    else:
        try:
            ''' 'mysql' is the database that's always there 
                so connect to it when instantiating Samdb '''
            if len(sys.argv) == 6:
                samdb = dbservices.Samdb(dbname='mysql',
                                         hostname=sys.argv[2],
                                         portnumber=int(sys.argv[3]),
                                         username=sys.argv[4],
                                         password=sys.argv[5])
            else:
                samdb = dbservices.Samdb(dbname='mysql')

            doEverything(samdb, sys.argv[1],
                         'WNC Returned Peace Corps Volunteers',
                         'Working to improve the world community',
                         'September 14, 2011')
        except MySQLdb.Error, e:
            print "createAuction.createAuction: Error %d: %s" % \
                    (e.args[0], e.args[1])
            sys.exit(1)
        except MySQLdb.Warning, e:
            print("createAuction.createAuction: Warning: ", e)
Пример #6
0
        row = samdb.fetchRow(query)
        return row[0]

    def getAuctionDate(self, samdb):
        query = "SELECT auction_header_text \
                FROM Auction WHERE auction_header_type = 'date' ;"

        row = samdb.fetchRow(query)
        return row[0]


# Run the program
if __name__ == '__main__':
    if len(sys.argv) < 2:
        print 'Usage: python auction.py dbname'
    else:
        try:
            samdb = dbservices.Samdb(dbname='mysql')
            dbname = sys.argv[1]
            print('Now create ' + dbname + ';')
            samdb.createDatabase(dbname)
            print(dbname + ' created.')
            auction = Auction()
            auction.createAuctionTable(samdb)
        except MySQLdb.Error, e:
            print "Error %d: %s" % (e.args[0], e.args[1])
            sys.exit(1)
        except MySQLdb.Warning, e:
            print("Warning: ", e)
Пример #7
0
    # Confirm whether a donor number is in the database.
    def isValidDonorNumber(self, samdb, donorNumber):
        query = "SELECT donor_name FROM Donors \
                WHERE donor_number = '" + donorNumber + "' ; "
        rows = samdb.fetchRows(query)
        if len(rows) > 0:
            return True
        else:
            return False

    def getDonorsItems(self, donorNumber, samdb):
        query = 'SELECT item_number FROM Items WHERE item_donatedby = ' \
                + donorNumber + ';'
        items = samdb.fetchRows(query)
        itemList = []
        for item in items:
            itemList.append(item[0])
        return itemList

    def getAllDonors(self, samdb):
        query = 'SELECT donor_number FROM Donors ORDER BY donor_number'
        allDonors = samdb.fetchRows(query)
        return allDonors


if __name__ == '__main__':
    samdb = dbservices.Samdb()
    samdb.createDatabase()
    dt = Donors()
    dt.createDonorsTable(samdb)
    print("CREATED THE DONORS TABLE")