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))
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))
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
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."
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."
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