def update_office(self): self.old_office_name = self.main.old_office_name_variable.get() self.editted_office_entry = self.main.editted_office_name.get().split( ' ') self.editted_office_article = latin_to_greek( self.editted_office_entry[0]) self.editted_office_name = latin_to_greek(' '.join( self.editted_office_entry[1:])) self.editted_office_type_string = self.main.edit_office_type_variable.get( ) self.editted_office_type = self.main.type_list.index( self.editted_office_type_string) + 1 if os.path.isfile(self.db): try: con = lite.connect(self.db) with con: cur = con.cursor() sql = 'UPDATE entries SET office_name=?, office_type=?, office_article=? WHERE office_name =?;' cur.execute( sql, (self.editted_office_name, self.editted_office_type, self.editted_office_article, self.old_office_name)) cur.execute('COMMIT;') #self.seach_tup = self.create_office_search_tup('search') TO BE REMOVED AFTER TESTING #self.main.office_name_search.configure(values=self.seach_tup) TO BE REMOVED AFTER TESTING self.main.edit_office_window.destroy() messagebox.showinfo('Επεξεργασία Αρχής', f'Επιτυχής επεξεργασία Αρχής!') except Exception as e: print(e)
def get_search_pars(self): self.id_number_search = latin_to_greek( self.id_number_search_entry.get().upper().strip()) self.surname_search = latin_to_greek( self.surname_search_entry.get().upper().strip()) self.office_name_search_selection = self.office_name_search_variable.get( ) self.sort_by = self.sort_by_variable.get() data.create_search_results()
def insert_update_entry(self): self.main.id_number = latin_to_greek( self.main.edit_id_number.get().upper().strip()) self.main.surname = latin_to_greek( self.main.edit_surname.get().upper().strip()) self.main.name = latin_to_greek(self.main.edit_name.get().strip()) self.main.reason = self.main.edit_reason_variable.get() self.main.edit_office_name = self.main.edit_office_name_variable.get() self.main.protocol_num = self.main.edit_protocol_num.get() try: self.protocol_date_string = self.main.edit_protocol_date.get() self.main.protocol_date = datetime_formatter( self.protocol_date_string, self.app_date_str, self.data_date_str) except: self.main.protocol_date = self.main.edit_protocol_date.get() proceed = self.main.field_check('edit') if proceed: self.main.edit_window.destroy() if os.path.isfile(self.db): try: con = lite.connect(self.db) with con: cur = con.cursor() sql = f'SELECT office_type, office_article FROM entries WHERE office_name = "{self.main.edit_office_name}" LIMIT 1' cur.execute(sql) results = cur.fetchall() self.edit_office_type = results[0][0] self.edit_office_article = results[0][1] sql = 'UPDATE entries SET id_number=?, surname=?, name=?, reason=?, office_type =?, office_article =?, office_name=?, protocol_num=?, protocol_date=? WHERE id_number = ?;' cur.execute( sql, (self.main.id_number, self.main.surname, self.main.name, self.main.reason, self.edit_office_type, self.edit_office_article, self.main.edit_office_name, self.main.protocol_num, self.main.protocol_date, self.main.id_selection)) cur.execute('COMMIT;') self.create_search_results() self.main.disable_widgets( [self.main.delete_button, self.main.edit_button]) messagebox.showinfo('Επεξεργασία Εγγραφής', f'Επιτυχής επεξεργασία εγγραφής!') except Exception as e: print(e)
def new_office_entry(self): self.new_office_type_key = list(self.office_dict.keys())[list( self.office_dict.values()).index( self.new_office_type_variable.get())] self.user_office_entry = self.new_office_name.get().split(' ') self.office_article = latin_to_greek(self.user_office_entry[0]) self.office_tup = (latin_to_greek(' '.join( self.user_office_entry[1:]).strip(' ')), ) if self.office_tup[0] == '': self.new_office_error = True messagebox.showerror( 'Σφάλμα!', 'Το όνομα της Αρχής δεν μπορεί να είναι κενό!') else: self.new_office_error = False if not self.new_office_error: self.office_variable.set(self.new_office_type_key) self.office_name_combo.config(values=self.office_tup) self.office_name_combo.current(0) self.protocol_num_entry.delete(0, 'end') self.protocol_date_entry.delete(0, 'end') self.new_office_window.destroy()
def field_check(self, check_reason): self.error = False self.error_message = '' if self.reason == '': self.error = True self.error_message += '\n- Δώστε αιτία ακύρωσης!' if self.id_number == '': self.error = True self.error_message += '\n- Δώστε αριθμό δελτίου!' elif not ((self.id_number[0].isalpha() and self.id_number[1:].isdecimal() and len(self.id_number)==7)\ or (self.id_number[0:2].isalpha() and self.id_number[2:].isdecimal() and len(self.id_number) == 8)): self.error = True self.error_message += '\n- Δώστε σωστό αριθμό δελτίου!' if self.surname == '': self.error = True self.error_message += '\n- Δώστε επώνυμο!' if self.name == '': self.error = True self.error_message += '\n- Δώστε όνομα!' if check_reason == 'new': if self.office_type == 0: self.error = True self.error_message += '\n- Δώστε είδος Αρχής του εγγράφου!' if self.office_name == 'Επιλέξτε από τη λίστα...': self.error = True self.error_message += '\n- Διαλέξτε Προξενική/Λιμενική Αρχή!' if check_reason == 'edit': if self.edit_office_name == 'Επιλέξτε από τη λίστα...': self.error = True self.error_message += '\n- Διαλέξτε Προξενική/Λιμενική Αρχή!' try: self.protocol_date_object = datetime.strptime( self.protocol_date, self.data_date_str) if self.protocol_date_object > datetime.today(): self.error = True self.error_message += '\n- Η ημερομηνία πρωτοκόλλου δεν μπορεί να είναι μεταγενέστερη της σημερινής!' except: if not self.protocol_date == '': self.error = True self.error_message += '\n- Δώστε σωστή μορφή ημερομηνίας πρωτοκόλλου! π.χ. 24/03/2020' if not self.error: self.id_number = latin_to_greek(self.id_number) self.surname = latin_to_greek(self.surname) self.name = final_s_checker(latin_to_greek(self.name)) if check_reason == 'new': self.office_name = latin_to_greek(self.office_name) self.office_article = latin_to_greek(self.office_article) self.save_to_db = data.save_to_database() if self.save_to_db: self.create_button.grid_forget() self.new_button.grid(row=0, column=0, sticky='ns') self.disable_widgets([ self.f1_1, self.f1_2, self.f1_3_1, self.f1_3_2, self.f1_4, self.f1_4_1 ]) word.create_text_variables() else: messagebox.showerror( 'Σφάλμα!', f'Υπάρχει ήδη δελτίο ταυτότητας με αριθμό {self.id_number} καταχωριμένο στη βάση!' ) elif check_reason == 'edit': return True else: messagebox.showerror('Σφάλμα!', self.error_message.strip('\n'))