Пример #1
0
	def toggleChecked(self, indexes):
		checkedRecords = []
		unCheckedRecords = []

		for index in indexes:
			recordId = self.index(index.row(), enum.kRecords_RecordId).data()
			if self.index(index.row(), enum.kRecords_Checked).data(QtCore.Qt.CheckStateRole) == QtCore.Qt.Checked:
				checkedRecords.append(recordId)
			else:
				unCheckedRecords.append(recordId)

		with db.transaction():
			if unCheckedRecords:
				query = QtSql.QSqlQuery()
				query.prepare("""
					UPDATE records
					   SET checked=1, checkdate=CURRENT_TIMESTAMP
					 WHERE recordid IN (?)
					""")
				query.addBindValue(unCheckedRecords)
				if not query.execBatch(QtSql.QSqlQuery.ValuesAsColumns):
					raise Exception(query.lastError().text())

			if checkedRecords:
				query = QtSql.QSqlQuery()
				query.prepare("""
					UPDATE records
					   SET checked=0, checkdate=NULL
					 WHERE recordid IN (?)
					""")
				query.addBindValue(checkedRecords)
				if not query.execBatch(QtSql.QSqlQuery.ValuesAsColumns):
					raise Exception(query.lastError().text())

		self.select()

		for index in indexes:
			checkedIndex = self.index(index.row(), enum.kRecords_Checked)
			self.dataChanged.emit(checkedIndex, checkedIndex)
Пример #2
0
    def __importRecords(self):
        """ Import selected rows to database
		"""

        if self.currencyComboBox.currentIndex() == -1:
            QtGui.QMessageBox.critical(self, 'Import Error',
                                       'Please select currency',
                                       QtGui.QMessageBox.Ok)
            return

        currencyCode = self.currencyComboBox.currentText()
        accountId, _ = self.accountTypeComboBox.itemData(
            self.accountTypeComboBox.currentIndex(), QtCore.Qt.UserRole)

        model = self.view.model()
        selectionModel = self.view.selectionModel()
        indexes = selectionModel.selectedRows()

        if len(indexes) == 0:
            return

        try:
            self.progressBar.setVisible(True)

            self.progressBar.setValue(0)
            self.progressBar.setMaximum(len(indexes))
            self.view.clearSelection()

            self.__importInProgress = True
            self.closeButton.setEnabled(False)
            self.selectAllButton.setEnabled(False)
            self.importCancelButton.setText('Cancel')
            self.importCancelButton.setEnabled(True)

            # Wrap the import in a transaction
            with db.transaction():
                for num, index in enumerate(indexes, 1):
                    model.saveRecord(accountId, currencyCode, index)
                    self.view.scrollTo(index,
                                       QtGui.QAbstractItemView.EnsureVisible)
                    self.__setCounters()
                    QtCore.QCoreApplication.processEvents()
                    self.progressBar.setValue(self.progressBar.value() + 1)

                    if self.__cancelImport:
                        raise UserCancelledException

                if num:
                    self.__dataSaved = True
                    if QtGui.QMessageBox.question(
                            self, 'Import',
                            'Imported %d records successfully' % num,
                            QtGui.QMessageBox.Save | QtGui.QMessageBox.Cancel
                    ) != QtGui.QMessageBox.Save:
                        # By raising here we will rollback the database transaction
                        raise UserCancelledException

        except UserCancelledException:
            self.__dataSaved = False
            model.reset()

        except Exception, exc:
            QtGui.QMessageBox.critical(self, 'Import Error', str(exc),
                                       QtGui.QMessageBox.Ok)
Пример #3
0
	def __importRecords(self):
		""" Import selected rows to database
		"""

		if self.currencyComboBox.currentIndex() == -1:
			QtGui.QMessageBox.critical(
				self,
				'Import Error',
				'Please select currency',
				QtGui.QMessageBox.Ok
			)
			return

		currencyCode = self.currencyComboBox.currentText()
		accountId, _ = self.accountTypeComboBox.itemData(self.accountTypeComboBox.currentIndex(), QtCore.Qt.UserRole)

		model = self.view.model()
		selectionModel = self.view.selectionModel()
		indexes = selectionModel.selectedRows()

		if len(indexes) == 0:
			return

		try:
			self.progressBar.setVisible(True)

			self.progressBar.setValue(0)
			self.progressBar.setMaximum(len(indexes))
			self.view.clearSelection()

			self.__importInProgress = True
			self.closeButton.setEnabled(False)
			self.selectAllButton.setEnabled(False)
			self.importCancelButton.setText('Cancel')
			self.importCancelButton.setEnabled(True)

			# Wrap the import in a transaction
			with db.transaction():
				for num, index in enumerate(indexes, 1):
					model.saveRecord(accountId, currencyCode, index)
					self.view.scrollTo(index, QtGui.QAbstractItemView.EnsureVisible)
					self.__setCounters()
					QtCore.QCoreApplication.processEvents()
					self.progressBar.setValue(self.progressBar.value() +1)

					if self.__cancelImport:
						raise UserCancelledException

				if num:
					self.__dataSaved = True
					if QtGui.QMessageBox.question(
						self, 'Import', 'Imported %d records successfully' % num,
						QtGui.QMessageBox.Save|QtGui.QMessageBox.Cancel) != QtGui.QMessageBox.Save:
						# By raising here we will rollback the database transaction
						raise UserCancelledException

		except UserCancelledException:
			self.__dataSaved = False
			model.reset()

		except Exception, exc:
			QtGui.QMessageBox.critical(self, 'Import Error', str(exc), QtGui.QMessageBox.Ok)