ソースを参照

添加泄漏值录入, 添加设备自检页面

guoqiang 2 年 前
コミット
49ee59d282
共有26 個のファイルを変更した2404 個の追加178 個の削除を含む
  1. 0 1
      DLog.cpp
  2. 149 0
      Deviceinfo.cpp
  3. 46 0
      Deviceinfo.h
  4. 1 0
      Log.qml
  5. 202 0
      PageLeakageInput.qml
  6. 57 7
      PageMain.qml
  7. 889 0
      PageSelfTest.qml
  8. 26 25
      PageSetting.qml
  9. 10 8
      PageTest.qml
  10. 32 36
      RecoveryValve.qml
  11. 22 0
      ReturnButton.qml
  12. 102 0
      TNormalProgress.qml
  13. 191 89
      TestService.cpp
  14. 13 5
      TestService.h
  15. 3 1
      ValveTest.pro
  16. 2 1
      ValveTest.pro.user
  17. BIN
      img/fail_circle.png
  18. BIN
      img/ok_circle.png
  19. BIN
      img/return.png
  20. 1 0
      main.cpp
  21. 8 0
      qml.qrc
  22. 324 4
      report.cpp
  23. 23 1
      report.h
  24. 245 0
      selftest_db.js
  25. 42 0
      tank.cpp
  26. 16 0
      tank.h

+ 0 - 1
DLog.cpp

@@ -8,7 +8,6 @@
 void DLog_Init()
 {
 
-    //tmp 存放生成的曲线图片
     QDir dir("D:/tmp");
 
     if(dir.exists()){

+ 149 - 0
Deviceinfo.cpp

@@ -0,0 +1,149 @@
+#include "Deviceinfo.h"
+#include <QSettings>
+#include <QString>
+#include <QFile>
+#include <QDir>
+#include <QDebug>
+#include <QTextCodec>
+
+#include <QJsonDocument>
+#include <QJsonArray>
+#include <QJsonObject>
+
+#define CONFIG_PATH  "D:/Profile"
+#define CONFIG_FULL_PATH  "D:/Profile/deviceinfo.ini"
+#define CONFIG_NAME  "deviceinfo.ini"
+
+DeviceInfo::DeviceInfo()
+{
+    genDefault();
+    load();
+}
+
+bool DeviceInfo::update_testinfo(const QString& jsonStr )
+{
+    QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonStr.toUtf8());
+    QJsonObject jsonObj = jsonDoc.object();
+
+
+    if(jsonObj.contains("target") && jsonObj.value("target").isDouble()){
+        m_testinfo.m_target = jsonObj.value("target").toDouble();
+    }
+
+    if(jsonObj.contains("interval") && jsonObj.value("interval").isDouble()){
+        m_testinfo.m_interval = jsonObj.value("interval").toInt();
+    }
+
+    if(jsonObj.contains("threshold") && jsonObj.value("threshold").isDouble()){
+        m_testinfo.m_threshold = jsonObj.value("threshold").toDouble();
+    }
+
+    if(jsonObj.contains("begin") && jsonObj.value("begin").isDouble()){
+        m_testinfo.m_begin = jsonObj.value("begin").toDouble();
+        qDebug() << "m_testinfo.m_begin = " << m_testinfo.m_begin;
+    }
+
+    if(jsonObj.contains("end") && jsonObj.value("end").isDouble()){
+        m_testinfo.m_end = jsonObj.value("end").toDouble();
+    }
+
+    if(jsonObj.contains("delta") && jsonObj.value("delta").isDouble()){
+        m_testinfo.m_delta = jsonObj.value("delta").toDouble();
+    }
+
+    if(jsonObj.contains("passed") && jsonObj.value("passed").isDouble()){
+        m_testinfo.m_passed = jsonObj.value("passed").toInt();
+    }
+
+
+    return true;
+}
+
+void DeviceInfo::genDefault()
+{
+    QTextCodec *codec = QTextCodec::codecForName("UTF-8");
+
+    m_model = "JL-VRST-2000";
+    m_id = "JL0000000";
+    m_name = codec->toUnicode("汽车罐车油气回收系统智能检测仪");
+    m_ex_level = "Exd IIBT4 Gb";
+    m_manufacture = codec->toUnicode("杭州嘉隆物联网科技有限公司");
+    m_date = "2000-00-00";
+
+    m_testinfo.m_target = 6.0;
+    m_testinfo.m_interval = 300;
+    m_testinfo.m_threshold = 0.5;
+    m_testinfo.m_begin = 0.0;
+    m_testinfo.m_end = 0.0;
+    m_testinfo.m_delta = 0.0;
+    m_testinfo.m_passed = 1;
+
+}
+
+void DeviceInfo::load()
+{
+    QFileInfo fi(CONFIG_FULL_PATH);
+    if(fi.isFile()){
+
+        QSettings *configIniRead = new QSettings(CONFIG_FULL_PATH, QSettings::IniFormat);
+        configIniRead->setIniCodec("UTF-8");
+
+        m_name = configIniRead->value("Device/Name").toString();
+        m_model = configIniRead->value("Device/Model").toString();
+        m_id = configIniRead->value("Device/ID").toString();
+        m_ex_level = configIniRead->value("Device/ExFlag").toString();
+        m_date = configIniRead->value("Device/Date").toString();
+        m_manufacture = configIniRead->value("Device/Manufacture").toString();
+
+        m_testinfo.m_target = configIniRead->value("SelfTest/Target").toDouble();
+        m_testinfo.m_interval = configIniRead->value("SelfTest/Interval").toInt();
+        m_testinfo.m_threshold = configIniRead->value("SelfTest/Threshold").toDouble();
+
+        if(m_testinfo.m_target > 50.0){
+           m_testinfo.m_target = 50.0;
+        }else if(m_testinfo.m_target < -20.0){
+           m_testinfo.m_target = -20.0;
+        }
+
+        if(m_testinfo.m_interval > 10*60){
+            m_testinfo.m_interval = 10*60;
+        }else if(m_testinfo.m_interval < 10){
+           m_testinfo.m_interval = 10;
+        }
+
+        //if(m_testinfo.m_threshold > m_testinfo.m_target){
+        //    m_testinfo.m_threshold = m_testinfo.m_target;
+        //}
+        qDebug() << "manufacture:" << m_manufacture;
+
+        delete configIniRead;
+
+    }else{
+
+        qDebug() << "CONFIG is not exists";
+
+        QDir dir(CONFIG_PATH);
+        if(false == dir.exists()){
+            qDebug() << "CONFIG_PATH is not exists, will mk it";
+            dir.mkdir(CONFIG_PATH);
+        }
+
+        QSettings *configIniWrite = new QSettings(CONFIG_FULL_PATH, QSettings::IniFormat);
+        configIniWrite->setIniCodec("UTF-8");
+
+        configIniWrite->setValue("Device/Name", m_name);
+        configIniWrite->setValue("Device/Model", m_model);
+        configIniWrite->setValue("Device/ID", m_id);
+        configIniWrite->setValue("Device/ExFlag", m_ex_level);
+        configIniWrite->setValue("Device/Date", m_date);
+        configIniWrite->setValue("Device/Manufacture", m_manufacture);
+
+        configIniWrite->setValue("SelfTest/Target", m_testinfo.m_target);
+        configIniWrite->setValue("SelfTest/Interval", m_testinfo.m_interval);
+        configIniWrite->setValue("SelfTest/Threshold", m_testinfo.m_threshold);
+
+        delete configIniWrite;
+
+    }
+
+}

+ 46 - 0
Deviceinfo.h

@@ -0,0 +1,46 @@
+#ifndef DEVICEINFO_H
+#define DEVICEINFO_H
+
+#include <QObject>
+#include <QString>
+#include <QMetaType>
+
+class SelfTest_Info{
+public:
+    double m_target;     //目标压力
+    int    m_interval;   //检测时间间隔
+    double m_threshold;  //判定阀值
+    double m_begin;  //开始压力
+    double m_end;    //结束压务
+    double m_delta;  //压力变化值
+    int    m_passed;  // 0:not passed  1: passed
+};
+
+
+class DeviceInfo{
+public:
+    explicit DeviceInfo();
+
+    bool update_testinfo(const QString& jsonStr );
+
+signals:
+
+public:
+    SelfTest_Info m_testinfo;
+    QString m_model;
+    QString m_id;
+    QString m_name;
+    QString m_ex_level;
+    QString m_manufacture;
+    QString m_date;   //生产日期
+
+private:
+    void genDefault();
+    void load();
+
+};
+
+Q_DECLARE_METATYPE(DeviceInfo);
+
+
+#endif // DEVICEINFO_H

+ 1 - 0
Log.qml

@@ -38,6 +38,7 @@ Item {
             id:item
             property alias text:fgtext.text
 
+
             Rectangle{
                 id:bg
                 anchors.fill: parent

+ 202 - 0
PageLeakageInput.qml

@@ -0,0 +1,202 @@
+import QtQuick 2.15
+import QtQuick.Layouts 1.3
+import QtQuick.Controls 2.14
+import QtQuick.Controls.Styles 1.2
+import Qt.labs.platform 1.1
+import TService 1.0
+
+
+Rectangle {
+    id:leakage_root
+
+    //implicitWidth: 600
+    //implicitHeight: 400
+    width: 600
+    height: 240
+    radius: 6
+
+    property  string title_str:"油气密封点泄漏值录入"
+    property double value_couplevalve: -100.0
+    property double value_manhole: -100.0
+    property  string carplate
+
+
+    function pad_with_zeroes(number, length) {
+        var my_string = '' + number;
+        while (my_string.length < length) {
+            my_string = '0' + my_string;
+        }
+        return my_string;
+    }
+
+    function getWordSaveFileName( para){
+        var date = new Date;
+        var year = date.getFullYear()
+        var month = pad_with_zeroes(date.getMonth()+1,2)
+        var day = pad_with_zeroes(date.getDate(),2)
+        var hour = pad_with_zeroes(date.getHours(),2)
+        var minute = pad_with_zeroes(date.getMinutes(),2)
+        var second = pad_with_zeroes(date.getSeconds(),2)
+
+        var time = year+month+day+hour+minute+second
+        return "file:///"+time+"_"+para
+    }
+
+
+
+    DynamicGroupBox{
+        id:dgroupbox
+        //x:width
+        //x:0
+
+        anchors.centerIn: parent
+        anchors.fill: parent
+
+        title: title_str
+
+
+        FileDialog {
+            id: saveWordDialog
+            title: "保存为"
+            //nameFilters: [ "Word files (*.doc)"]
+            nameFilters: [ "Text files (*.pdf)"]
+            fileMode: FileDialog.SaveFile
+            onAccepted: {
+                var savePath = file.toString().substring(8)
+
+                console.log("saveWordDialog savePath:")
+                console.log(savePath)
+
+                //reportWord.generateBreatheValveWord(savePath,para,obj1,obj2,obj3)
+                testService.genReport(savePath, "D:/tmp/")
+            }
+        }
+
+
+        Column{
+            spacing:20
+            anchors.centerIn: parent
+            width: 560
+
+            Row{
+                spacing:10
+                height: 80
+
+                Column{
+                    spacing:10
+                    Row{
+                        //spacing:10
+                        InputLine{
+                            id:vrs_couplevalve
+                            paraName: "油气回收耦合阀 : "
+                            paraLength: 170
+                            validator:RegExpValidator {
+                                regExp: /[0-9]*/
+                            }
+                            onTextChanged: {
+                                if(text.length > 0){
+                                    value_couplevalve = Number(text)
+                                }else{
+                                    value_couplevalve = -100.0
+                                }
+                            }
+                        }
+
+                        Text {
+                            text: "(μmol/mol)";
+                            //font.bold: true;
+                            font.pointSize: 20;
+                        }
+
+                    }
+
+                    Row{
+                        //spacing:10
+                        InputLine{
+                            id:manhole_cover
+                            paraName: "人孔盖(含紧急泄放装置): "
+                            paraLength: 80
+                            validator:RegExpValidator {
+                                regExp: /[0-9]*/
+                            }
+                            onTextChanged: {
+                                if(text.length > 0){
+                                    value_manhole = Number(text)
+                                }else{
+                                    value_manhole = -100.0
+                                }
+                            }
+                        }
+
+                        Text {
+                            text: "(μmol/mol)";
+                            //font.bold: true;
+                            font.pointSize: 20;
+                        }
+
+                    }
+
+                }
+
+            }
+
+
+            Row{
+                spacing:100
+                height: 80
+                padding: 80
+
+                UserButton {
+                    id: report_button;
+                    text: "生成检测报告";
+                    font.pixelSize: 20
+
+                    anchors.verticalCenter: parent.verticalCenter
+
+                    width: 160
+                    height: 45
+
+                    onClicked: {
+
+                            var lvJson={}
+                            lvJson.couplevalve = value_couplevalve
+                            lvJson.manhole = value_manhole
+                            testService.set_leakage_value(JSON.stringify(lvJson))
+
+
+                            var fileName = leakage_root.carplate
+                            var text = getWordSaveFileName(fileName)
+                            console.log(text)
+
+                            saveWordDialog.currentFile = getWordSaveFileName(fileName)
+                            saveWordDialog.open()
+
+                    }
+                }
+
+                UserButton {
+                    id: close_button;
+                    text: "退出";
+                    font.pixelSize: 20
+
+                    anchors.verticalCenter: parent.verticalCenter
+
+                    width: 120
+                    height: 45
+
+                    onClicked: {
+                        popupCenter.close()
+                    }
+                }
+            }
+
+        }
+
+    }
+
+    Component.onCompleted: {
+
+
+    }
+
+}

+ 57 - 7
PageMain.qml

@@ -263,7 +263,11 @@ Rectangle{
         z:10
         width: 300
         height: 50
-        anchors.centerIn: parent
+        //anchors.centerIn: parent
+        anchors.top: parent.top
+        anchors.topMargin: 100
+        anchors.left: parent.left
+        anchors.leftMargin: 480
     }
 
     Log{
@@ -271,14 +275,53 @@ Rectangle{
         z:20
         width: 300
         height: 50
-        anchors.centerIn: parent
+        //anchors.centerIn: parent
+        anchors.top: parent.top
+        anchors.topMargin: 100
+        anchors.left: parent.left
+        anchors.leftMargin: 480
     }
 
     TestService{
         id:testService
     }
 
+    Popup{
+       id:             popupCenter
+       modal:          true            //模态, 为 true后弹出窗口会叠加一个独特的背景调光效果
+       focus:          true            //焦点,  当弹出窗口实际接收到焦点时,activeFocus将为真
+       padding:        0
+       closePolicy:    Popup.CloseOnEscape  //| Popup.CloseOnPressOutside
+       property var    raiseItem:          null
+       background: Rectangle {
+            color:      Qt.rgba(0,0,0,0)   //背景为无色
+       }
+       Loader {
+           id:loaderCenter
+           onLoaded: {
+               popupCenter.x = (main_window.width - loaderCenter.width) * 0.5
+               popupCenter.y = (main_window.height - loaderCenter.height) * 0.5
+               popupCenter.z = 12
+           }
+       }
+       onOpened: {
+           loaderCenter.sourceComponent = popupCenter.raiseItem
+       }
+       onClosed: {
+           loaderCenter.sourceComponent = null
+           popupCenter.raiseItem = null
+       }
 
+    }
+
+    Component{
+        id: com_leakage
+        PageLeakageInput{
+            id:leakage_input
+            carplate: page_set.licenseplate
+        }
+
+    }
 
     Component.onCompleted: {
         //page_set.show()
@@ -376,13 +419,9 @@ Rectangle{
 
         if((id >= 1) &&(id<=rootitem.max_compartment_num)){
             var page_var = getTestPage(id)
-
-            //page_var.pressure = str
-            //page_var.add_record(str)
-            //page_var.pressureDisplayInput(str)
             page_var.update_pressure(map);
         }else if(id === 0){
-            pagetest.show_pressure(map.pressure)
+            //pagetest.show_pressure(map.pressure)
         }
 
 
@@ -439,12 +478,23 @@ Rectangle{
         if((id >= 1) &&(id<=rootitem.max_compartment_num)){
             var page_var = getTestPage(id)
             page_var.test_stoped()
+
+            if(testService.check_alltest_ok(0))
+            {
+                qmlshowPopupCenter(com_leakage)
+            }
+
         }else if(id === 0){
             pagetest.selftestStop()
             console.log("qmlProcessStop pagetest ",id )
         }
     }
 
+    function qmlshowPopupCenter(raiseItem){
+        popupCenter.raiseItem = raiseItem
+        popupCenter.open()
+    }
+
 }
 
 

+ 889 - 0
PageSelfTest.qml

@@ -0,0 +1,889 @@
+import QtQuick 2.15
+import QtQuick.Layouts 1.3
+import QtQuick.Controls 1.2
+import QtQuick.Controls.Styles 1.4
+import Qt.labs.qmlmodels 1.0
+import QtQuick.LocalStorage 2.0
+//import io.qt.DataBaseModel 1.0
+import Qt.labs.platform 1.1
+
+import TService 1.0
+import "selftest_db.js" as SelfDB
+
+
+Item {
+    id: selftest_root
+    property  string title_str:"系统自测"
+
+    property string background: "#d7e3bc"
+    property string alterBackground: "white"
+    property string highlight: "#e4f7d6"
+    property string headerBkgnd: "#F0F0F0"
+
+    property  var  allArray: []
+    //property  string state
+    property  string pressure:"0.00"
+    property int  pressureCnt:0
+    property  int test_direction:0
+    property  bool bStart: false
+    property  real m_maxY: 0.0
+    property  real m_minY: 0.0
+
+    property  string report_record_str:"null"
+    property  string test_state_str:"未开始"
+    property  string test_result_str:"未知"
+
+    //var selftest_info = new Object
+
+    property var normalG: Gradient {
+            GradientStop { position: 0.0; color: "#c7d3ac" }
+            GradientStop { position: 1.0; color: "#F0F0F0" }
+    }
+    property var hoverG: Gradient {
+            GradientStop { position: 0.0; color: "white"; }
+            GradientStop { position: 1.0; color: "#d7e3bc"; }
+    }
+    property var pressG: Gradient {
+            GradientStop { position: 0.0; color: "#d7e3bc"; }
+            GradientStop { position: 1.0; color: "white"; }
+    }
+
+    function qmlProcessState(id, str1, str2){
+        if(id === 0){
+
+            test_state_str = str1
+        }
+    }
+
+    function qmlProcessResult(id, str, bPassed){
+        if(id === 0){
+            if(bPassed){
+                test_result_str = "合格"
+            }else{
+                test_result_str = "超标"
+            }
+
+            var selftest_info = new Object
+            var jsontmp = testService.get_selftest_info()
+
+            selftest_info.target = jsontmp.target
+            selftest_info.interval = jsontmp.interval
+            selftest_info.threshold = jsontmp.threshold
+            selftest_info.begin = jsontmp.begin
+            selftest_info.end = jsontmp.end
+            selftest_info.delta = jsontmp.delta
+            selftest_info.passed = jsontmp.pass
+
+            //pagetest.show_selftestDetail(str)
+        }
+
+    }
+
+    function qmlProcessStop(id){
+        if(id === 0){
+            //pagetest.selftestStop()
+            startStopButton.running = false;
+            database_add()
+            tableview_refresh()
+            //console.log("qmlProcessStop pagetest ",id )
+        }
+    }
+
+    function database_add(){
+
+        //var record = new Object
+        //record.target = selftest_info.target
+        //record.interval = selftest_info.interval
+        //record.threshold = selftest_info.threshold
+        //record.begin = selftest_info.begin
+        //record.end = selftest_info.end
+        //record.passed = selftest_info.passed
+
+        var selftest_info = new Object
+        var jsontmp = testService.get_selftest_info()
+
+        selftest_info.target = jsontmp.target
+        selftest_info.interval = jsontmp.interval
+        selftest_info.threshold = jsontmp.threshold
+        selftest_info.begin = jsontmp.begin
+        selftest_info.end = jsontmp.end
+        selftest_info.delta = jsontmp.delta
+        selftest_info.passed = jsontmp.passed
+
+        SelfDB.insertRecord(selftest_info)
+        SelfDB.insertData(allArray)
+
+    }
+
+    function curveDisplay_refresh(date){
+        curveDisplay.spline.clear()
+        pressureCnt =0
+
+        let table_name = 'data_'+date
+        var records = SelfDB.readData(table_name)
+
+        if(records){
+
+            if(records.rows.length > 0){
+                var index = 0
+                while(index < records.rows.length){
+
+                    var item = records.rows.item(index)
+                    curveDisplay_show(item)
+
+                    index++;
+                }
+            }
+
+        }else{
+            console.log("tableview_refresh records is null:" )
+        }
+
+    }
+
+    function tableview_refresh(){
+       selttest_Model.clear()
+       var records = SelfDB.readData("test_table")
+
+       if(records){
+
+           console.log("tableview_refresh records.rows.length:"+records.rows.length )
+
+           if(records.rows.length > 0){
+               var index = records.rows.length-1
+               var tmp_id = 0;
+               while(index >= 0){
+                   var item = records.rows.item(index)
+                   /*
+                   selttest_Model.append({
+                                             "idx":tmp_id,
+                                             "date":item.dt,
+                                             "time":item.time,
+                                             "target":item.target.toString(),
+                                             "interval":item.interval.toString(),
+                                             "threshold":item.threshold.toString(),
+                                             "start":item.begin.toString(),
+                                             "end":item.end.toString(),
+                                             "delta":item.delta.toString(),
+                                             "result":item.passed === 1? "合格":"超标" })
+                   */
+
+                   selttest_Model.append({
+                                             "idx":tmp_id,
+                                             "date":item.dt,
+                                             "time":item.time,
+                                             "target":item.target,
+                                             "interval":item.interval,
+                                             "threshold":item.threshold,
+                                             "start":item.begin,
+                                             "end":item.end,
+                                             "delta":item.delta,
+                                             "result":item.passed === 1? "合格":"超标" })
+                   index--
+                   tmp_id++
+               }
+           }
+
+       }else{
+        console.log("tableview_refresh records is null:" )
+       }
+
+    }
+
+    function qmlProcessReportProgress_self(str){
+
+        console.log("main.qml tservice qmlProcessReportProgress:", str )
+
+        if(str === "close"){
+            genreportprogress_self.exit()
+        }else{
+            genreportprogress_self.show(str)
+        }
+
+    }
+
+    function qmlProcessPressure(id, map){
+        //console.log("main.qml qmlProcessPressure ",id )
+        //log.show2(str)
+        //var textstring = ''
+        //var varmap = map
+        //textstring += map.pressure+":"
+        //textstring += map.direction.toString()+":"
+        //textstring += map.stage.toString()+":"
+        //textstring += map.step.toString()+":"
+
+        //console.log("main.qml qmlProcessPressure :",textstring.toString() )
+        if(id === 0){
+            pressure = map.pressure
+            //pressureDisplayInput(Number(pressure_map.pressure))
+
+            var data = new Object
+            data.step = map.step
+            data.pressure = Number(map.pressure)
+
+            curveDisplay_show(data)
+
+            allArray.push(data)
+        }
+
+    }
+
+    function curveDisplay_show(value){
+        pressureCnt++
+        var number = value.pressure
+
+        m_maxY = (m_maxY < number)? number:m_maxY
+        m_minY = (m_minY > number)? number:m_minY
+
+        curveDisplay.setRange_Y(m_minY-2.0, m_maxY+2.0)
+
+        if(pressureCnt <= 180){
+            curveDisplay.spline.append(pressureCnt-1,number)
+        }
+        else{
+
+            curveDisplay.setRange_X(0, pressureCnt-1)
+            curveDisplay.spline.append(pressureCnt-1,number)
+        }
+
+    }
+
+
+    function cleardata(){
+
+        allArray = []
+        curveDisplay.spline.clear()
+        pressureCnt =0
+
+        pressure = "0.00"
+
+        test_state_str="未开始"
+        test_result_str="未知"
+    }
+
+    function pad_with_zeroes(number, length) {
+        var my_string = '' + number;
+        while (my_string.length < length) {
+            my_string = '0' + my_string;
+        }
+        return my_string;
+    }
+
+    function getWordSaveFileName( para){
+        var date = new Date;
+        var year = date.getFullYear()
+        var month = pad_with_zeroes(date.getMonth()+1,2)
+        var day = pad_with_zeroes(date.getDate(),2)
+        var hour = pad_with_zeroes(date.getHours(),2)
+        var minute = pad_with_zeroes(date.getMinutes(),2)
+        var second = pad_with_zeroes(date.getSeconds(),2)
+
+        var time = year+month+day+hour+minute+second
+        return "file:///"+time+"_"+para
+    }
+
+
+    DynamicGroupBox{
+        id:groupbox_all
+        anchors.centerIn: parent
+        anchors.fill: parent
+
+        title: title_str
+
+        Column{
+            anchors.left: parent.left
+            anchors.leftMargin: 3
+            anchors.top: parent.top
+            anchors.topMargin: 10
+            spacing: 0
+
+            FileDialog {
+                id: saveWordDialog
+                title: "保存为"
+                //nameFilters: [ "Word files (*.doc)"]
+                //nameFilters: [ "Word files (*.doc)", "Text files (*.pdf)"]
+                nameFilters: ["Text files (*.pdf)"]
+                fileMode: FileDialog.SaveFile
+                onAccepted: {
+
+                    var fileName = "D:/tmp/selftest.jpg"
+
+                    rect_display.grabToImage(function(result) {
+                        result.saveToFile(fileName);
+                    });
+
+
+                    var savePath = file.toString().substring(8)
+
+                    console.log("saveWordDialog savePath:")
+                    console.log(savePath)
+
+                    if("null" == report_record_str){
+                        testService.genReport_Self(savePath, "D:/tmp/")
+                    }else{
+                        testService.genReport_Self2(report_record_str, savePath, "D:/tmp/")
+                    }
+
+                    //reportWord.generateBreatheValveWord(savePath,para,obj1,obj2,obj3)
+                   // testService.genReport(savePath, "D:/tmp/")
+                }
+            }
+
+
+
+
+            Row{
+               //x:-10
+                y:-10
+                //width: 900
+                //height: parent.height
+
+               Rectangle{
+                   id:rect_display
+                   //anchors.verticalCenter: parent.verticalCenter
+                   width: 900
+                   height: 460
+
+                   CurveDisplay{
+                       id:curveDisplay
+                       anchors.fill: parent
+
+                       axisxMax:180
+                       axisxMin:0
+                       axisyMax:14
+                       axisyMin:0
+                       name:"横轴时间(秒) 纵轴压力(kPa)"
+                   }
+               }
+
+
+
+               Item {
+                   id:button_root
+                   width: 360
+                   height: 460
+
+                   Column{
+                       id:button_column
+                       spacing: 10
+
+                       Rectangle{
+                           id:buttonWindow
+                           //anchors.fill: parent
+                           width: 350
+                           height: 70
+
+                           color: "white"
+                           radius: 6
+                            border.color: "black"
+
+                           Row{
+                               anchors.verticalCenter: parent.verticalCenter
+                               anchors.horizontalCenter: parent.horizontalCenter
+                               spacing: 50
+
+                               StartStopButton{
+                                   id:startStopButton
+                                   width: 50
+                                   height: 50
+                                   anchors.verticalCenter: parent.verticalCenter
+                                   onRunningChanged: {
+
+                                       if(running){
+                                           //clearCurveDisplay()
+                                           cleardata()
+                                          bStart = testService.tstart(0, 0)
+                                          if(!bStart){
+                                              running=false;
+                                          }
+                                       }else{
+                                           if(bStart){
+                                                testService.tstop(0)
+                                               bStart=false
+                                           }
+                                       }
+
+                                  }
+                               }
+
+                               ReportButton{
+                                   id:reportButton
+                                   width: 50
+                                   height: 50
+                                   anchors.verticalCenter: parent.verticalCenter
+                                   onUserClicked:{
+
+                                       //database_add()
+                                       //tableview_refresh()
+
+
+                                       if(false == startStopButton.running){
+
+                                           //var fileName = "D:/tmp/selftest.jpg"
+
+                                           //rect_display.grabToImage(function(result) {
+                                           //    result.saveToFile(fileName);
+                                           //});
+
+                                           var date = new Date;
+                                           var year = date.getFullYear()
+                                           var month = pad_with_zeroes(date.getMonth()+1,2)
+                                           var day = pad_with_zeroes(date.getDate(),2)
+
+                                           var time = year+month+day
+                                           saveWordDialog.currentFile = "file:///"+time+"_VRST2000"
+
+                                           report_record_str = "null"
+
+                                           saveWordDialog.open()
+                                       }
+
+
+                                   }
+                               }
+
+                               ReturnButton{
+                                    id: return_button
+                                    width: 50
+                                    height: 50
+                                    anchors.verticalCenter: parent.verticalCenter
+                                    onUserClicked: {
+                                        if(false == startStopButton.running){
+                                            selftest_root.destroy()
+                                        }
+                                    }
+                               }
+
+                            }
+
+                        }
+
+                       Rectangle{
+                           id:test_selrect
+                           //anchors.fill: parent
+                           anchors.margins: 10
+                           width: 350
+                           height: 50
+                           color: "white"
+                           radius: 6
+                           border.color: "black"
+                           UserComboBox{
+                              id:test_comboBox
+                              //anchors.fill:parent
+                              implicitWidth:350
+                              implicitHeight:50
+                              bgColor:"#D2D5D9"
+                              model: ["正压系统自测","负压系统自测"]
+                              onCurrentTextChanged: {
+                                  //root.standard_name = currentText
+                                  test_direction = currentIndex
+                                  console.log("choose test direction : "+test_direction)
+
+                              }
+
+                           }
+
+                       }
+
+                       Rectangle{
+                           id:pressureWindow
+                           //anchors.fill: parent
+                           anchors.margins: 10
+                           width: 350
+                           height: 100
+                           color: "white"
+                           radius: 6
+                           border.color: "black"
+
+
+                           Text {
+                               id: pressurekpa
+                               anchors.right: pressureWindow.right
+                               anchors.verticalCenter: parent.verticalCenter
+                               text: qsTr("kPa ")
+                               //font: 40
+                               font.bold: true
+                               font.pixelSize: 35
+
+                           }
+
+                           Rectangle{
+                               id:pressure_rect
+
+                               anchors.verticalCenter: parent.verticalCenter
+                               anchors.right: pressurekpa.left;
+
+                               width: 250
+                               height: 80
+                               LCDNumber{
+                                    id:lcd_pressure
+                                    anchors.centerIn: parent
+                                    text: selftest_root.pressure
+                               }
+                           }
+
+
+                       }
+
+                       Rectangle{
+                           id:resultWindow
+                           //anchors.fill: parent
+                           anchors.margins: 5
+                           width: 350
+                           height: 80
+                           color: "white"
+                           radius: 6
+                           border.color: "black"
+
+                           Column{
+                               anchors.margins: 10
+                               anchors.fill: parent
+                               spacing: 5
+
+                               ResultDisplayText{
+                                   id: result_title
+                                   width: parent.width
+                                   height: 25
+                                   color: "white"
+                                   //paraName_fontColor:"red"
+                                   paraName: "自身密闭性检测:"
+                                   paraResult:""
+                                   paraUnit:""
+                               }
+
+                               ResultDisplayText{
+                                   id:result_dis
+                                   width: parent.width
+                                   height: 25
+                                   color: "#D2D5D9"
+                                   paraName_fontColor:"green"
+                                   paraName: "检测结果:"
+                                   paraResult_fontColor:"#272727"
+                                   paraResult:test_result_str
+                                   paraUnit:""
+                               }
+
+                           }
+
+                         }
+
+                       Rectangle{
+                           id:progressWindow
+                           //anchors.fill: parent
+                           anchors.margins: 5
+                           width: 350
+                           height: 110
+                           color: "white"
+                           radius: 6
+                           border.color: "black"
+
+                           Column{
+                               anchors.margins: 10
+                               anchors.fill: parent
+                               spacing: 5
+
+                               ResultDisplayText{
+                                   id: state_title
+                                   width: parent.width
+                                   height: 25
+                                   color: "white"
+                                   //paraName_fontColor:"red"
+                                   paraName: "检测进度:"
+                                   paraResult:""
+                                   paraUnit:""
+                               }
+
+                               /*
+                               TNormalProgress {
+                                   id:test_progress
+                                   width: parent.width
+                                   backgroundColor: "#D2D5D9"
+                                   //barType: TNormalProgress.BarType.SucceedOrFailed
+
+                                   percent: 100
+                                   //NumberAnimation on percent { from: 0; to: 100; duration: 5000; running: true; loops: Animation.Infinite}
+                               }
+                               */
+
+                               ResultDisplayText{
+                                   id:state_dis
+                                   width: parent.width
+                                   height: 25
+                                   color: "#D2D5D9"
+                                   paraName_fontColor:"green"
+                                   paraName: "检测状态:"
+                                   paraResult_fontColor:"#272727"
+                                   paraResult:test_state_str
+                                   paraUnit:""
+                               }
+
+                           }
+
+
+
+                         }
+
+
+                   }
+
+               }
+
+
+            }
+
+            Rectangle{
+                id:records_rect
+                //x:-10
+                width: 1250
+                height: 240
+                color: "white"
+                radius: 6
+                border.color: "black"
+
+                Text{
+                    id:text_title
+                    anchors.top: parent.top
+                    anchors.topMargin: 10
+                    anchors.horizontalCenter: parent.horizontalCenter
+                    font.bold: true
+                    font.pixelSize: 24
+                    text: "系统自测历史记录"
+
+                }
+
+                Component{
+                            id:itemDelegateText
+                            Text {
+                                anchors.verticalCenter: parent.verticalCenter
+                                color: styleData.selected?"#1E90FF":"#000000"
+                                elide: styleData.elideMode
+                                text: styleData.value
+                                font.pointSize: 10
+                                //font.pixelSize: 24
+                                //font.bold: true
+                                horizontalAlignment: Text.AlignHCenter
+                                verticalAlignment: Text.AlignVCenter
+                                anchors.fill: parent
+                            }
+                        }
+
+                Component{
+                            id:itemDelegateButton
+                            Row{
+                                anchors.fill: parent
+                                anchors.centerIn: parent
+                                spacing: 10
+
+                                Button {
+                                    anchors.verticalCenter: parent.verticalCenter
+                                    //color: styleData.selected?"#1E90FF":"#000000"
+                                    //elide: styleData.elideMode
+                                    //anchors.centerIn: parent
+                                    text: "报告"
+                                    width: 60
+                                    onClicked: {
+
+                                        console.log("index ==="+styleData.row);
+                                        console.log("tableView.currentRow ==="+tableView.currentRow);
+                                        console.log("select date:"+selttest_Model.get(styleData.row).date);
+
+                                        var today = new Date(selttest_Model.get(styleData.row).date);
+                                        var DD = String(today.getDate()).padStart(2, '0'); // 获取日
+                                        var MM = String(today.getMonth()+1).padStart(2, '0'); //获取月份,1 月为 0
+                                        var yyyy = today.getFullYear(); // 获取年
+
+                                        let date = yyyy + MM  + DD;
+                                        curveDisplay_refresh(date)
+
+                                        //var fileName = "D:/tmp/selftest.jpg"
+
+                                        //rect_display.grabToImage(function(result) {
+                                        //    result.saveToFile(fileName);
+                                        //});
+
+
+
+                                        //生成测试结果 JSON 字符串
+                                        var recordJson={}
+
+                                        recordJson.target = Number(selttest_Model.get(styleData.row).target)
+                                        recordJson.interval = Number(selttest_Model.get(styleData.row).interval)
+                                        recordJson.threshold = Number(selttest_Model.get(styleData.row).threshold)
+                                        recordJson.begin = Number(selttest_Model.get(styleData.row).start)
+                                        recordJson.end = Number(selttest_Model.get(styleData.row).end)
+                                        recordJson.delta = Number(selttest_Model.get(styleData.row).delta)
+
+                                        if("合格" === selttest_Model.get(styleData.row).result){
+                                            recordJson.passed = 1
+                                        }else{
+                                            recordJson.passed = 0
+                                        }
+
+
+                                        report_record_str = JSON.stringify(recordJson)
+
+                                        saveWordDialog.currentFile = "file:///"+date+"_VRST2000"
+                                        saveWordDialog.open()
+
+
+                                    }
+                                }
+
+                                Button {
+                                    anchors.verticalCenter: parent.verticalCenter
+                                    //color: styleData.selected?"#1E90FF":"#000000"
+                                    //elide: styleData.elideMode
+                                    //anchors.centerIn: parent
+                                    text: "删除"
+                                    width: 60
+
+                                    onClicked: {
+
+                                        //curveDisplay.spline.clear()
+                                       // pressureCnt =0
+
+                                        SelfDB.deleteRecord(selttest_Model.get(styleData.row).date)
+                                        tableview_refresh()
+
+                                    }
+                                }
+
+                            }
+
+                        }
+
+                TableView{
+                    id:tableView
+                    //frameVisible: true
+                    width: parent.width
+                    focus: true
+                    //height: parent.height - 50
+                    anchors.top: text_title.bottom
+                    anchors.bottom: parent.bottom
+                    anchors.topMargin: 10
+
+                    TableViewColumn{role: "idx"; title: "ID"; width: 40;delegate: itemDelegateText}
+                    TableViewColumn{role: "date"; title: "自检日期"; width: 120;delegate: itemDelegateText}
+                    TableViewColumn{role: "time"; title: "完成时间"; width: 120;delegate: itemDelegateText}
+                    TableViewColumn{role: "target"; title: "目标压力(Kpa)"; width: 120;delegate: itemDelegateText}
+                    TableViewColumn{role: "interval"; title: "检测时间(秒)"; width: 120;delegate: itemDelegateText}
+                    TableViewColumn{role: "threshold"; title: "变化限值(Kpa)"; width: 120;delegate: itemDelegateText}
+                    TableViewColumn{role: "start"; title: "开始压力(Kpa)"; width: 120;delegate: itemDelegateText}
+                    TableViewColumn{role: "end"; title: "结束压力(Kpa)"; width: 120;delegate: itemDelegateText}
+                    TableViewColumn{role: "delta"; title: "压力变化(Kpa)"; width: 120;delegate: itemDelegateText}
+                    TableViewColumn{role: "result"; title: "自测结果"; width: 80;delegate: itemDelegateText}
+                    TableViewColumn{role: "detail"; title: "操作"; width: 130;delegate: itemDelegateButton}
+
+                    //model: modelItems
+
+                    headerDelegate: Rectangle{
+                        implicitWidth: 16
+                        implicitHeight: 24
+
+                        gradient: styleData.pressed ? selftest_root.pressG : (styleData.containsMouse ? selftest_root.hoverG: selftest_root.normalG)
+
+                        border.color: "gray"
+                        border.width: 1
+                        Text{
+                            anchors.verticalCenter: parent.verticalCenter
+                            anchors.left: parent.left
+                            anchors.leftMargin: 4
+                            anchors.right: parent.right
+                            anchors.rightMargin: 4
+                            text: styleData.value
+                            color: styleData.pressed ?"red" : "blue"
+                            horizontalAlignment: Text.AlignHCenter
+                            verticalAlignment: Text.AlignVCenter
+                            font.bold: true
+                        }
+                    }
+                    rowDelegate: Rectangle{
+                        height: 28
+                        //border.color: "gray"
+                        //color: styleData.selected?"#f0b0b0af":(styleData.alternate?"#c3c3c0":"#c0c0c3")
+                        color: styleData.selected ? selftest_root.highlight : selftest_root.alterBackground
+
+                    }
+
+                    itemDelegate: Rectangle {
+                        height: 24
+                        //border.color: "gray"
+                        color: "transparent"
+                        Text {
+                            //anchors.centerIn: parent
+                            //anchors.left: parent.left
+                            anchors.leftMargin: 6
+                            anchors.verticalCenter: parent.verticalCenter
+                            //color: styleData.textColor
+                            color: styleData.selected ? "red" : styleData.textColor
+                            text: styleData.value
+                            verticalAlignment: Text.AlignVCenter
+                            font.pointSize: 13
+                        }
+                    }
+
+                    onClicked:{
+                        console.log("onClicked index ==="+ row);
+                        console.log("select date:"+selttest_Model.get(row).date);
+
+                        var today = new Date(selttest_Model.get(row).date);
+                        var DD = String(today.getDate()).padStart(2, '0'); // 获取日
+                        var MM = String(today.getMonth()+1).padStart(2, '0'); //获取月份,1 月为 0
+                        var yyyy = today.getFullYear(); // 获取年
+
+                        let date = yyyy + MM  + DD;
+                        curveDisplay_refresh(date)
+
+                    }
+
+
+                    model:ListModel{
+                         id: selttest_Model
+                    }
+                }
+
+
+            }
+
+        }
+
+
+
+    }
+
+    Log{
+        id:genreportprogress_self
+        z:30
+        width: 300
+        height: 50
+        //anchors.centerIn: parent
+        anchors.top: parent.top
+        anchors.topMargin: 100
+        anchors.left: parent.left
+        anchors.leftMargin: 480
+    }
+
+    Component.onCompleted: {
+
+        testService.sigPressure.connect(qmlProcessPressure);
+
+        testService.sigState.connect(qmlProcessState);
+        //testService.sigSystemResult.connect(qmlProcessSystemResult);
+        //testService.sigValveResult.connect(qmlProcessValveResult);
+        testService.sigSelfTestResult.connect(qmlProcessResult);
+        testService.onGenreportProgress.connect(qmlProcessReportProgress_self);
+
+        testService.sigStop.connect(qmlProcessStop);
+
+        SelfDB.initDatabase()
+
+        tableview_refresh()
+
+    }
+}
+
+/*##^##
+Designer {
+    D{i:0;autoSize:true;height:480;width:640}
+}
+##^##*/

+ 26 - 25
PageSetting.qml

@@ -23,31 +23,6 @@ Item{
     property var volume_arry: [0,0,0,0,0,0,0,0]
 
 
-
-/*
-    Loader{
-        id:loader
-        anchors.fill: parent
-        anchors.margins: 0
-        sourceComponent: componet
-    }
-    */
-
-/*
-    function show(){
-        if(loader.sourceComponent  === null){
-            loader.sourceComponent  = componet
-            console.debug("avans 1111")
-        }
-        loader.item.show()
-    }
-
-    function exit(){
-        if(loader.sourceComponent  !== null){
-            loader.item.exit()
-        }
-    }
-*/
     function update_standard(){
         var jsonObj = StandardManager.get_names();
 
@@ -180,6 +155,7 @@ Item{
     }
 
 
+
    // Component{
     //    id:componet
         DynamicGroupBox{
@@ -650,6 +626,31 @@ Item{
                         onClicked: myLoder.sourceComponent = null // 切换显示主页面
                     }
 
+                    UserButton {
+                        id: self_test
+                        text: "系统自测"
+                        height: 60
+                        width: 160
+                        font.pixelSize: 24
+                        anchors.left: prev_step.right;
+                        anchors.leftMargin: 40;
+                        anchors.bottom: parent.bottom;
+                        anchors.bottomMargin: 10;
+
+                        onClicked:{
+                            //var varPage = Qt.createComponent("PageLeakageInput.qml")
+                            //            .createObject(main_window, {x:0, y:0, width:main_window.width/2, height:main_window.height/2});
+
+                            var compMainPage = Qt.createComponent("PageSelfTest.qml")
+                                        .createObject(main_window, {x:0, y:0, width:main_window.width, height:main_window.height});
+
+
+                            //popupCenter.raiseItem = com_leakage
+                            //popupCenter.open()
+
+                        }
+                    }
+
                     UserButton {
 
                         id: next_step;

+ 10 - 8
PageTest.qml

@@ -280,11 +280,16 @@ Item{
 
 
                 Row{
+                    //anchors.fill: parent
+                    //anchors.verticalCenter: parent.verticalCenter
+
                     anchors.verticalCenter: parent.verticalCenter
-                    anchors.left: parent.left
+                    //anchors.left: parent.left
+                    layoutDirection: Qt.LeftToRight
 
                     spacing: 20
 
+
                     Timer {
                         id: timer;
                         interval: 1000;//设置定时器定时时间为500ms,默认1000ms
@@ -298,12 +303,11 @@ Item{
 
                     }
 
-
                     UserButton {
                     id: readbutton;
                     text: "开始";
                     font.pixelSize: 20
-                    anchors.verticalCenter: parent.verticalCenter
+                    //anchors.verticalCenter: parent.verticalCenter
 
                     implicitWidth: 120
                     implicitHeight: 45
@@ -335,7 +339,7 @@ Item{
                     Rectangle{
                         id:pressureWindow
                         //anchors.fill: parent
-                        anchors.verticalCenter: parent.verticalCenter
+                        //anchors.verticalCenter: parent.verticalCenter
                         width: 120
                         height: 40
                         //color: "white"
@@ -349,13 +353,11 @@ Item{
                              fontsize: 40
                         }
 
-
-
                     }
 
                     Text {
                         id: kpa
-                        anchors.left: lcd_pressure.right
+                        //anchors.left: pressureWindow.right
                         anchors.verticalCenter: parent.verticalCenter
                         text: qsTr("kPa")
                         //font: 40
@@ -367,7 +369,7 @@ Item{
                     id: zerobutton;
                     text: "传感器标零";
                     font.pixelSize: 20
-                    anchors.verticalCenter: parent.verticalCenter
+                    //anchors.verticalCenter: parent.verticalCenter
 
                     implicitWidth: 120
                     implicitHeight: 45

+ 32 - 36
RecoveryValve.qml

@@ -259,46 +259,12 @@ Item{
 
 */
 
-            //报告
-            Connections{
-                target: reportButton
-                onUserClicked:{
-
-                    //if(allArray.length > 0){
-                        //console.log("allTestGeneratePicture")
-                        //groupbox.allTestGeneratePicture()
-                   // }
-
-                    //if(syskpArray.length > 0){
-                        //console.log("sysTestGeneratePicture")
-                        //groupbox.sysTestGeneratePicture()
-                   // }
-
-                   // if(valvekpArray.length > 0){
-                   //     console.log("valveTestGeneratePicture")
-                   //     groupbox.valveTestGeneratePicture()
-                   // }
-
-
-                    //testService.reportpic_Ready(compartment_id);
-
-                    if(testService.check_alltest_ok()){
-                        var fileName = root.carplate
-                        var text = getWordSaveFileName(fileName)
-                        console.log(text)
-
-                        saveWordDialog.currentFile = getWordSaveFileName(fileName)
-                        saveWordDialog.open()
-                    }
-
-                }
-            }
-
             FileDialog {
                 id: saveWordDialog
                 title: "保存为"
                 //nameFilters: [ "Word files (*.doc)"]
-                nameFilters: [ "Word files (*.doc)", "Text files (*.pdf)"]
+                //nameFilters: [ "Word files (*.doc)", "Text files (*.pdf)"]
+                nameFilters: ["Text files (*.pdf)"]
                 fileMode: FileDialog.SaveFile
                 onAccepted: {
                     var savePath = file.toString().substring(8)
@@ -389,6 +355,36 @@ Item{
                                        width: 50
                                        height: 50
                                        anchors.verticalCenter: parent.verticalCenter
+                                       onUserClicked:{
+
+                                           //if(allArray.length > 0){
+                                               //console.log("allTestGeneratePicture")
+                                               //groupbox.allTestGeneratePicture()
+                                          // }
+
+                                           //if(syskpArray.length > 0){
+                                               //console.log("sysTestGeneratePicture")
+                                               //groupbox.sysTestGeneratePicture()
+                                          // }
+
+                                          // if(valvekpArray.length > 0){
+                                          //     console.log("valveTestGeneratePicture")
+                                          //     groupbox.valveTestGeneratePicture()
+                                          // }
+
+
+                                           //testService.reportpic_Ready(compartment_id);
+
+                                           if(testService.check_alltest_ok(1)){
+                                               var fileName = root.carplate
+                                               var text = getWordSaveFileName(fileName)
+                                               console.log(text)
+
+                                               saveWordDialog.currentFile = getWordSaveFileName(fileName)
+                                               saveWordDialog.open()
+                                           }
+
+                                       }
                                    }
 
                                 }

+ 22 - 0
ReturnButton.qml

@@ -0,0 +1,22 @@
+import QtQuick 2.11
+
+Item {
+    signal userClicked
+    Image {
+        id:image
+        anchors.fill: parent
+        source: "qrc:/img/return.png"
+        MouseArea{
+            anchors.fill: parent
+            onPressed: {
+                image.opacity = 0.5
+            }
+            onReleased: {
+                image.opacity = 1.0
+            }
+            onClicked: {
+                userClicked()
+            }
+        }
+    }
+}

+ 102 - 0
TNormalProgress.qml

@@ -0,0 +1,102 @@
+//NormalProgressBar.qml
+
+import QtQuick 2.12
+import QtQuick.Controls 2.12
+Item {
+    id: r
+    property int percent: 0
+    implicitWidth: 200
+    implicitHeight: 16
+    //枚举, 表示右侧Bar的类型
+    enum BarType {
+        Text,               //右侧放文本
+        SucceedOrFailed,    //右侧放图片表示成功和失败,没有100%就是失败
+        NoBar               //右侧不放东西
+    }
+    //只读属性,内置一些颜色
+    readonly property color __backColor: "#f5f5f5"
+    readonly property color __blueColor: "#1890ff"
+    readonly property color __succeedColor: "#52c41a"
+    readonly property color __failedColor: "#f5222d"
+
+    //背景色,默认值
+    property color backgroundColor: __backColor
+    //前景色
+    property color frontColor: {
+        switch (barType) {
+        case TNormalProgress.BarType.SucceedOrFailed:
+            return percent === 100 ? __succeedColor : __failedColor
+        default:
+            return __blueColor
+        }
+    }
+    //文字
+    property string text: String("%1%").arg(percent)
+    //渐变 0-180 除掉不能用的,165种渐变任你选
+    property int gradientIndex: -1
+    //闪烁特效
+    property bool flicker: false
+    //右侧Bar类型
+    property var barType: TNormalProgress.BarType.Text
+    Text {
+        id: t
+        enabled: barType === TNormalProgress.BarType.Text
+        visible: enabled
+        text: r.text
+        anchors.verticalCenter: parent.verticalCenter
+        anchors.right: parent.right
+    }
+    Image {
+        id: image
+        source: percent === 100 ? "qrc:/img/ok_circle.png" : "qrc:/img/fail_circle.png"
+        height: parent.height
+        width: height
+        enabled: barType === TNormalProgress.BarType.SucceedOrFailed
+        visible: enabled
+        anchors.right: parent.right
+    }
+
+    property var __right: {
+        switch (barType) {
+        case TNormalProgress.BarType.Text:
+            return t.left
+        case TNormalProgress.BarType.SucceedOrFailed:
+            return image.left
+        default:
+            return r.right
+        }
+    }
+    Rectangle {                             //背景
+        id: back
+        anchors.left: parent.left
+        anchors.right: __right
+        anchors.rightMargin: 4
+        height: parent.height
+        radius: height / 2
+        color: backgroundColor
+        Rectangle {                         //前景
+            id: front
+            width: percent / 100 * parent.width
+            height: parent.height
+            radius: parent.radius
+            color: frontColor
+            gradient: gradientIndex === -1 ? null : gradientIndex
+            Rectangle {                     //前景上的闪光特效
+                id: flick
+                height: parent.height
+                width: 0
+                radius: parent.radius
+                color: Qt.lighter(parent.color, 1.2)
+                enabled: flicker
+                visible: enabled
+                NumberAnimation on width {
+                    running: visible
+                    from: 0
+                    to: front.width
+                    duration: 1000
+                    loops: Animation.Infinite;
+                }
+            }
+        }
+    }
+}

+ 191 - 89
TestService.cpp

@@ -35,10 +35,8 @@ TestService::TestService(QThread *parent)
         m_tank.m_comparts[i].m_id = i;
     }
 
-    //moveToThread(&m_Thread);
-    //connect(this, SIGNAL(operate()), this, SLOT(doTest()));
-
 }
+
 TestService::~TestService()
 {
 
@@ -299,7 +297,7 @@ bool TestService::reportpic_Ready(int compartmentid)
     return true;
 }
 
-bool TestService::check_alltest_ok()
+bool TestService::check_alltest_ok(int with_tips)
 {
     bool ret_flag = true;
     for(int i=0; i< m_tank.compartment_num; i++){
@@ -310,7 +308,7 @@ bool TestService::check_alltest_ok()
         }
     }
 
-    if(false == ret_flag){
+    if((false == ret_flag) && (1 == with_tips)){
         QMessageBox::StandardButton result = QMessageBox::question(NULL, "提示:", "有油仓还未进行检测,是否强制生成报告?", QMessageBox::Yes|QMessageBox::No, QMessageBox::No);
 
         switch (result)
@@ -351,6 +349,38 @@ bool TestService::genReport(QString word_path, QString pic_dir)
     return ret;
 }
 
+bool TestService::genReport_Self(QString word_path, QString pic_dir)
+{
+    bool ret = false;
+
+    if(word_path.contains(".doc") || word_path.contains(".pdf") ){
+        m_report.makeReport_Self(m_devinfo, word_path, pic_dir);
+    }else{
+        QString str = "word_path invalid!";
+        qDebug() << str;
+    }
+
+    return ret;
+}
+
+bool TestService::genReport_Self2(const QString& jsonStr, QString word_path, QString pic_dir)
+{
+    bool ret = false;
+
+    if(word_path.contains(".doc") || word_path.contains(".pdf") ){
+
+        qDebug() << "genReport_Self2 jsonStr:" << jsonStr;
+        m_devinfo2.update_testinfo(jsonStr);
+        m_report.makeReport_Self(m_devinfo2, word_path, pic_dir);
+
+    }else{
+        QString str = "word_path invalid!";
+        qDebug() << str;
+    }
+
+    return ret;
+}
+
 QJsonObject TestService::get_vrs_items()
 {
     return m_tank.get_vrs_items();
@@ -366,8 +396,28 @@ bool TestService::set_item_result(const QString& jsonStr )
     return m_tank.set_item_result(jsonStr);
 }
 
+bool TestService::set_leakage_value(const QString& jsonStr)
+{
+    return m_tank.set_leakage_value(jsonStr);
+}
+
+QJsonObject TestService::get_selftest_info()
+{
+    QJsonObject rootObj;
+
+    rootObj.insert("target", m_devinfo.m_testinfo.m_target);
+    rootObj.insert("interval", m_devinfo.m_testinfo.m_interval);
+    rootObj.insert("threshold", m_devinfo.m_testinfo.m_threshold);
+    rootObj.insert("begin", m_devinfo.m_testinfo.m_begin);
+    rootObj.insert("end", m_devinfo.m_testinfo.m_end);
+    rootObj.insert("delta", m_devinfo.m_testinfo.m_delta);
+    rootObj.insert("passed", m_devinfo.m_testinfo.m_passed);
+
+    return rootObj;
+}
 
-void TestService::push_pressurelist(float pressure)
+
+void TestService::push_pressurelist(double pressure)
 {
     m_pressuremutex.lock();
 
@@ -384,16 +434,16 @@ void TestService::clear_pressurelist()
     m_pressuremutex.unlock();
 }
 
-float TestService::calculate_averagepressure()
+double TestService::calculate_averagepressure()
 {
-    float average = 0.0;
+    double average = 0.0;
 
     m_pressuremutex.lock();
     int n = m_pressurelist.size();
 
     if(n>0){
 
-        float sum = 0.0;
+        double sum = 0.0;
         for(int i=0; i<n; i++){
             sum += m_pressurelist.at(i);
             //qDebug("push_pressurelist 333 size[%f]", m_pressurelist.at(i));
@@ -433,6 +483,7 @@ bool TestService::valve_close(Valve_ID id)
 QString TestService::read_PressureValue()
 {
     float pressure = 0.0;
+    double d_pressure = 0.0;
     static int timeout_count =0;
 
     PressureSensor ps(&m_SerialUi4);
@@ -454,9 +505,9 @@ QString TestService::read_PressureValue()
 
     int _ipressure = pressure*1000;
     _ipressure = (_ipressure/PRESSURE_DIVISION_VALUE)*PRESSURE_DIVISION_VALUE;
-    pressure = _ipressure/1000.0;
+    d_pressure = _ipressure/1000.0;
 
-    QString pressure_str = QString("%1").arg(pressure, 4,'f',2,QLatin1Char('0'));
+    QString pressure_str = QString("%1").arg(d_pressure, 4,'f',2,QLatin1Char('0'));
     return pressure_str;
 
 }
@@ -540,6 +591,18 @@ void TestService::OnTimer1()
 
     PressureSensor ps(&m_SerialUi4);
     if(ps.Read(pressure)){
+        if(m_direction == Test_Direction_Positive){
+            //正压检测,不允许出现负值
+            if(pressure < 0.0){
+                pressure = 0.0;
+            }
+        }else {
+            // 负压检测,不允许出现正值
+            if(pressure > 0.0){
+                pressure = 0.0;
+            }
+
+        }
 
         push_pressurelist(pressure);
         timeout_count=0;
@@ -560,12 +623,13 @@ void TestService::OnTimer1()
     if(0 == times_count%2){
 
         int _ipressure = 0;
+        double d_pressure = 0.00;
 
         _ipressure = pressure*1000;
         _ipressure = (_ipressure/PRESSURE_DIVISION_VALUE)*PRESSURE_DIVISION_VALUE;
-        pressure = _ipressure/1000.0;
+        d_pressure = _ipressure/1000.0;
 
-        QString pressure_str = QString("%1").arg(pressure, 4,'f',2,QLatin1Char('0'));
+        QString pressure_str = QString("%1").arg(d_pressure, 4,'f',2,QLatin1Char('0'));
 
         PressureItem item;
         //item.m_pressure = pressure_str;
@@ -614,8 +678,8 @@ Ret_Value  TestService::PositivePressure_Add(const TestExpect& expect, bool bSav
 
    QElapsedTimer  timer;
    timer.start();
-   float prev_pressure = 0;
-   float current_pressure = 0;
+   double prev_pressure = 0;
+   double current_pressure = 0;
 
    double current_speed = 0;
    unsigned char bvstatus;
@@ -651,7 +715,7 @@ Ret_Value  TestService::PositivePressure_Add(const TestExpect& expect, bool bSav
 
    Valve in_v(&m_SerialUi3, VALVE_INTAKE);
    bool bOpen_intake = false;
-   //bOpen_intake = in_v.Open();
+   bOpen_intake = in_v.Open();
 
    //
    QDateTime datetime = QDateTime::currentDateTime();
@@ -688,6 +752,11 @@ Ret_Value  TestService::PositivePressure_Add(const TestExpect& expect, bool bSav
                       bv.SetPosition(bvoffset);
                 }
             }
+
+            //
+            if(true == bv_ready){
+                pPIDinner->reset();
+            }
         }else{
 
             current_pressure = calculate_averagepressure();
@@ -902,7 +971,7 @@ Ret_Value  TestService::PositivePressure_Add_V2(const TestExpect& expect)
 
    QElapsedTimer  timer;
    timer.start();
-   float current_pressure = 0;
+   double current_pressure = 0;
    unsigned char bvstatus;
    unsigned short bvposition;
    unsigned short bvoffset = 120;
@@ -1059,6 +1128,8 @@ Ret_Value  TestService::PositivePressure_Add_V2(const TestExpect& expect)
 
 }
 
+
+//将打开泄压阀,等待压力归零 (小于 0.01Kpa )。
 Ret_Value  TestService::Pressure_Relief(const TestExpect& expect)
 {
     Ret_Value ret_v = Ret_OK;
@@ -1094,7 +1165,7 @@ Ret_Value  TestService::Pressure_Relief(const TestExpect& expect)
             last_pressure = current_pressure;
         }
 
-        if((count > 20) ||(current_pressure < 0.01)){
+        if((count > 20) ||(fabs(current_pressure) < 0.01)){
             //关闭泄压阀
             vent_v.Close();
              break;
@@ -1178,15 +1249,18 @@ Ret_Value  TestService::Pressure_Relief()
 }
 
 
-Ret_Value  TestService::Pressure_Keep(int keeptime, float& start_value, float& end_value)
+Ret_Value  TestService::Pressure_Keep(int keeptime, double& start_value, double& end_value)
 {
     int count = 0;
 
     Ret_Value ret_v = Ret_OK;
 
     start_value = calculate_averagepressure();
-    int _ipressure = start_value*100;
-    start_value = _ipressure/100.0;
+
+    int _ipressure = start_value*1000;
+    _ipressure = (_ipressure/PRESSURE_DIVISION_VALUE)*PRESSURE_DIVISION_VALUE;
+    start_value = _ipressure/1000.0;
+
 
     while((count < keeptime) && m_bRunning){
        QThread::msleep(1000);
@@ -1195,8 +1269,9 @@ Ret_Value  TestService::Pressure_Keep(int keeptime, float& start_value, float& e
 
     end_value = calculate_averagepressure();
 
-    _ipressure = end_value*100;
-    end_value = _ipressure/100.0;
+    _ipressure = end_value*1000;
+    _ipressure = (_ipressure/PRESSURE_DIVISION_VALUE)*PRESSURE_DIVISION_VALUE;
+    end_value = _ipressure/1000.0;
 
 
     if(!m_bRunning){
@@ -1419,9 +1494,9 @@ void TestService::run()
                         //bool bPassed = true;
 
                         // 检测 5分钟都没超限,就是通过了
-                        float delta = 0;
-                        float start_value = 0.0;
-                        float end_value = 0.0;
+                        double delta = 0;
+                        double start_value = 0.0;
+                        double end_value = 0.0;
                         bool bPassed = true;
 
                         //ret_v = Pressure_Keep2(5*60, start_value, end_value);
@@ -1534,7 +1609,7 @@ void TestService::run()
 
                         texpect.volume = 0;
                         texpect.target = 0.0;
-                        texpect.timeout = 60;//m_tank.m_comparts[m_compartmentid].get_adjust_timeout();
+                        texpect.timeout = 90;//m_tank.m_comparts[m_compartmentid].get_adjust_timeout();
                         ret_v = Pressure_Relief(texpect);
                         if(Ret_Exit == ret_v){
                             bQuit = true;
@@ -1580,6 +1655,38 @@ void TestService::run()
 
             }
 
+            if(Test_Step_End == m_step){
+                ret_btn = m_msgbox.information(NULL, "提示:", "检测结束,是否要泄压? 此过程可能需要很长时间", QMessageBox::Yes|QMessageBox::No, QMessageBox::Yes);
+            }else{
+
+                ret_btn = QMessageBox::NoButton;
+                if(true == bQuit){
+                    ret_btn = m_msgbox.information(NULL, "提示:", "程序即将退出,是否要泄压? 此过程可能需要很长时间", QMessageBox::Yes|QMessageBox::No, QMessageBox::Yes);
+                }
+            }
+
+            switch (ret_btn)
+            {
+            case QMessageBox::Yes:
+                if(m_step == Test_Step_reliefPressure){
+                    m_msgbox.information(NULL, "提示:", "即将对罐仓内压力进行泄放,请确认已打开油气回收阀", QMessageBox::Yes, QMessageBox::Yes);
+                }
+                Pressure_Relief();
+                break;
+            default:
+                break;
+            }
+
+
+            if((true == m_tank.m_comparts[m_compartmentid].m_result.sys_test_finished))
+                    //&& (true == m_tank.m_comparts[m_compartmentid].m_result.valve_test_finished))
+            {
+                m_tank.m_comparts[m_compartmentid].m_testfinished = true;
+            }
+
+            emit sigStop(m_compartmentid+1);
+
+
 
         }else{
             //负压测试, 暂不支持
@@ -1625,8 +1732,8 @@ void TestService::run()
                              QThread::msleep(2000);
 
                              texpect.volume = 0;
-                             texpect.target = 4.50;
-                             texpect.timeout = 5*60; //3分钟
+                             texpect.target = m_devinfo.m_testinfo.m_target;
+                             texpect.timeout = 5*60; //5分钟
                              ret_v = PositivePressure_Add(texpect);
 
                              if(Ret_Exit == ret_v){
@@ -1636,27 +1743,24 @@ void TestService::run()
                              }else{
 
                                  ret_btn = QMessageBox::NoButton;
-                                if(Ret_Timeout == ret_v){
-                                    notice_str = "正压加压超时, 是否重试?";
-                                    ret_btn = m_msgbox.information(NULL, "提示:", notice_str, QMessageBox::Retry|QMessageBox::Abort,  QMessageBox::Retry);
-                                }else{
-                                    notice_str = "继电器通信失败, 程序终止";
-                                    ret_btn = m_msgbox.information(NULL, "提示:", notice_str, QMessageBox::Ok,  QMessageBox::Ok);
-                                }
-
-                                switch (ret_btn)
-                                {
-                                case QMessageBox::Retry:
-                                    break;
-                                case QMessageBox::Abort:
-                                    bQuit = true;
-                                    break;
-                                case QMessageBox::Ok:
-                                    bQuit = true;
-                                    break;
-                                default:
-                                    break;
-                                }
+                                 ret_btn = make_messagebox(m_direction, m_step, ret_v);
+                                 switch (ret_btn)
+                                 {
+                                 case QMessageBox::Retry:
+                                     qDebug()<<"Retry";
+
+                                     break;
+                                 case QMessageBox::Abort:
+                                     qDebug()<<"Abort";
+                                     bQuit = true;
+                                     break;
+                                 case QMessageBox::Ok:
+                                     qDebug()<<"OK";
+                                     bQuit = true;
+                                     break;
+                                 default:
+                                     break;
+                                 }
 
                              }
 
@@ -1667,24 +1771,34 @@ void TestService::run()
                              emit sigState(m_compartmentid+1, "保压", "");
 
                              // 检测 5分钟都没超限,就是通过了
-                             float delta = 0;
-                             float start_value = 0.0;
-                             float end_value = 0.0;
+                             double delta = 0;
+                             double start_value = 0.0;
+                             double end_value = 0.0;
                              bool bPassed = true;
 
-                             ret_v = Pressure_Keep(5*60, start_value, end_value);
+                             ret_v = Pressure_Keep(m_devinfo.m_testinfo.m_interval, start_value, end_value);
 
                              if(Ret_Exit == ret_v){
                                 bQuit = true;
                              }else {
 
+                                 m_devinfo.m_testinfo.m_begin = start_value;
+                                 m_devinfo.m_testinfo.m_end = end_value;
+
                                  delta = start_value - end_value;
-                                 if(delta <= 0.5){
+
+                                 if(delta <= m_devinfo.m_testinfo.m_threshold){
                                     bPassed = true;
                                  }else{
                                     bPassed = false;
                                  }
 
+                                // m_devinfo.m_testinfo.m_delta = delta;
+                                 int i_delta = delta*1000;
+                                 i_delta = (i_delta/PRESSURE_DIVISION_VALUE)*PRESSURE_DIVISION_VALUE;
+                                 m_devinfo.m_testinfo.m_delta  = i_delta/1000.0;
+                                 m_devinfo.m_testinfo.m_passed = (bPassed == true?1:0);
+
                                  //QString delta_str = QString("%1").arg(delta, 4,'f',2,QLatin1Char('0'));
                                  QString info_str = "初始压力:";
                                  info_str +=  QString("%1").arg(start_value, 4,'f',2,QLatin1Char('0'));
@@ -1712,12 +1826,7 @@ void TestService::run()
                               case QMessageBox::Yes:
                                   qDebug()<<"Yes";
                                   {
-                                      TestExpect expect;
-                                      expect.target = 0.0;
-                                      expect.volume = 0;
-                                      expect.timeout = 30;
-
-                                      ret_v = Pressure_Relief(expect);
+                                      ret_v = Pressure_Relief();
                                       if(Ret_Exit == ret_v){
                                          bQuit = true;
                                       }
@@ -1739,44 +1848,37 @@ void TestService::run()
 
              }
 
-        }else{ //negtive
+             if(Test_Step_End == m_step){
+                 ret_btn = QMessageBox::NoButton;
+             }else{
 
-        }
+                 ret_btn = QMessageBox::NoButton;
+                 if(true == bQuit){
+                     ret_btn = m_msgbox.information(NULL, "提示:", "程序即将退出,是否要泄压?", QMessageBox::Yes|QMessageBox::No, QMessageBox::Yes);
+                 }
 
-    }
+                 switch (ret_btn)
+                 {
+                 case QMessageBox::Yes:
+                     Pressure_Relief();
+                     break;
+                 default:
+                     break;
+                 }
 
-    if(Test_Step_End == m_step){
-        ret_btn = QMessageBox::NoButton;
-    }else{
-        if(true == bQuit){
-            if(Ret_Exit == ret_v){ // 主动退出
-                ret_btn = m_msgbox.information(NULL, "提示:", "程序退出,是否要泄压?", QMessageBox::Yes|QMessageBox::No, QMessageBox::Yes);
-            }else if(Ret_Timeout == ret_v){  // 超时退出
-                ret_btn = m_msgbox.information(NULL, "提示:", "程序超时退出,是否要泄压?", QMessageBox::Yes|QMessageBox::No, QMessageBox::Yes);
-            }else{//通信错误退出
-                ret_btn = m_msgbox.information(NULL, "提示:", "程序通信错误退出,是否要泄压?", QMessageBox::Yes|QMessageBox::No, QMessageBox::Yes);
-            }
-        }
+             }
 
-    }
 
 
-    switch (ret_btn)
-    {
-    case QMessageBox::Yes:
-        Pressure_Relief();
-        break;
-    default:
-        break;
+        }else{ //negtive
+
+        }
+
     }
 
+
     if(m_bRunning){
         m_bRunning = false;
-        if(m_compartmentid >= 0){ //不是系统自测
-            if(true == m_tank.m_comparts[m_compartmentid].m_result.sys_test_finished){
-                m_tank.m_comparts[m_compartmentid].m_testfinished = true;
-            }
-        }
         emit sigStop(m_compartmentid+1);
     }
 

+ 13 - 5
TestService.h

@@ -13,6 +13,7 @@
 #include <QDebug>
 //#include"Standard.h"
 #include "tank.h"
+#include "Deviceinfo.h"
 #include "report.h"
 #include"Msgbox.h"
 #include"serialui.h"
@@ -56,7 +57,6 @@ enum Test_Direction{
     Test_Direction_Unkown,
 };
 
-
 class TestExpect{
 public:
     int volume;
@@ -95,13 +95,18 @@ public:
     Q_INVOKABLE bool tselfstart(int compartmentid, int direction);  //direction : 0 positive test , 1 negative test
     Q_INVOKABLE bool tstop(int compartmentid);
     Q_INVOKABLE bool reportpic_Ready(int compartmentid);
-    Q_INVOKABLE bool check_alltest_ok();
+    Q_INVOKABLE bool check_alltest_ok(int with_tips);
     Q_INVOKABLE bool genReport(QString word_path, QString pic_dir);
+    Q_INVOKABLE bool genReport_Self(QString word_path, QString pic_dir);
+    Q_INVOKABLE bool genReport_Self2(const QString& jsonStr, QString word_path, QString pic_dir);
 
     Q_INVOKABLE QJsonObject get_vrs_items();
     Q_INVOKABLE QJsonObject get_bls_items();
+
     Q_INVOKABLE bool set_item_result(const QString& jsonStr );
 
+    Q_INVOKABLE bool set_leakage_value(const QString& jsonStr);
+    Q_INVOKABLE QJsonObject get_selftest_info();
 
 signals:
    void sigPressure(int id, QVariantMap  pressure_map);
@@ -124,9 +129,9 @@ public slots:
 private:
     //bool Adjust_pressure(unsigned short voltage);
 
-    void push_pressurelist(float pressure);
+    void push_pressurelist(double pressure);
     void clear_pressurelist();
-    float calculate_averagepressure();
+    double calculate_averagepressure();
 
     bool OpenSerial3();
     bool OpenSerial4();
@@ -155,7 +160,7 @@ private:
     // 0   ok
     // -1  timeout
     // -2  error
-    Ret_Value  Pressure_Keep(int keeptime, float& start_value, float& end_value);
+    Ret_Value  Pressure_Keep(int keeptime, double& start_value, double& end_value);
 
 
 
@@ -189,6 +194,9 @@ private:
    Test_Step      m_step;
    Test_Direction m_direction;
 
+   DeviceInfo     m_devinfo;
+   DeviceInfo     m_devinfo2;//系统自测检测 历史记录生成报告用
+
    MsgBox         m_msgbox;
 
 

+ 3 - 1
ValveTest.pro

@@ -1,4 +1,4 @@
-QT += quick charts
+QT += quick charts sql
 QT   += serialport
 QT += testlib
 QT += widgets
@@ -14,6 +14,7 @@ SOURCES += \
         Calibrationpara.cpp \
         ComStatistics.cpp \
         DLog.cpp \
+        Deviceinfo.cpp \
         Modbus.cpp \
         Msgbox.cpp \
         PressureSensor.cpp \
@@ -48,6 +49,7 @@ HEADERS += \
     Calibrationpara.h \
     ComStatistics.h \
     DLog.h \
+    Deviceinfo.h \
     Modbus.h \
     Msgbox.h \
     PressureSensor.h \

+ 2 - 1
ValveTest.pro.user

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE QtCreatorProject>
-<!-- Written by QtCreator 8.0.0, 2023-06-13T10:14:45. -->
+<!-- Written by QtCreator 8.0.0, 2023-07-03T18:13:46. -->
 <qtcreator>
  <data>
   <variable>EnvironmentId</variable>
@@ -246,6 +246,7 @@
     <value type="bool" key="RunConfiguration.UseLibrarySearchPath">true</value>
     <value type="bool" key="RunConfiguration.UseQmlDebugger">false</value>
     <value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
+    <value type="QString" key="RunConfiguration.WorkingDirectory.default">D:/Code/QTapps/build-ValveTest-Desktop_Qt_5_15_2_MinGW_32_bit-Release</value>
    </valuemap>
    <value type="qlonglong" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
   </valuemap>

BIN
img/fail_circle.png


BIN
img/ok_circle.png


BIN
img/return.png


+ 1 - 0
main.cpp

@@ -48,6 +48,7 @@ int main(int argc, char *argv[])
     StandardManager::instance();
 
     QQmlApplicationEngine engine;
+    engine.setOfflineStoragePath("D:/VaporRecoverySystemTest/");  //设置数据库存储路径
     //engine.rootContext()->setContextProperty("TService",new TestService);
     const QUrl url(QStringLiteral("qrc:/main.qml"));
     QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,

+ 8 - 0
qml.qrc

@@ -42,5 +42,13 @@
         <file>img/shutdown_red.png</file>
         <file>img/tj_icon.png</file>
         <file>PageCalibration.qml</file>
+        <file>PageLeakageInput.qml</file>
+        <file>PageSelfTest.qml</file>
+        <file>img/return.png</file>
+        <file>ReturnButton.qml</file>
+        <file>selftest_db.js</file>
+        <file>TNormalProgress.qml</file>
+        <file>img/fail_circle.png</file>
+        <file>img/ok_circle.png</file>
     </qresource>
 </RCC>

+ 324 - 4
report.cpp

@@ -43,13 +43,17 @@ QString g_bookmark_bls_check[BLS_VISUAL_INSPECTION_ITEMS_NUM][3]={
     {BOOKMARK_BLS_CHECK_ITEMS_5_0, BOOKMARK_BLS_CHECK_ITEMS_5_1, BOOKMARK_BLS_CHECK_ITEMS_5_2}
 };
 
+QString g_bookmark_leakage_result[3]={BOOKMARK_LEAKAGE_RESULT_0, BOOKMARK_LEAKAGE_RESULT_1, BOOKMARK_LEAKAGE_RESULT_2};
+
 #define REPORT_TEMPLATES_PATH  "D:/VaporRecoverySystemTest/Templates/"
-#define REPORT_TEMPLATES_NAME  "report_v2.dotx"
+#define REPORT_TEMPLATES_NAME  "report_v5.dotx"
+#define REPORT_TEMPLATES_SELFNAME  "report_self_v2.dotx"
 
 ReportWoker::ReportWoker()
 {
     qRegisterMetaType<Tanker>("Tanker&");
     qRegisterMetaType<QString>("QString&");
+    qRegisterMetaType<DeviceInfo>("DeviceInfo&");
 }
 
 ReportWoker::~ReportWoker()
@@ -69,6 +73,11 @@ void ReportWoker::makeReport(Tanker& tanker, QString& word_path, QString& pic_di
     //CoUninitialize();
 }
 
+void ReportWoker::makeselfReport(DeviceInfo& dev_info, QString& word_path, QString& pic_dir)
+{
+    make_selfReport(dev_info, word_path, pic_dir);
+}
+
 bool ReportWoker::make_report(Tanker& tanker, QString word_path, QString pic_dir)
 {
 
@@ -77,7 +86,7 @@ bool ReportWoker::make_report(Tanker& tanker, QString word_path, QString pic_dir
     QString text_progress1 = codec->toUnicode("正在生成Word报告,请耐心等待");
     QString text_progresspdf = codec->toUnicode("正在生成PDF报告,请耐心等待");
     QString text_progress2 = codec->toUnicode("正在保存中...");
-    QString text_progress3 = codec->toUnicode("报告已成");
+    QString text_progress3 = codec->toUnicode("报告已成");
     QString text_progress4 = codec->toUnicode("打开word应用失败");
     QString text_progress5 = codec->toUnicode("报告模板无法使用");
 
@@ -418,7 +427,9 @@ bool ReportWoker::make_report(Tanker& tanker, QString word_path, QString pic_dir
        }
    }
 
-   if(nosys_testcount != tanker.compartment_num){
+   qDebug()<< "avans  sys result:";
+   if(nosys_testcount != tanker.compartment_num)
+   {
        //系统检测结果
        QChar cc = 0x2611;
        QString sText;
@@ -441,7 +452,9 @@ bool ReportWoker::make_report(Tanker& tanker, QString word_path, QString pic_dir
    }
 
 
-   if(novalve_testcount != tanker.compartment_num){
+    qDebug()<< "avans  valve result:";
+   if(novalve_testcount != tanker.compartment_num)
+    {
        //阀门检测结果
        QChar cc = 0x2611;
        QString sText;
@@ -465,6 +478,63 @@ bool ReportWoker::make_report(Tanker& tanker, QString word_path, QString pic_dir
    }
 
 
+   //油气密封点泄漏值
+   qDebug()<< "avans  couplevalve:";
+   if(tanker.m_leakagevalue.couplevalve >= 0){
+
+       bookmark = document->querySubObject("Bookmarks(QVariant)",BOOKMARK_LEAKAGE_COUPLEVALVE);
+       if(!bookmark->isNull())
+       {
+           QString _str = QString("%1").arg(tanker.m_leakagevalue.couplevalve, 4,'f',2,QLatin1Char('0'));
+           QString sText=codec->toUnicode(_str.toStdString().c_str());                          //此处为替换内容
+           //qDebug()<<sText;
+           bookmark->dynamicCall("Select(void)");                             //选中要选中的区域
+           bookmark->querySubObject("Range")->setProperty("Text",sText);      //进行替换操作
+       }
+
+   }
+
+   qDebug()<< "avans  manhole  cover:";
+
+   if(tanker.m_leakagevalue.manhole >= 0){
+       bookmark = document->querySubObject("Bookmarks(QVariant)",BOOKMARK_LEAKAGE_MANHOLECOVER);
+       if(!bookmark->isNull())
+       {
+           QString _str = QString("%1").arg(tanker.m_leakagevalue.manhole, 4,'f',2,QLatin1Char('0'));
+           QString sText=codec->toUnicode(_str.toStdString().c_str());                          //此处为替换内容
+           //qDebug()<<sText;
+           bookmark->dynamicCall("Select(void)");                             //选中要选中的区域
+           bookmark->querySubObject("Range")->setProperty("Text",sText);      //进行替换操作
+       }
+   }
+
+   {
+        int index = 2;
+        if((tanker.m_leakagevalue.couplevalve >= 0) && (tanker.m_leakagevalue.manhole >= 0)){
+            if((tanker.m_leakagevalue.couplevalve <= 500) && (tanker.m_leakagevalue.manhole <= 500)){
+                index = 0;
+            }else{
+                index =1;
+            }
+        }else{
+            index = 2;
+        }
+
+        qDebug()<< "avans  leakage result :" << index;
+
+        bookmark = document->querySubObject("Bookmarks(QVariant)",g_bookmark_leakage_result[index]);
+        if(!bookmark->isNull())
+        {
+            QChar cc = 0x2611;
+            QString sText;
+            sText.insert(0, cc);
+            bookmark->dynamicCall("Select(void)");                             //选中要选中的区域
+            bookmark->querySubObject("Range")->setProperty("Text",sText);      //进行替换操作
+        }
+
+   }
+
+
    //检测日期
    QDate date(QDate::currentDate());
 
@@ -504,6 +574,12 @@ bool ReportWoker::make_report(Tanker& tanker, QString word_path, QString pic_dir
 
        qDebug()<<"start save PDF file ";
 
+       //如果文件已经存在了,不删掉,会有问题
+       QFile file_bak(word_path);
+       if(file_bak.exists()){
+           file_bak.remove();
+       }
+
        QVariant OutputFileName(word_path);
        QVariant ExportFormat(17);      //17是pdf
        QVariant OpenAfterExport(false); //保存后是否自动打开
@@ -532,6 +608,244 @@ bool ReportWoker::make_report(Tanker& tanker, QString word_path, QString pic_dir
 
 }
 
+bool ReportWoker::make_selfReport(DeviceInfo& dev_info, QString& word_path, QString& pic_dir)
+{
+    QTextCodec *codec = QTextCodec::codecForName("UTF-8");
+
+    QString text_progress1 = codec->toUnicode("正在生成Word报告,请耐心等待");
+    QString text_progresspdf = codec->toUnicode("正在生成PDF报告,请耐心等待");
+    QString text_progress2 = codec->toUnicode("正在保存中...");
+    QString text_progress3 = codec->toUnicode("报告已生成");
+    QString text_progress4 = codec->toUnicode("打开word应用失败");
+    QString text_progress5 = codec->toUnicode("报告模板无法使用");
+
+    //新建一个word应用程序
+    QAxWidget *word = new QAxWidget("Word.Application",0,Qt::MSWindowsOwnDC);
+    if(word->isNull()){
+        emit onProgress(text_progress4);
+        return false;
+    }
+    //并设置为不可见
+    word->setProperty("Visible",false);
+    //获取所有的工作文档
+    QAxObject *documents = word->querySubObject("Documents");
+    //以test2.dot为模板新建一个文档
+    documents->dynamicCall("Add(QString)",QString(REPORT_TEMPLATES_PATH)+QString(REPORT_TEMPLATES_SELFNAME));
+    //documents->dynamicCall("Add(QString)",QString::fromLocal8Bit("D:\Code\QTapps\build-valve_testing-Desktop_Qt_5_15_2_MinGW_32_bit-Debug\debug\test1.dotx"));
+    //获取当前激活的文档
+    QAxObject *document = word->querySubObject("ActiveDocument");
+    if(document->isNull()){
+        emit onProgress(text_progress5);
+       return false;
+    }
+
+     if(word_path.contains(".pdf")){
+        emit onProgress(text_progresspdf);
+     }else{
+        emit onProgress(text_progress1);
+     }
+
+     QThread::msleep(1000);
+
+     //填写设备信息
+
+     //设备型号
+     QAxObject *bookmark = document->querySubObject("Bookmarks(QVariant)",BOOKMARK_SELF_DEVICEMODEL);
+     if(!bookmark->isNull())
+     {
+         //QChar cc = 0x2611;
+         QString str =  dev_info.m_model;
+         //str.insert(0, cc);
+         QString sText=codec->toUnicode(str.toStdString().c_str());                          //此处为替换内容
+         qDebug()<<sText;
+         bookmark->dynamicCall("Select(void)");                             //选中要选中的区域
+         bookmark->querySubObject("Range")->setProperty("Text",sText);      //进行替换操作
+     }
+
+     //设备编号
+     bookmark = document->querySubObject("Bookmarks(QVariant)",BOOKMARK_SELF_DEVICEID);
+     if(!bookmark->isNull())
+     {
+         //QChar cc = 0x2611;
+         QString str =  dev_info.m_id;
+         //str.insert(0, cc);
+         QString sText=codec->toUnicode(str.toStdString().c_str());                          //此处为替换内容
+         qDebug()<<sText;
+         bookmark->dynamicCall("Select(void)");                             //选中要选中的区域
+         bookmark->querySubObject("Range")->setProperty("Text",sText);      //进行替换操作
+     }
+
+     // 压力变化曲线图片
+     QAxObject*bookmark_pic=document->querySubObject("Bookmarks(QVariant)", BOOKMARK_SELF_TESTPIC);
+      // 选中标签,将图片插入到标签位置
+     if(!bookmark_pic->isNull())
+     {
+         QString pic_path_str = pic_dir+"selftest.jpg";
+         qDebug()<<pic_path_str;
+
+         QFile file(pic_path_str);
+
+         if(file.exists()){
+
+             bookmark_pic->dynamicCall("Select(void)");
+             QAxObject *range;
+             range = bookmark_pic->querySubObject("Range");
+             QVariant tmp = range->asVariant();
+
+             QList<QVariant>qList;
+             qList<<QVariant(pic_path_str);
+             qList<<QVariant(false);
+             qList<<QVariant(true);
+             qList<<tmp;
+
+             QAxObject *Inlineshapes = document->querySubObject("InlineShapes");
+             Inlineshapes->dynamicCall("AddPicture(const QString&, QVariant, QVariant ,QVariant)",qList);
+         }
+
+
+     }
+
+     //密闭性检测的初始表压
+     bookmark = document->querySubObject("Bookmarks(QVariant)", BOOKMARK_SELF_BEGIN);
+     if(!bookmark->isNull())
+     {
+         //int volume = m_tank.m_comparts[i].m_volume;
+         QString pressure_str = QString("%1").arg(dev_info.m_testinfo.m_begin, 4,'f',2,QLatin1Char('0'));
+         QString sText=codec->toUnicode(pressure_str.toStdString().c_str());                          //此处为替换内容
+         qDebug()<<sText;
+         bookmark->dynamicCall("Select(void)");                             //选中要选中的区域
+         bookmark->querySubObject("Range")->setProperty("Text",sText);      //进行替换操作
+     }
+
+     //5 min之后的表压
+     bookmark = document->querySubObject("Bookmarks(QVariant)", BOOKMARK_SELF_END);
+     if(!bookmark->isNull())
+     {
+         //int volume = m_tank.m_comparts[i].m_volume;
+         QString pressure_str = QString("%1").arg(dev_info.m_testinfo.m_end, 4,'f',2,QLatin1Char('0'));
+         QString sText=codec->toUnicode(pressure_str.toStdString().c_str());                          //此处为替换内容
+         qDebug()<<sText;
+         bookmark->dynamicCall("Select(void)");                             //选中要选中的区域
+         bookmark->querySubObject("Range")->setProperty("Text",sText);      //进行替换操作
+     }
+
+     //压力变化值
+     bookmark = document->querySubObject("Bookmarks(QVariant)",BOOKMARK_SELF_DELTA);
+     if(!bookmark->isNull())
+     {
+         //int volume = m_tank.m_comparts[i].m_volume;
+         QString pressure_str = QString("%1").arg(dev_info.m_testinfo.m_delta, 4,'f',2,QLatin1Char('0'));
+         QString sText=codec->toUnicode(pressure_str.toStdString().c_str());                          //此处为替换内容
+         qDebug()<<sText;
+         bookmark->dynamicCall("Select(void)");                             //选中要选中的区域
+         bookmark->querySubObject("Range")->setProperty("Text",sText);      //进行替换操作
+     }
+
+     //压力变化限值
+     bookmark = document->querySubObject("Bookmarks(QVariant)", BOOKMARK_SELF_THRESHOLD);
+     if(!bookmark->isNull())
+     {
+         //int volume = m_tank.m_comparts[i].m_volume;
+         QString pressure_str = QString("%1").arg(dev_info.m_testinfo.m_threshold, 4,'f',2,QLatin1Char('0'));
+         QString sText=codec->toUnicode(pressure_str.toStdString().c_str());                          //此处为替换内容
+         qDebug()<<sText;
+         bookmark->dynamicCall("Select(void)");                             //选中要选中的区域
+         bookmark->querySubObject("Range")->setProperty("Text",sText);      //进行替换操作
+     }
+
+     //检测结果
+     QChar cc = 0x2611;
+     QString sText;
+     sText.insert(0, cc);
+
+     if(1 == dev_info.m_testinfo.m_passed){
+         bookmark = document->querySubObject("Bookmarks(QVariant)",BOOKMARK_SELF_PASS);
+         if(!bookmark->isNull())
+         {
+             bookmark->dynamicCall("Select(void)");                             //选中要选中的区域
+             bookmark->querySubObject("Range")->setProperty("Text",sText);      //进行替换操作
+         }
+     }else{
+         bookmark = document->querySubObject("Bookmarks(QVariant)",BOOKMARK_SELF_EXCEEDED);
+         if(!bookmark->isNull())
+         {
+             bookmark->dynamicCall("Select(void)");                             //选中要选中的区域
+             bookmark->querySubObject("Range")->setProperty("Text",sText);      //进行替换操作
+         }
+     }
+
+     //检测日期
+     QDate date(QDate::currentDate());
+
+     bookmark = document->querySubObject("Bookmarks(QVariant)",BOOKMARK_SELF_YEAR);
+     if(!bookmark->isNull())
+     {
+         QString sText=codec->toUnicode(QString::number(date.year()).toStdString().c_str());                          //此处为替换内容
+         qDebug()<<sText;
+         bookmark->dynamicCall("Select(void)");                             //选中要选中的区域
+         bookmark->querySubObject("Range")->setProperty("Text",sText);      //进行替换操作
+     }
+
+     bookmark = document->querySubObject("Bookmarks(QVariant)",BOOKMARK_SELF_MONTH);
+     if(!bookmark->isNull())
+     {
+         QString sText=codec->toUnicode(QString::number(date.month()).toStdString().c_str());                          //此处为替换内容
+         qDebug()<<sText;
+         bookmark->dynamicCall("Select(void)");                             //选中要选中的区域
+         bookmark->querySubObject("Range")->setProperty("Text",sText);      //进行替换操作
+     }
+
+     bookmark = document->querySubObject("Bookmarks(QVariant)",BOOKMARK_SELF_DAY);
+     if(!bookmark->isNull())
+     {
+         QString sText=codec->toUnicode(QString::number(date.day()).toStdString().c_str());                          //此处为替换内容
+         qDebug()<<sText;
+         bookmark->dynamicCall("Select(void)");                             //选中要选中的区域
+         bookmark->querySubObject("Range")->setProperty("Text",sText);      //进行替换操作
+     }
+
+     //将文件保存为PDF,
+
+     emit onProgress(text_progress2);
+     QThread::msleep(1000);
+
+     if(word_path.contains(".pdf")){
+
+         qDebug()<<"start save PDF file ";
+
+         //如果文件已经存在了,不删掉,会有问题
+         QFile file_bak(word_path);
+         if(file_bak.exists()){
+             file_bak.remove();
+         }
+
+
+         QVariant OutputFileName(word_path);
+         QVariant ExportFormat(17);      //17是pdf
+         QVariant OpenAfterExport(false); //保存后是否自动打开
+
+         document->querySubObject("ExportAsFixedFormat(const QVariant&,const QVariant&,const QVariant&)",
+                                  OutputFileName,
+                                  ExportFormat,
+                                  OpenAfterExport);
+
+     }else {
+         qDebug()<<"start save Word file ";
+         document->dynamicCall("SaveAs(const QString&))",QDir::toNativeSeparators(word_path));
+     }
+
+
+
+     document->dynamicCall("Close (boolean)",false);
+     word->dynamicCall("Quit()");
+
+     emit onProgress(text_progress3);
+     QThread::msleep(1000);
+     emit onProgress("close");
+
+     return true;
+
+}
 
 
 Report::Report()
@@ -543,6 +857,7 @@ Report::Report()
     worker->moveToThread(&workerThread);
     connect(&workerThread, &QThread::finished, worker, &QObject::deleteLater);
     connect(this, &Report::operate, worker, &ReportWoker::makeReport);
+    connect(this, &Report::operateself, worker, &ReportWoker::makeselfReport);
     connect(this, &Report::oninit, worker, &ReportWoker::init);
     connect(worker, &ReportWoker::onProgress, this, &Report::recvProgress);
     workerThread.start();
@@ -566,3 +881,8 @@ void Report::makeReport(Tanker& tanker, QString word_path, QString pic_dir)
     emit operate(tanker, word_path, pic_dir);
 }
 
+void Report::makeReport_Self(DeviceInfo& dev_info, QString word_path, QString pic_dir)
+{
+    emit operateself(dev_info, word_path, pic_dir);
+}
+

+ 23 - 1
report.h

@@ -2,6 +2,7 @@
 #define REPORT_H
 
 #include "tank.h"
+#include "Deviceinfo.h"
 #include<QThread>
 #include<windows.h>
 
@@ -137,7 +138,24 @@
 #define BOOKMARK_SYSTEST_PICTURE_4      "bm_picSys_4"
 #define BOOKMARK_VALVETEST_PICTURE_4    "bm_picValve_4"
 
-
+#define BOOKMARK_LEAKAGE_COUPLEVALVE    "bm_leakage_couplevalve"
+#define BOOKMARK_LEAKAGE_MANHOLECOVER   "bm_leakage_manholecover"
+#define BOOKMARK_LEAKAGE_RESULT_0       "bm_leakage_result_0"
+#define BOOKMARK_LEAKAGE_RESULT_1       "bm_leakage_result_1"
+#define BOOKMARK_LEAKAGE_RESULT_2       "bm_leakage_result_2"
+
+#define BOOKMARK_SELF_YEAR          "bm_year"
+#define BOOKMARK_SELF_MONTH         "bm_month"
+#define BOOKMARK_SELF_DAY           "bm_day"
+#define BOOKMARK_SELF_DEVICEMODEL   "bm_devicemodel"
+#define BOOKMARK_SELF_DEVICEID      "bm_deviceid"
+#define BOOKMARK_SELF_TESTPIC       "bm_test_pic"
+#define BOOKMARK_SELF_BEGIN         "bm_begin"
+#define BOOKMARK_SELF_END           "bm_end"
+#define BOOKMARK_SELF_THRESHOLD     "bm_threshold"
+#define BOOKMARK_SELF_DELTA         "bm_delta"
+#define BOOKMARK_SELF_PASS          "bm_self_pass"
+#define BOOKMARK_SELF_EXCEEDED      "bm_self_exceeded"
 
 class ReportWoker:public QObject
 {
@@ -148,6 +166,7 @@ public:
 
 public slots:
     void makeReport(Tanker& tanker, QString& word_path, QString& pic_dir);
+    void makeselfReport(DeviceInfo& dev_info, QString& word_path, QString& pic_dir);
     void init();
 
 signals:
@@ -156,6 +175,7 @@ signals:
 
 private:
     bool make_report(Tanker& tanker, QString word_path, QString pic_dir);
+    bool make_selfReport(DeviceInfo& dev_info, QString& word_path, QString& pic_dir);
 };
 
 class Report :public QObject
@@ -167,6 +187,7 @@ public:
     ~Report();
 
     void makeReport(Tanker& tanker, QString word_path, QString pic_dir);
+    void makeReport_Self(DeviceInfo& dev_info, QString word_path, QString pic_dir);
 
 public slots:
     //void handleResults(const int);
@@ -174,6 +195,7 @@ public slots:
 
 signals:
     void operate(Tanker& , QString& , QString& );
+    void operateself(DeviceInfo& , QString& , QString& );
     void onProgress(QString);
     void oninit();
 

+ 245 - 0
selftest_db.js

@@ -0,0 +1,245 @@
+var st_db;
+
+function getDatabase(){
+    if(!st_db)
+        st_db = LocalStorage.openDatabaseSync("selftest_db", "1.0", "selftest history records", 2048*1000);
+
+    return st_db
+}
+
+function initDatabase() {
+    st_db = LocalStorage.openDatabaseSync("selftest_db", "1.0", "selftest history records", 2048*1000);
+    try {
+        st_db.transaction( function(tx) {
+            tx.executeSql('CREATE TABLE IF NOT EXISTS test_table(\
+                                    dt TEXT primary key, \
+                                    time TEXT, \
+                                    target REAL, \
+                                    interval INTEGER, \
+                                    threshold REAL, \
+                                    begin REAL, \
+                                    end REAL, \
+                                    delta REAL, \
+                                    passed INTEGER )');
+        })
+    } catch (err) {
+           console.log("Error creating table in database: " + err)
+    };
+}
+
+function readData(tablename_str) {
+    var res;
+    //let sql_str = 'select * from ${tablename_str}'
+    if(!st_db) { return; }
+
+    try{
+        st_db.transaction( function(tx) {
+            res = tx.executeSql('select * from '+ tablename_str);
+        })
+    }catch(err){
+        console.log("Error table:"+tablename_str+" not exist in database: " + err)
+        return;
+    }
+
+    return res;
+}
+
+function readRecord(date_str) {
+    var res;
+    //let sql_str = 'select * from ${tablename_str}'
+    if(!st_db) { return; }
+
+    try{
+        st_db.transaction( function(tx) {
+            res = tx.executeSql('SELECT * FROM test_table WHERE dt = '+ date_str);
+        })
+    }catch(err){
+        console.log("Error Record:"+date_str+" not exist in test_table: " + err)
+        return;
+    }
+
+    return res;
+}
+
+function insertRecord(record) {
+    var res = "Error";
+
+    if(!st_db) { return res }
+
+    var today = new Date();
+
+    //日期
+    var DD = String(today.getDate()).padStart(2, '0'); // 获取日
+    var MM = String(today.getMonth() + 1).padStart(2, '0'); //获取月份,1 月为 0
+    var yyyy = today.getFullYear(); // 获取年
+
+    // 时间
+    var hh =  String(today.getHours()).padStart(2, '0');       //获取当前小时数(0-23)
+    var mm = String(today.getMinutes()).padStart(2, '0');     //获取当前分钟数(0-59)
+    var ss = String(today.getSeconds()).padStart(2, '0');     //获取当前秒数(0-59)
+
+    let date = yyyy + '-' + MM + '-' + DD;
+    let time = hh + ':' + mm + ':' + ss;
+
+    try{
+        st_db.transaction( function(tx) {
+            var result = tx.executeSql('INSERT OR REPLACE INTO test_table VALUES (?,?,?,?,?,?,?,?,?)',
+                                       [date, time, record.target, record.interval, record.threshold, record.begin, record.end, record.delta, record.passed]);
+            if (result.rowsAffected > 0) {
+              res = "OK";
+            } else {
+              res = "Error";
+            }
+        })
+    }catch(err){
+        console.log("Error insert record in test_table: " + err)
+        res = "Error";
+    }
+    return res
+}
+
+
+function deleteRecord(date_str) {
+    var res = "Error";
+
+    var today = new Date(date_str);
+    var DD = String(today.getDate()).padStart(2, '0'); // 获取日
+    var MM = String(today.getMonth()+1).padStart(2, '0'); //获取月份,1 月为 0
+    var yyyy = today.getFullYear(); // 获取年
+
+    let date = yyyy + MM  + DD;
+    let table_name = 'data_'+date
+
+    console.log("DeleteRecord in date_str: " + date_str)
+    console.log("DeleteRecord in table_name: " + table_name)
+
+    if(!st_db) { return res }
+
+    try{
+        st_db.transaction( function(tx) {
+            tx.executeSql('DELETE FROM test_table WHERE dt =\"'+date_str+'\"');
+
+            var result = tx.executeSql('SELECT * FROM sqlite_master WHERE type="table" AND name=\"'+table_name+'\"')
+
+            if(result.rows.length > 0){
+                tx.executeSql('DROP TABLE '+table_name);
+            }
+
+        })
+    }catch(err){
+        console.log("Error insert record in test_table: " + err)
+        return res
+    }
+
+    res = "OK";
+
+    return res
+}
+
+function insertData(data_arry) {
+    var res = "Error";
+    if(!st_db) { return res }
+
+    var today = new Date();
+    var DD = String(today.getDate()).padStart(2, '0'); // 获取日
+    var MM = String(today.getMonth() + 1).padStart(2, '0'); //获取月份,1 月为 0
+    var yyyy = today.getFullYear(); // 获取年
+
+    let date = yyyy + MM  + DD;
+    let table_name = 'data_'+date
+
+        console.log("insertData tablename: " + table_name)
+
+    try {
+        st_db.transaction( function(tx) {
+            var result = tx.executeSql('SELECT * FROM sqlite_master WHERE type="table" AND name=\"'+table_name+'\"')
+
+            console.log("insertData 1111 result.rows.length: " + result.rows.length)
+
+
+            var table_exist = false
+            if(result.rows.length > 0){
+                table_exist=true
+            }
+
+            if(true == table_exist){
+                console.log("insertData 1111 true table_exist: " + table_exist)
+                st_db.transaction( function(tx) {
+                    tx.executeSql('DELETE  FROM '+ table_name);
+                    tx.executeSql('UPDATE sqlite_sequence SET seq = 0 WHERE name =\"'+table_name+'\"');
+                })
+
+            }else{
+                console.log("insertData 1111 false table_exist: " + table_exist)
+                st_db.transaction( function(tx) {
+                    tx.executeSql('CREATE TABLE IF NOT EXISTS '+ table_name +'(\
+                                            ID INTEGER primary key AUTOINCREMENT, \
+                                            step INTEGER, \
+                                            pressure REAL)');
+                })
+            }
+
+
+            console.log("insertData 2222 tablename: " + table_name)
+
+            st_db.transaction( function(tx) {
+                //var i;
+                for(var i=0; i< data_arry.length; i++){
+                    tx.executeSql('INSERT INTO '+ table_name +' (step,pressure) VALUES ('+data_arry[i].step +','+ data_arry[i].pressure+')');
+                }
+            })
+
+        })
+    } catch (error) {
+        console.log("Error SELECT table in sqlite_master: " + error)
+        return res;
+    };
+
+
+    /*
+    if(table_exist){
+        try {
+            st_db.transaction( function(tx) {
+                tx.executeSql('DELETE * FROM '+ table_name);
+            })
+        } catch (error1) {
+            console.log("Error1 DELETE * FROM table insertData : " + error1)
+            return res;
+        };
+    }else{
+        try {
+            st_db.transaction( function(tx) {
+                tx.executeSql('CREATE TABLE IF NOT EXISTS '+ table_name +'(\
+                                        id INTEGER primary key AUTOINCREMENT, \
+                                        step INTEGER, \
+                                        pressure REAL)');
+            })
+        } catch (error2) {
+               console.log("Error creating table insertData in database: " + error2)
+            return res;
+        };
+    }
+
+    try {
+        st_db.transaction( function(tx) {
+            for(i=0; i< data_arry.length; i++){
+                tx.executeSql('INSERT INTO '+ table_name +'(?,?)', [NULL, data_arry[i].step, data_arry[i].pressure]);
+            }
+        })
+    } catch (error3) {
+           console.log("Error INSERT INTO "+ table_name +"(?,?):"  + error3)
+        return res
+    };
+
+*/
+    res = "OK";
+
+    return res
+}
+
+/*
+function deleteData(date_str){
+    let table_name = date_str+'_data'
+
+}
+*/

+ 42 - 0
tank.cpp

@@ -90,6 +90,17 @@ void Compartment::clear_result()
     m_testfinished = false;
 }
 
+LeakageValue::LeakageValue()
+{
+    couplevalve = -100.0;
+    manhole = -100.0;
+}
+
+LeakageValue::~LeakageValue()
+{
+
+}
+
 
 Tanker::Tanker()
 {
@@ -222,5 +233,36 @@ bool Tanker::set_item_result(const QString& jsonStr )
     return true;
 }
 
+bool Tanker::set_leakage_value(const QString& jsonStr)
+{
+    QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonStr.toUtf8());
+    QJsonObject jsonObj = jsonDoc.object();
+
+    LeakageValue lv;
+
+    if(jsonObj.contains("couplevalve") && jsonObj.value("couplevalve").isDouble()){
+        lv.couplevalve = jsonObj.value("couplevalve").toDouble();
+    }else{
+        qDebug() << "set_leakage_value no couplevalve";
+        return false;
+    }
+
+    if(jsonObj.contains("manhole") && jsonObj.value("manhole").isDouble()){
+        lv.manhole = jsonObj.value("manhole").toDouble();
+    }else{
+        qDebug() << "set_leakage_value no manhole";
+        return false;
+    }
+
+    if(lv.couplevalve < 0 || lv.manhole < 0){
+        return false;
+    }
+
+    m_leakagevalue = lv;
+
+
+    return true;
+}
+
 
 

+ 16 - 0
tank.h

@@ -39,6 +39,7 @@ public:
     bool  valve_test_finished;
 };
 
+
 class Compartment{
 public:
     Compartment();
@@ -63,6 +64,16 @@ public:
 
 };
 
+class LeakageValue{
+public:
+    LeakageValue();
+    ~LeakageValue();
+    double couplevalve;
+    double manhole;
+
+};
+
+
 class Tanker
 {
 public:
@@ -74,6 +85,9 @@ public:
     QString  companyname_str;
     int compartment_num;
     int total_volume;
+
+    LeakageValue m_leakagevalue;
+
     Compartment m_comparts[MAX_COMPARTMENT_NUM];
 
     int vrs_results[VRS_VISUAL_INSPECTION_ITEMS_NUM];
@@ -82,6 +96,8 @@ public:
     QJsonObject get_vrs_items();
     QJsonObject get_bls_items();
     bool set_item_result(const QString& jsonStr );
+
+    bool set_leakage_value(const QString& jsonStr);
 };
 
 Q_DECLARE_METATYPE(Tanker);