123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497 |
- from flask import Flask, render_template,request,url_for, redirect
- import pymysql
- import pandas as pd
- import csv
- app = Flask(__name__)
- conn = pymysql.connect(
- host='127.0.0.1',
- user='root',
- password='Gold@53743001',
- db='erp',
- charset='utf8'
- )
- #首頁
- @app.route("/")
- def index():
- return render_template("index.html",title = 'ERP WEB')
- #產品清單頁面
- @app.route('/productinfo/')
- def productinfo():
- cur = conn.cursor()
- #獲取欄位資料
- sql = "select * from product_info"
- cur.execute(sql)
- content = cur.fetchall()
- #獲取欄位名稱
- sql = "SHOW FIELDS FROM product_info"
- cur.execute(sql)
- labels = cur.fetchall()
- labels = [g[0] for g in labels]
- return render_template('productinfo.html', labels=labels, content=content)
- @app.route('/submit/')
- def form():
- return render_template('submit.html')
- #新增產品清單內容
- @app.route('/add_product', methods=['POST', 'GET'])
- def add_product():
- if request.method == 'GET':
- return "Login via the login Form"
- if request.method == 'POST':
- NO = request.form['NO']
- 內部料號 = request.form['內部料號']
- 品名 = request.form['品名']
- 規格型號 = request.form['規格型號']
- 類型 = request.form['類型']
- 技術文件連結 = request.form['技術文件連結']
- 原廠料號 = request.form['原廠料號']
- 賣家料號 = request.form['賣家料號']
- 圖示 = request.form['圖示']
- 進單價 = request.form['進單價']
- 數量 = request.form['數量']
- 單位 = request.form['單位']
- 取得方式 = request.form['取得方式']
- 庫存 = request.form['庫存']
- 廠商 = request.form['廠商']
- cur = conn.cursor()
- cur.execute(''' INSERT INTO product_info VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)'''
- , (NO, 內部料號, 品名, 規格型號, 類型, 技術文件連結, 原廠料號, 賣家料號, 圖示, 進單價, 數量, 單位, 取得方式, 庫存, 廠商))
- conn.commit()
- cur.close()
- return f"Done!!"
- @app.route('/check/',methods=['GET','POST'])
- def check():
- cur = conn.cursor()
- #獲取欄位名稱
- sql = "select 品名 from product_info"
- cur.execute(sql)
- labels = cur.fetchall()
- labels = [g[0] for g in labels]
- if request.method =='POST':
- sql = "SHOW FIELDS FROM product_info"
- cur.execute(sql)
- labels = cur.fetchall()
- labels = [g[0] for g in labels]
- t = request.values['Test']
- #print(t)
- cur = conn.cursor()
- #獲取欄位資料
- cur.execute("""select * from product_info WHERE 品名 = {}""".format(repr(t)))
- content = cur.fetchall()
- #print(content)
- return render_template('check1.html',content=content,labels=labels)
-
- return render_template('check.html', labels=labels)
- @app.route('/update/')
- def update():
- # 獲取頁面輸入內容,提供給sql使用
- userinfoId = request.args.get('userinfoId')
- name = request.args.get('name') # 更新後的數據返回到頁面上面顯示
- #return render_template('update.html')
- #修改資料庫資料
- @app.route('/updateaction/', methods=['POST'])
- def updateaction():
- cur = conn.cursor()
- params = request.args if request.method == 'GET' else request.form
- #選定欄位的值
- userinfoId = params.get('userinfoId')
- #修改的數值
- 技術文件連結 = params.get('技術文件連結')
- NO = params.get('NO')
- 品名 = params.get('品名')
- 規格型號 = params.get('規格型號')
- 類型 = params.get('類型')
- 原廠料號 = params.get('原廠料號')
- 賣家料號 = params.get('賣家料號')
- 圖示 = params.get('圖示')
- 進單價 = params.get('進單價')
- 數量 = params.get('數量')
- 單位 = params.get('單位')
- 取得方式 = params.get('取得方式')
- 庫存 = params.get('庫存')
- 廠商 = params.get('廠商')
- sql = "update product_info set 技術文件連結='%s',NO='%s',品名='%s',規格型號='%s'" \
- ",類型='%s',原廠料號='%s',賣家料號='%s',圖示='%s'" \
- ",進單價='%s',數量='%s',單位='%s',取得方式='%s'" \
- ",庫存='%s',廠商='%s' where 內部料號='%s'" \
- %(技術文件連結,NO,品名,規格型號,類型,原廠料號,賣家料號,圖示,進單價,數量,單位,取得方式,庫存,廠商,userinfoId) # 執行插入操作
-
- cur.execute(sql)
- conn.commit()
- return render_template('index.html') # 返回更新後的數據,確認是否更新成功
- #---------------------------------------------------------------------------------------#
- #產品清單頁面
- @app.route('/system_sink/')
- def system_sink():
- cur = conn.cursor()
- #獲取欄位資料
- sql = "select * from abc"
- cur.execute(sql)
- content = cur.fetchall()
- print(content)
- #獲取欄位名稱
- sql = "SHOW FIELDS from abc"
- cur.execute(sql)
- labels = cur.fetchall()
- labels = [g[0] for g in labels]
- return render_template('system_sink.html', labels=labels, content=content)
- @app.route('/submit_sink/')
- def form_sink():
- return render_template('submit_sink.html')
- #新增產品清單內容
- @app.route('/add_sink', methods=['POST', 'GET'])
- def add_sink():
- if request.method == 'GET':
- return "Login via the login Form"
- if request.method == 'POST':
- 系統 = request.form['系統']
- 狀態 = request.form['狀態']
- 進貨狀態 = request.form['進貨狀態']
- 內部料號 = request.form['內部料號']
- 組序號 = request.form['組序號']
- 模組圖名 = request.form['模組圖名']
- 模組圖號出圖連結 = request.form['模組圖號/出圖連結']
- 模組數量 = request.form['模組數量']
- 項次 = request.form['項次']
- 零件圖名 = request.form['零件圖名']
- 零件圖號 = request.form['零件圖號']
- 零件數量 = request.form['零件數量']
- 零件總數量 = request.form['零件總數量']
- 類型 = request.form['類型']
- 進度 = request.form['進度']
- 備註 = request.form['備註']
- 出圖日期 = request.form['出圖日期']
- 出圖人員 = request.form['出圖人員']
- 修改日期 = request.form['修改日期']
- 修改原因 = request.form['修改原因']
- 修改人員 = request.form['修改人員']
- 模組 = request.form['模組']
- 主板編號 = request.form['主板編號']
- 制動器編號 = request.form['制動器編號']
- 項目 = request.form['項目']
- 韌體有V = request.form['韌體(有V)']
- 韌體連結git = request.form['韌體連結git']
- 型號規格書 = request.form['型號(規格書)']
- 安裝位置 = request.form['安裝位置']
- 數量 = request.form['數量']
- 需求電壓V = request.form['需求電壓(V)']
- 需求電流A = request.form['需求電流(A)']
- 功率W = request.form['功率(W)']
- 通訊介面 = request.form['通訊介面']
- 芯數 = request.form['芯數']
- 線材編號 = request.form['線材編號']
- 單價 = request.form['單價']
- 總價 = request.form['總價']
- 請購單號 = request.form['請購單號']
- 電流_220V = request.form['220V_電流']
- 功率_220V = request.form['220V_功率']
- 電流_24V = request.form['24V_電流']
- 功率_24V = request.form['24V_功率']
- 電流_12V = request.form['12V_電流']
- 功率_12V = request.form['12V_功率']
- 電流_5V = request.form['5V_電流']
- 功率_5V = request.form['5V_功率']
- 電流_3_3V = request.form['3.3V_電流']
- 功率_3_3V = request.form['3.3V_功率']
- 流量率 = request.form['流量(率)']
- 容量 = request.form['容量']
- 壓力 = request.form['壓力']
-
- cur = conn.cursor()
- cur.execute(''' INSERT INTO sink VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)'''
- , (系統,狀態,進貨狀態,內部料號,組序號,模組圖名,模組圖號出圖連結,模組數量,項次,零件圖名,零件圖號,零件數量,零件總數量,類型,進度,備註,出圖日期,出圖人員,修改日期,修改原因,修改人員,模組,主板編號,制動器編號,項目,韌體有V,韌體連結git,型號規格書,安裝位置,數量,需求電壓V,需求電流A,功率W,通訊介面,芯數,線材編號,單價,總價,請購單號,電流_220V,功率_220V,電流_24V,功率_24V,電流_12V,功率_12V,電流_5V,功率_5V,電流_3_3V,功率_3_3V,流量率,容量,壓力))
- conn.commit()
- cur.close()
- return f"Done!!"
- @app.route('/check_sink/',methods=['GET','POST'])
- def check_sink():
- cur = conn.cursor()
- #獲取欄位名稱
- sql = "select 組序號 from abc"
- cur.execute(sql)
- labels = cur.fetchall()
- labels = [g[0] for g in labels]
- if request.method =='POST':
- sql = "SHOW FIELDS from abc"
- cur.execute(sql)
- labels = cur.fetchall()
- labels = [g[0] for g in labels]
- t = request.values['Test']
- #print(t)
- cur = conn.cursor()
- #獲取欄位資料
- cur.execute("""select * from abc WHERE 組序號 = {}""".format(repr(t)))
- content = cur.fetchall()
- #print(content)
- return render_template('check1_sink.html',content=content,labels=labels)
-
- return render_template('check_sink.html', labels=labels)
- @app.route('/update_sink/')
- def update_sink():
- # 獲取頁面輸入內容,提供給sql使用
- userinfoId = request.args.get('系統')
- name = request.args.get('name') # 更新後的數據返回到頁面上面顯示
- #return render_template('update.html')
- #修改資料庫資料
- @app.route('/updateaction_sink/', methods=['POST'])
- def updateaction_sink():
- cur = conn.cursor()
- params = request.args if request.method == 'GET' else request.form
- #選定欄位的值
- userinfoId = params.get('系統')
- #修改的數值
- 狀態 = params.get('狀態')
- 進貨狀態 = params.get('進貨狀態')
- 內部料號 = params.get('內部料號')
- 組序號 = params.get('組序號')
- 模組圖名 = params.get('模組圖名')
- 模組圖號出圖連結 = params.get('模組圖號出圖連結')
- 模組數量 = params.get('模組數量')
- 項次 = params.get('項次')
- 零件圖名 = params.get('零件圖名')
- 零件圖號 = params.get('零件圖號')
- 零件數量 = params.get('零件數量')
- 零件總數量 = params.get('零件總數量')
- 類型 = params.get('類型')
- 進度 = params.get('進度')
- 備註 = params.get('備註')
- 出圖日期 = params.get('出圖日期')
- 出圖人員 = params.get('出圖人員')
- 修改日期 = params.get('修改日期')
- 修改原因 = params.get('修改原因')
- 修改人員 = params.get('修改人員')
- 模組 = params.get('模組')
- 主板編號 = params.get('主板編號')
- 制動器編號 = params.get('制動器編號')
- 項目 = params.get('項目')
- 韌體有V = params.get('韌體(有V)')
- 韌體連結git = params.get('韌體連結git')
- 型號規格書 = params.get('型號(規格書)')
- 安裝位置 = params.get('安裝位置')
- 數量 = params.get('數量')
- 需求電壓V = params.get('需求電壓(V)')
- 需求電流A = params.get('需求電流(A)')
- 功率W = params.get('功率(W)')
- 通訊介面 = params.get('通訊介面')
- 芯數 = params.get('芯數')
- 線材編號 = params.get('線材編號')
- 單價 = params.get('單價')
- 總價 = params.get('總價')
- 請購單號 = params.get('請購單號')
- 電流_220V = params.get('220V_電流')
- 功率_220V = params.get('220V_功率')
- 電流_24V = params.get('24V_電流')
- 功率_24V = params.get('24V_功率')
- 電流_12V = params.get('12V_電流')
- 功率_12V = params.get('12V_功率')
- 電流_5V = params.get('5V_電流')
- 功率_5V = params.get('5V_功率')
- 電流_3_3V = params.get('3.3V_電流')
- 功率_3_3V = params.get('3.3V_功率')
- 流量率 = params.get('流量(率)')
- 容量 = params.get('容量')
- 壓力 = params.get('壓力')
-
- sql = "update sink set 狀態='%s',進貨狀態='%s',內部料號='%s',組序號='%s',模組圖名='%s',模組圖號出圖連結='%s',模組數量='%s',項次='%s',零件圖名='%s',零件圖號='%s',零件數量='%s',零件總數量='%s',類型='%s',進度='%s',備註='%s',出圖日期='%s',出圖人員='%s',修改日期='%s',修改原因='%s',修改人員='%s',模組='%s',主板編號='%s',制動器編號='%s',項目='%s',韌體 ( 有V)='%s',韌體連結git='%s',型號規格書='%s',安裝位置='%s',數量='%s',需求電壓(V)='%s',需求電流(A)='%s',功率(W)='%s',通訊介面='%s',芯數='%s',線材編號='%s',單價='%s',總價='%s',請購單號='%s',220V_電流='%s',220V_功率='%s',24V_電流='%s',24V_功率='%s',12V_電流='%s',12V_功率='%s',5V_電流='%s',5V_功率='%s',3.3V_電流='%s',3.3V_功率='%s',流量(率)='%s',容量='%s',壓力='%s' where userinfoId='%s'"%(狀態,進貨狀態,內部料號,組序號,模組圖名,模組圖號出圖連結,模組數量,項次,零件圖名,零件圖號,零件數量,零件總數量,類型,進度,備註,出圖日期,出圖人員,修改日期,修改原因,修改人員,模組,主板編號,制動器編號,項目,韌體有V,韌體連結git,型號規格書,安裝位置,數量,需求電壓V,需求電流A,功率W,通訊介面,芯數,線材編號,單價,總價,請購單號,電流_220V,功率_220V,電流_24V,功率_24V,電流_12V,功率_12V,電流_5V,功率_5V,電流_3_3V,功率_3_3V,流量率,容量,壓力,userinfoId) # 執行插入操作
-
- cur.execute(sql)
- conn.commit()
- return render_template('index.html') # 返回更新後的數據,確認是否更新成功
- @app.route('/bomform',methods=['GET','POST'])
- def bom():
- cur = conn.cursor()
- #獲取欄位名稱
- sql = "select 品名,內部料號 from product_info"
- cur.execute(sql)
- labels = cur.fetchall()
- print(labels)
- labels = [g for g in labels]
- if request.method =='POST':
- #sql = "SHOW FIELDS FROM product_info"
- #cur.execute(sql)
- #labels = cur.fetchall()
- #labels = [g[0] for g in labels]
- nn = request.values['test1']
- t = request.values['test2']
- t1 = request.values['test3']
- cur1 = conn.cursor()
- #獲取欄位資料
- cur1.execute("""select 品名 from product_info WHERE 品名 = {}""".format(repr(nn)))
- content1 = cur1.fetchone()
- cur2 = conn.cursor()
- #獲取欄位資料
- cur2.execute("""select 內部料號,品名,數量,庫存 from product_info WHERE 品名 = {}""".format(repr(t)))
- content2 = cur2.fetchall()
- cur3 = conn.cursor()
- #獲取欄位資料
- cur3.execute("""select 內部料號,品名,數量,庫存 from product_info WHERE 品名 = {}""".format(repr(t1)))
- content3 = cur3.fetchall()
- print(content1)
- print(content2)
- print(content3)
- return render_template('bom1.html',content1=content1,content2=content2,content3=content3,labels=labels)
-
- return render_template('bom.html', labels=labels)
- @app.route("/read_excel",methods=['GET','POST'])
- def read_excel():
- return render_template("read_excel.html")
- @app.route("/data_excel",methods=['GET','POST'])
- def data_excel():
- if request.method =='POST':
- f = request.form['csvfile']
- data = []
- with open(f,encoding='UTF8') as file:
- csvfile = csv.reader(file)
- for row in csvfile:
- data.append(row)
- data = pd.DataFrame(data)
- return render_template('data_excel.html',data=data.to_html(header=False,index=False))
- @app.route('/loginurl', methods=['GET', 'POST'])
- def login():
- # 利用request取得使用者端傳來的方法為何
- if request.method == 'POST':
- # 利用request取得表單欄位值
- return 'Hello ' + request.values['username']
-
- # 非POST的時候就會回傳一個空白的模板
- return render_template('login.html')
- @app.route('/Inquire_from/',methods=['GET','POST'])
- def Inquire_from():
- cur1 = conn.cursor()
- # 獲取欄位資料
- sql1 = "select DISTINCT 產品 from abc"
- cur1.execute(sql1)
- labels1 = cur1.fetchall()
- labels1 = [g[0] for g in labels1]
- print(labels1)
- cur2 = conn.cursor()
- # 獲取欄位資料
- sql2 = "select DISTINCT 系統 from abc"
- cur2.execute(sql2)
- labels2 = cur2.fetchall()
- labels2 = [g[0] for g in labels2]
- print(labels2)
- cur3 = conn.cursor()
- # 獲取欄位資料
- sql3 = "select DISTINCT 模組圖名 from abc"
- cur3.execute(sql3)
- labels3 = cur3.fetchall()
- labels3 = [g[0] for g in labels3]
- print(labels3)
- cur4 = conn.cursor()
- # 獲取欄位資料
- sql4 = "select DISTINCT 類型 from abc"
- cur4.execute(sql4)
- labels4 = cur4.fetchall()
- labels4 = [g[0] for g in labels4]
- print(labels4)
- if request.method == 'POST':
- sql = "SHOW FIELDS FROM abc"
- cur1.execute(sql)
- labels = cur1.fetchall()
- labels = [g[0] for g in labels]
- # ----------------------------------------#
- t1 = request.values['Test1']
- t2 = request.values['Test2']
- t3 = request.values['Test3']
- t4 = request.values['Test4']
- # print(t1)
- # print(t2)
- # print(t3)
- # print(t4)
- cur = conn.cursor()
- #
- data = 'select * from abc'
- if t1 == '' and t2 == '' and t3 == '' and t4 == '':
- pass
- else:
- data += ' WHERE '
- if t1 != '':
- data += '產品 = \'' + t1 + '\' '
- if t2 != '':
- data += ' AND '
- elif t3 != '':
- data += ' AND '
- elif t4 != '':
- data += ' AND '
- if t2 != '':
- data += '系統 = \'' + t2 + '\' '
- if t3 != '':
- data += ' AND '
- elif t4 != '':
- data += ' AND '
- if t3 != '':
- data += '模組圖名 = \'' + t3 + '\' '
- if t4 != '':
- data += ' AND '
- if t4 != '': data += '零件圖名 = \'' + t4 + '\' '
- print(data)
- # 進資料庫
- cur.execute(data)
- content = cur.fetchall()
- # print(content)
- return render_template('Inquire1.html', content=content, labels=labels)
- return render_template('Inquire.html',labels1=labels1,labels2=labels2,labels3=labels3,labels4=labels4)
-
- if __name__ == '__main__':
- app.run(debug=True,host='0.0.0.0',port=3030)
|