class RegisterWindow(QDialog, registerUi.Ui_Dialog): def __init__(self, parent=None): super(RegisterWindow, self).__init__(parent) self.setupUi(self) self.xlh = '' self.registerTime = time.time() self.getXlh() self.db = Dboperator() def getXlh(self): disk = printDisk() self.xlh = disk[0]['UUID'] self.lineEdit_xlh.setText(self.xlh) @pyqtSlot() def on_pb_esc_clicked(self): self.close() @pyqtSlot() def on_pb_ok_clicked(self): company = self.lineEdit_company.text() zcm = forzc(str.strip(self.lineEdit_xlh.text())) if company != '' and zcm != '': if str.strip(self.lineEdit_zcm.text()) == zcm: self.accept() qs = "update wis_sysSet set zcm = '%s', company = '%s', registerTime = %d" % ( zcm, company, self.registerTime) self.db.excuteSQl(qs) else: self.reject() else: QMessageBox.information(self, '提示', '公司名和注册码不能为空!', QMessageBox.Yes)
class RecordHandle: def __init__(self, dic): self.dic = dic self.db = Dboperator() def insertdb(self): jn = self.dic['body'] dtime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(int(jn['usec']) - 8 * 60 * 60)) per_id = jn['per_id'] sn = jn['sn'] qs = ''' insert into wis_recordsx values ('%s', '%s', %d,'%s', %d, '%s','%s', %d, %d, %d, %d,'%s','%s', %d) ''' % (jn['sequence'], jn['sn'], jn['usec'] - 8 * 60 * 60, dtime, int(jn['matched']), jn['per_id'], jn['name'], int(jn['role']), int(jn['hat']), int( jn['face_imgsize']), int( jn['model_imgsize']), jn['face_imgdata'], '', 0) self.db.excuteSQl(qs) qs = "select wis_faceDevice.location from wis_faceDevice where wis_faceDevice.deviceSn ='%s'" % sn inOrout = self.db.querySQL(qs).record(0).field('location').value() qs = "select wis_person.department from wis_person where wis_person.idNo = '%s'" % per_id departs = self.db.querySQL(qs) deName = departs.record(0).field('department').value() if inOrout == '入口设备': qs1 = "update wis_department set currentNum = currentNum + 1 where name = '%s'" % deName if inOrout == '出口设备': qs1 = "update wis_department set currentNum = currentNum - 1 where name = '%s'" % deName self.db.excuteSQl(qs1)
class ZjptDeviceWindow(QWidget, zjptUi.Ui_Form): def __init__(self, parent=None): super(ZjptDeviceWindow, self).__init__(parent) self.setupUi(self) self.db = Dboperator() self.load() def load(self): qs = "select * from wis_cdzjpt where id = '99'" current = self.db.querySQL(qs).record(0) self.le_deletePersonURL.setText(current.field('deletePersonURL').value()) self.le_downloadPersonURL.setText(current.field('downloadPersonURL').value()) self.le_feedbackURL.setText(current.field('feedbackURL').value()) self.le_uploadAttURL.setText(current.field('uploadAttURL').value()) self.le_uploadPersonURL.setText(current.field('uploadPersonURL').value()) def enableAll(self): self.le_uploadPersonURL.setEnabled(True) self.le_uploadAttURL.setEnabled(True) self.le_feedbackURL.setEnabled(True) self.le_downloadPersonURL.setEnabled(True) self.le_deletePersonURL.setEnabled(True) self.pb_save.setEnabled(True) def disableAll(self): self.le_uploadPersonURL.setEnabled(False) self.le_uploadAttURL.setEnabled(False) self.le_feedbackURL.setEnabled(False) self.le_downloadPersonURL.setEnabled(False) self.le_deletePersonURL.setEnabled(False) self.pb_save.setEnabled(False) @pyqtSlot() def on_pb_update_clicked(self): self.enableAll() @pyqtSlot() def on_pb_save_clicked(self): uploadPersonURL = self.le_uploadPersonURL.text() downloadPersonURL= self.le_downloadPersonURL.text() deletePersonURL = self.le_deletePersonURL.text() uploadAttURL = self.le_uploadAttURL.text() feedbackURL = self.le_feedbackURL.text() qs = "update wis_cdzjpt set uploadPersonURL = '%s', downloadPersonURL = '%s', deletePersonURL = '%s', uploadAttURL = '%s', feedbackURL = '%s'"%(uploadPersonURL,downloadPersonURL,deletePersonURL, uploadAttURL, feedbackURL) self.db.excuteSQl(qs) self.disableAll()
class OperatorWindow(QWidget, operatorUi.Ui_Form): def __init__(self, parent=None): super(OperatorWindow, self).__init__(parent) self.setupUi(self) self.db = Dboperator() self.data = None self.load() self.txtDisable() def txtEnable(self): """将输入框设置为可用""" self.le_qxz.setEnabled(True) self.le_name.setEnabled(True) self.le_password.setEnabled(True) self.pb_save.setEnabled(True) self.le_name.setFocus() self.pb_add.setEnabled(False) def txtDisable(self): """将输入框设置为不可用""" self.le_qxz.setEnabled(False) self.le_password.setEnabled(False) self.le_name.setEnabled(False) self.pb_save.setEnabled(False) self.pb_del.setEnabled(False) self.pb_update.setEnabled(False) def txtClear(self): """清除输入框内容""" self.le_qxz.clear() self.le_password.clear() self.le_name.clear() self.checkBox_isAdmin.setChecked(False) def load(self): """表格装载全部的数据""" qs = "select name as 操作员名称, password as 操作员密码, qxz as 权限组, case isAdmin when 1 then '管理员' else '普通人员' end as 是否管理员 from wis_operator" alldata = self.db.querySQL(qs) self.data = alldata self.tv_operator.setModel(self.data) delegate = MyDelegate() self.tv_operator.setItemDelegateForColumn(1, delegate) @pyqtSlot() def on_pb_add_clicked(self): """增加 按钮函数""" self.txtEnable() @pyqtSlot() def on_pb_update_clicked(self): """修改 按钮函数""" self.txtEnable() self.le_name.setEnabled(False) @pyqtSlot() def on_pb_esc_clicked(self): self.txtClear() self.pb_del.setEnabled(False) self.pb_update.setEnabled(False) self.pb_add.setEnabled(True) self.pb_save.setEnabled(False) @pyqtSlot() def on_pb_save_clicked(self): """保存 按钮函数""" name = self.le_name.text() password = self.le_password.text() qxz = self.le_qxz.text() isAdmin = 1 if self.checkBox_isAdmin.isChecked() else 0 if name != '' and password != '': qs = "select name as 操作员名称, password as 操作员密码, qxz as 权限组, case isAdmin when 1 then '管理员' else '普通人员' end as 是否管理员 from wis_operator where name = '%s'" % name data = self.db.querySQL(qs) if data.rowCount() == 0: qs = "INSERT INTO wis_operator VALUES('%s','%s','%s', %d)" % (name, password, qxz, isAdmin) self.db.excuteSQl(qs) self.load() self.txtClear() self.le_name.setFocus() else: QMessageBox.information(self, '提示', '操作员名称不能重复!', QMessageBox.Yes) self.txtClear() self.pb_del.setEnabled(False) self.pb_update.setEnabled(False) self.pb_add.setEnabled(True) self.pb_save.setEnabled(False) self.txtDisable() else: QMessageBox.information(self, '提示', '人员名称和密码不能为空!', QMessageBox.Yes) self.txtClear() self.pb_del.setEnabled(False) self.pb_update.setEnabled(False) self.pb_add.setEnabled(True) self.pb_save.setEnabled(False) self.txtDisable() @pyqtSlot(QModelIndex) def on_tv_operator_clicked(self, QModelIndex): """选中表格中一行的处理函数""" rowID = self.tv_operator.currentIndex().row() name = self.data.index(rowID, 0).data() self.le_name.setText(name) self.le_password.setText(self.data.index(rowID, 1).data()) self.le_qxz.setText(self.data.index(rowID, 2).data()) if self.data.index(rowID, 3).data() == '管理员': self.checkBox_isAdmin.setChecked(True) else: self.checkBox_isAdmin.setChecked(False) self.txtDisable() self.pb_add.setEnabled(False) self.pb_update.setEnabled(True) self.pb_del.setEnabled(True) @pyqtSlot() def on_pb_query_clicked(self): """查询 按钮的函数""" qs = "select name as 操作员名称, password as 操作员密码, qxz as 权限组, case isAdmin when 1 then '管理员' else '普通人员' end as 是否管理员 from wis_operator where name like '%{}%'".format(self.le_queryPara.text()) data = self.db.querySQL(qs) self.tv_operator.setModel(data) @pyqtSlot() def on_pb_del_clicked(self): """删除按钮的处理函数""" qs = "delete from wis_operator where name = '%s' and name != 'admin'" % self.le_name.text() self.db.excuteSQl(qs) self.txtClear() self.load()
class FaceDeviceWindow(QWidget, faceDeviceUi.Ui_Form): def __init__(self, parent=None): super(FaceDeviceWindow, self).__init__(parent) self.setupUi(self) self.db = Dboperator() self.data = None self.load() self.disableTxt() self.operator = '' def load(self): '''初始化界面中的表格数据''' qs = ''' select id, name, deviceType, location, case status when 1 then '正常使用' else '停止使用' end, ip, netmask, gateway, sn, key, deviceSn from wis_faceDevice ''' self.data = self.db.querySQL(qs) self.tv_device.setModel(self.data) self.data.setHeaderData(0, Qt.Horizontal, '设备编号') self.data.setHeaderData(1, Qt.Horizontal, '设备名称') self.data.setHeaderData(2, Qt.Horizontal, '设备类型') self.data.setHeaderData(3, Qt.Horizontal, '安装位置') self.data.setHeaderData(4, Qt.Horizontal, '是否启用') self.data.setHeaderData(5, Qt.Horizontal, '设备IP') self.data.setHeaderData(6, Qt.Horizontal, '子网掩码') self.data.setHeaderData(7, Qt.Horizontal, '设备网关') self.data.setHeaderData(8, Qt.Horizontal, '平台SN') self.data.setHeaderData(9, Qt.Horizontal, '平台KEY') self.data.setHeaderData(10, Qt.Horizontal, '硬件序列号') self.tv_device.resizeColumnsToContents() def enableTxt(self): '''使界面文本框可编辑''' self.le_deviceId.setEnabled(True) self.le_deviceName.setEnabled(True) self.cb_deviceType.setEnabled(True) self.cb_location.setEnabled(True) self.radioButton_nomal.setEnabled(True) self.radioButton_stop.setEnabled(True) self.le_deviceIP.setEnabled(True) self.le_deivceMask.setEnabled(True) self.le_deviceGateWay.setEnabled(True) self.le_deviceSN.setEnabled(True) self.le_key.setEnabled(True) self.le_Memo.setEnabled(True) self.pb_update.setEnabled(False) self.pb_del.setEnabled(False) self.pb_save.setEnabled(True) self.pb_esc.setEnabled(True) def disableTxt(self): '''使界面文本框不可编辑''' self.le_deviceId.setEnabled(False) self.le_deviceName.setEnabled(False) self.cb_deviceType.setEnabled(False) self.cb_location.setEnabled(False) self.radioButton_nomal.setEnabled(False) self.radioButton_stop.setEnabled(False) self.le_deviceIP.setEnabled(False) self.le_deivceMask.setEnabled(False) self.le_deviceGateWay.setEnabled(False) self.le_deviceSN.setEnabled(False) self.le_key.setEnabled(False) self.le_Memo.setEnabled(False) self.pb_del.setEnabled(False) self.pb_update.setEnabled(False) self.pb_save.setEnabled(False) self.pb_esc.setEnabled(False) def clearTxt(self): '''清除界面文本框中的内容''' self.le_deviceId.clear() self.le_deviceName.clear() # self.cb_deviceType.clear() # self.cb_location.clear() self.radioButton_nomal.setChecked(True) self.radioButton_stop.setChecked(False) self.le_deviceIP.clear() self.le_deivceMask.clear() self.le_deviceGateWay.clear() self.le_deviceSN.clear() self.le_key.clear() self.le_Memo.clear() @pyqtSlot() def on_pb_search_clicked(self): '''搜索控制器''' pass @pyqtSlot() def on_pb_add_clicked(self): '''增加按钮的处理方法''' self.enableTxt() self.clearTxt() self.pb_add.setEnabled(False) self.operator = 'add' @pyqtSlot() def on_pb_update_clicked(self): '''修改按钮的处理方法''' self.enableTxt() self.pb_add.setEnabled(False) self.operator = 'update' @pyqtSlot() def on_pb_del_clicked(self): '''删除按钮的处理方法''' qs = "delete from wis_faceDevice where id = '%s'" % self.le_deviceId.text( ) if QMessageBox.information(self, '提示', '你确认要删除选中设备?', QMessageBox.Yes | QMessageBox.No, QMessageBox.Yes) == QMessageBox.Yes: self.db.excuteSQl(qs) self.txtClear() self.load() @pyqtSlot() def on_pb_save_clicked(self): '''保存按钮的处理方法''' deviceId = self.le_deviceId.text() name = self.le_deviceName.text() deviceType = self.cb_deviceType.currentText() location = self.cb_location.currentText() status = 1 if self.radioButton_nomal.isChecked() else 0 ip = self.le_deviceIP.text() netmask = self.le_deivceMask.text() gateway = self.le_deviceGateWay.text() sn = self.le_deviceSN.text() key = self.le_key.text() deviceSn = self.le_Memo.text() if self.operator == 'add': qs = ''' insert into wis_faceDevice values ('%s', '%s', '%s', '%s', %d, '%s','%s','%s','%s','%s','%s') ''' % (deviceId, name, deviceType, location, status, ip, netmask, gateway, sn, key, deviceSn) else: qs = ''' update wis_faceDevice set name = '%s', deviceType = '%s', location = '%s', status = %d, ip = '%s', netmask = '%s', gateway = '%s', sn = '%s', key = '%s', deviceSn = '%s' where id = '%s' ''' % (name, deviceType, location, status, ip, netmask, gateway, sn, key, deviceSn, deviceId) self.db.excuteSQl(qs) self.load() self.disableTxt() self.clearTxt() self.pb_add.setEnabled(True) @pyqtSlot() def on_pb_esc_clicked(self): '''取消按钮的处理方法''' self.disableTxt() self.clearTxt() self.pb_add.setEnabled(True) @pyqtSlot() def on_pb_query_clicked(self): '''查询按钮的处理方法''' queryPara = self.le_queryPara.text() if queryPara == '': QMessageBox.information(self, '提示', '请输入查询条件!', QMessageBox.Yes) else: qs = '''select id, name, deviceType, location, case status when 1 then '正常使用' else '停止使用' end, ip, netmask, gateway, sn, key, deviceSn from wis_faceDevice where name = '%s' or ip = '%s' ''' % (queryPara, queryPara) self.data = self.db.querySQL(qs) self.tv_device.setModel(self.data) self.data.setHeaderData(0, Qt.Horizontal, '设备编号') self.data.setHeaderData(1, Qt.Horizontal, '设备名称') self.data.setHeaderData(2, Qt.Horizontal, '设备类型') self.data.setHeaderData(3, Qt.Horizontal, '安装位置') self.data.setHeaderData(4, Qt.Horizontal, '是否启用') self.data.setHeaderData(5, Qt.Horizontal, '设备IP') self.data.setHeaderData(6, Qt.Horizontal, '子网掩码') self.data.setHeaderData(7, Qt.Horizontal, '设备网关') self.data.setHeaderData(8, Qt.Horizontal, '平台SN') self.data.setHeaderData(9, Qt.Horizontal, '平台KEY') self.data.setHeaderData(10, Qt.Horizontal, '设备序列号') self.tv_device.resizeColumnsToContents() @pyqtSlot() def on_pb_allData_clicked(self): '''全部数据按钮的处理方法''' self.le_queryPara.clear() self.load() @pyqtSlot(QModelIndex) def on_tv_device_clicked(self): '''选择表中行数据的处理方法''' rowID = self.tv_device.currentIndex().row() deviceId = self.data.index(rowID, 0).data() deviceName = self.data.index(rowID, 1).data() deviceType = self.data.index(rowID, 2).data() location = self.data.index(rowID, 3).data() status = self.data.index(rowID, 4).data() deviceIP = self.data.index(rowID, 5).data() netmask = self.data.index(rowID, 6).data() gateway = self.data.index(rowID, 7).data() deviceSN = self.data.index(rowID, 8).data() deviceKey = self.data.index(rowID, 9).data() memo = self.data.index(rowID, 10).data() self.le_deviceId.setText(deviceId) self.le_deviceName.setText(deviceName) self.cb_deviceType.setCurrentText(deviceType) self.cb_location.setCurrentText(location) self.le_deviceIP.setText(deviceIP) self.le_deivceMask.setText(netmask) self.le_deviceGateWay.setText(gateway) self.le_deviceSN.setText(deviceSN) self.le_key.setText(deviceKey) self.le_Memo.setText(memo) if status == '正常使用': self.radioButton_nomal.setChecked(True) else: self.radioButton_stop.setChecked(True) self.pb_update.setEnabled(True) self.pb_del.setEnabled(True)
class SysSetWindow(QWidget, sysSetUi.Ui_Form): def __init__(self, parent=None): super(SysSetWindow, self).__init__(parent) self.setupUi(self) self.setStyleSheet("background-color: rgb(255, 255, 255);\n" "border-radius:5px;") self.db = Dboperator() self.load() def enableAll(self): self.checkBox_photoBdYN.setEnabled(True) self.checkBox_aqmYN.setEnabled(True) self.checkBox_htzdclYN.setEnabled(True) self.comboBox_zjptName.setEnabled(True) self.checkBox_zjptYN.setEnabled(True) self.spinBox_htzkclTime.setEnabled(True) self.le_localServer.setEnabled(True) self.le_backupUrl.setEnabled(True) self.pb_selectPath.setEnabled(True) self.le_cjSN.setEnabled(True) self.le_cjKEY.setEnabled(True) self.pb_save.setEnabled(True) self.lineEdit_lcdTitle.setEnabled(True) def disableAll(self): self.checkBox_photoBdYN.setEnabled(False) self.checkBox_aqmYN.setEnabled(False) self.checkBox_htzdclYN.setEnabled(False) self.comboBox_zjptName.setEnabled(False) self.checkBox_zjptYN.setEnabled(False) self.spinBox_htzkclTime.setEnabled(False) self.le_localServer.setEnabled(False) self.le_backupUrl.setEnabled(False) self.pb_selectPath.setEnabled(False) self.le_cjSN.setEnabled(False) self.le_cjKEY.setEnabled(False) self.pb_save.setEnabled(False) self.lineEdit_lcdTitle.setEnabled(False) def load(self): """装载系统参数""" qs = "select * from wis_sysSet where id = '99'" alldata = self.db.querySQL(qs) current = alldata.record(0) zjptYN = current.field('zjptYN').value() htzdclYN = current.field('htzdclYN').value() htzdclTime = current.field('htzdclTime').value() localServer = current.field('localServer').value() backupUrl = current.field('backupUrl').value() photoBdYN = current.field('photoBdYN').value() aqmYN = current.field('aqmYN').value() cjSN = current.field('cjSN').value() cjKEY = current.field('cjKEY').value() lcdTitle = current.field('lcdTitle').value() if zjptYN == 1: self.checkBox_zjptYN.setChecked(True) item = current.field('zjptName').value() items = [] items.append(item) self.comboBox_zjptName.addItems(items) self.comboBox_zjptName.setCurrentIndex(0) else: self.checkBox_zjptYN.setChecked(False) self.comboBox_zjptName.clear() self.comboBox_zjptName.setEnabled(False) if htzdclYN == 1: self.checkBox_htzdclYN.setChecked(True) self.spinBox_htzkclTime.setValue(htzdclTime) else: self.checkBox_htzdclYN.setChecked(False) self.spinBox_htzkclTime.setEnabled(False) if aqmYN == 1: self.checkBox_aqmYN.setChecked(True) else: self.checkBox_aqmYN.setChecked(False) if photoBdYN == 1: self.checkBox_photoBdYN.setChecked(True) else: self.checkBox_photoBdYN.setChecked(False) self.le_backupUrl.setText(backupUrl) self.le_localServer.setText(localServer) self.le_cjSN.setText(cjSN) self.le_cjKEY.setText(cjKEY) self.lineEdit_lcdTitle.setText(lcdTitle) @pyqtSlot() def on_pb_update_clicked(self): self.enableAll() @pyqtSlot() def on_pb_save_clicked(self): zjptYN = 1 if self.checkBox_zjptYN.isChecked() else 0 zjptName = self.comboBox_zjptName.currentText() htzdclYN = 1 if self.checkBox_htzdclYN.isChecked() else 0 htzdclTime = int(self.spinBox_htzkclTime.value()) localServer = self.le_localServer.text() backupUrl = self.le_backupUrl.text() photoBdYN = 1 if self.checkBox_photoBdYN.isChecked() else 0 aqmYN = 1 if self.checkBox_aqmYN.isChecked() else 0 cjSN = self.le_cjSN.text() cjKEY = self.le_cjKEY.text() lcdTitle = self.lineEdit_lcdTitle.text() qs = "update wis_sysSet set zjptYN = %d, zjptName = '%s', htzdclYN = %d, htzdclTime = %d, localServer = '%s', backupUrl = '%s', photoBdYN = %d, aqmYN = %d, cjSN = '%s', cjKEY = '%s', lcdTitle = '%s' " % ( zjptYN, zjptName, htzdclYN, htzdclTime, localServer, backupUrl, photoBdYN, aqmYN, cjSN, cjKEY, lcdTitle) self.db.excuteSQl(qs) self.disableAll() @pyqtSlot() def on_pb_selectPath_clicked(self): path = QFileDialog.getExistingDirectory(self, '选择用于备份数据的目录', '/') self.le_backupUrl.setText(path)
class DepartmentWindow(QWidget, departmentUi.Ui_Form): def __init__(self, parent=None): super(DepartmentWindow, self).__init__(parent) self.setupUi(self) self.db = Dboperator() self.data = None self.load() self.txtDisable() def txtEnable(self): """将输入框设置为可用""" self.le_departmentDemo.setEnabled(True) self.le_departmentName.setEnabled(True) self.le_departmentID.setEnabled(True) self.pb_save.setEnabled(True) self.le_departmentID.setFocus() self.pb_add.setEnabled(False) self.checkBox_forLcd.setChecked(True) self.lineEdit_num.setEnabled(True) def txtDisable(self): """将输入框设置为不可用""" self.le_departmentDemo.setEnabled(False) self.le_departmentName.setEnabled(False) self.le_departmentID.setEnabled(False) self.pb_save.setEnabled(False) self.pb_del.setEnabled(False) self.pb_update.setEnabled(False) self.checkBox_forLcd.setEnabled(False) self.lineEdit_num.setEnabled(False) def txtClear(self): """清除输入框内容""" self.le_departmentDemo.clear() self.le_departmentName.clear() self.le_departmentID.clear() self.lineEdit_num.setText("0") def load(self): """表格装载全部的数据""" qs = ''' select id as 部门编号, name as 部门名称, memo as 部门详细说明, case forLcd when 1 then '是' else '否' end as 是否在LCD中显示, currentNum as 在场人员数 from wis_department ''' alldata = self.db.querySQL(qs) self.data = alldata self.tv_department.setModel(self.data) @pyqtSlot() def on_pb_add_clicked(self): """增加 按钮函数""" self.txtEnable() @pyqtSlot() def on_pb_update_clicked(self): """修改 按钮函数""" self.txtEnable() self.checkBox_forLcd.setEnabled(True) self.le_departmentID.setEnabled(False) @pyqtSlot() def on_pb_esc_clicked(self): self.txtClear() self.pb_del.setEnabled(False) self.pb_update.setEnabled(False) self.pb_add.setEnabled(True) self.pb_save.setEnabled(False) @pyqtSlot() def on_pb_save_clicked(self): """保存 按钮函数""" departmentID = self.le_departmentID.text() departmentName = self.le_departmentName.text() departmentDemo = self.le_departmentDemo.text() forLcd = 1 if self.checkBox_forLcd.isChecked() else 0 currentNum = self.lineEdit_num.text() if departmentID != '' and departmentName != '': qs = "select * from wis_department where id = '%s' or name = '%s'" % (departmentID, departmentName) data = self.db.querySQL(qs) if data.rowCount() == 0: qs = "INSERT INTO wis_department VALUES('%s','%s','%s', %d, %d)" % (departmentID, departmentName, departmentDemo, forLcd, int(currentNum)) self.db.excuteSQl(qs) self.load() self.txtClear() self.le_departmentID.setFocus() else: QMessageBox.information(self, '提示', '编号与名称不能重复!', QMessageBox.Yes) self.txtClear() self.pb_del.setEnabled(False) self.pb_update.setEnabled(False) self.pb_add.setEnabled(True) self.pb_save.setEnabled(False) self.txtDisable() else: QMessageBox.information(self, '提示', '编号与名称不能为空!', QMessageBox.Yes) self.txtClear() self.pb_del.setEnabled(False) self.pb_update.setEnabled(False) self.pb_add.setEnabled(True) self.pb_save.setEnabled(False) self.txtDisable() @pyqtSlot(QModelIndex) def on_tv_department_clicked(self, QModelIndex): """选中表格中一行的处理函数""" rowID = self.tv_department.currentIndex().row() data = self.data.index(rowID, 0).data() self.le_departmentID.setText(data) self.le_departmentName.setText(self.data.index(rowID, 1).data()) self.le_departmentDemo.setText(self.data.index(rowID, 2).data()) if self.data.index(rowID, 3).data() == '是': self.checkBox_forLcd.setChecked(True) else: self.checkBox_forLcd.setChecked(False) self.lineEdit_num.setText(str(self.data.index(rowID, 4).data())) self.txtDisable() self.pb_add.setEnabled(False) self.pb_update.setEnabled(True) self.pb_del.setEnabled(True) @pyqtSlot() def on_pb_query_clicked(self): """查询 按钮的函数""" qs = ''' select id as 部门编号, name as 部门名称, memo as 部门详细说明, case forLcd when 1 then '是' else '否' end as 是否在LCD中显示, currentNum as 在场人员数 from wis_department where 部门名称 like '%{}%' '''.format(self.le_queryPara.text()) # qs = "select id as 部门编号, name as 部门名称, memo as 部门详细说明 from wis_department where 部门名称 like '%{}%'".format(self.le_queryPara.text()) data = self.db.querySQL(qs) self.tv_department.setModel(data) @pyqtSlot() def on_pb_allData_clicked(self): """全部数据 按钮的函数""" self.le_queryPara.clear() self.load() @pyqtSlot() def on_pb_del_clicked(self): """删除按钮的处理函数""" qs = "delete from wis_department where id = '%s' " % self.le_departmentID.text() self.db.excuteSQl(qs) self.txtClear() self.load()
class InfoCollectionCls(QWidget, infoCollectionUi.Ui_infoCollectionForm): def __init__(self, parent=None): super(InfoCollectionCls, self).__init__(parent) self.setupUi(self) self.face = FaceDevice() self.pb_cj.setVisible(False) # self.pb_refresh_photo.setVisible(False) self.pb_uploadtoDev.setVisible(False) self.pb_uploadPerson.setVisible(False) self.pb_downloadPerson.setVisible(False) # self.cr = zkCardReader.CardReader() self.db = Dboperator() self.cdzj = Cdzj() self.dlg = None self.cjSN = '' self.cjKEY = '' self.faceDevices = None self.load() def load(self): self.pb_uploadPerson.setEnabled(False) self.pb_uploadtoDev.setEnabled(False) qs = "select name from wis_department" data = self.db.querySQL(qs) self.cb_department.setModel(data) zjqs = "select * from wis_cdzjpt where id = '99'" current = self.db.querySQL(zjqs).record(0) self.cdzj.uploadPersonURL = current.field('uploadPersonURL').value() # print(self.cdzj.uploadPersonURL) self.cdzj.downloadPersonURL = current.field( 'downloadPersonURL').value() self.cdzj.downloadDelPersonURL = current.field( 'deletePersonURL').value() self.cdzj.uploadAttendanceURL = current.field('uploadAttURL').value() self.cdzj.feedbackURL = current.field('feedbackURL').value() sysSetQs = "select * from wis_sysSet where id = 99" currentSysSet = self.db.querySQL(sysSetQs).record(0) self.cjSN = currentSysSet.field('cjSN').value() self.cjKEY = currentSysSet.field('cjKEY').value() device_qs = "select sn, key from wis_faceDevice where status = 1" self.faceDevices = self.db.querySQL(device_qs) @pyqtSlot() def on_pb_refresh_photo_clicked(self): """刷新考勤设备照片 处理函数""" img = QPixmap('./photos_face/{}.jpg'.format(self.le_idNum.text())) self.lb_photo3.setPixmap(img) @pyqtSlot() def on_pb_camera1_clicked(self): """从摄像头拍照 处理函数""" idNo = self.le_idNum.text() self.dlg = collectImgController.CollectImgWindow() self.dlg.idNo = idNo if self.dlg.exec_() == QDialog.Accepted: self.dlg.destroy() srcImg = './photos_face/{}.jpg'.format(self.dlg.idNo) dstImg = './photos_face/{}_face.jpg'.format(self.dlg.idNo) r = self.face.getFacePos(srcImg, dstImg) if r: img = QPixmap(dstImg) self.lb_photo3.setPixmap(img) else: QMessageBox.information(self, '提示', '图片中未检测到头像,请重试!', QMessageBox.Yes) else: pass # @pyqtSlot() # def on_pb_camera_clicked(self): # """从摄像头拍照 处理函数""" # try: # cam_Dev = CameraDev() # cam_Dev.filename = self.le_idNum.text() # cam_Dev.take_photo() # srcImg = './photos_face/{}.jpg'.format(cam_Dev.filename) # dstImg = './photos_face/{}_face.jpg'.format(cam_Dev.filename) # r = self.face.getFacePos(srcImg, dstImg) # if r: # img = QPixmap(dstImg) # # self.lb_photo3.setPixmap(img) # else: # QMessageBox.information(self, '提示', '图片中未检测到头像,请重试!', QMessageBox.Yes) # except Exception as e: # QMessageBox.information(self, '提示', '未检测到摄像头!', QMessageBox.Yes) # @pyqtSlot() # def on_pb_cj_photo_clicked(self): # """从考勤设备拍摄照片 处理函数""" # face = Face_device('192.168.0.105') # person = {"id": str(self.le_idNum.text()), "name": str(self.le_name.text())} # # if face.createPerson(person): # # if face.takeImg(person["id"]): # map = QPixmap("./photos_face/{}".format(self.le_idNum.text())) # self.lb_photo3.setPixmap(map) # else: # QMessageBox.information(self, '提示', '不能拍照', QMessageBox.Yes) # else: # QMessageBox.information(self, '提示', '不能创建人员', QMessageBox.Yes) @pyqtSlot() def on_pb_uploadtoDev_clicked(self): '''上传人员信息至考勤设备''' idNo = self.le_idNum.text() qs = "select * from wis_person where zjptStatus = 0 and uploadYN = 1 and personStatus = 1 and idNo = '%s'" % idNo persons = self.db.querySQL(qs) rows = persons.rowCount() if rows == 1: with open('./photos_face/{}_face.jpg'.format(self.le_idNum.text()), 'rb') as f: img_data = base64.b64encode(f.read()) payload = {'version': '0.2', 'cmd': 'create_face'} payload['per_id'] = self.le_idNum.text() payload['face_id'] = self.le_idNum.text() payload['per_name'] = self.le_name.text() payload['idcardNum'] = '' payload['img_data'] = img_data payload['idcardper'] = self.le_idNum.text() payload['s_time'] = 0 payload['e_time'] = 10000 if self.rb_personStatus1.isChecked(): payload['per_type'] = 0 else: payload['per_type'] = 2 payload['usr_type'] = 0 requests.post('http://127.0.0.1:8080/addFace', data=payload) time.sleep(1) dic = {} dic['version'] = '0.2' dic['cmd'] = 'query_face' dic['per_id'] = self.le_idNum.text() dic['id'] = 20 dic['name'] = '' requests.post('http://127.0.0.1:8080/queryFace', data=dic) QMessageBox.information(self, '提示', '增加人脸到设备完成,在数据中查看上传结果!', QMessageBox.Yes) else: QMessageBox.information(self, '提示', '请先增加和保存需要上传的数据!', QMessageBox.Yes) @pyqtSlot() def on_pb_readall_clicked(self): """人员信息列表 处理函数""" queryModel = self.db.querySQL('select * from wis_person') self.tableView.setModel(queryModel) queryModel.setHeaderData(0, Qt.Horizontal, '身份证号') queryModel.setHeaderData(1, Qt.Horizontal, '姓名') queryModel.setHeaderData(2, Qt.Horizontal, '性别') queryModel.setHeaderData(3, Qt.Horizontal, '民族') queryModel.setHeaderData(4, Qt.Horizontal, '出生日期') queryModel.setHeaderData(5, Qt.Horizontal, '住址') queryModel.setHeaderData(6, Qt.Horizontal, '发证机关') queryModel.setHeaderData(7, Qt.Horizontal, '证件有效期') queryModel.setHeaderData(8, Qt.Horizontal, '身份证照片') queryModel.setHeaderData(9, Qt.Horizontal, '人员可见光照片') queryModel.setHeaderData(10, Qt.Horizontal, '人员红外照片') queryModel.setHeaderData(11, Qt.Horizontal, '人员类型') queryModel.setHeaderData(12, Qt.Horizontal, '设备序列号') queryModel.setHeaderData(13, Qt.Horizontal, '注册类别') queryModel.setHeaderData(14, Qt.Horizontal, '住建平台ID') queryModel.setHeaderData(15, Qt.Horizontal, '用户工号') queryModel.setHeaderData(16, Qt.Horizontal, '所属班组或部门') queryModel.setHeaderData(17, Qt.Horizontal, '数据状态') @pyqtSlot() def on_pb_save_upload_clicked(self): """保存数据到本地 处理函数""" idperiod = str('{}-{}'.format(self.le_effectedDate.text(), self.le_expiredDate.text())) idNo = str(self.le_idNum.text()) name = str(self.le_name.text()) gender = 1 if self.le_sex.text() == '男' else 2 nation = str(self.le_nation.text()) birthday = str(self.le_birthdate.text()) address = str(self.le_address.text()) idissue = str(self.le_issue.text()) idphoto = "./photos_kl/{}.jpg".format(self.le_idNum.text()) photo = './photos_face/{}_face.jpg'.format(self.le_idNum.text()) inf_photo = "" userType = 1 RegType = 3 if self.cb_RegType.currentText() == '人脸采集' else 1 user_id = "" work_sn = "" department = str(self.cb_department.currentText()) deviceStatus = 0 zjptStatus = 0 if self.checkbox_uploadYN.isChecked(): uploadYN = 1 else: uploadYN = 0 if self.rb_personStatus1.isChecked(): personStatus = 1 else: personStatus = 2 if idNo != '': q_sql = "select * from wis_person where idNo = '%s'" % idNo query = self.db.querySQL(q_sql) if query.rowCount() > 0: QMessageBox.information(self, '提示', '人员信息重复!', QMessageBox.Yes) else: sql = "INSERT INTO wis_person VALUES('%s','%s',%d,'%s','%s','%s','%s','%s','%s','%s','%s',%d,%d,'%s','%s','%s',%d,%d,%d,%d)" % ( idNo, name, gender, nation, birthday, address, idissue, idperiod, idphoto, photo, inf_photo, userType, RegType, user_id, work_sn, department, deviceStatus, zjptStatus, uploadYN, personStatus) self.db.excuteSQl(sql) QMessageBox.information(self, '提示', '人员信息采集成功!', QMessageBox.Yes) self.pb_uploadPerson.setEnabled(True) self.pb_uploadtoDev.setEnabled(True) else: QMessageBox.information(self, '提示', '人员信息为空!', QMessageBox.Yes) @pyqtSlot() def on_pb_uploadPhoto_clicked(self): """使用电脑中的照片 处理函数""" path, imptype = QFileDialog.getOpenFileName(self, '选择用于识别的人像', '/', 'jpg(*.jpg);') if path != '': img = QPixmap(path) self.lb_photo2.setPixmap(img) self.lb_photo2.setScaledContents(True) newpath = './photos_face/{}.jpg'.format(self.le_idNum.text()) shutil.copyfile(path, newpath) srcImg = './photos_face/{}.jpg'.format(self.le_idNum.text()) dstImg = './photos_face/{}_face.jpg'.format(self.le_idNum.text()) r = self.face.getFacePos(srcImg, dstImg) if r: img = QPixmap(dstImg) self.lb_photo3.setPixmap(img) else: QMessageBox.information(self, '提示', '图片中未检测到头像,请重选图片!', QMessageBox.Yes) else: QMessageBox.information(self, '提示', '本次未选择照片!', QMessageBox.Yes) @pyqtSlot() def on_pb_cj1_clicked(self): """读身份证信息 处理函数""" self.pb_cj1.setText('信息读取中....') self.lb_photo.clear() self.lb_photo2.clear() self.lb_photo3.clear() try: cr = klCardReader.CardReader() except Exception as e: return e r = cr.openDevice() if r == 0: try: r = cr.readCard() if r == 0: self.le_name.setText(cr.info['name']) self.le_address.setText(cr.info['address']) self.le_sex.setText(cr.info['sexDesc']) self.le_nation.setText(cr.info['nationDesc']) self.le_birthdate.setText(cr.info['born']) self.le_idNum.setText(cr.info['cardNo']) self.le_issue.setText(cr.info['issuedAt']) self.le_effectedDate.setText(cr.info['effectedDate']) self.le_expiredDate.setText(cr.info['expiredDate']) image = QPixmap("./photos_kl/{}.jpg".format( cr.info['cardNo'])) self.lb_photo.setPixmap(image) else: QMessageBox.information(self, '提示', '请确认身份证是否放到阅读器上!', QMessageBox.Yes) except Exception as e: QMessageBox.information(self, '提示', '读卡失败,{}'.format(e), QMessageBox.Yes) finally: cr.closeDevice() self.pb_cj1.setText('读身份证信息') else: QMessageBox.information(self, '提示', '身份证阅读器打开失败!', QMessageBox.Yes) @pyqtSlot() def on_pb_cj_clicked(self): """读身份证信息(中控) 处理函数""" try: cr = zkCardReader.CardReader() except Exception as e: return e if cr.openDevice() > 0: re = cr.readCard() if re == 1: self.le_name.setText(cr.info['name']) self.le_address.setText(cr.info['address']) self.le_sex.setText(cr.info['sex']) self.le_nation.setText(cr.info['nation']) self.le_birthdate.setText(cr.info['birthdate']) self.le_idNum.setText(cr.info['idNum']) self.le_issue.setText(cr.info['issue']) self.le_effectedDate.setText(str(cr.info['effectedDate'])) self.le_expiredDate.setText(str(cr.info['expiredDate'])) photo = base64.b64decode(cr.info['b_Photo']) q_photo = QImage.fromData(photo) image = QPixmap.fromImage(q_photo) self.lb_photo.setPixmap(image) cr.closeDevice() else: QMessageBox.information(self, '提示', '请重新放置身份证!', QMessageBox.Yes) else: QMessageBox.information(self, '提示', '身份证阅读器打开失败!', QMessageBox.Yes) @pyqtSlot() def on_pb_uploadPerson_clicked(self): """同步人员平台信息""" # 整理符合上传需求的人员信息 idNo = self.le_idNum.text() qs = "select * from wis_person where uploadYN = 1 and personStatus = 1 and idNo = '%s'" % idNo persons = self.db.querySQL(qs) rows = persons.rowCount() if rows == 1: person = persons.record(0) idNo = person.field('idNo').value() name = person.field('name').value() gender = person.field('gender').value() nation = person.field('nation').value() tbirthday = person.field('birthday').value() year = tbirthday[0:4] month = tbirthday[4:6] day = tbirthday[6:] birthday = year + '-' + month + '-' + day address = person.field('address').value() idissue = person.field('idissue').value() idperiod = person.field('idperiod').value() idphotoPath = person.field('idphoto').value() idphoto = jpgtostr(idphotoPath) photoPath = person.field('photo').value() photo = jpgtostr(photoPath) inf_photo = '' userType = person.field('userType').value() dev_mac = self.cjSN RegType = person.field('RegType').value() self.cdzj.person['idNo'] = idNo self.cdzj.person['name'] = name self.cdzj.person['gender'] = gender self.cdzj.person['nation'] = nation self.cdzj.person['birthday'] = birthday self.cdzj.person['address'] = address self.cdzj.person['idissue'] = idissue self.cdzj.person['idperiod'] = idperiod self.cdzj.person['idphoto'] = idphoto self.cdzj.person['photo'] = photo self.cdzj.person['inf_photo'] = inf_photo self.cdzj.person['userType'] = userType self.cdzj.person['dev_mac'] = dev_mac self.cdzj.person['RegType'] = RegType # 上传人员信息到住建平台 self.cdzj.uploadPerson() if self.cdzj.msg_uploadPerson == 'success': # 上传上成功后将本地数据库对应记录打上成功标记 qs = "update wis_person set zjptStatus = 1 where idNo = '%s'" % idNo self.db.excuteSQl(qs) okMsg = "人员:%s,身份证号:%s,%s成功上传到平台\n" % ( name, idNo, datetime.datetime.now().strftime('%Y-%m-%d %X')) self.pb_save_upload.setEnabled(False) with open('uploadLog.txt', 'a') as f: f.write(okMsg) f.close() # 上传成功后,平台会产生人员的住建号,需要系统下载对应的人员信息并下发到有脸设备中,并返馈下发到设备的结果到平台 qs = "select sn, key from wis_faceDevice where status = 1" devices = self.db.querySQL(qs) rows = devices.rowCount() if rows > 0: i = 0 while i < rows: device = devices.record(i) sn = str.strip(device.field('sn').value()) key = str.strip(device.field('key').value()) self.cdzj.downloadPerson(deviceSN=sn, key=key) if self.cdzj.msg_downloadPerson == 'success': # 下载住建平台产生的的人员编号 ,并更新到本地数据库 qs = "update wis_person set user_id = '%s', work_sn = '%s' where idNo = '%s'" % ( self.cdzj.person['user_id'], self.cdzj.person['work_sn'], self.cdzj.person['idNo']) self.db.excuteSQl(qs) # 下发人员信息到人脸设备 dic = {} person = self.cdzj.person.record(0) dic['version'] = '0.2' dic['cmd'] = 'create_face' dic['per_id'] = person.field('idNo').value() dic['face_id'] = person.field('idNo').value() dic['per_name'] = person.field('name').value() dic['idcardNum'] = person.field('idNo').value() dic['idcardper'] = person.field('idNo').value() dic['s_time'] = 0 dic['e_time'] = 10000 personStatus = person.field('personStatus').value() if personStatus == 1: dic['per_type'] = 0 else: dic['per_type'] = 2 dic['usr_type'] = 0 desImg = './photos_face/{}_face.jpg'.format( dic['per_id']) with open(desImg, 'rb') as f: bimg = base64.b64encode(f.read()) dic['img_data'] = bimg requests.post('http://127.0.0.1:8080/addFace', data=dic) time.sleep(1) self.cdzj.feedback(sn, 2, '下发成功') i += 1 else: QMessageBox.information( self, '提示', self.cdzj.msg_downloadPerson, QMessageBox.Yes) else: failMsg = "人员:%s,身份证号:%s,%s上传到平台失败,原因:%s\n" % ( name, idNo, datetime.datetime.now(), self.cdzj.msg) QMessageBox.information(self, '提示', failMsg) with open('uploadLog.txt', 'a') as f: f.write(failMsg) f.close() else: QMessageBox.information(self, '提示', '当前数据不需与住建平台进行同步!', QMessageBox.Yes)
class LcdMonitorWindow(QtWidgets.QWidget, lcdMonitorUi.Ui_Form): def __init__(self, parent=None): super(LcdMonitorWindow, self).__init__(parent) self.setupUi(self) self.sequence = '' self.listWidget_l.setHorizontalScrollBarPolicy(1) self.listWidget_l.setVerticalScrollBarPolicy(1) self.listWidget_r.setHorizontalScrollBarPolicy(1) self.listWidget_r.setVerticalScrollBarPolicy(1) self.db = Dboperator() self.setTitle() self.firstWeather() self.timer = QTimer() self.timer.timeout.connect(self.load) self.timer.start(3) def firstWeather(self): qs = "select * from wis_lcdConfig where id = '99'" confs = self.db.querySQL(qs) city = confs.record(0).field('location').value() we = weather.getWeatherBycityName(city) fengli = weather.getFengLi(we['fengli']) self.label_xq.setText(we['date']) self.label_tq.setText(we['type']) wd = "%s\n%s" % (we['high'], we['low']) self.label_wd.setText(wd) self.label_fengli.setText(r'%s' % fengli) date = QDate.currentDate().toString(Qt.DefaultLocaleLongDate) day = QDate.currentDate().day() self.lcdNumber_date.display(str(date)) qs = "update wis_lcdConfig set weatherDay = '%s'" % str(day) self.db.excuteSQl(qs) def setWeather(self): qs = "select * from wis_lcdConfig where id = '99'" confs = self.db.querySQL(qs) day = confs.record(0).field('weatherDay').value() if day != str(QDate.currentDate().day()): city = confs.record(0).field('location').value() we = weather.getWeatherBycityName(city) fengli = weather.getFengLi(we['fengli']) self.label_xq.setText(we['date']) self.label_tq.setText(we['type']) wd = "%s\n%s" % (we['high'], we['low']) self.label_wd.setText(wd) self.label_fengli.setText(fengli) def setTitle(self): qs = "select lcdTitle from wis_sysSet where id = '99'" sy = self.db.querySQL(qs) title = sy.record(0).field('lcdTitle').value() self.label_title.setText(title) self.label_title.setStyleSheet("font: 75 36pt \"微软雅黑\";\n" "color: rgb(255, 255, 255);") def refreshNum(self): for i in range(self.flayout_bz.count()): self.flayout_bz.itemAt(i).widget().deleteLater() qs = "select * from wis_department where forLcd = 1" sumq = "select sum(currentNum) as sumq from wis_department where forLcd = 1" dps = self.db.querySQL(qs) q = self.db.querySQL(sumq) countq = q.record(0).field('sumq').value() self.lcdNumber_all.display(str(countq)) dps_count = dps.rowCount() if dps_count > 0: i = 0 while i < dps_count: name = dps.record(i).field('name').value() currentNum = dps.record(i).field('currentNum').value() label = QtWidgets.QLabel(name) label.setStyleSheet("font: 75 26pt \"微软雅黑\";\n" "color: rgb(255, 255, 255);") num = QtWidgets.QLCDNumber(5, self) num.setStyleSheet("font: 75 26pt \"微软雅黑\";\n" "color: rgb(255, 255, 255);") num.setMode(QtWidgets.QLCDNumber.Dec) num.setSegmentStyle(QtWidgets.QLCDNumber.Flat) num.setFrameShape(QtWidgets.QLCDNumber.NoFrame) num.setDigitCount(5) num.setNumDigits(3) num.display(currentNum) self.flayout_bz.addRow(label, num) time = QTime.currentTime().toString(Qt.DefaultLocaleLongDate) self.label_time.setText("当前时间:%s" % time) i += 1 def refreshPhoto(self): qs = ''' select wis_recordsx.name, wis_recordsx.usec, wis_recordsx.per_id, wis_person.department, wis_person.idphoto, wis_recordsx.timeSta from wis_recordsx, wis_person where wis_recordsx.per_id = wis_person.idNo order by wis_recordsx.timeSta desc limit 0, 5 ''' dps = self.db.querySQL(qs) dps_count = dps.rowCount() if dps_count > 0: i = 0 while i < dps_count: if self.sequence != dps.record(i).field('timeSta').value(): # 处理需要显示的数据 name = dps.record(i).field('name').value() usec = dps.record(i).field('usec').value() per_id = dps.record(i).field('per_id').value() department = dps.record(i).field('department').value() idphoto = dps.record(i).field('idphoto').value() info = "\n班组:%s\n 人员:%s\n 时间:%s" % (department, name, usec[11:]) # 建立 两个LABEL 左边显示图片,右边显示信息 idphoto_pixmap = QPixmap(idphoto).scaled(150, 200) label_photo = QtWidgets.QLabel() label_photo.clear() label_photo.setPixmap(idphoto_pixmap) label_info = QtWidgets.QLabel() label_info.clear() label_info.setText(info) label_info.setStyleSheet("font: 75 18pt \"微软雅黑\";\n" "color: rgb(255, 255, 255);") label_info.setScaledContents(True) label_info.setAlignment(Qt.AlignVCenter) widget = QtWidgets.QWidget() layout_main = QtWidgets.QVBoxLayout() layout_center = QtWidgets.QFormLayout() layout_center.setSpacing(10) layout_center.addRow(label_photo, label_info) layout_main.addLayout(layout_center) widget.setLayout(layout_main) item = QtWidgets.QListWidgetItem() item.setSizeHint((QtCore.QSize(150, 400))) self.listWidget_l.addItem(item) self.listWidget_l.setItemWidget(item, widget) self.sequence = dps.record(i).field('timeSta').value() i += 1 def load(self): self.refreshNum() self.refreshPhoto() self.setWeather() @pyqtSlot() def on_pb_max_clicked(self): self.setWindowFlags(Qt.FramelessWindowHint) self.showMaximized() @pyqtSlot() def on_pb_exit_clicked(self): self.close() def mousePressEvent(self, QMouseEvent): if QMouseEvent.button() == Qt.LeftButton: self.flag = True self.m_Position = QMouseEvent.globalPos() - self.pos() QMouseEvent.accept() self.setCursor(QCursor(Qt.OpenHandCursor)) def mouseMoveEvent(self, QMouseEvent): if Qt.LeftButton and self.flag: self.move(QMouseEvent.globalPos() - self.m_Position) QMouseEvent.accept() def mouseReleaseEvent(self, QMouseEvent): self.flag = False self.setCursor(QCursor(Qt.ArrowCursor))
class PersonManageWindow(QWidget, personManagementUi.Ui_Form): def __init__(self, parent=None): super(PersonManageWindow, self).__init__(parent) self.setupUi(self) self.pb_refresh.setVisible(False) self.pb_uploadPerson.setVisible(False) self.pb_uploadToDevice.setVisible(False) self.pb_refresh.setVisible(False) self.pb_downloadPerson.setVisible(False) self.data = None self.disableEdit() # self.face = FaceDevice() self.db = Dboperator() self.cdzj = cdzjpt.Cdzj() self.cjSN = '' self.cjKEY = '' self.faceDevices = None self.load() def load(self): '''方法作用为初始化窗口数据''' qs = ''' select idNo, name, case gender when 1 then '男' when 2 then '女' end, nation, birthday, address, idissue, idperiod, idphoto, photo, case userType when 1 then '劳务人员' when 2 then '岗位人员' end, case RegType when 3 then '人脸采集' else '其他' end, user_id, work_sn, department, case deviceStatus when 0 then '未同步到设备' when 1 then '已同步到设备' end, case zjptStatus when 0 then '未同步到住建平台' when 1 then '已同步到住建平台' end, case uploadYN when 0 then '不上传平台' when 1 then '应上传平台' end, case personStatus when 2 then '已停用' when 1 then '正常' end from wis_person ''' allPerson = self.db.querySQL(qs) self.data = allPerson self.tv_person.setModel(self.data) allPerson.setHeaderData(0, Qt.Horizontal, '身份证号码') allPerson.setHeaderData(1, Qt.Horizontal, '姓名') allPerson.setHeaderData(2, Qt.Horizontal, '性别') allPerson.setHeaderData(3, Qt.Horizontal, '民族') allPerson.setHeaderData(4, Qt.Horizontal, '出生日期') allPerson.setHeaderData(5, Qt.Horizontal, '住址') allPerson.setHeaderData(6, Qt.Horizontal, '发证机关') allPerson.setHeaderData(7, Qt.Horizontal, '有效期') allPerson.setHeaderData(8, Qt.Horizontal, '身份证照片地址') allPerson.setHeaderData(9, Qt.Horizontal, '人脸照片地址') allPerson.setHeaderData(10, Qt.Horizontal, '用户类型') allPerson.setHeaderData(11, Qt.Horizontal, '注册类型') allPerson.setHeaderData(12, Qt.Horizontal, '住建平台统一号') allPerson.setHeaderData(13, Qt.Horizontal, '住建平台工作号') allPerson.setHeaderData(14, Qt.Horizontal, '部门班组') allPerson.setHeaderData(15, Qt.Horizontal, '设备同步状态') allPerson.setHeaderData(16, Qt.Horizontal, '平台同步状态') allPerson.setHeaderData(17, Qt.Horizontal, '是否上传平台') allPerson.setHeaderData(18, Qt.Horizontal, '人员状态') self.tv_person.resizeColumnsToContents() zjqs = "select * from wis_cdzjpt where id = '99'" current = self.db.querySQL(zjqs).record(0) self.cdzj.uploadPersonURL = current.field('uploadPersonURL').value() # print(self.cdzj.uploadPersonURL) self.cdzj.downloadPersonURL = current.field( 'downloadPersonURL').value() self.cdzj.downloadDelPersonURL = current.field( 'deletePersonURL').value() self.cdzj.uploadAttendanceURL = current.field('uploadAttURL').value() self.cdzj.feedbackURL = current.field('feedbackURL').value() sysSetQs = "select * from wis_sysSet where id = 99" currentSysSet = self.db.querySQL(sysSetQs).record(0) self.cjSN = currentSysSet.field('cjSN').value() self.cjKEY = currentSysSet.field('cjKEY').value() device_qs = "select sn, key from wis_faceDevice where status = 1" self.faceDevices = self.db.querySQL(device_qs) def enableEdit(self): '''方法作用为使界面文本框可以输入''' self.comboBox_department.setEnabled(True) self.comboBox_userType.setEnabled(True) self.comboBox_RegType.setEnabled(True) self.checkBox_uploadYN.setEnabled(True) self.radioButton_personStatus_stop.setEnabled(True) self.radioButton_personStatus_nomal.setEnabled(True) self.pb_save.setEnabled(True) self.pb_esc.setEnabled(True) self.pb_del.setEnabled(False) def disableEdit(self): '''方法作用为使界面文本框无法输入''' self.comboBox_department.setEnabled(False) self.comboBox_userType.setEnabled(False) self.comboBox_RegType.setEnabled(False) self.checkBox_uploadYN.setEnabled(False) self.radioButton_personStatus_stop.setEnabled(False) self.radioButton_personStatus_nomal.setEnabled(False) self.pb_save.setEnabled(False) self.pb_esc.setEnabled(False) self.pb_del.setEnabled(False) self.pb_update.setEnabled(False) def txtClear(self): '''方法作用为清除文本框中的内容''' self.le_idNo.clear() self.le_name.clear() self.le_gender.clear() self.le_nation.clear() self.le_address.clear() self.le_birthday.clear() self.le_idperiod.clear() self.le_idissue.clear() self.comboBox_department.clear() self.comboBox_RegType.clear() self.comboBox_userType.clear() self.le_user_id.clear() self.checkBox_uploadYN.setChecked(False) self.le_work_sn.clear() self.le_deviceStatus.clear() self.le_zjptStatus.clear() self.label_photo.clear() self.label_idphoto.clear() @pyqtSlot() def on_pb_del_clicked(self): '''方法作用删除人员''' qs = "delete from wis_person where idNo = '%s'" % self.le_idNo.text() if QMessageBox.information(self, '提示', '你确认要删除选中人员?', QMessageBox.Yes | QMessageBox.No, QMessageBox.Yes) == QMessageBox.Yes: self.db.excuteSQl(qs) self.txtClear() self.load() @pyqtSlot() def on_pb_update_clicked(self): '''方法作用为对人员信息进行修改''' self.enableEdit() @pyqtSlot() def on_pb_save_clicked(self): '''方法作用为修改人员信息后,进行保存''' department = self.comboBox_department.currentText() idNo = self.le_idNo.text() userType = 1 if self.comboBox_userType.currentText() == '劳务人员' else 2 RegType = 3 if self.comboBox_RegType.currentText() == '人脸采集' else 0 uploadYN = 1 if self.checkBox_uploadYN.isChecked() else 0 personStatus = 1 if self.radioButton_personStatus_nomal.isChecked( ) else 2 qs = ''' update wis_person set department = '%s', userType = %d, RegType = %d, uploadYN = %d, personStatus = %d where idNo = '%s' ''' % (department, userType, RegType, uploadYN, personStatus, idNo) self.db.excuteSQl(qs) self.disableEdit() self.load() @pyqtSlot() def on_pb_esc_clicked(self): '''方法作用为中止修改操作''' self.disableEdit() @pyqtSlot() def on_comboBox_department_activated(self): '''方法作用为点部门单选框时,载入相应部门信息''' qs1 = 'select name from wis_department' allDepartment = self.db.querySQL(qs1) self.comboBox_department.clear() self.comboBox_department.setModel(allDepartment) @pyqtSlot(QModelIndex) def on_tv_person_clicked(self, QModelIndex): '''方法作用为选中表中人员信息后,将人员信息在详情中进行填充''' rowID = self.tv_person.currentIndex().row() idNo = self.data.index(rowID, 0).data() name = self.data.index(rowID, 1).data() gender = self.data.index(rowID, 2).data() nation = self.data.index(rowID, 3).data() birthday = self.data.index(rowID, 4).data() address = self.data.index(rowID, 5).data() idissue = self.data.index(rowID, 6).data() idperiod = self.data.index(rowID, 7).data() idphoto = self.data.index(rowID, 8).data() photo = self.data.index(rowID, 9).data() userType = self.data.index(rowID, 10).data() RegType = self.data.index(rowID, 11).data() user_id = self.data.index(rowID, 12).data() work_sn = self.data.index(rowID, 13).data() department = self.data.index(rowID, 14).data() deviceStatus = self.data.index(rowID, 15).data() zjptStatus = self.data.index(rowID, 16).data() uploadYN = self.data.index(rowID, 17).data() personStatus = self.data.index(rowID, 18).data() self.le_idNo.setText(idNo) self.le_name.setText(name) self.le_gender.setText(gender) self.le_nation.setText(nation) self.le_address.setText(address) self.le_birthday.setText(birthday) self.le_idperiod.setText(idperiod) self.le_idissue.setText(idissue) self.le_user_id.setText(user_id) self.le_work_sn.setText(work_sn) self.le_deviceStatus.setText(deviceStatus) self.le_zjptStatus.setText(zjptStatus) qs1 = 'select name from wis_department' allDepartment = self.db.querySQL(qs1) self.comboBox_department.clear() self.comboBox_department.setModel(allDepartment) self.comboBox_department.setCurrentText(department) list_userType = ['劳务人员', '岗位人员', '其他人员'] self.comboBox_userType.clear() self.comboBox_userType.addItems(list_userType) self.comboBox_userType.setCurrentText(userType) list_RegType = ['人脸采集', '刷卡采集', '指纹采集', '其他采集'] self.comboBox_RegType.clear() self.comboBox_RegType.addItems(list_RegType) self.comboBox_RegType.setCurrentText(RegType) if uploadYN == '应上传平台': self.checkBox_uploadYN.setChecked(True) else: self.checkBox_uploadYN.setChecked(False) if personStatus == '正常': self.radioButton_personStatus_nomal.setChecked(True) else: self.radioButton_personStatus_stop.setChecked(True) idphoto_pixmap = QPixmap(idphoto) self.label_idphoto.setPixmap(idphoto_pixmap) self.label_idphoto.setScaledContents(True) photo_pixmap = QPixmap(photo) self.label_photo.setPixmap(photo_pixmap) self.label_photo.setScaledContents(True) self.pb_update.setEnabled(True) # self.pb_replaceIMG.setEnabled(True) self.pb_del.setEnabled(True) @pyqtSlot() def on_pb_query_clicked(self): '''方法作用为根据输入条件,查询本地人员信息''' queryPara = self.le_queryPara.text() if queryPara == '': QMessageBox.information(self, '提示', '请输入查询条件!', QMessageBox.Yes) else: qs = ''' select idNo, name, case gender when 1 then '男' when 2 then '女' end, nation, birthday, address, idissue, idperiod, idphoto, photo, case userType when 1 then '劳务人员' when 2 then '岗位人员' end, case RegType when 3 then '人脸采集' else '其他' end, user_id, work_sn, department, case deviceStatus when 0 then '未同步到设备' when 1 then '已同步到设备' end, case zjptStatus when 0 then '未同步到住建平台' when 1 then '已同步到住建平台' when 2 then '住建平台已删除' end, case uploadYN when 0 then '不上传平台' when 1 then '应上传平台' end, case personStatus when 2 then '已停用' when 1 then '正常' end from wis_person where idNo = '%s' or name = '%s' ''' % (queryPara, queryPara) somePerson = self.db.querySQL(qs) self.data = somePerson self.tv_person.setModel(self.data) somePerson.setHeaderData(0, Qt.Horizontal, '身份证号码') somePerson.setHeaderData(1, Qt.Horizontal, '姓名') somePerson.setHeaderData(2, Qt.Horizontal, '性别') somePerson.setHeaderData(3, Qt.Horizontal, '民族') somePerson.setHeaderData(4, Qt.Horizontal, '出生日期') somePerson.setHeaderData(5, Qt.Horizontal, '住址') somePerson.setHeaderData(6, Qt.Horizontal, '发证机关') somePerson.setHeaderData(7, Qt.Horizontal, '有效期') somePerson.setHeaderData(8, Qt.Horizontal, '身份证照片地址') somePerson.setHeaderData(9, Qt.Horizontal, '人脸照片地址') somePerson.setHeaderData(10, Qt.Horizontal, '用户类型') somePerson.setHeaderData(11, Qt.Horizontal, '注册类型') somePerson.setHeaderData(12, Qt.Horizontal, '住建平台统一号') somePerson.setHeaderData(13, Qt.Horizontal, '住建平台工作号') somePerson.setHeaderData(14, Qt.Horizontal, '部门班组') somePerson.setHeaderData(15, Qt.Horizontal, '设备同步状态') somePerson.setHeaderData(16, Qt.Horizontal, '平台同步状态') somePerson.setHeaderData(17, Qt.Horizontal, '是否上传平台') somePerson.setHeaderData(18, Qt.Horizontal, '人员状态') self.tv_person.resizeColumnsToContents() @pyqtSlot() def on_pb_allData_clicked(self): '''方法作用为查询全部人员信息''' self.load() @pyqtSlot() def on_pb_uploadToDevice_clicked(self): '''方法作用为上传人员信息到人脸识别设备-授权''' qs = "select * from wis_person" persons = self.db.querySQL(qs) countP = persons.rowCount() if countP > 0: i = 0 while i < countP: dic = {} person = persons.record(i) dic['version'] = '0.2' dic['cmd'] = 'create_face' dic['per_id'] = person.field('idNo').value() dic['face_id'] = person.field('idNo').value() dic['per_name'] = person.field('name').value() # dic['idcardNum'] = person.field('idNo').value() dic['idcardper'] = person.field('idNo').value() dic['s_time'] = 0 dic['e_time'] = 10000 personStatus = person.field('personStatus').value() if personStatus == 1: dic['per_type'] = 0 else: dic['per_type'] = 2 dic['usr_type'] = 0 desImg = './photos_face/{}_face.jpg'.format(dic['per_id']) with open(desImg, 'rb') as f: bimg = base64.b64encode(f.read()) dic['img_data'] = bimg requests.post('http://127.0.0.1:8080/addFace', data=dic) time.sleep(1) i += 1 self.queryResult() QMessageBox.information(self, '提示', '增加人脸到设备完成,在数据中查看上传结果!', QMessageBox.Yes) @pyqtSlot() def on_pb_refresh_clicked(self): '''刷新本地数据''' qs = "select * from wis_person where personStatus = 1 and deviceStatus = 0" persons = self.db.querySQL(qs) countP = persons.rowCount() if countP > 0: i = 0 while i < countP: dic = {} person = persons.record(i) dic['version'] = '0.2' dic['cmd'] = 'query_face' dic['per_id'] = person.field('idNo').value() dic['id'] = 20 dic['name'] = '' requests.post('http://127.0.0.1:8080/queryFace', data=dic) time.sleep(1) i += 1 self.load() @pyqtSlot() def on_pb_uploadPerson_clicked(self): '''方法作用为上传本地人员信息到成都住建平台''' qs = "select * from wis_person where zjptStatus = 0 and uploadYN = 1 and personStatus = 1" uploadPersons = self.db.querySQL(qs) countP = uploadPersons.rowCount() if countP > 0: i = 0 while i < countP: person = uploadPersons.record(i) idNo = person.field('idNo').value() name = person.field('name').value() gender = person.field('gender').value() nation = person.field('nation').value() tbirthday = person.field('birthday').value() year = tbirthday[0:4] month = tbirthday[4:6] day = tbirthday[6:] birthday = year + '-' + month + '-' + day address = person.field('address').value() idissue = person.field('idissue').value() idperiod = person.field('idperiod').value() idphotoPath = person.field('idphoto').value() idphoto = jpgtostr(idphotoPath) photoPath = person.field('photo').value() photo = jpgtostr(photoPath) inf_photo = '' userType = person.field('userType').value() dev_mac = self.cjSN RegType = person.field('RegType').value() self.cdzj.person['idNo'] = idNo self.cdzj.person['name'] = name self.cdzj.person['gender'] = gender self.cdzj.person['nation'] = nation self.cdzj.person['birthday'] = birthday self.cdzj.person['address'] = address self.cdzj.person['idissue'] = idissue self.cdzj.person['idperiod'] = idperiod self.cdzj.person['idphoto'] = idphoto self.cdzj.person['photo'] = photo self.cdzj.person['inf_photo'] = inf_photo self.cdzj.person['userType'] = userType self.cdzj.person['dev_mac'] = dev_mac self.cdzj.person['RegType'] = RegType self.cdzj.uploadPerson() if self.cdzj.msg_uploadPerson == 'success': qs = "update wis_person set zjptStatus = 1 where idNo = '%s'" % idNo self.db.excuteSQl(qs) okMsg = "人员:%s,身份证号:%s,%s成功上传到平台\n" % ( name, idNo, datetime.datetime.now()) with open('uploadLog.txt', 'a') as f: f.write(okMsg) f.close() else: failMsg = "人员:%s,身份证号:%s,%s上传到平台失败,原因:%s\n" % ( name, idNo, datetime.datetime.now(), self.cdzj.msg_uploadPerson) with open('uploadLog.txt', 'a') as f: f.write(failMsg) f.close() i = i + 1 QMessageBox.information(self, '提示', '上传结束!', QMessageBox.Yes) else: QMessageBox.information(self, '提示', '当前没有需要上传的人员!', QMessageBox.Yes) @pyqtSlot() def on_pb_downloadPerson_clicked(self): '''方法作用从住建平台上下载已生成了住建平台号的人员信息''' runStatus = True progress = QProgressDialog(self) progress.setWindowTitle('请稍等') progress.setLabelText('数据下载中...') progress.setCancelButtonText('中止操作') progress.setWindowModality(Qt.WindowModal) progress.resize(800, 50) while runStatus: countD = self.faceDevices.rowCount() progress.setRange(0, countD) if countD > 0: i = 0 while i < countD: faces = self.faceDevices.record(i) sn = str.strip(faces.field('sn').value()) key = str.strip(faces.field('key').value()) self.cdzj.downloadPerson(sn, key) if self.cdzj.msg_downloadPerson == 'success': qs = "update wis_person set user_id = '%s', work_sn = '%s' where idNo = '%s'" % ( self.cdzj.person['user_id'], self.cdzj.person['work_sn'], self.cdzj.person['idNo']) self.db.excuteSQl(qs) selectQs = "select * from wis_person where idNo = '%s'" % self.cdzj.person[ 'idNo'] data = self.db.querySQL(selectQs) countP = data.rowCount() self.cdzj.feedback(sn, 2, '下发成功') progress.setValue(i) if progress.wasCanceled(): QMessageBox.warning(self, "提示", "操作失败") break # QMessageBox.information(self, '提示', '本次同步人员数:%d ' % countP, QMessageBox.Yes) else: runStatus = False progress.close() QMessageBox.information(self, '提示', '同步失败,原因:%s ' % self.cdzj.msg, QMessageBox.Yes) # self.cdzj.feedback('smz-a03', 3, '下发失败') break i += 1 else: progress.setValue(countD) QMessageBox.information(self, "提示", "操作成功") else: progress.deleteLater() QMessageBox.information(self, '提示', '未找到考勤设备!', QMessageBox.Yes) break @pyqtSlot() def on_pb_downloadDeletePerson_clicked(self): '''方法作用从住建平台上下载已删除的人员信息''' runStatus = True while runStatus: countd = self.faceDevices.rowCount() if countd > 0: i = 0 while i < countd: faces = self.faceDevices.record(i) sn = str.strip(faces.field('sn').value()) key = str.strip(faces.field('key').value()) self.cdzj.downloadDelPerson(sn, key) if self.cdzj.msg_downloadDelPerson == 'success': qs = "update wis_person set personStatus = 0 where idNo = '%s'" % self.cdzj.delPersonID self.db.excuteSQl(qs) self.cdzj.feedback(sn, 0, '人员删除成功') QMessageBox.information(self, '提示', '已同步需删除人员,请手工同步到设备!', QMessageBox.Yes) else: QMessageBox.information(self, '提示', '同步失败,原因:%s ' % self.cdzj.msg, QMessageBox.Yes) runStatus = False # self.cdzj.feedback('smz-a03', 1, '人员删除失败') i += 1 else: QMessageBox.information(self, '提示', '未找到考勤设备!', QMessageBox.Yes) break @pyqtSlot() def on_pb_deletePerson_clicked(self): '''方法作用删除已在平台上删除并在设备中删除的人员''' qs = "delete from wis_person where zjptStatus = 2" if QMessageBox.information(self, '提示', '你确认要删除所有在住建平台中已删除的人员?', QMessageBox.Yes | QMessageBox.No, QMessageBox.Yes) == QMessageBox.Yes: self.db.excuteSQl(qs) self.txtClear() self.load() def queryResult(self): '''用来处理增加人员后,更新增加人员的情况,同刷新本地数据''' qs = "select * from wis_person where personStatus = 1 and deviceStatus = 0" persons = self.db.querySQL(qs) countP = persons.rowCount() if countP > 0: i = 0 while i < countP: dic = {} person = persons.record(i) dic['version'] = '0.2' dic['cmd'] = 'query_face' dic['per_id'] = person.field('idNo').value() dic['id'] = 20 dic['name'] = '' requests.post('http://127.0.0.1:8080/queryFace', data=dic) time.sleep(1) i += 1 self.load()
class ResultHandle: def __init__(self, dic): self.dic = dic self.db = Dboperator() self.prepare() def prepare(self): last_result = self.dic['last_result'] if last_result != '1': lr = json.loads(last_result) print(lr) cmd = lr['cmd'] code = lr['code'] reply = lr['reply'] if cmd == 'create_face': if code == 0: print('人员增加成功!') else: print(reply) elif cmd == 'query_face': if code == 0: qs = "update wis_person set deviceStatus = 1 where idNo = '%s'" % lr[ 'per_id'] self.db.excuteSQl(qs) print('查询成功!') elif cmd == 'delete_face': if lr['code'] == 0: print('人员删除成功!') else: print(lr['reply']) elif cmd == 'update_face': print('update_face') elif cmd == 'reboot_cam': print('reboot_cam') elif cmd == 'ss_set_timing': print('ss_set_timing') elif cmd == 'set_spoofing': print('set_spoofing') elif cmd == 'set_attr': print('set_attr') elif cmd == 'set_voice_cfg': print('set_voice_cfg') elif cmd == 'set_sleep_time': print('set_sleep_time') elif cmd == 'set_reco_mode': print('set_reco_mode') elif cmd == 'set_hat_pass': print('set_hat_pass') elif cmd == 'set_face_mode': print('set_face_mode') elif cmd == 'error': print('命令错误') else: pass def addFaceHandle(self): print('处理人员增加成功后事宜')