class CRBPrintDialog(CSimplePrintDialog): u"""Выбор элемента из справочника var - код элемента или объект класса, если этот класс задан""" def __init__(self, title, table, class_=None, combo=None, default=None): CSimplePrintDialog.__init__(self, title, 200, 100, default) self.class_ = class_ if combo: self.comboBox = combo(self) else: self.comboBox = CRBComboBox(self) self.comboBox.setTable(table) self.comboBox.setObjectName("comboBox") self.verticalLayout.insertWidget(0, self.comboBox) def getId(self): return self.comboBox.value() def getCode(self): return self.comboBox.code() def getName(self): return self.comboBox.model().getName(self.comboBox.currentIndex()) def saveData(self): if self.class_: self.var = self.context.getInstance(self.class_, self.getId()) else: self.var = self.getCode() return True
class CSamplingApplyDialog(CDialogBase): def __init__(self, parent, tissueExternalId, equipmentId, testGroupVisible=False, autoEquipment=False): CDialogBase.__init__(self, parent) self.vLayout = QtGui.QVBoxLayout() self.lblExternalId = QtGui.QLabel(u'Идентификатор', self) self.vLayout.addWidget(self.lblExternalId) self.edtExternalId = QtGui.QLineEdit(tissueExternalId, self) self.vLayout.addWidget(self.edtExternalId) self.lblEquipment = QtGui.QLabel(u'Оборудование', self) self.vLayout.addWidget(self.lblEquipment) self.cmbEquipment = CRBComboBox(self) specialValues = ( (-1, '-', u'Автоопределение оборудования'), ) if autoEquipment else None self.cmbEquipment.setTable('rbEquipment', addNone=True, specialValues=specialValues) self.cmbEquipment.setValue(equipmentId) self.vLayout.addWidget(self.cmbEquipment) self.lblTestGroup = QtGui.QLabel(u'Группа тестов', self) self.vLayout.addWidget(self.lblTestGroup) self.cmbTestGroup = CRBComboBox(self) self.cmbTestGroup.setTable('rbTestGroup', addNone=True) self.vLayout.addWidget(self.cmbTestGroup) self.lblExternalId.setVisible(not testGroupVisible) self.edtExternalId.setVisible(not testGroupVisible) self.lblTestGroup.setVisible(testGroupVisible) self.cmbTestGroup.setVisible(testGroupVisible) self.buttonBox = QtGui.QDialogButtonBox(self) self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Ok | QtGui.QDialogButtonBox.Cancel) self.vLayout.addWidget(self.buttonBox) self.setLayout(self.vLayout) self.connect(self.buttonBox, QtCore.SIGNAL('accepted()'), self.accept) self.connect(self.buttonBox, QtCore.SIGNAL('rejected()'), self.reject) self._tissueJournalId = None self._tissueTypeId = None self._datetimeTaken = None self.setWindowTitle(u'Регистрация проб') def setSettings(self, tissueJournalId, tissueTypeId, datetimeTaken): self._tissueJournalId = tissueJournalId self._tissueTypeId = tissueTypeId self._datetimeTaken = datetimeTaken def checkDataEntered(self): result = True result = result and self.checkExternalId() return result def saveData(self): return self.checkDataEntered() def checkExternalId(self): result = True if self.edtExternalId.isVisible(): message = u'' externalId = forceStringEx(self.edtExternalId.text()) if bool(externalId): if not externalId.isdigit(): result = False message = u'корректный идентификатор' else: result = False message = u'идентификатор' result = result or self.checkInputMessage(message, False, self.edtExternalId) result = result and self.checkSelectedToSave( externalId, self._tissueJournalId) return result def checkSelectedToSave(self, externalId, tissueJournalId): db = QtGui.qApp.db tableProbe = db.table('Probe') tableTissueJournal = db.table('TakenTissueJournal') cond = [ tableProbe['takenTissueJournal_id'].ne(tissueJournalId), tableProbe['externalId'].eq(externalId), tableTissueJournal['tissueType_id'].eq(self._tissueTypeId), tableTissueJournal['deleted'].eq(0) ] dateCond = getExternalIdDateCond(self._tissueTypeId, self._datetimeTaken) if dateCond: cond.append(dateCond) queryTable = tableProbe.innerJoin( tableTissueJournal, tableTissueJournal['id'].eq(tableProbe['takenTissueJournal_id'])) record = QtGui.qApp.db.getRecordEx(queryTable, tableProbe['id'].name(), cond) if record and forceRef(record.value('id')): return self.checkInputMessage( u'другой идентификатор.\nТакой уже существует', False, self.edtExternalId) return True def externalId(self): result = forceStringEx(self.edtExternalId.text()).lstrip('0') return (6 - len(result)) * '0' + result def equipmentId(self): return self.cmbEquipment.value() def testGroupId(self): return self.cmbTestGroup.value()