using DevExpress.Emf; using DevExpress.XtraTreeList; using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace IStation.WinFrmUI.Monitor { public class HistoryDataHelper { public HistoryDataHelper(DateTime dateTime, double water, double electricity, string pump1,string pump2 ,string pump3 ,string pump4, string pump5) { this.DateTime = dateTime; this.water = water; this.electricity = electricity; this.pump1 = pump1; this.pump2 = pump2; this.pump3 = pump3; this.pump4 = pump4; this.pump5 = pump5; //timesspan = new span(); } public HistoryDataHelper() { } /// /// 时间 /// public DateTime DateTime { get; set; } /// /// 用水量 /// public double water { get; set; } /// /// 用电量 /// public double electricity { get; set; } /// public string pump1 { get; set; } public string pump2 { get; set; } public string pump3 { get; set; } public string pump4 { get; set; } public string pump5 { get; set; } private List _historyDataHelpers = new List(); public List GetHistoryData() { string path = System.IO.Path.Combine(IStation.DataFolderHelper.GetRootPath(), "二取机泵参数", "二取参数.csv"); if (!File.Exists(path)) return null; int totalLines = File.ReadLines(path, Encoding.GetEncoding("gb2312")).Count();//总行数 System.IO.FileStream fs = new System.IO.FileStream(path, System.IO.FileMode.Open); System.IO.StreamReader sr = new System.IO.StreamReader(fs, Encoding.GetEncoding("gb2312")); string tempText; int line = 0; while ((tempText = sr.ReadLine()) != null) { line++; string[] arr = tempText.Split(new char[] { ',' }); //一般第一行为标题,所以取出来作为标头 _historyDataHelpers.Add(new HistoryDataHelper(Convert.ToDateTime(arr[0]), Convert.ToDouble(arr[1]), Convert.ToDouble(arr[2]), arr[3], arr[4], arr[5], arr[6], arr[7])); } //关闭流 sr.Close(); fs.Close(); // List historyModels= GetDataModel(); return _historyDataHelpers; } HistoryModel historyModel = new HistoryModel(); List historyModels = new List(); List timespan1List = new List(); List timespan2List = new List(); List timespan3List = new List(); List timespan4List = new List(); List timespan5List = new List(); public List GetDataModel( List< HistoryDataHelper> historyDataHelper) { foreach (var item in historyDataHelper) { string[] arr = item.pump1.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); foreach (var itm in arr) { string[] time = itm.Split(new char[] { '~' }); if (time.Length > 1) timespan1List.Add(new span { StartTime = time[0], EndTime = time[1] }); } string[] arr2 = item.pump2.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); foreach (var itm in arr2) { string[] time = itm.Split(new char[] { '~' }); if (time.Length > 1) timespan2List.Add(new span { StartTime = time[0], EndTime = time[1] }); } string[] arr3 = item.pump3.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); foreach (var itm in arr3) { string[] time = itm.Split(new char[] { '~' }); if (time.Length > 1) timespan3List.Add(new span { StartTime = time[0], EndTime = time[1] }); } string[] arr4 = item.pump4.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); foreach (var itm in arr4) { string[] time = itm.Split(new char[] { '~' }); if (time.Length > 1) timespan4List.Add(new span { StartTime = time[0], EndTime = time[1] }); } string[] arr5 = item.pump5.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); foreach (var itm in arr5) { string[] time = itm.Split(new char[] { '~' }); if (time.Length > 1) timespan5List.Add(new span { StartTime = time[0], EndTime = time[1] }); } historyModel = new HistoryModel { DateTime = item.DateTime, water = item.water, timespan1=timespan1List, timespan2=timespan2List, timespan3 = timespan3List, timespan4 = timespan4List, timespan5 = timespan5List, }; historyModels.Add(historyModel); timespan1List = new List(); timespan2List = new List(); timespan3List = new List(); timespan4List = new List(); timespan5List = new List(); } return historyModels; } } } /* private List GetData( List result,string name) { List onTime = new List(); onTime.Clear(); List timeList = new List(); string StartTime = null; string EndTime = null; string Time = null; for (int day = 0; day < result.Count(); day += 288) //最外层循环 控制一天一天的循环 { bool allZero = true; for (int time = day; time < day + 288 && time < result.Count; time++) //内层循环,在当天每个时间进行循环 { if (result[time].state == 1) { allZero = false; StartTime = result[time].DateTime.ToString("HH:mm"); EndTime = result[time].DateTime.ToString("HH:mm"); for (int k = time + 1; k < day + 288 && k < result.Count; k++) //k为从开机后比较的变量下标 { if (result[k].state ==1) { EndTime = result[k].DateTime.ToString("HH:mm"); time = k; } else break; } Time = $"{name}:{StartTime}~{EndTime}"; timeList.Add(Time); } } if (allZero) //如果一天都没有开泵,就添加一条空 { timeList.Add(null); } var connect = string.Join($"\n", timeList); //把一天中可能有好几条的list添加到一个list onTime.Add(connect); timeList.Clear(); *//* StartTime = null;*/