Advertisement
Guest User

Untitled

a guest
Mar 19th, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.79 KB | None | 0 0
  1. from mysql.connector import (connection)
  2. from datetime import *
  3. from RPI1_ui import Ui_Form
  4.  
  5. '''Handling of database related stuff'''
  6.  
  7.  
  8. class DatabaseUtility(Ui_Form):
  9. def __init__(self):
  10. #DB Connection
  11. self.cnx = None
  12. self.cursor = None
  13.  
  14. def mysql_connect(self):
  15. # Database connection
  16. try:
  17. self.cnx = connection.MySQLConnection(user='root', password='', host='127.0.0.1', database='spicadb')
  18. self.cursor = self.cnx.cursor()
  19. except connection.errors.InterfaceError as e:
  20. self.lblShowInfo.setText(str(e)) # -> Try to change label
  21.  
  22. def get_table(self):
  23. return self.run_command("SELECT * FROM tblseal")
  24.  
  25. def get_columns(self):
  26. return self.run_command("SHOW COLUMNS FROM tblseal")
  27.  
  28. from PyQt5.QtWidgets import QApplication, QWidget, QDialog
  29. from mysql.connector import (connection)
  30. from datetime import *
  31. from bs4 import BeautifulSoup as bs
  32. import os
  33. import sys
  34. import DatabaseHandling
  35.  
  36. '''Convert UI file to Python'''
  37. os.chdir("C:\UsersGianni DeclercqAppDataLocalProgramsPythonPython36-32Scripts")
  38. os.system("pyuic5.exe H:QtProjects\RPI1.ui -o H:QtProjects\RPI1_ui.py")
  39.  
  40. from RPI1_ui import Ui_Form # import after recreation of py file
  41. from RPI1_Sec import SecondWindow
  42.  
  43. '''Main program'''
  44.  
  45.  
  46. class MainWindow(QWidget, Ui_Form):
  47. def __init__(self):
  48. super(MainWindow, self).__init__()
  49. # Initialize variables
  50. self.dbu = DatabaseHandling.DatabaseUtility()
  51. self.spica_reference = None
  52. self.barcode = None
  53. self.msl = None
  54. self.package_body = None
  55.  
  56. self.window2 = None
  57.  
  58. # Get UI elements + resize window
  59. self.setupUi(self)
  60. self.resize(800, 480)
  61.  
  62. # Define what should happen on button click
  63. self.btnQuit.clicked.connect(lambda: app.exit())
  64. self.btnInsert.clicked.connect(lambda: self.get_entry())
  65. self.btnTable.clicked.connect(lambda: self.new_window())
  66.  
  67. # Style buttons
  68. self.btnQuit.setStyleSheet("background-color: red")
  69. self.btnInsert.setStyleSheet("background-color: green")
  70. self.btnTable.setStyleSheet("background-color: orange")
  71.  
  72. def get_entry(self):
  73. try:
  74. self.spica_reference = self.txtReferentie.text()
  75. self.barcode = self.txtBarcode.text()
  76. self.msl = self.txtMsl.text()
  77. self.package_body = float(self.txtBodyPackage.text())
  78.  
  79. except ValueError:
  80. self.lblShowInfo.setText("Please insert the correct values")
  81. self.lblShowInfo.setStyleSheet('color: red')
  82. else:
  83. self.dbu.mysql_connect()
  84. if self.dbu.cursor and self.dbu.cnx is not None:
  85. self.dbu.add_entry(self.spica_reference, self.barcode, self.msl, self.package_body, self.calc_floor_life)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement