def add(self): """This method is automatically called on clicking 'Add Designation' button This first checks if all inputs are valid. If any of the inputs are invalid, error message is shown for the first invalid input, else a new Designation object is created from available info. This Employee object is then passed to addEmployee() function of DatabaseManager which adds a new designation record in the database. """ valid = True for i in range(len(self.inputs)): if not self.inputs[i].isValid(): QMessageBox(QMessageBox.Information, "Error", self.inputs[i].getErrorMessage(), parent=self).exec_() valid = False break if valid: desg = Designation(self.designation.text(), self.da.text(), self.hra.text(), self.ta.text(), self.it.text(), self.pt.text()) try: Database.getdb().addDesignation(desg) QMessageBox(QMessageBox.NoIcon, "Success", "Designation added successfully", parent=self).exec_() self.goBack() except mysql.connector.Error as e: ShowMysqlError(e, self)
def changeDetails(self): origDesig = self.chooseDesignation.currentText() valid = True if len(origDesig) == 0: QtGui.QMessageBox(QtGui.QMessageBox.Information, "Error", "Please select a Designation to edit!", parent=self).exec_() valid = False else: for i in range(len(self.inputs)): if not self.inputs[i].isValid(): QtGui.QMessageBox(QtGui.QMessageBox.Information, "Error", self.inputs[i].getErrorMessage(), parent=self).exec_() valid = False break if valid: desig = Designation(self.designation.text(), self.da.text(), self.hra.text(), self.ta.text(), self.it.text(), self.pt.text()) try: Database.getdb().editDesignationInfo(desig, origDesig) self.loadDesignations() self.clearInfo() except mysql.connector.Error as e: ShowMysqlError(e, self) return QtGui.QMessageBox(QtGui.QMessageBox.NoIcon, "Success", "Designation edited successfully", parent=self).exec_()
def getDesignationInfo(self, designation): """Get designation info for given designation name Args: designation (str): Name of the designation who's information is required Returns: Designation: Designation object representing designation with given name """ command = "SELECT * FROM " + self.designationTableName + " WHERE designation = %s" self.mycursor.execute(command, (designation, )) res = self.mycursor.fetchone() if res is None: return None return Designation(*res)
def calculate(self): """Automatically called on clicking calculate button""" if self.__emp is None: QMessageBox(QMessageBox.Information, "Error", "Please select an employee!", parent=self).exec_() else: if self.__parent is not None: self.__desig = Designation(self.__desig.designation, self.da_percent.text(), self.hra_percent.text(), self.ta_percent.text(), self.it_percent.text(), self.pt_percent.text()) salary = Salary(self.__emp, self.__desig, self.month.currentText(), self.year.text()) self.__parent.gotoPage("Result", salary)