def registerbranch(id): if request.method == 'GET': database = mysql.connector.connect(**db.DBconfig()) cursor = database.cursor() _SQL = """SELECT * FROM empresa WHERE id = %s""" cursor.execute(_SQL, (id,)) empresa = cursor.fetchall() cursor.close() database.close() return render_template('register_branch.html', the_title='MyBusiness - Register Branch', the_heading='Formulário de Cadastro de Filiais', empresa=empresa) elif request.method == 'POST': database = mysql.connector.connect(**db.DBconfig()) cursor = database.cursor() _SQL = """INSERT INTO unidade (id_empresa, razao_social, cnpj, estado, municipio, cep) VALUES (%s, %s, %s, %s, %s, %s)""" cursor.execute(_SQL, (id, request.form['razao_social'], request.form['cnpj'], request.form['estado'], request.form['municipio'], request.form['cep'],)) database.commit() cursor.close() database.close() return redirect(url_for('index'))
def update(id): if request.method == 'GET': database = mysql.connector.connect(**db.DBconfig()) cursor = database.cursor() _SQL = """SELECT * FROM empresa WHERE id = %s""" cursor.execute(_SQL, (id,)) empresa = cursor.fetchall() cursor.close() database.close() return render_template('update.html', the_title='MyBusiness - Update data Companies', the_heading='Atualizar Empresa', empresa=empresa) elif request.method == 'POST': database = mysql.connector.connect(**db.DBconfig()) cursor = database.cursor() _SQL = """UPDATE empresa SET razao_social = %s, cnpj = %s, estado = %s, municipio = %s, cep = %s WHERE id = %s""" cursor.execute(_SQL, (request.form.get('razao_social'), request.form.get('cnpj'), request.form.get('estado'), request.form.get('municipio'), request.form.get('cep'), id,)) database.commit() cursor.close() database.close() return redirect(url_for('view'))
def delete(id): database = mysql.connector.connect(**db.DBconfig()) cursor = database.cursor() _SQL = """DELETE FROM empresa WHERE id = %s""" cursor.execute(_SQL, (id,)) empresa = cursor.fetchall() database.commit() cursor.close() database.close() return redirect(url_for('view', empresa=empresa))
def deletebranch(id): database = mysql.connector.connect(**db.DBconfig()) cursor = database.cursor() _SQL = """DELETE FROM unidade WHERE id = %s""" cursor.execute(_SQL, (id,)) unidade = cursor.fetchall() database.commit() cursor.close() database.close() return redirect(url_for('view', unidade=unidade))
def view(): if request.method == "GET": database = mysql.connector.connect(**db.DBconfig()) cursor = database.cursor() # cursor.execute("SELECT * FROM empresa WHERE tipo = 'Matriz'") --- Estou selecionando na tabela empresa somente do tipo Matriz cursor.execute("SELECT * FROM empresa") empresa = cursor.fetchall() cursor.close() database.close() return render_template('view.html', the_title='MyBusiness - View Companies', the_heading='Relação de Empresas Cadastradas', empresa=empresa)
def branch(id): if request.method == "GET": database = mysql.connector.connect(**db.DBconfig()) cursor = database.cursor() _SQL = """SELECT * FROM unidade WHERE id_empresa = %s""" cursor.execute(_SQL, (id,)) unidade = cursor.fetchall() cursor.close() database.close() return render_template('view_branches.html', the_title='MyBusiness - View Branches Companies', the_heading="Relação das Unidades Cadastradas", unidade=unidade)
def registered() -> 'str': if request.method == "POST": database = mysql.connector.connect(**db.DBconfig()) cursor = database.cursor() _SQL = """INSERT INTO empresa (razao_social, cnpj, estado, municipio, cep) VALUES (%s, %s, %s, %s, %s)""" cursor.execute(_SQL, (request.form['razao_social'], request.form['cnpj'], request.form['estado'], request.form['municipio'], request.form['cep'],)) database.commit() cursor.close() database.close() return redirect(url_for('index'))