示例#1
0
    def updateContact(self, contact: Contact) -> None:
        with open("contacts.csv", "r") as myContactsFile:
            contactsReader = csv.DictReader(myContactsFile)

            with open("contacts_tmp.csv", "w") as outFile:
                writer = csv.writer(outFile)
                writer.writerow(contactsReader.fieldnames)
                for row in contactsReader:
                    if row["name"] == contact.name():
                        writer.writerow([contact.name(), contact.phoneNumber()])
                        continue
                    writer.writerow([row["name"], row["phone number"]])
                    
        os.remove("contacts.csv")
        os.rename("contacts_tmp.csv", "contacts.csv")
示例#2
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))
示例#3
0
    def create():
        newContact = Contact()
        print(
            "\n================================Add Contact=================================="
        )

        userInput1 = input("\nContact Name : ")
        if not userInput1:
            userInput1 = "No Name"
        newContact.name = userInput1

        userInput2 = input("\nContact Number : ")
        if not userInput2:
            userInput2 = "Unknown"
        newContact.contactNumber = userInput2

        userInput3 = input("\nAddress : ")
        if not userInput3:
            userInput3 = "No Address"
        newContact.address = userInput3

        userInput4 = input("\nEmail : ")
        if not userInput4:
            userInput4 = "Unknown"
        newContact.email = userInput4

        print("\nNew Contact \n{}".format(newContact))

        result = ContactCRUD.insert_contact(newContact)
        print("\n{} records Inserted".format(result))
示例#4
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
示例#5
0
    def addContact(self, contact: Contact) -> None:
        with open("contacts.csv", "r") as inFile:
            reader = csv.reader(inFile)
            with open("contacts_tmp.csv", "w") as outFile:
                writer = csv.writer(outFile)

                for line in reader:
                    writer.writerow(line)
                writer.writerow([contact.name(), contact.phoneNumber()])
        os.remove("contacts.csv")
        os.rename("contacts_tmp.csv", "contacts.csv")
示例#6
0
    def update(self):
        if (self.validateInputs()):
            ct = Contact()
            ct.name = self.inputName.get()
            ct.number = self.inputNumber.get()
            ct.email = self.inputEmail.get()
            ct.idContact = self.hiddenId

            self.labelResult["text"] = ct.updateContact()
            self.cleanInputs()
        else:
            self.labelResult["text"] = "Invalid inputs."
示例#7
0
    def insert(self):
        if (self.validateInputs()):
            ct = Contact()
            ct.name = self.inputName.get()
            ct.number = self.inputNumber.get()
            ct.email = self.inputEmail.get()

            self.labelResult["text"] = ct.insertContact()

            self.cleanInputs()
        else:
            self.labelResult["text"] = "Invalid inputs."
示例#8
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