def delete_department(): cursor, cnx = db.get_connection() department_name = request.form.get("department_name", "") get_query_delete_department = f"DELETE FROM department_table WHERE department_name = '{department_name}' " cursor.execute(get_query_delete_department) cnx.commit() return redirect("/department")
def create_department(change_department_name): cursor, cnx = db.get_connection() department_id = create_department_id() # insert文 get_query_create_department = f"INSERT INTO department_table (department_id, department_name) VALUES ('{department_id}', '{change_department_name}') " cursor.execute(get_query_create_department) cnx.commit()
def execute_edit_employee(id, employee_id, employee_name, employee_age, employee_gender, employee_image, employee_image_id, employee_postal_code, employee_prefecture, employee_address, employee_start_date, employee_leave_date, department_name, department_id): cursor, cnx = db.get_connection() # employee_image_id = create_employee_image_id() # query_update = db.create_query_update_employee(id, employee_id, employee_name, employee_age, employee_gender, employee_image, employee_postal_code, employee_prefecture, employee_address, employee_start_date, employee_leave_date, department_name, department_id) query_update = get_query_edit_employee( id, employee_id, employee_name, employee_age, employee_gender, employee_image, employee_image_id, employee_postal_code, employee_prefecture, employee_address, employee_start_date, employee_leave_date, department_name, department_id) if employee_image.filename != "": filename = save_filename(employee_image) query_update_image = db.create_query_update_image( filename, employee_image_id) cursor.execute(query_update_image) # query_update_department = db.create_query_update_department(department_name, department_id) cursor.execute(query_update) # cursor.execute(query_update_department) cnx.commit() return
def download(): cursor, cnx = db.get_connection() csv_employees = db.get_csv_employee_query() csv = "" csv = csv_employees response = make_response(csv) response.headers[ "Content-Disposition"] = "attachment; filename=employees.csv" return response
def delete_employee(): cursor, cnx = db.get_connection() id = request.form.get("id", "") # employee_id = request.form.get("employee_id", "") get_query_delete_employee = f"DELETE FROM employee_table WHERE id = {id} " # get_query_delete_employee = f"DELETE FROM employee_table WHERE employee_id = '{employee_id}' " cursor.execute(get_query_delete_employee) cnx.commit() return redirect("/")
def execute_add_employee(employee_id, employee_name, employee_age, employee_gender, employee_image_id, employee_postal_code, employee_prefecture, employee_address, department_id, employee_start_date, employee_leave_date, filename, department_name): cursor, cnx = db.get_connection() query_employee = db.add_query_employee_table( employee_id, employee_name, employee_age, employee_gender, employee_image_id, employee_postal_code, employee_prefecture, employee_address, department_id, employee_start_date, employee_leave_date) query_employee_image = db.add_query_employee_image_table( employee_image_id, filename) cursor.execute(query_employee) cursor.execute(query_employee_image) cnx.commit()
def employee_search(): cursor, cnx = db.get_connection() department_name, search_employee_id, search_employee_name = get_request_employee( ) get_query_search_employee_table = "SELECT id, employee_id, employee_name, department_name FROM employee_table JOIN department_table ON employee_table.department_id = department_table.department_id WHERE employee_id IS NOT NULL" get_query_search_employee_table = db.get_query_search_employee( get_query_search_employee_table, department_name, search_employee_id, search_employee_name) cursor.execute(get_query_search_employee_table) search_employees = db.retrieve_search_employees(cursor) if len(search_employees) == 0: flash("登録されている社員がいません", "") else: flash("検索結果はこちらになります", "") return render_template("search_result.html", search_employees=search_employees)
def show_edit_employee(): cursor, cnx = db.get_connection() # id = int(request.form.get("id", "")) id = request.form.get("id", "") # if id == str: # id = int(id) # 部署一覧を取得している department = db.get_department_query() # 選択した社員の全てのステータスをここで取得 get_query_employee_information = f"SELECT id, employee_id, employee_name, employee_age, employee_gender, employee_table.employee_image_id, employee_postal_code, employee_prefecture, employee_address, employee_table.department_id, employee_start_date, employee_leave_date, employee_update_date, employee_image, department_table.department_name FROM employee_table JOIN employee_image_table ON employee_table.employee_image_id = employee_image_table.employee_image_id JOIN department_table ON employee_table.department_id = department_table.department_id WHERE employee_table.id = {id} " # get_query_employee_information = f"SELECT id, employee_id, employee_name, employee_age, employee_gender, employee_table.employee_image_id, employee_postal_code, employee_prefecture, employee_address, department_id, employee_start_date, employee_leave_date, employee_update_date, employee_image FROM employee_table JOIN employee_image_table ON employee_table.employee_image_id = employee_image_table.employee_image_id WHERE employee_table.id = {id} " # get_query_employee_information = f"SELECT * FROM employee_table WHERE id = {id} " cursor.execute(get_query_employee_information) employees = db.retrieve_edit_employee(cursor) params = {"employees": employees, "department": department} return render_template("employee_add.html", **params)