using System; using System.Collections.Generic; using System.Data; using System.IO; using System.Linq; namespace IStation.DAL { /// /// 监测月数据集 /// public partial class StationStatisticalRecordPacket { /// /// 文件信息类 /// private class FileInfo { public string FullName { get; set; } public int Year { get; set; } public int Month { get; set; } } #region FolderInfo /// /// 查询年月 /// 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(SettingsD.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; } /// /// 查询文件信息列表 /// private List 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(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 } }