1. 設為首頁   文化中國網歡迎您~!

          Python信息系統實驗:倉庫管理

          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 '''
          <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/

          Web頁面

          • 如上代碼所隱含,使用了一個靜態文件,即about.html;
          • 使用了兩個模板文件,用于生成檢索數據庫表生成的列表,即StorageList.html和StorageUnitList.html;
          • 注意在login,StorageUnitAdd,StorageUnitDelete,StorageAdd,StorageDelete中都生成了Form,這些內容是在瀏覽器前端顯示的。

          about.html

          <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>

          StorageList.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>

          StorageUnitList.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/

          Login

          Storage Unit: List

          Storage Unit: Add

          Storage Unit: Delete

          Storage: List

          Storage: Add

          Storage: Delete

          私信小編01 領取完整代碼

          推薦閱讀:手機要降價
          好运来 www.kidodidoo.com:成都市| www.glviagragtr.com:广东省| www.sao94sao.com:邮箱| www.cp8559.com:安庆市| www.frenchjacuzzi.com:秦皇岛市| www.atcdhaka.com:阿合奇县| www.cp2110.com:武鸣县| www.yourwebside.com:思南县| www.cropbowtie.com:普宁市| www.znlkw.cn:长武县| www.leopad.net:建阳市| www.jtjdg.cn:黄冈市| www.x1900.com:拉孜县| www.l248.com:朝阳市| www.garagedoorsirvine.com:贡觉县| www.satext.com:阿尔山市| www.marcandreboivin.com:望谟县| www.flamwoodvideo.com:清水河县| www.flickneroptometry.com:神农架林区| www.quit-list.com:安化县| www.di1da.com:台东市| www.conceptpromotions.net:房山区| www.chiemlamdep.com:昭苏县| www.forfonts.com:邛崃市| www.huaye-tj.com:平远县| www.blackangelunivers.com:张家界市| www.xybww.cn:辽阳县| www.arcadaproductions.com:合肥市| www.pieelectronics.com:彭水| www.devpsy2015.com:哈巴河县| www.022tjhj.com:龙山县| www.ecurielesvolants.org:赤峰市| www.findnewyorkmuseums.com:北川| www.switchgeardubai.net:乐安县| www.chungcuhanoimoi.net:吴旗县| www.ccss9988.com:池州市| www.webyinfo.com:曲水县| www.cqwjwz.com:新平| www.world-anime.com:新营市| www.jrjhl.com.cn:灵石县| www.nbuyi.com:澳门| www.litianaudio.com:双辽市| www.sacnakil.com:萍乡市| www.blimprobotics.com:通榆县| www.twosojourners.com:南京市| www.jillian-redosendo.com:新建县| www.appleidd.com:莲花县| www.garagedoorsirvine.com:泊头市| www.qywdj.com:炉霍县| www.pj43730.com:松滋市| www.olgirl.com:馆陶县| www.hoyins.com:陇川县| www.quizonerp.com:大兴区| www.wunderkind56dvoek.net:长葛市| www.xingyixiehe.com:海淀区| www.ylzttgbus.com:永嘉县| www.debibaker.org:河南省| www.adonisparadise.com:福建省| www.duhocnamhai.com:丽江市| www.rightics.com:临海市| www.bieberlc.com:金山区| www.tang-mart.com:白山市| www.jhjxjgc.com:兴文县| www.cp9396.com:昌宁县| www.guitarquest.net:页游| www.yourhcgcoach.com:万荣县| www.huangdaobb.com:汉阴县| www.huangdaobb.com:吴旗县| www.v7h6.com:禹城市| www.copperkidsolo.com:汕头市| www.hearthemlive.com:饶河县| www.pengxing18.com:台中市| www.guanglistone.com:赤峰市| www.adocweb-bourgogne.org:金沙县| www.weatherkingdom.net:胶州市| www.amb-eco.com:东方市| www.fm556.com:宿迁市| www.nadabula.com:京山县| www.lulumom.com:延安市| www.idleclickinggames.com:阳原县| www.thegreatmuseum.net:桃江县| www.practicalitstrategy.com:云浮市| www.cp9776.com:开鲁县| www.poengun.com:云浮市|