using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Xml;
namespace IStation.WinFrmUI.Monitor
{
///
/// 常规监测数据导入辅助类
///
public class MonitorDataImportHelper
{
public static bool Import()
{
var monitorPoints = new BLL.MonitorPoint().GetAllExSignalExSignalType();
if (monitorPoints == null || !monitorPoints.Any())
return false;
var importMappers = new List();
foreach (var monitorPoint in monitorPoints)
{
if (string.IsNullOrEmpty(monitorPoint.TagName))
continue;
var mapper = new DataSourcesMapper
{
SysID = monitorPoint.MonitorPointID,
SignID = monitorPoint.TagName
};
if (monitorPoint.UnitType == Unit.eUnitType.压力)
{
if (monitorPoint.Flags != null)
{
if (monitorPoint.Flags.Contains(IStation.Flags.出口))
{
mapper.Coefficients = new Coefficients();
mapper.Coefficients.A = 0.001; //kpa>map
}
else
{
mapper.Coefficients = new Coefficients();
mapper.Coefficients.A = 0.00981;//m>map
}
}
}
importMappers.Add(mapper);
}
return Import(importMappers);
}
///
/// 导入
///
public static bool Import(List mapperList)
{
if (mapperList == null || mapperList.Count < 1)
return false;
var monitorPointIds = mapperList.Select(x => x.SysID).Distinct().ToList();
var monitorList = new BLL.MonitorPoint().GetExSignalListByIds(monitorPointIds);
if (monitorList == null || monitorList.Count < 1)
return false;
var fileDlg = new OpenFileDialog();
fileDlg.Title = "历史数据导入";
fileDlg.Filter = "CSV文档|*.csv";
fileDlg.Multiselect = true;
fileDlg.AutoUpgradeEnabled = true;
if (fileDlg.ShowDialog() != DialogResult.OK)
{
return false;
}
var fileNames = fileDlg.FileNames?.ToList();
if (fileNames == null || fileNames.Count < 1)
return false;
var dockingList = new List();
foreach (var monitor in monitorList)
{
var mapper = mapperList.Find(x => x.SysID == monitor.ID);
var dockingModel = new MonitorDataImportModel();
var signal = monitor.SignalList.First();
dockingModel.MonitorPointID = monitor.ID;
dockingModel.SignalId = signal.ID;
dockingModel.TagName = mapper.SignID;
dockingModel.Coefficients = mapper.Coefficients;
dockingList.Add(dockingModel);
}
var waitDlg = new WaitMonitorDataImportDlg();
waitDlg.SetBindingData(dockingList, fileNames);
if (waitDlg.ShowDialog() != DialogResult.OK)
return false;
return true;
}
}
}