app_old.py 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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='g53743001',
  10. db='erp',
  11. charset='utf8'
  12. )
  13. @app.route('/')
  14. def index():
  15. return render_template('index.html')
  16. @app.route('/submit/')
  17. def form():
  18. return render_template('update.html')
  19. #新增產品清單內容
  20. @app.route('/add_Nu', methods=['POST', 'GET'])
  21. def add_Nu():
  22. if request.method == 'POST':
  23. 會計科目 = request.form['會計科目']
  24. 名稱1 = request.form['名稱1']
  25. 類別 = request.form['類別']
  26. 名稱2 = request.form['名稱2']
  27. 廠商 = request.form['廠商']
  28. 名稱3 = request.form['名稱3']
  29. if 會計科目 == '' and 名稱1 == '' and 類別 == '' and 名稱2 == ''and 廠商 == ''and 名稱3 == '':
  30. print('都沒輸入,直接略過')
  31. pass
  32. else:
  33. if 會計科目 != '' and 名稱1 != '':
  34. cur = conn.cursor()
  35. cur.execute(''' INSERT INTO accounting_subjects VALUES(%s,%s)'''
  36. ,(會計科目, 名稱1))
  37. conn.commit()
  38. cur.close()
  39. else:
  40. print('accounting_subjects error')
  41. if 類別 != '' and 名稱2 != '':
  42. cur = conn.cursor()
  43. cur.execute(''' INSERT INTO category VALUES(%s,%s)'''
  44. ,(類別, 名稱2))
  45. conn.commit()
  46. cur.close()
  47. else:
  48. print('category error')
  49. if 廠商 != ''and 名稱3 != '':
  50. cur = conn.cursor()
  51. cur.execute(''' INSERT INTO company VALUES(%s,%s)'''
  52. ,(廠商, 名稱3))
  53. conn.commit()
  54. cur.close()
  55. else:
  56. print('company error')
  57. return render_template('index.html')
  58. @app.route('/check/', methods=['GET', 'POST'])
  59. def check():
  60. cur = conn.cursor()
  61. # 獲取欄位名稱
  62. sql = "select concat(會計科目,類別,流水號,供應商),名稱 from parts_list ORDER BY concat(會計科目,類別,流水號,供應商) ASC"
  63. cur.execute(sql)
  64. labels = cur.fetchall()
  65. print(labels)
  66. labels = [g for g in labels]
  67. if request.method == 'POST':
  68. sql = "SHOW FIELDS FROM parts_list"
  69. cur.execute(sql)
  70. labels = cur.fetchall()
  71. labels = [g[0] for g in labels]
  72. t = request.values['Test']
  73. #t = t[2:13]
  74. print(t)
  75. #cur = conn.cursor()
  76. # 獲取欄位資料
  77. cur.execute("""select * from parts_list WHERE concat(會計科目,類別,流水號,供應商) = {}""".format(repr(t[2:13])))
  78. content = cur.fetchall()
  79. print(content)
  80. sql1 = "SELECT 名稱 FROM parts_list"
  81. cur.execute(sql1)
  82. pdname = cur.fetchall()
  83. pdname = [g for g in pdname]
  84. sql2 = "SELECT * FROM accounting_subjects"
  85. cur.execute(sql2)
  86. accounting_subjects = cur.fetchall()
  87. accounting_subjects = [g for g in accounting_subjects]
  88. sql3 = "SELECT * FROM category"
  89. cur.execute(sql3)
  90. category = cur.fetchall()
  91. category = [g for g in category]
  92. sql4 = "SELECT * FROM company"
  93. cur.execute(sql4)
  94. company = cur.fetchall()
  95. company = [g for g in company]
  96. return render_template('check1.html', content=content, labels=labels,pdname=pdname,accounting_subjects=accounting_subjects,category=category,company=company)
  97. return render_template('check.html', labels=labels)
  98. @app.route('/update/')
  99. def update():
  100. # 獲取頁面輸入內容,提供給sql使用
  101. userinfoId = request.args.get('userinfoId')
  102. name = request.args.get('name') # 更新後的數據返回到頁面上面顯示
  103. # return render_template('update.html')
  104. # 修改資料庫資料
  105. @app.route('/updateaction/', methods=['POST'])
  106. def updateaction():
  107. cur = conn.cursor()
  108. params = request.args if request.method == 'GET' else request.form
  109. serial_number = params.get('serial_number')
  110. pdname = params.get('pdname')
  111. accounting_subjects = params.get('accounting_subjects')
  112. category = params.get('category')
  113. company = params.get('company')
  114. print(pdname)
  115. print(accounting_subjects[2:4])
  116. print(category[2:4])
  117. print(company[2:4])
  118. sql = "update parts_list set 會計科目='%s',類別='%s',供應商='%s',名稱='%s'"" where 流水號='%s'" \
  119. %(accounting_subjects[2:4], category[2:4], company[2:4], pdname, serial_number) # 執行插入操作
  120. cur.execute(sql)
  121. conn.commit()
  122. return render_template('index.html') # 返回更新後的數據,確認是否更新成功
  123. if __name__ == '__main__':
  124. app.run(debug=True,host='0.0.0.0',port=5050)