duheng
2025-03-18 7ee0220b5f5626deef516b6e5c417bfa201e5a88
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
using Yw;
using Yw.WinFrmUI;
 
namespace IBox.WinFrmUI
{
    public partial class IBoxFormOverview : DocumentPage
    {
 
        //private string startCode = "[&start&]";
        //private string endCode = "[&end&]";
        //private string paramCode = "[&param&]";
        //private string getbaseCode = "getbase";
        //private string getrealrecordCode = "getrealrecord";
        //private string gethistoryrecordCode = "gethistoryrecord";
        //private string getalarmbydayCode = "getalarmbyday";
        //private string getbysignalidofdayrangeCode = "getbysignalidofdayrange";
 
        //Stopwatch sw = new Stopwatch();
        //string swstr=string.Empty;
        private List<MonitorValueAlarmRecord> monitorValueAlarmRecords = new List<MonitorValueAlarmRecord>();
 
        private List<DataGridMonitorViewModel> dataGridMonitorViewModels = new List<DataGridMonitorViewModel>();
        private List<PumpRunStatusViewModel> pumpRunStatusModels = new List<PumpRunStatusViewModel>();
        private List<PumpEnergyViewModel> pumpEnergyViewModels = new List<PumpEnergyViewModel>();
 
        public IBoxFormOverview()
        {
            this.PageTitle.Caption = "泵组总览";
            InitializeComponent();
 
        }
 
        
        private void EboxForm_Load(object sender, EventArgs e)
        {
            Thread.Sleep(500);
            SendText(IBoxHelper.startCode + IBoxHelper.getbaseCode + IBoxHelper.paramCode + IBoxHelper.endCode);
 
        }
 
        private List<DataGridMonitorViewModel> dataList = null;
 
        /// <summary>
        /// 绑定数据
        /// </summary>
        /// <param name="list"></param>
        /// <param name="isBlue"></param>
        /// <returns></returns>
        public async Task<int> BindGrid(List<StationMonitorListGroupMobileDto> list, bool isBlue = true)
        {
            dataList = new List<DataGridMonitorViewModel>();
            foreach (var item in list)
            {
                foreach (var ml in item.MonitorList)
                {
                    dataList.Add(new DataGridMonitorViewModel()
                    {
                        DataTime = !ml.DataTime.HasValue ? "-" : ml.DataTime?.ToString("yyyy-MM-dd HH:mm:ss"),
                        DataValue = string.IsNullOrEmpty(ml.DataValue) ? "-" : ml.DataValue,
                        GroupID = item.ID,
                        GroupName = item.Name,
                        MonitorName = ml.Name,
                        SignalID = ml.SignalID,
                        UnitName = ml.UnitName,
                        DataStatus = ml.DataStatus,
                    });
                }
            }
 
            if (isBlue)
            {
                this.Invoke(new Action(() =>
                {
                    dataGridMonitorViewModels = dataList;
                    this.bindingSource1.DataSource = dataGridMonitorViewModels;
                }));
            }
            else
            {
                dataGridMonitorViewModels = dataList;
                this.bindingSource1.DataSource = dataGridMonitorViewModels;
            }
 
            return 0;
        }
               
 
        private void gridView3_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
        {
            var b = gridView3.GetRow(e.RowHandle) as PumpRunStatusViewModel;
 
            if (e.Column.FieldName.Equals("ContinutRunTime"))
            {
                e.DisplayText = ConvertToText(b.ContinutRunTime);
            }
            if (e.Column.FieldName.Equals("TotalRunTime"))
            {
                e.DisplayText = ConvertToText(b.TotalRunTime);
            }
            if (e.Column.FieldName.Equals("RunStatus"))
            {
                var s = "关机";
                e.Appearance.ForeColor = Color.LightSlateGray;
                switch (b.RunStatus)
                {
                    case 1:
                        s = "开机";
                        e.Appearance.ForeColor = Color.Green;
                        break;
                }
                e.DisplayText = s;
            }
        }
 
        private string ConvertToText(long? minite)
        {
            if (!minite.HasValue)
                return "";
            long minites = minite.Value;
            long days = minites / 60 / 24;
            long hours = 0;
            if (days > 0)
                hours = (minites - (days * 1440)) / 60;
            else hours = minites / 60;
            long minitesLeft = minites % 60;
            if (days > 0)
                return $"{days}天{hours}小时{minitesLeft}分钟";
            else return $"{hours}小时{minitesLeft}分钟";
        }
 
        public event EventHandler<string> SendData;
        private void SendText(string content)
        {
            //BluetoothHelper.GetInstance().SendData(content);
            SendData?.Invoke(null, content);
        }
    }
}