Пример #1
0
	def deleteById(id):
		emp=Ems_services.searchById(id)
		if emp==None:
			return False
		else:
			cnx=DBconnection.connect()
			cur=cnx.cursor()
			query="delete from empDetails where empId=%s"
			data=[]
			data.append(id)
			cur.execute(query,data)
			cnx.commit()
			cur.close()
			cnx.close()
			return True
Пример #2
0
	def getAllEmployees():
		emplist=[]
		cnx=DBconnection.connect()
		cur=cnx.cursor()
		query="select * from empDetails"
		cur.execute(query)
		tb=cur.fetchall()
		for row in tb:
			emp=Employee()
			emp.setId(int(row[0]))
			emp.setName(row[1])
			emp.setSalary(float(row[2]))
			emp.setAddress(row[3])
			emplist.append(emp)
		cur.close()
		cnx.close()
		return emplist
Пример #3
0
	def addEmployee(emp):
		result=False
		cnx=DBconnection.connect()
		cur=cnx.cursor()
		query="insert into empDetails values(%s,%s,%s,%s)"
		data=[]
		data.append(emp.getId())
		data.append(emp.getName())
		data.append(emp.getSalary())
		data.append(emp.getAddress())
		try:
			cur.execute(query,data)
		except:
			return False
		if (cur.rowcount==1):
			result=True
		cnx.commit()
		cur.close()
		cnx.close()
		return result
Пример #4
0
 def searchBySalRange(min, max):
     emplist = []
     cnx = DBconnection.connect()
     cur = cnx.cursor()
     query = "select * from empDetails_2 where empSalary>%s and empSalary<%s"
     data = []
     data.append(min)
     data.append(max)
     cur.execute(query, data)
     tb = cur.fetchall()
     for row in tb:
         emp = Employee()
         emp.setId(int(row[0]))
         emp.setName(row[1])
         emp.setSalary(float(row[2]))
         emp.setAddress(row[3])
         emplist.append(emp)
     cur.close()
     cnx.close()
     return emplist
Пример #5
0
	def searchById(id):
		cnx=DBconnection.connect()
		cur=cnx.cursor()
		query="select * from empDetails where empId=%s"
		data=[]
		data.append(id)
		cur.execute(query,data)
		tb=cur.fetchall()
		if cur.rowcount==0:
			cur.close()
			cnx.close()
			return None
		for row in tb:
			emp=Employee()
			emp.setId(int(row[0]))
			emp.setName(row[1])
			emp.setSalary(float(row[2]))
			emp.setAddress(row[3])
		cur.close()
		cnx.close()
		return emp