Mar-04-2021, 02:11 AM
Okay I have played around with it enough now the SQL statement is actually entering rows of blank data in the database and not freezing up and closing so it's connecting/executing the statement. Even though I am typing something in the text boxes. So freaking close. I did take the checkbox out of the mix temporarily because it was actually causing an error. Will add it back later. For now I just added a fourth text box on the hardwareTab and using it for testing now.
from PyQt5.QtWidgets import (QLabel, QPushButton, QLineEdit, QApplication, QCheckBox, QMainWindow, QWidget, QVBoxLayout, QTabWidget, QStatusBar) import pyodbc import sys class mainWindow(QMainWindow): def __init__(self): super().__init__() self.resize(385, 323) self.setWindowTitle("HARDWARE | SOFTWARE MANAGER") self.statusBar = QStatusBar() self.setStatusBar(self.statusBar) self.tabForm = QTabWidget() self.tabForm.addTab(hardwareTab(), "HARDWARE") self.tabForm.addTab(softwareTab(), "SOFTWARE") self.setCentralWidget(self.tabForm) class hardwareTab(QWidget): def __init__(self): super().__init__() self.snLabel = QLabel("SERIAL NUMBER") self.snTextBox = QLineEdit() self.modelLabel = QLabel("MODEL") self.modelTextBox = QLineEdit() self.userLabel = QLabel("USER") self.userTextBox = QLineEdit() self.enButton = QPushButton("ENTER NEW HARDWARE") self.cfButton = QPushButton("CLEAR FIELDS") self.seButton = QPushButton("SEARCH/EDIT HARDWARE") self.activeCheckbox = QCheckBox("ACTIVE") self.testTextbox = QLineEdit() layout = QVBoxLayout(self) layout.addWidget(self.snLabel) layout.addWidget(self.snTextBox) layout.addWidget(self.modelLabel) layout.addWidget(self.modelTextBox) layout.addWidget(self.userLabel) layout.addWidget(self.userTextBox) layout.addWidget(self.activeCheckbox) layout.addWidget(self.enButton) layout.addWidget(self.cfButton) layout.addWidget(self.seButton) layout.addWidget(self.testTextbox) self.enButton.clicked.connect(enterNewHardware) class softwareTab(QWidget): def __init__(self): super().__init__() self.snLabel = QLabel("SERIAL NUMBER / KEY") self.snTextbox = QLineEdit() self.nameLabel = QLabel("APPLICATION NAME") self.nameTextBox = QLineEdit() self.userLabel = QLabel("USER") self.userTextBox = QLineEdit() self.enButton = QPushButton("ENTER NEW SOFTWARE") self.cfButton = QPushButton("CLEAR FIELDS") self.seButton = QPushButton("SEARCH/EDIT SOFTWARE") layout = QVBoxLayout(self) layout.addWidget(self.snLabel) layout.addWidget(self.snTextbox) layout.addWidget(self.nameLabel) layout.addWidget(self.nameTextBox) layout.addWidget(self.userLabel) layout.addWidget(self.userTextBox) layout.addWidget(self.enButton) layout.addWidget(self.cfButton) layout.addWidget(self.seButton) class enterNewHardware(hardwareTab): def __init__(self): super().__init__() serial_number = self.snTextBox.text() model_name = self.modelTextBox.text() user_name = self.userTextBox.text() test_textbox = self.testTextbox.text() azureServer = "pythonserver5874.database.windows.net" azureDB = "inventoryDatabase" userName = "na" password = "na" driver = "{ODBC Driver 17 for SQL Server}" connectionString = f"DRIVER={driver};SERVER={azureServer};PORT=1433;DATABASE={azureDB};UID={userName};PWD={password}" conn = pyodbc.connect(connectionString) cursor = conn.cursor() sqlstatement = 'INSERT INTO inventoryDatabase.dbo.Hardware(serialNumber, modelName, userName, machineActive) VALUES (?, ?, ?, ?)' data = (serial_number, model_name, user_name, test_textbox) cursor.execute(sqlstatement, data) conn.commit() if __name__ == "__main__": APP = QApplication(sys.argv) WINDOW = mainWindow() WINDOW.show() sys.exit(APP.exec_())