Beispiel #1
0
 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()
Beispiel #2
0
 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()
Beispiel #3
0
    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()
Beispiel #4
0
    def ListPart_show(self):
        field_name = self.lineListPartName.text()
        field_department = self.comboBoxListPartDepartment.currentText()
        field_category = self.comboBoxListPartCategory.currentText()
        field_storage = self.comboBoxListPartStorage.currentText()
        # field_stocklevel = self.comboBoxListPartStockLevel.currentText()
        search_name = '%{}%'.format(field_name)
        search_department = '%{}%'.format(field_department)
        search_category = '%{}%'.format(field_category)
        search_storage = '%{}%'.format(field_storage)
        # search_stocklevel = '%{}%'.format(field_stocklevel)

        self.db = ConnectDatabase()
        self.cur = self.db.cursor()
        try:
            self.cur.execute(
                '''SELECT part.id, part.part_name, part.part_department, part.part_manufacturer, part.part_model, part.part_category, part.part_storage, part.part_stocklimit, 
            SUM ( ( CASE 
                    WHEN entry.entry_status = 'In' THEN 1 
                    ELSE -1 END)*entry.entry_qty) AS stock_quantity,
            CASE 
                WHEN SUM( (CASE  WHEN entry.entry_status = 'In' THEN 1 ELSE -1 END)* entry.entry_qty) < part.part_stocklimit/2 THEN 'Critical'
                WHEN SUM( (CASE  WHEN entry.entry_status = 'In' THEN 1 ELSE -1 END)* entry.entry_qty) < part.part_stocklimit THEN 'Low'
                WHEN SUM( (CASE  WHEN entry.entry_status = 'In' THEN 1 ELSE -1 END)* entry.entry_qty) >= part.part_stocklimit THEN 'Normal'
                WHEN SUM( (CASE  WHEN entry.entry_status = 'In' THEN 1 ELSE -1 END)* entry.entry_qty) > part.part_stocklimit*2 THEN 'High'
                ELSE 'Normal' END AS stock_level,
            part.part_description
            FROM part 
            INNER JOIN entry ON entry.part_id = part.id 
            GROUP BY part.id
            HAVING part.part_name ILIKE %s AND part.part_department ILIKE %s AND part.part_category ILIKE %s AND part.part_storage ILIKE %s ORDER BY part.id ASC''',
                (search_name, search_department, search_category,
                 search_storage))
            fetch_data = self.cur.fetchall()
        except Exception as error:
            print(error)
            self.error_popup("Duplicate Error", str(error))
        else:
            if fetch_data is None:
                self.tableWidgetListPart.setRowCount(0)
                self.error_popup("List Part", "No records found!")
            else:
                self.tableWidgetListPart.horizontalHeader(
                ).setSectionResizeMode(0, 20)
                self.tableWidgetListPart.horizontalHeader(
                ).setSectionResizeMode(1, 20)
                self.tableWidgetListPart.setRowCount(0)
                self.tableWidgetListPart.insertRow(0)
                for row, form in enumerate(fetch_data):
                    for column, item in enumerate(form):
                        self.tableWidgetListPart.setItem(
                            row, column, QTableWidgetItem(str(item)))
                        column += 1
                        row_position = self.tableWidgetListPart.rowCount()
                        self.tableWidgetListPart.insertRow(row_position)
                        self.tableWidgetListPart.resizeColumnsToContents()
                        self.tableWidgetListPart.horizontalHeader(
                        ).setSectionResizeMode(10, QHeaderView.Stretch)
        self.db.close()
Beispiel #5
0
 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()
Beispiel #6
0
 def Connect_status(self):
     try:
         ConnectDatabase()
     except Exception as error:
         self.statusBar().showMessage('Failed connect to database.')
     else:
         self.statusBar().showMessage('Connected to database.')
     ConnectDatabase().close()
Beispiel #7
0
 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()
Beispiel #8
0
 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()
Beispiel #9
0
 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.comboBoxListPartCategory.addItem(category[0])
     self.db.close()
Beispiel #10
0
 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.comboBoxListPartStorage.addItem(storage[0])
     self.db.close()
Beispiel #11
0
 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.comboBoxListEntryDepartment.addItem(department[0])
     self.db.close()
Beispiel #12
0
class SearchEditEntryApp(QDialog, searcheditentry_ui):
    def __init__(self, parent=None):
        super(SearchEditEntryApp, self).__init__(parent)
        self.setupUi(self)
        self.HandleButtonAction()

    # Method for Button action
    def HandleButtonAction(self):
        self.pushButtonSearchEditEntryIdSearch.clicked.connect(
            self.SearchEditEntry_search)

    def SearchEditEntry_search(self):
        search_id = self.lineSearchEditId.text()
        try:
            entry_id = int(search_id)  # Convert text into integer
        except Exception as error:
            self.error_popup("Input Error", "Please enter numbers only.")
        else:
            self.db = ConnectDatabase()
            self.cur = self.db.cursor()
            self.cur.execute('SAVEPOINT SP1')
            self.cur.execute(
                '''SELECT * FROM entry where id = %s''',
                [(entry_id, )])  # Check if entry id available in db
            fetch_data = self.cur.fetchone()
            if fetch_data is None:  # If returns None or Id not in database
                self.cur.execute('ROLLBACK TO SAVEPOINT SP1')
                self.error_popup("Invalid Input", "Entry not registered.")
            else:
                self.EditEntry_window(entry_id)
        self.db.close()
        self.close()

    # Method to open Edit Entry window
    def EditEntry_window(self, entry_id):
        self.apw = EditEntryApp(entry_id)
        self.apw.show()

    # 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_()
Beispiel #13
0
 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()
Beispiel #14
0
 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()
Beispiel #15
0
 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()
Beispiel #16
0
 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()
Beispiel #17
0
 def SearchEditPart_search(self):
     search_id = self.lineSearchEditId.text()
     try:
         part_id = int(search_id)  # Convert text into integer
     except Exception as error:
         self.error_popup("Input Error", "Please enter numbers only.")
     else:
         self.db = ConnectDatabase()
         self.cur = self.db.cursor()
         self.cur.execute('SAVEPOINT SP1')
         self.cur.execute('''SELECT * FROM part where id = %s''',
                          [(part_id, )])  # Check if part id available in db
         fetch_data = self.cur.fetchone()
         if fetch_data is None:  # If returns None or Id not in database
             self.cur.execute('ROLLBACK TO SAVEPOINT SP1')
             self.error_popup("Invalid Input", "Part not registered.")
         else:
             self.EditPart_window(part_id)
     self.db.close()
     self.close()
Beispiel #18
0
 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")
Beispiel #19
0
 def ListEntry_show(self):
     field_name = self.lineListEntryPartName.text()
     field_department = self.comboBoxListEntryDepartment.currentText()
     field_status = self.comboBoxListEntryStatus.currentText()
     search_name = '%{}%'.format(field_name)
     search_department = '%{}%'.format(field_department)
     search_status = '%{}%'.format(field_status)
     self.db = ConnectDatabase()
     self.cur = self.db.cursor()
     try:
         self.cur.execute(
             '''SELECT entry.id, entry.entry_date, part.part_name, part.part_department, 
         entry.entry_status, entry.entry_qty, entry.entry_employee, entry.entry_desc FROM entry JOIN part ON 
         entry.part_id = part.id WHERE part.part_name ILIKE %s AND part.part_department ILIKE %s AND 
         entry.entry_status ILIKE %s ORDER BY entry.id ASC''',
             (search_name, search_department, search_status))
         fetch_data = self.cur.fetchall()
     except Exception as error:
         self.error_popup("Duplicate Error", "Failed to connect database")
     else:
         if fetch_data is None:
             self.tableWidgetListEntry.setRowCount(0)
             self.error_popup("List Entry", "No records found!")
         else:
             self.tableWidgetListEntry.setRowCount(0)
             self.tableWidgetListEntry.insertRow(0)
             for row, form in enumerate(fetch_data):
                 for column, item in enumerate(form):
                     self.tableWidgetListEntry.setItem(
                         row, column, QTableWidgetItem(str(item)))
                     column += 1
                     row_position = self.tableWidgetListEntry.rowCount()
                     self.tableWidgetListEntry.insertRow(row_position)
                     self.tableWidgetListEntry.resizeColumnsToContents()
                     self.tableWidgetListEntry.horizontalHeader(
                     ).setSectionResizeMode(7, QHeaderView.Stretch)
     self.db.close()
Beispiel #20
0
 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()
Beispiel #21
0
class ListEntryApp(QDialog, listentry_ui):
    def __init__(self, parent=None):
        super(ListEntryApp, self).__init__(parent)
        self.setupUi(self)
        self.HandleButtonAction()
        self.ShowDepartment_custom()
        self.ShowStatus_entry()
        self.ClearDropDown()
        self.ListEntry_show()

    # Method for Button action
    def HandleButtonAction(self):
        self.pushButtonListEntrySearch.clicked.connect(self.ListEntry_show)
        self.pushButtonListEntryReset.clicked.connect(self.ListEntry_reset)

    # Method to set empty value in drop-down field
    def ClearDropDown(self):
        self.comboBoxListEntryDepartment.setCurrentText('')
        self.comboBoxListEntryStatus.setCurrentText('')

    # 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.comboBoxListEntryDepartment.addItem(department[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.comboBoxListEntryStatus.addItem(status[0])
        self.db.close()

    # Method to show list of entry
    def ListEntry_show(self):
        field_name = self.lineListEntryPartName.text()
        field_department = self.comboBoxListEntryDepartment.currentText()
        field_status = self.comboBoxListEntryStatus.currentText()
        search_name = '%{}%'.format(field_name)
        search_department = '%{}%'.format(field_department)
        search_status = '%{}%'.format(field_status)
        self.db = ConnectDatabase()
        self.cur = self.db.cursor()
        try:
            self.cur.execute(
                '''SELECT entry.id, entry.entry_date, part.part_name, part.part_department, 
            entry.entry_status, entry.entry_qty, entry.entry_employee, entry.entry_desc FROM entry JOIN part ON 
            entry.part_id = part.id WHERE part.part_name ILIKE %s AND part.part_department ILIKE %s AND 
            entry.entry_status ILIKE %s ORDER BY entry.id ASC''',
                (search_name, search_department, search_status))
            fetch_data = self.cur.fetchall()
        except Exception as error:
            self.error_popup("Duplicate Error", "Failed to connect database")
        else:
            if fetch_data is None:
                self.tableWidgetListEntry.setRowCount(0)
                self.error_popup("List Entry", "No records found!")
            else:
                self.tableWidgetListEntry.setRowCount(0)
                self.tableWidgetListEntry.insertRow(0)
                for row, form in enumerate(fetch_data):
                    for column, item in enumerate(form):
                        self.tableWidgetListEntry.setItem(
                            row, column, QTableWidgetItem(str(item)))
                        column += 1
                        row_position = self.tableWidgetListEntry.rowCount()
                        self.tableWidgetListEntry.insertRow(row_position)
                        self.tableWidgetListEntry.resizeColumnsToContents()
                        self.tableWidgetListEntry.horizontalHeader(
                        ).setSectionResizeMode(7, QHeaderView.Stretch)
        self.db.close()

    # Method to reset list of entry
    def ListEntry_reset(self):
        self.ClearDropDown()
        self.lineListEntryPartName.clear()
        self.ListEntry_show()

    # 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_()
Beispiel #22
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
Beispiel #23
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
Beispiel #24
0
class ListPartApp(QDialog, listpart_ui):
    def __init__(self, parent=None):
        super(ListPartApp, self).__init__(parent)
        self.setupUi(self)
        self.HandleButtonAction()
        self.ShowDepartment_custom()
        self.ShowCategory_custom()
        self.ShowStorage_custom()
        self.ClearDropDown()
        self.ListPart_show()

    # Method for Button action
    def HandleButtonAction(self):
        self.pushButtonListPartSearch.clicked.connect(self.ListPart_show)
        self.pushButtonListPartReset.clicked.connect(self.ListPart_reset)

    # Method to set empty value in drop-down field
    def ClearDropDown(self):
        self.comboBoxListPartDepartment.setCurrentText('')
        self.comboBoxListPartCategory.setCurrentText('')
        self.comboBoxListPartStorage.setCurrentText('')
        # self.comboBoxListPartStockLevel.setCurrentText('')

    # 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.comboBoxListPartDepartment.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.comboBoxListPartCategory.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.comboBoxListPartStorage.addItem(storage[0])
        self.db.close()

    # Method to show list of part
    def ListPart_show(self):
        field_name = self.lineListPartName.text()
        field_department = self.comboBoxListPartDepartment.currentText()
        field_category = self.comboBoxListPartCategory.currentText()
        field_storage = self.comboBoxListPartStorage.currentText()
        # field_stocklevel = self.comboBoxListPartStockLevel.currentText()
        search_name = '%{}%'.format(field_name)
        search_department = '%{}%'.format(field_department)
        search_category = '%{}%'.format(field_category)
        search_storage = '%{}%'.format(field_storage)
        # search_stocklevel = '%{}%'.format(field_stocklevel)

        self.db = ConnectDatabase()
        self.cur = self.db.cursor()
        try:
            self.cur.execute(
                '''SELECT part.id, part.part_name, part.part_department, part.part_manufacturer, part.part_model, part.part_category, part.part_storage, part.part_stocklimit, 
            SUM ( ( CASE 
                    WHEN entry.entry_status = 'In' THEN 1 
                    ELSE -1 END)*entry.entry_qty) AS stock_quantity,
            CASE 
                WHEN SUM( (CASE  WHEN entry.entry_status = 'In' THEN 1 ELSE -1 END)* entry.entry_qty) < part.part_stocklimit/2 THEN 'Critical'
                WHEN SUM( (CASE  WHEN entry.entry_status = 'In' THEN 1 ELSE -1 END)* entry.entry_qty) < part.part_stocklimit THEN 'Low'
                WHEN SUM( (CASE  WHEN entry.entry_status = 'In' THEN 1 ELSE -1 END)* entry.entry_qty) >= part.part_stocklimit THEN 'Normal'
                WHEN SUM( (CASE  WHEN entry.entry_status = 'In' THEN 1 ELSE -1 END)* entry.entry_qty) > part.part_stocklimit*2 THEN 'High'
                ELSE 'Normal' END AS stock_level,
            part.part_description
            FROM part 
            INNER JOIN entry ON entry.part_id = part.id 
            GROUP BY part.id
            HAVING part.part_name ILIKE %s AND part.part_department ILIKE %s AND part.part_category ILIKE %s AND part.part_storage ILIKE %s ORDER BY part.id ASC''',
                (search_name, search_department, search_category,
                 search_storage))
            fetch_data = self.cur.fetchall()
        except Exception as error:
            print(error)
            self.error_popup("Duplicate Error", str(error))
        else:
            if fetch_data is None:
                self.tableWidgetListPart.setRowCount(0)
                self.error_popup("List Part", "No records found!")
            else:
                self.tableWidgetListPart.horizontalHeader(
                ).setSectionResizeMode(0, 20)
                self.tableWidgetListPart.horizontalHeader(
                ).setSectionResizeMode(1, 20)
                self.tableWidgetListPart.setRowCount(0)
                self.tableWidgetListPart.insertRow(0)
                for row, form in enumerate(fetch_data):
                    for column, item in enumerate(form):
                        self.tableWidgetListPart.setItem(
                            row, column, QTableWidgetItem(str(item)))
                        column += 1
                        row_position = self.tableWidgetListPart.rowCount()
                        self.tableWidgetListPart.insertRow(row_position)
                        self.tableWidgetListPart.resizeColumnsToContents()
                        self.tableWidgetListPart.horizontalHeader(
                        ).setSectionResizeMode(10, QHeaderView.Stretch)
        self.db.close()

    # Method to reset list of entry
    def ListPart_reset(self):
        self.ClearDropDown()
        self.lineListPartName.clear()
        self.ListPart_show()

    # 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_()
Beispiel #25
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_()
Beispiel #26
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_()
Beispiel #27
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_()