Shuxia Ning
2025-02-13 2f1cbec203dcff25df7a5c2b51b13ec558f2c3db
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
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
 
namespace IStation.DAL
{
    /// <summary>
    /// 监测月数据集
    /// </summary>    
    public partial class StationStatisticalRecordPacket
    {
        /// <summary>
        ///  文件信息类
        /// </summary>
        private class FileInfo
        {
            public string FullName { get; set; }
            public int Year { get; set; }
            public int Month { get; set; }
        }
 
        #region FolderInfo
 
        /// <summary>
        /// 查询年月
        /// </summary> 
        private bool GetYearMonth(string folderPath, out int year, out int month)
        {
            year = month = 0;
            if (!File.Exists(folderPath))
                return false;
 
            var name = Path.GetFileNameWithoutExtension(folderPath);
            var strList = name.Split(Settings.File.FileNameSpacer);
            if (strList.Length != 4)
                return false;
            if (!int.TryParse(strList[0], out year))
            {
                return false;
            }
            if (!int.TryParse(strList[1], out month))
            {
                return false;
            }
            return true;
        }
 
        /// <summary>
        /// 查询文件信息列表
        /// </summary> 
        private List<FileInfo> GetStationStatisticalRecordPacketFileInfoList(string stationFolder)
        {
            if (!Directory.Exists(stationFolder))
                return default;
            var files = Directory.GetFiles(stationFolder);
            if (files == null || files.Count() < 1)
                return default;
 
            var list = new List<FileInfo>(files.Count());
            foreach (var file in files)
            {
                if (!GetYearMonth(file, out int year, out int month))
                    continue;
                var info = new FileInfo
                {
                    FullName = file,
                    Year = year,
                    Month = month,
                };
                list.Add(info);
            }
            if (list.Count > 0)
            {
                list = list.OrderBy(x => x.Year).ThenBy(x => x.Month).ToList();
            }
            return list;
        }
 
        #endregion
 
 
        #region CsvConvert
 
 
        //To
        private string ToDsString(Model.StationStatisticalRecord record)
        {
            return $"{record.Time:yyyy-MM-dd HH:mm:ss},{record.TotalFlow},{record.TotalHead},{record.PumpRunCount},{record.PumpRunFlags}";
        }
 
        //from
        public Model.StationStatisticalRecord FromDsString(string dsString)
        {
            var strList = dsString.Split(',');
            if (strList.Length < 2)
                return default;
            var model = new Model.StationStatisticalRecord
            {
                Time = DateTime.Parse(strList[0]),
                TotalFlow = double.Parse(strList[1]),
                TotalHead = double.Parse(strList[2]),
                PumpRunCount = int.Parse(strList[3]),
                PumpRunFlags = strList[4]
            };
            return model;
        }
 
        #endregion
    }
}