wumu
2024-03-04 31ed29f804a6850ef9a8f60326f4da603e7c8a39
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
#include "problemnotmoney.h"
#include "ui_problemnotmoney.h"
 
#include <QFileDialog>
#include <QPushButton>
#include <QSqlQuery>
#include <QDebug>
#include <QProcess>
 
extern int g_comId;
extern QString g_auditDate;
extern QString g_dataRootPath;
 
ProblemNotMoney::ProblemNotMoney(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::ProblemNotMoney)
{
    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));
                }
            }
        });
    }
}
 
ProblemNotMoney::~ProblemNotMoney()
{
    delete ui;
}
 
void ProblemNotMoney::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 ProblemNotMoney::on_tableWidget_clicked(const QModelIndex &index)
{
    int allCnt = 0;
    for(int i=1;i<ui->tableWidget->rowCount();++i){
        allCnt += ui->tableWidget->item(i,2)->text().toInt();
    }
    ui->tableWidget->setItem(0,2,new QTableWidgetItem(QString::number(allCnt)));
}
 
void ProblemNotMoney::on_pushButton_clicked()
{
    // 再统计一把
    on_tableWidget_clicked(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_no_money (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 ProblemNotMoney::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_clicked(QModelIndex());
}