Exemplo n.º 1
0
    def saveTradableGoodType(self):
        ''' Saves newly created data to database '''

        # get the data entered by user
        mytradablegood = self.txtTradableGoodType.text()
        mymeasuringunit = self.txtTradableGoodMeasuringUnit.text()
                        	
	# check if record exists
	query = '''SELECT tradablegoodtype, unitofmeasure FROM setup_tradablegoods WHERE tradablegoodtype='%s' ''' % (mytradablegood)    
		
	p = GenericDBOP(query)
        recordset = p.runSelectQuery()

	numrows = 0		
	for row in recordset:
            numrows = numrows + 1
				      	
            if numrows == 0:
			
		query = '''INSERT INTO setup_tradablegoods(tradablegoodtype, unitofmeasure) 
                     		VALUES('%s','%s')''' % (mytradablegood, mymeasuringunit)
            else:
		query = '''UPDATE setup_tradablegoods SET tradablegoodtype='%s', unitofmeasure='%s'
                     		WHERE tradablegoodtype='%s' ''' % (mytradablegood, mymeasuringunit, mytradablegood)
    
        # execute query and commit changes
        temp = GenericDBOP(query)
        recordset = temp.runUpdateQuery()
Exemplo n.º 2
0
    def deleteTradableGoodType(self):
	''' Deletes record from database '''

       	# get the data entered by user
       	mytradablegood = self.txtTradableGoodType.text()		
        	
	# check if record exists
	query = '''SELECT tradablegoodtype, unitofmeasure FROM setup_tradablegoods WHERE tradablegoodtype='%s' ''' % (mytradablegood)
		
	p = GenericDBOP(query)
        recordset = p.runSelectQuery()
	numrows = 0		
	for row in recordset:
		numrows = numrows + 1

	if numrows <> 0:
			
		query = '''DELETE FROM setup_tradablegoods WHERE tradablegoodtype='%s' ''' % (mytradablegood)

		# execute query and commit changes
       		temp = GenericDBOP(query)
                recordset = temp.runUpdateQuery()

			
       		#self.cmbKCalories.clear()
			
		#refresh categories list
		self.getAssetCategories()			
			
	else:
		QMessageBox.information(self, 'Delete TradableGood Type', "Record not found")