tangxu
2024-03-26 edd23f115dba31d764fdaf75a6207d888d0419d3
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
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
 
namespace IStation.DAL
{
    /// <summary>
    /// 监测月数据集
    /// </summary>    
    public partial class MonthSignalRecordPacket
    {
        /// <summary>
        ///  文件信息类
        /// </summary>
        private class FileInfo
        {
            public string FullName { get; set; }
            public int Year { get; set; }
            public int Month { get; set; }
            public int RecordCount { get; set; }
        }
 
        #region DateFolderInfo
        /// <summary>
        /// 查询年月
        /// </summary> 
        private bool GetYearMonth(string folderPath, out int year, out int month, out int recordCount)
        {
            year = month = recordCount = 0;
            if (!File.Exists(folderPath))
                return false;
 
            var name = Path.GetFileNameWithoutExtension(folderPath);
            var strList = name.Split(LocalFileConfig.Separator);
            if (strList.Length != 3)
                return false;
            if (!int.TryParse(strList[0], out year))
            {
                return false;
            }
            if (!int.TryParse(strList[1], out month))
            {
                return false;
            }
            if (!int.TryParse(strList[2], out recordCount))
            {
                return false;
            }
            return true;
        }
 
        /// <summary>
        /// 查询文件信息列表
        /// </summary> 
        private List<FileInfo> GetMonthSignalRecordFileInfos(string monthSignalRecordDataFolder)
        {
            if (!Directory.Exists(monthSignalRecordDataFolder))
                return default;
            var files = Directory.GetFiles(monthSignalRecordDataFolder);
            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, out int recordCount))
                    continue;
                var info = new FileInfo();
                info.FullName = file;
                info.Year = year;
                info.Month = month;
                info.RecordCount = recordCount;
                list.Add(info);
            }
            if (list.Count > 0)
            {
                list = list.OrderBy(x => x.Year).ThenBy(x => x.Month).ToList();
            }
            return list;
        }
 
        #endregion
 
 
 
    }
}