Exemple #1
0
    def accept(self) -> None:
        self.popup = MessagePopup()
        if self.IDInput.text() == "" or (self.IDInput.text() == ""
                                         and self.barcodeInput.text() == ""):
            message = "Enter valid ID (8 digits) or barcode (14 digits)"
            self.popup.show_message(message)
            self.IDInput.setFocus()
            return

        if self.firstnameInput.text() == "" or self.lastnameInput.text() == "":
            message = "Enter first name and last name"
            self.popup.show_message(message)
            self.firstnameInput.setFocus()
            return

        if self.classTable.rowCount() == 0:
            message = "Select a class"
            self.popup.show_message(message)
            self.classListComboBox.setFocus()
            return

        success = Database.add_student(self.IDInput.text(),
                                       self.firstnameInput.text(),
                                       self.lastnameInput.text(),
                                       self.barcodeInput.text(),
                                       self.emailInput.text())
        message = ""
        if success:
            count = 0
            while count < self.classTable.rowCount():
                self.classTable.selectRow(count)
                selected_class = self.classTable.selectedItems()
                result = Database.register_student(self.IDInput.text(),
                                                   self.firstnameInput.text(),
                                                   self.lastnameInput.text(),
                                                   selected_class[0].text(),
                                                   selected_class[1].text(),
                                                   selected_class[2].text())
                a_class = combine_into_class(selected_class[0].text(),
                                             selected_class[1].text(),
                                             selected_class[2].text())
                if type(result) is tuple and result == (True, True):
                    message += "Student was successfully registered for " + a_class + "\n"
                    count += 1
                elif type(result) is tuple and result == (True, False):
                    message += "Student is already registered for " + a_class + "\n"
                elif type(result) is not tuple and result == False:
                    message += "The class " + a_class + " does not exist\n"
        else:
            message = "Student could not be added to system because student is already in the system"

        print(message)
        self.popup.show_message(message)
        self.close()
Exemple #2
0
 def add_button_clicked(self):
     if self.windowTitle() == "Add Student":
         result = Database.add_student(self.EIDInput.text(), self.firstNameInput.text(), self.lastNameInput.text(),
                                       self.barcodeInput.text(), self.emailInput.text())
         if result is True:
             self.accept()
         else:
             print("could not add student")
     else:
         result = Database.add_professor(self.firstNameInput.text(), self.lastNameInput.text(),
                                         self.emailInput.text())
         if result is True:
             self.accept()
         else:
             print("could not add professor")