def connect(self): # print(QSqlDatabase.drivers()) gl._init() self.db.setHostName(gl.get_value('HOSTNAME')) self.db.setPort(gl.get_value('PORT')) self.db.setDatabaseName(gl.get_value('DBNAME')) self.db.setUserName(gl.get_value('USRNAME')) self.db.setPassword(gl.get_value('PWD')) # self.db.setHostName('111.231.82.68') # self.db.setPort(8000) # self.db.setDatabaseName('suggestion') # self.db.setUserName('pentairSuggest') # self.db.setPassword('Zhao.jiayun_0217') if not self.db.open(): print(self.db.lastError().text())
def downloadq(self): q = QMessageBox.information(self, '即将开始下载', '开始下载后,下载过程可能会等待2秒,不要拼命点击', QMessageBox.Yes | QMessageBox.No, QMessageBox.No) if q == QMessageBox.Yes: self.connect = pymysql.connect(host=gl.get_value('HOSTNAME'), port=gl.get_value('PORT'), user=gl.get_value('USRNAME'), password=gl.get_value('PWD'), database=gl.get_value('DBNAME'), charset=gl.get_value('CHAR')) # 返回一个cursor对象,也就是游标对象 self.cursor = self.connect.cursor( cursor=pymysql.cursors.DictCursor) sql = "select questionresult.Id as id,dept1,dept2,dept3,cname,testdate,score,testtimes from questionresult left join userinfo on questionresult.eid=userinfo.eid where taskid=%d" % ( self.taskid) self.cursor.execute(sql) field = self.cursor.fetchall() if not field: QMessageBox.warning(self, '警告', '目前并无测试记录,请稍后再试') return data = pandas.DataFrame(field) pandas.DataFrame.to_csv(data.set_index("id", drop=True), os.getcwd() + "/" + self.lineEdit.text() + "测试结果.csv", encoding="utf_8_sig") QMessageBox.about(self, '注意', '文件已经下载到程序的同一目录,请注意查看')
def downloadsug(self): q = QMessageBox.information(self, '即将开始下载', '开始下载提案后,下载过程可能会等待2秒,不要拼命点击', QMessageBox.Yes | QMessageBox.No, QMessageBox.No) if q == QMessageBox.Yes: gl._init() self.connect = pymysql.connect(host=gl.get_value('HOSTNAME'), port=gl.get_value('PORT'), user=gl.get_value('USRNAME'), password=gl.get_value('PWD'), database=gl.get_value('DBNAME'), charset=gl.get_value('CHAR')) # 返回一个cursor对象,也就是游标对象 self.cursor = self.connect.cursor( cursor=pymysql.cursors.DictCursor) self.cursor.execute( "SELECT id as '提案ID',A.cname as '提案人',A.dept1 as '提案部门',idate as '提案日期',B.cname as '执行人',B.dept1 as '执行部门',content as '内容',status as '状态',acdate as '确认日期',duedate,cfdate as '完成日期',type as '类别',type2 as '类别2',fifi,cancel as 备注 FROM `suggest` left join `userinfo` as A on suggest.eid=A.eid left join `userinfo` as B on suggest.exeid=B.eid" ) field = self.cursor.fetchall() data = pandas.DataFrame(field) pandas.DataFrame.to_csv(data, os.getcwd() + "/suggest.csv", encoding="utf_8_sig", index=None) QMessageBox.about(self, '注意', '文件已经下载到程序的同一目录,请注意查看')
def setTableView(self): gl._init() self.db = QSqlDatabase.addDatabase('QMYSQL') self.db.setHostName(gl.get_value('HOSTNAME')) self.db.setPort(gl.get_value('PORT')) self.db.setDatabaseName(gl.get_value('DBNAME')) self.db.setUserName(gl.get_value('USRNAME')) self.db.setPassword(gl.get_value('PWD')) # 设置数据库名称 # self.db.setDatabaseName('./database.db') # 打开数据库 self.db.open() # 声明查询模型 self.queryModel = QSqlQueryModel(self) # 设置当前页 self.currentPage = 1 # 得到总记录数 self.totalRecrodCount = self.getTotalRecordCount() # 得到总页数 self.totalPage = self.getPageCount() # 刷新状态 self.updateStatus() # 设置总页数文本 self.setTotalPageLabel() # 设置总记录数 self.setTotalRecordLabel() # 记录查询 self.recordQuery(0) # 设置模型 self.tableView.setModel(self.queryModel) self.updateStatus() print('totalRecrodCount=' + str(self.totalRecrodCount)) print('totalPage=' + str(self.totalPage))