| | |
| | | #include "coverinfo.h" |
| | | #include "coverinfo.h" |
| | | #include "ui_coverinfo.h" |
| | | #include <QDebug> |
| | | #include <QDirIterator> |
| | | #include <QFileDialog> |
| | | #include <QSqlQuery> |
| | | #include <QSqlRecord> |
| | | |
| | | int g_comId = 0; // 全局变量,保存单位id |
| | | QString g_dataRootPath; // 数据的根目录 |
| | | |
| | | CoverInfo::CoverInfo(QWidget *parent) : |
| | | QMainWindow(parent), |
| | |
| | | // ui->label_creditCode->setText(cc); |
| | | |
| | | QString dirPath = "./debug/Data"; |
| | | QString dirPathRelease = "./release/Data"; |
| | | QString dirPathData = "./Data"; |
| | | QDir dir(dirPathData); |
| | | if(dir.exists()){ |
| | | dirPath = dirPathData; // 存在则覆盖 |
| | | } |
| | | |
| | | QDir dirRe(dirPathRelease); |
| | | if(dirRe.exists()){ |
| | | dirPath = dirPathRelease; |
| | | } |
| | | g_dataRootPath = dirPath; // 将根目录保存起来 |
| | | QStringList list; |
| | | QDirIterator it(dirPath, {"*.xls","*.xlsx"}, QDir::Files | QDir::NoSymLinks | QDir::NoDotAndDotDot, QDirIterator::Subdirectories); |
| | | while(it.hasNext()) |
| | |
| | | QVariant name = valRows[9].toList().at(8); |
| | | if(name.isValid()){ |
| | | ui->label_name->setText(name.toString()); |
| | | }else{ |
| | | ui->label_name->setText(""); |
| | | } |
| | | // 机构类型 |
| | | QVariant comType = valRows[12].toList().at(3); |
| | | if(comType.isValid()){ |
| | | ui->label_comType->setText(comType.toString()); |
| | | }else{ |
| | | ui->label_comType->setText(""); |
| | | } |
| | | // 主要业务活动 |
| | | QString business; |
| | |
| | | } |
| | | if(business.size() > 0){ |
| | | ui->label_business->setText(business); |
| | | ui->label_business->setToolTip(business); |
| | | }else{ |
| | | ui->label_business->setText(""); |
| | | } |
| | | // 业务代码 |
| | | QVariant busCode = valRows[19].toList().at(4); |
| | | if(busCode.isValid()){ |
| | | ui->label_businessCode->setText(busCode.toString()); |
| | | }else{ |
| | | ui->label_businessCode->setText(""); |
| | | } |
| | | // 注册地址 |
| | | QString addr=""; |
| | |
| | | if(street.isValid()) addr += street.toString(); |
| | | if(Sub.isValid()) addr += Sub.toString(); |
| | | if(committee.isValid()) addr += committee.toString(); |
| | | if(addr.size()>10)ui->label_addr->setText(addr); |
| | | if(addr.size()>10){ |
| | | ui->label_addr->setText(addr); |
| | | }else{ |
| | | ui->label_addr->setText(""); |
| | | } |
| | | // 区域代码 |
| | | QVariant areaCode = valRows[24].toList().at(2); |
| | | if(areaCode.isValid()) ui->label_areaCode->setText(areaCode.toString()); |
| | | if(areaCode.isValid()){ |
| | | ui->label_areaCode->setText(areaCode.toString()); |
| | | }else{ |
| | | ui->label_areaCode->setText(""); |
| | | } |
| | | // 城乡代码 |
| | | QVariant townCode = valRows[24].toList().at(6); |
| | | if(townCode.isValid()) ui->label_townCode->setText(townCode.toString()); |
| | | if(townCode.isValid()) { |
| | | ui->label_townCode->setText(townCode.toString()); |
| | | }else{ |
| | | ui->label_townCode->setText(""); |
| | | } |
| | | |
| | | // 单位规模 |
| | | QVariant scale = valRows[25].toList().at(3); |
| | | if(scale.isValid()) ui->label_scale->setText(scale.toString()); |
| | | if(scale.isValid()){ |
| | | ui->label_scale->setText(scale.toString()); |
| | | }else{ |
| | | ui->label_scale->setText(""); |
| | | } |
| | | // 从业人数 |
| | | QVariant people = valRows[26].toList().at(6); |
| | | if(people.isValid()) ui->label_people->setText(people.toString()); |
| | | if(people.isValid()) { |
| | | ui->label_people->setText(people.toString()); |
| | | }else{ |
| | | ui->label_people->setText(""); |
| | | } |
| | | // 法人 |
| | | QVariant representative = valRows[27].toList().at(4); |
| | | if(representative.isValid()) ui->label_representative->setText(representative.toString()); |
| | | if(representative.isValid()) { |
| | | ui->label_representative->setText(representative.toString()); |
| | | }else{ |
| | | ui->label_representative->setText(""); |
| | | } |
| | | // 会计标准类别 standardType |
| | | QVariant standardType = valRows[27].toList().at(8); |
| | | if(standardType.isValid()) ui->label_standardType->setText(standardType.toString()); |
| | | if(standardType.isValid()){ |
| | | ui->label_standardType->setText(standardType.toString()); |
| | | }else{ |
| | | ui->label_standardType->setText(""); |
| | | } |
| | | // 长途区号 |
| | | QVariant trunkCode = valRows[31].toList().at(2); |
| | | if(trunkCode.isValid()) ui->label_trunkCode->setText(trunkCode.toString()); |
| | | if(trunkCode.isValid()){ |
| | | ui->label_trunkCode->setText(trunkCode.toString()); |
| | | }else{ |
| | | ui->label_trunkCode->setText(""); |
| | | } |
| | | // 固定电话 |
| | | QVariant fixedTel = valRows[32].toList().at(2); |
| | | if(fixedTel.isValid()) ui->label_fixedTel->setText(fixedTel.toString()); |
| | | if(fixedTel.isValid()) { |
| | | ui->label_fixedTel->setText(fixedTel.toString()); |
| | | }else{ |
| | | ui->label_fixedTel->setText(""); |
| | | } |
| | | // 邮政编码 |
| | | QVariant postCode = valRows[33].toList().at(2); |
| | | if(postCode.isValid()) ui->label_postCode->setText(postCode.toString()); |
| | | if(postCode.isValid()){ |
| | | ui->label_postCode->setText(postCode.toString()); |
| | | }else{ |
| | | ui->label_postCode->setText(""); |
| | | } |
| | | // 电子邮箱 |
| | | QVariant email = valRows[30].toList().at(5); |
| | | if(email.isValid()) ui->label_email->setText(email.toString()); |
| | | if(email.isValid()) { |
| | | ui->label_email->setText(email.toString()); |
| | | }else{ |
| | | ui->label_email->setText(""); |
| | | } |
| | | // 网址 |
| | | QVariant webSite = valRows[32].toList().at(5); |
| | | if(webSite.isValid()) ui->label_webSite->setText(webSite.toString()); |
| | | if(webSite.isValid()) { |
| | | ui->label_webSite->setText(webSite.toString()); |
| | | }else{ |
| | | ui->label_webSite->setText(""); |
| | | } |
| | | } |
| | | wbs->dynamicCall("Close()"); |
| | | excel.dynamicCall("Quit(void)"); |
| | |
| | | int id = query.value(0).toInt(); |
| | | QString name = query.value(1).toString(); |
| | | qDebug()<<"com select:"<<id<<name; |
| | | m_com[name] = id; |
| | | ui->comboBox->addItem(name); |
| | | bool isInBox = false; |
| | | for(int i=0;i<ui->comboBox->count();++i){ |
| | | if(ui->comboBox->itemText(i) == name){ |
| | | isInBox = true; |
| | | break; |
| | | } |
| | | } |
| | | if(!isInBox){ |
| | | m_com[name] = id; |
| | | ui->comboBox->addItem(name); |
| | | emit sendComName(name); |
| | | ui->comboBox->setCurrentText(name); |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | void CoverInfo::readExcelFromPath(QString path) |
| | | { |
| | | QAxObject excel("Excel.Application"); |
| | | excel.setProperty("Visible",false); |
| | | excel.setProperty("DisplayAlerts",false); |
| | | qDebug()<<"open:"<<path; |
| | | qDebug()<<"excel:"<<excel.className(); |
| | | QAxObject * wbs = excel.querySubObject("WorkBooks"); |
| | | QAxObject * wb = wbs->querySubObject("Open(QString&)",path); |
| | | //QAxObject* pWorkBook = excel.querySubObject("ActiveWorkBook"); |
| | | //QAxObject* pWorkSheets = pWorkBook->querySubObject("Sheets");//获取工作表 |
| | | QAxObject * shs = wb->querySubObject("Sheets"); // WorkSheets 也可以 |
| | | int cnt = shs->property("Count").toInt(); |
| | | qDebug()<<"cnt="<<cnt; |
| | | for(int i=0;i<cnt;++i){ |
| | | QAxObject * sheet = shs->querySubObject("Item(int)", i+1); |
| | | QString sheetName = sheet->property("Name").toString(); |
| | | qDebug()<<"sh name:"<<sheetName; |
| | | QAxObject *usedRange = sheet->querySubObject("UsedRange"); |
| | | int rows = usedRange->querySubObject("Rows")->property("Count").toInt(); |
| | | int columns = usedRange->querySubObject("Columns")->property("Count").toInt(); |
| | | qDebug()<<"r--c:"<<rows<<columns; |
| | | QVariant val = usedRange->dynamicCall("Value"); // 拿到二维表格 |
| | | QVariantList valRows = val.toList(); |
| | | // 统一信用代码 |
| | | // QVariant uniCode = valRows[9].toList().at(3); |
| | | // if(uniCode.isValid()){ |
| | | // ui->label_creditCode->setText(uniCode.toString()); |
| | | // } |
| | | // // 单位名称 |
| | | // QVariant name = valRows[9].toList().at(8); |
| | | // if(name.isValid()){ |
| | | // ui->label_name->setText(name.toString()); |
| | | // } |
| | | // // 机构类型 |
| | | // QVariant comType = valRows[12].toList().at(3); |
| | | // if(comType.isValid()){ |
| | | // ui->label_comType->setText(comType.toString()); |
| | | // } |
| | | // // 主要业务活动 |
| | | // QString business; |
| | | // QVariant first = valRows[18].toList().at(2); |
| | | // if(first.isValid()){ |
| | | // business.append(first.toString()); |
| | | // } |
| | | // QVariant sec = valRows[18].toList().at(5); |
| | | // if(sec.isValid()){ |
| | | // business += "、"; |
| | | // business.append(sec.toString()); |
| | | // } |
| | | // QVariant third = valRows[18].toList().at(8); |
| | | // if(third.isValid()){ |
| | | // business += "、"; |
| | | // business.append(third.toString()); |
| | | // } |
| | | // if(business.size() > 0){ |
| | | // ui->label_business->setText(business); |
| | | // } |
| | | // // 业务代码 |
| | | // QVariant busCode = valRows[19].toList().at(4); |
| | | // if(busCode.isValid()){ |
| | | // ui->label_businessCode->setText(busCode.toString()); |
| | | // } |
| | | // // 注册地址 |
| | | // QString addr=""; |
| | | // QVariant province = valRows[21].toList().at(1); // 省份 |
| | | // QVariant city = valRows[21].toList().at(4); // 城市 |
| | | // QVariant district = valRows[21].toList().at(7); // 管辖区 |
| | | // QVariant village = valRows[22].toList().at(2); // 乡镇 |
| | | // QVariant street = valRows[22].toList().at(4); // 街道 |
| | | // QVariant Sub = valRows[23].toList().at(2); // 街道办事处 |
| | | // QVariant committee = valRows[25].toList().at(3); // 居委会 |
| | | // //qDebug()<<province<<city<<district<<village<<street<<Sub<<committee; |
| | | // if(province.isValid()) addr += province.toString(); |
| | | // if(city.isValid()) addr += city.toString(); |
| | | // if(district.isValid()) addr += district.toString(); |
| | | // if(village.isValid()) addr += village.toString(); |
| | | // if(street.isValid()) addr += street.toString(); |
| | | // if(Sub.isValid()) addr += Sub.toString(); |
| | | // if(committee.isValid()) addr += committee.toString(); |
| | | // if(addr.size()>10)ui->label_addr->setText(addr); |
| | | // // 区域代码 |
| | | // QVariant areaCode = valRows[24].toList().at(2); |
| | | // if(areaCode.isValid()) ui->label_areaCode->setText(areaCode.toString()); |
| | | // // 城乡代码 |
| | | // QVariant townCode = valRows[24].toList().at(6); |
| | | // if(townCode.isValid()) ui->label_townCode->setText(townCode.toString()); |
| | | // // 单位规模 |
| | | // QVariant scale = valRows[25].toList().at(3); |
| | | // if(scale.isValid()) ui->label_scale->setText(scale.toString()); |
| | | // // 从业人数 |
| | | // QVariant people = valRows[26].toList().at(6); |
| | | // if(people.isValid()) ui->label_people->setText(people.toString()); |
| | | // // 法人 |
| | | // QVariant representative = valRows[27].toList().at(4); |
| | | // if(representative.isValid()) ui->label_representative->setText(representative.toString()); |
| | | // // 会计标准类别 standardType |
| | | // QVariant standardType = valRows[27].toList().at(8); |
| | | // if(standardType.isValid()) ui->label_standardType->setText(standardType.toString()); |
| | | // // 长途区号 |
| | | // QVariant trunkCode = valRows[31].toList().at(2); |
| | | // if(trunkCode.isValid()) ui->label_trunkCode->setText(trunkCode.toString()); |
| | | // // 固定电话 |
| | | // QVariant fixedTel = valRows[32].toList().at(2); |
| | | // if(fixedTel.isValid()) ui->label_fixedTel->setText(fixedTel.toString()); |
| | | // // 邮政编码 |
| | | // QVariant postCode = valRows[33].toList().at(2); |
| | | // if(postCode.isValid()) ui->label_postCode->setText(postCode.toString()); |
| | | // // 电子邮箱 |
| | | // QVariant email = valRows[30].toList().at(5); |
| | | // if(email.isValid()) ui->label_email->setText(email.toString()); |
| | | // // 网址 |
| | | // QVariant webSite = valRows[32].toList().at(5); |
| | | // if(webSite.isValid()) ui->label_webSite->setText(webSite.toString()); |
| | | |
| | | // 统一信用代码 |
| | | QVariant uniCode = valRows[9].toList().at(3); |
| | | if(uniCode.isValid()){ |
| | | ui->label_creditCode->setText(uniCode.toString()); |
| | | } |
| | | // 单位名称 |
| | | QVariant name = valRows[9].toList().at(8); |
| | | if(name.isValid()){ |
| | | ui->label_name->setText(name.toString()); |
| | | }else{ |
| | | ui->label_name->setText(""); |
| | | } |
| | | // 机构类型 |
| | | QVariant comType = valRows[12].toList().at(3); |
| | | if(comType.isValid()){ |
| | | ui->label_comType->setText(comType.toString()); |
| | | }else{ |
| | | ui->label_comType->setText(""); |
| | | } |
| | | // 主要业务活动 |
| | | QString business; |
| | | QVariant first = valRows[18].toList().at(2); |
| | | if(first.isValid()){ |
| | | business.append(first.toString()); |
| | | } |
| | | QVariant sec = valRows[18].toList().at(5); |
| | | if(sec.isValid()){ |
| | | business += "、"; |
| | | business.append(sec.toString()); |
| | | } |
| | | QVariant third = valRows[18].toList().at(8); |
| | | if(third.isValid()){ |
| | | business += "、"; |
| | | business.append(third.toString()); |
| | | } |
| | | if(business.size() > 0){ |
| | | ui->label_business->setText(business); |
| | | }else{ |
| | | ui->label_business->setText(""); |
| | | } |
| | | // 业务代码 |
| | | QVariant busCode = valRows[19].toList().at(4); |
| | | if(busCode.isValid()){ |
| | | ui->label_businessCode->setText(busCode.toString()); |
| | | }else{ |
| | | ui->label_businessCode->setText(""); |
| | | } |
| | | // 注册地址 |
| | | QString addr=""; |
| | | QVariant province = valRows[21].toList().at(1); // 省份 |
| | | QVariant city = valRows[21].toList().at(4); // 城市 |
| | | QVariant district = valRows[21].toList().at(7); // 管辖区 |
| | | QVariant village = valRows[22].toList().at(2); // 乡镇 |
| | | QVariant street = valRows[22].toList().at(4); // 街道 |
| | | QVariant Sub = valRows[23].toList().at(2); // 街道办事处 |
| | | QVariant committee = valRows[25].toList().at(3); // 居委会 |
| | | //qDebug()<<province<<city<<district<<village<<street<<Sub<<committee; |
| | | if(province.isValid()) addr += province.toString(); |
| | | if(city.isValid()) addr += city.toString(); |
| | | if(district.isValid()) addr += district.toString(); |
| | | if(village.isValid()) addr += village.toString(); |
| | | if(street.isValid()) addr += street.toString(); |
| | | if(Sub.isValid()) addr += Sub.toString(); |
| | | if(committee.isValid()) addr += committee.toString(); |
| | | if(addr.size()>10){ |
| | | ui->label_addr->setText(addr); |
| | | }else{ |
| | | ui->label_addr->setText(""); |
| | | } |
| | | // 区域代码 |
| | | QVariant areaCode = valRows[24].toList().at(2); |
| | | if(areaCode.isValid()){ |
| | | ui->label_areaCode->setText(areaCode.toString()); |
| | | }else{ |
| | | ui->label_areaCode->setText(""); |
| | | } |
| | | // 城乡代码 |
| | | QVariant townCode = valRows[24].toList().at(6); |
| | | if(townCode.isValid()) { |
| | | ui->label_townCode->setText(townCode.toString()); |
| | | }else{ |
| | | ui->label_townCode->setText(""); |
| | | } |
| | | |
| | | // 单位规模 |
| | | QVariant scale = valRows[25].toList().at(3); |
| | | if(scale.isValid()){ |
| | | ui->label_scale->setText(scale.toString()); |
| | | }else{ |
| | | ui->label_scale->setText(""); |
| | | } |
| | | // 从业人数 |
| | | QVariant people = valRows[26].toList().at(6); |
| | | if(people.isValid()) { |
| | | ui->label_people->setText(people.toString()); |
| | | }else{ |
| | | ui->label_people->setText(""); |
| | | } |
| | | // 法人 |
| | | QVariant representative = valRows[27].toList().at(4); |
| | | if(representative.isValid()) { |
| | | ui->label_representative->setText(representative.toString()); |
| | | }else{ |
| | | ui->label_representative->setText(""); |
| | | } |
| | | // 会计标准类别 standardType |
| | | QVariant standardType = valRows[27].toList().at(8); |
| | | if(standardType.isValid()){ |
| | | ui->label_standardType->setText(standardType.toString()); |
| | | }else{ |
| | | ui->label_standardType->setText(""); |
| | | } |
| | | // 长途区号 |
| | | QVariant trunkCode = valRows[31].toList().at(2); |
| | | if(trunkCode.isValid()){ |
| | | ui->label_trunkCode->setText(trunkCode.toString()); |
| | | }else{ |
| | | ui->label_trunkCode->setText(""); |
| | | } |
| | | // 固定电话 |
| | | QVariant fixedTel = valRows[32].toList().at(2); |
| | | if(fixedTel.isValid()) { |
| | | ui->label_fixedTel->setText(fixedTel.toString()); |
| | | }else{ |
| | | ui->label_fixedTel->setText(""); |
| | | } |
| | | // 邮政编码 |
| | | QVariant postCode = valRows[33].toList().at(2); |
| | | if(postCode.isValid()){ |
| | | ui->label_postCode->setText(postCode.toString()); |
| | | }else{ |
| | | ui->label_postCode->setText(""); |
| | | } |
| | | // 电子邮箱 |
| | | QVariant email = valRows[30].toList().at(5); |
| | | if(email.isValid()) { |
| | | ui->label_email->setText(email.toString()); |
| | | }else{ |
| | | ui->label_email->setText(""); |
| | | } |
| | | // 网址 |
| | | QVariant webSite = valRows[32].toList().at(5); |
| | | if(webSite.isValid()) { |
| | | ui->label_webSite->setText(webSite.toString()); |
| | | }else{ |
| | | ui->label_webSite->setText(""); |
| | | } |
| | | |
| | | // 如果单位是新增加的,得写入到数据库中保存起来 |
| | | readDataFromSQL(); // 再次调用API 确认数据进到表中 |
| | | |
| | | } |
| | | wbs->dynamicCall("Close()"); |
| | | excel.dynamicCall("Quit(void)"); |
| | | } |
| | | |
| | | void CoverInfo::on_comboBox_currentIndexChanged(const QString &arg1) |
| | |
| | | qDebug()<<"切换查询失败:"<<arg1; |
| | | } |
| | | } |
| | | |
| | | void CoverInfo::on_pushButton_importExcel_clicked() |
| | | { |
| | | QString path = QFileDialog::getOpenFileName(this,"选择表格:单位及内部审计机构基本情况表","./","excel(*基本情况表*.xls)"); |
| | | qDebug()<<"path:"<<path; |
| | | if(path.size() > 1){ |
| | | readExcelFromPath(path); |
| | | } |
| | | } |