app.py 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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"
  47. cur5.execute(sql5)
  48. labels5 = cur5.fetchall()
  49. labels5 = [g[0] for g in labels5]
  50. print(labels5)
  51. cur6 = conn.cursor()
  52. # 獲取欄位資料
  53. sql6 = "select DISTINCT 系統 from abc"
  54. cur6.execute(sql6)
  55. labels6 = cur6.fetchall()
  56. labels6 = [g[0] for g in labels6]
  57. print(labels6)
  58. cur7 = conn.cursor()
  59. # 獲取欄位資料
  60. sql7 = "select DISTINCT 模組圖名 from abc"
  61. cur7.execute(sql7)
  62. labels7 = cur7.fetchall()
  63. labels7 = [g[0] for g in labels7]
  64. print(labels7)
  65. cur8 = conn.cursor()
  66. # 獲取欄位資料
  67. sql8 = "select DISTINCT 零件圖名 from abc"
  68. cur8.execute(sql8)
  69. labels8 = cur8.fetchall()
  70. labels8 = [g[0] for g in labels8]
  71. print(labels8)
  72. if request.method =='POST':
  73. sql = "SHOW FIELDS FROM abc"
  74. cur1.execute(sql)
  75. labels = cur1.fetchall()
  76. labels = [g[0] for g in labels]
  77. #----------------------------------------#
  78. t1 = request.values['Test1']
  79. t2 = request.values['Test2']
  80. t3 = request.values['Test3']
  81. t4 = request.values['Test4']
  82. t5 = request.values['Test5']
  83. t6 = request.values['Test6']
  84. t7 = request.values['Test7']
  85. t8 = request.values['Test8']
  86. #print(t1)
  87. #print(t2)
  88. #print(t3)
  89. #print(t4)
  90. cur = conn.cursor()
  91. #
  92. data = 'select * from abc'
  93. if t1 == '' and t2 == '' and t3 == '' and t4 == '':
  94. pass
  95. else:
  96. data += ' WHERE '
  97. if t1 != '':
  98. data += '產品 = \'' + t1 + '\' '
  99. if t2 != '':
  100. data += ' AND '
  101. elif t3 != '':
  102. data += ' AND '
  103. elif t4 != '':
  104. data += ' AND '
  105. if t2 != '':
  106. data += '系統 = \'' + t2 + '\' '
  107. if t3 != '':
  108. data += ' AND '
  109. elif t4 != '':
  110. data += ' AND '
  111. if t3 != '':
  112. data += '模組圖名 = \'' + t3 + '\' '
  113. if t4 != '':
  114. data += ' AND '
  115. if t4 != '':
  116. data += '零件圖名 = \'' + t4 + '\' '
  117. print(data)
  118. # 進資料庫
  119. cur.execute(data)
  120. content = cur.fetchall()
  121. #print(content)
  122. data1 = 'select * from abc'
  123. if t5 == '' and t6 == '' and t7 == '' and t8 == '':
  124. pass
  125. else:
  126. data += ' WHERE '
  127. if t5 != '':
  128. data += '產品 = \'' + t5 + '\' '
  129. if t6 != '':
  130. data += ' AND '
  131. elif t7 != '':
  132. data += ' AND '
  133. elif t8 != '':
  134. data += ' AND '
  135. if t6 != '':
  136. data += '系統 = \'' + t6 + '\' '
  137. if t7 != '':
  138. data += ' AND '
  139. elif t8 != '':
  140. data += ' AND '
  141. if t7 != '':
  142. data += '模組圖名 = \'' + t7 + '\' '
  143. if t8 != '':
  144. data += ' AND '
  145. if t8 != '':
  146. data += '零件圖名 = \'' + t8 + '\' '
  147. print(data1)
  148. # 進資料庫
  149. cur.execute(data1)
  150. return render_template('Inquire1.html', content=content, labels=labels)
  151. return render_template('Inquire.html',labels1=labels1,labels2=labels2,labels3=labels3,labels4=labels4,
  152. labels5=labels5,labels6=labels6,labels7=labels7,labels8=labels8)
  153. if __name__ == '__main__':
  154. app.run(debug=True,port=5050)