def add_item(): item_name = name_entry.get() item_name = item_name.upper() item_name = item_name.translate({ord(c): None for c in ' \n\t\r'}) if item_name == "": messagebox.showerror( "Błąd", 'Pole "' + constants.ADD_NAME_LABEL_TEXT + '" nie może być puste.') else: item_description = description_entry.get() item_description = item_description.translate( {ord(c): None for c in '\n\t\r'}) item_type = chosen_type.get() if item_type == "": messagebox.showerror("Błąd", "Wybierz rodzaj obiektu.") else: now = generaldefinitions.get_time() notes = constants.ADD_ITEM_INFO + now sql_insert_values = (item_name, item_type, item_description, notes, now) connection = plkdatabase.create_connection(constants.DB_NAME) if connection is not None: id = plkdatabase.add_item(connection, sql_insert_values) if id is not None: messagebox.showinfo("Info", "Zapis dodano do bazy") connection.close() update_tree_list()
def change_item_description(): item_name = plk_tree.item(plk_tree.selection())["text"] if item_name not in constants.DB_TYPE_NAME_LIST: change_description = messagebox.askquestion("Info", "Zmienić opis?") if change_description == "yes": new_description = simpledialog.askstring("Info", "Podaj nowy opis dla " + item_name + '.', parent=main_window) connection = plkdatabase.create_connection(constants.DB_NAME) if connection is not None: old_description = plkdatabase.get_description( connection, item_name)[0][0] plkdatabase.update_description(connection, item_name, new_description) now = generaldefinitions.get_time() info = constants.CHANGE_DESCRIPTION_INFO + now + " z [" + old_description + "] na [" + new_description + "]. \n" notes = plkdatabase.get_notes(connection, item_name)[0][0] notes = info + notes plkdatabase.update_notes(connection, item_name, notes) plkdatabase.update_modification_time(connection, item_name, now) update_tree_list() load_memo_info() connection.close()
def save_memo_info(): item_name = get_hostname() if item_name not in constants.DB_TYPE_NAME_LIST: connection = plkdatabase.create_connection(constants.DB_NAME) if connection is not None: notes = plk_user_memo.get("1.0", END) back_notes = plkdatabase.get_notes(connection, item_name)[0][0] if notes[:-1] != back_notes: now = generaldefinitions.get_time() plkdatabase.update_notes(connection, item_name, notes) plkdatabase.update_modification_time(connection, item_name, now) connection.close()
def change_item_type(): item_name = plk_tree.item(plk_tree.selection())["text"] connection = plkdatabase.create_connection(constants.DB_NAME) if item_name not in constants.DB_TYPE_NAME_LIST: change_type = messagebox.askquestion( "Info", "Zmienić typ dla " + item_name + "?") if change_type == "yes": old_type = plkdatabase.get_type(connection, item_name)[0][0] info = """Podaj nową nazwę typu. Dozwolone typy: USER dla użytkowników, COMPUTER dla komputerów, DEVICE dla urządzeń, PROGRAM dla programów, TIP dla wskazówek.""" new_type = simpledialog.askstring(item_name + ": Zmiana typu", info) if new_type != "": new_type = str(new_type) new_type = new_type.upper() new_type = new_type.translate( {ord(c): None for c in ' \n\t\r'}) if new_type in constants.DB_TYPE_VALUE_LIST: plkdatabase.update_type(connection, item_name, new_type) now = generaldefinitions.get_time() info = constants.CHANGE_TYPE_INFO + now + " z [" + old_type + "] na [" + new_type + "]. \n" notes = plkdatabase.get_notes(connection, item_name)[0][0] notes = info + notes plkdatabase.update_notes(connection, item_name, notes) plkdatabase.update_modification_time( connection, item_name, now) load_memo_info() update_tree_list() else: messagebox.showerror("Info", "Błędny typ") connection.close()
def change_item_name(): item_name = plk_tree.item(plk_tree.selection())["text"] if item_name not in constants.DB_TYPE_NAME_LIST: change_name = messagebox.askquestion("Info", "Zmienić nazwę?") if change_name == "yes": new_name = simpledialog.askstring( "Info", "Podaj nową nazwę dla " + item_name + '.') new_name = new_name.upper() new_name = new_name.translate({ord(c): None for c in ' \n\t\r'}) if new_name == "": messagebox.showerror("Info", "Nazwa jest pusta.") else: connection = plkdatabase.create_connection(constants.DB_NAME) if connection is not None: plkdatabase.update_name(connection, item_name, new_name) now = generaldefinitions.get_time() info = constants.CHANGE_NAME_INFO + now + " z [" + item_name + "] na [" + new_name + "]. \n" notes = plkdatabase.get_notes(connection, new_name)[0][0] notes = info + notes plkdatabase.update_notes(connection, new_name, notes) plkdatabase.update_modification_time( connection, new_name, now) update_tree_list() connection.close()
def memo_add_timestamp(): now = generaldefinitions.get_time() plk_user_memo.insert(INSERT, now)