wenxiangchao
3 天以前 b544d5cccd76735e034c8055918a50927b437474
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
using System;
using System.Data;
using System.IO;
 
namespace HMI.Simple.Util
{
    public class SerialDataHelper
    {
        public static bool GetFailCountBySNR(string snr, out int count, out string msg)
        {
            count = -1;
            msg = string.Empty;
            SqliteHelper sqliteHelper = null;
            try
            {
                string dataLogPath = "";
                var value = ParameterUtil.GetCommonParameterValue("TS_DataLogPath", out msg);
                if (!string.IsNullOrEmpty(msg))
                {
                    string appFolder = RegUtil.GetLocaltion();
                    dataLogPath = Path.Combine(appFolder, "Config", "DataBoard", "DataLog.db");
                }
                if (!File.Exists(dataLogPath))
                {
                    msg = "数据库文件不存在";
                    return false;
                }
                sqliteHelper = new SqliteHelper(dataLogPath);
 
                var sql = $@"SELECT COUNT(*) as num FROM testResult WHERE sn = '{snr}' AND result = 'Failed';";
                DataTable dt = sqliteHelper.GetDataTable(sql);
                if (dt.Rows.Count <= 0)
                {
                    count = 0;
                    return true;
                }
                count = int.Parse(dt.Rows[0]["num"].ToString());
                return true;
            }
            catch (Exception ex)
            {
                msg = ex.Message;
                return false;
            }
            finally
            {
                sqliteHelper?.Dispose();
            }
        }
 
        public static bool GetCountBySNRAndPosition(string snr, string position,
            out int okCount,
            out int ngCount,
            out string status,
            out string msg)
        {
            okCount = -1;
            ngCount = -1;
            status = string.Empty;
            msg = string.Empty;
            SqliteHelper sqliteHelper = null;
            try
            {
                string dataLogPath = "";
                var value = ParameterUtil.GetCommonParameterValue("TS_DataLogPath", out msg);
                if (!string.IsNullOrEmpty(msg))
                {
                    string appFolder = RegUtil.GetLocaltion();
                    dataLogPath = Path.Combine(appFolder, "Config", "DataBoard", "DataLog.db");
                }
                if (!File.Exists(dataLogPath))
                {
                    msg = "数据库文件不存在";
                    return false;
                }
                sqliteHelper = new SqliteHelper(dataLogPath);
 
                var sql = $@"SELECT COUNT(*) as num FROM testResult WHERE sn = '{snr}' AND position = '{position}' AND result = 'Failed';";
                DataTable dt = sqliteHelper.GetDataTable(sql);
                if (dt.Rows.Count <= 0)
                {
                    ngCount = 0;
                    return true;
                }
                ngCount = int.Parse(dt.Rows[0]["num"].ToString());
 
                sql = $@"SELECT COUNT(*) as num FROM testResult WHERE sn = '{snr}' AND position = '{position}' AND result = 'Passed';";
                dt = sqliteHelper.GetDataTable(sql);
                if (dt.Rows.Count <= 0)
                {
                    okCount = 0;
                    return true;
                }
                okCount = int.Parse(dt.Rows[0]["num"].ToString());
 
                sql = $@"SELECT status as status FROM testResult WHERE sn = '{snr}' ORDER BY time DESC LIMIT 0,1;";
                dt = sqliteHelper.GetDataTable(sql);
                if (dt.Rows.Count <= 0)
                {
                    status = string.Empty;
                    return true;
                }
                status = dt.Rows[0]["status"] == DBNull.Value ? string.Empty : dt.Rows[0]["status"].ToString();
                return true;
            }
            catch (Exception ex)
            {
                msg = ex.Message;
                return false;
            }
            finally
            {
                sqliteHelper?.Dispose();
            }
        }
    }
}