Пример #1
0
	def _checkAndReply(self, aMsg):
		aMsg = aMsg.strip()
		if aMsg == serverproperties.CHOICE_SEND_KEY:
			print "[%s] Receiving key" % serverproperties._getTime()
			msg = self._recv(False).strip()
			print "[%s] Received key" % serverproperties._getTime()
			(pk, esk) = ast.literal_eval(msg)
			FHC.writeKeyToFile("None", pk, esk)
			self.m_clientSock.send(serverproperties.SERVER_OP_SUCCESS+"\n")
		
		elif aMsg == serverproperties.CHOICE_INSERT:
			print "[%s] Receiving Record" % serverproperties._getTime()
			msg = self._recv(False).strip()
			print "[%s] Received Record" % serverproperties._getTime()
			r = ast.literal_eval(msg)
			aRecord = record.recordDTO(r)
			controller.insertRecord(aRecord)
			self.m_clientSock.send(serverproperties.SERVER_OP_SUCCESS+"\n")
		
		elif aMsg == serverproperties.CHOICE_CHECK_ROLL:
			print "[%s] Receiving Query" % serverproperties._getTime()
			msg = self._recv().strip()
			print "[%s] Received Query" % serverproperties._getTime()
			rid=controller.getIdByRollNo(msg)
			self.m_clientSock.send(str(rid)+"\n")
			time.sleep(1)
			self.m_clientSock.send(serverproperties.SERVER_OP_SUCCESS+"\n")
		
		elif aMsg == serverproperties.CHOICE_GET_ROW_BY_ID:
			msg = self._recv()
			if msg is not None:
				dto = controller.getRowById(int(msg.strip()))
			if not self.m_die:			
				try:
					self.m_clientSock.send(repr(dto)+'\n')
				except:
					print "[%s] %s %s" % (serverproperties._getTime(),serverproperties.SERVER_ERR_CANNOT_SEND,self.m_server.m_dict[self.m_clientSock])				
					self.m_die = True
			time.sleep(1)
			self.m_clientSock.send(serverproperties.SERVER_OP_SUCCESS+"\n")
		
		elif aMsg == serverproperties.CHOICE_INCREMENT_MARKS_BY_ID:
			pass
		
		elif aMsg == serverproperties.CHOICE_EVAL_TOTAL:
			rows = controller.getAllRows()
			for row in rows:
				mark1 = row.getMarks1()
				mark2 = row.getMarks2()
				weight1 = row.getWeight1()
				weight2 = row.getWeight2()
				total = FHC.do4BitWeightedSum(mark1, weight1, mark2, weight2)
				row.setTotal(total)
				controller.updateStudentRecord(row)
			self.m_clientSock.send(serverproperties.SERVER_OP_SUCCESS+"\n")
		
		elif aMsg == serverproperties.SERVER_CLIENT_QUIT_MSG:
			self._checkQuit(aMsg)
Пример #2
0
#! /usr/bin/python

import controller
import record
if __name__ == "__main__":
	print "All Rows: ",controller.getAllRows(),"\n\n"
	print "ID for roll 321: ",controller.getIdByRollNo("321"),"\n\n"
	print "Row for ID 1: ",controller.getRowById(1),"\n\n"
	dto = record.recordDTO()
	dto.setId(1)
	dto.setRollNo('567')
	dto.setMarks1('456')
	dto.setMarks2('56')
	dto.setWeight1('6')
	dto.setWeight2('4')
	print "Rows Updated for ID 1: ",controller.updateStudentRecord(dto),"\n\n"

	dto.setRollNo('765')
	dto.setMarks1('92')
	dto.setWeight1('5')
	dto.setMarks2('45')
	dto.setWeight2('5')
	#print "Rows Inserted: ",controller.insertRecord(dto),"\n\n"

	print "Rows Deleted for ID 5: ",controller.deleteRecordById(3),"\n\n"