class OutSign(QMainWindow): def __init__(self,parent): super().__init__() self.parent = parent #Setting the window title self.setWindowTitle("Sign Out") #Widget set up self.searchTerm = QLineEdit("") self.btnSearch = QPushButton("Search") self.searchList = QListWidget() self.btnBack = QPushButton("Back") self.btnOut = QPushButton("Sign Out") self.labelT = QLabel("Please enter your Surname:") self.vLayoutMAIN = QVBoxLayout() self.hLayout1 = QHBoxLayout() self.hLayout2 = QHBoxLayout() self.hLayout1.addWidget(self.searchTerm) self.hLayout1.addWidget(self.btnSearch) self.hLayout2.addWidget(self.btnBack) self.hLayout2.addWidget(self.btnOut) self.vLayoutMAIN.addWidget(self.labelT) self.vLayoutMAIN.addLayout(self.hLayout1) self.vLayoutMAIN.addWidget(self.searchList) self.vLayoutMAIN.addLayout(self.hLayout2) self.widget = QWidget() self.widget.setLayout(self.vLayoutMAIN) self.setCentralWidget(self.widget) #Setting up push button connections self.btnSearch.clicked.connect(self.btnSearch_pushed) self.btnBack.clicked.connect(self.btnBack_pushed) self.btnOut.clicked.connect(self.btnOut_pushed) def btnSearch_pushed(self): #Clearing the list self.searchList.clear() #Retrieving all visitors from the database visitors = g_database.GetAllEntries() #Converting the users entry to text term = self.searchTerm.text() #converting the term to lower to allow for user input error term = term.lower() termFound = False for visitor in visitors: #Obtaing the surname from the database surname = visitor[2] #converting the surname to lower to allow for user input error surname = surname.lower() #Checking the search term matches the term in the database and the visitor isnt signed out if term == surname and visitor[7] == "N/A": #Creating a full name name = "" #Adding the forename and a space to the string name= name + (visitor[1]) + " " #Adding a surname name = name + (visitor[2]) #Adding the full name to the list self.searchList.addItem(name) termFound = True #If the term isnt found if termFound == False: #Calling the error window, passing in the message to display self.message=Message(self,"No entries found, please search again") #Showing the window self.message.show() #Raising the window the front of the screen self.message.raise_() #Returning the to the parent window def btnBack_pushed(self): self.parent.show() self.parent.raise_() self.close() def btnOut_pushed(self): #Converting the users selected item to text currentItem = self.searchList.currentItem().text() #Calling the clarification window, passing in the users selected name self.clarification = Clarification(self,currentItem) self.clarification.show() self.clarification.raise_() self.close()
class InSign(QMainWindow): def __init__(self,parent): super().__init__(parent) self.parent=parent #Setting the window title self.setWindowTitle("Sign In") #Widget set up self.forename = QLineEdit() self.labelF = QLabel("Forename: ") self.surname = QLineEdit() self.labelS = QLabel("Surname: ") self.reg = QLineEdit() self.labelR = QLabel("Car registration: ") self.labelE = QLabel("Visiting: ") self.EmployeeCombo = QComboBox() self.PopulateEmployeeComboBox() self.btnSignIn = QPushButton("Sign in") self.btnCancel = QPushButton("Cancel") #Using two & symbols to make it show up on the button self.btnTC = QPushButton("T&&C's") self.labelTC = QLabel("I have read and agree to the T&C's:") self.tick =QCheckBox() self.VLayoutMAIN = QVBoxLayout() self.VLayout1 = QVBoxLayout() self.VLayout2 = QVBoxLayout() self.HLayout1 = QHBoxLayout() self.HLayout2 = QHBoxLayout() self.HLayout3 = QHBoxLayout() self.VLayout1.addWidget(self.labelF) self.VLayout1.addWidget(self.labelS) self.VLayout1.addWidget(self.labelR) self.VLayout1.addWidget(self.labelE) self.VLayout2.addWidget(self.forename) self.VLayout2.addWidget(self.surname) self.VLayout2.addWidget(self.reg) self.VLayout2.addWidget(self.EmployeeCombo) self.HLayout1.addLayout(self.VLayout1) self.HLayout1.addLayout(self.VLayout2) self.HLayout2.addWidget(self.btnCancel) self.HLayout2.addWidget(self.btnTC) self.HLayout2.addWidget(self.btnSignIn) self.HLayout3.addWidget(self.labelTC) self.HLayout3.addWidget(self.tick) self.VLayoutMAIN.addLayout(self.HLayout1) self.VLayoutMAIN.addLayout(self.HLayout3) self.VLayoutMAIN.addLayout(self.HLayout2) self.widget = QWidget() self.widget.setLayout(self.VLayoutMAIN) self.setCentralWidget(self.widget) #Setting up push button connections self.btnSignIn.clicked.connect(self.btnSignIn_pushed) self.btnCancel.clicked.connect(self.btnCancel_pushed) self.btnTC.clicked.connect(self.btnTC_pushed) def PopulateEmployeeComboBox(self): #Retrieving all employess from the database employees = g_database.GetAllEmployees() #Creating a blank list name_list = [] for employee in employees: #Creating a full name name= "" #Adding the employee's name and department to the string name= name+ (employee[2]) + " " + (employee[1][0])+ " (" + (employee[3])+")" #Adding the full name to the drop down box name_list.append(name) #Sorting the list into alphabetical order name_list.sort() #Sorting through each employee for employee in name_list: #Adding the employee to the drop down box in alphabetical order self.EmployeeCombo.addItem(employee) def btnTC_pushed(self): #Starting the file called 'text.txt' using operating system commands os.startfile("text.txt") def btnSignIn_pushed(self): #Obtaining the selected index indexEmployee = self.EmployeeCombo.currentIndex() #Retrieving all the employee entries from the database employees = g_database.GetAllEmployees() #Assigning 'employee' to its data in the database employee = employees[indexEmployee] name= "" #Adding the forname initial and a space to the string name= name+(employee[1][0])+ " " #Adding the surname to the string name= name+(employee[2]) #Re-assigning 'employee' to the variable 'name' employee = name #Obtaining the current date and time time = datetime.datetime.now() #Obtaining just the time in the format hour:minute inTime =time.strftime('%H:%M') #Obataining just the date in the format day/month/year inDate = time.strftime('%d/%m/%Y') #Assigning 'outTime' to "N/A" as the user hasnt signed out outTime = "N/A" #Validation #Converting the users input to text forename = self.forename.text() surname = self.surname.text() registration = self.reg.text() forename_valid = True surname_valid = True reg_valid = False #Checking if the line edit has been left blank if forename != "" and surname != "" and registration != "": #Converting the forename and surname to lower case for easier validation forename = forename.lower() surname = surname.lower() #Setting up blank lists to append the alphabet into alphabet = ['-'] #Creating the alphabet from ascii characters for letter in map(chr, range(97, 123)): #Adding the character to the blank list alphabet.append(letter) count = -1 #Sorting through each character in 'forename' for each in forename: #Checking to see if its in the alphabet if each not in alphabet: forename_valid = False #Sorting through each character in 'surname' for each in surname: #Checking to see if its in the alphabet if each not in alphabet: surname_valid = False if forename_valid == False: #Calling the message window, passing in the message to display self.error = Message(self,"Please enter a valid Forename") #Showing the window self.error.show() #Raising the window the front of the screen self.error.raise_() if surname_valid == False: #Calling the message window, passing in the message to display self.error = Message(self,"Please enter a valid Surname") #Showing the window self.error.show() #Raising the window the front of the screen self.error.raise_() #Making the initial upper case initial = forename[0].upper() count = 1 #Adding the rest of the 'forename' to the new string for each in range(len(forename)-1): initial= initial + forename[count] count +=1 forename = initial #Making the initial upper case initial = surname[0].upper() count = 1 #Adding the rest of the 'forename' to the new string for each in range(len(surname)-1): initial= initial + surname[count] count +=1 surname = initial #Converting all of registration to upper case to format it correctly registration= registration.upper() #Checking that the registration number is less than or equal to 7 if len(registration) <= 7: reg_valid = True else: #Calling the message window, passing in the message to display self.error = Message(self,"Please enter a valid Registration Number ('N/A' if not applicable)") #Showing the window self.error.show() #Raising the window the front of the screen self.error.raise_() if reg_valid == True and forename_valid == True and surname_valid == True: #Checking if the tick box is checked if self.tick.isChecked(): #Adding the entered validated data to the database g_database.AddVisitor(forename,surname,registration,employee,inDate,inTime,outTime) self.parent.show() self.parent.raise_() #Calling the message window, passing in the message to display self.message=Message(self,"Please see a Receptionist to obtain your Visitor Pass") self.message.show() self.message.raise_() self.close() else: #Calling the message window, passing in the message to display self.error = Message(self,"Please read and agree to the terms and conditions") self.error.show() self.error.raise_() else: if forename == "" and surname == "" and registration =="": self.error = Message(self,"Please enter a forename, a surname and a registration number") self.error.show() self.error.raise_() elif forename == "" and surname=="": self.error = Message(self,"Please enter a forename and a surname") self.error.show() self.error.raise_() elif forename=="" and registration == "": self.error = Message(self,"Please enter a forename and a registration number") self.error.show() self.error.raise_() elif surname=="" and registration == "": self.error = Message(self,"Please enter a surname and a registration number") self.error.show() self.error.raise_() elif forename == "": self.error = Message(self,"Please enter a forename") self.error.show() self.error.raise_() elif surname =="": self.error = Message(self,"Please enter a surname") self.error.show() self.error.raise_() elif registration == "": self.error = Message(self,"Please enter a registration number ('N/A' if not applicable)") self.error.show() self.error.raise_() #Returning to the parent window def btnCancel_pushed(self): self.parent.show() self.close()
class VisitorBook(QMainWindow): def __init__(self,parent): super().__init__() self.parent = parent #Setting the window title self.setWindowTitle("Visitor Book") #Widget set up self.table = QTableWidget() self.refreshTable() self.btnBack = QPushButton("Back") self.btnClear = QPushButton("Clear") self.labelS = QLabel("Search:") self.searchTerm = QLineEdit("") self.btnSearch = QPushButton("Search") self.Hlayout1 = QHBoxLayout() self.VlayoutMAIN = QVBoxLayout() self.Vlayout = QVBoxLayout() self.Hlayout= QHBoxLayout() self.Vlayout.addWidget(self.table) self.Hlayout.addWidget(self.btnBack) self.Hlayout.addWidget(self.btnClear) self.Hlayout1.addWidget(self.labelS) self.Hlayout1.addWidget(self.searchTerm) self.Hlayout1.addWidget(self.btnSearch) self.VlayoutMAIN.addLayout(self.Hlayout1) self.VlayoutMAIN.addLayout(self.Vlayout) self.VlayoutMAIN.addLayout(self.Hlayout) self.widget = QWidget() self.widget.setLayout(self.VlayoutMAIN) self.setCentralWidget(self.widget) #Setting up push button connections self.btnBack.clicked.connect(self.btnBackPushed) self.btnClear.clicked.connect(self.btnClearPushed) self.btnSearch.clicked.connect(self.btnSearchPushed) def refreshTable(self): #Retrieving all visitor entries from the database entries = g_database.GetAllEntries() #Setting the row count to the number of entries so that there are no empty rows self.table.setRowCount(len(entries)) #Setting the coloumn count to 8 self.table.setColumnCount(8) #Setting the header labels self.table.setHorizontalHeaderLabels(["ID","Forename","Surname","Reg","Visiting","Date","Time In","Time Out"]) row = -1 #Sorting through each entry for entry in entries: column = 0 row += 1 #Sorting through each field in each entry for field in entry: #Adding each field to the table self.table.setItem(row,column,QTableWidgetItem(str(field))) column += 1 def btnSearchPushed(self): #Clearing the table self.table.clear() #Converting the users input to text term = self.searchTerm.text() #converting the term to lower case to allow for user input error term = term.lower() #Checking if the user actually entered something if term == "": #Running the 'refreshTable' function self.refreshTable() else: #Retrieving all visitor entries from the database entries = g_database.GetAllEntries() RowCount = 0 #Setting the row count self.table.setRowCount(RowCount) #Setting the coloumn count self.table.setColumnCount(8) #Setting the table headers self.table.setHorizontalHeaderLabels(["ID","Forename","Surname","Reg","Visiting","Date","Time In","Time Out"]) row = -1 #Sorting through each entry in the database #Setting the variable to True table_empty =True for entry in entries: #Obtaining the forename from the database forename = entry[1] #converting the forename to lower case to allow for user input error forename=forename.lower() #Obtaining the surname from the database surname = entry[2] #converting the surname to lower case to allow for user input error surname = surname.lower() #Converting the id intger to a string so it can be compared to the term, as the term is text ID = str(entry[0]) #Obtaining the registration number from the database reg = entry[3] #converting the registration number to lower case to allow for user input error reg = reg.lower() ##Obtaining the employee being visited from the database visiting = entry[4] #converting visiting to lower case to allow for user input error visiting = visiting.lower() #Checking to see if the term matches any of the fields in the database if term == ID or term == forename or term == surname or term == reg or term == visiting or term == entry[5] or term == entry[6] or term == entry[7]: RowCount +=1 #Resetting the row count to allow the program to add the found visitor self.table.setRowCount(RowCount) column = 0 row += 1 #Sorting through each field in that entry for field in entry: #Adding the field to the table self.table.setItem(row,column,QTableWidgetItem(str(field))) column += 1 #Changing table_empty to False if an entry has been entered into the table table_empty = False if table_empty == True: #Calling the message window, passing in the message to display self.error = Message(self,"No entries found, please try again") self.error.show() self.error.raise_() self.refreshTable() #Returning to the parent window def btnBackPushed(self): self.parent.show() self.parent.raise_() self.close() def btnClearPushed(self): #Calling the clarification window self.clear = Clarification(self) #Showing the window self.clear.show() #Raising the window to the front of the screen self.clear.raise_() #Closing the current window self.close()
class addEmployee(QMainWindow): def __init__(self,parent): super().__init__() self.parent = parent #Setting the window title self.setWindowTitle("Add employee") #Widget set up self.forename = QLineEdit() self.labelF = QLabel("Forename: ") self.surname = QLineEdit() self.labelS = QLabel("Surname: ") self.btnAdd = QPushButton("Add") self.btnCancel = QPushButton("Cancel") self.labelD = QLabel("Department:") self.department = QComboBox() #Adding the departments self.department.addItem("Marketing") self.department.addItem("Production") self.department.addItem("Sales") self.department.addItem("R&D") self.VLayoutMAIN = QVBoxLayout() self.VLayout1 = QVBoxLayout() self.VLayout2 = QVBoxLayout() self.HLayout1 = QHBoxLayout() self.HLayout2 = QHBoxLayout() self.VLayout1.addWidget(self.labelF) self.VLayout1.addWidget(self.labelS) self.VLayout1.addWidget(self.labelD) self.VLayout2.addWidget(self.forename) self.VLayout2.addWidget(self.surname) self.VLayout2.addWidget(self.department) self.HLayout1.addLayout(self.VLayout1) self.HLayout1.addLayout(self.VLayout2) self.HLayout2.addWidget(self.btnCancel) self.HLayout2.addWidget(self.btnAdd) self.VLayoutMAIN.addLayout(self.HLayout1) self.VLayoutMAIN.addLayout(self.HLayout2) self.widget = QWidget() self.widget.setLayout(self.VLayoutMAIN) self.setCentralWidget(self.widget) #Setting up button connections, to run functions when the buttons are pushed self.btnAdd.clicked.connect(self.btnAdd_pushed) self.btnCancel.clicked.connect(self.btnCancel_pushed) def btnAdd_pushed(self): #Converting the entries to text forename = self.forename.text() surname = self.surname.text() #Obtaining the selected index index = self.department.currentIndex() if index == 0: department = "Marketing" elif index == 1: department = "Production" elif index == 2: department = "Sales" elif index == 3: department = "R&D" forename_valid = True surname_valid = True #Checking if the line edit has been left blank if forename != "" and surname != "": #Converting the forename and surname to lower case for easier validation forename = forename.lower() surname = surname.lower() #Setting up blank lists to append the alphabet into alphabet = ['-'] #Creating the alphabet from ascii characters for letter in map(chr, range(97, 123)): #Adding the character to the blank list alphabet.append(letter) count = -1 #Sorting through each character in 'forename' for each in forename: #Checking to see if its in the alphabet if each not in alphabet: forename_valid = False #Sorting through each character in 'surname' for each in surname: #Checking to see if its in the alphabet if each not in alphabet: surname_valid = False if forename_valid == False: #Calling the message window, passing in the message to display self.error = Message(self,"Please enter a valid Forename") #Showing the window self.error.show() #Raising the window the front of the screen self.error.raise_() if surname_valid == False: #Calling the message window, passing in the message to display self.error = Message(self,"Please enter a valid Surname") #Showing the window self.error.show() #Raising the window the front of the screen self.error.raise_() #Making the initial upper case initial = forename[0].upper() count = 1 #Adding the rest of the 'forename' to the new string for each in range(len(forename)-1): initial= initial + forename[count] count +=1 forename = initial #Making the initial upper case initial = surname[0].upper() count = 1 #Adding the rest of the 'forename' to the new string for each in range(len(surname)-1): initial= initial + surname[count] count +=1 surname = initial if forename_valid == True and surname_valid == True: #Running the 'AddEmployee' function in the database to add the data to the database g_database.AddEmployee(forename,surname,department) #Showing the window self.parent.show() #Raising the window the front of the screen self.parent.raise_() #Refreshing the 'refresh_List' in the parent window to show the new addition self.parent.refresh_List() #Closing the current window self.close() else: if forename =="" and surname == "": #Calling the message window, passing in the message to display self.error = Message(self,"Please enter a Forename and Surname") #Showing the window self.error.show() #Raising the window the front of the screen self.error.raise_() elif forename == "": #Calling the message window, passing in the message to display self.error = Message(self,"Please enter a Forename") #Showing the window self.error.show() #Raising the window the front of the screen self.error.raise_() elif surname=="": #Calling the message window, passing in the message to display self.error = Message(self,"Please enter a Surname") #Showing the window self.error.show() #Raising the window the front of the screen self.error.raise_() #Returning the to the parent window def btnCancel_pushed(self): self.parent.show() self.parent.raise_() self.close()