You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

154 lines
6.3 KiB

from flask import Flask
from flask import render_template,request,redirect,Flask
from mysql操作 import *
from flask_sqlalchemy import SQLAlchemy
#模板渲染引擎
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://root:123456@localhost:3306/goods'
#设置每次请求结束后会自动提交数据库中的改动
app.config['SQLALCHEMY_COMMIT_ON_TEARDOWN'] = True
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
#查询时会显示原始SQL语句
app.config['SQLALCHEMY_ECHO'] = True
db = SQLAlchemy(app)
class donations(db.Model):
捐赠编号 = db.Column(db.String(255),primary_key=True)
捐赠单位 = db.Column(db.String(255))
捐赠物资 = db.Column(db.String(255))
规格 = db.Column(db.String(255))
计量单位 = db.Column(db.String(255))
数量总计 = db.Column(db.String(255))
class distributions(db.Model):
分配编号 = db.Column(db.String(255),primary_key=True)
接收单位= db.Column(db.String(255))
品名= db.Column(db.String(255))
规格= db.Column(db.String(255))
计量单位= db.Column(db.String(255))
数量= db.Column(db.String(255))
仓库号= db.Column(db.String(255))
签收人 = db.Column(db.String(255))
签收人联系电话 = db.Column(db.String(255))
@app.route('/')
def hello():
return render_template('主页.html')
@app.route('/donations')
def donations():
donations = select('select * from donations')
return render_template('查询捐赠情况.html',donations = donations)
@app.route('/distributions')
def distributions():
distributions = select('select * from distributions')
return render_template('查询分配情况.html',distributions = distributions)
@app.route("/insert1")
def insert1():
return render_template("insert1.html")
@app.route("/insert2")
def insert2():
return render_template("insert2.html")
@app.route("/insertmask1",methods=['GET','POST'])
def insertmask1():
#com_name=request.form['com_name']
a1 = request.form['a1']
a2 = request.form['a2']
a3 = request.form['a3']
a4 = request.form['a4']
a5 = request.form['a5']
a6 = request.form['a6']
masktj=donations(捐赠编号 = a1,捐赠单位= a2,捐赠物资 = a3,规格 = a4,计量单位 = a5,数量总计 = a6)
db.session.add(masktj)
db.session.commit()
return render_template("查询捐赠情况.html")
@app.route("/insertmask2",methods=['GET','POST'])
def insertmask2():
#com_name=request.form['com_name']
a1 = request.form['a1']
a2 = request.form['a2']
a3 = request.form['a3']
a4 = request.form['a4']
a5 = request.form['a5']
a6 = request.form['a6']
a7 = request.form['a7']
a8 = request.form['a8']
a9 = request.form['a9']
masktj=mask(分配编号 = a1,接收单位= a2,品名= a3,规格= a4,计量单位= a5,数量= a6,仓库号= a7,签收人 = a8,签收人联系电话 = a9)
db.session.add(masktj)
db.session.commit()
return render_template("查询分配情况.html")
@app.route('/删除捐赠记录',methods=['GET'])
def shanchujuanzeng():
id= request.args.get("id")
#展示语句是否正确的
#print('delete from donations where 捐赠编号={};'.format(id))
delete('delete from donations where 捐赠编号={};'.format(id))
return redirect('/donations')
@app.route("/修改捐赠记录",methods=['GET','POST'])
def xiugaijuanzeng():
if request.method == 'GET':
id = request.args.get("id")
donation = select('select * from donations where 捐赠编号="{}"'.format(id))[0]
return render_template("修改捐赠记录.html",donation = donation)
else:
#接收参数,修改数据
id = request.form["id"]
捐赠单位 = request.form['捐赠单位']
捐赠物资名称 = request.form['捐赠物资名称']
规格 = request.form['规格']
计量单位 = request.form['计量单位']
数量总计 = request.form['数量总计']
#print('update donations set 时间=STR_TO_DATE("{}","%Y-%m-%d") ,捐赠方单位="{}" ,物资名称="{}" ,类别="{}" ,数量={} ,计量单位="{}" ,价值={} where 捐赠编号={}'.format(时间,捐赠方单位,物资名称,物资类别,数量,单位,价值,id))
alter('update donations set 捐赠单位="{}" ,捐赠物资名称="{}" ,规格="{}" ,计量单位="{}" ,数量总计="{}" where 捐赠编号="{}"'.format(捐赠单位,捐赠物资名称,规格,计量单位,数量总计,id))
return redirect('/donations')
@app.route('/删除分配记录',methods=['GET'])
def shanchufenpei():
id= request.args.get("id")
#展示语句是否正确的
#print('delete from distributions where 发放编号={};'.format(id))
delete('delete from distributions where 分配编号="{}";'.format(id))
#print(id)
return redirect('/distributions')
#/*----------------------------------------------------------------------------------------*/
@app.route("/修改分配记录",methods=['GET','POST'])
def xiugaifenpei():
if request.method == 'GET':
id = request.args.get("id")
distribution = select('select * from distributions where 分配编号="{}"'.format(id))[0]
return render_template("修改分配记录.html",distribution = distribution)
else:
#接收参数,修改数据
id = request.form["id"]
接收单位 = request.form['接收单位']
物资名称 = request.form['物资名称']
规格 = request.form['规格']
计量单位 = request.form['计量单位']
数量 = request.form['数量']
仓库号 = request.form['仓库号']
签收人 = request.form['签收人']
签收人联系电话= request.form['签收人联系电话']
#print('update donations set 时间=STR_TO_DATE("{}","%Y-%m-%d") ,捐赠方单位="{}" ,物资名称="{}" ,类别="{}" ,数量={} ,计量单位="{}" ,价值={} where 捐赠编号={}'.format(时间,捐赠方单位,物资名称,物资类别,数量,单位,价值,id))
alter('update distributions set 接收单位="{}" ,物资名称="{}" ,规格="{}" ,计量单位="{}" ,数量="{}" ,仓库号="{}" ,签收人="{}",签收人联系电话="{}" where 分配编号="{}"'.format(接收单位,物资名称,规格,计量单位,数量,仓库号, 签收人,签收人联系电话,id))
return redirect('/distributions')
if __name__ == '__main__':
app.run()