Shuxia Ning
2024-10-08 cf4967a0aebab18c5a37137f3e4c61b2d73a54bb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
 
namespace IStation.DAL
{
    /// <summary>
    /// 曲线分析点包
    /// </summary>    
    public partial class CurveAnalyzePoint
    {
        /// <summary>
        ///  文件信息类
        /// </summary>
        private class FileInfo
        {
            public string FullName { get; set; }
            public int RecordCount { get; set; }
        }
 
        #region FolderInfo
 
        /// <summary>
        /// 查询年月
        /// </summary> 
        private bool GetFileInfo(string filePath, out long curveAnalyzeId, out int recordCount)
        {
            curveAnalyzeId = recordCount = 0;
            if (!File.Exists(filePath))
                return false;
 
            var name = Path.GetFileNameWithoutExtension(filePath);
            var strList = name.Split(Settings.File.FileNameSpacer);
            if (strList.Length != 2)
                return false;
            if (!long.TryParse(strList[0], out curveAnalyzeId))
            {
                return false;
            }
            if (!int.TryParse(strList[1], out recordCount))
            {
                return false;
            }
 
            return true;
        }
 
        /// <summary>
        /// 查询文件信息
        /// </summary> 
        private FileInfo GetCurveAnalyzePointFileInfo(string folder, long curveAnalyzeId)
        {
            if (!Directory.Exists(folder))
                return default;
            var files = Directory.GetFiles(folder);
            if (files == null || files.Count() < 1)
                return default;
            FileInfo info = null;
            foreach (var file in files)
            {
                if (!GetFileInfo(file, out long id, out int recordCount))
                    continue;
                if (id != curveAnalyzeId)
                    continue;
                info = new FileInfo
                {
                    FullName = file,
                    RecordCount = recordCount
                };
            }
            return info;
        }
 
        /// <summary>
        /// 查询文件信息
        /// </summary> 
        private List<FileInfo> GetCurveAnalyzePointFileInfoList(string folder, long curveAnalyzeId)
        {
            if (!Directory.Exists(folder))
                return default;
            var files = Directory.GetFiles(folder);
            if (files == null || files.Count() < 1)
                return default;
            List<FileInfo> list = new List<FileInfo>();
            foreach (var file in files)
            {
                if (!GetFileInfo(file, out long id, out int recordCount))
                    continue;
                if (id != curveAnalyzeId)
                    continue;
                list.Add(new FileInfo
                {
                    FullName = file,
                    RecordCount = recordCount
                });
            }
            return list;
        }
 
        #endregion
 
        #region CsvConvert
        //To
        public static string ToDsString(Model.CurveAnalyzePoint model)
        {
            var line =
                     $"{model.Time:yyyy-MM-dd HH:mm:ss}" +
                     $",{model.Q}" +
                     $",{model.P1}" +
                     $",{model.P2}" +
                     $",{model.H}" +
                     $",{model.P}" +
                     $",{model.E}" +
                     $",{model.N}" +
                     $",{model.HZ}" +
                     $",{model.Status}";
 
            return line;
        }
 
        //from
        public static Model.CurveAnalyzePoint FromDsString(string dsString)
        {
            var strList = dsString.Split(',');
            if (strList.Length < 2)
                return default;
            var model = new Model.CurveAnalyzePoint();
            model.Time = DateTime.Parse(strList[0]);
            model.Q = double.Parse(strList[1]);
            model.P1 = double.Parse(strList[2]);
            model.P2 = double.Parse(strList[3]);
            model.H = double.Parse(strList[4]);
            model.P = double.Parse(strList[5]);
            model.E = double.Parse(strList[6]);
            model.N = double.Parse(strList[7]);
            model.HZ = double.Parse(strList[8]);
            model.Status = int.Parse(strList[9]);
            return model;
        }
 
        #endregion
 
    }
}