tx
2025-04-09 fa7510e1ed63df0366787fa4ed1b3db6426d2b46
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
using DevExpress.XtraEditors;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using TProduct.Model;
 
namespace TProduct.WinFrmUI.TValve
{
    /// <summary>
    /// 性能测试
    /// </summary>
    public partial class FeatTestIngMainPage : TestIngBaseMainPage
    {
        //通讯辅助类
        private TProduct.Link.LinkBaseHelper _linkHelper = null;
        //是否正在测试
        protected bool _isIngTestStatus = false;
        //仪表盘控件
        private Dictionary<long, TProduct.WinFrmUI.TBase.UserGaugeControl> _allMonitorGaugeDict = null;
        //列表控件
        private GridFeatMonitorRecordCtrl _monitorGridCtrl = null;
        //图表控件
        private ChartValveFeatCurveCtrl _chartMainCtrl = null;
        //步骤操作控件
        private TProduct.WinFrmUI.TBase.CommConBaseCtrl _commCtrl = null;
        //自动测试表
        private FeatTestAutoParasCtrl _autoTestInfoCtrl = null;
        //日志控件
        private TBase.TestItemLogContentCtrl _testLogCtrl = null;
        //产品信息
        private PartInfoCtrl _partInfoCtrl = null;
        //所有记录
        private List<TProduct.Model.ValveFeatTestRecordViewModel> _allRecords = null;
        public int GetTestRecordCount()
        {
            if (_allRecords == null)
                return 0;
            return _allRecords.Count();
        }
        //数据记录辅助类
        private MonitorValveIngRecordHelper _monitorValveIngRecordHelper = null;
        //
        private TProduct.Model.TestStandard _testStandard = null;
 
        /// <summary>
        /// 构造函数
        /// </summary>
        public FeatTestIngMainPage()
        {
            InitializeComponent();
 
            this.PageTitle.Caption = "性能测试";
            this.tabPageLinkLog.PageVisible =
                TProduct.UserSetting.Setting.Disp.IsShowLog;
        }
 
        public override void Close()
        {
            if (_realTimeChart != null)
                _realTimeChart.Stop();
 
            base.Close();
 
            DisconectCommPort();
        }
 
        //能否关闭对话框
        public virtual bool IsCloseFrmAble()
        {
            if (_durabilityTestTimeHelper != null)
            {
                if (_durabilityTestTimeHelper.IsTesting())
                {
                    MessageBox.Show("请先停止耐力试验,再关闭对话框");
 
                    return false;
                }
            }
            if (_isIngTestStatus)
            {
                DialogResult result = MessageBox.Show("请问是否关闭", "询问",
    System.Windows.Forms.MessageBoxButtons.YesNo,
    System.Windows.Forms.MessageBoxIcon.Warning);
                if (result != DialogResult.Yes)
                {
                    return false;
                }
 
                DisconectCommPort();
            }
            if (_realTimeChart != null)
                _realTimeChart.Stop();
 
            return true;
        }
 
        #region 收到信息/发送消息
        //收到信息
        private void ReceiveIntrumentMonitorValue(List<TProduct.Model.MonitorPointValue> receiveMessagesInfos)
        {
            if (receiveMessagesInfos == null)
                return;
            //放到辅助类进行修正
            List<TProduct.Model.MonitorPointValuePure> items =
                this._monitorValveIngRecordHelper.SetMonitorValue(receiveMessagesInfos);
 
            //仪表控件
            foreach (var measValue in items)
            {
                if (_allMonitorGaugeDict.ContainsKey(measValue.ID))
                    _allMonitorGaugeDict[measValue.ID].RefreshRecordValue(measValue.Value);
            }
 
            //三维控件
            //if (this._model3dCtrl != null)
            //{
            //    this._model3dCtrl.RefreshMonitorValue(items);
            //}
        }
 
        //附加信息
        private void RefreshAdditionInfo(
            Dictionary<string, string> additionInfos)
        {
            if (_isRefreshAdditionInfo == false)
                return;
            if (additionInfos == null)
                return;
 
            if (TProduct.CorpConfig.Instance.CorpFlag == eCorpFlag.WH701)
            {
                RefreshAdditionInfo武汉701(additionInfos);
            }
            _isRefreshAdditionInfo = false;
        }
 
        #endregion
 
        #region 修改Comm链接状态
        private bool ChangeCommConnectStatus(bool isConnect)
        {
            if (isConnect)
            {
                return ConectCommPort();
            }
            else
            {
                return DisconectCommPort();
            }
        }
        /// <summary>
        /// 是否链接过COM口
        /// </summary>
        private bool _isConnetctCommPort = false;
        public bool IsConnetctCommPort
        {
            get { return _isConnetctCommPort; }
        }
        /// <summary>
        /// 链接COM口 
        /// </summary>
        private bool ConectCommPort()
        {
            if (_linkHelper == null)
            {
                XtraMessageBox.Show("设备初始化失败!Error:79");
                return false;
            }
 
 
            _isConnetctCommPort = true;
 
            //开始
            string error_info = null;
            if (!_linkHelper.Start(out error_info))
            {
                XtraMessageBox.Show(error_info);
                return false;
            }
            if (this._monitorValveIngRecordHelper != null)
            {
                _monitorValveIngRecordHelper.Start();
            }
            //通知操作组件
            if (_recordOperateCtrl != null)
            {
                _recordOperateCtrl.SetCommConnectStatus(true);
            }
 
            //实时图表
            if (_realTimeChart != null)
                _realTimeChart.Start();
 
            //设置最后一次测试信息
            RefreshLastTestInfo();
 
            bsiOperateInfo.Caption = "已链接COM口";
 
 
            this._isIngTestStatus = true;
 
            return true;
        }
        public void RefreshLastTestInfo()
        {
            var user = TProduct.WinFrmUI.GlobeParas.CurrentLoginUser;
            if (user == null)
                return;
            if (_currentPart != null)
            {
                new BLL.PartBase().UpdateLastTestUserID(_currentPart.ID, user.ID);
            }
            if (_workBenchInfo != null)
            {
                new BLL.WorkBenchBase().UpdateLastTestUserID(_workBenchInfo.ID, user.ID);
            }
            if (this._testItem.TestStartTime == null)
            {
                this._testItem.TestStartTime = DateTime.Now;
                new BLL.TestProjectItem().RefreshTestStartTime(this._testItem.ItemID);
            }
        }
 
        /// <summary>
        /// 结束测试,断开链接
        /// </summary>
        public bool DisconectCommPort()
        {
            if (_recordOperateCtrl != null)
            {//在Stop之前, 因为还要调用COM口
                _recordOperateCtrl.SetCommConnectStatus(false);
            }
 
            string error_info = null;
            if (!_linkHelper.Stop(out error_info))
            {
                MessageBox.Show(error_info);
            }
 
 
            this._isIngTestStatus = false;
 
            //if (_durabilityTestTimeHelper != null)
            //{
            //    _durabilityTestTimeHelper.SetStop();
            //}
            if (this._monitorValveIngRecordHelper != null)
            {
                this._monitorValveIngRecordHelper.Stop();
            }
            if (_realTimeChart != null)
                _realTimeChart.Stop();
 
 
            this._testItem.TestEndTime = DateTime.Now;
            new BLL.TestProjectItem().RefreshTestEndTime(this._testItem.ItemID);
 
 
            bsiOperateInfo.Caption = "已断开COM口";
 
            return true;
        }
        public void CheckTestEndTime()
        {
            if (this._testItem.TestStartTime == null)
                return;
            if (this._isIngTestStatus)
            {
                if (this._testItem.TestEndTime == null)
                {
                    this._testItem.TestEndTime = DateTime.Now;
                    new BLL.TestProjectItem().RefreshTestEndTime(this._testItem.ItemID);
                }
                else if (this._testItem.TestEndTime.Value <= this._testItem.TestStartTime.Value)
                {
                    this._testItem.TestEndTime = DateTime.Now;
                    new BLL.TestProjectItem().RefreshTestEndTime(this._testItem.ItemID);
                }
            }
        }
 
        #endregion
 
 
 
 
        public Action OnCloseAndView = null;
        private void bbi关闭并查看_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (OnCloseAndView != null)
                OnCloseAndView.Invoke();
        }
 
        private bool _isRefreshAdditionInfo = false;
        private void bbi刷新状态信息_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            _isRefreshAdditionInfo = true;
        }
    }
}