app.py 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  1. from flask import Flask, render_template,request,url_for, redirect
  2. import pymysql
  3. import pandas as pd
  4. import csv
  5. app = Flask(__name__)
  6. conn = pymysql.connect(
  7. host='127.0.0.1',
  8. user='root',
  9. password='Gold@53743001',
  10. db='erp',
  11. charset='utf8'
  12. )
  13. #首頁
  14. @app.route("/")
  15. def index():
  16. return render_template("index.html",title = 'ERP WEB')
  17. #產品清單頁面
  18. @app.route('/productinfo/')
  19. def productinfo():
  20. cur = conn.cursor()
  21. #獲取欄位資料
  22. sql = "select * from product_info"
  23. cur.execute(sql)
  24. content = cur.fetchall()
  25. #獲取欄位名稱
  26. sql = "SHOW FIELDS FROM product_info"
  27. cur.execute(sql)
  28. labels = cur.fetchall()
  29. labels = [g[0] for g in labels]
  30. return render_template('productinfo.html', labels=labels, content=content)
  31. @app.route('/submit/')
  32. def form():
  33. return render_template('submit.html')
  34. #新增產品清單內容
  35. @app.route('/add_product', methods=['POST', 'GET'])
  36. def add_product():
  37. if request.method == 'GET':
  38. return "Login via the login Form"
  39. if request.method == 'POST':
  40. NO = request.form['NO']
  41. 內部料號 = request.form['內部料號']
  42. 品名 = request.form['品名']
  43. 規格型號 = request.form['規格型號']
  44. 類型 = request.form['類型']
  45. 技術文件連結 = request.form['技術文件連結']
  46. 原廠料號 = request.form['原廠料號']
  47. 賣家料號 = request.form['賣家料號']
  48. 圖示 = request.form['圖示']
  49. 進單價 = request.form['進單價']
  50. 數量 = request.form['數量']
  51. 單位 = request.form['單位']
  52. 取得方式 = request.form['取得方式']
  53. 庫存 = request.form['庫存']
  54. 廠商 = request.form['廠商']
  55. cur = conn.cursor()
  56. cur.execute(''' INSERT INTO product_info VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)'''
  57. , (NO, 內部料號, 品名, 規格型號, 類型, 技術文件連結, 原廠料號, 賣家料號, 圖示, 進單價, 數量, 單位, 取得方式, 庫存, 廠商))
  58. conn.commit()
  59. cur.close()
  60. return f"Done!!"
  61. @app.route('/check/',methods=['GET','POST'])
  62. def check():
  63. cur = conn.cursor()
  64. #獲取欄位名稱
  65. sql = "select 品名 from product_info"
  66. cur.execute(sql)
  67. labels = cur.fetchall()
  68. labels = [g[0] for g in labels]
  69. if request.method =='POST':
  70. sql = "SHOW FIELDS FROM product_info"
  71. cur.execute(sql)
  72. labels = cur.fetchall()
  73. labels = [g[0] for g in labels]
  74. t = request.values['Test']
  75. #print(t)
  76. cur = conn.cursor()
  77. #獲取欄位資料
  78. cur.execute("""select * from product_info WHERE 品名 = {}""".format(repr(t)))
  79. content = cur.fetchall()
  80. #print(content)
  81. return render_template('check1.html',content=content,labels=labels)
  82. return render_template('check.html', labels=labels)
  83. @app.route('/update/')
  84. def update():
  85. # 獲取頁面輸入內容,提供給sql使用
  86. userinfoId = request.args.get('userinfoId')
  87. name = request.args.get('name') # 更新後的數據返回到頁面上面顯示
  88. #return render_template('update.html')
  89. #修改資料庫資料
  90. @app.route('/updateaction/', methods=['POST'])
  91. def updateaction():
  92. cur = conn.cursor()
  93. params = request.args if request.method == 'GET' else request.form
  94. #選定欄位的值
  95. userinfoId = params.get('userinfoId')
  96. #修改的數值
  97. 技術文件連結 = params.get('技術文件連結')
  98. NO = params.get('NO')
  99. 品名 = params.get('品名')
  100. 規格型號 = params.get('規格型號')
  101. 類型 = params.get('類型')
  102. 原廠料號 = params.get('原廠料號')
  103. 賣家料號 = params.get('賣家料號')
  104. 圖示 = params.get('圖示')
  105. 進單價 = params.get('進單價')
  106. 數量 = params.get('數量')
  107. 單位 = params.get('單位')
  108. 取得方式 = params.get('取得方式')
  109. 庫存 = params.get('庫存')
  110. 廠商 = params.get('廠商')
  111. sql = "update product_info set 技術文件連結='%s',NO='%s',品名='%s',規格型號='%s'" \
  112. ",類型='%s',原廠料號='%s',賣家料號='%s',圖示='%s'" \
  113. ",進單價='%s',數量='%s',單位='%s',取得方式='%s'" \
  114. ",庫存='%s',廠商='%s' where 內部料號='%s'" \
  115. %(技術文件連結,NO,品名,規格型號,類型,原廠料號,賣家料號,圖示,進單價,數量,單位,取得方式,庫存,廠商,userinfoId) # 執行插入操作
  116. cur.execute(sql)
  117. conn.commit()
  118. return render_template('index.html') # 返回更新後的數據,確認是否更新成功
  119. #---------------------------------------------------------------------------------------#
  120. #產品清單頁面
  121. @app.route('/system_sink/')
  122. def system_sink():
  123. cur = conn.cursor()
  124. #獲取欄位資料
  125. sql = "select * from abc"
  126. cur.execute(sql)
  127. content = cur.fetchall()
  128. print(content)
  129. #獲取欄位名稱
  130. sql = "SHOW FIELDS from abc"
  131. cur.execute(sql)
  132. labels = cur.fetchall()
  133. labels = [g[0] for g in labels]
  134. return render_template('system_sink.html', labels=labels, content=content)
  135. @app.route('/submit_sink/')
  136. def form_sink():
  137. return render_template('submit_sink.html')
  138. #新增產品清單內容
  139. @app.route('/add_sink', methods=['POST', 'GET'])
  140. def add_sink():
  141. if request.method == 'GET':
  142. return "Login via the login Form"
  143. if request.method == 'POST':
  144. 系統 = request.form['系統']
  145. 狀態 = request.form['狀態']
  146. 進貨狀態 = request.form['進貨狀態']
  147. 內部料號 = request.form['內部料號']
  148. 組序號 = request.form['組序號']
  149. 模組圖名 = request.form['模組圖名']
  150. 模組圖號出圖連結 = request.form['模組圖號/出圖連結']
  151. 模組數量 = request.form['模組數量']
  152. 項次 = request.form['項次']
  153. 零件圖名 = request.form['零件圖名']
  154. 零件圖號 = request.form['零件圖號']
  155. 零件數量 = request.form['零件數量']
  156. 零件總數量 = request.form['零件總數量']
  157. 類型 = request.form['類型']
  158. 進度 = request.form['進度']
  159. 備註 = request.form['備註']
  160. 出圖日期 = request.form['出圖日期']
  161. 出圖人員 = request.form['出圖人員']
  162. 修改日期 = request.form['修改日期']
  163. 修改原因 = request.form['修改原因']
  164. 修改人員 = request.form['修改人員']
  165. 模組 = request.form['模組']
  166. 主板編號 = request.form['主板編號']
  167. 制動器編號 = request.form['制動器編號']
  168. 項目 = request.form['項目']
  169. 韌體有V = request.form['韌體(有V)']
  170. 韌體連結git = request.form['韌體連結git']
  171. 型號規格書 = request.form['型號(規格書)']
  172. 安裝位置 = request.form['安裝位置']
  173. 數量 = request.form['數量']
  174. 需求電壓V = request.form['需求電壓(V)']
  175. 需求電流A = request.form['需求電流(A)']
  176. 功率W = request.form['功率(W)']
  177. 通訊介面 = request.form['通訊介面']
  178. 芯數 = request.form['芯數']
  179. 線材編號 = request.form['線材編號']
  180. 單價 = request.form['單價']
  181. 總價 = request.form['總價']
  182. 請購單號 = request.form['請購單號']
  183. 電流_220V = request.form['220V_電流']
  184. 功率_220V = request.form['220V_功率']
  185. 電流_24V = request.form['24V_電流']
  186. 功率_24V = request.form['24V_功率']
  187. 電流_12V = request.form['12V_電流']
  188. 功率_12V = request.form['12V_功率']
  189. 電流_5V = request.form['5V_電流']
  190. 功率_5V = request.form['5V_功率']
  191. 電流_3_3V = request.form['3.3V_電流']
  192. 功率_3_3V = request.form['3.3V_功率']
  193. 流量率 = request.form['流量(率)']
  194. 容量 = request.form['容量']
  195. 壓力 = request.form['壓力']
  196. cur = conn.cursor()
  197. 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)'''
  198. , (系統,狀態,進貨狀態,內部料號,組序號,模組圖名,模組圖號出圖連結,模組數量,項次,零件圖名,零件圖號,零件數量,零件總數量,類型,進度,備註,出圖日期,出圖人員,修改日期,修改原因,修改人員,模組,主板編號,制動器編號,項目,韌體有V,韌體連結git,型號規格書,安裝位置,數量,需求電壓V,需求電流A,功率W,通訊介面,芯數,線材編號,單價,總價,請購單號,電流_220V,功率_220V,電流_24V,功率_24V,電流_12V,功率_12V,電流_5V,功率_5V,電流_3_3V,功率_3_3V,流量率,容量,壓力))
  199. conn.commit()
  200. cur.close()
  201. return f"Done!!"
  202. @app.route('/check_sink/',methods=['GET','POST'])
  203. def check_sink():
  204. cur = conn.cursor()
  205. #獲取欄位名稱
  206. sql = "select 組序號 from abc"
  207. cur.execute(sql)
  208. labels = cur.fetchall()
  209. labels = [g[0] for g in labels]
  210. if request.method =='POST':
  211. sql = "SHOW FIELDS from abc"
  212. cur.execute(sql)
  213. labels = cur.fetchall()
  214. labels = [g[0] for g in labels]
  215. t = request.values['Test']
  216. #print(t)
  217. cur = conn.cursor()
  218. #獲取欄位資料
  219. cur.execute("""select * from abc WHERE 組序號 = {}""".format(repr(t)))
  220. content = cur.fetchall()
  221. #print(content)
  222. return render_template('check1_sink.html',content=content,labels=labels)
  223. return render_template('check_sink.html', labels=labels)
  224. @app.route('/update_sink/')
  225. def update_sink():
  226. # 獲取頁面輸入內容,提供給sql使用
  227. userinfoId = request.args.get('系統')
  228. name = request.args.get('name') # 更新後的數據返回到頁面上面顯示
  229. #return render_template('update.html')
  230. #修改資料庫資料
  231. @app.route('/updateaction_sink/', methods=['POST'])
  232. def updateaction_sink():
  233. cur = conn.cursor()
  234. params = request.args if request.method == 'GET' else request.form
  235. #選定欄位的值
  236. userinfoId = params.get('系統')
  237. #修改的數值
  238. 狀態 = params.get('狀態')
  239. 進貨狀態 = params.get('進貨狀態')
  240. 內部料號 = params.get('內部料號')
  241. 組序號 = params.get('組序號')
  242. 模組圖名 = params.get('模組圖名')
  243. 模組圖號出圖連結 = params.get('模組圖號出圖連結')
  244. 模組數量 = params.get('模組數量')
  245. 項次 = params.get('項次')
  246. 零件圖名 = params.get('零件圖名')
  247. 零件圖號 = params.get('零件圖號')
  248. 零件數量 = params.get('零件數量')
  249. 零件總數量 = params.get('零件總數量')
  250. 類型 = params.get('類型')
  251. 進度 = params.get('進度')
  252. 備註 = params.get('備註')
  253. 出圖日期 = params.get('出圖日期')
  254. 出圖人員 = params.get('出圖人員')
  255. 修改日期 = params.get('修改日期')
  256. 修改原因 = params.get('修改原因')
  257. 修改人員 = params.get('修改人員')
  258. 模組 = params.get('模組')
  259. 主板編號 = params.get('主板編號')
  260. 制動器編號 = params.get('制動器編號')
  261. 項目 = params.get('項目')
  262. 韌體有V = params.get('韌體(有V)')
  263. 韌體連結git = params.get('韌體連結git')
  264. 型號規格書 = params.get('型號(規格書)')
  265. 安裝位置 = params.get('安裝位置')
  266. 數量 = params.get('數量')
  267. 需求電壓V = params.get('需求電壓(V)')
  268. 需求電流A = params.get('需求電流(A)')
  269. 功率W = params.get('功率(W)')
  270. 通訊介面 = params.get('通訊介面')
  271. 芯數 = params.get('芯數')
  272. 線材編號 = params.get('線材編號')
  273. 單價 = params.get('單價')
  274. 總價 = params.get('總價')
  275. 請購單號 = params.get('請購單號')
  276. 電流_220V = params.get('220V_電流')
  277. 功率_220V = params.get('220V_功率')
  278. 電流_24V = params.get('24V_電流')
  279. 功率_24V = params.get('24V_功率')
  280. 電流_12V = params.get('12V_電流')
  281. 功率_12V = params.get('12V_功率')
  282. 電流_5V = params.get('5V_電流')
  283. 功率_5V = params.get('5V_功率')
  284. 電流_3_3V = params.get('3.3V_電流')
  285. 功率_3_3V = params.get('3.3V_功率')
  286. 流量率 = params.get('流量(率)')
  287. 容量 = params.get('容量')
  288. 壓力 = params.get('壓力')
  289. 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) # 執行插入操作
  290. cur.execute(sql)
  291. conn.commit()
  292. return render_template('index.html') # 返回更新後的數據,確認是否更新成功
  293. @app.route('/bomform',methods=['GET','POST'])
  294. def bom():
  295. cur = conn.cursor()
  296. #獲取欄位名稱
  297. sql = "select 品名,內部料號 from product_info"
  298. cur.execute(sql)
  299. labels = cur.fetchall()
  300. print(labels)
  301. labels = [g for g in labels]
  302. if request.method =='POST':
  303. #sql = "SHOW FIELDS FROM product_info"
  304. #cur.execute(sql)
  305. #labels = cur.fetchall()
  306. #labels = [g[0] for g in labels]
  307. nn = request.values['test1']
  308. t = request.values['test2']
  309. t1 = request.values['test3']
  310. cur1 = conn.cursor()
  311. #獲取欄位資料
  312. cur1.execute("""select 品名 from product_info WHERE 品名 = {}""".format(repr(nn)))
  313. content1 = cur1.fetchone()
  314. cur2 = conn.cursor()
  315. #獲取欄位資料
  316. cur2.execute("""select 內部料號,品名,數量,庫存 from product_info WHERE 品名 = {}""".format(repr(t)))
  317. content2 = cur2.fetchall()
  318. cur3 = conn.cursor()
  319. #獲取欄位資料
  320. cur3.execute("""select 內部料號,品名,數量,庫存 from product_info WHERE 品名 = {}""".format(repr(t1)))
  321. content3 = cur3.fetchall()
  322. print(content1)
  323. print(content2)
  324. print(content3)
  325. return render_template('bom1.html',content1=content1,content2=content2,content3=content3,labels=labels)
  326. return render_template('bom.html', labels=labels)
  327. @app.route("/read_excel",methods=['GET','POST'])
  328. def read_excel():
  329. return render_template("read_excel.html")
  330. @app.route("/data_excel",methods=['GET','POST'])
  331. def data_excel():
  332. if request.method =='POST':
  333. f = request.form['csvfile']
  334. data = []
  335. with open(f,encoding='UTF8') as file:
  336. csvfile = csv.reader(file)
  337. for row in csvfile:
  338. data.append(row)
  339. data = pd.DataFrame(data)
  340. return render_template('data_excel.html',data=data.to_html(header=False,index=False))
  341. @app.route('/loginurl', methods=['GET', 'POST'])
  342. def login():
  343. # 利用request取得使用者端傳來的方法為何
  344. if request.method == 'POST':
  345. # 利用request取得表單欄位值
  346. return 'Hello ' + request.values['username']
  347. # 非POST的時候就會回傳一個空白的模板
  348. return render_template('login.html')
  349. @app.route('/Inquire_from/',methods=['GET','POST'])
  350. def Inquire_from():
  351. cur1 = conn.cursor()
  352. # 獲取欄位資料
  353. sql1 = "select DISTINCT 產品 from abc"
  354. cur1.execute(sql1)
  355. labels1 = cur1.fetchall()
  356. labels1 = [g[0] for g in labels1]
  357. print(labels1)
  358. cur2 = conn.cursor()
  359. # 獲取欄位資料
  360. sql2 = "select DISTINCT 系統 from abc"
  361. cur2.execute(sql2)
  362. labels2 = cur2.fetchall()
  363. labels2 = [g[0] for g in labels2]
  364. print(labels2)
  365. cur3 = conn.cursor()
  366. # 獲取欄位資料
  367. sql3 = "select DISTINCT 模組圖名 from abc"
  368. cur3.execute(sql3)
  369. labels3 = cur3.fetchall()
  370. labels3 = [g[0] for g in labels3]
  371. print(labels3)
  372. cur4 = conn.cursor()
  373. # 獲取欄位資料
  374. sql4 = "select DISTINCT 類型 from abc"
  375. cur4.execute(sql4)
  376. labels4 = cur4.fetchall()
  377. labels4 = [g[0] for g in labels4]
  378. print(labels4)
  379. if request.method == 'POST':
  380. sql = "SHOW FIELDS FROM abc"
  381. cur1.execute(sql)
  382. labels = cur1.fetchall()
  383. labels = [g[0] for g in labels]
  384. # ----------------------------------------#
  385. t1 = request.values['Test1']
  386. t2 = request.values['Test2']
  387. t3 = request.values['Test3']
  388. t4 = request.values['Test4']
  389. # print(t1)
  390. # print(t2)
  391. # print(t3)
  392. # print(t4)
  393. cur = conn.cursor()
  394. #
  395. data = 'select * from abc'
  396. if t1 == '' and t2 == '' and t3 == '' and t4 == '':
  397. pass
  398. else:
  399. data += ' WHERE '
  400. if t1 != '':
  401. data += '產品 = \'' + t1 + '\' '
  402. if t2 != '':
  403. data += ' AND '
  404. elif t3 != '':
  405. data += ' AND '
  406. elif t4 != '':
  407. data += ' AND '
  408. if t2 != '':
  409. data += '系統 = \'' + t2 + '\' '
  410. if t3 != '':
  411. data += ' AND '
  412. elif t4 != '':
  413. data += ' AND '
  414. if t3 != '':
  415. data += '模組圖名 = \'' + t3 + '\' '
  416. if t4 != '':
  417. data += ' AND '
  418. if t4 != '': data += '零件圖名 = \'' + t4 + '\' '
  419. print(data)
  420. # 進資料庫
  421. cur.execute(data)
  422. content = cur.fetchall()
  423. # print(content)
  424. return render_template('Inquire1.html', content=content, labels=labels)
  425. return render_template('Inquire.html',labels1=labels1,labels2=labels2,labels3=labels3,labels4=labels4)
  426. if __name__ == '__main__':
  427. app.run(debug=True,host='0.0.0.0',port=3030)