| | |
| | | #include "converinfo2.h" |
| | | #include "ui_converinfo2.h" |
| | | #include <QDebug> |
| | | #include <QDirIterator> |
| | | #include <QFileDialog> |
| | | #include <QSqlQuery> |
| | | #include <QSqlRecord> |
| | | |
| | | ConverInfo2::ConverInfo2(QWidget *parent) : |
| | | QMainWindow(parent), |
| | | ui(new Ui::ConverInfo2) |
| | | { |
| | | ui->setupUi(this); |
| | | initUi(); |
| | | m_menu = nullptr; |
| | | //initUi(); |
| | | readInfo(); // 加载表格 |
| | | addMenu(); // 增加菜单 |
| | | } |
| | | |
| | | ConverInfo2::~ConverInfo2() |
| | |
| | | { |
| | | qDebug()<<"双击"<<index; |
| | | } |
| | | |
| | | void ConverInfo2::readInfo() |
| | | { |
| | | // QXlsx::Document doc("./debug/Data/test.xlsx"); |
| | | // QString cc = doc.read("A1").toString(); |
| | | // qDebug()<<"cc"<<cc; |
| | | // ui->label_creditCode->setText(cc); |
| | | extern QString g_dataRootPath; |
| | | |
| | | 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()) |
| | | { |
| | | it.next(); |
| | | list.append(it.fileInfo().absoluteFilePath()); |
| | | } |
| | | foreach(QString str, list) |
| | | { |
| | | qDebug() << str; |
| | | int index = str.indexOf("内审统01表"); |
| | | qDebug()<<"index:"<<index; |
| | | if(index > 0){ |
| | | QAxObject excel("Excel.Application"); |
| | | excel.setProperty("Visible",false); |
| | | excel.setProperty("DisplayAlerts",false); |
| | | qDebug()<<"open:"<<str; |
| | | qDebug()<<"excel:"<<excel.className(); |
| | | QAxObject * wbs = excel.querySubObject("WorkBooks"); |
| | | QAxObject * wb = wbs->querySubObject("Open(QString&)",str); |
| | | //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(); |
| | | // 遍历每一项 |
| | | for(int i=0;i<rows;++i){ |
| | | QVariantList valrow = valRows[i].toList(); |
| | | for(int j=0;j<columns;++j){ |
| | | QVariant valData = valrow[j]; |
| | | if(valData.isValid()){ |
| | | qDebug()<<"val:"<< i<< j << valData; |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | // 实例化结构体,然后挨个赋值 |
| | | ComInfo curComInfo; |
| | | |
| | | // 统一信用代码 |
| | | QVariant uniCode = valRows[9].toList().at(3); |
| | | if(uniCode.isValid()){ |
| | | ui->label_creditCode->setText(uniCode.toString()); |
| | | strcpy(curComInfo.creditCode,uniCode.toString().toLocal8Bit().data()); |
| | | } |
| | | // 单位名称 |
| | | QVariant name = valRows[9].toList().at(8); |
| | | if(name.isValid()){ |
| | | ui->label_name->setText(name.toString()); |
| | | QTreeWidgetItem *top1 = new QTreeWidgetItem(ui->treeWidget); |
| | | top1->setText(0,name.toString()); |
| | | |
| | | }else{ |
| | | ui->label_name->setText(""); |
| | | } |
| | | // 机构类型 |
| | | QVariant comType = valRows[12].toList().at(3); |
| | | if(comType.isValid()){ |
| | | ui->label_comType->setText(comType.toString()); |
| | | strcpy(curComInfo.comType,comType.toString().toLocal8Bit().data()); |
| | | }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); |
| | | ui->label_business->setToolTip(business); |
| | | strcpy(curComInfo.business,business.toLocal8Bit().data()); |
| | | }else{ |
| | | ui->label_business->setText(""); |
| | | } |
| | | // 业务代码 |
| | | QVariant busCode = valRows[19].toList().at(4); |
| | | if(busCode.isValid()){ |
| | | ui->label_businessCode->setText(busCode.toString()); |
| | | strcpy(curComInfo.businessCode,busCode.toString().toLocal8Bit().data()); |
| | | }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); |
| | | strcpy(curComInfo.addr,addr.toLocal8Bit().data()); |
| | | }else{ |
| | | ui->label_addr->setText(""); |
| | | } |
| | | // 区域代码 |
| | | QVariant areaCode = valRows[24].toList().at(2); |
| | | if(areaCode.isValid()){ |
| | | ui->label_areaCode->setText(areaCode.toString()); |
| | | strcpy(curComInfo.areaCode,areaCode.toString().toLocal8Bit().data()); |
| | | }else{ |
| | | ui->label_areaCode->setText(""); |
| | | } |
| | | // 城乡代码 |
| | | QVariant townCode = valRows[24].toList().at(6); |
| | | if(townCode.isValid()) { |
| | | ui->label_townCode->setText(townCode.toString()); |
| | | strcpy(curComInfo.townCode,townCode.toString().toLocal8Bit().data()); |
| | | }else{ |
| | | ui->label_townCode->setText(""); |
| | | } |
| | | |
| | | // 单位规模 |
| | | QVariant scale = valRows[25].toList().at(3); |
| | | if(scale.isValid()){ |
| | | ui->label_scale->setText(scale.toString()); |
| | | strcpy(curComInfo.scale,scale.toString().toLocal8Bit().data()); |
| | | }else{ |
| | | ui->label_scale->setText(""); |
| | | } |
| | | // 从业人数 |
| | | QVariant people = valRows[26].toList().at(6); |
| | | if(people.isValid()) { |
| | | ui->label_people->setText(people.toString()); |
| | | //strcpy(curComInfo.people,people.toString().toLocal8Bit().data()); |
| | | curComInfo.people = people.toInt(); |
| | | }else{ |
| | | ui->label_people->setText(""); |
| | | } |
| | | // 法人 |
| | | QVariant representative = valRows[27].toList().at(4); |
| | | if(representative.isValid()) { |
| | | ui->label_representative->setText(representative.toString()); |
| | | strcpy(curComInfo.representative,representative.toString().toLocal8Bit().data()); |
| | | }else{ |
| | | ui->label_representative->setText(""); |
| | | } |
| | | // 会计标准类别 standardType |
| | | QVariant standardType = valRows[27].toList().at(8); |
| | | if(standardType.isValid()){ |
| | | ui->label_standardType->setText(standardType.toString()); |
| | | strcpy(curComInfo.standardType,standardType.toString().toLocal8Bit()); |
| | | }else{ |
| | | ui->label_standardType->setText(""); |
| | | } |
| | | // 长途区号 |
| | | QVariant trunkCode = valRows[31].toList().at(2); |
| | | if(trunkCode.isValid()){ |
| | | ui->label_trunkCode->setText(trunkCode.toString()); |
| | | strcpy(curComInfo.trunkCode,trunkCode.toString().toLocal8Bit().data()); |
| | | }else{ |
| | | ui->label_trunkCode->setText(""); |
| | | } |
| | | // 固定电话 |
| | | QVariant fixedTel = valRows[32].toList().at(2); |
| | | if(fixedTel.isValid()) { |
| | | ui->label_fixedTel->setText(fixedTel.toString()); |
| | | strcpy(curComInfo.fixedTel,fixedTel.toString().toLocal8Bit().data()); |
| | | }else{ |
| | | ui->label_fixedTel->setText(""); |
| | | } |
| | | // 邮政编码 |
| | | QVariant postCode = valRows[33].toList().at(2); |
| | | if(postCode.isValid()){ |
| | | ui->label_postCode->setText(postCode.toString()); |
| | | strcpy(curComInfo.postCode,postCode.toString().toLocal8Bit().data()); |
| | | }else{ |
| | | ui->label_postCode->setText(""); |
| | | } |
| | | // 电子邮箱 |
| | | QVariant email = valRows[30].toList().at(5); |
| | | if(email.isValid()) { |
| | | ui->label_email->setText(email.toString()); |
| | | strcpy(curComInfo.email,email.toString().toLocal8Bit().data()); |
| | | }else{ |
| | | ui->label_email->setText(""); |
| | | } |
| | | // 网址 |
| | | QVariant webSite = valRows[32].toList().at(5); |
| | | if(webSite.isValid()) { |
| | | ui->label_webSite->setText(webSite.toString()); |
| | | strcpy(curComInfo.webSite,webSite.toString().toLocal8Bit().data()); |
| | | }else{ |
| | | ui->label_webSite->setText(""); |
| | | } |
| | | |
| | | // 二、单位组织结构情况 |
| | | // 是否有上一级法人 |
| | | QVariant hasUpLegal = valRows[35].toList().at(4); |
| | | if(hasUpLegal.isValid()){ |
| | | strcpy(curComInfo.hasUpLegal,hasUpLegal.toString().toLocal8Bit().data()); |
| | | qDebug()<<"has up legal"<<hasUpLegal; |
| | | } |
| | | // 上级法人单位统一社会信用代码 |
| | | QVariant upCreditCode = valRows[36].toList().at(7); |
| | | if(upCreditCode.isValid()){ |
| | | strcpy(curComInfo.upCreditCode,upCreditCode.toString().toLocal8Bit().data()); |
| | | qDebug()<<"upCreditCode"<<upCreditCode; |
| | | }else { |
| | | qDebug()<<"upCreditCode fail"<<name; |
| | | } |
| | | // 原组织机构代码 |
| | | QVariant oldCreditCode = valRows[37].toList().at(7); |
| | | if(oldCreditCode.isValid()){ |
| | | strcpy(curComInfo.oldCreditCode,oldCreditCode.toString().toLocal8Bit().data()); |
| | | qDebug()<<"oldCreditCode"<<oldCreditCode; |
| | | } |
| | | // 上一级单位详细名称 |
| | | QVariant upName = valRows[38].toList().at(7); |
| | | if(upName.isValid()){ |
| | | strcpy(curComInfo.upName,upName.toString().toLocal8Bit().data()); |
| | | qDebug()<<"upName"<<upName; |
| | | } |
| | | |
| | | // 总审计师与内审机构基本情况 |
| | | |
| | | // 是否设置总审计师 |
| | | QVariant hasChiefDesigner = valRows[40].toList().at(4); |
| | | if(hasChiefDesigner.isValid()){ |
| | | strcpy(curComInfo.hasChiefDesigner,hasChiefDesigner.toString().toLocal8Bit().data()); |
| | | qDebug()<<"hasChiefDesigner"<<hasChiefDesigner; |
| | | } |
| | | // 总审计师职位层级 |
| | | QVariant ChiefDesignerLevel = valRows[41].toList().at(4); |
| | | if(ChiefDesignerLevel.isValid()){ |
| | | strcpy(curComInfo.ChiefDesignerLevel,ChiefDesignerLevel.toString().toLocal8Bit().data()); |
| | | qDebug()<<"ChiefDesignerLevel"<<ChiefDesignerLevel; |
| | | } |
| | | // 总审计师任职方式 |
| | | QVariant employmentMode = valRows[44].toList().at(4); |
| | | if(employmentMode.isValid()){ |
| | | strcpy(curComInfo.employmentMode,employmentMode.toString().toLocal8Bit().data()); |
| | | qDebug()<<"employmentMode"<<employmentMode; |
| | | } |
| | | |
| | | // 是否设置内审机构 |
| | | QVariant hasSetIntervalAudit = valRows[47].toList().at(4); |
| | | if(hasSetIntervalAudit.isValid()){ |
| | | strcpy(curComInfo.hasSetIntervalAudit,hasSetIntervalAudit.toString().toLocal8Bit().data()); |
| | | qDebug()<<"hasSetIntervalAudit"<<hasSetIntervalAudit; |
| | | } |
| | | // 内审机构名称 |
| | | QVariant internalName = valRows[48].toList().at(4); |
| | | if(internalName.isValid()){ |
| | | strcpy(curComInfo.internalName,internalName.toString().toLocal8Bit().data()); |
| | | qDebug()<<"internalName"<<internalName; |
| | | } |
| | | // 内审工作的领导机构 |
| | | QVariant leadingOrganization = valRows[49].toList().at(4); |
| | | if(leadingOrganization.isValid()){ |
| | | strcpy(curComInfo.leadingOrganization,leadingOrganization.toString().toLocal8Bit().data()); |
| | | qDebug()<<"leadingOrganization"<<leadingOrganization; |
| | | } |
| | | // 是否独立设置内审机构 |
| | | QVariant hasSetSeparateIA = valRows[53].toList().at(4); |
| | | if(hasSetSeparateIA.isValid()){ |
| | | strcpy(curComInfo.hasSetSeparateIA,hasSetSeparateIA.toString().toLocal8Bit().data()); |
| | | qDebug()<<"hasSetSeparateIA"<<hasSetSeparateIA; |
| | | } |
| | | // 合并设置 财务部门 |
| | | QVariant financeDepartment = valRows[55].toList().at(4); |
| | | if(financeDepartment.isValid()){ |
| | | //strcpy(curComInfo.financeDepartment,financeDepartment.toString().toLocal8Bit().data()); |
| | | curComInfo.financeDepartment = financeDepartment.toBool(); |
| | | qDebug()<<"financeDepartment"<<financeDepartment; |
| | | } |
| | | // 法务部门、内部控制部门、纪检部门、其他部门 |
| | | |
| | | // 内审机构层级 |
| | | QVariant intavalAuditLeval = valRows[56].toList().at(4); |
| | | if(intavalAuditLeval.isValid()){ |
| | | strcpy(curComInfo.intavalAuditLeval,intavalAuditLeval.toString().toLocal8Bit().data()); |
| | | qDebug()<<"intavalAuditLeval"<<intavalAuditLeval; |
| | | } |
| | | |
| | | // 最后存到map中 |
| | | m_nameAndComInfos[name.toString()]=curComInfo; |
| | | |
| | | } |
| | | wbs->dynamicCall("Close()"); |
| | | excel.dynamicCall("Quit(void)"); |
| | | |
| | | qDebug()<<"单位信息数量:"<<m_nameAndComInfos.size(); |
| | | } |
| | | } |
| | | |
| | | |
| | | // QAxObject excel("./debug/Data/附件2_内审统01表_单位及内部审计机构基本情况表-1.301版(1).xls"); |
| | | // excel.setProperty("Visible",true); |
| | | // excel.setProperty("DisplayAlerts",false); |
| | | |
| | | } |
| | | |
| | | void ConverInfo2::addMenu() |
| | | { |
| | | // 设置菜单:添加单位、删除单位 |
| | | if(m_menu==nullptr){ |
| | | m_menu = new QMenu(this); |
| | | qDebug()<<"init menu ok"; |
| | | } |
| | | |
| | | m_menu->addAction("删除"); |
| | | m_menu->addAction("增加"); |
| | | |
| | | ui->treeWidget->setContextMenuPolicy(Qt::CustomContextMenu); |
| | | connect(ui->treeWidget,SIGNAL(customContextMenuRequested(QPoint)),this,SLOT(showMenu(QPoint))); |
| | | |
| | | connect(m_menu->actions().at(0),SIGNAL(triggered(bool)),this,SLOT(deleteInfo())); |
| | | connect(m_menu->actions().at(1),SIGNAL(triggered(bool)),this,SLOT(addInfo())); |
| | | } |