class AllManufactersWindow(QFrame):
	def __init__(self):
		QFrame.__init__(self)
		self.ui = Ui_all_manufacters_form()
	
		self.ui.setupUi(self)
		#self.manufacters = query_session.query(Manufacter).all()
		self.drawTable()
		QObject.connect(self.ui.add_manufacter_btn, SIGNAL("clicked()"), self.showNewManufacterForm)
		QObject.connect(self.ui.del_manufacter_btn, SIGNAL("clicked()"), self.delManufacter)
	
	def drawTable(self):
		self.manufacters = query_session.query(Manufacter).all()
		self.ui.manufacters_table.clear()
		self.ui.manufacters_table.setRowCount(1)
		self.ui.manufacters_table.setColumnCount(3)
		self.ui.manufacters_table.setHorizontalHeaderLabels([QString.fromUtf8('Номер'), QString.fromUtf8('Название'), QString.fromUtf8('Страна')])
		self.ui.manufacters_table.resizeColumnsToContents()
		
		for manufacter in self.manufacters:
			data = []
			data.append(str(manufacter.id))
			data.append(manufacter.name)
			data.append(manufacter.country)
			for i in range(0,3):	
				tableitem = QTableWidgetItem()
				tableitem.setText(data[i])
				tableitem.font = QFont("Arial", 10)
				tableitem.font.setBold(True)
				tableitem.textcolor = QColor("black")
				self.ui.manufacters_table.setItem(self.ui.manufacters_table.rowCount() - 1,i,tableitem)
			self.ui.manufacters_table.setRowCount(self.ui.manufacters_table.rowCount()+1)
		self.ui.manufacters_table.resizeColumnsToContents()
				
	def showNewManufacterForm(self):
		self.new_manufacter_form = NewManufacterForm(self)
		QObject.connect(self.new_manufacter_form, SIGNAL("manufacterAdded()"), self.drawTable)
		self.new_manufacter_form.setWindowModality(2)
		self.new_manufacter_form.show()
		
		
	def delManufacter(self):
		row = self.ui.manufacters_table.currentRow()
		id_for_delete = int(self.ui.manufacters_table.item(row, 0).text())
		manufacter_for_delete = query_session.query(Manufacter).filter_by(id=id_for_delete).one()
		s = Session()
		s.delete(manufacter_for_delete)
		s.commit()
		s.close
		self.drawTable()
예제 #2
0
	def setManufacter(self,num):
		c = self.ui.manufacter_combo.count()
		if (num < self.ui.manufacter_combo.count() - 1):
			manufacter = query_session.query(Manufacter).filter_by(name=unicode(self.ui.manufacter_combo.itemText(num))).one()
			self.manufacter = manufacter
		else:
			self.new_manufacter_form = NewManufacterForm(self)
			self.new_manufacter_form.setWindowModality(2)
			self.new_manufacter_form.show()
			QObject.connect(self.new_manufacter_form, SIGNAL("manufacterAdded()"), self.drawManufacterCombo)
예제 #3
0
class NewDrugForm(QFrame):
	def __init__(self):
		QFrame.__init__(self)
		self.ui = Ui_new_drug_form()
		self.ui.setupUi(self)
		
		QObject.connect(self.ui.ok_btn, SIGNAL("clicked()"), self.addDrug)
		self.drawManufacterCombo()
		#self.setManufacter(0)
		
		
	def addDrug(self):
		drug = Drug(str(self.ui.drug_name.text().toUtf8()), self.manufacter, str(self.ui.serial_number.text().toUtf8()), _date_from_str(self.ui.best_before.text()), float(self.ui.price.text().toUtf8()))
		s = Session()
		s.add(drug)
		s.commit()
		s.close()
		self.emit(SIGNAL("drugCreated()"))
		self.close()
		
		
	def drawManufacterCombo(self):
		combo = self.ui.manufacter_combo
		items = self.manufacters = query_session.query(Manufacter).all()
		combo.clear()
		for item in items:
			combo.addItem(item.name)
		combo.addItem(QString.fromUtf8('Новый производитель'))
		QObject.connect(self.ui.manufacter_combo, SIGNAL("currentIndexChanged(int)"), self.setManufacter)
		self.setManufacter(0)
	
	
	def setManufacter(self,num):
		c = self.ui.manufacter_combo.count()
		if (num < self.ui.manufacter_combo.count() - 1):
			manufacter = query_session.query(Manufacter).filter_by(name=unicode(self.ui.manufacter_combo.itemText(num))).one()
			self.manufacter = manufacter
		else:
			self.new_manufacter_form = NewManufacterForm(self)
			self.new_manufacter_form.setWindowModality(2)
			self.new_manufacter_form.show()
			QObject.connect(self.new_manufacter_form, SIGNAL("manufacterAdded()"), self.drawManufacterCombo)
	def showNewManufacterForm(self):
		self.new_manufacter_form = NewManufacterForm(self)
		QObject.connect(self.new_manufacter_form, SIGNAL("manufacterAdded()"), self.drawTable)
		self.new_manufacter_form.setWindowModality(2)
		self.new_manufacter_form.show()