Exemple #1
0
    def save(self):
        valid = True
        if len(self.id.currentText()) == 0:
            QMessageBox(QMessageBox.Information,
                        "Error",
                        "Please select name and ID!",
                        parent=self).exec_()
            valid = False
        else:
            for i in range(len(self.inputs)):
                if not self.inputs[i].isValid():
                    valid = False
                    QtGui.QMessageBox(QtGui.QMessageBox.Information,
                                      "Error",
                                      self.inputs[i].getErrorMessage(),
                                      parent=self).exec_()
                    break

        if valid:
            emp = Employee(self.id.currentText(), self.nameEdit.text(),
                           self.designation.currentText(),
                           self.originalPay.text(),
                           self.originalPayGrade.text(), self.DOJ.getDate(),
                           self.pan.text())
            try:
                Database.getdb().editEmployee(emp)
            except mysql.connector.Error as e:
                ShowMysqlError(e, self)
                return

            QMessageBox(QMessageBox.NoIcon,
                        "Success",
                        "Employee edited successfully",
                        parent=self).exec_()
    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)
Exemple #3
0
    def add(self):
        """This method is automatically called on clicking 'Add Employee' 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 Employee object is created from available info.
        This Employee object is then passed to addEmployee() function of DatabaseManager which adds
        a new employee record in the database.
        """

        valid = True
        for i in range(len(self.inputs)):
            if not self.inputs[i].isValid():
                valid = False
                QtGui.QMessageBox(QtGui.QMessageBox.Information, "Error", self.inputs[i].getErrorMessage(),
                                        parent=self).exec_()
                break

        if valid:
            emp = Employee(self.id.text(),
                           self.name.text(),
                           self.designation.currentText(),
                           self.originalPay.text(),
                           self.gradePay.text(),
                           self.DOJ.getDate(),
                           self.pan.text())
            try:
                Database.getdb().addEmployee(emp)
                QtGui.QMessageBox(QtGui.QMessageBox.NoIcon, "Success", "Employee added successfully",
                                  parent=self).exec_()
                self.goBack()
            except mysql.connector.Error as e:
                ShowMysqlError(e, self)
                return
Exemple #4
0
    def gotoPage(self, name, *args):
        """A method to open page corresponding to given name

        This method takes the page ``name`` and passes it to the pages dictionary to get corresponding class and
        creates a new instance of the class. The ``*args`` (if any) are passed to the constructor of that class.
        This newly created page is then added to the ``QStackedWidget`` and this new page is set as current page.

        As all pages are initialized in this class, this class is passed as an argument in the constructor
        and stored in __parent attribute. So, now we can use ``self.__parent.gotoPage()`` to access
        this ``gotoPage()`` from any class. Thus we now have the ability to go from any page to any page.
        Also, similarly they can use ``self.__parent.goBack()`` to access ``goBack()`` method of this class.

        Args:
            name (str): Name of the page
            *args: variable length argument list

        """
        print "Goto page", name, ";   args=", args
        try:
            if len(args) == 0:
                newPage = self.pages[name](self)
            else:
                newPage = self.pages[name](self, *args)
            self.widgetStack.addWidget(newPage)
            self.widgetStack.setCurrentWidget(newPage)
            try:
                self.setTitle(newPage.title)
            except AttributeError as e:
                self.setTitle("")

        except mysql.connector.Error as e:
            ShowMysqlError(e, self)
Exemple #5
0
 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_()
Exemple #6
0
 def doLogin(self):
     try:
         if DatabaseManager.db.checkLogin(self.username.text(),
                                          self.password.text()):
             if self._parent is not None:
                 self._parent.gotoPage("Home")
         else:
             QtGui.QMessageBox.warning(self, 'Error',
                                       'Bad user or password')
     except mysql.connector.Error as e:
         ShowMysqlError(e, self)
Exemple #7
0
 def printSlip(self):
     try:
         Database.getdb().saveSalary(self.salary)
         printPaySlip(*self.salary.result())
     except mysql.connector.Error as e:
         if e.errno == errorcode.ER_DUP_ENTRY:
             choice = QtGui.QMessageBox.question(
                 self, 'Replace?',
                 "Salary calculation of " + self.salary.id + " for " +
                 self.salary.month + ", " + str(self.salary.year) +
                 " already exists! Do you want to replace it?",
                 QtGui.QMessageBox.Yes | QtGui.QMessageBox.No)
             if choice == QtGui.QMessageBox.Yes:
                 try:
                     Database.getdb().replaceSalary(self.salary)
                     printPaySlip(*self.salary.result())
                 except mysql.connector.Error as e:
                     ShowMysqlError(e)
         else:
             ShowMysqlError(e)
Exemple #8
0
 def gotoPage(self, name, args=()):
     print "Goto page", name, ";   args=", args
     try:
         if len(args) == 0:
             newPage = self.pages[name](self)
         else:
             newPage = self.pages[name](self, *args)
         self.widgetStack.addWidget(newPage)
         self.widgetStack.setCurrentWidget(newPage)
     except mysql.connector.Error as e:
         ShowMysqlError(e, self)
Exemple #9
0
    def goBack(self):
        print "Going Back"
        try:
            currentIndex = self.widgetStack.currentIndex()
            if currentIndex > 0:
                currentPage = self.widgetStack.currentWidget()
                self.widgetStack.setCurrentIndex(currentIndex-1)

                currentPage.deleteLater()
                self.widgetStack.removeWidget(currentPage)

        except mysql.connector.Error as e:
            ShowMysqlError(e, self)
Exemple #10
0
    def goBack(self):
        """Method to go back to previous page

        This method sets the index of ``QWidgetStack`` used in this class to ``currentIndex - 1`` (hence effectively
        going to previous page). It then removes the previous page from the stack and deletes it.
        """
        print "Going Back"
        try:
            currentIndex = self.widgetStack.currentIndex()
            if currentIndex > 0:
                currentPage = self.widgetStack.currentWidget()
                self.widgetStack.setCurrentIndex(currentIndex - 1)
                try:
                    self.setTitle(self.widgetStack.currentWidget().title)
                except AttributeError as e:
                    self.setTitle("")

                currentPage.deleteLater()
                self.widgetStack.removeWidget(currentPage)

        except mysql.connector.Error as e:
            ShowMysqlError(e, self)
    def add(self):
        id = self.id.text()
        name = self.name.text()
        designation = self.designation.currentText()
        originalPay = self.originalPay.text()
        originalPayGrade = self.originalPayGrade.text()
        doj = self.DOJ.getDate()
        pan = self.pan.text()

        if "" in [id, name, designation, originalPay, originalPayGrade, doj, pan]:
            msg = QMessageBox(QMessageBox.Information, "Error", "Please enter all the information!", parent=self)
            msg.exec_()
        else:
            doj = "%4d-%02d-%02d" % (doj.year(), doj.month(), doj.day())
            print id, name, designation, originalPay, originalPayGrade, doj, pan

            try:
                DatabaseManager.db.addEmployee(id, name, designation, float(originalPay), float(originalPayGrade), doj, pan)
            except mysql.connector.Error as e:
                ShowMysqlError(e, self)
                return

            QMessageBox(QMessageBox.NoIcon, "Success", "Employee added successfully", parent=self).exec_()
Exemple #12
0
        #                  username="******",
        #                  password="******")

        Database.connect(host="remotemysql.com",
                         username="******",
                         password="******",
                         databaseName="ll703lm6tX")

        w = MainWindow()

        styleSheetFile = QtCore.QFile("styleSheet/flatStyleSheet.css")
        styleSheetFile.open(QtCore.QIODevice.ReadOnly)
        w.setStyleSheet(str(styleSheetFile.readAll()))

        w.show()

        splash.finish(w)

    except mysql.connector.Error as e:
        splash.close()
        ShowMysqlError(e)
        sys.exit()

    # except Exception as e:
    #     splash.close()
    #     msg = QMessageBox(QMessageBox.Critical, "Error", "Unexpected error occured!\n" + str(e))
    #     msg.exec_()
    #     sys.exit()

    sys.exit(app.exec_())