Sfoglia il codice sorgente

上傳檔案到 'select_mysql'

fatwolf 3 anni fa
parent
commit
a758d65c92
3 ha cambiato i file con 355 aggiunte e 0 eliminazioni
  1. 84 0
      select_mysql/Inquire.html
  2. 89 0
      select_mysql/Inquire1.html
  3. 182 0
      select_mysql/app.py

+ 84 - 0
select_mysql/Inquire.html

@@ -0,0 +1,84 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+</head>
+
+
+<body>
+
+
+<form action="{{ url_for('Inquire_from') }}" method="POST">
+  <select name="Test1">
+    <tr>
+    <option value="" selected></option>
+    {% for i1 in labels1 %}
+    <option>{{i1}}</option>
+    {% endfor %}
+    </tr>
+  </select>
+  <select name="Test2">
+    <tr>
+    <option value="" selected></option>
+    {% for i1 in labels2 %}
+    <option>{{i1}}</option>
+    {% endfor %}
+    </tr>
+  </select>
+  <select name="Test3">
+    <tr>
+    <option value="" selected></option>
+    {% for i1 in labels3 %}
+    <option>{{i1}}</option>
+    {% endfor %}
+    </tr>
+  </select>
+  <select name="Test4">
+    <tr>
+    <option value="" selected></option>
+    {% for i1 in labels4 %}
+    <option>{{i1}}</option>
+    {% endfor %}
+    </tr>
+  </select>
+  <br>
+  <select name="Test5">
+    <tr>
+    <option value="" selected></option>
+    {% for i1 in labels5 %}
+    <option>{{i1}}</option>
+    {% endfor %}
+    </tr>
+  </select>
+  <select name="Test6">
+    <tr>
+    <option value="" selected></option>
+    {% for i1 in labels6 %}
+    <option>{{i1}}</option>
+    {% endfor %}
+    </tr>
+  </select>
+  <select name="Test7">
+    <tr>
+    <option value="" selected></option>
+    {% for i1 in labels7 %}
+    <option>{{i1}}</option>
+    {% endfor %}
+    </tr>
+  </select>
+  <select name="Test8">
+    <tr>
+    <option value="" selected></option>
+    {% for i1 in labels8 %}
+    <option>{{i1}}</option>
+    {% endfor %}
+    </tr>
+  </select>
+  <br>
+
+
+
+
+  <button type='submit'>Submit</button>
+</form>
+</body>
+</html>

+ 89 - 0
select_mysql/Inquire1.html

@@ -0,0 +1,89 @@
+<!DOCTYPE html>
+<html>
+<style>
+table, th, td {
+  border:1px solid black;
+}
+</style>
+
+
+<body>
+
+
+<form>
+<table class="table table-bordered">
+    <tr>
+
+      {% for i1 in labels %}
+        <th>{{i1}}</font></th>
+      {% endfor %}
+    </tr>
+
+      {% for i in content %}
+      <tr>
+        <td>{{ i[0] }}</td>
+        <td>{{ i[1] }}</td>
+        <td>{{ i[2] }}</td>
+        <td>{{ i[3] }}</td>
+        <td>{{ i[4] }}</td>
+        <td>{{ i[5] }}</td>
+        <td>{{ i[6] }}</td>
+        <td>{{ i[7] }}</td>
+        <td>{{ i[8] }}</td>
+        <td>{{ i[9] }}</td>
+        <td>{{ i[10] }}</td>
+        <td>{{ i[11] }}</td>
+        <td>{{ i[12] }}</td>
+        <td>{{ i[13] }}</td>
+        <td>{{ i[14] }}</td>
+        <td>{{ i[15] }}</td>
+        <td>{{ i[16] }}</td>
+        <td>{{ i[17] }}</td>
+        <td>{{ i[18] }}</td>
+        <td>{{ i[19] }}</td>
+        <td>{{ i[20] }}</td>
+        <td>{{ i[21] }}</td>
+        <td>{{ i[22] }}</td>
+        <td>{{ i[23] }}</td>
+        <td>{{ i[24] }}</td>
+        <td>{{ i[25] }}</td>
+        <td>{{ i[26] }}</td>
+        <td>{{ i[27] }}</td>
+        <td>{{ i[28] }}</td>
+        <td>{{ i[29] }}</td>
+        <td>{{ i[30] }}</td>
+        <td>{{ i[31] }}</td>
+        <td>{{ i[32] }}</td>
+        <td>{{ i[33] }}</td>
+        <td>{{ i[34] }}</td>
+        <td>{{ i[35] }}</td>
+        <td>{{ i[36] }}</td>
+        <td>{{ i[37] }}</td>
+        <td>{{ i[38] }}</td>
+        <td>{{ i[39] }}</td>
+        <td>{{ i[40] }}</td>
+        <td>{{ i[41] }}</td>
+        <td>{{ i[42] }}</td>
+        <td>{{ i[43] }}</td>
+        <td>{{ i[44] }}</td>
+        <td>{{ i[45] }}</td>
+        <td>{{ i[46] }}</td>
+        <td>{{ i[47] }}</td>
+        <td>{{ i[48] }}</td>
+        <td>{{ i[49] }}</td>
+        <td>{{ i[50] }}</td>
+        <td>{{ i[51] }}</td>
+        <td>{{ i[52] }}</td>
+        <td>{{ i[53] }}</td>
+        <td>{{ i[54] }}</td>
+        <td>{{ i[55] }}</td>
+        <td>{{ i[56] }}</td>
+        <td>{{ i[57] }}</td>
+        <td>{{ i[58] }}</td>
+      </tr>
+    {% endfor %}
+    </table>
+</form>
+
+</body>
+</html>

+ 182 - 0
select_mysql/app.py

@@ -0,0 +1,182 @@
+from flask import Flask, render_template,request,url_for, redirect
+import pymysql
+import pandas as pd
+import csv
+
+app = Flask(__name__)
+
+
+
+# MySQL configurations
+conn = pymysql.connect(
+    host='127.0.0.1',
+    user='root',
+    password='g53743001',
+    db='erptest',
+    charset='utf8'
+)
+
+
+@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)
+
+    cur5 = conn.cursor()
+    # 獲取欄位資料
+    sql5 = "select DISTINCT 產品 from abc"
+    cur5.execute(sql5)
+    labels5 = cur5.fetchall()
+    labels5 = [g[0] for g in labels5]
+    print(labels5)
+
+    cur6 = conn.cursor()
+    # 獲取欄位資料
+    sql6 = "select DISTINCT 系統 from abc"
+    cur6.execute(sql6)
+    labels6 = cur6.fetchall()
+    labels6 = [g[0] for g in labels6]
+    print(labels6)
+
+    cur7 = conn.cursor()
+    # 獲取欄位資料
+    sql7 = "select DISTINCT 模組圖名 from abc"
+    cur7.execute(sql7)
+    labels7 = cur7.fetchall()
+    labels7 = [g[0] for g in labels7]
+    print(labels7)
+
+    cur8 = conn.cursor()
+    # 獲取欄位資料
+    sql8 = "select DISTINCT 零件圖名 from abc"
+    cur8.execute(sql8)
+    labels8 = cur8.fetchall()
+    labels8 = [g[0] for g in labels8]
+    print(labels8)
+
+    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']
+        t5 = request.values['Test5']
+        t6 = request.values['Test6']
+        t7 = request.values['Test7']
+        t8 = request.values['Test8']
+        #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)
+        data1 = 'select * from abc'
+        if t5 == '' and t6 == '' and t7 == '' and t8 == '':
+            pass
+        else:
+            data += ' WHERE '
+            if t5 != '':
+                data += '產品 = \'' + t5 + '\' '
+                if t6 != '':
+                    data += ' AND '
+                elif t7 != '':
+                    data += ' AND '
+                elif t8 != '':
+                    data += ' AND '
+            if t6 != '':
+                data += '系統 = \'' + t6 + '\' '
+                if t7 != '':
+                    data += ' AND '
+                elif t8 != '':
+                    data += ' AND '
+
+            if t7 != '':
+                data += '模組圖名 = \'' + t7 + '\' '
+                if t8 != '':
+                    data += ' AND '
+            if t8 != '':
+                data += '零件圖名 = \'' + t8 + '\' '
+
+        print(data1)
+        # 進資料庫
+        cur.execute(data1)
+
+        return render_template('Inquire1.html', content=content, labels=labels)
+
+    return render_template('Inquire.html',labels1=labels1,labels2=labels2,labels3=labels3,labels4=labels4,
+                           labels5=labels5,labels6=labels6,labels7=labels7,labels8=labels8)
+
+
+
+
+
+if __name__ == '__main__':
+    app.run(debug=True,port=5050)