Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from PyQt5.QtGui import *
- from PyQt5.QtCore import *
- from PyQt5.QtWidgets import *
- import sys
- # noinspection PyUnresolvedReferences
- import ImageResources
- import pickle
- # noinspection PyUnresolvedReferences
- import sqlite3
- from StyleSheet import *
- from CreateDatabase import *
- from SortResults import *
- class ChamberMainApplication(QApplication):
- def __init__(self):
- super().__init__(sys.argv)
- self.connection = sqlite3.connect("ChamberOfTrade.db")
- self.cursor = self.connection.cursor()
- self.checkDatabaseExistence()
- self.checkPaymentFileExistence()
- def checkDatabaseExistence(self):
- """used to check if the database already exists. if not, it creates a sample"""
- results = self.executeSQL("select name from sqlite_master where name=?", ("Contacts",))
- if len(results) != 1:
- create_database()
- # noinspection PyMethodMayBeStatic
- def checkPaymentFileExistence(self):
- """checks if the payments file already exists, and if not creates one"""
- file_check = open("Payments.dat", "ab")
- file_check.close()
- def executeSQL(self, sql, parameters):
- """executes any SQL in the program"""
- if parameters != "":
- self.cursor.execute(sql, parameters)
- else:
- self.cursor.execute(sql)
- results = self.cursor.fetchall()
- self.connection.commit()
- return results
- # noinspection PyUnboundLocalVariable
- def checkReferentialIntegrity(self, identifier, table):
- """checks if an item is in use elsewhere in the database before deletion"""
- id_valid = True
- if table == "Contact":
- temp_data = self.executeSQL("SELECT ContactID FROM Businesses", "")
- elif table == "Business":
- temp_data = self.executeSQL("SELECT BusinessID FROM Adverts", "")
- for row in range(0, len(temp_data)):
- if identifier == temp_data[row][0]:
- id_valid = False
- return id_valid
- class NavigationToolBar(QToolBar):
- def __init__(self):
- super().__init__()
- self.spacer1 = QWidget()
- self.spacer2 = QWidget()
- self.spacer3 = QWidget()
- self.spacer4 = QWidget()
- self.logoPixmap = QPixmap(":/Logo.png")
- self.logoLabel = QLabel()
- self.mainMenuButton = QPushButton("Main Menu")
- self.exitButton = QPushButton("Exit")
- self.spacer1.setFixedSize(10, 10)
- self.spacer2.setFixedSize(10, 10)
- self.spacer3.setFixedSize(10, 10)
- self.spacer4.setFixedSize(10, 10)
- self.setMovable(False)
- self.logoLabel.setPixmap(self.logoPixmap.scaledToWidth(60, 1))
- self.logoLabel.setAlignment(Qt.AlignCenter)
- self.mainMenuButton.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
- self.exitButton.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
- self.addWidget(self.spacer1)
- self.addWidget(self.mainMenuButton)
- self.addWidget(self.spacer2)
- self.addWidget(self.logoLabel)
- self.addWidget(self.spacer3)
- self.addWidget(self.exitButton)
- self.addWidget(self.spacer4)
- assign_style_sheet(self, "body")
- # connections
- self.mainMenuButton.clicked.connect(lambda: self.mainMenuClicked())
- self.exitButton.clicked.connect(lambda: self.exitClicked())
- # noinspection PyMethodMayBeStatic
- def exitClicked(self):
- exit_dialog = ExitDialog()
- button_clicked = exit_dialog.exec_()
- if button_clicked == 16384:
- sys.exit()
- # noinspection PyMethodMayBeStatic
- def mainMenuClicked(self):
- chamber_main_window.changeView("MainMenu")
- class ChamberMainWindow(QMainWindow):
- def __init__(self):
- super().__init__()
- self.navigationToolBar = NavigationToolBar()
- self.tempView = QWidget()
- self.addToolBar(self.navigationToolBar)
- self.setWindowTitle("Chamber of Trade Management System")
- self.view = QWidget()
- self.changeView("MainMenu")
- # noinspection PyUnboundLocalVariable,PyAttributeOutsideInit
- def changeView(self, new_view):
- self.view = None
- self.tempView = QWidget()
- self.setCentralWidget(self.tempView)
- self.setCentralWidget(self.tempView)
- self.tempView.setFixedSize(100, 100)
- self.adjustSize()
- self.hide()
- if new_view == "Login":
- self.view = LoginViewWidget()
- self.size = [350, 550]
- elif new_view == "MainMenu":
- self.view = MainMenuViewWidget()
- self.size = [350, 630]
- elif new_view == "ViewDatabase":
- self.view = ViewDatabaseViewWidget()
- self.size = [350, 630]
- elif new_view == "SearchDatabase":
- self.view = SearchDatabaseViewWidget()
- self.size = [300, 650]
- elif new_view == "OtherDatabase":
- self.view = OtherDatabaseViewWidget()
- self.size = [400, 480]
- elif new_view == "ViewFinances":
- self.view = ViewFinancesViewWidget()
- self.size = [400, 500]
- elif new_view == "AddPayment":
- self.view = AddPaymentViewWidget()
- self.size = [320, 320]
- self.setCentralWidget(self.view)
- self.resize(100, 100)
- self.resize(self.size[0], self.size[1])
- self.show()
- if new_view == "Login" or new_view == "MainMenu":
- self.navigationToolBar.mainMenuButton.setEnabled(False)
- else:
- self.navigationToolBar.mainMenuButton.setEnabled(True)
- class LoginViewWidget(QWidget):
- def __init__(self):
- super().__init__()
- self.loginAttemptsRemaining = 3
- self.businessNameLabel = QLabel("Tadley and District Chamber of Trade")
- self.usernameLabel = QLabel("Username:")
- self.passwordLabel = QLabel("Password:")
- self.logoPixmap = QPixmap(":/Logo.png")
- self.logoLabel = QLabel()
- self.usernameLineEdit = QLineEdit()
- self.passwordLineEdit = QLineEdit()
- self.loginButton = QPushButton("Log In")
- self.spacer = QWidget()
- self.detailsLayout = QFormLayout()
- self.loginLayout = QVBoxLayout()
- self.businessNameLabel.setWordWrap(True)
- self.businessNameLabel.setAlignment(Qt.AlignCenter)
- assign_style_sheet(self.businessNameLabel, "title")
- self.passwordLineEdit.setEchoMode(QLineEdit.Password)
- assign_style_sheet(self.usernameLabel, "heading2")
- assign_style_sheet(self.passwordLabel, "heading2")
- assign_style_sheet(self.usernameLineEdit, "body")
- assign_style_sheet(self.passwordLineEdit, "body")
- assign_style_sheet(self.loginButton, "body")
- self.logoLabel.setFixedHeight(250)
- self.logoLabel.setPixmap(self.logoPixmap.scaledToWidth(220, 1))
- self.logoLabel.setAlignment(Qt.AlignCenter)
- self.spacer.setFixedSize(3, 3)
- self.loginLayout.setSpacing(10)
- self.loginButton.setFixedWidth(150)
- self.passwordLineEdit.setFixedWidth(180)
- self.usernameLineEdit.setFixedWidth(180)
- self.detailsLayout.addRow(self.usernameLabel, self.usernameLineEdit)
- self.detailsLayout.addRow(self.passwordLabel, self.passwordLineEdit)
- self.detailsLayout.setFormAlignment(Qt.AlignCenter)
- self.loginLayout.addWidget(self.businessNameLabel)
- self.loginLayout.addWidget(self.logoLabel)
- self.loginLayout.addLayout(self.detailsLayout)
- self.loginLayout.addWidget(self.spacer)
- self.loginLayout.addWidget(self.loginButton)
- self.loginLayout.setAlignment(self.detailsLayout, Qt.AlignCenter)
- self.loginLayout.setAlignment(self.loginButton, Qt.AlignCenter)
- self.setLayout(self.loginLayout)
- # connections
- self.loginButton.clicked.connect(lambda: self.loginClicked())
- def loginClicked(self):
- actual_username, actual_password = self.readLoginFile()
- entered_username = self.usernameLineEdit.text()
- entered_password = self.passwordLineEdit.text()
- if entered_username == "" or entered_password == "":
- login_empty_fields_dialog = LoginEmptyFieldsDialog()
- login_empty_fields_dialog.exec()
- self.usernameLineEdit.setText("")
- self.passwordLineEdit.setText("")
- elif actual_username == entered_username and actual_password == entered_password:
- chamber_main_window.changeView("MainMenu")
- else:
- self.loginAttemptsRemaining -= 1
- failed_login_dialog = FailedLoginDialog(self.loginAttemptsRemaining)
- failed_login_dialog.exec()
- if self.loginAttemptsRemaining == 0:
- sys.exit()
- else:
- self.usernameLineEdit.setText("")
- self.passwordLineEdit.setText("")
- # noinspection PyMethodMayBeStatic
- def readLoginFile(self):
- login_file = open("LoginDetails.txt", "r")
- login_text = login_file.readlines()
- username, password = login_text[0].split(",")
- return username, password
- class MainMenuViewWidget(QWidget):
- def __init__(self):
- super().__init__()
- self.businessNameLabel = QLabel("Tadley and District Chamber of Trade")
- self.mainMenuLabel = QLabel("Main Menu")
- assign_style_sheet(self.mainMenuLabel, "heading1")
- assign_style_sheet(self.businessNameLabel, "title")
- self.viewDatabaseButton = QPushButton("View Database")
- self.searchDatabaseButton = QPushButton("Search Database")
- self.otherDatabaseButton = QPushButton("Add / Edit / Delete Entry")
- self.viewFinancesButton = QPushButton("View Finances")
- self.addPaymentButton = QPushButton("Add Payment")
- assign_style_sheet(self.viewDatabaseButton, "body")
- assign_style_sheet(self.searchDatabaseButton, "body")
- assign_style_sheet(self.otherDatabaseButton, "body")
- assign_style_sheet(self.viewFinancesButton, "body")
- assign_style_sheet(self.addPaymentButton, "body")
- self.logoPixmap = QPixmap(":/Logo.png")
- self.logoLabel = QLabel()
- self.financesButtonsLayout = QHBoxLayout()
- self.databaseButtonsLayout = QGridLayout()
- self.layout = QVBoxLayout()
- self.databaseGroupBox = QGroupBox("Business Database")
- self.financesGroupBox = QGroupBox("Finances")
- self.businessNameLabel.setAlignment(Qt.AlignCenter)
- self.businessNameLabel.setWordWrap(True)
- self.mainMenuLabel.setAlignment(Qt.AlignCenter)
- self.otherDatabaseButton.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
- self.logoLabel.setAlignment(Qt.AlignCenter)
- self.logoLabel.setPixmap(self.logoPixmap.scaledToWidth(200, 1))
- self.financesButtonsLayout.addWidget(self.addPaymentButton)
- self.financesButtonsLayout.addWidget(self.viewFinancesButton)
- self.databaseButtonsLayout.addWidget(self.viewDatabaseButton, 0, 0)
- self.databaseButtonsLayout.addWidget(self.searchDatabaseButton, 0, 1)
- self.databaseButtonsLayout.addWidget(self.otherDatabaseButton, 1, 0, 1, 2)
- assign_style_sheet(self.databaseGroupBox, "heading2")
- self.databaseGroupBox.setAlignment(Qt.AlignCenter)
- self.databaseGroupBox.setLayout(self.databaseButtonsLayout)
- assign_style_sheet(self.financesGroupBox, "heading2")
- self.financesGroupBox.setAlignment(Qt.AlignCenter)
- self.financesGroupBox.setLayout(self.financesButtonsLayout)
- self.layout.setSpacing(10)
- self.layout.addWidget(self.businessNameLabel)
- self.layout.addWidget(self.mainMenuLabel)
- self.layout.addWidget(self.logoLabel)
- self.layout.addWidget(self.databaseGroupBox)
- self.layout.addWidget(self.financesGroupBox)
- self.setLayout(self.layout)
- # connections
- self.viewDatabaseButton.clicked.connect(lambda: self.viewDatabaseClicked())
- self.searchDatabaseButton.clicked.connect(lambda: self.searchDatabaseClicked())
- self.otherDatabaseButton.clicked.connect(lambda: self.otherDatabaseClicked())
- self.addPaymentButton.clicked.connect(lambda: self.addPaymentClicked())
- self.viewFinancesButton.clicked.connect(lambda: self.viewFinancesClicked())
- # noinspection PyMethodMayBeStatic
- def viewDatabaseClicked(self):
- chamber_main_window.changeView("ViewDatabase")
- # noinspection PyMethodMayBeStatic
- def searchDatabaseClicked(self):
- chamber_main_window.changeView("SearchDatabase")
- # noinspection PyMethodMayBeStatic
- def otherDatabaseClicked(self):
- chamber_main_window.changeView("OtherDatabase")
- # noinspection PyMethodMayBeStatic
- def addPaymentClicked(self):
- chamber_main_window.changeView("AddPayment")
- # noinspection PyMethodMayBeStatic
- def viewFinancesClicked(self):
- chamber_main_window.changeView("ViewFinances")
- class ViewDatabaseViewWidget(QWidget):
- def __init__(self):
- super().__init__()
- self.databaseTabs = QTabWidget()
- self.businessTab = DatabaseTabWidget("Businesses")
- self.contactsTab = DatabaseTabWidget("Contacts")
- self.adverts2018Tab = DatabaseTabWidget("Adverts")
- self.viewDatabaseLabel = QLabel("View Database")
- self.viewDatabaseLayout = QVBoxLayout()
- self.viewDatabaseLabel.setAlignment(Qt.AlignCenter)
- assign_style_sheet(self.viewDatabaseLabel, "heading1")
- assign_style_sheet(self.databaseTabs, "heading2")
- self.databaseTabs.addTab(self.contactsTab, "Contacts")
- self.databaseTabs.addTab(self.businessTab, "Businesses")
- self.databaseTabs.addTab(self.adverts2018Tab, "Adverts 2018")
- self.viewDatabaseLayout.setSpacing(10)
- self.viewDatabaseLayout.addWidget(self.viewDatabaseLabel)
- self.viewDatabaseLayout.addWidget(self.databaseTabs)
- self.setLayout(self.viewDatabaseLayout)
- class SearchDatabaseViewWidget(QWidget):
- def __init__(self):
- super().__init__()
- self.getSearchDetails()
- self.searchDatabaseLabel = QLabel("Search Database")
- self.details1Label = QLabel(
- "Search results are displayed below.\nIf there are no results, please try another search.")
- self.details2Label = QLabel("You can change the results order in the bar to the left.")
- self.searchDetailsLabel = QLabel(
- "Searching by: " + str(self.searchMethod) + "\nSearching for: " + str(self.searchData))
- self.newSearchButton = QPushButton("New Search")
- self.helpButton = QPushButton("Help")
- self.orderByWidget = OrderByWidget()
- self.tableWidget = SearchTableWidget(self.searchMethod, self.searchData)
- self.buttonsLayout = QHBoxLayout()
- self.smallLayout = QHBoxLayout()
- self.layout = QVBoxLayout()
- self.searchDatabaseLabel.setAlignment(Qt.AlignCenter)
- self.details1Label.setAlignment(Qt.AlignCenter)
- self.details2Label.setAlignment(Qt.AlignCenter)
- self.searchDetailsLabel.setAlignment(Qt.AlignCenter)
- assign_style_sheet(self.searchDatabaseLabel, "heading1")
- assign_style_sheet(self.details1Label, "body")
- assign_style_sheet(self.details2Label, "body")
- assign_style_sheet(self.searchDetailsLabel, "heading2")
- assign_style_sheet(self.helpButton, "body")
- assign_style_sheet(self.newSearchButton, "body")
- self.buttonsLayout.setSpacing(20)
- self.smallLayout.setSpacing(10)
- self.layout.setSpacing(10)
- self.buttonsLayout.addWidget(self.newSearchButton)
- self.buttonsLayout.addWidget(self.helpButton)
- self.smallLayout.addWidget(self.tableWidget)
- self.smallLayout.addWidget(self.orderByWidget)
- self.layout.addWidget(self.searchDatabaseLabel)
- self.layout.addWidget(self.searchDetailsLabel)
- self.layout.addWidget(self.details1Label)
- self.layout.addWidget(self.details2Label)
- self.layout.addLayout(self.smallLayout)
- self.layout.addLayout(self.buttonsLayout)
- self.setLayout(self.layout)
- # connections
- self.newSearchButton.clicked.connect(lambda: self.newSearchClicked())
- self.helpButton.clicked.connect(lambda: self.helpClicked())
- self.orderByWidget.updateButton.clicked.connect(lambda: self.updateResultsClicked())
- # noinspection PyAttributeOutsideInit
- def getSearchDetails(self):
- values = False
- search_by_dialog = SearchByDialog()
- while not values:
- search_by_dialog.exec()
- self.searchMethod = search_by_dialog.searchByComboBox.currentText()
- if self.searchMethod == "Contact Surname":
- self.searchData = search_by_dialog.surnameLineEdit.text()
- elif self.searchMethod == "Business Name":
- self.searchData = search_by_dialog.nameLineEdit.text()
- elif self.searchMethod == "Category":
- self.searchData = search_by_dialog.categoryComboBox.currentText()
- elif self.searchMethod == "Advert Paid":
- self.searchData = search_by_dialog.paidComboBox.currentText()
- elif self.searchMethod == "Advert Option":
- self.searchData = search_by_dialog.advertOptionComboBox.currentText()
- if len(self.searchData) > 0:
- values = True
- else:
- search_empty_dialog = SearchEmptyDialog()
- search_empty_dialog.exec()
- # noinspection PyMethodMayBeStatic
- def helpClicked(self):
- search_help_dialog = SearchHelpDialog()
- search_help_dialog.exec()
- # noinspection PyMethodMayBeStatic
- def newSearchClicked(self):
- chamber_main_window.changeView("SearchDatabase")
- # noinspection PyUnboundLocalVariable
- def updateResultsClicked(self):
- order = self.orderByWidget.radioButtonWidget.radioButtonGroup.checkedId()
- order_by = self.orderByWidget.orderByComboBox.currentText()
- while self.tableWidget.rowCount() > 0:
- self.tableWidget.removeRow(0)
- if order_by == "Contact ID":
- key_col = 0
- elif order_by == "First Name":
- key_col = 2
- elif order_by == "Surname":
- key_col = 3
- elif order_by == "Address 2":
- key_col = 5
- elif order_by == "Town":
- key_col = 6
- elif order_by == "Business ID":
- key_col = 8
- elif order_by == "Business Name":
- key_col = 9
- elif order_by == "Category 1":
- key_col = 13
- elif order_by == "Category 2":
- key_col = 14
- elif order_by == "Advert No.":
- key_col = 15
- elif order_by == "Advert Size":
- key_col = 16
- elif order_by == "Print Type":
- key_col = 17
- elif order_by == "Paid?":
- key_col = 18
- elif order_by == "Payment Method":
- key_col = 19
- elif order_by == "Receipt?":
- key_col = 20
- elif order_by == "Option":
- key_col = 21
- self.tableWidget.populateTable(self.searchMethod, self.searchData, order, key_col)
- class OtherDatabaseViewWidget(QWidget):
- def __init__(self):
- super().__init__()
- self.getSearchDetails()
- if self.method == "Add":
- self.methodLabel = QLabel("Add Entry")
- self.enterButton = QPushButton("Add Entry")
- elif self.method == "Edit":
- self.methodLabel = QLabel("Edit Entry")
- self.enterButton = QPushButton("Save Edit")
- elif self.method == "Delete":
- self.methodLabel = QLabel("Delete Entry")
- self.enterButton = QPushButton("Delete Entry")
- self.tableLabel = QLabel(self.table)
- self.helpButton = QPushButton("Help")
- self.clearButton = QPushButton("Clear")
- self.changeButton = QPushButton("Change Options")
- self.buttonsLayout = QGridLayout()
- self.layout = QVBoxLayout()
- if self.table == "Contact":
- self.formDetailsWidget = ContactFormDetailsWidget()
- elif self.table == "Business":
- self.formDetailsWidget = BusinessFormDetailsWidget()
- elif self.table == "Advert":
- self.formDetailsWidget = AdvertFormDetailsWidget()
- if self.method == "Edit" or self.method == "Delete":
- self.fillFormDetails()
- if self.method == "Delete":
- self.clearButton.setEnabled(False)
- assign_style_sheet(self.methodLabel, "heading1")
- assign_style_sheet(self.tableLabel, "heading2")
- assign_style_sheet(self.helpButton, "body")
- assign_style_sheet(self.clearButton, "body")
- assign_style_sheet(self.changeButton, "body")
- assign_style_sheet(self.enterButton, "body")
- self.methodLabel.setAlignment(Qt.AlignCenter)
- self.tableLabel.setAlignment(Qt.AlignCenter)
- self.formDetailsWidget.setContentsMargins(10, 0, 10, 0)
- self.buttonsLayout.addWidget(self.clearButton, 1, 0)
- self.buttonsLayout.addWidget(self.enterButton, 0, 0)
- self.buttonsLayout.addWidget(self.changeButton, 0, 1)
- self.buttonsLayout.addWidget(self.helpButton, 1, 1)
- self.layout.addWidget(self.methodLabel)
- self.layout.addWidget(self.tableLabel)
- self.layout.addWidget(self.formDetailsWidget)
- self.layout.addLayout(self.buttonsLayout)
- self.buttonsLayout.setSpacing(10)
- self.buttonsLayout.setContentsMargins(5, 5, 5, 5)
- self.setLayout(self.layout)
- # connections
- self.clearButton.clicked.connect(lambda: self.clearClicked())
- self.enterButton.clicked.connect(lambda: self.enterClicked())
- self.changeButton.clicked.connect(lambda: self.changeOptionsClicked())
- self.helpButton.clicked.connect(lambda: self.helpClicked())
- # noinspection PyAttributeOutsideInit
- def getSearchDetails(self):
- choices_dialog = ChoicesDialog()
- choices_dialog.exec()
- self.method = choices_dialog.selectMethodComboBox.currentText()
- self.table = choices_dialog.selectTypeComboBox.currentText()
- # noinspection PyAttributeOutsideInit,PyUnboundLocalVariable
- def fillFormDetails(self):
- search_id_dialog = SearchIDDialog(self.table)
- search_id_dialog.exec()
- search_id = search_id_dialog.idComboBox.currentText()
- search_id_list = search_id.split()
- search_id = str(search_id_list[0])
- if self.table == "Contact":
- sql = "SELECT * FROM Contacts WHERE ContactID = ?"
- elif self.table == "Business":
- sql = "SELECT * FROM Businesses WHERE BusinessID = ?"
- elif self.table == "Advert":
- sql = "SELECT * FROM Adverts WHERE AdvertNo = ?"
- data = [search_id]
- details = chamber_main_application.executeSQL(sql, data)
- self.formDetailsWidget.setData(details, self.method)
- def helpClicked(self):
- help_dialog = HelpDialog(self.table, self.method)
- help_dialog.exec()
- # noinspection PyMethodMayBeStatic
- def changeOptionsClicked(self):
- chamber_main_window.changeView("OtherDatabase")
- def clearClicked(self):
- self.formDetailsWidget.clearData()
- # noinspection PyUnboundLocalVariable
- def enterClicked(self):
- data_valid, data, errors = self.formDetailsWidget.validateData(self.method, self.table)
- if data_valid:
- if self.method == "Add":
- if self.table == "Contact":
- sql = "INSERT INTO Contacts VALUES (?,?,?,?,?,?,?,?)"
- elif self.table == "Business":
- sql = "INSERT INTO Businesses VALUES (?,?,?,?,?,?,?,?)"
- elif self.table == "Advert":
- sql = "INSERT INTO Adverts VALUES (?,?,?,?,?,?,?,?,?)"
- sql_parameters = data
- elif self.method == "Delete":
- sql_parameters = [data[0]]
- if self.table == "Contact":
- sql = "DELETE FROM Contacts WHERE ContactID = ?"
- elif self.table == "Business":
- sql = "DELETE FROM Businesses WHERE BusinessID = ?"
- elif self.table == "Advert":
- sql = "DELETE FROM Adverts WHERE AdvertNo = ?"
- elif self.method == "Edit":
- if self.table == "Contact":
- sql = "UPDATE Contacts SET Title = ?,FirstName = ?,Surname = ?,Address1 = ?,Address2 = ?," \
- "Town = ?, Postcode =? WHERE ContactID = ?"
- elif self.table == "Business":
- sql = "UPDATE Businesses SET Name = ?,ContactID = ?,Email = ?,Telephone = ?,Website = ?," \
- "Category1 = ?,Category2 = ? WHERE BusinessID = ?"
- elif self.table == "Advert":
- sql = "UPDATE Adverts SET BusinessID = ?,Size = ?,PrintType = ?,Paid = ?,PaymentMethod = ?," \
- "Receipt = ?,Option = ?,Details = ? WHERE AdvertNo = ?"
- update_id = data.pop(0)
- data.append(update_id)
- sql_parameters = data
- chamber_main_application.executeSQL(sql, sql_parameters)
- successful_dialog = EntrySuccessfulDialog(self.method)
- successful_dialog.exec()
- chamber_main_window.changeView("MainMenu")
- else:
- failed_dialog = FailedEntryDialog(errors, self.method)
- failed_dialog.exec()
- class ViewFinancesViewWidget(QWidget):
- def __init__(self):
- super().__init__()
- self.readPaymentFile()
- self.titleLabel = QLabel("View Payments")
- self.detailsLabel = QLabel(
- "Note: Payments are displayed from newest to oldest\n if no details are displayed, the file was empty")
- self.tableWidget = QTableWidget()
- self.layout = QVBoxLayout()
- assign_style_sheet(self.titleLabel, "heading1")
- assign_style_sheet(self.tableWidget.horizontalHeader(), "heading2")
- assign_style_sheet(self.detailsLabel, "body")
- assign_style_sheet(self.tableWidget, "body")
- self.titleLabel.setAlignment(Qt.AlignCenter)
- self.detailsLabel.setAlignment(Qt.AlignCenter)
- self.tableWidget.setRowCount(self.maxLength)
- self.tableWidget.setColumnCount(self.maxWidth)
- self.tableWidget.setFixedHeight(350)
- self.tableWidget.setFixedWidth(600)
- header_labels = ["Direction", "Business", "Date", "Amount", "Details"]
- self.tableWidget.setHorizontalHeaderLabels(header_labels)
- self.tableWidget.setEditTriggers(QAbstractItemView.NoEditTriggers)
- for i in range(0, len(header_labels)):
- self.tableWidget.horizontalHeader().setSectionResizeMode(i, QHeaderView.ResizeToContents)
- self.populatePaymentsTable()
- self.layout.addWidget(self.titleLabel)
- self.layout.addWidget(self.detailsLabel)
- self.layout.addWidget(self.tableWidget)
- self.layout.setAlignment(self.tableWidget, Qt.AlignCenter)
- self.setLayout(self.layout)
- # noinspection PyAttributeOutsideInit
- def readPaymentFile(self):
- payment_file = open("Payments.dat", "rb")
- self.paymentsList = []
- proceed = True
- while proceed:
- try:
- payment = pickle.load(payment_file)
- self.paymentsList.append(payment)
- except EOFError:
- proceed = False
- payment_file.close()
- self.maxWidth = 5
- self.maxLength = len(self.paymentsList)
- self.paymentsList = sorted(self.paymentsList, key=lambda item: item[2])
- self.paymentsList = self.paymentsList[::-1]
- def populatePaymentsTable(self):
- for row in range(0, self.maxLength):
- # noinspection SpellCheckingInspection
- self.paymentsList[row][2] = self.paymentsList[row][2].toString("dd.MM.yyyy")
- for column in range(0, self.maxWidth):
- item = QTableWidgetItem(self.paymentsList[row][column])
- self.tableWidget.setItem(row, column, item)
- class AddPaymentViewWidget(QWidget):
- def __init__(self):
- super().__init__()
- self.titleLabel = QLabel("Add Payment")
- self.directionLabel = QLabel("Direction")
- self.businessLabel = QLabel("Business:")
- self.dateLabel = QLabel("Date:")
- self.amountLabel = QLabel("Amount:")
- self.advertPaymentLabel = QLabel("Advert Payment")
- self.detailsLabel = QLabel("Details:")
- self.directionComboBox = DirectionComboBox()
- self.businessIDComboBox = BusinessIDComboBox()
- self.dateWidget = QDateEdit()
- self.amountLineEdit = QLineEdit()
- self.advertPaymentCheckBox = QCheckBox()
- self.detailsPlainTextEdit = QPlainTextEdit()
- self.savePaymentButton = QPushButton("Save Payment")
- self.clearButton = QPushButton("Clear")
- self.detailsLayout = QFormLayout()
- self.buttonsLayout = QHBoxLayout()
- self.mainLayout = QVBoxLayout()
- self.titleLabel.setAlignment(Qt.AlignCenter)
- self.amountLineEdit.setText("0.00")
- self.dateWidget.setCalendarPopup(True)
- self.dateWidget.setDate(QDate.currentDate())
- self.dateWidget.setMaximumDate(QDate.currentDate())
- self.detailsLayout.addRow(self.directionLabel, self.directionComboBox)
- self.detailsLayout.addRow(self.businessLabel, self.businessIDComboBox)
- self.detailsLayout.addRow(self.dateLabel, self.dateWidget)
- self.detailsLayout.addRow(self.amountLabel, self.amountLineEdit)
- self.detailsLayout.addRow(self.advertPaymentLabel, self.advertPaymentCheckBox)
- self.detailsLayout.addRow(self.detailsLabel, self.detailsPlainTextEdit)
- self.detailsLayout.setSpacing(10)
- self.detailsLayout.setContentsMargins(5, 5, 5, 5)
- self.buttonsLayout.addWidget(self.clearButton)
- self.buttonsLayout.addWidget(self.savePaymentButton)
- self.buttonsLayout.setSpacing(10)
- self.buttonsLayout.setContentsMargins(5, 5, 5, 5)
- self.mainLayout.addWidget(self.titleLabel)
- self.mainLayout.addLayout(self.detailsLayout)
- self.mainLayout.addLayout(self.buttonsLayout)
- self.mainLayout.setSpacing(10)
- self.mainLayout.setContentsMargins(10, 10, 10, 10)
- self.setLayout(self.mainLayout)
- assign_style_sheet(self, "body")
- assign_style_sheet(self, "body2)")
- assign_style_sheet(self.titleLabel, "heading1")
- self.advertPaymentCheckBox.setStyleSheet("QCheckBox::indicator {width: 30px; height: 30px;}"
- "QCheckBox::indicator:checked {image: url(:/Checked.png);}"
- "QCheckBox::indicator:unchecked {image: url(:/Unchecked.png);}"
- "QCheckBox::indicator:checked:disabled {image: url(:/Disabled.png);}"
- "QCheckBox::indicator:unchecked:disabled {image: url(:/Disabled.png);}"
- )
- # connections
- self.clearButton.clicked.connect(lambda: self.clearClicked())
- self.savePaymentButton.clicked.connect(lambda: self.savePaymentClicked())
- self.directionComboBox.currentIndexChanged.connect(lambda: self.checkAdvertPayment())
- def checkAdvertPayment(self):
- if self.directionComboBox.currentText() == "Incoming":
- self.advertPaymentCheckBox.setEnabled(True)
- else:
- self.advertPaymentCheckBox.setEnabled(False)
- def savePaymentClicked(self):
- direction = self.directionComboBox.currentText()
- business_id = self.businessIDComboBox.currentText()
- business_id = self.businessIDComboBox.businessIDList[self.businessIDComboBox.businessList.index(business_id)]
- date = self.dateWidget.date()
- amount = self.amountLineEdit.text()
- details = self.detailsPlainTextEdit.toPlainText()
- details = details.title()
- if direction == "Outgoing":
- advert_payment = False
- else:
- advert_payment = self.advertPaymentCheckBox.isChecked()
- if advert_payment and details == "":
- details = "ADVERT PAYMENT"
- elif advert_payment:
- details += " ADVERT PAYMENT"
- elif details == "":
- details = "N/A"
- data_valid, data, errors = self.validateUserInput(direction, business_id, date, amount, details)
- if data_valid:
- payment_file = open("Payments.dat", "ab")
- pickle.dump(data, payment_file)
- payment_file.close()
- entry_successful_dialog = EntrySuccessfulDialog("AddPayment")
- entry_successful_dialog.exec()
- chamber_main_window.changeView("MainMenu")
- else:
- failed_entry_dialog = FailedEntryDialog(errors, "AddPayment")
- failed_entry_dialog.exec()
- # noinspection PyListCreation,PyUnusedLocal
- def validateUserInput(self, direction, business_id, date, amount, details):
- data_valid = True
- errors = []
- data = []
- data.append(direction)
- data.append(business_id)
- if self.dateWidget.validate:
- data.append(date)
- else:
- errors.append(date)
- data_valid = False
- amount_valid = False
- number = False
- for i in range(0, len(amount)):
- if amount[i] in ["1", "2", "3", "4", "5", "6", "7", "8", "9"]:
- number = True
- try:
- int_amount = float(amount)
- if int_amount <= 0:
- number = False
- except ValueError:
- number = False
- amount += "."
- amount_list = amount.split(".")
- amount_list[1] = "00"
- if len(amount_list) != 2:
- amount_list = amount_list[:2]
- amount = ".".join(amount_list)
- if not number:
- amount_valid = False
- errors.append("Amount")
- else:
- amount_valid = True
- data.append(str(amount))
- data.append(details)
- if not amount_valid:
- data_valid = False
- return data_valid, data, errors
- def clearClicked(self):
- self.directionComboBox.setCurrentIndex(0)
- self.businessIDComboBox.setCurrentIndex(0)
- self.amountLineEdit.setText("0.00")
- self.detailsPlainTextEdit.setPlainText("")
- self.advertPaymentCheckBox.setCheckState(0)
- class ExitDialog(QMessageBox):
- def __init__(self):
- super().__init__()
- self.setIcon(QMessageBox.Question)
- self.setText("Are you sure you want to exit?\t\n")
- self.setStandardButtons(QMessageBox.Cancel | QMessageBox.Yes)
- assign_style_sheet(self, "body")
- class LoginEmptyFieldsDialog(QMessageBox):
- def __init__(self):
- super().__init__()
- self.setIcon(QMessageBox.Warning)
- self.setText("Please enter the login details\nand try again.")
- self.setStandardButtons(QMessageBox.Ok)
- assign_style_sheet(self, "body")
- class SearchEmptyDialog(QMessageBox):
- def __init__(self):
- super().__init__()
- self.setIcon(QMessageBox.Warning)
- self.setText("Please check search criteria\nand try again")
- self.setStandardButtons(QMessageBox.Ok)
- assign_style_sheet(self, "body")
- class FailedLoginDialog(QMessageBox):
- def __init__(self, attempts_left):
- super().__init__()
- self.setIcon(QMessageBox.Warning)
- self.setText("Incorrect Login Attempt\t\t")
- if attempts_left > 0:
- attempts_string = ("You have " + str(attempts_left) + " attempt(s) remaining")
- else:
- attempts_string = "You have no attempts remaining\n- the system will now close."
- self.setInformativeText(attempts_string)
- self.setStandardButtons(QMessageBox.Ok)
- assign_style_sheet(self, "body")
- class FailedEntryDialog(QMessageBox):
- def __init__(self, errors, method):
- super().__init__()
- self.setIcon(QMessageBox.Warning)
- if method == "Add":
- self.setText("~ Error when adding entry ~")
- self.setWindowTitle("Adding Entry - Error")
- elif method == "Edit":
- self.setText("~ Error when updating entry ~")
- self.setWindowTitle("Updating Entry - Error")
- elif method == "Delete":
- self.setText("~ Error when deleting entry ~")
- self.setWindowTitle("Deleting Entry - Error")
- elif method == "AddPayment":
- self.setText("~ Error when saving Payment ~")
- self.setWindowTitle("Saving payment - Error")
- self.setInformativeText("Please alter the details listed below and try again.")
- details = "Please check/alter the details below:\n"
- for item in errors:
- details += item + "\n"
- self.setDetailedText(details)
- self.setStandardButtons(QMessageBox.Ok)
- assign_style_sheet(self, "body")
- class HelpDialog(QDialog):
- def __init__(self, form_type, method):
- super().__init__()
- self.helpTitleLabel = QLabel("Help")
- self.buttonHelpLabel = QLabel("Button Help")
- self.formHelpLabel = QLabel("Form Help")
- self.closeButton = QPushButton("Close")
- self.spacer1 = QWidget()
- self.spacer2 = QWidget()
- if method == "Add":
- self.buttonHelpText = QLabel(
- "Enter:\t\tAdds entry to database\nChange Table:\tChange the entry type\nClear:\t\tReset the form")
- elif method == "Edit":
- self.buttonHelpText = QLabel(
- "Enter:\t\tCommits the edit to database\nChange Table:\tChange the entry type\nClear:\t\tReset"
- " the form")
- elif method == "Delete":
- self.buttonHelpText = QLabel(
- "Enter:\t\tDeletes the entry\nChange Table:\tChange the entry type\nClear:\t\tReset the form")
- if form_type == "Contact":
- self.formHelpText = QLabel(
- "Contact ID:\tEnter as Mary Hancock = MH01\n\t\tEnsure this is unique\nPostcode:\tEnter with space")
- elif form_type == "Business":
- self.formHelpText = QLabel(
- "Business ID:\tEnter as Showoffs = Sho01\n\t\tEnsure this is unique\nCategories:\tTo add a new "
- "category,\n\t\ttype it in and press enter")
- elif form_type == "Advert":
- self.formHelpText = QLabel("Advert Number:\tEnsure this is unique")
- self.layout = QVBoxLayout()
- self.helpTitleLabel.setAlignment(Qt.AlignCenter)
- self.spacer1.setFixedSize(20, 10)
- self.spacer2.setFixedSize(20, 10)
- self.layout.setContentsMargins(20, 20, 20, 20)
- self.layout.addWidget(self.helpTitleLabel)
- self.layout.addWidget(self.formHelpLabel)
- self.layout.addWidget(self.formHelpText)
- self.layout.addWidget(self.spacer1)
- self.layout.addWidget(self.buttonHelpLabel)
- self.layout.addWidget(self.buttonHelpText)
- self.layout.addWidget(self.spacer2)
- self.layout.addWidget(self.closeButton)
- self.layout.setAlignment(self.closeButton, Qt.AlignCenter)
- self.setLayout(self.layout)
- assign_style_sheet(self, "body")
- assign_style_sheet(self.helpTitleLabel, "heading1")
- assign_style_sheet(self.buttonHelpLabel, "heading2")
- assign_style_sheet(self.formHelpLabel, "heading2")
- assign_style_sheet(self.buttonHelpText, "body")
- assign_style_sheet(self.formHelpText, "body")
- assign_style_sheet(self.closeButton, "body")
- # connections
- self.closeButton.clicked.connect(lambda: self.close())
- class SearchHelpDialog(QDialog):
- def __init__(self):
- super().__init__()
- self.helpTitleLabel = QLabel("Help")
- self.helpTextLabel = QLabel(
- "To perform a new search, click 'New Search'\n\nTo sort results, select from the drop-down\nhow you wish "
- "to sort them,\nthen select ascending/descending.\n")
- self.closeButton = QPushButton("Close")
- self.layout = QVBoxLayout()
- self.layout.setContentsMargins(20, 20, 20, 20)
- self.layout.setSpacing(10)
- self.layout.addWidget(self.helpTitleLabel)
- self.layout.addWidget(self.helpTextLabel)
- self.layout.addWidget(self.closeButton)
- self.helpTitleLabel.setAlignment(Qt.AlignCenter)
- self.layout.setAlignment(self.closeButton, Qt.AlignCenter)
- self.setLayout(self.layout)
- assign_style_sheet(self, "body")
- assign_style_sheet(self.helpTitleLabel, "heading1")
- # connections
- self.closeButton.clicked.connect(lambda: self.close())
- class SearchIDDialog(QDialog):
- def __init__(self, id_type):
- super().__init__()
- self.submitButton = QPushButton("Next")
- self.layout = QVBoxLayout()
- if id_type == "Contact":
- self.instructionLabel = QLabel("Select the Contact ID:")
- self.idComboBox = ContactIDComboBox()
- elif id_type == "Business":
- self.instructionLabel = QLabel("Select the Business ID:")
- self.idComboBox = BusinessIDComboBox()
- elif id_type == "Advert":
- self.instructionLabel = QLabel("Select the Advert ID:")
- self.idComboBox = AdvertIDComboBox()
- self.instructionLabel.setAlignment(Qt.AlignCenter)
- self.submitButton.setFixedWidth(90)
- self.layout.setSpacing(10)
- self.layout.addWidget(self.instructionLabel)
- self.layout.addWidget(self.idComboBox)
- self.layout.addWidget(self.submitButton)
- self.setLayout(self.layout)
- self.layout.setAlignment(self.submitButton, Qt.AlignCenter)
- assign_style_sheet(self, "body")
- # connections
- self.submitButton.clicked.connect(lambda: self.close())
- class ChoicesDialog(QDialog):
- def __init__(self):
- super().__init__()
- self.selectMethodComboBox = QComboBox()
- self.selectTypeComboBox = QComboBox()
- self.methodLabel = QLabel("Select Method:")
- self.typeLabel = QLabel("Select entry type:")
- self.submitButton = QPushButton("Next")
- self.spacer = QWidget()
- self.layout = QVBoxLayout()
- self.methodList = ["Add", "Edit", "Delete"]
- self.typeList = ["Contact", "Business", "Advert"]
- self.selectMethodComboBox.insertItems(0, self.methodList)
- self.selectTypeComboBox.insertItems(0, self.typeList)
- self.selectMethodComboBox.setFixedWidth(100)
- self.selectTypeComboBox.setFixedWidth(120)
- self.submitButton.setFixedWidth(90)
- self.spacer.setFixedSize(5, 5)
- self.layout.addWidget(self.methodLabel)
- self.layout.addWidget(self.selectMethodComboBox)
- self.layout.addWidget(self.spacer)
- self.layout.addWidget(self.typeLabel)
- self.layout.addWidget(self.selectTypeComboBox)
- self.layout.addWidget(self.submitButton)
- self.layout.setAlignment(self.selectMethodComboBox, Qt.AlignCenter)
- self.layout.setAlignment(self.selectTypeComboBox, Qt.AlignCenter)
- self.layout.setAlignment(self.submitButton, Qt.AlignCenter)
- self.layout.setSpacing(10)
- self.methodLabel.setAlignment(Qt.AlignCenter)
- self.typeLabel.setAlignment(Qt.AlignCenter)
- self.setLayout(self.layout)
- assign_style_sheet(self, "body")
- assign_style_sheet(self.methodLabel, "heading2")
- assign_style_sheet(self.typeLabel, "heading2")
- # connections
- self.submitButton.clicked.connect(lambda: self.close())
- class EntrySuccessfulDialog(QDialog):
- def __init__(self, method):
- super().__init__()
- self.returnLabel = QLabel("Click OK to return to main menu")
- self.okButton = QPushButton("OK")
- if method == "Add":
- self.methodLabel = QLabel("Entry added to database")
- elif method == "Edit":
- self.methodLabel = QLabel("Entry updated in database")
- elif method == "Delete":
- self.methodLabel = QLabel("Entry deleted from database")
- elif method == "AddPayment":
- self.methodLabel = QLabel("Payment saved")
- self.layout = QVBoxLayout()
- self.methodLabel.setAlignment(Qt.AlignCenter)
- self.returnLabel.setAlignment(Qt.AlignCenter)
- self.layout.addWidget(self.methodLabel)
- self.layout.addWidget(self.returnLabel)
- self.layout.addWidget(self.okButton)
- self.okButton.setFixedWidth(90)
- self.layout.setSpacing(10)
- self.layout.setContentsMargins(10, 10, 10, 10)
- self.layout.setAlignment(self.okButton, Qt.AlignCenter)
- self.setLayout(self.layout)
- assign_style_sheet(self.methodLabel, "heading2")
- assign_style_sheet(self.returnLabel, "body")
- # connections
- self.okButton.clicked.connect(lambda: self.close())
- class SearchByDialog(QDialog):
- def __init__(self):
- super().__init__()
- self.searchByLabel = QLabel("Select search by method:")
- self.surnameLabel = QLabel("Enter contact's surname:")
- self.nameLabel = QLabel("Enter business name:")
- self.categoryLabel = QLabel("Select the category:")
- self.paidLabel = QLabel("Select paid option:")
- self.advertOptionLabel = QLabel("Select advert option:")
- self.searchByComboBox = QComboBox()
- self.surnameLineEdit = QLineEdit()
- self.nameLineEdit = QLineEdit()
- self.categoryComboBox = CategoryComboBox(1)
- self.paidComboBox = YesNoComboBox()
- self.advertOptionComboBox = AdvertOptionComboBox()
- self.submitButton = QPushButton("Search")
- self.spacer = QWidget()
- self.surnameLayout = QVBoxLayout()
- self.nameLayout = QVBoxLayout()
- self.categoryLayout = QVBoxLayout()
- self.paidLayout = QVBoxLayout()
- self.advertOptionLayout = QVBoxLayout()
- self.layout = QVBoxLayout()
- self.stackedLayout = QStackedLayout()
- self.surnameWidget = QWidget()
- self.nameWidget = QWidget()
- self.categoryWidget = QWidget()
- self.paidWidget = QWidget()
- self.advertOptionWidget = QWidget()
- self.searchForWidget = QWidget()
- self.searchByList = ["Contact Surname", "Business Name", "Category", "Advert Paid", "Advert Option"]
- self.searchByComboBox.insertItems(0, self.searchByList)
- self.searchByComboBox.setFixedWidth(150)
- self.categoryComboBox.setEditable(False)
- self.paidComboBox.setFixedWidth(70)
- self.submitButton.setFixedWidth(100)
- self.spacer.setFixedSize(5, 5)
- self.searchByLabel.setAlignment(Qt.AlignCenter)
- self.surnameLabel.setAlignment(Qt.AlignCenter)
- self.nameLabel.setAlignment(Qt.AlignCenter)
- self.categoryLabel.setAlignment(Qt.AlignCenter)
- self.paidLabel.setAlignment(Qt.AlignCenter)
- self.advertOptionLabel.setAlignment(Qt.AlignCenter)
- self.surnameLayout.addWidget(self.surnameLabel)
- self.surnameLayout.addWidget(self.surnameLineEdit)
- self.surnameLayout.setAlignment(self.surnameLineEdit, Qt.AlignCenter)
- self.nameLayout.addWidget(self.nameLabel)
- self.nameLayout.addWidget(self.nameLineEdit)
- self.nameLayout.setAlignment(self.nameLineEdit, Qt.AlignCenter)
- self.categoryLayout.addWidget(self.categoryLabel)
- self.categoryLayout.addWidget(self.categoryComboBox)
- self.categoryLayout.setAlignment(self.categoryComboBox, Qt.AlignCenter)
- self.paidLayout.addWidget(self.paidLabel)
- self.paidLayout.addWidget(self.paidComboBox)
- self.paidLayout.setAlignment(self.paidComboBox, Qt.AlignCenter)
- self.advertOptionLayout.addWidget(self.advertOptionLabel)
- self.advertOptionLayout.addWidget(self.advertOptionComboBox)
- self.advertOptionLayout.setAlignment(self.advertOptionComboBox, Qt.AlignCenter)
- self.surnameWidget.setLayout(self.surnameLayout)
- self.nameWidget.setLayout(self.nameLayout)
- self.categoryWidget.setLayout(self.categoryLayout)
- self.paidWidget.setLayout(self.paidLayout)
- self.advertOptionWidget.setLayout(self.advertOptionLayout)
- self.stackedLayout.addWidget(self.surnameWidget)
- self.stackedLayout.addWidget(self.nameWidget)
- self.stackedLayout.addWidget(self.categoryWidget)
- self.stackedLayout.addWidget(self.paidWidget)
- self.stackedLayout.addWidget(self.advertOptionWidget)
- self.searchForWidget.setLayout(self.stackedLayout)
- self.layout.addWidget(self.searchByLabel)
- self.layout.addWidget(self.searchByComboBox)
- self.layout.addWidget(self.spacer)
- self.layout.addWidget(self.searchForWidget)
- self.layout.addWidget(self.submitButton)
- self.layout.setAlignment(self.searchByComboBox, Qt.AlignCenter)
- self.layout.setAlignment(self.searchForWidget, Qt.AlignCenter)
- self.layout.setAlignment(self.submitButton, Qt.AlignCenter)
- self.layout.setSpacing(10)
- self.setLayout(self.layout)
- self.stackedLayout.setCurrentWidget(self.surnameWidget)
- assign_style_sheet(self, "body")
- assign_style_sheet(self.surnameLabel, "heading2")
- assign_style_sheet(self.nameLabel, "heading2")
- assign_style_sheet(self.categoryLabel, "heading2")
- assign_style_sheet(self.paidLabel, "heading2")
- assign_style_sheet(self.advertOptionLabel, "heading2")
- assign_style_sheet(self.searchByLabel, "heading2")
- # connections
- self.submitButton.clicked.connect(lambda: self.close())
- self.searchByComboBox.currentIndexChanged.connect(self.setSearchForLayout)
- def setSearchForLayout(self):
- search_method = self.searchByComboBox.currentText()
- if search_method == "Contact Surname":
- self.stackedLayout.setCurrentWidget(self.surnameWidget)
- elif search_method == "Business Name":
- self.stackedLayout.setCurrentWidget(self.nameWidget)
- elif search_method == "Category":
- self.stackedLayout.setCurrentWidget(self.categoryWidget)
- elif search_method == "Advert Paid":
- self.stackedLayout.setCurrentWidget(self.paidWidget)
- elif search_method == "Advert Option":
- self.stackedLayout.setCurrentWidget(self.advertOptionWidget)
- class TitleComboBox(QComboBox):
- def __init__(self):
- super().__init__()
- self.titleList = ["Miss", "Mr", "Mrs", "Ms"]
- self.insertItems(0, self.titleList)
- class ContactIDComboBox(QComboBox):
- def __init__(self):
- super().__init__()
- sql = "SELECT ContactID,FirstName,Surname FROM Contacts"
- contact_data = chamber_main_application.executeSQL(sql, "")
- self.contactList = []
- self.contactIDList = []
- for row in range(0, len(contact_data)):
- item = str(contact_data[row][0]) + " - " + str(contact_data[row][1]) + " " + str(contact_data[row][2])
- self.contactList.append(item)
- item = str(contact_data[row][0])
- self.contactIDList.append(item)
- mergeSort(self.contactList)
- mergeSort(self.contactIDList)
- self.insertItems(0, self.contactList)
- class CategoryComboBox(QComboBox):
- def __init__(self, no):
- super().__init__()
- sql = "SELECT Category1, Category2 FROM Businesses"
- self.setEditable(True)
- self.setInsertPolicy(QComboBox.InsertAlphabetically)
- category_data = chamber_main_application.executeSQL(sql, "")
- self.categoryList = []
- for column in range(0, 2):
- for row in range(0, len(category_data)):
- if category_data[row][column] not in self.categoryList and category_data[row][column] != "":
- self.categoryList.append(category_data[row][column])
- mergeSort(self.categoryList)
- if no != 1:
- self.categoryList.append(" - ")
- self.insertItems(0, self.categoryList)
- class AdvertNumberLineEdit(QLineEdit):
- def __init__(self):
- super().__init__()
- sql = "SELECT AdvertNo FROM Adverts"
- advert_no_data = chamber_main_application.executeSQL(sql, "")
- self.temp = 0
- for row in range(0, len(advert_no_data)):
- if advert_no_data[row][0] > self.temp:
- self.temp = advert_no_data[row][0]
- self.temp = str(self.temp + 1)
- self.setText(self.temp)
- class BusinessIDComboBox(QComboBox):
- def __init__(self):
- super().__init__()
- sql = "SELECT BusinessID,Name FROM Businesses"
- business_data = chamber_main_application.executeSQL(sql, "")
- self.businessList = []
- self.businessIDList = []
- for row in range(0, len(business_data)):
- item = str(business_data[row][0]) + " - " + str(business_data[row][1])
- self.businessList.append(item)
- item = business_data[row][0]
- self.businessIDList.append(item)
- mergeSort(self.businessList)
- mergeSort(self.businessIDList)
- self.insertItems(0, self.businessList)
- class AdvertIDComboBox(QComboBox):
- def __init__(self):
- super().__init__()
- sql = "SELECT AdvertNo,Name FROM Adverts,Businesses WHERE Adverts.BusinessID = Businesses.BusinessID"
- advert_data = chamber_main_application.executeSQL(sql, "")
- self.advertList = []
- self.advertIDList = []
- for row in range(0, len(advert_data)):
- item = str(advert_data[row][0]) + " - " + str(advert_data[row][1])
- self.advertList.append(item)
- item = str(advert_data[row][0])
- self.advertIDList.append(item)
- mergeSort(self.advertList)
- mergeSort(self.advertIDList)
- self.insertItems(0, self.advertList)
- class SizeComboBox(QComboBox):
- def __init__(self):
- super().__init__()
- self.sizeList = ["Full Page", "Half Page", "Special"]
- self.insertItems(0, self.sizeList)
- class PrintTypeComboBox(QComboBox):
- def __init__(self):
- super().__init__()
- self.printTypeList = ["Colour", "Monochrome"]
- self.insertItems(0, self.printTypeList)
- class YesNoComboBox(QComboBox):
- def __init__(self):
- super().__init__()
- self.yesNoList = ["Yes", "No"]
- self.insertItems(0, self.yesNoList)
- class DirectionComboBox(QComboBox):
- def __init__(self):
- super().__init__()
- self.directionList = ["Incoming", "Outgoing"]
- self.insertItems(0, self.directionList)
- class PaymentMethodComboBox(QComboBox):
- def __init__(self):
- super().__init__()
- self.paymentMethodList = ["Cash", "Cheque", "Online"]
- self.insertItems(0, self.paymentMethodList)
- class AdvertOptionComboBox(QComboBox):
- def __init__(self):
- super().__init__()
- self.advertOptionList = ["New", "Changes", "No Changes"]
- self.insertItems(0, self.advertOptionList)
- class BusinessComboBox(QComboBox):
- def __init__(self):
- super().__init__()
- self.businessEntityList = ["Business ID", "Name", "Contact ID", "Email",
- "Telephone", "Website", "Category 1", "Category 2"]
- self.insertItems(0, self.businessEntityList)
- class AdvertComboBox(QComboBox):
- def __init__(self):
- super().__init__()
- self.advertEntityList = ["Advert Number", "Business ID", "Size", "Print Type",
- "Paid", "Payment Method", "Receipt", "Option", "Details"]
- self.insertItems(0, self.advertEntityList)
- class ContactComboBox(QComboBox):
- def __init__(self):
- super().__init__()
- self.contactEntityList = ["Contact ID", "Title", "First Name", "Surname",
- "Address 1", "Address 2", "Town", "Postcode"]
- self.insertItems(0, self.contactEntityList)
- class OrderByComboBox(QComboBox):
- def __init__(self):
- super().__init__()
- self.orderByList = ["Contact ID", "First Name", "Surname", "Address 2", "Town", "Business ID", "Business Name",
- "Category 1", "Category 2", "Advert No.", "Advert Size", "Print Type", "Paid?",
- "Payment Method", "Receipt?", "Option"]
- self.insertItems(0, self.orderByList)
- class DatabaseTabWidget(QWidget):
- def __init__(self, table_type):
- super().__init__()
- self.tableWidget = ViewTableWidget(table_type)
- self.tabLayout = QVBoxLayout()
- self.tableWidget.setEditTriggers(QAbstractItemView.NoEditTriggers)
- self.tableWidget.verticalHeader().setVisible(False)
- self.tableWidget.setFixedWidth(1100)
- self.tableWidget.setFixedHeight(400)
- self.tabLayout.addWidget(self.tableWidget)
- self.tabLayout.setAlignment(Qt.AlignCenter)
- self.setLayout(self.tabLayout)
- assign_style_sheet(self.tableWidget.horizontalHeader(), "heading2")
- class OrderByWidget(QWidget):
- def __init__(self):
- super().__init__()
- self.orderLabel = QLabel("Order:")
- self.orderByLabel = QLabel("Order By:")
- self.orderByComboBox = OrderByComboBox()
- self.updateButton = QPushButton("Update")
- self.radioButtonWidget = RadioButtonWidget()
- self.layout = QVBoxLayout()
- assign_style_sheet(self, "body")
- assign_style_sheet(self.orderLabel, "heading2")
- assign_style_sheet(self.orderByLabel, "heading2")
- self.layout.addWidget(self.orderLabel)
- self.layout.addWidget(self.radioButtonWidget)
- self.layout.addWidget(self.orderByLabel)
- self.layout.addWidget(self.orderByComboBox)
- self.layout.addWidget(self.updateButton)
- self.layout.setAlignment(self.orderLabel, Qt.AlignCenter)
- self.layout.setAlignment(self.radioButtonWidget, Qt.AlignCenter)
- self.layout.setAlignment(self.orderByLabel, Qt.AlignCenter)
- self.layout.setAlignment(self.orderByComboBox, Qt.AlignCenter)
- self.layout.setAlignment(self.updateButton, Qt.AlignCenter)
- self.setLayout(self.layout)
- class RadioButtonWidget(QWidget):
- def __init__(self):
- super().__init__()
- self.radioButtonGroup = QButtonGroup()
- self.radioButtonList = []
- self.radioButtonLayout = QVBoxLayout()
- self.radioButtonList.append(QRadioButton("Ascending"))
- self.radioButtonList.append(QRadioButton("Descending"))
- self.radioButtonList[0].setChecked(True)
- counter = 1
- for item in self.radioButtonList:
- self.radioButtonLayout.addWidget(item)
- self.radioButtonGroup.addButton(item)
- self.radioButtonGroup.setId(item, counter)
- counter += 1
- self.setLayout(self.radioButtonLayout)
- class SearchTableWidget(QTableWidget):
- def __init__(self, method, data):
- super().__init__()
- assign_style_sheet(self, "body")
- self.setFixedWidth(1000)
- self.setFixedHeight(350)
- self.setEditTriggers(QAbstractItemView.NoEditTriggers)
- self.verticalHeader().setVisible(False)
- self.setColumnCount(23)
- header_labels = ["Contact ID", "Title", "First Name", "Surname", "Address 1", "Address 2", "Town",
- "Postcode", "Business ID", "Business Name", "Email", "Telephone", "Website",
- "Category 1", "Category 2", "Advert No.", "Advert Size", "Print Type", "Paid?",
- "Payment Method", "Receipt?", "Option", "Details"]
- self.setHorizontalHeaderLabels(header_labels)
- self.populateTable(method, data, 1, 0)
- for i in range(0, len(header_labels)):
- self.horizontalHeader().setSectionResizeMode(i, QHeaderView.ResizeToContents)
- assign_style_sheet(self, "body")
- assign_style_sheet(self.horizontalHeader(), "heading2")
- # noinspection PyUnboundLocalVariable
- def populateTable(self, method, data, order, key_col):
- if method == "Contact Surname":
- sql = "SELECT * FROM Contacts,Businesses,Adverts WHERE Surname=? AND Contacts.ContactID = " \
- "Businesses.ContactID AND Businesses.BusinessID = Adverts.BusinessID"
- elif method == "Business Name":
- sql = "SELECT * FROM Contacts,Businesses,Adverts WHERE Name=? AND Contacts.ContactID = " \
- "Businesses.ContactID AND Businesses.BusinessID = Adverts.BusinessID"
- elif method == "Category":
- sql = "SELECT * FROM Contacts,Businesses,Adverts WHERE (Category1=? OR Category2=?) AND Contacts.ContactID " \
- "= Businesses.ContactID AND Businesses.BusinessID = Adverts.BusinessID"
- elif method == "Advert Paid":
- sql = "SELECT * FROM Contacts,Businesses,Adverts WHERE Paid=? AND Contacts.ContactID = " \
- "Businesses.ContactID AND Businesses.BusinessID = Adverts.BusinessID"
- elif method == "Advert Option":
- sql = "SELECT * FROM Contacts,Businesses,Adverts WHERE Option=? AND Contacts.ContactID = " \
- "Businesses.ContactID AND Businesses.BusinessID = Adverts.BusinessID"
- # noinspection PyUnboundLocalVariable
- temp_data = data
- if method == "Category":
- data = [temp_data, temp_data]
- else:
- data = [temp_data]
- temp_results = chamber_main_application.executeSQL(sql, data)
- results = []
- for row in range(0, len(temp_results)):
- temp_list = []
- for column in range(0, 25):
- item = str(temp_results[row][column])
- if column != 10 and column != 18:
- temp_list.append(item)
- results.append(temp_list)
- results = sortList(results, order, key_col)
- for row in range(0, len(results)):
- self.insertRow(row)
- for column in range(0, 23):
- if column == 11:
- item = QTableWidgetItem("0" + str(results[row][column]))
- else:
- item = QTableWidgetItem(str(results[row][column]))
- self.setItem(row, column, item)
- class ViewTableWidget(QTableWidget):
- # noinspection PyUnboundLocalVariable
- def __init__(self, table_type):
- super().__init__()
- if table_type == "Contacts":
- sql = "SELECT * FROM Contacts ORDER BY ContactID"
- column_count = 8
- headers = ["Contact ID", "Title", "First Name", "Surname", "Address 1", "Address 2", "Town", "Postcode"]
- elif table_type == "Businesses":
- sql = "SELECT * FROM Businesses ORDER BY BusinessID"
- column_count = 8
- headers = ["Business ID", "Name", "Contact ID", "Email", "Telephone", "Website", "Category 1", "Category 2"]
- elif table_type == "Adverts":
- sql = "SELECT * FROM Adverts ORDER BY AdvertNo"
- column_count = 9
- headers = ["Advert No", "Business ID", "Size", "Print Type", "Paid", "Payment Method", "Receipt", "Option",
- "Details"]
- self.setColumnCount(column_count)
- self.setHorizontalHeaderLabels(headers)
- for i in range(0, column_count):
- self.horizontalHeader().setSectionResizeMode(i, QHeaderView.ResizeToContents)
- results = chamber_main_application.executeSQL(sql, "")
- for row in range(0, len(results)):
- self.insertRow(row)
- for column in range(0, column_count):
- if table_type == "Businesses" and column == 4:
- item = QTableWidgetItem("0"+str(results[row][column]))
- else:
- item = QTableWidgetItem(str(results[row][column]))
- self.setItem(row, column, item)
- assign_style_sheet(self, "body")
- class FormDetailsWidget(QWidget):
- def __init__(self):
- super().__init__()
- # noinspection PyMethodMayBeStatic
- def validateText(self, data):
- if data.isalpha() and len(data) > 0:
- return True
- else:
- return False
- # noinspection PyMethodMayBeStatic
- def validateNumber(self, data):
- if not data.isalpha() and len(data) > 0:
- return True
- else:
- return False
- class ContactFormDetailsWidget(FormDetailsWidget):
- def __init__(self):
- super().__init__()
- self.errors = []
- self.data = []
- self.contactIDLabel = QLabel("Contact ID:")
- self.titleLabel = QLabel("Title:")
- self.firstNameLabel = QLabel("First Name:")
- self.surnameLabel = QLabel("Surname:")
- self.address1Label = QLabel("Address Line 1:")
- self.address2Label = QLabel("Address Line 2:")
- self.townLabel = QLabel("Town:")
- self.postcodeLabel = QLabel("Postcode:")
- self.contactIDLineEdit = QLineEdit()
- self.titleComboBox = TitleComboBox()
- self.firstNameLineEdit = QLineEdit()
- self.surnameLineEdit = QLineEdit()
- self.address1LineEdit = QLineEdit()
- self.address2LineEdit = QLineEdit()
- self.townLineEdit = QLineEdit()
- self.postcodeLineEdit = QLineEdit()
- self.layout = QFormLayout()
- assign_style_sheet(self, "body")
- self.layout.addRow(self.contactIDLabel, self.contactIDLineEdit)
- self.layout.addRow(self.titleLabel, self.titleComboBox)
- self.layout.addRow(self.firstNameLabel, self.firstNameLineEdit)
- self.layout.addRow(self.surnameLabel, self.surnameLineEdit)
- self.layout.addRow(self.address1Label, self.address1LineEdit)
- self.layout.addRow(self.address2Label, self.address2LineEdit)
- self.layout.addRow(self.townLabel, self.townLineEdit)
- self.layout.addRow(self.postcodeLabel, self.postcodeLineEdit)
- self.layout.setLabelAlignment(Qt.AlignRight)
- self.setLayout(self.layout)
- def clearData(self):
- self.contactIDLineEdit.setText("")
- self.titleComboBox.setCurrentIndex(0)
- self.firstNameLineEdit.setText("")
- self.surnameLineEdit.setText("")
- self.address1LineEdit.setText("")
- self.address2LineEdit.setText("")
- self.townLineEdit.setText("")
- self.postcodeLineEdit.setText("")
- # noinspection PyAttributeOutsideInit
- def getEntries(self):
- self.contactID = self.contactIDLineEdit.text()
- self.title = self.titleComboBox.currentText()
- self.firstName = self.firstNameLineEdit.text()
- self.firstName = self.firstName.title()
- self.surname = self.surnameLineEdit.text()
- self.surname = self.surname.title()
- self.address1 = self.address1LineEdit.text()
- self.address1 = self.address1.title()
- self.address2 = self.address2LineEdit.text()
- self.address2 = self.address2.title()
- self.town = self.townLineEdit.text()
- self.town = self.town.title()
- self.postcode = self.postcodeLineEdit.text()
- def validateData(self, method, table):
- data_valid = True
- self.getEntries()
- if method == "Add":
- if not self.validateContactID():
- data_valid = False
- self.errors.append("Contact ID")
- else:
- self.data.append(self.contactID)
- self.data.append(self.title)
- elif method == "Edit":
- self.data.append(self.contactID)
- self.data.append(self.title)
- elif method == "Delete":
- checked = chamber_main_application.checkReferentialIntegrity(self.contactID, table)
- if checked:
- self.data.append(self.contactID)
- self.data.append(self.title)
- self.data.append(self.firstName)
- self.data.append(self.surname)
- self.data.append(self.address1)
- self.data.append(self.address2)
- self.data.append(self.town)
- self.data.append(self.postcode)
- else:
- data_valid = False
- self.errors.append("Contact in use in another table")
- if method != "Delete":
- if not self.validateText(self.firstName):
- data_valid = False
- self.errors.append("First Name")
- else:
- self.data.append(self.firstName)
- if not self.validateText(self.surname):
- data_valid = False
- self.errors.append("Surname")
- else:
- self.data.append(self.surname)
- if self.address1 == "":
- data_valid = False
- self.errors.append("Address 1")
- else:
- self.data.append(self.address1)
- self.data.append(self.address2)
- if not self.validateText(self.town):
- data_valid = False
- self.errors.append("Town")
- else:
- self.data.append(self.town)
- if len(self.postcode) not in range(5, 9):
- data_valid = False
- self.errors.append("Postcode")
- else:
- self.data.append(self.postcode)
- return data_valid, self.data, self.errors
- # noinspection PyAttributeOutsideInit,PyUnboundLocalVariable
- def validateContactID(self):
- data_valid = True
- chars_list = list(self.contactID)
- valid_list = []
- if len(chars_list) == 4:
- letter_list = chars_list[:2]
- number_list = chars_list[2:]
- elif len(chars_list) == 5:
- letter_list = chars_list[:3]
- number_list = chars_list[2:]
- else:
- data_valid = False
- letter_list = []
- number_list = []
- for char in letter_list:
- if not char.isalpha():
- data_valid = False
- else:
- char = char.upper()
- valid_list.append(char)
- for char in number_list:
- if not char.isdigit():
- data_valid = False
- else:
- valid_list.append(char)
- if data_valid:
- self.contactID = "".join(valid_list)
- sql = "SELECT ContactID FROM Contacts"
- data = chamber_main_application.executeSQL(sql, "")
- contact_id_list = []
- for item in data:
- contact_id_list.append(item[0])
- for item in contact_id_list:
- if self.contactID == item:
- data_valid = False
- return data_valid
- def setData(self, data_list, method):
- self.contactIDLineEdit.setText(data_list[0][0])
- self.titleComboBox.setCurrentIndex(self.titleComboBox.titleList.index(data_list[0][1]))
- self.firstNameLineEdit.setText(data_list[0][2])
- self.surnameLineEdit.setText(data_list[0][3])
- self.address1LineEdit.setText(data_list[0][4])
- self.address2LineEdit.setText(data_list[0][5])
- self.townLineEdit.setText(data_list[0][6])
- self.postcodeLineEdit.setText(data_list[0][7])
- if method == "Delete":
- self.contactIDLineEdit.setReadOnly(True)
- self.firstNameLineEdit.setReadOnly(True)
- self.surnameLineEdit.setReadOnly(True)
- self.address1LineEdit.setReadOnly(True)
- self.address2LineEdit.setReadOnly(True)
- self.townLineEdit.setReadOnly(True)
- self.postcodeLineEdit.setReadOnly(True)
- self.titleComboBox.clear()
- self.titleComboBox.addItem(data_list[0][1])
- class BusinessFormDetailsWidget(FormDetailsWidget):
- def __init__(self):
- super().__init__()
- self.errors = []
- self.data = []
- self.businessIDLabel = QLabel("Business ID:")
- self.businessNameLabel = QLabel("Business Name:")
- self.contactIDLabel = QLabel("Contact ID:")
- self.emailLabel = QLabel("Email:")
- self.telephoneLabel = QLabel("Telephone:")
- self.webAddressLabel = QLabel("Web Address:")
- self.category1Label = QLabel("Category 1:")
- self.category2Label = QLabel("Category 2:")
- self.businessIDLineEdit = QLineEdit()
- self.businessNameLineEdit = QLineEdit()
- self.contactIDComboBox = ContactIDComboBox()
- self.emailLineEdit = QLineEdit()
- self.telephoneLineEdit = QLineEdit()
- self.webAddressLineEdit = QLineEdit()
- self.category1ComboBox = CategoryComboBox(1)
- self.category2ComboBox = CategoryComboBox(2)
- self.layout = QFormLayout()
- assign_style_sheet(self, "body")
- self.layout.addRow(self.businessIDLabel, self.businessIDLineEdit)
- self.layout.addRow(self.businessNameLabel, self.businessNameLineEdit)
- self.layout.addRow(self.contactIDLabel, self.contactIDComboBox)
- self.layout.addRow(self.emailLabel, self.emailLineEdit)
- self.layout.addRow(self.telephoneLabel, self.telephoneLineEdit)
- self.layout.addRow(self.webAddressLabel, self.webAddressLineEdit)
- self.layout.addRow(self.category1Label, self.category1ComboBox)
- self.layout.addRow(self.category2Label, self.category2ComboBox)
- self.layout.setLabelAlignment(Qt.AlignRight)
- self.setLayout(self.layout)
- def clearData(self):
- self.businessIDLineEdit.setText("")
- self.businessNameLineEdit.setText("")
- self.contactIDComboBox.setCurrentIndex(0)
- self.emailLineEdit.setText("")
- self.telephoneLineEdit.setText("")
- self.webAddressLineEdit.setText("")
- self.category1ComboBox.setCurrentIndex(0)
- self.category2ComboBox.setCurrentIndex(0)
- # noinspection PyAttributeOutsideInit
- def getEntries(self):
- self.businessID = self.businessIDLineEdit.text()
- self.businessName = self.businessNameLineEdit.text()
- self.businessName = self.businessName.title()
- self.contactID = self.contactIDComboBox.currentText()
- self.email = self.emailLineEdit.text()
- self.telephone = self.telephoneLineEdit.text()
- self.webAddress = self.webAddressLineEdit.text()
- self.category1 = self.category1ComboBox.currentText()
- self.category1 = self.category1.title()
- self.category2 = self.category2ComboBox.currentText()
- self.category2 = self.category2.title()
- if self.category2 == " - ":
- self.category2 = ""
- self.tempContactID = self.contactID.split()
- self.contactID = self.tempContactID[0]
- def validateData(self, method, table):
- data_valid = True
- self.getEntries()
- if method == "Add":
- if not self.validateBusinessID():
- data_valid = False
- self.errors.append("BusinessID")
- else:
- self.data.append(self.businessID)
- elif method == "Edit":
- self.data.append(self.businessID)
- elif method == "Delete":
- checked = chamber_main_application.checkReferentialIntegrity(self.businessID, table)
- if checked:
- self.data.append(self.businessID)
- self.data.append(self.businessName)
- self.data.append(self.contactID)
- self.data.append(self.email)
- self.data.append(self.telephone)
- self.data.append(self.webAddress)
- self.data.append(self.category1)
- self.data.append(self.category2)
- else:
- data_valid = False
- self.errors.append("Business in use in another table")
- if method != "Delete":
- if self.businessName == "":
- self.errors.append("Business Name")
- else:
- self.data.append(self.businessName)
- self.data.append(self.contactID)
- if not self.validateEmail():
- data_valid = False
- self.errors.append("Email")
- else:
- self.data.append(self.email)
- if not self.validateNumber(self.telephone) or len(self.telephone) not in range(10, 13):
- data_valid = False
- self.errors.append("Telephone")
- else:
- self.data.append(self.telephone)
- if not self.validateWebAddress:
- data_valid = False
- self.errors.append("Web Address")
- else:
- self.data.append(self.webAddress)
- if self.category1 == self.category2:
- data_valid = False
- self.errors.append("Category 2")
- else:
- self.data.append(self.category1)
- self.data.append(self.category2)
- return data_valid, self.data, self.errors
- # noinspection PyAttributeOutsideInit,PyUnboundLocalVariable
- def validateBusinessID(self):
- data_valid = True
- chars_list = list(self.businessID)
- valid_list = []
- if len(chars_list) == 5:
- number_list = chars_list[3:]
- letter_list = chars_list[:3]
- else:
- data_valid = False
- for char in letter_list:
- if not char.isalpha():
- data_valid = False
- else:
- char = char.upper()
- valid_list.append(char)
- for char in number_list:
- if not char.isdigit():
- data_valid = False
- else:
- valid_list.append(char)
- if data_valid:
- self.businessID = "".join(valid_list)
- sql = "SELECT BusinessID FROM Businesses"
- data = chamber_main_application.executeSQL(sql, "")
- business_id_list = []
- for item in data:
- business_id_list.append(item[0])
- for item in business_id_list:
- if self.businessID == item:
- data_valid = False
- return data_valid
- def validateEmail(self):
- data_valid = False
- for char in self.email:
- if char == "@":
- data_valid = True
- if len(self.email) == 0:
- data_valid = False
- return data_valid
- def validateWebAddress(self):
- data_valid = False
- web_list = self.webAddress.split(".")
- endings_list = ["com", "net", "uk", "org", "gov"]
- if web_list[-1] not in endings_list:
- data_valid = False
- return data_valid
- def setData(self, data_list, method):
- self.businessIDLineEdit.setText(data_list[0][0])
- self.businessNameLineEdit.setText(data_list[0][1])
- self.contactIDComboBox.setCurrentIndex(self.contactIDComboBox.contactIDList.index(data_list[0][2]))
- self.emailLineEdit.setText(data_list[0][3])
- self.telephoneLineEdit.setText("0" + str(data_list[0][4]))
- self.webAddressLineEdit.setText(data_list[0][5])
- self.category1ComboBox.setCurrentIndex(self.category1ComboBox.categoryList.index(data_list[0][6]))
- if data_list[0][7] != "":
- self.category2ComboBox.setCurrentIndex(self.category2ComboBox.categoryList.index(data_list[0][7]))
- else:
- self.category2ComboBox.setCurrentIndex(len(self.category2ComboBox.categoryList) - 1)
- if method == "Delete":
- self.businessIDLineEdit.setReadOnly(True)
- self.businessNameLineEdit.setReadOnly(True)
- self.emailLineEdit.setReadOnly(True)
- self.telephoneLineEdit.setReadOnly(True)
- self.webAddressLineEdit.setReadOnly(True)
- self.contactIDComboBox.clear()
- self.contactIDComboBox.addItem(data_list[0][2])
- self.category1ComboBox.clear()
- self.category1ComboBox.addItem(data_list[0][6])
- self.category1ComboBox.setEditable(False)
- self.category2ComboBox.clear()
- self.category2ComboBox.addItem(data_list[0][7])
- self.category2ComboBox.setEditable(False)
- class AdvertFormDetailsWidget(FormDetailsWidget):
- def __init__(self):
- super().__init__()
- self.errors = []
- self.data = []
- self.advertNumberLabel = QLabel("Advert Number:")
- self.businessIDLabel = QLabel("Business ID:")
- self.sizeLabel = QLabel("Size:")
- self.printTypeLabel = QLabel("Print Type:")
- self.paidLabel = QLabel("Paid?:")
- self.paymentMethodLabel = QLabel("Payment Method:")
- self.receiptLabel = QLabel("Receipt?:")
- self.advertOptionLabel = QLabel("Advert Option:")
- self.detailsLabel = QLabel("Details:")
- self.advertNumberLineEdit = AdvertNumberLineEdit()
- self.businessIDComboBox = BusinessIDComboBox()
- self.sizeComboBox = SizeComboBox()
- self.printTypeComboBox = PrintTypeComboBox()
- self.paidComboBox = YesNoComboBox()
- self.paymentMethodComboBox = PaymentMethodComboBox()
- self.receiptComboBox = YesNoComboBox()
- self.advertOptionComboBox = AdvertOptionComboBox()
- self.detailsPlainTextEdit = QPlainTextEdit()
- self.layout = QFormLayout()
- assign_style_sheet(self, "body")
- self.layout.addRow(self.advertNumberLabel, self.advertNumberLineEdit)
- self.layout.addRow(self.businessIDLabel, self.businessIDComboBox)
- self.layout.addRow(self.sizeLabel, self.sizeComboBox)
- self.layout.addRow(self.printTypeLabel, self.printTypeComboBox)
- self.layout.addRow(self.paidLabel, self.paidComboBox)
- self.layout.addRow(self.paymentMethodLabel, self.paymentMethodComboBox)
- self.layout.addRow(self.receiptLabel, self.receiptComboBox)
- self.layout.addRow(self.advertOptionLabel, self.advertOptionComboBox)
- self.layout.addRow(self.detailsLabel, self.detailsPlainTextEdit)
- self.layout.setLabelAlignment(Qt.AlignRight)
- self.setLayout(self.layout)
- # connections
- self.paidComboBox.currentIndexChanged.connect(self.checkPayment)
- def clearData(self):
- self.advertNumberLineEdit.setText(self.advertNumberLineEdit.temp)
- self.businessIDComboBox.setCurrentIndex(0)
- self.sizeComboBox.setCurrentIndex(0)
- self.printTypeComboBox.setCurrentIndex(0)
- self.paidComboBox.setCurrentIndex(0)
- self.paymentMethodComboBox.setCurrentIndex(0)
- self.receiptComboBox.setCurrentIndex(0)
- self.advertOptionComboBox.setCurrentIndex(0)
- self.detailsPlainTextEdit.setPlainText("")
- # noinspection PyAttributeOutsideInit
- def getEntries(self):
- self.advertNumber = self.advertNumberLineEdit.text()
- self.businessID = self.businessIDComboBox.currentText()
- self.size = self.sizeComboBox.currentText()
- self.printType = self.printTypeComboBox.currentText()
- self.paid = self.paidComboBox.currentText()
- if self.paid == "Yes":
- self.paymentMethod = self.paymentMethodComboBox.currentText()
- self.receipt = self.receiptComboBox.currentText()
- else:
- self.paymentMethod = ""
- self.receipt = ""
- self.advertOption = self.advertOptionComboBox.currentText()
- self.details = self.detailsPlainTextEdit.toPlainText()
- self.details = self.details.title()
- self.tempBusinessID = self.businessID.split()
- self.businessID = self.tempBusinessID[0]
- # noinspection PyUnusedLocal
- def validateData(self, method, table):
- data_valid = True
- self.getEntries()
- if method == "Add":
- if not self.validateAdvertNumber():
- data_valid = False
- self.errors.append("Advert Number")
- else:
- self.data.append(self.advertNumber)
- else:
- self.data.append(self.advertNumber)
- self.data.append(self.businessID)
- self.data.append(self.size)
- self.data.append(self.printType)
- self.data.append(self.paid)
- self.data.append(self.paymentMethod)
- self.data.append(self.receipt)
- self.data.append(self.advertOption)
- self.data.append(self.details)
- return data_valid, self.data, self.errors
- def validateAdvertNumber(self):
- data_valid = True
- if not self.validateNumber(self.advertNumber):
- data_valid = False
- sql = "SELECT AdvertNo FROM Adverts"
- data = chamber_main_application.executeSQL(sql, "")
- advert_id_list = []
- for item in data:
- advert_id_list.append(item[0])
- for item in advert_id_list:
- if self.advertNumber == item:
- data_valid = False
- return data_valid
- def checkPayment(self):
- if self.paidComboBox.currentText() == "No":
- self.paymentMethodComboBox.setEnabled(False)
- self.receiptComboBox.setEnabled(False)
- elif self.paidComboBox.currentText() == "Yes":
- self.paymentMethodComboBox.setEnabled(True)
- self.receiptComboBox.setEnabled(True)
- def setData(self, data_list, method):
- self.advertNumberLineEdit.setText(str(data_list[0][0]))
- self.businessIDComboBox.setCurrentIndex(self.businessIDComboBox.businessIDList.index(data_list[0][1]))
- self.sizeComboBox.setCurrentIndex(self.sizeComboBox.sizeList.index(data_list[0][2]))
- self.printTypeComboBox.setCurrentIndex(self.printTypeComboBox.printTypeList.index(data_list[0][3]))
- self.paidComboBox.setCurrentIndex(self.paidComboBox.yesNoList.index(data_list[0][4]))
- if self.paidComboBox.currentText() == "Yes":
- self.paymentMethodComboBox.setCurrentIndex(self.paymentMethodComboBox.paymentMethodList.index(
- data_list[0][5]))
- self.receiptComboBox.setCurrentIndex(self.receiptComboBox.yesNoList.index(data_list[0][6]))
- self.advertOptionComboBox.setCurrentIndex(self.advertOptionComboBox.advertOptionList.index(data_list[0][7]))
- self.detailsPlainTextEdit.setPlainText(data_list[0][8])
- if method == "Delete":
- self.advertNumberLineEdit.setReadOnly(True)
- self.detailsPlainTextEdit.setReadOnly(True)
- self.businessIDComboBox.clear()
- self.businessIDComboBox.addItem(data_list[0][1])
- self.sizeComboBox.clear()
- self.sizeComboBox.addItem(data_list[0][2])
- self.printTypeComboBox.clear()
- self.printTypeComboBox.addItem(data_list[0][3])
- self.paidComboBox.clear()
- self.paidComboBox.addItem(data_list[0][4])
- self.paymentMethodComboBox.clear()
- self.paymentMethodComboBox.addItem(data_list[0][5])
- self.receiptComboBox.clear()
- self.receiptComboBox.addItem(data_list[0][6])
- self.advertOptionComboBox.clear()
- self.advertOptionComboBox.addItem(data_list[0][7])
- # Main Program
- chamber_main_application = ChamberMainApplication()
- chamber_main_window = ChamberMainWindow()
- chamber_main_window.show()
- chamber_main_window.raise_()
- chamber_main_application.exec_()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement