From e55e2ed1ceb92334c4f839642b3e68d8f4dceba6 Mon Sep 17 00:00:00 2001
From: wumu <mayi@mayi.com>
Date: 星期二, 19 九月 2023 00:16:13 +0800
Subject: [PATCH] 0919

---
 internal_system_v1/coverinfo.cpp |  159 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 157 insertions(+), 2 deletions(-)

diff --git a/internal_system_v1/coverinfo.cpp b/internal_system_v1/coverinfo.cpp
index 90569ed..f211e18 100644
--- a/internal_system_v1/coverinfo.cpp
+++ b/internal_system_v1/coverinfo.cpp
@@ -2,6 +2,7 @@
 #include "ui_coverinfo.h"
 #include <QDebug>
 #include <QDirIterator>
+#include <QFileDialog>
 #include <QSqlQuery>
 #include <QSqlRecord>
 
@@ -30,6 +31,17 @@
 //    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;
+    }
     QStringList list;
     QDirIterator it(dirPath, {"*.xls","*.xlsx"}, QDir::Files | QDir::NoSymLinks | QDir::NoDotAndDotDot, QDirIterator::Subdirectories);
     while(it.hasNext())
@@ -221,11 +233,145 @@
             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();
+        // 缁熶竴淇$敤浠g爜
+        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);
+        }
+        // 涓氬姟浠g爜
+        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);
+        // 鍖哄煙浠g爜
+        QVariant areaCode = valRows[24].toList().at(2);
+        if(areaCode.isValid()) ui->label_areaCode->setText(areaCode.toString());
+        // 鍩庝埂浠g爜
+        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());
+
+        // 濡傛灉鍗曚綅鏄柊澧炲姞鐨勶紝寰楀啓鍏ュ埌鏁版嵁搴撲腑淇濆瓨璧锋潵
+        readDataFromSQL(); // 鍐嶆璋冪敤API 纭鏁版嵁杩涘埌琛ㄤ腑
+
+    }
+    wbs->dynamicCall("Close()");
+    excel.dynamicCall("Quit(void)");
 }
 
 void CoverInfo::on_comboBox_currentIndexChanged(const QString &arg1)
@@ -260,3 +406,12 @@
         qDebug()<<"鍒囨崲鏌ヨ澶辫触:"<<arg1;
     }
 }
+
+void CoverInfo::on_pushButton_importExcel_clicked()
+{
+    QString path = QFileDialog::getOpenFileName(this,"閫夋嫨琛ㄦ牸:鍗曚綅鍙婂唴閮ㄥ璁℃満鏋勫熀鏈儏鍐佃〃","./","excel(*鍩烘湰鎯呭喌琛�*.xls)");
+    qDebug()<<"path:"<<path;
+    if(path.size() > 1){
+        readExcelFromPath(path);
+    }
+}

--
Gitblit v1.8.0