From 6ea2769d53615984e57b26b63b8d56b49c472e26 Mon Sep 17 00:00:00 2001
From: wumu <mayi@mayi.com>
Date: 星期三, 13 九月 2023 22:44:13 +0800
Subject: [PATCH] 0913

---
 internal_system_v1/searchinfo.cpp |  113 +++++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 102 insertions(+), 11 deletions(-)

diff --git a/internal_system_v1/searchinfo.cpp b/internal_system_v1/searchinfo.cpp
index 2b931ad..1d5265e 100644
--- a/internal_system_v1/searchinfo.cpp
+++ b/internal_system_v1/searchinfo.cpp
@@ -1,6 +1,8 @@
 #include "searchinfo.h"
 #include "ui_searchinfo.h"
+#include <QAxObject>
 #include <QDebug>
+#include <QDir>
 #include <QSqlError>
 #include <QSqlQuery>
 
@@ -9,15 +11,18 @@
     ui(new Ui::SearchInfo)
 {
     ui->setupUi(this);
-    ui->label_2->hide();
-    ui->label_3->hide();
-    ui->dateTimeEdit->hide();
-    ui->dateTimeEdit_2->hide();
+//    ui->label_2->hide();
+//    ui->label_3->hide();
+//    ui->dateTimeEdit->hide();
+//    ui->dateTimeEdit_2->hide();
 
     m_model = new QStandardItemModel(this);
     ui->tableView->setModel(m_model);
     ui->tableView->verticalHeader()->setVisible(false); // 闅愯棌琛屽ご
-
+    m_model->setColumnCount(5);
+    QStringList labels;
+    labels<<"ID"<<"鎸囨爣鍚嶇О"<<"浠g爜"<<"鏁伴噺"<<"鍏徃缂栧彿";
+    m_model->setHorizontalHeaderLabels(labels);
     if(QSqlDatabase::contains("qt_sql_default_connection")){
         m_db = QSqlDatabase::addDatabase("qt_sql_default_connection");
     }else{
@@ -32,7 +37,8 @@
     }else{
         qDebug()<<"db open fail";
     }
-
+    // 璁剧疆琛ㄦ牸鍒楁爣绛�
+    setLabels();
 
 }
 
@@ -199,6 +205,39 @@
     }
 }
 
+QVector<QVector<QString>> SearchInfo::getResult(QString &sql,int colCnt)
+{
+    QVector<QVector<QString>> resultSet;
+    QSqlQuery query;
+    qDebug()<<sql;
+    if(query.exec(sql)){
+        while (query.next()) {
+            QVector<QString> tmp;
+            for(int i=0;i<colCnt;++i){
+                tmp.push_back(query.value(i).toString());
+            }
+            resultSet.append(tmp);
+        }
+    }
+    return resultSet;
+}
+
+void SearchInfo::setLabels()
+{
+    QStringList labels,labels2,labels3;
+    labels<<"ID"<<"鎸囨爣鍚嶇О"<<"浠g爜"<<"鏁伴噺"<<"鍏徃缂栧彿"<<" ";
+    labels2<<"ID"<<"鎸囨爣鍚嶇О"<<"浠g爜"<<"鍗曚綅"<<"鏁伴噺"<<"鍏徃缂栧彿";
+    labels3<<"ID"<<"鎸囨爣鍚嶇О"<<"浠g爜"<<"鏁伴噺"<<"浣愯瘉"<<"鍏徃缂栧彿";
+    m_labels["瀹¤椤圭洰"] = labels;
+    m_labels["鍐呭宸ヤ綔閲�"] = labels;
+    m_labels["闂閲戦"] = labels3;
+    m_labels["闂涓暟"] = labels3;
+    m_labels["闂鏁存敼"] = labels3;
+    m_labels["闂鏁存敼--闈為噾棰�"] = labels3;
+    m_labels["澶勫垎"] = labels;
+    m_labels["妗堜欢绾跨储"] = labels2;
+}
+
 void SearchInfo::on_pushButton_search_clicked()
 {
     // 鑾峰彇淇℃伅锛岀劧鍚庢煡璇�
@@ -215,12 +254,64 @@
             rowCnt++;
             m_model->setRowCount(rowCnt);
             qDebug()<<query.value(0).toInt();
-            m_model->setItem(rowCnt-1,0,new QStandardItem(query.value(0).toString()));
-            m_model->setItem(rowCnt-1,1,new QStandardItem(query.value(1).toString()));
-            m_model->setItem(rowCnt-1,2,new QStandardItem(query.value(2).toString()));
-            m_model->setItem(rowCnt-1,3,new QStandardItem(query.value(3).toString()));
-            m_model->setItem(rowCnt-1,4,new QStandardItem(query.value(4).toString()));
+            for(int i=0;i<6;++i){
+                if(query.value(i).isValid()){
+                    m_model->setItem(rowCnt-1,i,new QStandardItem(query.value(i).toString()));
+                }
+            }
+
         }
     }
 
 }
+
+void SearchInfo::on_pushButton_export_clicked()
+{
+    // 姣忎竴寮犺〃鎷挎渶鏂扮殑閭d竴鎵规暟鎹嵆鍙紝鐒跺悗淇濆瓨鍒扮數瀛愯〃鏍间腑
+    int comId = m_comInfo[ui->comboBox_company->currentText()];
+    QString audit_project = QString("select kpi_name,code,num from %2 where com_id=%1 limit 10").arg(comId).arg("audit_project");
+    QString audit_workload = QString("select kpi_name,code,num from %2 where com_id=%1 limit 1").arg(comId).arg("audit_workload");
+    QString case_clue = QString("select kpi_name,code,unit,num from %2 where com_id=%1 limit 2").arg(comId).arg("case_clue");
+    QString problem_count = QString("select kpi_name,code,num,evidences from %2 where com_id=%1 limit 7").arg(comId).arg("problem_count");
+    QString problem_money = QString("select kpi_name,code,num,evidences from %2 where com_id=%1 limit 11").arg(comId).arg("problem_money");
+    QString problem_no_money = QString("select kpi_name,code,num,evidences from %2 where com_id=%1 limit 5").arg(comId).arg("problem_no_money");
+    QString problem_rectification = QString("select kpi_name,code,num,evidences from %2 where com_id=%1 limit 7").arg(comId).arg("problem_rectification");
+    QString punish = QString("select kpi_name,code,num from %2 where com_id=%1 limit 4").arg(comId).arg("punish");
+
+    QVector<QVector<QString>> audit_project_res = getResult(audit_project,3);
+    QVector<QVector<QString>> audit_workload_res = getResult(audit_workload,3);
+    QVector<QVector<QString>> case_clue_res = getResult(case_clue,4);
+    QVector<QVector<QString>> problem_count_res = getResult(problem_count,4);
+    QVector<QVector<QString>> problem_money_res = getResult(problem_money,4);
+    QVector<QVector<QString>> problem_no_money_res = getResult(problem_no_money,4);
+    QVector<QVector<QString>> problem_rectification_res = getResult(problem_rectification,4);
+    QVector<QVector<QString>> punish_res = getResult(punish,3);
+    qDebug()<<audit_project_res.size()<<punish_res.size();
+
+    // 鎿嶄綔excel
+    QAxObject* excel = new QAxObject("Excel.Application");  // 鍒涘缓Excel瀵硅薄
+    excel->setProperty("Visible", false);  // 璁剧疆Excel涓嶅彲瑙�
+    QAxObject* workbooks = excel->querySubObject("Workbooks");  // 鑾峰彇鎵�鏈夊伐浣滅翱
+    QAxObject* workbook = workbooks->querySubObject("Add");  // 娣诲姞鏂板伐浣滅翱
+    QAxObject* worksheets = workbook->querySubObject("Worksheets");  // 鑾峰彇鎵�鏈夊伐浣滆〃
+    QAxObject* worksheet = worksheets->querySubObject("Item(int)", 1);  // 鑾峰彇绗竴涓伐浣滆〃
+    for (int i = 1; i <= 5; i++) {
+        for (int j = 1; j <= 5; j++) {
+            QString cellValue = "Value";  // 璁剧疆瑕佸啓鍏ョ殑鍗曞厓鏍煎��
+            worksheet->querySubObject("Cells(int, int)", i, j)->dynamicCall("SetValue(const QVariant&)", cellValue);  // 鍐欏叆鍗曞厓鏍煎��
+        }
+    }
+    QString path = QDir::currentPath();
+    qDebug()<<"path:"<<path;
+    path += "/debug/Data/save2.xls";
+    qDebug()<<"path:"<<path;
+    workbook->dynamicCall("SaveAs(const QString&)", path);  // 淇濆瓨宸ヤ綔绨�
+    workbook->dynamicCall("Close()");  // 鍏抽棴宸ヤ綔绨�
+    excel->dynamicCall("Quit()");  // 閫�鍑篍xcel搴旂敤绋嬪簭
+
+}
+
+void SearchInfo::on_comboBox_currentIndexChanged(const QString &arg1)
+{
+    m_model->setHorizontalHeaderLabels(m_labels[arg1]);
+}

--
Gitblit v1.8.0