wumu
2024-12-13 1bb61da9f048f9f86b412479e3f4d18adb1876f2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#include "problemcount.h"
#include "ui_problemcount.h"
#include <QDebug>
#include <QFileDialog>
#include <QProcess>
#include <QPushButton>
#include <QSqlQuery>
 
#pragma execution_character_set("utf-8")
 
extern int g_comId;
extern QString g_auditDate;
extern QString g_dataRootPath;
 
ProblemCount::ProblemCount(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::ProblemCount)
{
    ui->setupUi(this);
    ui->tableWidget->setColumnWidth(0,300);
    m_comId = g_comId;
    for(int i=0;i<ui->tableWidget->rowCount();++i){
        QPushButton *btn = new QPushButton("上传",this);
        ui->tableWidget->setCellWidget(i,3,btn);
        connect(btn,&QPushButton::clicked,this,[=]{
            QStringList files = QFileDialog::getOpenFileNames();
            QString str;
            for(auto f:files){
                copyFile(f);
                QString targetPath = g_dataRootPath + QString("/%1/%2").arg(g_comId).arg(f.split("/").back());
                str += targetPath + " ";
            }
            ui->tableWidget->setItem(i,4,new QTableWidgetItem(str));
        });
 
        // 查看佐证
        QPushButton *lookBtn = new QPushButton("查看",this);
        ui->tableWidget->setCellWidget(i,5,lookBtn);
        connect(lookBtn,&QPushButton::clicked,this,[=]{
            QStringList files = ui->tableWidget->item(i,4)->text().split(" ");
            if(files.size() > 0 ){
                QString f = files.at(0);
                qDebug()<<"f:"<<f;
                if(f.size() > 10){
                    f.replace("/", "\\");    //win32下替换斜杠
                    QProcess process;
                    process.startDetached("explorer", QStringList() << QString("/select,") << QString("%1").arg(f));
                }
            }
        });
    }
}
 
ProblemCount::~ProblemCount()
{
    delete ui;
}
 
void ProblemCount::copyFile(QString path)
{
    QStringList paths = path.split("/");
    QString comPath = g_dataRootPath + QString("/%1").arg(g_comId);
    QDir comDir(comPath);
    if(!comDir.exists()){
        // 创建路径
        if(QDir().mkdir(comPath)){
            qDebug()<<"创建目录成功:"<<comPath;
        }
    }
    QString targetPath = g_dataRootPath + QString("/%1/%2").arg(g_comId).arg(paths.back());
    qDebug()<<"targetPath"<<targetPath;
    if(QFile::copy(path,targetPath)){
        qDebug()<<"成功拷贝:"<<path;
    }else{
        qDebug()<<"拷贝失败"<<path;
    }
}
void ProblemCount::on_tableWidget_clicked(const QModelIndex &index)
{
    qDebug()<<"index"<<index;
    int noMonCnt = 0;
    for(int i=3;i<=6;++i){
        noMonCnt += ui->tableWidget->item(i,2)->text().toInt();
    }
    ui->tableWidget->setItem(2,2,new QTableWidgetItem(QString::number(noMonCnt)));
 
    int allCnt = ui->tableWidget->item(1,2)->text().toInt()+ui->tableWidget->item(2,2)->text().toInt();
    ui->tableWidget->setItem(0,2,new QTableWidgetItem(QString::number(allCnt)));
 
 
}
 
void ProblemCount::on_tableWidget_activated(const QModelIndex &index)
{
    qDebug()<<"activated index"<<index;
    int noMonCnt = 0;
    for(int i=3;i<=6;++i){
        noMonCnt += ui->tableWidget->item(i,2)->text().toInt();
    }
    ui->tableWidget->setItem(2,2,new QTableWidgetItem(QString::number(noMonCnt)));
 
    int allCnt = ui->tableWidget->item(1,2)->text().toInt()+ui->tableWidget->item(2,2)->text().toInt();
    ui->tableWidget->setItem(0,2,new QTableWidgetItem(QString::number(allCnt)));
 
}
 
void ProblemCount::on_pushButton_clicked()
{
    // 再统计一把
    on_tableWidget_activated(QModelIndex());
 
 
    QString values = "";
    for(int i=0;i<ui->tableWidget->rowCount();++i){
        values += QString("('%1','%2',%3,'%4',%5,'%6'),").arg(ui->tableWidget->item(i,0)->text())
                .arg(ui->tableWidget->item(i,1)->text()).arg(ui->tableWidget->item(i,2)->text().toInt())
                .arg(ui->tableWidget->item(i,4)->text())
                .arg(g_comId).arg(g_auditDate);
    }
    values = values.left(values.length()-1);
    QString sql = QString("insert into problem_count (kpi_name,code,num,evidences,com_id,time) values %1").arg(values);
    qDebug()<<sql;
    QSqlQuery query;
    if(query.exec(sql)){
        qDebug()<<"OK sql"<<__FUNCTION__;
    }else{
        qDebug()<<"fail sql"<<__FUNCTION__;
    }
    static int cnt=1;
    ui->pushButton->setText(QString("提交--问题数量_%1次").arg(cnt++));
}
 
void ProblemCount::showData(QVariantList vlist)
{
    for(int i=0;i<vlist.size();++i){
        if(vlist.at(i).isValid()){
            ui->tableWidget->setItem(i,2,new QTableWidgetItem(vlist.at(i).toString()));
        }
    }
    // 再统计一把
    on_tableWidget_activated(QModelIndex());
}