duheng
2025-04-24 4de480ec624d3b79ca690dc906e10cd2fbdc9be7
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
90
91
92
93
94
95
96
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Xml;
 
namespace IStation.WinFrmUI.Monitor
{
    /// <summary>
    /// 常规监测数据导入辅助类
    /// </summary>
    public class MonitorDataImportHelper
    {
        public static bool Import()
        {
            var monitorPoints = new BLL.MonitorPoint().GetAllExSignalExSignalType();
            if (monitorPoints == null || !monitorPoints.Any())
                return false;
            var importMappers = new List<DataSourcesMapper>();
            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);
        }
 
 
        /// <summary>
        /// 导入
        /// </summary>
        public static bool Import(List<DataSourcesMapper> 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<MonitorDataImportModel>();
            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;
        }
 
    }
}