Python信息系统实验:仓库管理
这是给物流管理专业设计的仓库信息管理实验。尽量采用基本的方式组织数据、模块与实验。同时体现Browser-Application Server-Database 的三层逻辑。
实验要求
软件
- 开发工具:Python+ Flask+HTML
- 数据库:SQLite
- 架构:三层架构(Browser+Application Servier+Database)
仓库管理实验
模拟一个简单的仓库的以下基本管理过程:
- 1)库位查询:查询库位编码及其容量
- 2)增加库位
- 3)删除库位
- 4)入库:商品编码、库位
- 5)出库:商品编码
- 6)商品库位查询:根据商品编码找库位
- 7)库位统计
数据库表格
- StorageUnit: scode text, ssize int;
- Storage: scode text, ccode text, cname text, status text (=in, out)
Web Flask
关于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
导航
采用三组菜单导航
- 基本功能组:主页index、关于about、登录login
- 对存储单元的操纵,主要是列表显示StorageUnitList、增加StorageUnitAdd和删除StorageUnitDelete
- 对存储记录的操纵,主要是列表显示StorageList、增加StorageAdd和删除StorageDelete
- 对于Add和Delete这两类Action,生成表单Form和执行更新分开来,,例如StorageAdd生成Form,而StorageAddExe执行
- 在login,StorageUnitAddExe,StorageUnitDeleteExe,StorageAddExe,StorageDeleteExe中,通过session或request操纵交互数据。
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 '''
Warehouse management
'''
@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 '''
Warehouse management --> add a Storage Unit
'''
@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 '''
Warehouse management --> delete a Storage Unit
'''
@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 '''
Warehouse management --> add a Storage
'''
@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 '''
Warehouse management --> delete a Storage Unit
'''
@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/
Web页面
- 如上代码所隐含,使用了一个静态文件,即about.html;
- 使用了两个模板文件,用于生成检索数据库表生成的列表,即StorageList.html和StorageUnitList.html;
- 注意在login,StorageUnitAdd,StorageUnitDelete,StorageAdd,StorageDelete中都生成了Form,这些内容是在浏览器前端显示的。
about.html
Warehouse management: this is just a test application for demonstrating logistics information systems.
Menu
Storage Unit
[list]
[add]
[delete]
Storage
[list]
[add]
[delete]
System
[about]
[login]
[index]
StorageList.html
Warehouse management -> Storage
Menu
Storage Unit
[list]
[add]
[delete]
Storage
[list]
[add]
[delete]
System
[about]
[login]
[index]
Storage Unit Code
Goods Code
Goods Name
Status
{% for a in data %}
{{ a[0] }}
{{ a[1] }}
{{ a[2] }}
{{ a[3] }}
{% endfor %}
StorageUnitList.html
Warehouse management -> Storage Units
Menu
Storage Unit
[list]
[add]
[delete]
Storage
[list]
[add]
[delete]
System
[about]
[login]
[index]
Code Size
{% for a in data %}
{{ a[0] }}
{{ a[1] }}
{% endfor %}
测试
在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/
Login
Storage Unit: List
Storage Unit: Add
Storage Unit: Delete
Storage: List
Storage: Add
Storage: Delete
私信小编01 领取完整代码
推荐阅读:津都财讯网
频道推荐
百威集团旗下mikes麦克斯品牌正式进入中国(2020年9月6日,上海)百威集团旗下高端预调酒品牌mike’s麦克斯正式进入中国市场,并发布嗨柠鸡尾酒与裸气泡酒两款全新产品。预调酒因其独特的口感与饮用文化...
2020-09-07 京东618一起热爱趴开播:郑爽、吴昕、大张伟这个618,一起热爱一起嗨,玩的舒畅买的开心就是最重要的议题。6月17日,《京东618一起热爱趴》火热开启,郑爽、林允、吴昕、金靖、马东、大张伟、郭麒麟、丁禹兮...
2020-06-15 TFBOYS组合复工后更换头像!粉丝纷纷效仿4月15日是一个奇妙的日子,是三个男孩子梦想开始的地方,从开始的《heart》到现在的《第一次告白》,他们一直在成长!就在今天,TFBOYS组合复工后在某社交平...
2020-04-16 魏大勋姐弟恋就差个官宣?乔振宇曾评价杨幂:喜杨幂和魏大勋还差一点点就实锤了(差个官宣)。事情起因是最近有人拍到了魏大勋和杨幂共同进入酒店,助理买了三根冰淇淋,其中两根给了后座的魏大勋和一位女士。下车之后,...
2020-04-16 杨幂绯闻后首次发声,只提另一个男人?粉丝:失要说最近的娱乐圈最大的瓜,莫过于杨幂与魏大勋的恋爱绯闻了。4月13日,有媒体爆出两人一起吃冰淇淋,出入酒店的照片;第二天又有爆料称杨幂乘车至魏大勋《涩女郎》片场...
2020-04-16 史无前例!卜凡约黑粉线下见面对方赴约,发文表去年坤音娱乐ONER组合成员在举办完最后一场演唱会后分崩离析,卜凡因与公司单方面提出解约不被同意,之后与元公司陷入矛盾纠纷中,ONER四人组合就这样莫名其妙的解...
2020-04-16