Beispiel #1
0
    def save_contact_in_db(self):
        first_name = self.first_name.get().strip().lower().capitalize()
        last_name = self.last_name.get().strip().lower().capitalize()
        phone = self.phone_number.get().strip()
        email = self.email_id.get().strip()

        temp_contact = [(contact[0] + ' ' + contact[1])
                        for contact in self.contacts]

        if (first_name == '' or first_name == 'This field is required'
                or phone == '' or phone == 'This field is required'):
            messagebox.showerror('CMS', 'Fill in the Mandatory Fields')
        elif len(phone) != 10:
            messagebox.showerror('CMS', 'Enter 10 digit phone number')
        elif email and not valid_email(email):
            messagebox.showerror('CMS', 'Invalid email')
        else:
            if self.is_new_contact:
                if (first_name + ' ' + last_name) in temp_contact:
                    messagebox.showerror(
                        'CMS',
                        'Contact with this name already\nexist, edit & try again'
                    )
                else:
                    status = sql_operations.insert_item(
                        [first_name, last_name, phone, email])
                    if status == 'success':
                        messagebox.showinfo('CMS', 'Contact Saved')
                    else:
                        messagebox.showerror('CMS', 'An error Occured')

                    self.contacts = sql_operations.fetch_all_result()
                    self.data = (first_name, last_name, phone, email)
                    self.show_contact()
            else:
                status = sql_operations.delete_item(self.prev[0], self.prev[1])
                if status == 'success':
                    status = sql_operations.insert_item(
                        [first_name, last_name, phone, email])
                    if status == 'success':
                        messagebox.showinfo('CMS', 'Contact Saved')
                    else:
                        messagebox.showerror('CMS', 'An error Occured')

                    self.contacts = sql_operations.fetch_all_result()
                    self.data = (first_name, last_name, phone, email)
                    self.prev = self.data
                    self.show_contact()
	def __init__(self, master=None):
		super().__init__(master=master)
		self.master=master
		self.pack()

		self._attributes()
		self.contacts = sql_operations.fetch_all_result()

		self.draw_header_frames()
		self.draw_all_contact_frame()
	def delete_contact(self):
		status = sql_operations.delete_item(self.data[0], self.data[1])
		if status == 'success':
			messagebox.showinfo('CMS', 'Contact deleted')
		else:
			messagebox.showerror('CMS', 'An error Occured')

		self.contacts = sql_operations.fetch_all_result()
		self.data = None
		self.on_home = True
		self.go_back()