app.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. # MySQL configurations
  7. conn = pymysql.connect(
  8. host='127.0.0.1',
  9. user='root',
  10. password='g53743001',
  11. db='erptest',
  12. charset='utf8'
  13. )
  14. @app.route('/Inquire_from/',methods=['GET','POST'])
  15. def Inquire_from():
  16. cur1 = conn.cursor()
  17. # 獲取欄位資料
  18. sql1 = "select DISTINCT 產品 from abc"
  19. cur1.execute(sql1)
  20. labels1 = cur1.fetchall()
  21. labels1 = [g[0] for g in labels1]
  22. #print(labels1)
  23. cur2 = conn.cursor()
  24. # 獲取欄位資料
  25. sql2 = "select DISTINCT 系統 from abc"
  26. cur2.execute(sql2)
  27. labels2 = cur2.fetchall()
  28. labels2 = [g[0] for g in labels2]
  29. #print(labels2)
  30. cur3 = conn.cursor()
  31. # 獲取欄位資料
  32. sql3 = "select DISTINCT 模組圖名 from abc"
  33. cur3.execute(sql3)
  34. labels3 = cur3.fetchall()
  35. labels3 = [g[0] for g in labels3]
  36. #print(labels3)
  37. cur4 = conn.cursor()
  38. # 獲取欄位資料
  39. sql4 = "select DISTINCT 零件圖名 from abc"
  40. cur4.execute(sql4)
  41. labels4 = cur4.fetchall()
  42. labels4 = [g[0] for g in labels4]
  43. #print(labels4)
  44. cur5 = conn.cursor()
  45. # 獲取欄位資料
  46. sql5 = "select DISTINCT 系統 from abc WHERE 產品 = '乾燥貨櫃' "
  47. cur5.execute(sql5)
  48. labels5 = cur5.fetchall()
  49. labels5 = [g[0] for g in labels5]
  50. print(labels5)
  51. if request.method == 'POST':
  52. sql = "SHOW FIELDS FROM abc"
  53. cur1.execute(sql)
  54. labels = cur1.fetchall()
  55. labels = [g[0] for g in labels]
  56. # ----------------------------------------#
  57. t1 = request.values['Test1']
  58. t2 = request.values['Test2']
  59. t3 = request.values['Test3']
  60. t4 = request.values['Test4']
  61. # print(t1)
  62. # print(t2)
  63. # print(t3)
  64. # print(t4)
  65. cur = conn.cursor()
  66. #
  67. data = 'select * from abc'
  68. if t1 == '' and t2 == '' and t3 == '' and t4 == '':
  69. pass
  70. else:
  71. data += ' WHERE '
  72. if t1 != '':
  73. data += '產品 = \'' + t1 + '\' '
  74. if t2 != '':
  75. data += ' AND '
  76. elif t3 != '':
  77. data += ' AND '
  78. elif t4 != '':
  79. data += ' AND '
  80. if t2 != '':
  81. data += '系統 = \'' + t2 + '\' '
  82. if t3 != '':
  83. data += ' AND '
  84. elif t4 != '':
  85. data += ' AND '
  86. if t3 != '':
  87. data += '模組圖名 = \'' + t3 + '\' '
  88. if t4 != '':
  89. data += ' AND '
  90. if t4 != '': data += '零件圖名 = \'' + t4 + '\' '
  91. print(data)
  92. # 進資料庫
  93. cur.execute(data)
  94. content = cur.fetchall()
  95. # print(content)
  96. return render_template('Inquire1.html', content=content, labels=labels)
  97. return render_template('two_list.html',labels1=labels1,labels2=labels2,labels3=labels3,labels4=labels4,labels5=labels5)
  98. if __name__ == '__main__':
  99. app.run(debug=True,port=5050)