来源: 阅读:- 2020-03-30 10:04:02
Python信息系统实验:仓库管理
这是给物流管理专业设计的仓库信息管理实验。尽量采用基本的方式组织数据、模块与实验。同时体现Browser-Application Server-Database 的三层逻辑。
模拟一个简单的仓库的以下基本管理过程:
关于Flask请参考前文。Flask可以做很复杂的应用,但是本文仅仅利用其最简单的能力完成几个页面和功能之间的切换。
几分钟做个Web应用
from flask import Flask
from flask import session, redirect, url_for, request
from flask import render_template
关于数据库及其访问接口,请参考前文。
Python数据库
from Data import Data
采用三组菜单导航
app = Flask(__name__)
@app.route('/')
def index():
if 'username' in session:
return redirect(url_for('StorageUnitList'))
else:
return redirect(url_for('login'))
@app.route('/about')
def about():
return render_template('about.html', name='Flask')
@app.route('/login', methods=['GET', 'POST'])
def login():
if request.method == 'POST':
u = request.form['username']
if u is None or len(u)==0:
return redirect(url_for('login'))
session['username'] = u
return redirect(url_for('StorageUnitList'))
return '''
<center>
Warehouse management<br><br>
<table border=1>
<form action="" method="post">
<tr>
<td>user name</td>
<td><input type=text name=username></td>
</tr>
<tr>
<td></td>
<td><input type=submit value=Login></td>
</tr>
</form>
</table>
</center>
'''
@app.route('/StorageUnitList')
def StorageUnitList():
db = Data()
db.createDatabase()
d = db.selectStorageUnit()
return render_template('StorageUnitList.html', data=d)
@app.route('/StorageUnitAdd', methods=['GET', 'POST'])
def StorageUnitAdd():
return '''
<center>
Warehouse management --> add a Storage Unit<br><br>
<table border=1>
<form action="StorageUnitAddExe" method="post">
<tr>
<td>code</td>
<td><input type=text name=scode></td>
</tr>
<tr>
<td>size</td>
<td><input type=text name=ssize></td>
</tr>
<tr>
<td></td>
<td><input type=submit value=OK></td>
</tr>
</form>
</table>
</center>
'''
@app.route('/StorageUnitAddExe', methods=['GET', 'POST'])
def StorageUnitAddExe():
scode = request.form['scode']
ssize = request.form['ssize']
if scode is not None and len(scode)>0 and \
ssize is not None and len(ssize)>0:
db = Data()
db.createDatabase()
db.insertStorageUnit(scode,ssize);
return redirect(url_for('StorageUnitList'))
@app.route('/StorageUnitDelete', methods=['GET', 'POST'])
def StorageUnitDelete():
return '''
<center>
Warehouse management --> delete a Storage Unit<br><br>
<table border=1>
<form action="StorageUnitDeleteExe" method="post">
<tr>
<td>code</td>
<td><input type=text name=scode></td>
</tr>
<tr>
<td></td>
<td><input type=submit value=OK></td>
</tr>
</form>
</table>
</center>
'''
@app.route('/StorageUnitDeleteExe', methods=['GET', 'POST'])
def StorageUnitDeleteExe():
scode = request.form['scode']
if scode is not None and len(scode)>0:
db = Data()
db.createDatabase()
db.deleteStorageUnit(scode);
return redirect(url_for('StorageUnitList'))
@app.route('/StorageList')
def StorageList():
db = Data()
db.createDatabase()
d = db.selectStorage()
return render_template('StorageList.html', data=d)
@app.route('/StorageAdd', methods=['GET', 'POST'])
def StorageAdd():
return '''
<center>
Warehouse management --> add a Storage<br><br>
<table border=1>
<form action="StorageAddExe" method="post">
<tr>
<td>storage unit code </td>
<td><input type=text name=scode></td>
</tr>
<tr>
<td>goods code </td>
<td><input type=text name=ccode></td>
</tr>
<tr>
<td>goods name </td>
<td><input type=text name=cname></td>
</tr>
<tr>
<td>status </td>
<td><input type=text name=status></td>
</tr>
<tr>
<td></td>
<td><input type=submit value=OK></td>
</tr>
</form>
</table>
</center>
'''
@app.route('/StorageAddExe', methods=['GET', 'POST'])
def StorageAddExe():
scode = request.form['scode']
ccode = request.form['ccode']
cname = request.form['cname']
status = request.form['status']
if scode is not None and len(scode)>0 and ccode is not None and \
len(ccode)>0 and cname is not None and \
len(cname)>0 and status is not None and len(status)>0:
db = Data()
db.createDatabase()
if len(db.selectStorageUnitBy(scode))>0:
db.insertStorage(scode,ccode,cname,status);
return redirect(url_for('StorageList'))
@app.route('/StorageDelete', methods=['GET', 'POST'])
def StorageDelete():
return '''
<center>
Warehouse management --> delete a Storage Unit<br><br>
<table border=1>
<form action="StorageDeleteExe" method="post">
<tr>
<td>storage unit code</td>
<td><input type=text name=scode></td>
</tr>
<tr>
<td>goods code</td>
<td><input type=text name=ccode></td>
</tr>
<tr>
<td></td>
<td><input type=submit value=OK></td>
</tr>
</form>
</table>
</center>
'''
@app.route('/StorageDeleteExe', methods=['GET', 'POST'])
def StorageDeleteExe():
scode = request.form['scode']
ccode = request.form['ccode']
if scode is not None and len(scode)>0 and \
ccode is not None and len(ccode)>0:
db = Data()
db.createDatabase()
db.deleteStorage(scode, ccode);
return redirect(url_for('StorageList'))
# set the secret key:
app.secret_key = 'A0Zr98j/3yX R~XHH!jmN]LWX/,?RT**^4'
if __name__ == '__main__':
app.run()
# Flask:
# http://docs.jinkan.org/docs/flask/index.html
# Template:
# http://docs.jinkan.org/docs/jinja2/
<html>
<body>
<center>
Warehouse management: this is just a test application for demonstrating logistics information systems.<br>
<br>
<table border=1>
<tr>
<td colspan=4>Menu</td>
</tr>
<tr>
<td>Storage Unit</td>
<td>[<a href='/StorageUnitList'>list</a>]</td>
<td>[<a href='/StorageUnitAdd'>add</a>]</td>
<td>[<a href='/StorageUnitDelete'>delete</a>]</td>
</tr>
<tr>
<td>Storage</td>
<td>[<a href='/StorageList'>list</a>]</td>
<td>[<a href='/StorageAdd'>add</a>]</td>
<td>[<a href='/StorageDelete'>delete</a>]</td>
</tr>
<tr>
<td>System</td>
<td>[<a href='about'>about</a>]</td>
<td>[<a href='login'>login</a>]</td>
<td>[<a href='/'>index</a>]</td>
</tr>
<table>
</center>
</body>
</html>
<html>
<body>
<center>
Warehouse management -> Storage<br>
<br>
<table border=1>
<tr>
<td colspan=4>Menu</td>
</tr>
<tr>
<td>Storage Unit</td>
<td>[<a href='/StorageUnitList'>list</a>]</td>
<td>[<a href='/StorageUnitAdd'>add</a>]</td>
<td>[<a href='/StorageUnitDelete'>delete</a>]</td>
</tr>
<tr>
<td>Storage</td>
<td>[<a href='/StorageList'>list</a>]</td>
<td>[<a href='/StorageAdd'>add</a>]</td>
<td>[<a href='/StorageDelete'>delete</a>]</td>
</tr>
<tr>
<td>System</td>
<td>[<a href='about'>about</a>]</td>
<td>[<a href='login'>login</a>]</td>
<td>[<a href='/'>index</a>]</td>
</tr>
<table>
<br>
<table border=1>
<tr>
<td>Storage Unit Code</td>
<td>Goods Code</td>
<td>Goods Name</td>
<td>Status</td>
<tr>
{% for a in data %}
<tr>
<td>{{ a[0] }}</td>
<td>{{ a[1] }}</td>
<td>{{ a[2] }}</td>
<td>{{ a[3] }}</td>
</tr>
{% endfor %}
<table>
</center>
</body>
</html>
<html>
<body>
<center>
Warehouse management -> Storage Units<br>
<br>
<table border=1>
<tr>
<td colspan=4>Menu</td>
</tr>
<tr>
<td>Storage Unit</td>
<td>[<a href='/StorageUnitList'>list</a>]</td>
<td>[<a href='/StorageUnitAdd'>add</a>]</td>
<td>[<a href='/StorageUnitDelete'>delete</a>]</td>
</tr>
<tr>
<td>Storage</td>
<td>[<a href='/StorageList'>list</a>]</td>
<td>[<a href='/StorageAdd'>add</a>]</td>
<td>[<a href='/StorageDelete'>delete</a>]</td>
</tr>
<tr>
<td>System</td>
<td>[<a href='about'>about</a>]</td>
<td>[<a href='login'>login</a>]</td>
<td>[<a href='/'>index</a>]</td>
</tr>
<table>
<br>
<table border=1>
<tr><td>Code</td><td>Size</td><tr>
{% for a in data %}
<tr>
<td>{{ a[0] }}</td>
<td>{{ a[1] }}</td>
</tr>
{% endfor %}
<table>
</center>
</body>
</html>
在Anaconda Spyder中执行index.py,得到:
* Serving Flask app "index" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
在浏览器输入以下网址测试: http://127.0.0.1:5000/
私信小编01 领取完整代码
(正文已结束)
免责声明及提醒:此文内容为本网所转载企业宣传资讯,该相关信息仅为宣传及传递更多信息之目的,不代表本网站观点,文章真实性请浏览者慎重核实!任何投资加盟均有风险,提醒广大民众投资需谨慎!