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
|
|
|
|
}
|
}
|