123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212 |
- from flask import Flask, render_template,request,url_for, redirect
- import pymysql
- import pandas as pd
- import csv
- import time
- app = Flask(__name__)
- conn = pymysql.connect(
- host='127.0.0.1',
- user='root',
- password='g53743001',
- db='erp',
- charset='utf8'
- )
- @app.route('/')
- def index():
- return render_template('index.html')
- #新增資料
- @app.route('/add_Nu',methods=['POST', 'GET'])
- def form():
- cur = conn.cursor()
- sql2 = "SELECT * FROM 會計科目表"
- cur.execute(sql2)
- 會計科目 = cur.fetchall()
- sql3 = "SELECT * FROM 類別表"
- cur.execute(sql3)
- 類別 = cur.fetchall()
- sql4 = "SELECT * FROM 供應商"
- cur.execute(sql4)
- 供應商 = cur.fetchall()
- sql5 = "SELECT 名稱 FROM 零件表"
- cur.execute(sql5)
- 名稱 = cur.fetchall()
- if request.method == 'POST':
-
- 會計科目 = request.form['會計科目']
- 類別 = request.form['類別']
- 供應商 = request.form['供應商']
- cur = conn.cursor()
- sql6 = "select 流水號 from 零件表 WHERE"
- sql7 = 'order by 流水號 desc limit 1'
- if 會計科目 != '' and 類別 != '':
- sql6 += ' 會計科目 = \'' + 會計科目 + '\' ' 'AND' ' 類別 = \'' + 類別 +'\''
- data = sql6 + sql7
- #"select 流水號 from 零件表 WHERE `會計科目` = '04' AND `類別` = '01' order by 流水號 desc limit 1"
- print(data)
- cur.execute(data)
- 流水號 = cur.fetchone()
- print('查詢後流水號:',流水號)
- if 流水號 == None:
- 流水號 = int('0000')+1
- 流水號 = '{0:04}'.format(流水號)
- print('+1後流水號:',流水號)
- else :
- 流水號 = int(流水號[0]) + 1
- print('+1後流水號:',流水號)
- 流水號 = '{0:04}'.format(流水號)
- 內部料號 = str(會計科目)+str(類別)+str(流水號)+str(供應商)
- print(內部料號)
- 名稱 = request.form['名稱']
- 原廠料號 = request.form['原廠料號']
- 尺寸 = request.form['尺寸']
- 封裝材質 = request.form['封裝/材質']
- 工作電壓 = request.form['工作電壓']
- 工作電流 = request.form['工作電流']
- 功率 = request.form['功率']
- 最大電流 = request.form['最大電流']
- 工作溫度 = request.form['工作溫度']
- print(名稱,原廠料號,尺寸,封裝材質,工作電壓,工作電流,功率,最大電流,工作溫度)
- print(內部料號)
- if 會計科目 != '' and 類別 != '' and 流水號 !='' and 供應商 != '' and 名稱 !='':
- cur = conn.cursor()
- cur.execute(' INSERT INTO 零件表 VALUES(%s,%s,%s,%s,%s,%s)'
- ,(內部料號,會計科目, 類別, 流水號,供應商, 名稱))
- conn.commit()
- cur.close()
- else:
- print('都沒輸入,直接略過')
- pass
- if 名稱 != ''and 原廠料號 != ''and 尺寸 != '' and 封裝材質 !='' and 工作電壓 != '' and 工作電流 !=''and 功率 !='' and 最大電流 !='' and 工作溫度 !='':
- cur = conn.cursor()
- sql1 = "INSERT INTO 規格表 VALUES('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')"%(內部料號,名稱,原廠料號,尺寸, 封裝材質, 工作電壓, 工作電流, 功率, 最大電流, 工作溫度)
- cur.execute(sql1)
- conn.commit()
- cur.close()
- else:
- print('都沒輸入,直接略過')
- pass
- return render_template('update.html',**locals())
- return render_template('update.html',**locals())
- @app.route('/bom/')
- def bom():
- return render_template('bom.html')
- #改資料
- @app.route('/modify/',methods=['POST', 'GET'])
- def modify():
- cur = conn.cursor()
- sql = "SELECT 內部料號,名稱 FROM 規格表"
- cur.execute(sql)
- 內部料號 = cur.fetchall()
- #內部料號 = [g for g in 內部料號]
- if request.method == 'POST':
-
- 內部料號 = request.form['內部料號']
- 名稱 = request.form['名稱']
- 原廠料號 = request.form['原廠料號']
- 尺寸 = request.form['尺寸']
- 封裝材質 = request.form['封裝/材質']
- 工作電壓 = request.form['工作電壓']
- 工作電流 = request.form['工作電流']
- 功率 = request.form['功率']
- 最大電流 = request.form['最大電流']
- 工作溫度 = request.form['工作溫度']
- if 內部料號 != '' and 名稱 != ''and 原廠料號 != ''and 尺寸 != '' and 封裝材質 !='' and 工作電壓 != '' and 工作電流 !=''and 功率 !='' and 最大電流 !='' and 工作溫度 !='':
- cur = conn.cursor()
- sql = "update 規格表 set 名稱='%s',原廠料號='%s',尺寸='%s',`封裝/材質`='%s',工作電壓='%s',工作電流='%s',功率='%s',最大電流='%s',工作溫度='%s'"" where 內部料號='%s'"\
- %(名稱,原廠料號,尺寸, 封裝材質, 工作電壓, 工作電流, 功率, 最大電流, 工作溫度, 內部料號[2:13])
- cur.execute(sql)
- conn.commit()
- cur.close()
- else:
- print('都沒輸入,直接略過')
- pass
- return render_template('index.html')
- return render_template('modify.html',內部料號=內部料號)
- #查資料
- @app.route('/check/', methods=['GET', 'POST'])
- def check():
- cur = conn.cursor()
- # 獲取欄位名稱
- sql = "select 內部料號,名稱 from 規格表 "
- cur.execute(sql)
- labels = cur.fetchall()
- print(labels)
- labels = [g for g in labels]
- if request.method == 'POST':
- sql = "SHOW FIELDS FROM `規格表`"
- cur.execute(sql)
- labels = cur.fetchall()
- labels = [g[0] for g in labels]
- global t
- t = request.values['Test']
- #t = t[2:13]
- print(t[2:13])
- cur = conn.cursor()
- # 獲取欄位資料
- cur.execute("""select * from `規格表` WHERE 內部料號 = {}""".format(repr(t[2:13])))
- content = cur.fetchall()
- print(content)
- return render_template('check1.html', labels=labels,content=content)
- return render_template('check.html', labels=labels)
- #刪除資料
- @app.route('/del_data/', methods=['GET', 'POST'])
- def del_data():
- if request.method == 'POST':
- print('內部料號:',t[2:13])
- cur = conn.cursor()
- sql1 = "DELETE FROM `規格表` WHERE `內部料號` = {}".format(repr(t[2:13]))
- cur.execute(sql1)
- cur.close()
- print(sql1)
- cur = conn.cursor()
- sql2 = "DELETE FROM `零件表` WHERE `內部料號` = {}".format(repr(t[2:13]))
- cur.execute(sql2)
- cur.close()
- print(sql2)
-
-
- return render_template('index.html')
- if __name__ == '__main__':
- app.run(debug=True,port=5050)
|