using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
namespace IStation.DAL
{
///
/// 曲线分析点包
///
public partial class CurveAnalyzePointPacket
{
///
/// 文件信息类
///
private class FileInfo
{
public string FullName { get; set; }
public int Year { get; set; }
public int Month { get; set; }
public int RecordCount { get; set; }
}
#region FolderInfo
///
/// 查询年月
///
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(SettingsD.File.FileNameSpacer);
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;
}
///
/// 查询文件信息列表
///
private List GetCurveAnalyzePacketFileInfoList(string folder)
{
if (!Directory.Exists(folder))
return default;
var files = Directory.GetFiles(folder);
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, out int recordCount))
continue;
var info = new FileInfo
{
FullName = file,
Year = year,
Month = month,
RecordCount = recordCount
};
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.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.HZ}" +
// $",{model.Status}";
// return line;
//}
////from
//public 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 = long.Parse(strList[1]);
// model.P1 = long.Parse(strList[2]);
// model.P2 = long.Parse(strList[3]);
// model.H = long.Parse(strList[4]);
// model.P = long.Parse(strList[5]);
// model.E = long.Parse(strList[6]);
// model.HZ = long.Parse(strList[7]);
// model.Status = int.Parse(strList[8]);
// return model;
//}
//#endregion
}
}