示例#1
0
class CustomApp(QDialog, custom_ui):
    def __init__(self, parent=None):
        super(CustomApp, self).__init__(parent)
        self.setupUi(self)
        self.HandleButtonAction()

    # Method for Button action
    def HandleButtonAction(self):
        self.pushButtonCustomDepartmentAdd.clicked.connect(self.AddDepartment_validate)
        self.pushButtonCustomStorageAdd.clicked.connect(self.AddStorage_validate)
        self.pushButtonCustomCategoryAdd.clicked.connect(self.AddCategory_validate)
        self.pushButtonCustomEmployeeAdd.clicked.connect(self.AddEmployee_validate)

    # Method to validate empty field for drop-down data
    def AddDepartment_validate(self):
        if not self.lineCustomDepartment.text() == '':
            self.AddDepartment_custom()
        else:
            self.error_popup("Input Error", "Invalid or empty input in Department field")

    def AddStorage_validate(self):
        if not self.lineCustomStorage.text() == '':
            self.AddStorage_custom()
        else:
            self.error_popup("Input Error", "Invalid or empty input in Storage field.")

    def AddCategory_validate(self):
        if not self.lineCustomCategory.text() == '':
            self.AddCategory_custom()
        else:
            self.error_popup("Input Error", "Invalid or empty input in Category field.")

    def AddEmployee_validate(self):
        if not self.lineCustomEmployee.text() == '':
            self.AddEmployee_custom()
        else:
            self.error_popup("Input Error", "Invalid or empty input in Employee field.")

    # Method to add drop-down data
    def AddDepartment_custom(self):
        department_name = self.lineCustomDepartment.text()
        self.db = ConnectDatabase()
        try:
            self.cur = self.db.cursor()
            self.cur.execute('SAVEPOINT SP1')
            try:
                self.cur.execute('INSERT INTO department (department_name) VALUES (%s)', (department_name,))
            except psycopg2.IntegrityError:
                self.cur.execute('ROLLBACK TO SAVEPOINT SP1')
                self.lineCustomDepartment.clear()
                self.error_popup("Duplicate Input", "Department already exist. Please enter different input.")
            else:
                self.cur.execute('RELEASE SAVEPOINT SP1')
                self.db.commit()
                self.lineCustomDepartment.clear()
                self.success_popup("Department", "New Department Added.")
            self.db.close()
        except Exception as error:
            self.lineCustomDepartment.clear()
            self.error_popup("Input Error", "Failed to add department")

    def AddStorage_custom(self):
        storage_name = self.lineCustomStorage.text()
        self.db = ConnectDatabase()
        try:
            self.cur = self.db.cursor()
            self.cur.execute('SAVEPOINT SP1')
            try:
                self.cur.execute('INSERT INTO storage (storage_name) VALUES (%s)', (storage_name,))
            except psycopg2.IntegrityError:
                self.cur.execute('ROLLBACK TO SAVEPOINT SP1')
                self.lineCustomStorage.clear()
                self.error_popup("Duplicate Input", "Storage already exist. Please enter different input.")
            else:
                self.cur.execute('RELEASE SAVEPOINT SP1')
                self.db.commit()
                self.lineCustomStorage.clear()
                self.success_popup("Storage", "New Storage Added.")
            self.db.close()
        except Exception as error:
            self.lineCustomStorage.clear()
            self.error_popup("Input Error", "Failed to add storage")

    def AddCategory_custom(self):
        category_name = self.lineCustomCategory.text()
        self.db = ConnectDatabase()
        try:
            self.cur = self.db.cursor()
            self.cur.execute('SAVEPOINT SP1')
            try:
                self.cur.execute('INSERT INTO category (category_name) VALUES (%s)', (category_name,))
            except psycopg2.IntegrityError:
                self.cur.execute('ROLLBACK TO SAVEPOINT SP1')
                self.lineCustomCategory.clear()
                self.error_popup("Duplicate Input", "Category already exist. Please enter different input.")
            else:
                self.cur.execute('RELEASE SAVEPOINT SP1')
                self.db.commit()
                self.lineCustomCategory.clear()
                self.success_popup("Category", "New Category Added.")
            self.db.close()
        except Exception as error:
            self.lineCustomCategory.clear()
            self.error_popup("Input Error", "Failed to add category")

    def AddEmployee_custom(self):
        employee_name = self.lineCustomEmployee.text()
        self.db = ConnectDatabase()
        try:
            self.cur = self.db.cursor()
            self.cur.execute('SAVEPOINT SP1')
            try:
                self.cur.execute('INSERT INTO employee (employee_name) VALUES (%s)', (employee_name,))
            except psycopg2.IntegrityError:
                self.cur.execute('ROLLBACK TO SAVEPOINT SP1')
                self.lineCustomEmployee.clear()
                self.error_popup("Duplicate Input", "Employee already exist. Please enter different input.")
            else:
                self.cur.execute('RELEASE SAVEPOINT SP1')
                self.db.commit()
                self.lineCustomEmployee.clear()
                self.success_popup("Employee", "New Employee Added.")
            self.db.close()
        except Exception as error:
            self.lineCustomEmployee.clear()
            self.error_popup("Input Error", "Failed to add employee")

    # Method to show success popup window
    def success_popup(self, title_popup, msg_popup):
        popup = QMessageBox()
        popup.setFixedSize(500, 500)
        popup.setWindowTitle(title_popup)
        popup.setIcon(QMessageBox.Information)
        popup.setStyleSheet("font:9pt Poppins;")
        popup.setText(msg_popup)
        popup.exec_()

    # Method to show error popup window
    def error_popup(self, title_popup, msg_popup):
        popup = QMessageBox()
        popup.setFixedSize(500, 500)
        popup.setWindowTitle(title_popup)
        popup.setIcon(QMessageBox.Warning)
        popup.setStyleSheet("font:9pt Poppins;")
        popup.setText(msg_popup)
        popup.exec_()
示例#2
0
class AddPartApp(QDialog, addpart_ui):
    def __init__(self, parent=None):
        super(AddPartApp, self).__init__(parent)
        self.setupUi(self)
        self.ShowDepartment_custom()
        self.ShowStorage_custom()
        self.ShowCategory_custom()
        self.HandleButtonAction()

    # Method for Button action
    def HandleButtonAction(self):
        self.pushButtonNewPartAdd.clicked.connect(self.AddPart_validate)
        self.pushButtonNewPartReset.clicked.connect(self.AddPart_reset)

    # Method to show drop-down data
    def ShowDepartment_custom(self):
        self.db = ConnectDatabase()
        self.cur = self.db.cursor()
        self.cur.execute(
            'SELECT department_name FROM department ORDER BY department_name ASC'
        )
        department_list = self.cur.fetchall()
        for department in department_list:
            self.comboBoxNewPartDepartment.addItem(department[0])
        self.db.close()

    def ShowCategory_custom(self):
        self.db = ConnectDatabase()
        self.cur = self.db.cursor()
        self.cur.execute(
            'SELECT category_name FROM category ORDER BY category_name ASC')
        category_list = self.cur.fetchall()
        for category in category_list:
            self.comboBoxNewPartCategory.addItem(category[0])
        self.db.close()

    def ShowStorage_custom(self):
        self.db = ConnectDatabase()
        self.cur = self.db.cursor()
        self.cur.execute(
            'SELECT storage_name FROM storage ORDER BY storage_name ASC')
        storage_list = self.cur.fetchall()
        for storage in storage_list:
            self.comboBoxNewPartStorage.addItem(storage[0])
        self.db.close()

    # Method to validate empty field data entry
    def AddPart_validate(self):
        if not self.lineNewPartName.text() == '':
            if not self.lineNewPartManufacturer.text() == '':
                if not self.lineNewPartModel.text() == '':
                    if not self.lineNewPartDescription.toPlainText() == '':
                        self.AddPart_Data()
                    else:
                        self.error_popup(
                            "Input Error",
                            "Invalid input or empty Description field")
                else:
                    self.error_popup("Input Error",
                                     "Invalid input or empty Model field")
            else:
                self.error_popup("Input Error",
                                 "Invalid input or empty Manufacturer field")
        else:
            self.error_popup("Input Error",
                             "Invalid input or empty Name field")

    # Method to reset all add part fields
    def AddPart_reset(self):
        self.lineNewPartName.clear()
        self.comboBoxNewPartDepartment.clear()
        self.lineNewPartManufacturer.clear()
        self.lineNewPartModel.clear()
        self.comboBoxNewPartCategory.clear()
        self.comboBoxNewPartStorage.clear()
        self.spinBoxNewPartLimit.clear()
        self.lineNewPartDescription.clear()
        self.spinBoxNewPartLimit.setValue(1)
        self.ShowDepartment_custom()
        self.ShowStorage_custom()
        self.ShowCategory_custom()

    # Method to add part data
    def AddPart_Data(self):
        part_name = self.lineNewPartName.text()
        part_department = self.comboBoxNewPartDepartment.currentText()
        part_manufacturer = self.lineNewPartManufacturer.text()
        part_model = self.lineNewPartModel.text()
        part_category = self.comboBoxNewPartCategory.currentText()
        part_storage = self.comboBoxNewPartStorage.currentText()
        part_limit = self.spinBoxNewPartLimit.value()
        part_description = self.lineNewPartDescription.toPlainText()
        self.db = ConnectDatabase()
        try:
            self.cur = self.db.cursor()
            self.cur.execute('SAVEPOINT SP1')
            try:
                self.cur.execute(
                    '''INSERT INTO part (part_name, part_department, part_manufacturer, part_model, part_category, part_storage, part_description, part_stocklimit) 
                                                    VALUES (%s , %s , %s , %s , %s , %s , %s , %s)''',
                    (part_name, part_department, part_manufacturer, part_model,
                     part_category, part_storage, part_description,
                     part_limit))
            except IntegrityError as error:
                self.cur.execute('ROLLBACK TO SAVEPOINT SP1')
                self.AddPart_reset()
                self.error_popup(
                    "Duplicate Error",
                    "Name of part already exists! Please use different name")
            else:
                self.cur.execute('RELEASE SAVEPOINT SP1')
                self.db.commit()
                self.AddPart_reset()
                self.success_popup("Part", "New Part Added.")
        except Exception as error:
            self.cur.execute('ROLLBACK TO SAVEPOINT SP1')
            self.AddPart_reset()
            self.error_popup("Input Error", "Failed to add part.")
        self.db.close()

    # Method to show success popup window
    def success_popup(self, title_popup, msg_popup):
        popup = QMessageBox()
        popup.setFixedSize(500, 500)
        popup.setWindowTitle(title_popup)
        popup.setIcon(QMessageBox.Information)
        popup.setStyleSheet("font:9pt Poppins;")
        popup.setText(msg_popup)
        popup.exec_()

    # Method to show error popup window
    def error_popup(self, title_popup, msg_popup):
        popup = QMessageBox()
        popup.setFixedSize(500, 500)
        popup.setWindowTitle(title_popup)
        popup.setIcon(QMessageBox.Warning)
        popup.setStyleSheet("font:9pt Poppins;")
        popup.setText(msg_popup)
        popup.exec_()
示例#3
0
class EditPartApp(QDialog, editpart_ui):
    def __init__(self, part_id, parent=None):
        super(EditPartApp, self).__init__(parent)
        self.setupUi(self)
        self.HandleButtonAction()
        self.ShowCategory_custom()
        self.ShowStorage_custom()
        self.ShowDepartment_custom()
        self.EditPart_search(part_id)
        self.lineEditPartId.setText(str(part_id))

    # Method to show drop-down data
    def ShowDepartment_custom(self):
        self.db = ConnectDatabase()
        self.cur = self.db.cursor()
        self.cur.execute(
            'SELECT department_name FROM department ORDER BY department_name ASC'
        )
        department_list = self.cur.fetchall()
        for department in department_list:
            self.comboBoxEditPartDepartment.addItem(department[0])
        self.db.close()

    def ShowCategory_custom(self):
        self.db = ConnectDatabase()
        self.cur = self.db.cursor()
        self.cur.execute(
            'SELECT category_name FROM category ORDER BY category_name ASC')
        category_list = self.cur.fetchall()
        for category in category_list:
            self.comboBoxEditPartCategory.addItem(category[0])
        self.db.close()

    def ShowStorage_custom(self):
        self.db = ConnectDatabase()
        self.cur = self.db.cursor()
        self.cur.execute(
            'SELECT storage_name FROM storage ORDER BY storage_name ASC')
        storage_list = self.cur.fetchall()
        for storage in storage_list:
            self.comboBoxEditPartStorage.addItem(storage[0])
        self.db.close()

    # Method for Button action
    def HandleButtonAction(self):
        self.pushButtonEditPartSave.clicked.connect(self.save_action)
        self.pushButtonEditPartUndo.clicked.connect(self.EditPart_undo)
        self.pushButtonEditPartDelete.clicked.connect(self.delete_action)

    # Method to search the part
    def EditPart_search(self, part_id):
        self.db = ConnectDatabase()
        try:
            self.cur = self.db.cursor()
            self.cur.execute('''SELECT * FROM part WHERE id = %s''',
                             [(part_id, )])
            fetch_data = self.cur.fetchone()
            self.lineEditPartName.setText(fetch_data[1])
            self.comboBoxEditPartDepartment.setCurrentText(fetch_data[2])
            self.lineEditPartManufacturer.setText(fetch_data[3])
            self.lineEditPartModel.setText(fetch_data[4])
            self.comboBoxEditPartCategory.setCurrentText(fetch_data[5])
            self.comboBoxEditPartStorage.setCurrentText(fetch_data[6])
            self.spinBoxEditPartLimit.setValue(fetch_data[8])
            self.lineEditPartDescription.setPlainText(fetch_data[7])
        except Exception as error:
            self.error_popup("Input Error", "Part not found.")
        self.db.close()

    # Method to edit the part
    def EditPart_edit(self):
        edit_id = int(self.lineEditPartId.text())
        part_name = self.lineEditPartName.text()
        part_department = self.comboBoxEditPartDepartment.currentText()
        part_manufacturer = self.lineEditPartManufacturer.text()
        part_model = self.lineEditPartModel.text()
        part_category = self.comboBoxEditPartCategory.currentText()
        part_storage = self.comboBoxEditPartStorage.currentText()
        part_limit = self.spinBoxEditPartLimit.value()
        part_description = self.lineEditPartDescription.toPlainText()
        self.db = ConnectDatabase()
        try:
            self.cur = self.db.cursor()
            self.cur.execute('SAVEPOINT SP1')
            try:
                self.cur.execute(
                    '''UPDATE part SET part_name = %s, part_department = %s, part_manufacturer = %s, 
                part_model = %s, part_category = %s, part_storage = %s, part_description = %s, part_stocklimit = %s WHERE 
                id = %s''', (part_name, part_department, part_manufacturer,
                             part_model, part_category, part_storage,
                             part_description, part_limit, edit_id))
            except Exception as error:
                self.cur.execute('ROLLBACK TO SAVEPOINT SP1')
                self.error_popup("Input Error", "Fail to update Part.")
            else:
                self.cur.execute('RELEASE SAVEPOINT SP1')
                self.db.commit()
                self.success_popup("Part", "Successfully updated Part.")
        except Exception as error:
            self.cur.execute('ROLLBACK TO SAVEPOINT SP1')
            self.error_popup("Input Error", "Fail to connect database.")
        self.db.close()

    # Method to undo the part
    def EditPart_undo(self):
        edit_id = int(self.lineEditPartId.text())
        self.db = ConnectDatabase()
        try:
            self.cur = self.db.cursor()
            self.cur.execute('''SELECT * FROM part where id = %s''',
                             [(edit_id, )])
            fetch_data = self.cur.fetchone()
            self.lineEditPartName.setText(fetch_data[1])
            self.comboBoxEditPartDepartment.setCurrentText(fetch_data[2])
            self.lineEditPartManufacturer.setText(fetch_data[3])
            self.lineEditPartModel.setText(fetch_data[4])
            self.comboBoxEditPartCategory.setCurrentText(fetch_data[5])
            self.comboBoxEditPartStorage.setCurrentText(fetch_data[6])
            self.spinBoxEditPartLimit.setValue(fetch_data[8])
            self.lineEditPartDescription.setPlainText(fetch_data[7])
        except Exception as error:
            self.error_popup("Input Error", "Failed to undo Part.")
        self.db.close()

    # Method to delete the part
    def EditPart_delete(self):
        edit_id = int(self.lineEditPartId.text())
        self.db = ConnectDatabase()
        try:
            self.cur = self.db.cursor()
            self.cur.execute('SAVEPOINT SP1')
            try:
                self.cur.execute('''DELETE FROM part WHERE id = %s''',
                                 [(edit_id, )])
            except IntegrityError as error:
                self.cur.execute('ROLLBACK TO SAVEPOINT SP1')
                self.error_popup(
                    "Input Error",
                    "Part cannot be deleted due to entry data of the part exists."
                )
            else:
                self.cur.execute('RELEASE SAVEPOINT SP1')
                self.db.commit()
                self.success_popup("Part", "Successfully deleted Part.")
        except Exception as error:
            self.cur.execute('ROLLBACK TO SAVEPOINT SP1')
            self.error_popup("Input Error", "Failed to delete Part.")
        self.db.close()

    # Method to show success popup window
    def success_popup(self, title_popup, msg_popup):
        popup = QMessageBox()
        popup.setFixedSize(500, 500)
        popup.setWindowTitle(title_popup)
        popup.setIcon(QMessageBox.Information)
        popup.setStyleSheet("font:9pt Poppins;")
        popup.setText(msg_popup)
        popup.exec_()

    # Method to show error popup window
    def error_popup(self, title_popup, msg_popup):
        popup = QMessageBox()
        popup.setFixedSize(500, 500)
        popup.setWindowTitle(title_popup)
        popup.setIcon(QMessageBox.Warning)
        popup.setStyleSheet("font:9pt Poppins;")
        popup.setText(msg_popup)
        popup.exec_()

    # Method to confirm update part
    def save_action(self):
        action = QMessageBox.warning(
            self, 'Update Part',
            "Are you sure want to save the changes? Changes cannot be undo!",
            QMessageBox.Yes | QMessageBox.No)
        if action == QMessageBox.Yes:
            self.EditPart_edit()
        else:
            pass

    # Method to confirm delete part
    def delete_action(self):
        action = QMessageBox.warning(
            self, 'Delete Part',
            "Are you sure want to delete? Changes cannot be undo!",
            QMessageBox.Yes | QMessageBox.No)
        if action == QMessageBox.Yes:
            self.EditPart_delete()
        else:
            pass
示例#4
0
class EditEntryApp(QDialog, editentry_ui):
    def __init__(self, entry_id, parent=None):
        super(EditEntryApp, self).__init__(parent)
        self.setupUi(self)
        self.ShowEmployee_custom()
        self.ShowStatus_entry()
        self.HandleButtonAction()
        self.EditEntry_search(entry_id)
        self.lineEditEntryId.setText(str(entry_id))

    # Method to show drop-down data
    def ShowEmployee_custom(self):
        self.db = ConnectDatabase()
        self.cur = self.db.cursor()
        self.cur.execute('SELECT employee_name FROM employee ORDER BY employee_name ASC')
        employee_list = self.cur.fetchall()
        for employee in employee_list:
            self.comboBoxEditEntryEmployee.addItem(employee[0])
        self.db.close()

    def ShowStatus_entry(self):
        self.db = ConnectDatabase()
        self.cur = self.db.cursor()
        self.cur.execute('SELECT status_name FROM status ORDER BY status_name ASC')
        status_list = self.cur.fetchall()
        for status in status_list:
            self.comboBoxEditEntryStatus.addItem(status[0])
        self.db.close()

    # Method for Button action
    def HandleButtonAction(self):
        self.pushButtonEditEntrySave.clicked.connect(self.save_action)
        self.pushButtonEditEntryUndo.clicked.connect(self.EditEntry_undo)
        self.pushButtonEditEntryDelete.clicked.connect(self.delete_action)

    # Method to search the entry
    def EditEntry_search(self, entry_id):
        self.db = ConnectDatabase()
        try:
            self.cur = self.db.cursor()
            self.cur.execute('''SELECT entry.id, part.part_name, entry.entry_status, entry.entry_qty, 
            entry.entry_desc, entry.entry_date, entry.entry_employee FROM entry JOIN part ON entry.part_id = part.id 
            WHERE entry.id = %s''', [(entry_id,)])
            fetch_data = self.cur.fetchone()
            print(fetch_data)
            print(len(fetch_data[2]))
            self.lineEditEntryName.setText(fetch_data[1])
            self.comboBoxEditEntryStatus.setCurrentText(fetch_data[2])
            self.spinBoxEditEntryQuantity.setValue(fetch_data[3])
            self.lineEditEntryDescription.setPlainText(fetch_data[4])
            self.dateEditEntryDate.setDate(fetch_data[5])
            self.comboBoxEditEntryEmployee.setCurrentText(fetch_data[6])
        except Exception as error:
            self.error_popup("Input Error", "Failed to connect database")
        self.db.close()

    # Method to edit the entry
    def EditEntry_edit(self):
        edit_id = int(self.lineEditEntryId.text())
        entry_employee = self.comboBoxEditEntryEmployee.currentText()
        entry_status = self.comboBoxEditEntryStatus.currentText()
        entry_quantity = self.spinBoxEditEntryQuantity.value()
        entry_date = self.dateEditEntryDate.text()
        entry_description = self.lineEditEntryDescription.toPlainText()
        self.db = ConnectDatabase()
        try:
            self.cur = self.db.cursor()
            self.cur.execute('SAVEPOINT SP1')
            try:
                self.cur.execute('''UPDATE entry SET  entry_status = %s, entry_qty = %s, entry_desc = %s, entry_date 
                = %s, entry_employee = %s WHERE id = %s''', (entry_status, entry_quantity, entry_description,
                                                             entry_date, entry_employee, edit_id))
            except Exception as error:
                self.cur.execute('ROLLBACK TO SAVEPOINT SP1')
                self.error_popup("Input Error", "Fail to update Entry.")
            else:
                self.cur.execute('RELEASE SAVEPOINT SP1')
                self.db.commit()
                self.success_popup("Entry", "Successfully updated Entry.")
        except Exception as error:
            self.cur.execute('ROLLBACK TO SAVEPOINT SP1')
            self.error_popup("Input Error", "Fail to connect database.")
        self.db.close()

    # Method to undo the entry
    def EditEntry_undo(self):
        edit_id = int(self.lineEditEntryId.text())
        self.db = ConnectDatabase()
        try:
            self.cur = self.db.cursor()
            self.cur.execute('''SELECT entry.id, part.part_name, entry.entry_status, entry.entry_qty, 
            entry.entry_desc, entry.entry_date, entry.entry_employee FROM entry JOIN part ON entry.part_id = part.id 
            WHERE entry.id = %s''', [(edit_id,)])
            fetch_data = self.cur.fetchone()
            self.lineEditEntryName.setText(fetch_data[1])
            self.comboBoxEditEntryStatus.setCurrentText(fetch_data[4])
            self.spinBoxEditEntryQuantity.setValue(fetch_data[3])
            self.lineEditEntryDescription.setPlainText(fetch_data[2])
            self.dateEditEntryDate.setDate(fetch_data[5])
            self.comboBoxEditEntryEmployee.setCurrentText(fetch_data[6])
        except Exception as error:
            self.error_popup("Input Error", "Failed to undo Entry.")
        self.db.close()

    # Method to delete the part
    def EditEntry_delete(self):
        edit_id = int(self.lineEditEntryId.text())
        self.db = ConnectDatabase()
        try:
            self.cur = self.db.cursor()
            self.cur.execute('SAVEPOINT SP1')
            try:
                self.cur.execute('''DELETE FROM entry WHERE id = %s''', [(edit_id,)])
            except IntegrityError as error:
                self.cur.execute('ROLLBACK TO SAVEPOINT SP1')
                self.error_popup("Input Error", "Entry cannot be deleted due to part data of the entry exists.")
            else:
                self.cur.execute('RELEASE SAVEPOINT SP1')
                self.db.commit()
                self.success_popup("Entry", "Successfully deleted Entry.")
        except Exception as error:
            self.cur.execute('ROLLBACK TO SAVEPOINT SP1')
            self.error_popup("Input Error", "Failed to delete Entry.")
        self.db.close()

    # Method to show success popup window
    def success_popup(self, title_popup, msg_popup):
        popup = QMessageBox()
        popup.setFixedSize(500, 500)
        popup.setWindowTitle(title_popup)
        popup.setIcon(QMessageBox.Information)
        popup.setStyleSheet("font:9pt Poppins;")
        popup.setText(msg_popup)
        popup.exec_()

    # Method to show error popup window
    def error_popup(self, title_popup, msg_popup):
        popup = QMessageBox()
        popup.setFixedSize(500, 500)
        popup.setWindowTitle(title_popup)
        popup.setIcon(QMessageBox.Warning)
        popup.setStyleSheet("font:9pt Poppins;")
        popup.setText(msg_popup)
        popup.exec_()

    # Method to confirm update entry
    def save_action(self):
        action = QMessageBox.warning(self, 'Update Entry', "Are you sure want to save the changes? Changes cannot be undo!", QMessageBox.Yes | QMessageBox.No)
        if action == QMessageBox.Yes:
            self.EditEntry_edit()
        else:
            pass

    # Method to confirm delete entry
    def delete_action(self):
        action = QMessageBox.warning(self, 'Delete Entry', "Are you sure want to delete? Changes cannot be undo!", QMessageBox.Yes | QMessageBox.No)
        if action == QMessageBox.Yes:
            self.EditEntry_delete()
        else:
            pass
示例#5
0
class AddEntryApp(QDialog, addentry_ui):
    def __init__(self, parent=None):
        super(AddEntryApp, self).__init__(parent)
        self.setupUi(self)
        self.ShowEmployee_custom()
        self.ShowName_part()
        self.ShowStatus_entry()
        self.HandleButtonAction()

    # Method for Button action
    def HandleButtonAction(self):
        self.pushButtonNewEntryAdd.clicked.connect(self.AddEntry_validate)
        self.pushButtonNewEntryReset.clicked.connect(self.AddEntry_reset)

    # Method to show drop-down data
    def ShowEmployee_custom(self):
        self.db = ConnectDatabase()
        self.cur = self.db.cursor()
        self.cur.execute(
            'SELECT employee_name FROM employee ORDER BY employee_name ASC')
        employee_list = self.cur.fetchall()
        for employee in employee_list:
            self.comboBoxNewEntryEmployee.addItem(employee[0])
        self.db.close()

    def ShowName_part(self):
        self.db = ConnectDatabase()
        self.cur = self.db.cursor()
        self.cur.execute('SELECT part_name FROM part ORDER BY part_name ASC')
        part_list = self.cur.fetchall()
        for part in part_list:
            self.comboBoxNewEntryPart.addItem(part[0])
        self.db.close()

    def ShowStatus_entry(self):
        self.db = ConnectDatabase()
        self.cur = self.db.cursor()
        self.cur.execute(
            'SELECT status_name FROM status ORDER BY status_name ASC')
        status_list = self.cur.fetchall()
        for status in status_list:
            self.comboBoxNewEntryStatus.addItem(status[0])
        self.db.close()

    # Method to validate empty field data entry
    def AddEntry_validate(self):
        if not self.lineNewEntryDescription.toPlainText() == '':
            self.AddEntry_Data()
        else:
            self.error_popup("Input Error",
                             "Invalid input or empty Description field")

    # Method to reset all add part fields
    def AddEntry_reset(self):
        self.comboBoxNewEntryPart.clear()
        self.comboBoxNewEntryEmployee.clear()
        self.comboBoxNewEntryStatus.clear()
        self.spinBoxNewEntryQuantity.clear()
        self.lineNewEntryDescription.clear()
        self.comboBoxNewEntryEmployee.clear()
        self.spinBoxNewEntryQuantity.setValue(1)
        self.ShowName_part()
        self.ShowEmployee_custom()
        self.ShowStatus_entry()

    # Method to add entry data
    def AddEntry_Data(self):
        self.db = ConnectDatabase()
        part_id = self.comboBoxNewEntryPart.currentText()
        entry_employee = self.comboBoxNewEntryEmployee.currentText()
        entry_status = self.comboBoxNewEntryStatus.currentText()
        entry_quantity = self.spinBoxNewEntryQuantity.value()
        entry_description = self.lineNewEntryDescription.toPlainText()
        entry_date = self.dateNewEntryDate.text()

        try:
            self.cur = self.db.cursor()
            self.cur.execute('SAVEPOINT SP1')
            self.cur.execute(
                '''INSERT INTO entry (part_id, entry_status, entry_qty, entry_desc, entry_date, entry_employee)
                                                    VALUES ((SELECT id FROM part WHERE part_name = %s) , %s , %s , %s , %s , %s)''',
                (part_id, entry_status, entry_quantity, entry_description,
                 entry_date, entry_employee))
        except Exception as error:
            self.cur.execute('ROLLBACK TO SAVEPOINT SP1')
            self.AddEntry_reset()
            self.error_popup("Input Error", "Failed to add entry")
        else:
            self.cur.execute('RELEASE SAVEPOINT SP1')
            self.db.commit()
            self.AddEntry_reset()
            self.success_popup("Entry", "New Entry Added.")
        self.db.close()

    # Method to show success popup window
    def success_popup(self, title_popup, msg_popup):
        popup = QMessageBox()
        popup.setFixedSize(500, 500)
        popup.setWindowTitle(title_popup)
        popup.setIcon(QMessageBox.Information)
        popup.setStyleSheet("font:9pt Poppins;")
        popup.setText(msg_popup)
        popup.exec_()

    # Method to show error popup window
    def error_popup(self, title_popup, msg_popup):
        popup = QMessageBox()
        popup.setFixedSize(500, 500)
        popup.setWindowTitle(title_popup)
        popup.setIcon(QMessageBox.Warning)
        popup.setStyleSheet("font:9pt Poppins;")
        popup.setText(msg_popup)
        popup.exec_()