diff --git a/tpvs17/lpReport/DetectDataDB.cpp b/tpvs17/lpReport/DetectDataDB.cpp new file mode 100644 index 0000000..f6604d4 --- /dev/null +++ b/tpvs17/lpReport/DetectDataDB.cpp @@ -0,0 +1,391 @@ +#include "DetectDataDB.h" +#include "InfoFile.h" +#include "gensql.h" + +#define _MD_WARNINGTABLE "warningtable" +/*myself */ +#define _MD_PRIMARY_KEY "uid" +#define _MD_TABLE_FORMS_MANE "wftable" //数据表名称 + +#define _MD_MODEL "model" //model 模型名称 +#define _MD_DIAMETER "diameter" //直径 +#define _MD_HIGHT "hight" //高度 +#define _MD_CORRELATE "correlate" //相似度 +#define _MD_CHANNEL "channel" //通道 +#define _MD_PICPATH "picpath" //图片路径 +#define _MD_ROTATE "rotate"//辐条个数 +#define _MD_UPDATE_TIME "time" //最后更新的时间 +#define _MD_PIC "pic" //图片 + + +#define _MD_TIMETABLE "wftimetable_2" +#define _MD_TYPE "type" +#define _MD_STARTTIME "starttime" +#define _MD_ENDTIME "endtime" +#define _MD_TIMETYPY_S "startType" +#define _MD_TIMETYPY_E "EndType" + +#define _MD_WARNINGTABLE "warningtable" +#define _MD_MESSAGE "message" +#define _MD_CLASS "class" +#define _INDEX_FORTABLE "CREATE INDEX idx_wftable ON wftable (time COLLATE BINARY ASC); " +DetectDataDB::DetectDataDB(const QString& dbName,const QString &dbType) :DataBaseSql(dbName,dbType) +{ +// db = QSqlDatabase::addDatabase("QSQLITE"); +// db.setDatabaseName(dbName); +// if (!dbUser.isEmpty()){ +// db.setUserName(dbUser); +// db.setPassword(dbPwb); +// } +} + +DetectDataDB::~DetectDataDB() +{ + +} +//m_value.insert("time1", "");//起始时间 +//m_value.insert("time2", "");//结束时间 +//m_value.insert("name", "");//模型名字 +//m_value.insert("Type", "");//查询类型 +QString DataBaseSql::genCheckStr(QVariantMap m_value) +{ + int nType = m_value.value(_CHECK_TYPE_).toInt(); + QString select_sql; + switch (nType) + { + case EMT_CHECK_BY_TIME: + { + QString time1 = m_value.value(_CHECK_TIME1_).toString(); + QString strFifter = QString(" where time ='%1'").arg(time1); + int IsCount = m_value.value(_CHECK_COUNT_).toInt(0); + if (IsCount==1) + select_sql = QString("select count(*) from ") + _MD_TABLE_FORMS_MANE + strFifter; + else + select_sql = QString("select * from ") + _MD_TABLE_FORMS_MANE + strFifter; + } + break; + case EMT_CHECK_BY_NAME: + { + QString time1 = m_value.value(_CHECK_TIME1_).toString(); + QString time2 = m_value.value(_CHECK_TIME2_).toString(); + QString modelname = m_value.value(_CHECK_NAME_).toString(); + QString strFifter = QString(" where time >'%1' and time < '%2' and model='%3'").arg(time1).arg(time2).arg(modelname); + int IsCount = m_value.value(_CHECK_COUNT_).toInt(0); + if (IsCount == 1) + select_sql = QString("select count(*) from ") + _MD_TABLE_FORMS_MANE + strFifter; + else + select_sql = QString("select * from ") + _MD_TABLE_FORMS_MANE + strFifter; + } + break; + case EMT_CHECK_BY_SAE: + { + QString time1 = m_value.value(_CHECK_TIME1_).toString(); + QString time2 = m_value.value(_CHECK_TIME2_).toString(); + QString checktypeStr = m_value.value("CheckType").toString(); + QString strFifter = QString(" where time >'%1' and time < '%2'").arg(time1).arg(time2); + int IsCount = m_value.value(_CHECK_COUNT_).toInt(0); + if (IsCount == 1) + select_sql = QString("select count(*) from ") + _MD_TABLE_FORMS_MANE + strFifter; + else{ + if (checktypeStr == "Count") + select_sql = QString("select %1 from ").arg(_MD_MODEL) + _MD_TABLE_FORMS_MANE + strFifter; + else + select_sql = QString("select * from ") + _MD_TABLE_FORMS_MANE + strFifter; + } + } + break; + case EMT_CHECK_BY_LOG: + { + QString time1 = m_value.value(_CHECK_TIME1_).toString(); + QString time2 = m_value.value(_CHECK_TIME2_).toString(); + int logType = m_value.value(_CHECK_LOGTYPE).toInt(); + QString strFifter = QString(" where time >'%1' and time < '%2' and class = '%3' order by time desc ").arg(time1).arg(time2).arg(logType); + int IsCount = m_value.value(_CHECK_COUNT_).toInt(0); + if (IsCount == 1) + select_sql = QString("select count(*) from ") + _MD_WARNINGTABLE + strFifter; + else + select_sql = QString("select * from ") + _MD_WARNINGTABLE + strFifter; + } + break; + case EMT_CHECK_BY_COUNT: + { + QString time1 = m_value.value(_CHECK_TIME1_).toString(); + QString time2 = m_value.value(_CHECK_TIME2_).toString(); + QString checktypeStr = m_value.value("CheckType").toString(); + QString strFifter = QString(" where time >'%1' and time < '%2'").arg(time1).arg(time2); + int IsCount = m_value.value(_CHECK_COUNT_).toInt(0); + if (IsCount == 1) + select_sql = QString("select count(*) from ") + _MD_TABLE_FORMS_MANE + strFifter; + else{ + QString strGroup = QString(" GROUP BY %1 ORDER BY %2").arg(_MD_MODEL).arg(_MD_MODEL); + if (checktypeStr == "Count") + select_sql = QString("select %1 from ").arg(_MD_MODEL).arg(_MD_MODEL) + _MD_TABLE_FORMS_MANE + strFifter;// +strGroup; + else + select_sql = QString("select * from ") + _MD_TABLE_FORMS_MANE + strFifter; + } + } + break; + case EMT_CHECK_BY_UID: + { + QString uid = m_value.value(_CHECK_UID_).toString(); + QString strFifter = QString(" where uid = %1 ").arg(uid); + int IsCount = m_value.value(_CHECK_COUNT_).toInt(0); + if (IsCount == 1) + select_sql = QString("select count(*) from ") + _MD_TABLE_FORMS_MANE + strFifter; + else + select_sql = QString("select * from ") + _MD_TABLE_FORMS_MANE + strFifter; + } + break; + default: + break; + } + return select_sql; +} + +bool DetectDataDB::checkoutData(QVariantMap m_value, QSqlQuery &sql) +{ + int nType = m_value.value(_CHECK_TYPE_).toInt(); + QString select_sql; + switch (nType) + { + case EMT_CHECK_BY_TIME: + { + QString time1 = m_value.value(_CHECK_TIME1_).toString(); + QString strFifter = QString(" where time ='%1'").arg(time1); + select_sql = QString("select * from ") + _MD_TABLE_FORMS_MANE + strFifter; + } + break; + case EMT_CHECK_BY_NAME: + { + QString time1 = m_value.value(_CHECK_TIME1_).toString(); + QString time2 = m_value.value(_CHECK_TIME2_).toString(); + QString modelname = m_value.value(_CHECK_NAME_).toString(); + QString strFifter = QString(" where time >'%1' and time < '%2' and model='%3'").arg(time1).arg(time2).arg(modelname); + select_sql = QString("select * from ") + _MD_TABLE_FORMS_MANE + strFifter; + } + break; + case EMT_CHECK_BY_SAE: + { + QString time1 = m_value.value(_CHECK_TIME1_).toString(); + QString time2 = m_value.value(_CHECK_TIME2_).toString(); + QString strFifter = QString(" where time >'%1' and time < '%2'").arg(time1).arg(time2); + select_sql = QString("select * from ") + _MD_TABLE_FORMS_MANE + strFifter; + } + break; + case EMT_CHECK_BY_LOG: + { + QString time1 = m_value.value(_CHECK_TIME1_).toString(); + QString time2 = m_value.value(_CHECK_TIME2_).toString(); + int logType = m_value.value(_CHECK_LOGTYPE).toInt(); + QString strFifter = QString(" where time >'%1' and time < '%2' and class = '%3' order by time desc ").arg(time1).arg(time2).arg(logType); + select_sql = QString("select * from ") + _MD_WARNINGTABLE + strFifter; + } + break; + default: + break; + } + + sql = db->exec(select_sql); + return true; +} + +bool DetectDataDB::checkoutData(QString selectStr, QSqlQuery &sql) +{ + sql = db->exec(selectStr); + return true; +} +// bool DetectDataDB::checkoutData(QString selectStr, QSqlQuery &sql) +// { +// Q +// } +bool DetectDataDB::DelDatasByTime(QString minTime) +{ + QString StrTime = QString("time <'%1'").arg(minTime); + QString select_sql = QString("DELETE FROM %1 WHERE %2").arg(_MD_TABLE_FORMS_MANE).arg(StrTime); + db->exec(select_sql); + return true; +} + +bool DetectDataDB::DelAllDatas() +{ + QString strSqll = QString("delete from %1 ").arg(_MD_TABLE_FORMS_MANE); + db->exec(strSqll); + strSqll = QString("delete from %1 ").arg("warningtable"); + db->exec(strSqll); + return true; +} + +bool DetectDataDB::DelWarnDataByCount(int model /*=1*/, int nCount/*=100000*/) +{ + QString strLimit1 = QString("select count(uid) from %1 where class = '%3'").arg("warningtable").arg(model); + QString strLimit2 = QString("uid in(select uid from %1 where class = '%2' order by time desc limit(select count(uid) from %3 where class = '%4') offset %5)").arg("warningtable").arg(model).arg("warningtable").arg(model).arg(nCount); + QString strSqll = QString("delete from %1 where (%2)>%3 and %4").arg("warningtable").arg(strLimit1).arg(nCount).arg(strLimit2); + QSqlQuery sql = db->exec(strSqll); + return true; +} + +bool DetectDataDB::InitDatabase() +{ + if (!openDB()) + { + return false; + } + + QString strCheckTable = QString("select name from sqlite_master where type='table' order by name;"); + QSqlQuery sql = db->exec(strCheckTable);//查询数据库中所有的数据表 + QStringList tablenamelist; + while (sql.next()) + { + QString strname = sql.value(0).toString(); + tablenamelist.append(strname); + } + if (!tablenamelist.contains(_MD_TABLE_FORMS_MANE))//是否包含 table 否则创建新表 + { + QVariantMap vDataMap; + vDataMap.insert(_MD_MODEL, "VARCHAR(32)"); + vDataMap.insert(_MD_DIAMETER, "INT(100)");//直径 + vDataMap.insert(_MD_HIGHT, "INT(100)");//高度 + vDataMap.insert(_MD_CORRELATE, "INT(100)");//相似度 + vDataMap.insert(_MD_CHANNEL, "INT(100)"); + vDataMap.insert("detecttime", "VARCHAR(32)"); + vDataMap.insert(_MD_UPDATE_TIME, "DATETIME(32)"); + vDataMap.insert(_MD_PIC, "BLOB"); + if (!CreatTable(_MD_TABLE_FORMS_MANE, _MD_PRIMARY_KEY, vDataMap)) + { + //return false; + } + else + { + QString strIndex = QString("CREATE INDEX idx_wftable ON wftable (time COLLATE BINARY ASC); "); + db->exec(strIndex);//创建索引 + } + } + + if (!tablenamelist.contains(_MD_TIMETABLE)) + { + QVariantMap vTimeMap;//保存班次时间 + vTimeMap.insert(_MD_TYPE, "VARCHAR(32)"); + vTimeMap.insert(_MD_STARTTIME, "VARCHAR(32)"); + vTimeMap.insert(_MD_ENDTIME, "VARCHAR(32)"); + vTimeMap.insert(_MD_TIMETYPY_S, "INT(100)"); + vTimeMap.insert(_MD_TIMETYPY_E, "INT(100)"); + if (!CreatTable(_MD_TIMETABLE, _MD_PRIMARY_KEY, vTimeMap)) + { + //return false; + } + else{ + + } + } + + if (!tablenamelist.contains(_MD_WARNINGTABLE)) + { + QVariantMap vWarningMap;//报警信息 + vWarningMap.insert(_MD_MESSAGE, "VARCHAR(256)"); + vWarningMap.insert(_MD_CLASS, "VARCHAR(32)"); + vWarningMap.insert(_MD_UPDATE_TIME, "DATETIME(32)"); + if (!CreatTable(_MD_WARNINGTABLE, _MD_PRIMARY_KEY, vWarningMap)) + { + //return false; + + } + else{ + QString strIndex = QString("CREATE INDEX idx_warningtable ON warningtable (time COLLATE BINARY ASC); "); + db->exec(strIndex); + } + } + + return true; +} + +bool DetectDataDB::ReadOutTimeData(QMap &m_MapTimeMatch) +{ + QString select_sql = QString("select * from ") + _MD_TIMETABLE; + QSqlQuery sql = db->exec(select_sql); + QSqlError err = sql.lastError(); + int t = err.type(); + if (t != QSqlError::NoError) + { + return false; + } + while (sql.next()) + { + int nIndex = sql.value("uid").toInt(); + QString type = sql.value(_MD_TYPE).toString(); + QTime start = sql.value(_MD_STARTTIME).toTime(); + QTime end = sql.value(_MD_ENDTIME).toTime(); + int nSt = sql.value(_MD_TIMETYPY_S).toInt(); + int nEd = sql.value(_MD_TIMETYPY_E).toInt(); + TimeStruct m_timeStruct; + m_timeStruct.m_Index = nIndex; + m_timeStruct.m_name = type; + m_timeStruct.m_startTime = start; + m_timeStruct.m_endTime = end; + m_timeStruct.time_start = (AMPMType)nSt; + m_timeStruct.time_end = (AMPMType)nEd; + m_MapTimeMatch.insert(type, m_timeStruct); + } + return true; +} + +bool DetectDataDB::AddOneWarningMessage(WarnMessage m_messageInfo) +{ + QVariantMap m_map; + m_map.insert(_MD_MESSAGE, m_messageInfo.m_Message); + m_map.insert(_MD_UPDATE_TIME, m_messageInfo.m_Date); + m_map.insert(_MD_CLASS, m_messageInfo.m_class); + return InsertOneData(_MD_WARNINGTABLE, m_map); +} +bool DetectDataDB::AddOneTime(TimeStruct &m_timestruct) +{ + QVariantMap m_map; + m_map.insert(_MD_TYPE, m_timestruct.m_name); + m_map.insert(_MD_STARTTIME, m_timestruct.m_startTime); + m_map.insert(_MD_ENDTIME, m_timestruct.m_endTime); + m_map.insert(_MD_TIMETYPY_S, (int)m_timestruct.time_start); + m_map.insert(_MD_TIMETYPY_E, (int)m_timestruct.time_end); + return InsertOneData(_MD_TIMETABLE, m_map); +} +bool DetectDataDB::DelOneTime(TimeStruct &m_timestruct) +{ + QString m_map = gensql::genClass(_MD_TYPE, m_timestruct.m_name);//!>生成where条件语句 + QString strSql = gensql::genDeleteData(_MD_TIMETABLE, m_map); + db->exec(strSql); + if (db->lastError().isValid()) + { + return false; + } + return true; +} + +bool DetectDataDB::AddOneData(QVariantMap m_map) +{ + /*该部分数据是保存检测结果+结果图片*/ + + QString strInsert = "INSERT INTO %1(%2) VALUES(%3)"; + QString strHeader;// + QString strValue;// + + QStringList strKeys = m_map.keys(); + for (int i = 0; i < strKeys.size(); i++) { + strHeader += strKeys[i]; + if (i + 1 < strKeys.size()) + strHeader += ","; + strValue += ":" + strKeys[i] + ""; + + if (i + 1 < strKeys.size()) + strValue += ","; + } + strInsert = strInsert.arg(_MD_TABLE_FORMS_MANE, strHeader, strValue); + //return strInsert; + QSqlQuery query = db->exec(); + query.prepare(strInsert); + for (int i = 0; i < strKeys.size(); i++) + { + QString m_keys = strKeys.at(i); + QString str = ":" + m_keys; + query.bindValue(str, m_map.value(m_keys)); + } + query.exec(); + return true; +} diff --git a/tpvs17/lpReport/DetectDataDB.h b/tpvs17/lpReport/DetectDataDB.h new file mode 100644 index 0000000..a9a97f6 --- /dev/null +++ b/tpvs17/lpReport/DetectDataDB.h @@ -0,0 +1,34 @@ +#ifndef DETECTDATA_H +#define DETECTDATA_H +#include "databasesql.h" +#include +#include "InfoFile.h" +#include "QMutex" +/*DetectDataDB 用于记录检测数据 便于查询和插入*/ +class DetectDataDB : public DataBaseSql +{ + Q_OBJECT + +public: + DetectDataDB(const QString& dbName, const QString &dbType = QString("QSQLITE")); + ~DetectDataDB(); + virtual bool InitDatabase(); + + virtual bool checkoutData(QVariantMap m_value, QSqlQuery &sql); + virtual bool checkoutData(QString selectStr, QSqlQuery &sql); + virtual bool DelDatasByTime(QString minTime); + virtual bool DelAllDatas(); + virtual bool DelWarnDataByCount(int model /*=1*/, int nCount/*=100000*/); + bool AddOneWarningMessage(WarnMessage m_messageInfo); + + /*班次时间管理*/ + bool ReadOutTimeData(QMap &m_MapTimeMatch); + bool DelOneTime(TimeStruct &m_timestruct); + bool AddOneTime(TimeStruct &m_timestruct); + bool AddOneData(QVariantMap m_map); + +private: + +}; + +#endif // DETECTDATA_H diff --git a/tpvs17/lpReport/InfoFile.h b/tpvs17/lpReport/InfoFile.h new file mode 100644 index 0000000..cbf4319 --- /dev/null +++ b/tpvs17/lpReport/InfoFile.h @@ -0,0 +1,63 @@ +#ifndef _INFOFILE_H_ +#define _INFOFILE_H_ +#include +#include +#include "qstringlist.h" +#define WS_PICSIZE 129 //!>缩放大小 +#define WS_PICSIZELIST 120 + +#define WF_HUBMODEL_ID "hubID" +#define WF_HUBMODEL_DIAMETER "diameter"//轮毂直径 +#define WF_HUBMODEL_HEIGHT "height"//轮毂厚度 +#define WF_HUBMODEL_CHANNELS "channels" +#define WF_HUBMODEL_FILEPATH "filepath" + +#define WF_LIFHT "Light" +#define WF_PLCPARA "PlcPara" +#define WF_PARASET "paraSetting"//PLC参数设置 +enum AMPMType{ + AM=0, + PM=1, +}; +struct TimeStruct +{ + int m_Index; + QString m_name; + QTime m_startTime; + AMPMType time_start; + QTime m_endTime; + AMPMType time_end; + TimeStruct(){ + time_start = AM; + time_end = AM; + } +}; +struct WarnMessage +{ + QString m_Message; + QString m_Date; + QString m_class; +}; + +struct ChannelInfo +{ + QString m_ChannelName; + QString m_AboutName; + int m_value; + QStringList m_strModels; +}; +enum EM_LOG_TYPE{ + emTypeWaring = 1, + emTypeCameraState, + emTypeNetState, + emTypeRunState, + emTypeUseState +}; +enum emTypeBee{ + LIGHT_REDBEE = 0, + LIGHT_GREENBEE, + LIGHT_YELLOWBEE, + LIGHT_BEE +}; + +#endif diff --git a/tpvs17/lpReport/ModelDB.cpp b/tpvs17/lpReport/ModelDB.cpp new file mode 100644 index 0000000..8a3e225 --- /dev/null +++ b/tpvs17/lpReport/ModelDB.cpp @@ -0,0 +1,47 @@ +#include "ModelDB.h" +#define _MD_PRIMARY_KEY "uid" +#define _MD_TABLE_FORMS_MANE "wftable" //ݱ +#define _MD_MODEL "model" //model ģ +#define _MD_DIAMETER "diameter" //ֱ +#define _MD_HIGHT "hight" //߶ +#define _MD_CORRELATE "correlate" //ƶ +#define _MD_CHANNEL "channel" //ͨ +#define _MD_PICPATH "picpath" //ͼƬ· +#define _MD_ROTATE "rotate"// +#define _MD_UPDATE_TIME "time" //µʱ +#define _MD_PIC "pic" //ͼƬ +ModelDB::ModelDB(const QString& dbName, const QString& dbType) :DataBaseSql(dbName, dbType) +{ +} + +ModelDB::~ModelDB() +{ +} + +bool ModelDB::InitDatabase() +{ + if (!db->open()) + { + return false; + } + return true; +} + +QStringList ModelDB::ReadAllModes() +{ + QStringList lst; + QString select_sql = QString("select * from ") + "modelTable"; + QSqlQuery sql = db->exec(select_sql); + QSqlError err = sql.lastError(); + int t = err.type(); + if (t != QSqlError::NoError) + { + return lst; + } + while (sql.next()) + { + QString strName = sql.value(_MD_MODEL).toString(); + lst.append(strName); + } + return lst; +} \ No newline at end of file diff --git a/tpvs17/lpReport/ModelDB.h b/tpvs17/lpReport/ModelDB.h new file mode 100644 index 0000000..88f136e --- /dev/null +++ b/tpvs17/lpReport/ModelDB.h @@ -0,0 +1,33 @@ +/*! + *FileName: ModelDB.h + *Author: Pan Yingdong + *Email: bob.pan@hzleaper.com + *Created:2021/4/7 11:10 + *Note: +*/ +#ifndef _H_MODELDB_H_ +#define _H_MODELDB_H_ + +#include "databasesql.h" +#include "InfoFile.h" + +class ModelDB : public DataBaseSql +{ + Q_OBJECT + +public: + ModelDB(const QString& dbName, const QString &dbType = QString("QSQLITE")); + ~ModelDB(); + + virtual bool InitDatabase(); + QStringList ReadAllModes();//ģͺ + + virtual bool checkoutData(QVariantMap m_value, QSqlQuery &sql) { return false; }; + virtual bool checkoutData(QString selectStr, QSqlQuery &sql) { return false; }; + virtual bool AddOneWarningMessage(struct WarnMessage m_messageInfo) { return false; }; + virtual bool DelWarnDataByCount(int model = 1, int nCount = 100000) { return false; }; + virtual bool DelAllDatas() { return false; }; + virtual bool DelDatasByTime(QString minTime) { return false; }; +}; + +#endif diff --git a/tpvs17/lpReport/Resources/Log.png b/tpvs17/lpReport/Resources/Log.png new file mode 100644 index 0000000..b360632 Binary files /dev/null and b/tpvs17/lpReport/Resources/Log.png differ diff --git a/tpvs17/lpReport/Resources/log.ico b/tpvs17/lpReport/Resources/log.ico new file mode 100644 index 0000000..fe051a6 Binary files /dev/null and b/tpvs17/lpReport/Resources/log.ico differ diff --git a/tpvs17/lpReport/checkdata.h b/tpvs17/lpReport/checkdata.h new file mode 100644 index 0000000..a759475 --- /dev/null +++ b/tpvs17/lpReport/checkdata.h @@ -0,0 +1,70 @@ +#ifndef CHECKDATA_H +#define CHECKDATA_H + +#include +#include "QStandardItemModel.h" +#include "QIcon" +#include "QPixmap" +#include "QByteArray" +#include "databasesql.h" +#include "QJsonObject" +#include +#pragma execution_character_set("utf-8")//使用utf-8编码 可以使用中文,解决乱码 + +class CheckData : public QObject +{ + Q_OBJECT + +public: + CheckData(QObject *parent=0){ m_pDb = NULL; }; + ~CheckData(){}; + void setDB(DataBaseSql* pDB){ m_pDb = pDB; }; +public slots: + void doWork(QVariantMap m_map) + { + QVariantMap m_proMap; + m_proMap.insert("Type", "start"); + emit sgShowProgress(m_proMap); + + QVariantMap Mapstr; + QString strSql_Count = m_map.value("SqlCount").toString(); + QString strSql_Check = m_map.value("SqlCheck").toString(); + int nLimit = m_map.value("limit").toInt(); + int nSum = 0; + int nIndex = 0; + QSqlQuery sql_Check; + if (m_pDb){ + QSqlQuery sql_Count; + m_proMap.insert("msg", "正在获取数量"); + emit sgShowProgress(m_proMap); + m_pDb->checkoutData(strSql_Count, sql_Count); + while (sql_Count.next()){ + nSum = sql_Count.value(0).toInt(); + } + //加入 + //emit something + m_proMap.remove("msg"); + m_proMap.insert("msg", "正在获取数据"); + emit sgShowProgress(m_proMap); + m_pDb->checkoutData(strSql_Check, sql_Check); + + } + Mapstr.insert("sum", nSum); + Mapstr.insert("nIndex", nIndex); + Mapstr.insert("limit", nLimit); + m_proMap.remove("Type"); + m_proMap.insert("Type", "stop"); + emit sgShowProgress(m_proMap); + + emit resultReady(Mapstr, sql_Check); + //emit something + }; +private: + class DataBaseSql *m_pDb; +signals: + void resultReady(QVariantMap Mapstr,QSqlQuery sql); + void sgShowMsg(QString str); + void sgShowProgress(QVariantMap m_Map); +}; + +#endif // CHECKDATA_H diff --git a/tpvs17/lpReport/checkthread.h b/tpvs17/lpReport/checkthread.h new file mode 100644 index 0000000..b8dcf26 --- /dev/null +++ b/tpvs17/lpReport/checkthread.h @@ -0,0 +1,53 @@ +#ifndef CHECKTHREAD_H +#define CHECKTHREAD_H + +#include +#include "QSqlQuery" +#include "databasesql.h" +#include "QMetaType" +#include "QStandardItemModel" +#include +class CheckThread : public QThread +{ + Q_OBJECT + +public: + CheckThread(QObject *parent){ bFlags = false; }; + ~CheckThread(){}; + void setModelFlags(bool m_flags = false){ bFlags = m_flags; } + void setCheckStr(DataBaseSql *pDb ,QString m_str){ + m_pDb = pDb; + m_CheckStr = m_str; + }; + void run() Q_DECL_OVERRIDE{ + QSqlQuery sql; + int nCount = 0; + if (m_pDb){ + + m_pDb->checkoutData(m_CheckStr, sql); + + if (bFlags == true) + { + while (sql.next()) + { + QSqlRecord record = sql.record(); + QString fieldName = record.fieldName(0); + QString num = sql.value(0).toString(); + nCount = num.toInt(); +// /*这里下面是统计查询到的通道对应的产品总数*/ + } + } + } + emit (resultReady(sql)); + emit(resultCount(nCount)); + } +private: + DataBaseSql *m_pDb; + QString m_CheckStr; + bool bFlags; +signals: + void resultReady(QSqlQuery sql); + void resultCount(int nCount); +}; + +#endif // CHECKTHREAD_H diff --git a/tpvs17/lpReport/countdata.h b/tpvs17/lpReport/countdata.h new file mode 100644 index 0000000..c2a1970 --- /dev/null +++ b/tpvs17/lpReport/countdata.h @@ -0,0 +1,84 @@ +#ifndef COUNTDATA_H +#define COUNTDATA_H + +#include +#include "databasesql.h" +#include "QSqlQuery" +#pragma execution_character_set("utf-8") +class CountData : public QObject +{ + Q_OBJECT + +public: + CountData(QObject *parent = 0){ m_pDb = NULL; }; + ~CountData(){}; + void setDB(class DataBaseSql *pDb){ m_pDb = pDb; }; +public slots: + void doWork(QVariantMap m_Map) { + QMap *m_counter=new QMap(); + QVariantMap m_proMap; + m_proMap.insert("Type", "start"); + emit sgShowProgress(m_proMap); + + QString result; + QSqlQuery sqlCount; + QSqlQuery sql; + /* ... here is the expensive or blocking operation ... */ + + QString strSql_Count = m_Map.value("SqlCount").toString(); + QString strSql_Check = m_Map.value("SqlCheck").toString(); + + if (m_pDb){ + //m_counter->clear(); + m_proMap.insert("msg", "正在获取数量..."); + emit sgShowProgress(m_proMap); + m_pDb->checkoutData(strSql_Count, sqlCount); + //emit sgShowMsg("正在查询数据"); + int sum = 0; + int m_size = 0; + while (sqlCount.next()) + { + m_size = sqlCount.value(0).toInt(); + } + + QString strname = QString("select model,count(model) from (%1) GROUP BY model ;").arg(strSql_Check); + m_pDb->checkoutData(strname, sql); + //m_pDb->checkoutData(strSql_Check, sql); + //emit sgShowMsg("正在统计中"); + + m_proMap.remove("msg"); + m_proMap.insert("msg", QString("共%1条记录,正在分类核算数据,请稍后").arg(m_size)); + emit sgShowProgress(m_proMap); + + while (sql.next()) + { + /*这里下面是统计查询到的通道对应的产品总数*/ + + QString model = sql.value(0).toString(); + int nValue = sql.value(1).toInt(); + if (m_counter->contains(model)) + { + (*m_counter)[model]++; + } + else + { + m_counter->insert(model, nValue); + } + } + result = QString("%1").arg(m_size); + emit sgShowMsg("统计完成"); + } + m_proMap.remove("Type"); + m_proMap.insert("Type", "stop"); + emit sgShowProgress(m_proMap); + emit resultReady(result, m_counter); + } +signals: + void resultReady(const QString &result, const QMap *p); + void sgShowMsg(QString str); + void sgShowProgress(QVariantMap m_map); +private: + class DataBaseSql *m_pDb; +}; + +#endif // COUNTDATA_H diff --git a/tpvs17/lpReport/databasesql.cpp b/tpvs17/lpReport/databasesql.cpp new file mode 100644 index 0000000..dd0f6a5 --- /dev/null +++ b/tpvs17/lpReport/databasesql.cpp @@ -0,0 +1,165 @@ +#include "databasesql.h" +#include "gensql.h" +#define _MD_PRIMARY_KEY "uid" +#define _QMYSQL_ "QMYSQL" +#define _SQLITE_ "QSQLITE" + +DataBaseSql::DataBaseSql(const QString& dbName, const QString &dbType) +{ + m_DBType = dbType; + if (dbType == "QSQLITE") + { + db = new QSqlDatabase(QSqlDatabase::addDatabase("QSQLITE", dbName)); + db->setDatabaseName(dbName); + //qry = QSqlQuery::QSqlQuery(db); + } + else if (dbType == "QMYSQL") + { + //if (!QSqlDatabase::contains(m_DBType)) + db = new QSqlDatabase(QSqlDatabase::addDatabase("QMYSQL", dbName)); + //db.setDatabaseName(dbName); + } +} + +DataBaseSql::~DataBaseSql() +{ + if (db->isOpen()) + { + db->close(); + } + delete db; + db = NULL; +} + +bool DataBaseSql::openDB() +{ + return db->open(); +} + +void DataBaseSql::closeDB() +{ + db->close(); +} + +bool DataBaseSql::InitDatabase() +{ + if (!db->open() && db->open()) + { + return false; + } + + return true; +} + +bool DataBaseSql::CreatTable(QString m_tableName, QString m_primaty, QVariantMap m_map) +{ + QString strSql; + if (m_DBType == _SQLITE_) + strSql = gensql::genCreateTabel(m_tableName, m_primaty, "INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL", m_map); + else if (m_DBType == _QMYSQL_) + strSql = QString("CREATE TABLE `testtable2` (`id` int(11) NOT NULL,`name` varchar(60) DEFAULT NULL,`age` int(11) DEFAULT NULL,PRIMARY KEY(`id`)) ENGINE = InnoDB DEFAULT CHARSET = utf8; "); + QSqlQuery sql = db->exec(strSql); + + QSqlError err = sql.lastError(); + int nType = err.type(); + if (nType != QSqlError::NoError) + return false; + return true; +} + +bool DataBaseSql::InsertOneData(QString m_tableName, QVariantMap m_map) +{ + + if (m_tableName.isEmpty() || m_map.empty()) { + return false; + } + QString strSql; + strSql = gensql::genInsertData(m_tableName, m_map); + qry = db->exec(strSql); + QSqlError bflags = qry.lastError(); + int nType = bflags.type(); + QString str = db->databaseName(); + if (db->lastError().isValid()) + { + return false; + } + return true; +} + +bool DataBaseSql::ModefyOneData(QString m_tableName, QVariantMap m_map) +{ + if (m_tableName.isEmpty() || m_map.empty()) { + return false; + } + int max_id = 0; + QString select_max_sql = "select max(md_unique) from e_report_forms"; + QSqlQuery sql = db->exec(select_max_sql); + if (db->lastError().isValid()) + { + return false; + } + else + { + while (sql.next()) + { + max_id = sql.value(0).toInt(); + } + } + QString m = gensql::genClass(_MD_PRIMARY_KEY, "0"); + QString strSql = gensql::genUpdate(m_tableName, m_map, m); + + db->exec(strSql); + if (db->lastError().isValid()) + { + return false; + } + return true; +} + +bool DataBaseSql::DeleteOneData(QString m_tableName, QString m_map) +{ + if (m_tableName.isEmpty() || m_map.isEmpty()) { + return false; + } + int max_id = 0; + QString select_max_sql = "select max(" + QString(_MD_PRIMARY_KEY) + ") from " + m_tableName; + QSqlQuery sql = db->exec(select_max_sql); + if (db->lastError().isValid()) + { + return false; + } + else + { + while (sql.next()) + { + max_id = sql.value(0).toInt(); + } + } + QString m;// = genClass(_MD_PRIMARY_KEY, "0"); + QString strSql = gensql::genDeleteData(m_tableName, m); + + db->exec(strSql); + if (db->lastError().isValid()) + { + return false; + } + return true; +} + +void DataBaseSql::SetDatabaseName(QString dbName) +{ + db->setDatabaseName(dbName); +} + +void DataBaseSql::SetDBPort(QString nAddr /*= QString("localhost")*/, int nPort /*= 3306*/) +{ + db->setHostName(nAddr); + db->setPort(nPort); +} + +void DataBaseSql::SetDBUser(QString dbUser /*= QString("root")*/, QString dbPwd /*= QString("hzleaper")*/) +{ + db->setUserName(dbUser); + db->setPassword(dbPwd); +} + diff --git a/tpvs17/lpReport/databasesql.h b/tpvs17/lpReport/databasesql.h new file mode 100644 index 0000000..37d0e54 --- /dev/null +++ b/tpvs17/lpReport/databasesql.h @@ -0,0 +1,74 @@ +#ifndef DATABASESQL_H +#define DATABASESQL_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "QMutex" + +#define _CHECK_TIME1_ "time1" +#define _CHECK_TIME2_ "time2" +#define _CHECK_NAME_ "name" +#define _CHECK_TYPE_ "Type" +#define _CHECK_COUNT_ "Count" +#define _CHECK_LOGTYPE "logType" +#define _CHECK_UID_ "uid" +enum EMTYPE_CHECKTYPE{ + EMT_CHECK_BY_TIME = 0,//只按时间查询 + EMT_CHECK_BY_NAME,//按照模型名查询 + EMT_CHECK_BY_SAE,//按照起始结束时间查询 + EMT_CHECK_BY_LOG, + EMT_CHECK_BY_COUNT, + EMT_CHECK_BY_UID, +}; +class DataBaseSql : public QObject +{ + Q_OBJECT + +public: + DataBaseSql( const QString& dbName ,const QString &dbType = QString("QSQLITE")); + ~DataBaseSql(); + bool openDB(); + void closeDB(); + void SetDatabaseName(QString dbName); + void SetDBPort(QString nAddr = QString("localhost"), int nPort = 3306); + void SetDBUser(QString dbUser = QString("root"), QString dbPwd = QString("hzleaper")); + virtual bool InitDatabase(); + bool CreatTable(QString m_tableName, QString m_primaty, QVariantMap m_map); + + virtual bool InsertOneData(QString m_tableName, QVariantMap m_map); + virtual bool ModefyOneData(QString m_tableName, QVariantMap m_map); + virtual bool DeleteOneData(QString m_tableName, QString m_map); + /* + m_value.insert("time1","");//起始时间 + m_value.insert("time2","");//结束时间 + m_value.insert("name","");//模型名字 + m_value.insert("Type","");//查询类型 + m_value.insert("logType","");//报警信息查询 + */ + virtual bool checkoutData(QVariantMap m_value, QSqlQuery &sql) = 0; + virtual bool checkoutData(QString selectStr, QSqlQuery &sql) = 0; + virtual bool AddOneWarningMessage(struct WarnMessage m_messageInfo) = 0; + virtual bool DelWarnDataByCount(int model = 1, int nCount = 100000) = 0; + virtual bool DelAllDatas() = 0; + virtual bool DelDatasByTime(QString minTime) = 0; + virtual QString genCheckStr(QVariantMap m_value);//通过value数据生成查询语句 实现与checkoutdata相同 +public: + +protected: + QSqlDatabase *db; + QSqlQuery qry; + QString m_DBType; + +}; + +#endif // DATABASESQL_H diff --git a/tpvs17/lpReport/gensql.cpp b/tpvs17/lpReport/gensql.cpp new file mode 100644 index 0000000..fe955ad --- /dev/null +++ b/tpvs17/lpReport/gensql.cpp @@ -0,0 +1,116 @@ +#include "gensql.h" +#include +#include "QStringList" + +QString gensql::genInsertData(const QString & strTableName, const QVariantMap &vMap) +{ + QString strInsert = "INSERT INTO %1(%2) VALUES(%3)"; + QString strHeader;// + QString strValue;// + + QStringList strKeys = vMap.keys(); + for (int i = 0; i < strKeys.size(); i++) { + strHeader += strKeys[i]; + if (i + 1 < strKeys.size()) + strHeader += ","; + strValue += "'" + vMap[strKeys[i]].toString() + "'"; + if (i + 1 < strKeys.size()) + strValue += ","; + } + strInsert = strInsert.arg(strTableName, strHeader, strValue); + return strInsert; +} + +QString gensql::genSelect(const QString & strTableName, QStringList strSelectList, QString strClass) +{ + QString strDstSelect; + if (strClass.isEmpty()) { + strDstSelect = "SELECT %1 FROM %2"; + } + else { + strDstSelect = "SELECT %1 FROM %2 WHERE " + strClass; + } + + if (0 == strSelectList.size()) { + strDstSelect = strDstSelect.arg("*").arg(strTableName); + } + else { + QString strSeletTmp = strSelectList[0]; + for (int i = 1; i < strSelectList.size(); i++) { + strSeletTmp += "," + strSelectList[i]; + } + strDstSelect = strDstSelect.arg(strSeletTmp, strTableName); + } + + return strDstSelect; +} + +QString gensql::genClass(QString strName, QString strValue) +{ + QString strDst = ""; + strDst += strName + " = '" + strValue + "'"; + return strDst; +} + +QString gensql::genUpdate(const QString & strTableName, QVariantMap &vMap, QString strClass) +{ + QString strDst = "";// + if (strClass.isEmpty()) { + strDst = "UPDATE %1 SET %2";//全部修改 + } + else { + strDst = "UPDATE %1 SET %2 WHERE %3";//指定修改 + } + QString strUpdateTmp = ""; + if (vMap.size() != 0) { + QStringList strList = vMap.keys(); + strUpdateTmp += gensql::genClass(strList[0], vMap[strList[0]].toString()); + for (int i = 1; i < strList.size(); i++) { + strUpdateTmp += "," + gensql::genClass(strList[i], vMap[strList[i]].toString()); + } + } + + strDst = strDst.arg(strTableName, strUpdateTmp, strClass); + return strDst; +} + +QString gensql::genDeleteData(const QString & strTableName, QString strClass) +{ + QString strDst; + if (strClass.isEmpty()) { + strDst = "DELETE FROM %1";//全部删除 + } + else { + strDst = "DELETE FROM %1 WHERE %2";//指定删除 + } + + strDst = strDst.arg(strTableName, strClass); + return strDst; +} + +QString gensql::genInsertColumn(const QString & strTableName, QString strName, QString strType) +{ + QString strDst = "ALTER TABLE %1 ADD COLUMN %2 %3"; + strDst = strDst.arg(strTableName).arg(strName).arg(strType); + + return strDst; +} + +QString gensql::genDeleteColumn(const QString & strTableName, QString strColumnName) +{ + QString strDst = "ALTER TABLE %1 DROP %2"; + strDst = strDst.arg(strTableName, strColumnName); + return strDst; +} + +QString gensql::genCreateTabel(const QString strTable, QString strPrimary, QString strType, QVariantMap &vMap) +{ + QString strDst = "CREATE TABLE IF NOT EXISTS %1 (%2)"; + QString strColumn = strPrimary + " " + strType; + QStringList strList = vMap.keys(); + for (int i = 0; i < strList.size(); i++) { + strColumn += ", " + strList[i] + " " + vMap[strList[i]].toString(); + } + strDst = strDst.arg(strTable, strColumn); + return strDst; +} diff --git a/tpvs17/lpReport/gensql.h b/tpvs17/lpReport/gensql.h new file mode 100644 index 0000000..0a72be0 --- /dev/null +++ b/tpvs17/lpReport/gensql.h @@ -0,0 +1,15 @@ +#ifndef _GENSQL_H_ +#define _GENSQL_H_ +#include "QMetaType" +#include "QString" +namespace gensql{ + QString genInsertData(const QString & strTableName, const QVariantMap &vMap); + QString genSelect(const QString & strTableName, QStringList strSelectList, QString strClass); + QString genClass(QString strName, QString strValue); + QString genUpdate(const QString & strTableName, QVariantMap &vMap, QString strClass); + QString genDeleteData(const QString & strTableName, QString strClass); + QString genInsertColumn(const QString & strTableName, QString strName, QString strType); + QString genDeleteColumn(const QString & strTableName, QString strColumnName); + QString genCreateTabel(const QString strTable, QString strPrimary, QString strType, QVariantMap &vMap); +} +#endif diff --git a/tpvs17/lpReport/lpReport.aps b/tpvs17/lpReport/lpReport.aps new file mode 100644 index 0000000..f5e99f2 Binary files /dev/null and b/tpvs17/lpReport/lpReport.aps differ diff --git a/tpvs17/lpReport/lpReport.cpp b/tpvs17/lpReport/lpReport.cpp new file mode 100644 index 0000000..8f3363f --- /dev/null +++ b/tpvs17/lpReport/lpReport.cpp @@ -0,0 +1,1337 @@ +#include "lpReport.h" +#include "qtimedlg.h" +#include +#include +#include +#include "QProgressDialog" +#include "qsavecsvthread.h" +#include "checkthread.h" +#include "QCompleter" +#include "qreportwidget.h" +#include +#include "ModelDB.h" + +#pragma execution_character_set("utf-8") + +#define WHEEL_PIC_SIZE 150 +enum EM_TYPE_TIME +{ + em_Time_Year = 1, + em_Time_Moth, + em_Time_Day +}; +#define _QSQLITE_WHEELHUBWF_NAME "wheelhubwf.db" +#define WHEEL_DB_FILE "\\pattern\\modelTemplate.db" + +lpReport::lpReport(QWidget *parent) + : QMainWindow(parent) +{ + + qRegisterMetaType("QSqlQuery"); + ui.setupUi(this); + onInitUI(); + QString strDbPath = QApplication::applicationDirPath() + "\\" + _QSQLITE_WHEELHUBWF_NAME; + m_pDb = new DetectDataDB(strDbPath); + m_pDb->InitDatabase(); + m_pDb->ReadOutTimeData(m_Totaltime); + + QString strModelPath = QApplication::applicationDirPath() + "\\" + WHEEL_DB_FILE; + m_pModeDB = new ModelDB(strModelPath); + m_pModeDB->InitDatabase(); + QStringList strList = m_pModeDB->ReadAllModes(); + + m_GridLayout = new QGridLayout; + reportdlg = new QReportWidget; + m_GridLayout->addWidget(reportdlg); + m_countwidget = new QWidget; + Hbox = new QVBoxLayout; + m_GridLayout->setMargin(0); + m_GridLayout->addLayout(Hbox, 0, 1); + m_countwidget->setLayout(m_GridLayout); + nstartTime.setHMS(0, 0, 0); + nEndTime.setHMS(23, 59, 59); + m_tableModel = new QStandardItemModel; + + m_WorkDB = new WorkForDB; + m_WorkDB->moveToThread(&m_Workthread); + m_WorkDB->setDB(m_pDb); + connect(&m_Workthread, &QThread::finished, m_WorkDB, &QObject::deleteLater); + connect(this, &lpReport::operate, m_WorkDB, &WorkForDB::doWork); + connect(m_WorkDB, &WorkForDB::resultReady, this, &lpReport::handleResults); + m_Workthread.start(); + qDebug() << "start thread m_Workthread"; + + m_WorkCount = new CountData; + m_WorkCount->moveToThread(&m_WorkThreadCount); + m_WorkCount->setDB(m_pDb); + connect(&m_WorkThreadCount, &QThread::finished, m_WorkCount, &QObject::deleteLater); + connect(this, &lpReport::operateCount, m_WorkCount, &CountData::doWork); + connect(m_WorkCount, &CountData::resultReady, this, &lpReport::handleResultsCount); + connect(m_WorkCount, SIGNAL(sgShowMsg(QString)), this, SLOT(onShowMessage(QString))); + connect(m_WorkCount, &CountData::sgShowProgress, this, &lpReport::onProgressForTsk); + m_WorkThreadCount.start(); + qDebug() << "start thread m_WorkThreadCount"; + + m_WorkHistory = new CheckData; + m_WorkHistory->moveToThread(&m_WorkThreadCheckHistory); + m_WorkHistory->setDB(m_pDb); + connect(&m_WorkThreadCheckHistory, &QThread::finished, m_WorkHistory, &QObject::deleteLater); + connect(this, &lpReport::operateHistory, m_WorkHistory, &CheckData::doWork); + connect(m_WorkHistory, &CheckData::resultReady, this, &lpReport::handleResultsHistory); + connect(m_WorkHistory, &CheckData::sgShowProgress, this, &lpReport::onProgressForTsk); + m_WorkThreadCheckHistory.start(); + qDebug() << "start thread m_WorkThreadCheckHistory"; + + m_Progressdlg.setWindowModality(Qt::ApplicationModal); + m_Progressdlg.setWindowIcon(QIcon(":/image/leaper")); + m_IsRunCountTsk = false; + ui.scrollArea->setWidget(m_countwidget); + + InitUIParam(); + SetModelNames(strList); + + setWindowTitle("ݼ¼鿴"); + setWindowIcon(QIcon(":/lpReport/Resources/Log.png")); +} + +lpReport::~lpReport() +{ + if (m_Workthread.isRunning()) + { + qDebug() << "delete m_Workthread"; + m_Workthread.quit(); + m_Workthread.wait(50); + qDebug() << "delete m_Workthread end"; + } + if (m_WorkThreadCount.isRunning()) + { + qDebug() << "delete m_WorkThreadCount"; + m_WorkThreadCount.quit(); + m_WorkThreadCount.wait(50); + qDebug() << "delete m_WorkThreadCount end"; + } + if (m_WorkThreadCheckHistory.isRunning()) + { + qDebug() << "delete m_WorkThreadCheckHistory"; + m_WorkThreadCheckHistory.quit(); + m_WorkThreadCheckHistory.wait(50); + qDebug() << "delete m_WorkThreadCheckHistory end"; + } + if (m_tableWarnModel) { + delete m_tableWarnModel; + m_tableWarnModel = NULL; + } + if (m_tableModel) { + delete m_tableModel; + m_tableModel = NULL; + } + if (_pCompleter) { + delete _pCompleter; + _pCompleter = NULL; + } + if (m_countwidget) + { + delete m_countwidget; + m_countwidget = NULL; + } + +} + +void lpReport::onInitUI() +{ + connect(ui.pushButton_Set1_Warning, SIGNAL(clicked()), this, SLOT(SlotEditTime())); + connect(ui.pushButton_Set2_Warning, SIGNAL(clicked()), this, SLOT(SlotEditTime())); + connect(ui.pushButton_Set1_History, SIGNAL(clicked()), this, SLOT(SlotEditTime())); + connect(ui.pushButton_Set2_History, SIGNAL(clicked()), this, SLOT(SlotEditTime())); + connect(ui.pushButton_Set1_Count, SIGNAL(clicked()), this, SLOT(SlotEditTime())); + connect(ui.pushButton_Set2_Count, SIGNAL(clicked()), this, SLOT(SlotEditTime())); + + connect(ui.pushButton_Checkdata, SIGNAL(clicked()), this, SLOT(onCheckButton())); + connect(ui.pushButton_SaveHistory, SIGNAL(clicked()), this, SLOT(onCheckButton())); + connect(ui.pushButton_Wandring, SIGNAL(clicked()), this, SLOT(onCheckButton())); + connect(ui.pushButton_SaveWaring, SIGNAL(clicked()), this, SLOT(onCheckButton())); + connect(ui.pushButton_Checkdata_Calculate, SIGNAL(clicked()), this, SLOT(onCheckButton())); + connect(ui.pushButton_SaveCalculate, SIGNAL(clicked()), this, SLOT(onCheckButton())); + connect(this, SIGNAL(sgSetCurrentIndex(int)), ui.stackedWidget, SLOT(setCurrentIndex(int))); + connect(ui.comboBox_Banci_Calculate, SIGNAL(currentIndexChanged(int)), this, SLOT(SlotCombox(int))); + connect(ui.comboBox_Banci, SIGNAL(currentIndexChanged(int)), this, SLOT(SlotCombox(int))); + + ui.comboBox_Model->setEditable(true); + + connect(ui.Prev_checkShengchang, SIGNAL(clicked()), this, SLOT(onHistoryButton())); + connect(ui.Next_checkShengchang, SIGNAL(clicked()), this, SLOT(onHistoryButton())); + + ui.LineNumber_checkShengchang->setText("50"); + QValidator *validator = new QIntValidator(1, 9999, this); + ui.LineNumber_checkShengchang->setValidator(validator); + + ui.showNum_Label_Checkdata->setText(tr("ʾ%1¼").arg(0)); + ui.showPage_Label_Checkdata->setText(tr("%1ҳ %2ҳ").arg(0).arg(0)); + + int nItenCount = ui.check_listWidget->count(); + for (int nIndex = 0; nIndex < nItenCount; nIndex++) + { + QListWidgetItem *itenn = ui.check_listWidget->item(nIndex); + QSize s = itenn->sizeHint(); + itenn->setSizeHint(QSize(s.width(), 45)); + } + connect(ui.check_listWidget, SIGNAL(currentRowChanged(int)), this, SLOT(onSetCurrentIndex(int))); + + + ui.LineNumber_log->setText("50"); + QValidator *validatorlog = new QIntValidator(1, 9999, this); + ui.LineNumber_log->setValidator(validatorlog); + + connect(ui.Prev_checklog, SIGNAL(clicked()), this, SLOT(onLogButton())); + connect(ui.Next_checklog, SIGNAL(clicked()), this, SLOT(onLogButton())); + + ui.showPage_Label_Checkdata_2->setText(tr("%1ҳ %2ҳ").arg(0).arg(0)); + ui.showNum_Label_Checkdata_2->setText(tr("ʾ%1¼").arg(0)); +} + +void lpReport::timerEvent(QTimerEvent *event) +{ + +} + +Q_SLOT void lpReport::SlotEditTime() +{ + QObject *obj = sender(); + QString str = obj->objectName(); + if (str == "pushButton_Set1_Count") + { + QTimeDlg dlg; + dlg.SetDateTime(m_startDate_Count); + dlg.setWindowModality(Qt::ApplicationModal); + if (dlg.exec() == QDialog::Accepted) + { + dlg.GetDateTime(m_startDate_Count); + QString m_strLast = m_startDate_Count.toString("yyyy-MM-dd hh:mm:ss"); + ui.label_Time1_Count->setText(m_strLast); + } + } + else if (str == "pushButton_Set2_Count") + { + QTimeDlg dlg; + dlg.SetDateTime(m_endDate_Count); + if (dlg.exec() == QDialog::Accepted) + { + dlg.GetDateTime(m_endDate_Count); + QString m_endLast = m_endDate_Count.toString("yyyy-MM-dd hh:mm:ss"); + ui.label_Time2_Count->setText(m_endLast); + } + } + else if (str == "pushButton_Set1_Warning") + { + QTimeDlg dlg; + dlg.SetDateTime(m_startDate_Warning); + if (dlg.exec() == QDialog::Accepted) + { + dlg.GetDateTime(m_startDate_Warning); + QString m_endLast = m_startDate_Warning.toString("yyyy-MM-dd hh:mm:ss"); + ui.label_Time1_warning->setText(m_endLast); + } + } + else if (str == "pushButton_Set2_Warning") + { + QTimeDlg dlg; + dlg.SetDateTime(m_endDate_Warning); + if (dlg.exec() == QDialog::Accepted) + { + dlg.GetDateTime(m_endDate_Warning); + QString m_endLast = m_endDate_Warning.toString("yyyy-MM-dd hh:mm:ss"); + ui.label_Time2_warning->setText(m_endLast); + } + } + else if (str == "pushButton_Set1_History") + { + QTimeDlg dlg(NULL); + dlg.SetDateTime(m_startDate_History); + if (dlg.exec() == QDialog::Accepted) + { + dlg.GetDateTime(m_startDate_History); + QString m_endLast = m_startDate_History.toString("yyyy-MM-dd hh:mm:ss"); + ui.label_Time1_History->setText(m_endLast); + } + } + else if (str == "pushButton_Set2_History") + { + QTimeDlg dlg; + dlg.SetDateTime(m_endDate_History); + if (dlg.exec() == QDialog::Accepted) + { + dlg.GetDateTime(m_endDate_History); + QString m_endLast = m_endDate_History.toString("yyyy-MM-dd hh:mm:ss"); + ui.label_Time2_History->setText(m_endLast); + } + } +} + +Q_SLOT void lpReport::onCheckButton() +{ + QObject *obj = sender(); + QString str = obj->objectName(); + if ("pushButton_Checkdata" == str)//ѯ + {/*Ҫݷҳʾ ڴй¶*/ + static bool checkflags = false; + if (checkflags == false) + { + checkflags = true; + QString strBanci = ui.comboBox_Banci->currentText(); + QString modelName = ui.comboBox_Model->currentText(); + if (m_Totaltime.contains(strBanci)) + { + if (m_startDate_History.date() > m_endDate_History.date()) + { + if (m_Totaltime.value(strBanci).m_startTime > m_Totaltime.value(strBanci).m_endTime) + { + onMessageBox(QMessageBox::Information, tr("ʾ"), tr("ѡİʱǸҹģѡһµǰѯڣٲѯ")); + checkflags = false; + return; + } + else + { + onMessageBox(QMessageBox::Information, tr("ʾ"), tr("ѡڲѡһµǰѯڣٲѯ")); + checkflags = false; + return; + } + } + } + else + { + if (m_startDate_History.date() > m_endDate_History.date()) + { + onMessageBox(QMessageBox::Information, tr("ʾ"), tr("ѡڲѡһµǰѯڣٲѯ")); + checkflags = false; + return; + } + } + + QString m_strLast = ui.label_Time1_History->text(); + QString m_endLast = ui.label_Time2_History->text(); + QString strMsg = tr("ѯ%1-%2").arg(m_strLast).arg(m_endLast); + SaveLog(strMsg); + QApplication::setOverrideCursor(Qt::WaitCursor); + QFont font; + font.setPixelSize(14); + ui.label_Tab2_Title->setFont(font); + QString m_Title = tr("ʼʱ:%1 ʱ:%2 ʷ¼").arg(m_strLast).arg(m_endLast); + ui.label_Tab2_Title->setText(m_Title); + if (modelName == tr("ȫ")) + CheckDataHistoryByDate(m_strLast, m_endLast, "*"); + else + CheckDataHistoryByDate(m_strLast, m_endLast, modelName); + QApplication::restoreOverrideCursor(); + checkflags = false; + } + else + { + onMessageBox(QMessageBox::Information, tr("ʾ"), tr("ڲѯݣԺ")); + } + } + else if ("pushButton_SaveHistory" == str) + { + if (m_tableModel == NULL) + return; + if (m_tableModel->rowCount() <= 0) + { + onMessageBox(QMessageBox::Warning, tr("ʾ"), tr("ûݣ²ѯ")); + return; + } + + QString filename = QString("History_%1.csv").arg(QDateTime::currentDateTime().toString("yyyy_MM_dd")); + QString fileTitle = tr("ѡ񱣴ļ·"); + QFileDialog *fileDialog = new QFileDialog(NULL, fileTitle, filename); + fileDialog->setWindowTitle("Save As"); + fileDialog->setAcceptMode(QFileDialog::AcceptSave); + fileDialog->setFileMode(QFileDialog::AnyFile); + fileDialog->setViewMode(QFileDialog::Detail); + fileDialog->setGeometry(10, 30, 300, 200); + fileDialog->setDirectory("."); + fileDialog->setNameFilter("Execl(*.csv)"); + + if (fileDialog->exec() == QDialog::Accepted) + { + QString path = fileDialog->selectedFiles()[0]; + + QString strString = getHistoryCheckString(); + QSaveCSVThread *workerThread = new QSaveCSVThread(this); + workerThread->setInform(ui.label_Tab2_Title->text(), "username"); + workerThread->setCheckStr(m_pDb, strString, path, 0); + connect(workerThread, SIGNAL(resultReady(int)), this, SLOT(onSaveCSVDone(int))); + connect(workerThread, &QSaveCSVThread::finished, workerThread, &QObject::deleteLater); + workerThread->start(); + + onEventLoop(tr("ڵݣԵ")); + + QString strMsg = tr("%1-%2").arg(ui.label_Time1_History->text()).arg(ui.label_Time2_History->text()); + SaveLog(strMsg); + onMessageBox(QMessageBox::Information, tr("ʾ"), tr("ݵ")); + } + if (fileDialog) { + delete fileDialog; + fileDialog = NULL; + } + } + else if (str == "pushButton_Wandring") + { + static bool checkflags = false; + if (checkflags == false) + { + checkflags = true; + QApplication::setOverrideCursor(Qt::WaitCursor); + QString m_strLast = ui.label_Time1_warning->text(); + QString m_endLast = ui.label_Time2_warning->text(); + QString strMsg = tr("ѯ%1-%2־").arg(m_strLast).arg(m_endLast); + QString strCombox = ui.comboBox_Wandring_Log->currentText(); + int mType = 0; + if (strCombox == tr("ʹü¼ѯ")) { + mType = (int)emTypeUseState; + } + else if (strCombox == tr("¼ѯ")) { + mType = (int)emTypeWaring; + } + else if (strCombox == tr("״̬ѯ")) { + mType = (int)emTypeRunState; + } + SaveLog(strMsg); + QFont font; + font.setPixelSize(14); + ui.label_Tab3_Title->setFont(font); + QString m_Title = tr("ʼʱ:%1 ʱ:%2 ʷ¼").arg(m_strLast).arg(m_endLast); + ui.label_Tab3_Title->setText(m_Title); + + CheckDataWarningByDate(mType, m_strLast, m_endLast); + QApplication::restoreOverrideCursor(); + checkflags = false; + } + else + { + onMessageBox(QMessageBox::Information, tr("ʾ"), tr("ڲѯݣԺ")); + } + } + else if (str == "pushButton_SaveWaring") + { + if (m_tableWarnModel == NULL) + { + onMessageBox(QMessageBox::Warning, tr("ʾ"), tr("ûݣ²ѯ")); + return; + } + if (m_tableWarnModel->rowCount() <= 0) + { + onMessageBox(QMessageBox::Warning, tr("ʾ"), tr("ûݣ²ѯ")); + return; + } + QString filename = QString("WarnMessage_%1.csv").arg(QDateTime::currentDateTime().toString("yyyy_MM_dd")); + QString fileTitle = tr("ѡ񱣴ļ·"); + QFileDialog *fileDialog = new QFileDialog(NULL, fileTitle, filename); + fileDialog->setWindowTitle("Save As"); + fileDialog->setAcceptMode(QFileDialog::AcceptSave); + fileDialog->setFileMode(QFileDialog::AnyFile); + fileDialog->setViewMode(QFileDialog::Detail); + fileDialog->setGeometry(10, 30, 300, 200); + fileDialog->setDirectory("."); + fileDialog->setNameFilter("Execl(*.csv)"); + + if (fileDialog->exec() == QDialog::Accepted) + { + QString path = fileDialog->selectedFiles()[0]; + QString strString = getLogCheckString(); + QSaveCSVThread *workerThread = new QSaveCSVThread(this); + workerThread->setInform(ui.label_Tab3_Title->text(), "username"); + workerThread->setCheckStr(m_pDb, strString, path, 1); + connect(workerThread, SIGNAL(resultReady(int)), this, SLOT(onSaveCSVDone(int))); + connect(workerThread, &QSaveCSVThread::finished, workerThread, &QObject::deleteLater); + workerThread->start(); + + onEventLoop(tr("ڵݣԵ")); + + QString strMsg = tr("%1-%2־").arg(ui.label_Time1_warning->text()).arg(ui.label_Time2_warning->text()); + SaveLog(strMsg); + onMessageBox(QMessageBox::Information, tr("ʾ"), tr("ݵ")); + } + if (fileDialog) { + delete fileDialog; + fileDialog = NULL; + } + } + else if ("pushButton_Checkdata_Calculate" == str) + { + static bool checkflags = false; + if (checkflags == false) + { + checkflags = true; + QString strBanci = ui.comboBox_Banci_Calculate->currentText(); + QString modelName = ui.comboBox_Model->currentText(); + if (m_Totaltime.contains(strBanci)) + { + if (m_startDate_Count.date() > m_endDate_Count.date()) + { + if (m_Totaltime.value(strBanci).m_startTime > m_Totaltime.value(strBanci).m_endTime) + { + onMessageBox(QMessageBox::Information, tr("ʾ"), tr("ѡİʱǸҹģѡһµǰѯڣٲѯ")); + checkflags = false; + return; + } + else + { + onMessageBox(QMessageBox::Information, tr("ʾ"), tr("ѡڲʼڣٲѯ")); + checkflags = false; + return; + } + } + } + else + { + if (m_startDate_Count.date() > m_endDate_Count.date()) + { + onMessageBox(QMessageBox::Information, tr("ʾ"), tr("ѡڲѡһµǰѯڣٲѯ")); + checkflags = false; + return; + } + } + QString m_strLast = ui.label_Time1_Count->text(); + QString m_endLast = ui.label_Time2_Count->text(); + QString strMsg = tr("ѯ%1-%2ͳ").arg(ui.label_Time1_Count->text()).arg(ui.label_Time2_Count->text()); + SaveLog(strMsg); + QApplication::setOverrideCursor(Qt::WaitCursor); + CheckDataByDate(m_strLast, m_endLast); + QApplication::restoreOverrideCursor(); + checkflags = false; + } + else + { + onMessageBox(QMessageBox::Information, tr("ʾ"), tr("ڲѯݣԺ")); + } + } + else if ("pushButton_SaveCalculate" == str) + { + if (m_CountNumber.size() <= 0) + { + onMessageBox(QMessageBox::Warning, tr("ʾ"), tr("ûݣ²ѯ")); + return; + } + QString filename = QString("Data_%1.csv").arg(QDateTime::currentDateTime().toString("yyyy_MM_dd")); + QString fileTitle = tr("ѡ񱣴ļ·"); + QFileDialog *fileDialog = new QFileDialog(NULL, fileTitle, filename); + fileDialog->setWindowTitle("Save As"); + fileDialog->setAcceptMode(QFileDialog::AcceptSave); + fileDialog->setFileMode(QFileDialog::AnyFile); + fileDialog->setViewMode(QFileDialog::Detail); + fileDialog->setGeometry(10, 30, 300, 200); + fileDialog->setDirectory("."); + fileDialog->setNameFilter("Execl(*.csv)"); + + if (fileDialog->exec() == QDialog::Accepted) + { + QString path = fileDialog->selectedFiles()[0]; + if (SaveDataToCSV(path, m_CountNumber)) + onMessageBox(QMessageBox::Information, tr("ʾ"), tr("ݵ")); + QString strMsg = tr("%1-%2ͳ").arg(ui.label_Time1_Count->text()).arg(ui.label_Time2_Count->text()); + SaveLog(strMsg); + } + if (fileDialog) { + delete fileDialog; + fileDialog = NULL; + } + } +} + +bool lpReport::onMessageBox(QMessageBox::Icon ntype, QString strTitle, QString strAtl, int onlyOK) +{ + QMessageBox::StandardButton button = QMessageBox::Ok; + + if (onlyOK == 1) + button = QMessageBox::Cancel; + QMessageBox infobox(ntype, strTitle, strAtl, QMessageBox::Ok | button, NULL); + infobox.setWindowIcon(QIcon(":/image/leaper")); + infobox.setButtonText(QMessageBox::Ok, tr("ȷ")); + infobox.setButtonText(QMessageBox::Cancel, tr("ȡ")); + return (infobox.exec() == QMessageBox::Ok); +} + +void lpReport::CheckDataHistoryByDate(QString m_strLast, QString m_endLast, QString modelname) +{ + QSqlQuery sql; + QVariantMap m_Value; + m_Value.insert(_CHECK_TYPE_, EMT_CHECK_BY_NAME); + m_Value.insert(_CHECK_TIME1_, m_strLast); + m_Value.insert(_CHECK_TIME2_, m_endLast); + m_Value.insert(_CHECK_NAME_, modelname); + m_Value.insert(_CHECK_COUNT_, 1); + if (modelname == "*") + m_Value.insert(_CHECK_TYPE_, EMT_CHECK_BY_SAE); + else + m_Value.insert(_CHECK_TYPE_, EMT_CHECK_BY_NAME); + QString strString; + strString = m_pDb->genCheckStr(m_Value); + int nlimit = ui.LineNumber_checkShengchang->text().toInt(); + if (nlimit <= 0) + { + nlimit = 10; + ui.LineNumber_checkShengchang->setText("10"); + } + m_totlaNum = 0; + m_PrevNum = 0; + QString strStringcheck; + if (modelname == "*") + strStringcheck = QString("select * from wftable where time >'%1' and time <'%2' LIMIT %4 OFFSET %5").arg(m_strLast).arg(m_endLast).arg(nlimit).arg(m_PrevNum); + else + strStringcheck = QString("select * from wftable where time >'%1' and time <'%2' and model = '%3' LIMIT %4 OFFSET %5").arg(m_strLast).arg(m_endLast).arg(modelname).arg(nlimit).arg(m_PrevNum); + QVariantMap m_mapVarite; + m_mapVarite.insert("SqlCount", strString); + m_mapVarite.insert("SqlCheck", strStringcheck); + m_mapVarite.insert("limit", nlimit); + emit operateHistory(m_mapVarite); + +} + +bool lpReport::SaveDataToCSV(QString filePath, QMap &m_mapTable) +{ + QFile file(filePath); + if (!file.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Append))// ׷д + return false; + QTextStream out(&file); + QString tableData; + QString m_startStr = m_startDate_Count.toString("yyyy-MM-dd ") + m_startTime.toString("hh:mm:ss"); + QString m_endStr = m_endDate_Count.toString("yyyy-MM-dd ") + m_endTime.toString("hh:mm:ss"); + out << tr("%1%2ͳƵ").arg(m_startStr).arg(m_endStr) << "\n"; + out << tr("") << "," << tr("ͺ") << "," << tr("") << "\n"; + int index = 1; + int sum = 0; + for (QMap::iterator its = m_mapTable.begin(); its != m_mapTable.end(); ++its) + { + out << (index++) << ","; + tableData = its.key(); + out << tableData << ","; + out << QString::number(m_mapTable[tableData]) << ","; + sum += m_mapTable[tableData]; + out << "\n"; + } + if (!m_mapTable.contains(QString("NG"))) + { + out << (index++) << "," << QString("NG") << "," << 0 << "\n"; + } + out << (index++) << "," << tr("") << "," << QString::number(sum) << "\n"; + out << tr("ʱ:") << "," << QDateTime::currentDateTime().toString("yyyy-MM-dd") << "," << QDateTime::currentDateTime().toString("hh:mm:ss") << "\n"; + out << tr("û:") << "," << "username" << "," << "\n"; + file.close(); + return true; +} + +void lpReport::CheckDataByDate(QString m_strLast, QString m_endLast) +{ + if (m_IsRunCountTsk != false) + { + return; + } + m_IsRunCountTsk = true; + m_CountNumber.clear(); + m_channels.clear(); + + QProgressDialog progress; + progress.setWindowModality(Qt::ApplicationModal); + progress.setWindowTitle(tr("ѯ")); + progress.setWindowIcon(QIcon(":/image/leaper")); + progress.setLabelText(tr("ݲѯ,Ժ.....")); + progress.setCancelButton(0); + QSqlQuery sql; + QVariantMap m_Value; + m_Value.insert(_CHECK_TYPE_, EMT_CHECK_BY_COUNT); + m_Value.insert(_CHECK_TIME1_, m_strLast); + m_Value.insert(_CHECK_TIME2_, m_endLast); + m_Value.insert("CheckType", "Count"); + QString strCheck = m_pDb->genCheckStr(m_Value); + m_Value.insert(_CHECK_COUNT_, 1); + QString strCount = m_pDb->genCheckStr(m_Value); + QVariantMap m_map; + m_map.insert("SqlCount", strCount); + m_map.insert("SqlCheck", strCheck); + emit operateCount(m_map); +} + +void lpReport::onEventLoop(QString strMsg) +{ + WaitingDialog dlg; + dlg.setWindowModality(Qt::ApplicationModal); + dlg.setWindowIcon(QIcon(":/image/leaper")); + dlg.setWindowTitle(strMsg); + dlg.Start(50, 150), + dlg.show(); + QEventLoop eventloop; + connect(this, SIGNAL(sgFinish()), &eventloop, SLOT(quit())); + eventloop.exec(); +} + + +void lpReport::SaveLog(QString str) +{ + // QString strMsg = m_pCtrl->getUserName() + ":" + str; + // m_pCtrl->addLog(strMsg, emTypeUseState); +} + +QString lpReport::getHistoryCheckString() +{ + QString m_strLast = ui.label_Time1_History->text(); + QString m_endLast = ui.label_Time2_History->text(); + QString modelName = ui.comboBox_Model->currentText(); + QString strString; + if (modelName == tr("ȫ")) + strString = QString("select * from wftable where time >'%1' and time <'%2'").arg(m_strLast).arg(m_endLast); + else + strString = QString("select * from wftable where time >'%1' and time <'%2' and model = '%3'").arg(m_strLast).arg(m_endLast).arg(modelName); + return strString; +} + +Q_SLOT void lpReport::onHistoryButton() +{ + QString strObj = sender()->objectName(); + if ("Prev_checkShengchang" == strObj) { + + if (m_PrevNum <= 0) + return; + int limitNum = ui.LineNumber_checkShengchang->text().toInt(); + if (limitNum <= 0) + { + limitNum = 10; + ui.LineNumber_checkShengchang->setText("10"); + } + QString strString = getHistoryCheckString(); + m_PrevNum -= limitNum; + if (m_PrevNum <= 0) + m_PrevNum = 0; + strString = strString + QString(" LIMIT %1 OFFSET %2").arg(limitNum).arg(m_PrevNum); + + /*̲߳ѯ ٽ濨*/ + CheckThread *workerThread = new CheckThread(this); + workerThread->setCheckStr(m_pDb, strString); + connect(workerThread, SIGNAL(resultReady(QSqlQuery)), this, SLOT(onUpdateTableViewShow(QSqlQuery))); + connect(workerThread, &CheckThread::finished, workerThread, &QObject::deleteLater); + workerThread->start(); + + m_totalPage = (m_totlaNum / limitNum); + m_page = ((m_PrevNum) / limitNum) + 1; + ui.showPage_Label_Checkdata->setText(tr("%1ҳ %2ҳ").arg(m_page).arg(m_totalPage + 1)); + if (m_PrevNum <= 0) + { + m_PrevNum = 0; + ui.Prev_checkShengchang->setDisabled(true); + } + ui.Next_checkShengchang->setDisabled(false); + } + else if ("Next_checkShengchang" == strObj) { + if (m_PrevNum >= m_totlaNum) + return; + int limitNum = ui.LineNumber_checkShengchang->text().toInt(); + if (limitNum <= 0) + { + limitNum = 10; + ui.LineNumber_checkShengchang->setText("10"); + } + m_PrevNum += limitNum; + if (m_PrevNum >= m_totlaNum) + m_PrevNum = m_totlaNum - limitNum; + QString strString = getHistoryCheckString(); + strString = strString + QString(" LIMIT %1 OFFSET %2").arg(limitNum).arg(m_PrevNum); + + /*̲߳ѯ ٽ濨*/ + CheckThread *workerThread = new CheckThread(this); + workerThread->setCheckStr(m_pDb, strString); + connect(workerThread, SIGNAL(resultReady(QSqlQuery)), this, SLOT(onUpdateTableViewShow(QSqlQuery))); + connect(workerThread, &CheckThread::finished, workerThread, &QObject::deleteLater); + workerThread->start(); + + m_totalPage = (m_totlaNum / limitNum); + m_page = (m_PrevNum + limitNum) / limitNum; + ui.showPage_Label_Checkdata->setText(tr("%1ҳ %2ҳ").arg(m_page).arg(m_totalPage + 1)); + if ((m_PrevNum + limitNum) >= m_totlaNum) + { + m_PrevNum = m_totlaNum; + ui.Next_checkShengchang->setDisabled(true); + } + ui.Prev_checkShengchang->setDisabled(false); + } +} + +void lpReport::cleanHistorycal() +{ + m_PrevNum = 0; + m_NextNum = 0; + m_totlaNum = 0; + m_page = 0; + m_totalPage = 0; + + m_PrevNumlog = 0; + m_NextNumlog = 0; + m_totlaNumlog = 0; + m_pagelog = 0; + m_totalPagelog = 0; + + ui.showNum_Label_Checkdata->setText(tr("ʾ%1¼").arg(0)); + ui.showPage_Label_Checkdata->setText(tr("%1ҳ %2ҳ").arg(0).arg(0)); + ui.Prev_checkShengchang->setDisabled(true); + ui.Next_checkShengchang->setDisabled(true); + + ui.showNum_Label_Checkdata_2->setText(tr("ʾ%1¼").arg(0)); + ui.showPage_Label_Checkdata_2->setText(tr("%1ҳ %2ҳ").arg(0).arg(0)); + ui.Prev_checklog->setDisabled(true); + ui.Next_checklog->setDisabled(true); +} + +Q_SLOT void lpReport::onSetCurrentIndex(int nIndex) +{ + ui.label_Title->setText(ui.check_listWidget->item(nIndex)->data(0).toString()); + emit(sgSetCurrentIndex(nIndex)); +} + +Q_SLOT void lpReport::onSaveCSVDone(int) +{ + emit(sgFinish()); +} + +Q_SLOT void lpReport::handleResults(QString str) +{ + //QString strMsg = "username" + ":" + tr("ϵͳԶʱѯһɣĿڵ"); + //m_pCtrl->addLog(strMsg, emTypeRunState); + onShowMessage(tr("ϵͳԶ")); +} +Q_SLOT void lpReport::onShowMessage(QString str) +{ + // QPulpewidget *pw = new QPulpewidget(); + // pw->showmessage(str); + // pw->setParent(m_pDlgCheck); + // connect(pw, SIGNAL(finished()), pw, SLOT(deleteLater()));// +} + + +Q_SLOT void lpReport::onProgressForTsk(QVariantMap m_map) +{ + QString nType = m_map.value("Type").toString(); + if (nType == "start") + { + QString strMsg = m_map.value("msg", tr("ڲѯ")).toString(); + m_Progressdlg.setWindowTitle(strMsg); + m_Progressdlg.Start(50, 150), + m_Progressdlg.show(); + } + else + { + m_Progressdlg.Stop(); + m_Progressdlg.hide(); + } +} + +Q_SLOT void lpReport::handleResultsHistory(QVariantMap Mapstr, QSqlQuery sql) +{ + updateModelShowHistory(sql); + QString m_strLast = ui.label_Time1_History->text(); + QString m_endLast = ui.label_Time2_History->text(); + m_totlaNum = Mapstr.value("sum").toInt(); + int nlimit = Mapstr.value("limit").toInt(); + int nIndex = Mapstr.value("nIndex").toInt(); + QString m_Title = tr("ʼʱ:%1 ʱ:%2 ʷ¼ %3").arg(m_strLast).arg(m_endLast).arg(m_totlaNum); + ui.label_Number->setText(QString::number(m_totlaNum)); + QFont font; + font.setPixelSize(14); + font.setBold(true); + ui.label_Tab2_Title->setFont(font); + ui.label_Tab2_Title->setText(m_Title); + ui.Next_checkShengchang->setDisabled(false); + m_totalPage = (m_totlaNum / nlimit); + if (m_totlaNum > 0) + { + m_totalPage = m_totalPage + 1; + m_page = 1; + nIndex = m_totlaNum; + } + else + { + m_totlaNum = 0; + m_page = 0; + } + ui.showPage_Label_Checkdata->setText(tr("%1ҳ %2ҳ").arg(m_page).arg(m_totalPage)); + ui.showNum_Label_Checkdata->setText(tr("ʾ%1¼").arg(nIndex)); + onShowMessage(tr("ݲѯ")); +} + +Q_SLOT void lpReport::onShowMsg() +{ + onMessageBox(QMessageBox::Information, tr("ʾ"), tr("Ч")); +} + +Q_SLOT void lpReport::handleResultsCount(const QString &result, const QMap *p) +{ + reportdlg->ClearData(); + reportdlg->setTitle(tr("ͳƽ ")); + if (p == NULL) { + m_IsRunCountTsk = false; + return; + } + reportdlg->SetData(QMap(*p)/*m_CountNumber*/); + if (!p->contains(QString("NG"))) + reportdlg->AppendData(QString("NG"), 0, true); + reportdlg->AppendData(tr(""), result.toInt(), true); + reportdlg->UpdateTableView(); + onShowMessage(tr("ͳ")); + m_IsRunCountTsk = false; + if (p) + delete p; +} + +Q_SLOT void lpReport::onLogButton() +{ + QString strObj = sender()->objectName(); + if ("Prev_checklog" == strObj) { + if (m_PrevNumlog <= 0) + return; + int limitNum = ui.LineNumber_log->text().toInt(); + if (limitNum <= 0) + { + limitNum = 10; + ui.LineNumber_log->setText("10"); + } + m_PrevNumlog -= limitNum; + if (m_PrevNumlog <= 0) + m_PrevNumlog = 0; + QString strString = getLogCheckString(); + strString += QString(" LIMIT %1 OFFSET %2 ").arg(limitNum).arg(m_PrevNumlog); + /*̲߳ѯ ٽ濨*/ + CheckThread *workerThread = new CheckThread(this); + workerThread->setCheckStr(m_pDb, strString); + connect(workerThread, SIGNAL(resultReady(QSqlQuery)), this, SLOT(onUpdateTableViewShowlog(QSqlQuery))); + connect(workerThread, &CheckThread::finished, workerThread, &QObject::deleteLater); + workerThread->start(); + + m_totalPagelog = (m_totlaNumlog / limitNum); + m_pagelog = ((m_PrevNumlog) / limitNum) + 1; + ui.showPage_Label_Checkdata_2->setText(tr("%1ҳ %2ҳ").arg(m_pagelog).arg(m_totalPagelog + 1)); + if (m_PrevNumlog <= 0) + { + m_PrevNumlog = 0; + ui.Prev_checklog->setDisabled(true); + } + ui.Next_checklog->setDisabled(false); + } + else if ("Next_checklog" == strObj) { + if (m_PrevNumlog >= m_totlaNumlog) + return; + int limitNum = ui.LineNumber_log->text().toInt(); + if (limitNum <= 0) + { + limitNum = 10; + ui.LineNumber_log->setText("10"); + } + m_PrevNumlog += limitNum; + if (m_PrevNumlog >= m_totlaNumlog) + m_PrevNumlog = m_totlaNumlog - limitNum; + QString strString = getLogCheckString(); + + strString += QString(" LIMIT %1 OFFSET %2 ").arg(limitNum).arg(m_PrevNumlog); + /*̲߳ѯ ٽ濨*/ + CheckThread *workerThread = new CheckThread(this); + workerThread->setCheckStr(m_pDb, strString); + connect(workerThread, SIGNAL(resultReady(QSqlQuery)), this, SLOT(onUpdateTableViewShowlog(QSqlQuery))); + connect(workerThread, &CheckThread::finished, workerThread, &QObject::deleteLater); + workerThread->start(); + + m_totalPagelog = (m_totlaNumlog / limitNum); + m_pagelog = (m_PrevNumlog + limitNum) / limitNum; + ui.showPage_Label_Checkdata_2->setText(tr("%1ҳ %2ҳ").arg(m_pagelog).arg(m_totalPagelog + 1)); + if ((m_PrevNumlog + limitNum) >= m_totlaNumlog) + { + m_PrevNumlog = m_totlaNumlog; + ui.Next_checklog->setDisabled(true); + } + ui.Prev_checklog->setDisabled(false); + } +} + +QString lpReport::getLogCheckString(int nCheckCount/*=0*/) +{ + QString m_strLast = ui.label_Time1_warning->text(); + QString m_endLast = ui.label_Time2_warning->text(); + QString strCombox = ui.comboBox_Wandring_Log->currentText(); + int mType = 0; + if (strCombox == tr("ʹü¼ѯ")) { + mType = (int)emTypeUseState; + } + else if (strCombox == tr("¼ѯ")) { + mType = (int)emTypeWaring; + } + else if (strCombox == tr("״̬ѯ")) { + mType = (int)emTypeRunState; + } + QVariantMap m_vlaue; + m_vlaue.insert(_CHECK_TIME1_, m_strLast); + m_vlaue.insert(_CHECK_TIME2_, m_endLast); + m_vlaue.insert(_CHECK_LOGTYPE, mType); + m_vlaue.insert(_CHECK_TYPE_, EMT_CHECK_BY_LOG); + if (nCheckCount == 1) + m_vlaue.insert(_CHECK_COUNT_, 1); + return m_pDb->genCheckStr(m_vlaue); +} + +Q_SLOT void lpReport::onUpdateTableViewShow(QSqlQuery sql) +{ + updateModelShowHistory(sql); +} + +void lpReport::updateModelShowHistory(QSqlQuery &sql) +{ + QStandardItemModel *testmodel = new QStandardItemModel; + ui.tableView_checkShengchang->setModel(testmodel);//ȽģͲһʾ ʾ + ui.tableView_checkShengchang->setEditTriggers(QAbstractItemView::NoEditTriggers); + ui.tableView_checkShengchang->setSelectionBehavior(QAbstractItemView::SelectRows); + ui.tableView_checkShengchang->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);//Ӧп + ui.tableView_checkShengchang->horizontalHeader()->setMaximumHeight(100); + + if (m_tableModel == NULL) + m_tableModel = new QStandardItemModel; + m_tableModel->clear(); + ui.CheckDlg_label_Pic->clear(); + m_tableModel->setHorizontalHeaderItem(0, new QStandardItem(tr("ʱ"))); + m_tableModel->setHorizontalHeaderItem(1, new QStandardItem(tr("ƥͺ"))); + m_tableModel->setHorizontalHeaderItem(2, new QStandardItem(tr("ƶ"))); + m_tableModel->setHorizontalHeaderItem(3, new QStandardItem(tr("ʱs"))); + m_tableModel->setHorizontalHeaderItem(4, new QStandardItem(tr("ֱmm"))); + m_tableModel->setHorizontalHeaderItem(5, new QStandardItem(tr("mm"))); + m_tableModel->setHorizontalHeaderItem(6, new QStandardItem(tr("ͼ"))); + m_tableModel->setHorizontalHeaderItem(7, new QStandardItem(tr("uid"))); + int nIndex = 0; + + while (sql.next()) + { + /*ͳƲѯͨӦIJƷ*/ + int uid = sql.value("uid").toInt(); + QString time = sql.value("time").toString(); + QString model = sql.value("model").toString(); + double dCorrelate = sql.value("correlate").toDouble(); + QString correlate; + if (dCorrelate >= 1.7976931348623158e+308) + dCorrelate = 0; + correlate = QString::number(dCorrelate * 100, 'f', 3) + "%"; + double dDetecttime = sql.value("detecttime").toDouble(); + QString detecttime = QString::number(dDetecttime, 'f', 3); + double dDiameter = sql.value("diameter").toDouble(); + QString diameter = QString::number(dDiameter, 'f', 3); + double dHight = sql.value("hight").toDouble(); + QString hight = QString::number(dHight, 'f', 3); + QByteArray pic = sql.value("pic").toByteArray(); + QImage img = QImage::fromData(pic); + QSize s = img.size(); + QPixmap m_Pix = QPixmap::fromImage(img); + ui.CheckDlg_label_Pic->setPixmap(m_Pix.scaled(WHEEL_PIC_SIZE, WHEEL_PIC_SIZE)); + m_tableModel->setItem(nIndex, 0, new QStandardItem(time)); + m_tableModel->setItem(nIndex, 1, new QStandardItem(model)); + m_tableModel->setItem(nIndex, 2, new QStandardItem(correlate)); + m_tableModel->setItem(nIndex, 3, new QStandardItem(detecttime)); + m_tableModel->setItem(nIndex, 4, new QStandardItem(diameter)); + m_tableModel->setItem(nIndex, 5, new QStandardItem(hight)); + m_tableModel->setItem(nIndex, 6, new QStandardItem(QIcon(m_Pix.scaled(50, 50)), "")); + m_tableModel->setItem(nIndex, 7, new QStandardItem(QString("%1").arg(uid))); + nIndex++; + } + ui.showNum_Label_Checkdata->setText(tr("ʾ%1¼").arg(nIndex)); + ui.tableView_checkShengchang->setModel(m_tableModel); + ui.tableView_checkShengchang->hideColumn(7); + ui.tableView_checkShengchang->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); + connect(ui.tableView_checkShengchang, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(onTableViewClick(QModelIndex))); + delete testmodel; + testmodel = NULL; +} + +Q_SLOT void lpReport::onUpdateTableViewShowlog(QSqlQuery sql) +{ + updateModelShowLog(sql); +} + +Q_SLOT void lpReport::onResultCountlog(int nCount) +{ + m_totlaNumlog = nCount; + emit(sgFinish()); +} + +Q_SLOT void lpReport::onResultCount(int nCount) +{ + m_totlaNum = nCount; + emit(sgFinish()); +} + +void lpReport::CheckDataWarningByDate(int nType, QString m_strLast, QString m_endLast) +{ + QString strString = getLogCheckString(1); + m_PrevNumlog = 0; + m_totlaNumlog = 0; + CheckThread *workThread = new CheckThread(this); + workThread->setCheckStr(m_pDb, strString); + workThread->setModelFlags(true); + connect(workThread, SIGNAL(resultCount(int)), this, SLOT(onResultCountlog(int))); + connect(workThread, &CheckThread::finished, workThread, &QObject::deleteLater); + workThread->start(); + onEventLoop(tr("ڲѯ¼Ե")); + + strString = getLogCheckString(); + int nlimit = ui.LineNumber_log->text().toInt(); + if (nlimit <= 0) + { + nlimit = 10; + ui.LineNumber_log->setText("10"); + } + strString += QString(" LIMIT %1 OFFSET %2 ").arg(nlimit).arg(m_PrevNumlog); + CheckThread *workerThread = new CheckThread(this); + workerThread->setCheckStr(m_pDb, strString); + connect(workerThread, SIGNAL(resultReady(QSqlQuery)), this, SLOT(onUpdateTableViewShowlog(QSqlQuery))); + connect(workerThread, &CheckThread::finished, workerThread, &QObject::deleteLater); + workerThread->start(); + + QString m_Title = tr("%1 %2 ļ¼ %3").arg(m_strLast).arg(m_endLast).arg(m_totlaNumlog); + QFont font; + font.setPixelSize(14); + font.setBold(true); + ui.label_Tab3_Title->setFont(font); + ui.label_Tab3_Title->setText(m_Title); + + ui.Next_checklog->setDisabled(false); + m_totalPagelog = (m_totlaNumlog / nlimit); + if (m_totlaNumlog > 0) + { + m_totalPagelog = m_totalPagelog + 1; + m_pagelog = 1; + } + else + { + m_totlaNumlog = 0; + m_pagelog = 0; + } + ui.showPage_Label_Checkdata_2->setText(tr("%1ҳ %2ҳ").arg(m_pagelog).arg(m_totalPagelog)); +} + +void lpReport::updateModelShowLog(QSqlQuery &sql) +{ + QStandardItemModel *testmodel = new QStandardItemModel; + ui.tableView_TWarning->setModel(testmodel);//ȽģͲһʾ ʾ + ui.tableView_TWarning->setEditTriggers(QAbstractItemView::NoEditTriggers); + ui.tableView_TWarning->setSelectionBehavior(QAbstractItemView::SelectRows); + ui.tableView_TWarning->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);//Ӧп + if (m_tableWarnModel == NULL) + m_tableWarnModel = new QStandardItemModel; + m_tableWarnModel->clear(); + m_tableWarnModel->setHorizontalHeaderItem(0, new QStandardItem(tr("ʱ"))); + m_tableWarnModel->setHorizontalHeaderItem(1, new QStandardItem(tr("Ϣ"))); + + int nIndex = 0; + while (sql.next()) + { + /*ͳƲѯͨӦIJƷ*/ + QString time = sql.value("time").toString(); + QString message = sql.value("message").toString(); + QString classd = sql.value("class").toString(); + m_tableWarnModel->setItem(nIndex, 0, new QStandardItem(time)); + m_tableWarnModel->setItem(nIndex, 1, new QStandardItem(message)); + nIndex++; + } + ui.showNum_Label_Checkdata_2->setText(tr("ʾ%1¼").arg(nIndex)); + ui.tableView_TWarning->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); + ui.tableView_TWarning->setModel(m_tableWarnModel); + delete testmodel; + testmodel = NULL; +} + +Q_SLOT void lpReport::SlotCombox(int index) +{ + QObject *strobj = sender(); + QString objname = strobj->objectName(); + if ("comboBox_Banci_Calculate" == objname) + { + QString str = ui.comboBox_Banci_Calculate->currentText(); + + if (m_Totaltime.contains(str)) + { + if (m_Totaltime.value(str).m_startTime >= m_Totaltime.value(str).m_endTime) + { + QDate m = m_endDate_Count.date(); + m = m.addDays(-1); + QString strdata = m.toString("yyyy-MM-dd"); + m_startDate_Count.setDate(m); + } + else + { + m_startDate_Count.setDate(m_endDate_Count.date()); + } + if (m_startDate_Count.date() > m_endDate_Count.date()) + m_startDate_Count.setDate(m_endDate_Count.date()); + + m_startDate_Count.setTime(m_Totaltime.value(str).m_startTime);// + m_endDate_Count.setTime(m_Totaltime.value(str).m_endTime);// + } + else + { + if (str == tr("ȫ")) + { + QString strTime = nstartTime.toString("hh:mm:ss"); + if (m_startDate_Count.date() > m_endDate_Count.date()) + m_startDate_Count.setDate(m_endDate_Count.date()); + + m_startDate_Count.setTime(m_startTime); + m_endDate_Count.setTime(nEndTime); + QString strStart = m_startDate_Count.toString("yyyy-MM-dd hh:mm:ss"); + } + } + ui.label_Time1_Count->setText(m_startDate_Count.toString("yyyy-MM-dd hh:mm:ss")); + ui.label_Time2_Count->setText(m_endDate_Count.toString("yyyy-MM-dd hh:mm:ss")); + } + else if ("comboBox_Banci" == objname) + { + QString str = ui.comboBox_Banci->currentText(); + + if (m_Totaltime.contains(str)) + { + if (m_Totaltime.value(str).m_startTime >= m_Totaltime.value(str).m_endTime) + { + QDate m = m_endDate_History.date(); + m = m.addDays(-1); + QString strdata = m.toString("yyyy-MM-dd"); + m_startDate_History.setDate(m); + } + else + { + m_startDate_History.setDate(m_endDate_History.date()); + } + if (m_startDate_History.date() > m_endDate_History.date()) + m_startDate_History.setDate(m_endDate_History.date()); + m_startDate_History.setTime(m_Totaltime.value(str).m_startTime);// + m_endDate_History.setTime(m_Totaltime.value(str).m_endTime);// + } + else + { + if (str == tr("ȫ")) + { + QString strTime = nstartTime.toString("hh:mm:ss"); + if (m_startDate_History.date() > m_endDate_History.date()) + m_startDate_History.setDate(m_endDate_History.date()); + m_startDate_History.setTime(m_startTime); + m_endDate_History.setTime(nEndTime); + QString strStart = m_startDate_History.toString("yyyy-MM-dd hh:mm:ss"); + } + } + ui.label_Time1_History->setText(m_startDate_History.toString("yyyy-MM-dd hh:mm:ss")); + ui.label_Time2_History->setText(m_endDate_History.toString("yyyy-MM-dd hh:mm:ss")); + } +} + +Q_SLOT void lpReport::onSlowPixmap(QSqlQuery sql) +{ + static bool nFlag = false; + if (nFlag == true) + return; + nFlag = true; + + sql.next(); + double dHight = sql.value("hight").toDouble(); + QByteArray pic = sql.value("pic").toByteArray(); + QImage img = QImage::fromData(pic); + QSize s = img.size(); + QPixmap m_Pix = QPixmap::fromImage(img); + + { + int dhight = m_Pix.height(); + int dwidth = m_Pix.width(); + double nRate = m_Pix.width()*1.0 / m_Pix.height(); + int scarew = 150; + int scareh = 150 * 1.0 / nRate; + + if (scareh > 150) + { + scarew = 150; + scareh = 150 * 1.0 / nRate; + } + ui.CheckDlg_label_Pic->setPixmap(m_Pix.scaled(scarew, scareh)); + } + nFlag = false; +} + +Q_SLOT void lpReport::onTableViewClick(QModelIndex mIndex) +{ + QString strObj = sender()->objectName(); + if ("tableView_checkShengchang" == strObj) { + if (m_tableModel) + { + QModelIndex ItemIndex = m_tableModel->index(mIndex.row(), 7); + QString strdata = ItemIndex.data().toString(); + if (m_pDb) + { + QVariantMap m_value; + m_value.insert(_CHECK_UID_, strdata); + m_value.insert(_CHECK_TYPE_, EMT_CHECK_BY_UID); + QString seletcStr = m_pDb->genCheckStr(m_value); + + /*̲߳ѯ ٽ濨*/ + CheckThread *workerThread = new CheckThread(this); + workerThread->setCheckStr(m_pDb, seletcStr); + connect(workerThread, SIGNAL(resultReady(QSqlQuery)), this, SLOT(onSlowPixmap(QSqlQuery))); + connect(workerThread, &CheckThread::finished, workerThread, &QObject::deleteLater); + workerThread->start(); + } + } + } +} +//ʼUI +void lpReport::InitUIParam() +{ + m_startDate_History = QDateTime::currentDateTime(); + m_endDate_History = QDateTime::currentDateTime(); + QString strstartDate = m_startDate_History.toString("yyyy-MM-dd hh:mm:ss"); + ui.label_Time1_History->setText(m_startDate_History.toString("yyyy-MM-dd hh:mm:ss")); + ui.label_Time2_History->setText(m_endDate_History.toString("yyyy-MM-dd hh:mm:ss")); + ui.label_Time1_Count->setText(m_startDate_Count.toString("yyyy-MM-dd hh:mm:ss")); + ui.label_Time2_Count->setText(m_endDate_Count.toString("yyyy-MM-dd hh:mm:ss")); + + m_startDate_Count = QDateTime::currentDateTime(); + m_endDate_Count = QDateTime::currentDateTime(); + m_endDate_Warning = m_startDate_Warning = QDateTime::currentDateTime(); + m_startDate_Warning.setTime(nstartTime); + ui.label_Time1_warning->setText(m_startDate_Warning.toString("yyyy-MM-dd hh:mm:ss")); + ui.label_Time2_warning->setText(m_endDate_Warning.toString("yyyy-MM-dd hh:mm:ss")); + + ui.comboBox_Banci->clear(); + ui.comboBox_Banci->addItem(tr("ȫ")); + ui.comboBox_Banci->addItems(m_Totaltime.keys()); + ui.comboBox_Banci_Calculate->clear(); + ui.comboBox_Banci_Calculate->addItem(tr("ȫ")); + ui.comboBox_Banci_Calculate->addItems(m_Totaltime.keys()); + + ui.comboBox_Wandring_Log->clear(); + ui.comboBox_Wandring_Log->addItem(tr("¼ѯ")); + ui.comboBox_Wandring_Log->addItem(tr("״̬ѯ")); + ui.comboBox_Wandring_Log->addItem(tr("ʹü¼ѯ")); + + ui.label_Title->setText(tr("ݲѯ")); + ui.stackedWidget->setCurrentIndex(0); + + if (m_tableModel) + { + m_tableModel->clear(); + } + if (m_tableWarnModel) + m_tableWarnModel->clear(); + + ui.label_Number->setText("0"); + ui.CheckDlg_label_Pic->clear(); + + if (reportdlg) + reportdlg->ClearData(); +} + +void lpReport::SetModelNames(QStringList models) +{ + ui.comboBox_Model->clear(); + ui.comboBox_Model->addItem(tr("ȫ")); + if (!models.contains("NG")) + ui.comboBox_Model->addItem(tr("NG")); + ui.comboBox_Model->addItems(models); + if (_pCompleter) + delete _pCompleter; + _pCompleter = new QCompleter(models); + _pCompleter->setCaseSensitivity(Qt::CaseInsensitive); + ui.comboBox_Model->setCompleter(_pCompleter); +} \ No newline at end of file diff --git a/tpvs17/lpReport/lpReport.h b/tpvs17/lpReport/lpReport.h new file mode 100644 index 0000000..5872a2d --- /dev/null +++ b/tpvs17/lpReport/lpReport.h @@ -0,0 +1,130 @@ +/*! + *FileName: lpReport.h + *Author: Pan Yingdong + *Email: bob.pan@hzleaper.com + *Created:2021/4/6 11:54 + *Note:ݲѯ ģ +*/ +#ifndef _H_LPREPORT_H_ +#define _H_LPREPORT_H_ + +#include +#include "ui_lpReport.h" +#include +#include "InfoFile.h" +#include +#include "QThread" +#include "workfordb.h" +#include "countdata.h" +#include "waitingdialog.h" +#include "checkdata.h" +#include +#include "DetectDataDB.h" + +class lpReport : public QMainWindow +{ + Q_OBJECT + +public: + lpReport(QWidget *parent = Q_NULLPTR); + ~lpReport(); + + void onInitUI(); + +protected: + virtual void timerEvent(QTimerEvent *event); + Q_SLOT void SlotEditTime(); + Q_SLOT void onCheckButton(); + bool onMessageBox(QMessageBox::Icon ntype, QString strTitle, QString strAtl, int onlyOK = 0); + void CheckDataHistoryByDate(QString m_strLast, QString m_endLast, QString modelname); + bool SaveDataToCSV(QString filePath, QMap &m_mapTable); + void CheckDataByDate(QString m_strLast, QString m_endLast); + void onEventLoop(QString strMsg); + void SaveLog(QString str); + QString getHistoryCheckString(); + Q_SLOT void onHistoryButton(); + void cleanHistorycal(); + Q_SLOT void onSetCurrentIndex(int nIndex); + Q_SLOT void onSaveCSVDone(int); + Q_SLOT void handleResults(QString str); + Q_SLOT void onShowMessage(QString str); + Q_SLOT void onProgressForTsk(QVariantMap m_map); + Q_SLOT void handleResultsHistory(QVariantMap Mapstr, QSqlQuery sql); + Q_SLOT void onShowMsg(); + Q_SLOT void handleResultsCount(const QString &result, const QMap *p); + Q_SLOT void onLogButton(); + QString getLogCheckString(int nCheckCount = 0); + + Q_SLOT void onUpdateTableViewShow(QSqlQuery sql); + void updateModelShowHistory(QSqlQuery &sql); + Q_SLOT void onUpdateTableViewShowlog(QSqlQuery sql); + Q_SLOT void onResultCountlog(int nCount); + Q_SLOT void onResultCount(int nCount); + void CheckDataWarningByDate(int nType, QString m_strLast, QString m_endLast); + void updateModelShowLog(QSqlQuery &sql); + Q_SLOT void SlotCombox(int index); + Q_SLOT void onSlowPixmap(QSqlQuery sql); + Q_SLOT void onTableViewClick(QModelIndex mIndex); + void InitUIParam(); + void SetModelNames(QStringList models); +signals: + void sgSetCurrentIndex(int); + void sgFinish(); + void operate(const QString& strTime, const int &ncount); + void operateCount(QVariantMap m_Map); + void operateHistory(QVariantMap m_map); + void sgshowMsg(); +private: + Ui::lpReportClass ui; + class QReportWidget *reportdlg{ nullptr }; + class QGridLayout *m_GridLayout{ nullptr }; + class QVBoxLayout *Hbox{ nullptr }; + class QWidget *m_countwidget{ nullptr }; +protected: + QDateTime m_startDate_Count, m_endDate_Count; + QDateTime m_startDate_History, m_endDate_History; + QDateTime m_startDate_Warning, m_endDate_Warning; + QTime m_startTime, m_endTime; + bool m_CheckFlags{ false }; + QTime nstartTime; + QTime nEndTime; + QString m_userName; + + QMap m_tableView; + QMap m_standItemModel; + QMap m_Totaltime;//ʱ + QMap m_CountNumber; + QMap> m_channels; + + int m_PrevNum{ 0 }; + int m_NextNum{ 0 }; + int m_totlaNum{ 0 }; + int m_page{ 0 }, m_totalPage{ 0 }; + + int m_PrevNumlog{ 0 }; + int m_NextNumlog{ 0 }; + int m_totlaNumlog{ 0 }; + int m_pagelog{ 0 }, m_totalPagelog{ 0 }; + + QThread m_Workthread; + WorkForDB *m_WorkDB{ nullptr }; + + QThread m_WorkThreadCount; + CountData *m_WorkCount{ nullptr }; + + QThread m_WorkThreadCheckHistory; + CheckData *m_WorkHistory{ nullptr }; + + WaitingDialog m_Progressdlg; + + bool m_IsRunCountTsk{ false }; + QCompleter *_pCompleter{ nullptr }; + + QStandardItemModel *m_tableModel{ nullptr }; + QStandardItemModel *m_tableWarnModel{ nullptr }; + + class DetectDataDB *m_pDb{ nullptr }; + class ModelDB *m_pModeDB{ nullptr }; +}; + +#endif diff --git a/tpvs17/lpReport/lpReport.qrc b/tpvs17/lpReport/lpReport.qrc new file mode 100644 index 0000000..717d2d5 --- /dev/null +++ b/tpvs17/lpReport/lpReport.qrc @@ -0,0 +1,6 @@ + + + Resources/Log.png + Resources/log.ico + + diff --git a/tpvs17/lpReport/lpReport.rc b/tpvs17/lpReport/lpReport.rc new file mode 100644 index 0000000..5282966 Binary files /dev/null and b/tpvs17/lpReport/lpReport.rc differ diff --git a/tpvs17/lpReport/lpReport.ui b/tpvs17/lpReport/lpReport.ui new file mode 100644 index 0000000..6c7438c --- /dev/null +++ b/tpvs17/lpReport/lpReport.ui @@ -0,0 +1,1918 @@ + + + lpReportClass + + + + 0 + 0 + 1009 + 766 + + + + lpReport + + + + + + + + 0 + 0 + + + + + 0 + 30 + + + + + + + + + 0 + 0 + 0 + + + + + + + 170 + 170 + 127 + + + + + + + 170 + 170 + 127 + + + + + + + 170 + 170 + 127 + + + + + + + + + 0 + 0 + 0 + + + + + + + 170 + 170 + 127 + + + + + + + 170 + 170 + 127 + + + + + + + 170 + 170 + 127 + + + + + + + + + 120 + 120 + 120 + + + + + + + 170 + 170 + 127 + + + + + + + 170 + 170 + 127 + + + + + + + 170 + 170 + 127 + + + + + + + + font: 75 14pt "Consolas"; +background-color: rgb(170, 170, 127); + + + 生产数据查询 + + + Qt::AlignCenter + + + + + + + + 0 + 0 + + + + + 140 + 16777215 + + + + Qt::NoFocus + + + true + + + font: 75 14pt "Consolas"; + + + + Qt::ImhNone + + + QFrame::NoFrame + + + QFrame::Plain + + + QListView::TopToBottom + + + QListView::Adjust + + + QListView::SinglePass + + + 1 + + + QListView::ListMode + + + + 生产数据查询 + + + + 12 + 75 + false + true + PreferAntialias + true + + + + AlignCenter + + + + + 182 + 182 + 182 + + + + + + + 0 + 0 + 0 + + + + + + + 生产数据统计 + + + + 12 + 75 + true + + + + AlignCenter + + + + + 182 + 182 + 182 + + + + + + + 日志记录 + + + + 12 + 75 + true + + + + AlignCenter + + + + + 182 + 182 + 182 + + + + + + + + + + + 0 + 0 + + + + 0 + + + + + + + + + + 12 + + + + 显示数据数(条) + + + + + + + + 0 + 0 + + + + + 0 + 20 + + + + + 100 + 50 + + + + + 12 + + + + 50 + + + 4 + + + Qt::AlignCenter + + + + + + + + 12 + + + + 上一页 + + + + + + + + 12 + + + + TextLabel + + + + + + + + 12 + + + + 下一页 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 12 + + + + TextLabel + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + 12 + + + + + + + + + 0 + 0 + + + + + 0 + 0 + + + + + 150 + 150 + + + + QFrame::Box + + + QFrame::Plain + + + 0 + + + + + + + + + + + 0 + 30 + + + + + 11 + + + + QFrame::Box + + + 标题 + + + + + + + + 10 + + + + 双击单条记录显示图片 + + + + + + + + + + + font: 75 12pt "Consolas"; +background-color: rgb(170, 170, 127); + + + 开始日期时间: + + + Qt::AlignCenter + + + + + + + + 0 + 30 + + + + font: 75 12pt "Consolas"; +background-color: rgb(255, 255, 255); + + + 2017-11-11 11:11:11 + + + Qt::AlignCenter + + + + + + + + 0 + 0 + + + + + 0 + 30 + + + + background-color: rgb(85, 255, 0); +font: 75 12pt "Consolas"; + + + 设置开始时间 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + font: 75 12pt "Consolas"; +background-color: rgb(170, 170, 127); + + + 结束日期时间: + + + Qt::AlignCenter + + + + + + + + 0 + 30 + + + + font: 75 12pt "Consolas"; +background-color: rgb(255, 255, 255); + + + 2017-11-11 11:11:11 + + + Qt::AlignCenter + + + + + + + + 0 + 0 + + + + + 0 + 30 + + + + background-color: rgb(85, 255, 0); +font: 75 12pt "Consolas"; + + + 设置结束时间 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + 0 + 25 + + + + + + + + + 0 + 0 + 0 + + + + + + + 170 + 170 + 127 + + + + + + + 170 + 170 + 127 + + + + + + + 170 + 170 + 127 + + + + + + + + + 0 + 0 + 0 + + + + + + + 170 + 170 + 127 + + + + + + + 170 + 170 + 127 + + + + + + + 170 + 170 + 127 + + + + + + + + + 120 + 120 + 120 + + + + + + + 170 + 170 + 127 + + + + + + + 170 + 170 + 127 + + + + + + + 170 + 170 + 127 + + + + + + + + background-color: rgb(170, 170, 127); +font: 75 14pt "Consolas"; + + + 筛选型号 + + + Qt::AlignCenter + + + + + + + + 0 + 30 + + + + font: 75 12pt "Consolas"; + + + + + 所有 + + + + + + + + + 0 + 30 + + + + + + + + + 0 + 0 + 0 + + + + + + + 170 + 170 + 127 + + + + + + + 170 + 170 + 127 + + + + + + + 170 + 170 + 127 + + + + + + + + + 0 + 0 + 0 + + + + + + + 170 + 170 + 127 + + + + + + + 170 + 170 + 127 + + + + + + + 170 + 170 + 127 + + + + + + + + + 120 + 120 + 120 + + + + + + + 170 + 170 + 127 + + + + + + + 170 + 170 + 127 + + + + + + + 170 + 170 + 127 + + + + + + + + background-color: rgb(170, 170, 127); +font: 75 14pt "Consolas"; + + + 生产班次 + + + Qt::AlignCenter + + + + + + + + 0 + 30 + + + + font: 75 12pt "Consolas"; + + + + 全天 + + + + + + + + + 0 + 30 + + + + + + + + + 0 + 0 + 0 + + + + + + + 170 + 170 + 127 + + + + + + + 170 + 170 + 127 + + + + + + + 170 + 170 + 127 + + + + + + + + + 0 + 0 + 0 + + + + + + + 170 + 170 + 127 + + + + + + + 170 + 170 + 127 + + + + + + + 170 + 170 + 127 + + + + + + + + + 120 + 120 + 120 + + + + + + + 170 + 170 + 127 + + + + + + + 170 + 170 + 127 + + + + + + + 170 + 170 + 127 + + + + + + + + background-color: rgb(170, 170, 127); +font: 75 14pt "Consolas"; + + + 查询数量 + + + Qt::AlignCenter + + + + + + + font: 75 12pt "Consolas"; +background-color: rgb(170, 170, 127); + + + 0 + + + Qt::AlignCenter + + + + + + + + 0 + 30 + + + + background-color: rgb(85, 255, 0); +font: 75 12pt "Consolas"; + + + 查询 + + + + + + + + 0 + 30 + + + + background-color: rgb(85, 255, 0); +font: 75 12pt "Consolas"; + + + 导出CSV + + + + + + + + + + + + + + + + + + + font: 75 12pt "Consolas"; +background-color: rgb(170, 170, 127); + + + 结束日期时间: + + + Qt::AlignCenter + + + + + + + + 0 + 30 + + + + font: 75 12pt "Consolas"; +background-color: rgb(255, 255, 255); + + + 2017-11-11 11:11:11 + + + Qt::AlignCenter + + + + + + + + 0 + 0 + + + + + 0 + 30 + + + + background-color: rgb(85, 255, 0); +font: 75 12pt "Consolas"; + + + 设置结束时间 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + font: 75 12pt "Consolas"; +background-color: rgb(170, 170, 127); + + + 开始日期时间: + + + Qt::AlignCenter + + + + + + + + 0 + 30 + + + + font: 75 12pt "Consolas"; +background-color: rgb(255, 255, 255); + + + 2017-11-11 11:11:11 + + + Qt::AlignCenter + + + + + + + + 0 + 0 + + + + + 0 + 30 + + + + background-color: rgb(85, 255, 0); +font: 75 12pt "Consolas"; + + + 设置开始时间 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + true + + + + + 0 + 0 + 661 + 531 + + + + + + + + + + + + 0 + 30 + + + + + + + + + 0 + 0 + 0 + + + + + + + 170 + 170 + 127 + + + + + + + 170 + 170 + 127 + + + + + + + 170 + 170 + 127 + + + + + + + + + 0 + 0 + 0 + + + + + + + 170 + 170 + 127 + + + + + + + 170 + 170 + 127 + + + + + + + 170 + 170 + 127 + + + + + + + + + 120 + 120 + 120 + + + + + + + 170 + 170 + 127 + + + + + + + 170 + 170 + 127 + + + + + + + 170 + 170 + 127 + + + + + + + + background-color: rgb(170, 170, 127); +font: 75 14pt "Consolas"; + + + 生产班次 + + + Qt::AlignCenter + + + + + + + + 0 + 30 + + + + font: 75 12pt "Consolas"; + + + + 所有 + + + + + + + + + + + 0 + 30 + + + + background-color: rgb(85, 255, 0); +font: 75 12pt "Consolas"; + + + 导出CSV + + + + + + + + 0 + 30 + + + + background-color: rgb(85, 255, 0); +font: 75 12pt "Consolas"; + + + 查询 + + + + + + + + + + + + + + + + + font: 75 12pt "Consolas"; +background-color: rgb(170, 170, 127); + + + 结束日期时间: + + + Qt::AlignCenter + + + + + + + + 0 + 30 + + + + font: 75 12pt "Consolas"; +background-color: rgb(255, 255, 255); + + + 2017-11-11 11:11:11 + + + Qt::AlignCenter + + + + + + + + 0 + 0 + + + + + 0 + 30 + + + + background-color: rgb(85, 255, 0); +font: 75 12pt "Consolas"; + + + 设置结束时间 + + + + + + + + 0 + 0 + + + + + 100 + 30 + + + + + 12 + + + + + 数据类型查询 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + + 0 + 30 + + + + + 16777215 + 50 + + + + background-color: rgb(85, 255, 0); +font: 75 12pt "Consolas"; + + + 查询 + + + + + + + + 0 + 30 + + + + background-color: rgb(85, 255, 0); +font: 75 12pt "Consolas"; + + + 导出CSV + + + + + + + + + + + font: 75 12pt "Consolas"; +background-color: rgb(170, 170, 127); + + + 起始日期时间: + + + Qt::AlignCenter + + + + + + + + 0 + 30 + + + + font: 75 12pt "Consolas"; +background-color: rgb(255, 255, 255); + + + 2017-11-11 11:11:11 + + + Qt::AlignCenter + + + + + + + + 0 + 0 + + + + + 0 + 30 + + + + background-color: rgb(85, 255, 0); +font: 75 12pt "Consolas"; + + + 设置起始时间 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + 11 + + + + 报警记录查询 + + + + + + + + 12 + + + + + + + + + + + 12 + + + + 显示数据数(条) + + + + + + + + 0 + 0 + + + + + 0 + 20 + + + + + 100 + 50 + + + + + 12 + + + + 50 + + + 4 + + + Qt::AlignCenter + + + + + + + + 12 + + + + 上一页 + + + + + + + + 12 + + + + TextLabel + + + + + + + + 12 + + + + 下一页 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 12 + + + + TextLabel + + + + + + + + + + + + + + + 0 + 0 + 1009 + 23 + + + + + + + + + + + diff --git a/tpvs17/lpReport/lpReport.vcxproj b/tpvs17/lpReport/lpReport.vcxproj new file mode 100644 index 0000000..70f51d3 --- /dev/null +++ b/tpvs17/lpReport/lpReport.vcxproj @@ -0,0 +1,232 @@ + + + + + Debug + x64 + + + Release + x64 + + + + {0E042214-1B06-40D6-9D20-C6D5FA3D7A51} + Qt4VSv1.0 + 10.0.17763.0 + + + + Application + v141 + + + Application + v141 + + + + $(MSBuildProjectDirectory)\QtMsBuild + + + $(SolutionDir)$(Platform)\$(Configuration)\ + + + $(SolutionDir)$(Platform)\$(Configuration)\ + + + + + + + + + + + + + + + + + + + true + UNICODE;_UNICODE;WIN32;WIN64;QT_DLL;QT_CORE_LIB;QT_GUI_LIB;QT_WIDGETS_LIB;QT_SQL_LIB;%(PreprocessorDefinitions) + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSql;%(AdditionalIncludeDirectories) + Disabled + ProgramDatabase + MultiThreadedDebugDLL + true + + + Windows + $(SolutionDir)..\runner17\$(ProjectName).exe + $(QTDIR)\lib;%(AdditionalLibraryDirectories) + true + qtmaind.lib;Qt5Cored.lib;Qt5Guid.lib;Qt5Widgetsd.lib;Qt5Sqld.lib;%(AdditionalDependencies) + + + .\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp + Moc'ing %(Identity)... + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSql;%(AdditionalIncludeDirectories) + UNICODE;_UNICODE;WIN32;WIN64;QT_DLL;QT_CORE_LIB;QT_GUI_LIB;QT_WIDGETS_LIB;QT_SQL_LIB;%(PreprocessorDefinitions) + + + Uic'ing %(Identity)... + .\GeneratedFiles\ui_%(Filename).h + + + Rcc'ing %(Identity)... + .\GeneratedFiles\qrc_%(Filename).cpp + + + + + true + UNICODE;_UNICODE;WIN32;WIN64;QT_DLL;QT_NO_DEBUG;NDEBUG;QT_CORE_LIB;QT_GUI_LIB;QT_WIDGETS_LIB;QT_SQL_LIB;%(PreprocessorDefinitions) + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSql;%(AdditionalIncludeDirectories) + + MultiThreadedDLL + true + + + Windows + $(OutDir)\$(ProjectName).exe + $(QTDIR)\lib;%(AdditionalLibraryDirectories) + false + qtmain.lib;Qt5Core.lib;Qt5Gui.lib;Qt5Widgets.lib;Qt5Sql.lib;%(AdditionalDependencies) + + + .\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp + Moc'ing %(Identity)... + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSql;%(AdditionalIncludeDirectories) + UNICODE;_UNICODE;WIN32;WIN64;QT_DLL;QT_NO_DEBUG;NDEBUG;QT_CORE_LIB;QT_GUI_LIB;QT_WIDGETS_LIB;QT_SQL_LIB;%(PreprocessorDefinitions) + + + Uic'ing %(Identity)... + .\GeneratedFiles\ui_%(Filename).h + + + Rcc'ing %(Identity)... + .\GeneratedFiles\qrc_%(Filename).cpp + + + + + + + + + + + + + + + + + + + + + + + + + + + + + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets + + + + + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets + + + + + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets + + + + + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets + + + + + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets + + + + + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets + + + + + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets + + + + + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets + + + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets + + + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets + + + + + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSql + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSql + + + + + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSql + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSql + + + + + + + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSql + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSql + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tpvs17/lpReport/lpReport.vcxproj.filters b/tpvs17/lpReport/lpReport.vcxproj.filters new file mode 100644 index 0000000..bac7b7f --- /dev/null +++ b/tpvs17/lpReport/lpReport.vcxproj.filters @@ -0,0 +1,141 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {D9D6E242-F8AF-46E4-B9FD-80ECBC20BA3E} + qrc;* + false + + + {99349809-55BA-4b9d-BF79-8FDBB0286EB3} + ui + + + {D9D6E242-F8AF-46E4-B9FD-80ECBC20BA3E} + qrc;* + false + + + {71ED8ED8-ACB9-4CE9-BBE1-E00B30144E11} + moc;h;cpp + False + + + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + + + Form Files + + + Form Files + + + Form Files + + + + + Resource Files + + + + + Header Files + + + Header Files + + + + + + + + + \ No newline at end of file diff --git a/tpvs17/lpReport/lpReport.vcxproj.user b/tpvs17/lpReport/lpReport.vcxproj.user new file mode 100644 index 0000000..123c113 --- /dev/null +++ b/tpvs17/lpReport/lpReport.vcxproj.user @@ -0,0 +1,15 @@ + + + + + D:\Qt\Qt5.9.4\5.9.4\msvc2017_64 + $(SolutionDir)..\runner17\$(ProjectName).exe + $(SolutionDir)..\runner17\ + WindowsLocalDebugger + PATH=$(QTDIR)\bin%3b$(PATH) + + + D:\Qt\Qt5.9.4\5.9.4\msvc2017_64 + PATH=$(QTDIR)\bin%3b$(PATH) + + \ No newline at end of file diff --git a/tpvs17/lpReport/main.cpp b/tpvs17/lpReport/main.cpp new file mode 100644 index 0000000..0b98297 --- /dev/null +++ b/tpvs17/lpReport/main.cpp @@ -0,0 +1,10 @@ +#include "lpReport.h" +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + lpReport w; + w.show(); + return a.exec(); +} diff --git a/tpvs17/lpReport/qcheckcal.cpp b/tpvs17/lpReport/qcheckcal.cpp new file mode 100644 index 0000000..d819b20 --- /dev/null +++ b/tpvs17/lpReport/qcheckcal.cpp @@ -0,0 +1,12 @@ +#include "qcheckcal.h" + +QCheckCal::QCheckCal(QWidget *parent) + : QWidget(parent) +{ + +} + +QCheckCal::~QCheckCal() +{ + +} diff --git a/tpvs17/lpReport/qcheckcal.h b/tpvs17/lpReport/qcheckcal.h new file mode 100644 index 0000000..a657ee1 --- /dev/null +++ b/tpvs17/lpReport/qcheckcal.h @@ -0,0 +1,18 @@ +#ifndef QCHECKCAL_H +#define QCHECKCAL_H + +#include + +class QCheckCal : public QWidget +{ + Q_OBJECT + +public: + QCheckCal(QWidget *parent); + ~QCheckCal(); + +private: + +}; + +#endif // QCHECKCAL_H diff --git a/tpvs17/lpReport/qreportwidget.cpp b/tpvs17/lpReport/qreportwidget.cpp new file mode 100644 index 0000000..70f037b --- /dev/null +++ b/tpvs17/lpReport/qreportwidget.cpp @@ -0,0 +1,186 @@ +#include "qreportwidget.h" +#include +#include +#pragma execution_character_set("utf-8") +QReportWidget::QReportWidget(QString str /*=QString()*/, QWidget *parent/*=0*/) : QWidget(parent) +{ + m_Title = str; + m_titleLabel = new QLabel; + m_TableView = new QTableView; + m_tableViewModel = new QStandardItemModel; + + m_TableView->setAlternatingRowColors(true); + m_TableView->setSelectionBehavior(QAbstractItemView::SelectRows); + m_TableView->setEditTriggers(QAbstractItemView::NoEditTriggers); + m_TableView->setWordWrap(true); + m_TableView->resizeColumnsToContents(); + m_TableView->resizeRowsToContents(); + //m_TableView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);//自适应行宽 + m_TableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); + m_TableView->horizontalScrollBar()->setEnabled(false); + m_TableView->setMinimumHeight(100); + QVBoxLayout *VBox = new QVBoxLayout; + VBox->addWidget(m_titleLabel); + VBox->addWidget(m_TableView); + setLayout(VBox); +} + +QReportWidget::~QReportWidget() +{ + if (m_TableView){ + delete m_TableView; + m_TableView = NULL; + } + if (m_tableViewModel){ + m_tableViewModel->clear(); + delete m_tableViewModel; + m_tableViewModel = NULL; + } +} + +void QReportWidget::UpdateTableView() +{ + m_titleLabel->setText(m_Title); + QStandardItemModel *m_tableViewModelTmp = new QStandardItemModel; + m_TableView->setModel(m_tableViewModelTmp); + QFont font; + font.setPixelSize(14); + m_titleLabel->setFont(font); + m_tableViewModel->clear(); + m_tableViewModel->setHorizontalHeaderItem(0, new QStandardItem(tr("型号"))); + m_tableViewModel->setHorizontalHeaderItem(1, new QStandardItem(tr("数量"))); + int nIndex = 0; + for (QMap::iterator its = m_str.begin(); its != m_str.end(); ++its) + { + m_tableViewModel->setItem(nIndex, 0, new QStandardItem(its.key())); + m_tableViewModel->setItem(nIndex, 1, new QStandardItem(QString::number(*its))); + nIndex++; + } + if (m_listStr.size() > 0) + { + for (int m_Index = 0; m_Index < m_listStr.size(); m_Index++) + { + m_tableViewModel->setItem(nIndex, 0, new QStandardItem(m_listStr.at(m_Index).m_str)); + m_tableViewModel->setItem(nIndex, 1, new QStandardItem(QString::number(m_listStr.at(m_Index).num))); + nIndex++; + } + } + m_TableView->setModel(m_tableViewModel); + delete m_tableViewModelTmp; + m_tableViewModelTmp = NULL; +} +void QReportWidget::drawTexts(QPainter* painter) +{ + QDateTime cuttrnt_date_time = QDateTime::currentDateTime(); + QString current_date = cuttrnt_date_time.toString("yyyy-MM-dd hh:mm:ss ddd"); + + QPoint point(10, 14); + QFont font; + font.setPixelSize(14); + painter->setFont(font); + //if (!m_Title.isEmpty()) + { + // return; + } + QTextOption option(Qt::AlignLeft | Qt::AlignVCenter); + option.setWrapMode(QTextOption::WordWrap); + + painter->drawText(rect(), m_Title, option); + if (m_str.size() > 0) + { + int y = point.y(); + point.setY(y + 20); + painter->drawText(point, tr("编号")); + point.setX(10 + 2 * 28); + painter->drawText(point, tr("型号")); + point.setX(10 + 2 * 28 + 3 * 28); + painter->drawText(point, tr("数量")); + int i = 1; + point.setX(10); + font.setPixelSize(14); + painter->setFont(font); + for (QMap::iterator its = m_str.begin(); its != m_str.end(); ++its) + { + int y = point.y(); + point.setX(10); + point.setY(y + 20); + painter->drawText(point, QString::number(i++)); + point.setX(10 + 2 * 28); + painter->drawText(point, its.key()); + point.setX(10 + 2 * 28 + 3 * 28); + painter->drawText(point, QString::number(*its)); + } + if (m_listStr.size() > 0) + { + for (int nIndex = 0; nIndex < m_listStr.size(); nIndex++) + { + int y = point.y(); + point.setX(10); + point.setY(y + 20); + painter->drawText(point, QString::number(i++)); + point.setX(10 + 2 * 28); + painter->drawText(point, m_listStr.at(nIndex).m_str); + point.setX(10 + 2 * 28 + 3 * 28); + painter->drawText(point, QString::number(m_listStr.at(nIndex).num)); + } + } + } + else + { + int y = point.y(); + point.setY(y + 20); + painter->drawText(point, tr("请选择对应时间并查询数据!")); + } + //painter->drawLine(80, 100, 650, 500); + //painter->setPen(Qt::red); + //painter->drawRect(10, 10, 100, 400); + //painter->setPen(QPen(Qt::green, 5)); + //painter->setBrush(Qt::blue); + //painter->drawEllipse(50, 150, 400, 200); +} +void QReportWidget::DrawOneItem(QPainter* painter, QPoint& point, QStringList &mList) +{ + +} + +void QReportWidget::paintEvent(QPaintEvent *event) +{ + //QPainter painter_text(this); + //drawTexts(&painter_text); + //painter_text.end(); +} +void QReportWidget::AppendData(QString str, int num, bool model) +{ + if (model == 0) + { + m_listStr.clear(); + } + DataItem m_item; + m_item.m_str = str; + m_item.num = num; + m_listStr.append(m_item); + update(); +} + +void QReportWidget::setTitle(QString str) +{ + m_Title = str; +} + +void QReportWidget::ClearData() +{ + m_Title.clear(); + m_listStr.clear(); + m_str.clear(); +} + +Q_SLOT void QReportWidget::SetData(QMap &m_strMap) +{ + m_str = m_strMap; +} + + +void QReportWidget::resizeEvent(QResizeEvent *event) +{ + QWidget::resizeEvent(event); +} diff --git a/tpvs17/lpReport/qreportwidget.h b/tpvs17/lpReport/qreportwidget.h new file mode 100644 index 0000000..dac4d8a --- /dev/null +++ b/tpvs17/lpReport/qreportwidget.h @@ -0,0 +1,51 @@ +#ifndef QREPORTWIDGET_H +#define QREPORTWIDGET_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +struct DataItem +{ + QString m_str; + int num; +}; + + +class QReportWidget : public QWidget +{ + Q_OBJECT + +public: + QReportWidget(QString str =QString(), QWidget *parent=0); + ~QReportWidget(); +protected: + virtual void paintEvent(QPaintEvent *event); + void resizeEvent(QResizeEvent *event); +private: + void drawTexts(QPainter* painter); +private: + QMap m_str; + QString m_Title; +public: + Q_SLOT void SetData(QMap &m_strMap); + void UpdateTableView(); + void DrawOneItem(QPainter* painter, QPoint& point, QStringList &mList); + void AppendData(QString str, int num, bool model = 0); + void ClearData(); + void setTitle(QString str); + QList m_listStr; + + QLabel *m_titleLabel; + QTableView *m_TableView; + QStandardItemModel *m_tableViewModel; +}; + +#endif // QREPORTWIDGET_H diff --git a/tpvs17/lpReport/qsavecsvthread.h b/tpvs17/lpReport/qsavecsvthread.h new file mode 100644 index 0000000..8a6180f --- /dev/null +++ b/tpvs17/lpReport/qsavecsvthread.h @@ -0,0 +1,124 @@ +#ifndef QSAVECSVTHREAD_H +#define QSAVECSVTHREAD_H + +#include +#include "QFile" +#include "QTextStream" +#include "QSqlQuery" +#include "QDateTime" +#include "databasesql.h" +#pragma execution_character_set("utf-8") +class QSaveCSVThread : public QThread +{ + Q_OBJECT + +public: + QSaveCSVThread(QObject *parent){}; + ~QSaveCSVThread(){}; + void setInform(QString Title, QString username) + { + m_title = Title; + m_username = username; + } + void setCheckStr(DataBaseSql *pDb, QString m_str, QString savefilePath,int nType){ + m_pDb = pDb; + m_CheckStr = m_str; + m_saveFilename = savefilePath; + m_Type = nType; + }; + void run() Q_DECL_OVERRIDE{ + if (m_Type == 0){ + saveHistory(); + } + else if (m_Type==1) + { + saveLog(); + } + + emit(resultReady(m_Type)); + }; +private: + void saveLog() + { + QSqlQuery sql; + if (m_pDb){ + m_pDb->checkoutData(m_CheckStr, sql); + QFile file(m_saveFilename); + if (!file.open(QIODevice::WriteOnly | QIODevice::Text/* | QIODevice::Append*/))// 追加写入数据 + return; + QTextStream out(&file); + QString tableData; + int nIndex = 0; + out << m_title << "\n"; + out << QString("序号") << "," << QString("时间") << "," << QString("信息") << "\n"; + while (sql.next()) + { + nIndex = nIndex + 1; + out << nIndex << ","; + QString time = sql.value("time").toString(); + QString message = sql.value("message").toString(); + QString classd = sql.value("class").toString(); + out << time << "," << message << ","; + out << "\n"; + } + + out << QString("总数") << "," << QString::number(nIndex) << "\n"; + out << QString("保存时间:") << "," << QDateTime::currentDateTime().toString("yyyy-MM-dd") << "," << QDateTime::currentDateTime().toString("hh:mm:ss") << "\n"; + out << QString("用户:") << "," << m_username << "," << "\n"; + file.close(); + } + }; + void saveHistory() + { + QSqlQuery sql; + if (m_pDb){ + m_pDb->checkoutData(m_CheckStr, sql); + + QFile file(m_saveFilename); + if (!file.open(QIODevice::WriteOnly | QIODevice::Text/* | QIODevice::Append*/))// 追加写入数据 + return ; + QTextStream out(&file); + QString tableData; + + out << m_title << "\n"; + + out << QString("序号") << "," << QString("时间") << "," << QString("匹配型号") << "," << QString("相似度") << "," << QString("消耗时间") << "," << QString("直径") << "," << QString("厚度") << "\n"; + int nIndex = 0; + while (sql.next()) + { + QString time = sql.value("time").toString(); + QString model = sql.value("model").toString(); + double dCorrelate = sql.value("correlate").toDouble(); + QString correlate; + if (dCorrelate >= 1.7976931348623158e+308) + dCorrelate = 0; + correlate = QString::number(dCorrelate * 100, 'f', 3) + "%"; + double dDetecttime = sql.value("detecttime").toDouble(); + QString detecttime = QString::number(dDetecttime, 'f', 3); + double dDiameter = sql.value("diameter").toDouble(); + QString diameter = QString::number(dDiameter, 'f', 3); + double dHight = sql.value("hight").toDouble(); + QString hight = QString::number(dHight, 'f', 3); + + nIndex = nIndex + 1; + out << nIndex << ","; + out << time << "," << model << "," << correlate << "," << detecttime << "," << diameter << "," << hight << "\n"; + } + out << QString("总数") << "," << QString::number(nIndex) << "\n"; + out << QString("时间:") << "," << QDateTime::currentDateTime().toString("yyyy-MM-dd") << "," << QDateTime::currentDateTime().toString("hh:mm:ss") << "\n"; + out << QString("用户:") << "," << m_username << "," << "\n"; + file.close(); + } + }; +private: + int m_Type; + DataBaseSql *m_pDb; + QString m_CheckStr; + QString m_saveFilename; + QString m_title; + QString m_username; +signals: + void resultReady(int nType); +}; + +#endif // QSAVECSVTHREAD_H diff --git a/tpvs17/lpReport/qtimedlg.cpp b/tpvs17/lpReport/qtimedlg.cpp new file mode 100644 index 0000000..804cf62 --- /dev/null +++ b/tpvs17/lpReport/qtimedlg.cpp @@ -0,0 +1,131 @@ +#include "qtimedlg.h" +#pragma execution_character_set("utf-8") +QTimeDlg::QTimeDlg(QWidget *parent) + : QDialog(parent), m_clock(NULL) +{ + ui.setupUi(this); + m_clock = new QClockDlg; + m_clock->setMinimumSize(QSize(100, 150)); + ui.gridLayout->addWidget(m_clock); + setWindowIcon(QIcon(":/image/leaper")); + setWindowFlags(Qt::WindowCloseButtonHint);//|Qt::WindowContextHelpButtonHint | Qt::WindowMinimizeButtonHint | Qt::WindowMaximizeButtonHint + //connect(ui.dial_timedlg, SIGNAL(valueChanged(int)), this, SLOT(valuechange(int))); + //connect(ui.dial_2_timedlg, SIGNAL(valueChanged(int)), this, SLOT(valuechange(int))); + connect(ui.hour_comboBox, SIGNAL(currentTextChanged(QString)), this, SLOT(onCurrentStrChange(QString))); + connect(ui.minute_comboBox, SIGNAL(currentTextChanged(QString)), this, SLOT(onCurrentStrChange(QString))); + connect(ui.pushButton_timedlg, SIGNAL(clicked()), this, SLOT(SlotOk())); + connect(ui.calendarWidget_timedlg, SIGNAL(clicked(const QDate &)), this, SLOT(SlotCalWidget(const QDate &))); + connect(ui.calendarWidget_timedlg, SIGNAL(currentPageChanged(int, int)), this, SLOT(oncurrentPageChanged(int, int))); +} + +QTimeDlg::~QTimeDlg() +{ + if (m_clock) + { + delete m_clock; + m_clock = NULL; + } +} +Q_SLOT void QTimeDlg::oncurrentPageChanged(int nyear, int nMonth) +{ + m_Day = m_date.day(); + m_date.setDate(nyear, nMonth, m_Day); + QString m_str = QString("%1 %2").arg(m_date.toString("yyyy-MM-dd")).arg(m_time.toString("hh:mm")); + ui.label_timedlg->setText(m_str); +} + +Q_SLOT void QTimeDlg::onCurrentStrChange(QString str) +{ + QString strObj = sender()->objectName(); + if (strObj == "hour_comboBox"){ + int m_minute = m_time.minute(); + int m_value = str.toInt(); + m_time.setHMS(m_value, m_minute, 0); + m_clock->SetTime(m_value, m_minute); + QString m_str = QString("%1 %2").arg(m_date.toString("yyyy-MM-dd")).arg(m_time.toString("hh:mm")); + ui.label_timedlg->setText(m_str); + } + else if (strObj == "minute_comboBox"){ + int m_hour = m_time.hour(); + int m_value = str.toInt(); + m_clock->SetTime(m_hour, m_value); + m_time.setHMS(m_hour, m_value, 0); + QString m_str = QString("%1 %2").arg(m_date.toString("yyyy-MM-dd")).arg(m_time.toString("hh:mm")); + ui.label_timedlg->setText(m_str); + } + int a = 0; +} + +Q_SLOT void QTimeDlg::valuechange(int m_value) +{ + QObject *watch = sender(); + QString m_objname = watch->objectName(); + if (m_objname == "dial_timedlg") + { + int m_minute = m_time.minute(); + m_time.setHMS(m_value, m_minute, 0); + m_clock->SetTime(m_value, m_minute); + QString m_str = QString("%1 %2").arg(m_date.toString("yyyy-MM-dd")).arg(m_time.toString("hh:mm")); + ui.label_timedlg->setText(m_str); + } + else if (m_objname == "dial_2_timedlg") + { + int m_hour = m_time.hour(); + m_clock->SetTime(m_hour, m_value); + m_time.setHMS(m_hour, m_value, 0); + QString m_str = QString("%1 %2").arg(m_date.toString("yyyy-MM-dd")).arg(m_time.toString("hh:mm")); + ui.label_timedlg->setText(m_str); + } +} + +Q_SLOT void QTimeDlg::SlotOk() +{ + emit(QDialog::accept()); +} + +void QTimeDlg::SetDateTime(QDateTime m_datetime) +{ + this->m_time = m_datetime.time(); + this->m_date = m_datetime.date(); + m_clock->InitTime(m_time.hour(), m_time.minute()); + ui.hour_comboBox->setCurrentText(QString::number(m_time.hour())); + ui.minute_comboBox->setCurrentText(QString::number(m_time.minute())); + //ui.dial_timedlg->setValue(m_time.hour()); + //ui.dial_2_timedlg->setValue(m_time.minute()); + ui.calendarWidget_timedlg->setSelectedDate(m_date); + + QString m_str = QString("%1 %2").arg(m_date.toString("yyyy-MM-dd")).arg(m_time.toString("hh:mm")); + ui.label_timedlg->setText(m_str); +} + +void QTimeDlg::SetDateTime(QDate m_date, QTime m_time) +{ + this->m_time = m_time; + this->m_date = m_date; + m_clock->InitTime(m_time.hour(), m_time.minute()); + ui.hour_comboBox->setCurrentText(QString::number(m_time.hour())); + ui.minute_comboBox->setCurrentText(QString::number(m_time.minute())); + //ui.dial_timedlg->setValue(m_time.hour()); + //ui.dial_2_timedlg->setValue(m_time.minute()); + ui.calendarWidget_timedlg->setSelectedDate(m_date); + QString m_str = QString("%1 %2").arg(m_date.toString("yyyy-MM-dd")).arg(m_time.toString("hh:mm")); + ui.label_timedlg->setText(m_str); +} +void QTimeDlg::GetDateTime(QDateTime &m_datetime) +{ + m_datetime.setDate(m_date); + m_datetime.setTime(m_time); +} + +void QTimeDlg::GetDateTime(QDate &m_date, QTime &m_time) +{ + m_time = this->m_time; + m_date = this->m_date; +} + +Q_SLOT void QTimeDlg::SlotCalWidget(const QDate &mdate) +{ + m_date = ui.calendarWidget_timedlg->selectedDate(); + QString m_str = QString("%1 %2").arg(m_date.toString("yyyy-MM-dd")).arg(m_time.toString("hh:mm")); + ui.label_timedlg->setText(m_str); +} diff --git a/tpvs17/lpReport/qtimedlg.h b/tpvs17/lpReport/qtimedlg.h new file mode 100644 index 0000000..e29bb6e --- /dev/null +++ b/tpvs17/lpReport/qtimedlg.h @@ -0,0 +1,477 @@ +#ifndef QTIMEDLG_H +#define QTIMEDLG_H + +#include +#include "ui_qtimedlg.h" +#include +#include +#include +#include +#include +#include +#include +#include +class Digits : public QWidget +{ + Q_OBJECT + +public: + + /*Define three transition modes of the digital clock*/ + enum { + Slide, + Flip, + Rotate + }; + + Digits(QWidget *parent) + : QWidget(parent) + , m_number(0) + , m_transition(Slide) + { + setAttribute(Qt::WA_OpaquePaintEvent, true); + //Widget paints all its pixels when it receives a paint event + + setAttribute(Qt::WA_NoSystemBackground, true); + //Indicates that the widget has no background, i.e. when the widget receives paint events, the background is not automatically repainted. + + connect(&m_animator, SIGNAL(frameChanged(int)), SLOT(update())); + //start animation + + m_animator.setFrameRange(0, 100); + m_animator.setDuration(600); + //Construct a 0.6-second timeline with a frame range of 0 - 100 + + m_animator.setCurveShape(QTimeLine::EaseInOutCurve); + //starts growing slowly, then runs steadily, then grows slowly again + } + + /*Set transition when time changed*/ + void setTransition(int tr) { + m_transition = tr; + } + + /*Get transition mode*/ + int transition() const { + return m_transition; + } + + /*Set hours and minutes*/ + void setNumber(int n) { + if (m_number != n) { + m_number = qBound(0, n, 99); + preparePixmap(); + update(); + } + } + + /*Flip to next state*/ + void flipTo(int n) { + if (m_number != n) { + m_number = qBound(0, n, 99); + m_lastPixmap = m_pixmap; + preparePixmap(); + m_animator.stop(); + m_animator.start(); + } + } + +protected: + + /*Draw the main frame of the digits area*/ + void drawFrame(QPainter *p, const QRect &rect) { + p->setPen(Qt::NoPen); + QLinearGradient gradient(rect.topLeft(), rect.bottomLeft()); + //Set linear gradient area + + gradient.setColorAt(0.00, QColor(245, 245, 245)); + gradient.setColorAt(0.49, QColor(192, 192, 192)); + gradient.setColorAt(0.51, QColor(245, 245, 245)); + gradient.setColorAt(1.00, QColor(192, 192, 192)); + //Creates stop points at the given position with the given color + + p->setBrush(gradient); + QRect r = rect; + p->drawRoundedRect(r, 15, 15, Qt::RelativeSize); + /* + Draws outer rectangle rect with rounded corners. + Qt::RelativeSize specifies the size relative to the bounding rectangle, + typically using percentage measurements. + */ + + r.adjust(1, 4, -1, -4); + //Adds 1, 4, -1 and -4 respectively to the existing coordinates of the rectangle + + p->setPen(QColor(181, 181, 181)); + p->setBrush(Qt::NoBrush); + p->drawRoundedRect(r, 15, 15, Qt::RelativeSize); + //Draws inner rectangle rect with rounded corners. + + p->setPen(QColor(159, 159, 159)); + int y = rect.top() + rect.height() / 2 - 1; + p->drawLine(rect.left(), y, rect.right(), y); + //Draws the mid-line from (rect.left(), y) to (rect.right(), y) and sets the current pen position to (rect.right(), y) + + } + + /*Draw the digits*/ + QPixmap drawDigits(int n, const QRect &rect) { + + int scaleFactor = 2; +#if defined(Q_OS_SYMBIAN) || defined(Q_OS_WINCE_WM) + if (rect.height() > 240) + scaleFactor = 1; +#endif + + QString str = QString::number(n); + if (str.length() == 1) + str.prepend("0"); + //Ensure it is double-digit + + QFont font; + font.setFamily("Helvetica"); + int fontHeight = scaleFactor * 0.55 * rect.height(); + font.setPixelSize(fontHeight); + //Sets the font size to pixelSize pixels + + font.setBold(true); + + QPixmap pixmap(rect.size() * scaleFactor); + pixmap.fill(Qt::transparent); + + QLinearGradient gradient(QPoint(0, 0), QPoint(0, pixmap.height())); + //Constructs a linear gradient with interpolation area between (0,0) and (0,pixmap.height()) + + gradient.setColorAt(0.00, QColor(128, 128, 128)); + gradient.setColorAt(0.49, QColor(64, 64, 64)); + gradient.setColorAt(0.51, QColor(128, 128, 128)); + gradient.setColorAt(1.00, QColor(16, 16, 16)); + //Creates stop points at the given position with the given color + + QPainter p; + p.begin(&pixmap); + p.setFont(font); + QPen pen; + pen.setBrush(QBrush(gradient)); + //Set penbrush with linergrident + + p.setPen(pen); + p.drawText(pixmap.rect(), Qt::AlignCenter, str); + //Draws the digit number(str here) within the provided rectangle + + p.end(); + + return pixmap.scaledToWidth(width(), Qt::SmoothTransformation); + //Returns a scaled copy of the image which is transformed using bilinear filtering + } + + /*prepare the pixmap */ + void preparePixmap() { + m_pixmap = QPixmap(size()); + m_pixmap.fill(Qt::transparent); + //Fills the pixmap with the given transparent black value (i.e., QColor(0, 0, 0, 0)) + + QPainter p; + p.begin(&m_pixmap); + p.drawPixmap(0, 0, drawDigits(m_number, rect())); + //Draws the given digits-pixmap at position (0, 0) + + p.end(); + } + + /*define a resize event*/ + void resizeEvent(QResizeEvent*) { + preparePixmap(); + update();//Causes a paintEvent() call + + } + + /*Paint the static state*/ + void paintStatic() { + QPainter p(this); + p.fillRect(rect(), Qt::black); + //Fill the widget rec with black color + + int pad = width() / 10; + drawFrame(&p, rect().adjusted(pad, pad, -pad, -pad)); + p.drawPixmap(0, 0, m_pixmap); + } + + /*Paint the slide state*/ + void paintSlide() { + QPainter p(this); + p.fillRect(rect(), Qt::black); + + int pad = width() / 10; + QRect fr = rect().adjusted(pad, pad, -pad, -pad); + drawFrame(&p, fr); + p.setClipRect(fr); + //sets the clip region to the given rectangle using the given clip operation + + int y = height() * m_animator.currentFrame() / 100; + p.drawPixmap(0, y, m_lastPixmap); + //Draw last-time state pixmap from 0 to height()(Y Coordinate) in 0.6 second + + p.drawPixmap(0, y - height(), m_pixmap); + //Draw current-time state pixmap from -height() to 0 (Y Coordinate) in 0.6 second + } + + /*Paint the flip state*/ + void paintFlip() { + QPainter p(this); +#if !defined(Q_OS_SYMBIAN) && !defined(Q_OS_WINCE_WM) + p.setRenderHint(QPainter::SmoothPixmapTransform, true); + p.setRenderHint(QPainter::Antialiasing, true); +#endif + p.fillRect(rect(), Qt::black); + + int hw = width() / 2; + int hh = height() / 2; + + // behind is the new pixmap + int pad = width() / 10; + QRect fr = rect().adjusted(pad, pad, -pad, -pad); + drawFrame(&p, fr); + p.drawPixmap(0, 0, m_pixmap); + + int index = m_animator.currentFrame(); + + if (index <= 50) { + + // the top part of the old pixmap is flipping + int angle = -180 * index / 100; + QTransform transform; + transform.translate(hw, hh); + //Moves the coordinate system to the center of widget + + transform.rotate(angle, Qt::XAxis); + //Rotates the coordinate system counterclockwise by angle about the X axis + + p.setTransform(transform); + drawFrame(&p, fr.adjusted(-hw, -hh, -hw, -hh)); + p.drawPixmap(-hw, -hh, m_lastPixmap); + + // the bottom part is still the old pixmap + p.resetTransform(); + p.setClipRect(0, hh, width(), hh); + //Enables clipping, and sets the clip region to the rectangle beginning at (0, hh) with the given width and height + + drawFrame(&p, fr); + p.drawPixmap(0, 0, m_lastPixmap); + } + else { + + p.setClipRect(0, hh, width(), hh); + + // the bottom part is still the old pixmap + drawFrame(&p, fr); + p.drawPixmap(0, 0, m_lastPixmap); + + // the bottom part of the new pixmap is flipping + int angle = 180 - 180 * m_animator.currentFrame() / 100; + QTransform transform; + transform.translate(hw, hh); + transform.rotate(angle, Qt::XAxis); + p.setTransform(transform); + drawFrame(&p, fr.adjusted(-hw, -hh, -hw, -hh)); + p.drawPixmap(-hw, -hh, m_pixmap); + + } + + } + + /*Paint the rotate state*/ + void paintRotate() { + QPainter p(this); + + int pad = width() / 10; + QRect fr = rect().adjusted(pad, pad, -pad, -pad); + drawFrame(&p, fr); + p.setClipRect(fr); + + int angle1 = -180 * m_animator.currentFrame() / 100; + int angle2 = 180 - 180 * m_animator.currentFrame() / 100; + int angle = (m_animator.currentFrame() <= 50) ? angle1 : angle2; + QPixmap pix = (m_animator.currentFrame() <= 50) ? m_lastPixmap : m_pixmap; + + QTransform transform; + transform.translate(width() / 2, height() / 2); + transform.rotate(angle, Qt::XAxis); + + p.setTransform(transform); + p.setRenderHint(QPainter::SmoothPixmapTransform, true); + p.drawPixmap(-width() / 2, -height() / 2, pix); + } + + void paintEvent(QPaintEvent *event) { + Q_UNUSED(event); + if (m_animator.state() == QTimeLine::Running) { + if (m_transition == Slide) + paintSlide(); + if (m_transition == Flip) + paintFlip(); + if (m_transition == Rotate) + paintRotate(); + } + else { + paintStatic(); + } + } + +private: + int m_number;//number to set to digits + + int m_transition;//transition mode(change effect) + + QPixmap m_pixmap;//current time pixmap + + QPixmap m_lastPixmap;//next state time pixmap + + QTimeLine m_animator; + //used to animate a GUI control by calling a slot periodically + //The timeline's duration describes for how long the animation will run + //connect the frameChanged() signal to a suitable slot in the widget you wish to animate +}; +class QClockDlg : public QWidget +{ + Q_OBJECT + +public: + QClockDlg(QWidget *parent = 0) : QWidget(parent) + { + m_Ihour = 0; + m_Iminute = 0; + m_hour = new Digits(this); + m_hour->show(); + m_minute = new Digits(this); + m_minute->show(); + + QPalette pal = palette(); + pal.setColor(QPalette::Window, Qt::gray); + //Sets the color used for the given color role, in all color groups, to the specified solid color. + + setPalette(pal); + QAction *slideAction = new QAction("&Slide", this); + QAction *flipAction = new QAction("&Flip", this); + QAction *rotateAction = new QAction("&Rotate", this); + connect(slideAction, SIGNAL(triggered()), SLOT(chooseSlide())); + connect(flipAction, SIGNAL(triggered()), SLOT(chooseFlip())); + connect(rotateAction, SIGNAL(triggered()), SLOT(chooseRotate())); +#if defined(Q_OS_SYMBIAN) || defined(Q_OS_WINCE_WM) + menuBar()->addAction(slideAction); + menuBar()->addAction(flipAction); + menuBar()->addAction(rotateAction); +#else + addAction(slideAction); + addAction(flipAction); + addAction(rotateAction); + setContextMenuPolicy(Qt::ActionsContextMenu); + //Shows a context menu(right click) +#endif + } + void InitTime(int hour, int min){ + m_hour->setNumber(hour); + m_minute->setNumber(min); + } + void SetTime(int hour, int min){ + + m_hour->flipTo(hour); + m_minute->flipTo(min); + m_Ihour = hour; + m_Iminute = min; + } +private: + QBasicTimer m_ticker; + Digits *m_hour; + Digits *m_minute; +protected: + void resizeEvent(QResizeEvent*) { + int digitsWidth = width() / 2; + int digitsHeight = digitsWidth * 1.2; + + int y = (height() - digitsHeight) / 3; + + m_hour->resize(digitsWidth, digitsHeight); + m_hour->move(0, y); + + m_minute->resize(digitsWidth, digitsHeight); + m_minute->move(width() / 2, y); + } + + /*Timer event,receive timer events */ + void timerEvent(QTimerEvent*) { + updateTime(); + } + + /* Get key press event */ + void keyPressEvent(QKeyEvent *event) { + if (event->key() == Qt::Key_Right) { + switchTransition(1); + event->accept(); + } + if (event->key() == Qt::Key_Left) { + switchTransition(-1); + event->accept(); + } + } + + private slots: + void chooseSlide() { + m_hour->setTransition(0); + m_minute->setTransition(0); + updateTime(); + } + + void chooseFlip() { + m_hour->setTransition(1); + m_minute->setTransition(1); + updateTime(); + } + + void chooseRotate() { + m_hour->setTransition(2); + m_minute->setTransition(2); + updateTime(); + } +public: + int m_Ihour, m_Iminute; + /*Real-time updates*/ + void updateTime() { + m_hour->flipTo(m_Ihour); + m_minute->flipTo(m_Iminute); + } + + /*Switch transition mode*/ + void switchTransition(int delta) { + int i = (m_hour->transition() + delta + 3) % 3; + m_hour->setTransition(i); + m_minute->setTransition(i); + updateTime(); + } +}; + +class QTimeDlg : public QDialog +{ + Q_OBJECT + +public: + QTimeDlg(QWidget *parent = 0); + ~QTimeDlg(); + Q_SLOT void SlotOk(); + Q_SLOT void valuechange(int m_value); + Q_SLOT void SlotCalWidget(const QDate &m_date); + void SetDateTime(QDate m_date, QTime m_time); + void SetDateTime(QDateTime m_datetime); + void GetDateTime(QDate &m_date, QTime &m_time); + void GetDateTime(QDateTime &m_datetime); + Q_SLOT void onCurrentStrChange(QString str); + Q_SLOT void oncurrentPageChanged(int nyear, int nMonth); +private: + Ui::QTimeDlg ui; + QDate m_date; + QTime m_time; + QClockDlg *m_clock; + int m_year, m_month, m_Day; +}; + +#endif // QTIMEDLG_H diff --git a/tpvs17/lpReport/qtimedlg.ui b/tpvs17/lpReport/qtimedlg.ui new file mode 100644 index 0000000..5bbe584 --- /dev/null +++ b/tpvs17/lpReport/qtimedlg.ui @@ -0,0 +1,611 @@ + + + QTimeDlg + + + + 0 + 0 + 584 + 380 + + + + 时间设置 + + + + + + + + + background-color: rgb(170, 170, 127); + + + + + + + + + + + + + 60 + 45 + + + + + Consolas + 12 + 50 + false + false + + + + Qt::LeftToRight + + + font: 12pt "Consolas"; + + + + 30 + 30 + + + + + 0 + + + + + 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 + + + + + + + + + 0 + 0 + + + + + 60 + 45 + + + + + Consolas + 12 + 50 + false + false + + + + Qt::WheelFocus + + + font: 12pt "Consolas"; + + + + 30 + 30 + + + + + 0 + + + + + 1 + + + + + 2 + + + + + 3 + + + + + 4 + + + + + 5 + + + + + 6 + + + + + 7 + + + + + 8 + + + + + 9 + + + + + 10 + + + + + 11 + + + + + 12 + + + + + 13 + + + + + 14 + + + + + 15 + + + + + 16 + + + + + 17 + + + + + 18 + + + + + 19 + + + + + 20 + + + + + 21 + + + + + 22 + + + + + 23 + + + + + + + + font: 12pt "Consolas"; + + + 小时 + + + + + + + font: 12pt "Consolas"; + + + 分钟 + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + Consolas + 14 + 50 + false + false + + + + Qt::DefaultContextMenu + + + + + + 2017/00/00 00:00 + + + Qt::AlignCenter + + + + + + + + 0 + 0 + + + + + 100 + 60 + + + + background-color: rgb(76, 230, 0); +font: 75 12pt "Consolas"; + + + 确定 + + + + + + + + + diff --git a/tpvs17/lpReport/resource.h b/tpvs17/lpReport/resource.h new file mode 100644 index 0000000..68a41c6 --- /dev/null +++ b/tpvs17/lpReport/resource.h @@ -0,0 +1,16 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ ɵİļ +// lpReport.rc ʹ +// +#define IDI_ICON1 101 + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 102 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1001 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif diff --git a/tpvs17/lpReport/testwidget.cpp b/tpvs17/lpReport/testwidget.cpp new file mode 100644 index 0000000..84e5a94 --- /dev/null +++ b/tpvs17/lpReport/testwidget.cpp @@ -0,0 +1,103 @@ +#include "testwidget.h" +#include "QPushButton" +#include "QLineEdit" +#include "QAbstractItemView" +#pragma execution_character_set("utf-8") +TestWidget::TestWidget(QWidget *parent) + : QWidget(parent) +{ + ui.setupUi(this); + m_treewidget = ui.treeWidget; + + initTreewidget(m_treewidget); + +} + +void TestWidget::initTreewidget(QTreeWidget* pTreewidget) +{ + QStringList header; + header.append("属性"); + header.append("值"); + pTreewidget->setHeaderLabels(header); + pTreewidget->header()->setStretchLastSection(true); + pTreewidget->setColumnCount(2); + pTreewidget->setStyleSheet("QTreeView::item:hover{background-color:rgb(0,255,0,50)}" + "QTreeView::item:selected{background-color:rgb(255,0,0,100)}"); + //pTreewidget->setSelectionModel(QAbstractItemView::ExtendedSelection); + pTreewidget->setColumnWidth(0, 100); + addIPRoot(pTreewidget); + addEDitRoot(pTreewidget); + +} + +void TestWidget::addIPRoot(QTreeWidget *pTreewidget) +{ + + QRegExp regExpIP("((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])[\\.]){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])"); + QRegExp regExpNetPort("((6553[0-5])|[655[0-2][0-9]|65[0-4][0-9]{2}|6[0-4][0-9]{3}|[1-5][0-9]{4}|[1-9][0-9]{3}|[1-9][0-9]{2}|[1-9][0-9]|[0-9])"); + QRegExp regExpChannel("[0-5]"); + + QTreeWidgetItem *m_IPItems = new QTreeWidgetItem(pTreewidget, QStringList(QString("IP地址配置"))); + + QTreeWidgetItem *m_ServerItems = new QTreeWidgetItem(m_IPItems, QStringList(QString("本机服务器IP地址设置"))); + QList serveritems; + serveritems.append(new QTreeWidgetItem((QTreeWidget*)0, QStringList(QString("操作")))); + serveritems.append(new QTreeWidgetItem((QTreeWidget*)0, QStringList(QString("IP地址")))); + serveritems.append(new QTreeWidgetItem((QTreeWidget*)0, QStringList(QString("开放端口")))); + m_ServerItems->addChildren(serveritems); + QPushButton* m_pButOpen = new QPushButton("打开服务"); + QLineEdit *m_EditserverIP = new QLineEdit; + QLineEdit *m_EditserverPort = new QLineEdit; + m_EditserverIP->setValidator(new QRegExpValidator(regExpIP, this)); + m_EditserverPort->setValidator(new QRegExpValidator(regExpNetPort, this)); + m_EditserverIP->setText("192.168.1.1"); + m_EditserverPort->setText("100"); + pTreewidget->setItemWidget(serveritems.at(0), 1, m_pButOpen); + pTreewidget->setItemWidget(serveritems.at(1), 1, m_EditserverIP); + pTreewidget->setItemWidget(serveritems.at(2), 1, m_EditserverPort); + + QTreeWidgetItem *m_ClientItems = new QTreeWidgetItem(m_IPItems, QStringList(QString("目标客户端IP地址设置"))); + QList clientitems; + clientitems.append(new QTreeWidgetItem((QTreeWidget*)0, QStringList(QString("IP地址")))); + clientitems.append(new QTreeWidgetItem((QTreeWidget*)0, QStringList(QString("源端口")))); + + m_ClientItems->addChildren(clientitems); + QLineEdit *m_EditclientIP = new QLineEdit; + QLineEdit *m_EditclientPort = new QLineEdit; + m_EditclientIP->setValidator(new QRegExpValidator(regExpIP, this)); + m_EditclientPort->setValidator(new QRegExpValidator(regExpNetPort, this)); + + pTreewidget->setItemWidget(clientitems.at(0), 1, m_EditclientIP); + pTreewidget->setItemWidget(clientitems.at(1), 1, m_EditclientPort); + + QPushButton *pSaveButton = new QPushButton("保存"); + QTreeWidgetItem* saveItem = new QTreeWidgetItem(m_IPItems, QStringList(QString("保存设置"))); + pTreewidget->setItemWidget(saveItem, 1, pSaveButton); + +} + +void TestWidget::addEDitRoot(QTreeWidget *pTreewidget) +{ + QTreeWidgetItem *m_IPItems = new QTreeWidgetItem(pTreewidget, QStringList(QString("Edit设置"))); + + QList items; + QList pLineEdits; + for (int i = 0; i < 10; i++) + { + items.append(new QTreeWidgetItem((QTreeWidget*)0, QStringList(QString("item: %1").arg(i)))); + QLineEdit *pEdit = new QLineEdit; + pEdit->setText(QString("%1").arg(i)); + pLineEdits.append(pEdit); + } + m_IPItems->addChildren(items); + pTreewidget->insertTopLevelItem(0, m_IPItems); + for (int nIndex = 0; nIndex < pLineEdits.size(); nIndex++) + { + pTreewidget->setItemWidget(items.at(nIndex), 1, pLineEdits.at(nIndex)); + } +} + +TestWidget::~TestWidget() +{ + m_treewidget->clear(); +} diff --git a/tpvs17/lpReport/testwidget.h b/tpvs17/lpReport/testwidget.h new file mode 100644 index 0000000..3153169 --- /dev/null +++ b/tpvs17/lpReport/testwidget.h @@ -0,0 +1,22 @@ +#ifndef TESTWIDGET_H +#define TESTWIDGET_H + +#include +#include "ui_testwidget.h" +#include +class TestWidget : public QWidget +{ + Q_OBJECT + +public: + TestWidget(QWidget *parent = 0); + ~TestWidget(); + void initTreewidget(QTreeWidget* pTreewidget); + void addIPRoot(QTreeWidget *pTreewidget); + void addEDitRoot(QTreeWidget *pTreewidget); +private: + Ui::TestWidget ui; + QTreeWidget * m_treewidget; +}; + +#endif // TESTWIDGET_H diff --git a/tpvs17/lpReport/testwidget.ui b/tpvs17/lpReport/testwidget.ui new file mode 100644 index 0000000..72ba893 --- /dev/null +++ b/tpvs17/lpReport/testwidget.ui @@ -0,0 +1,35 @@ + + + TestWidget + + + + 0 + 0 + 659 + 562 + + + + TestWidget + + + + + 0 + 0 + 491 + 541 + + + + + 1 + + + + + + + + diff --git a/tpvs17/lpReport/waitingdialog.cpp b/tpvs17/lpReport/waitingdialog.cpp new file mode 100644 index 0000000..062cac9 --- /dev/null +++ b/tpvs17/lpReport/waitingdialog.cpp @@ -0,0 +1,50 @@ +#include "waitingdialog.h" +#include "QBoxLayout" +#include +WaitingDialog::WaitingDialog(QWidget *parent) + : QDialog(parent) +{ + m_ProgressBar = NULL; + m_ProgressBar = new QProgressBar(this); + m_CurrentValue = m_MaxValue = m_UpdateInterval = 0; + m_ProgressBar->setRange(0, 100); + connect(&m_Timer, SIGNAL(timeout()), this, SLOT(UpdateSlot())); + m_ProgressBar->setTextVisible(false); + QHBoxLayout *layout = new QHBoxLayout; + layout->addWidget(m_ProgressBar); + setLayout(layout); +} + +WaitingDialog::~WaitingDialog() +{ + if (m_ProgressBar) + { + delete m_ProgressBar; + m_ProgressBar = NULL; + } +} + +void WaitingDialog::Start(int interval /*= 100*/, int maxValue /*= 100*/) +{ + m_UpdateInterval = interval; + m_MaxValue = maxValue; + m_CurrentValue = 0; + if (m_Timer.isActive()) + m_Timer.stop(); + m_Timer.start(m_UpdateInterval); + m_ProgressBar->setRange(0, m_MaxValue); + m_ProgressBar->setValue(0); +} + +void WaitingDialog::Stop() +{ + m_Timer.stop(); +} + +void WaitingDialog::UpdateSlot() +{ + m_CurrentValue++; + if (m_CurrentValue == m_MaxValue) + m_CurrentValue = 0; + m_ProgressBar->setValue(m_CurrentValue); +} diff --git a/tpvs17/lpReport/waitingdialog.h b/tpvs17/lpReport/waitingdialog.h new file mode 100644 index 0000000..6459a9b --- /dev/null +++ b/tpvs17/lpReport/waitingdialog.h @@ -0,0 +1,28 @@ +#ifndef WAITINGDIALOG_H +#define WAITINGDIALOG_H + +#include +#include "QTimer" +#include +class WaitingDialog : public QDialog +{ + Q_OBJECT + +public: + WaitingDialog(QWidget *parent =0); + ~WaitingDialog(); + void Start(int interval = 100, int maxValue = 100); + void Stop(); + +private slots: + void UpdateSlot(); +private: + int m_CurrentValue; + int m_UpdateInterval; + int m_MaxValue; + QTimer m_Timer; + QProgressBar *m_ProgressBar; + +}; + +#endif // WAITINGDIALOG_H diff --git a/tpvs17/lpReport/workfordb.h b/tpvs17/lpReport/workfordb.h new file mode 100644 index 0000000..8a768e6 --- /dev/null +++ b/tpvs17/lpReport/workfordb.h @@ -0,0 +1,32 @@ +#ifndef WORKFORDB_H +#define WORKFORDB_H + +#include +#include "databasesql.h" + +class WorkForDB : public QObject +{ + Q_OBJECT + +public: + WorkForDB(QObject *parent = 0){ m_pDb = NULL; }; + ~WorkForDB(){}; + void setDB(DataBaseSql* pDB){ m_pDb = pDB; }; +public slots: + void doWork(const QString& strTime, const int &ncount) + { + QString str; + if (m_pDb){ + m_pDb->DelDatasByTime(strTime); + m_pDb->DelWarnDataByCount(1, ncount); + m_pDb->DelWarnDataByCount(4, ncount); + } + emit resultReady(str); + }; +private: + class DataBaseSql *m_pDb; +signals: + void resultReady(QString str); +}; + +#endif // WORKFORDB_H diff --git a/tpvs17/wheel.sln b/tpvs17/wheel.sln index 95f801e..b08db5c 100644 --- a/tpvs17/wheel.sln +++ b/tpvs17/wheel.sln @@ -9,30 +9,80 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "tpAlgorithmQt", "tpAlgorith EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RasterSDG20", "RasterSDG20\RasterSDG20.vcxproj", "{CE765894-2106-48FE-99C3-D8D7624889A0}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "lpCoreCtrl", "..\..\Valve\tpvs17\lpCoreCtrl\lpCoreCtrl.vcxproj", "{784071A9-BF94-4D27-B62E-588ACD7E0633}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "QUserInfo", "QUserInfo\QUserInfo.vcxproj", "{D7AF8AA1-0F2C-407F-B135-FBDA4448EE16}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "tpCamHik", "..\..\Valve\tpvs17\tpCamHik\tpCamHik.vcxproj", "{64C9A32D-82E8-4C36-9AA6-52D58B23F687}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "tpCamBaumer", "..\..\Valve\tpvs17\tpCamBaumer\tpCamBaumer.vcxproj", "{4CB8DBEB-EE73-4CEA-B662-E18B79EE113C}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "lpReport", "lpReport\lpReport.vcxproj", "{0E042214-1B06-40D6-9D20-C6D5FA3D7A51}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 Release|x64 = Release|x64 + Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {A229CF5C-81EF-4909-AB6E-49C746F1ED4C}.Debug|x64.ActiveCfg = Debug|x64 {A229CF5C-81EF-4909-AB6E-49C746F1ED4C}.Debug|x64.Build.0 = Debug|x64 + {A229CF5C-81EF-4909-AB6E-49C746F1ED4C}.Debug|x86.ActiveCfg = Debug|x64 {A229CF5C-81EF-4909-AB6E-49C746F1ED4C}.Release|x64.ActiveCfg = Release|x64 {A229CF5C-81EF-4909-AB6E-49C746F1ED4C}.Release|x64.Build.0 = Release|x64 + {A229CF5C-81EF-4909-AB6E-49C746F1ED4C}.Release|x86.ActiveCfg = Release|x64 {B12702AD-ABFB-343A-A199-8E24837244A3}.Debug|x64.ActiveCfg = Debug|x64 {B12702AD-ABFB-343A-A199-8E24837244A3}.Debug|x64.Build.0 = Debug|x64 + {B12702AD-ABFB-343A-A199-8E24837244A3}.Debug|x86.ActiveCfg = Debug|x64 {B12702AD-ABFB-343A-A199-8E24837244A3}.Release|x64.ActiveCfg = Release|x64 {B12702AD-ABFB-343A-A199-8E24837244A3}.Release|x64.Build.0 = Release|x64 + {B12702AD-ABFB-343A-A199-8E24837244A3}.Release|x86.ActiveCfg = Release|x64 {CE765894-2106-48FE-99C3-D8D7624889A0}.Debug|x64.ActiveCfg = Debug|x64 {CE765894-2106-48FE-99C3-D8D7624889A0}.Debug|x64.Build.0 = Debug|x64 + {CE765894-2106-48FE-99C3-D8D7624889A0}.Debug|x86.ActiveCfg = Debug|x64 {CE765894-2106-48FE-99C3-D8D7624889A0}.Release|x64.ActiveCfg = Release|x64 {CE765894-2106-48FE-99C3-D8D7624889A0}.Release|x64.Build.0 = Release|x64 + {CE765894-2106-48FE-99C3-D8D7624889A0}.Release|x86.ActiveCfg = Release|x64 + {784071A9-BF94-4D27-B62E-588ACD7E0633}.Debug|x64.ActiveCfg = Debug|x64 + {784071A9-BF94-4D27-B62E-588ACD7E0633}.Debug|x64.Build.0 = Debug|x64 + {784071A9-BF94-4D27-B62E-588ACD7E0633}.Debug|x86.ActiveCfg = Debug|x64 + {784071A9-BF94-4D27-B62E-588ACD7E0633}.Release|x64.ActiveCfg = Release|x64 + {784071A9-BF94-4D27-B62E-588ACD7E0633}.Release|x64.Build.0 = Release|x64 + {784071A9-BF94-4D27-B62E-588ACD7E0633}.Release|x86.ActiveCfg = Release|x64 + {D7AF8AA1-0F2C-407F-B135-FBDA4448EE16}.Debug|x64.ActiveCfg = Debug|x64 + {D7AF8AA1-0F2C-407F-B135-FBDA4448EE16}.Debug|x64.Build.0 = Debug|x64 + {D7AF8AA1-0F2C-407F-B135-FBDA4448EE16}.Debug|x86.ActiveCfg = Debug|x64 + {D7AF8AA1-0F2C-407F-B135-FBDA4448EE16}.Release|x64.ActiveCfg = Release|x64 + {D7AF8AA1-0F2C-407F-B135-FBDA4448EE16}.Release|x64.Build.0 = Release|x64 + {D7AF8AA1-0F2C-407F-B135-FBDA4448EE16}.Release|x86.ActiveCfg = Release|x64 + {64C9A32D-82E8-4C36-9AA6-52D58B23F687}.Debug|x64.ActiveCfg = Debug|x64 + {64C9A32D-82E8-4C36-9AA6-52D58B23F687}.Debug|x64.Build.0 = Debug|x64 + {64C9A32D-82E8-4C36-9AA6-52D58B23F687}.Debug|x86.ActiveCfg = Debug|Win32 + {64C9A32D-82E8-4C36-9AA6-52D58B23F687}.Debug|x86.Build.0 = Debug|Win32 + {64C9A32D-82E8-4C36-9AA6-52D58B23F687}.Release|x64.ActiveCfg = Release|x64 + {64C9A32D-82E8-4C36-9AA6-52D58B23F687}.Release|x64.Build.0 = Release|x64 + {64C9A32D-82E8-4C36-9AA6-52D58B23F687}.Release|x86.ActiveCfg = Release|Win32 + {64C9A32D-82E8-4C36-9AA6-52D58B23F687}.Release|x86.Build.0 = Release|Win32 + {4CB8DBEB-EE73-4CEA-B662-E18B79EE113C}.Debug|x64.ActiveCfg = Debug|x64 + {4CB8DBEB-EE73-4CEA-B662-E18B79EE113C}.Debug|x64.Build.0 = Debug|x64 + {4CB8DBEB-EE73-4CEA-B662-E18B79EE113C}.Debug|x86.ActiveCfg = Debug|x64 + {4CB8DBEB-EE73-4CEA-B662-E18B79EE113C}.Release|x64.ActiveCfg = Release|x64 + {4CB8DBEB-EE73-4CEA-B662-E18B79EE113C}.Release|x64.Build.0 = Release|x64 + {4CB8DBEB-EE73-4CEA-B662-E18B79EE113C}.Release|x86.ActiveCfg = Release|x64 + {0E042214-1B06-40D6-9D20-C6D5FA3D7A51}.Debug|x64.ActiveCfg = Debug|x64 + {0E042214-1B06-40D6-9D20-C6D5FA3D7A51}.Debug|x64.Build.0 = Debug|x64 + {0E042214-1B06-40D6-9D20-C6D5FA3D7A51}.Debug|x86.ActiveCfg = Debug|x64 + {0E042214-1B06-40D6-9D20-C6D5FA3D7A51}.Release|x64.ActiveCfg = Release|x64 + {0E042214-1B06-40D6-9D20-C6D5FA3D7A51}.Release|x64.Build.0 = Release|x64 + {0E042214-1B06-40D6-9D20-C6D5FA3D7A51}.Release|x86.ActiveCfg = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {CD365F32-5EAC-4A16-AD47-BFB1D8E5511A} Qt5Version = qt5.9.4-msvc2017-x64 + SolutionGuid = {CD365F32-5EAC-4A16-AD47-BFB1D8E5511A} EndGlobalSection EndGlobal