Ejemplo n.º 1
0
    def update():
        selectedContact = Main.selectContact()

        uContact = Contact()
        uContact.id = selectedContact.id

        print(
            "\n================================Update Contact=================================="
        )

        userInput1 = input("\nName : ")
        if not userInput1:
            userInput1 = selectedContact.name
        uContact.name = userInput1

        userInput2 = input("\nContact Number : ")
        if not userInput2:
            userInput2 = selectedContact.contactNumber
        uContact.contactNumber = userInput2

        userInput3 = input("\nAddress : ")
        if not userInput3:
            userInput3 = selectedContact.address
        uContact.address = userInput3

        userInput4 = input("\nEmail : ")
        if not userInput4:
            userInput4 = selectedContact.email
        uContact.email = userInput4

        result = ContactCRUD.update(uContact)
        print("\n{} records Updated".format(result))
Ejemplo n.º 2
0
 def getAllContacts():
     '''
         getAllContacts() method tom fetch All contacts from DB.
         Returns Contacts as list of Objects(Contact)
     '''
     contactList = []
     try:
         con = DBConnection.get_connection()  #Getting DB connection
         cur = con.cursor(dictionary=True)
         if cur != None:
             cur.execute(Queries.ALL)
             for contct in cur:
                 c = Contact()
                 c.id = contct['contact_id']
                 c.name = contct['contact_name']
                 c.address = contct['contact_address']
                 c.contactNumber = contct['contact_number']
                 c.email = contct['contact_email']
                 contactList.append(c)
     except (mysql.Error, mysql.Warning) as e:
         print("error in operation")
         print(e)
     finally:
         con.close()
         return contactList
Ejemplo n.º 3
0
 def search(str):
     query = Queries.SEARCH
     contactList = []
     try:
         con = DBConnection.get_connection()
         cur = con.cursor(dictionary=True)
         data = (str, str, str, str)
         if cur != None:
             cur.execute(query, data)
             for contct in cur:
                 c = Contact()
                 c.id = contct['contact_id']
                 c.name = contct['contact_name']
                 c.address = contct['contact_address']
                 c.contactNumber = contct['contact_number']
                 c.email = contct['contact_email']
                 contactList.append(c)
     except (mysql.Error, mysql.Warning) as e:
         print("error in operation")
         print(e)
     finally:
         con.close()
         return contactList