schangxiang@126.com
2025-11-04 f5ed29dc26c7cd952d56ec5721a2efc43cd25992
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
302
303
304
305
306
307
308
using DataEntity.Device;
using DataEntity.Share;
using DataRWDAL;
using DataRWDAL.Device;
using HandyControl.Data;
using HxEnum;
using HxSocketImplement.Sockets;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Input;
using System.Xml;
using XCommon;
using XCommon.Log;
using XCommon.Tip;
using XHandler.Class.DataEx;
using XHandler.Controls.Run.Com;
using XHandler.View.MethodProperty;
using XImagingXhandler.XDAL;
using static HxEnum.StateEnum;
 
namespace XHandler.View
{
    /// <summary>
    /// 设备编辑 页面
    /// </summary>
    public partial class RunAgoTips : System.Windows.Window
    {
        #region 参数 
        private RunWnd m_lauchView = null;
        private ObservableCollection<DeviceStatusData> m_deviceStatusList = new ObservableCollection<DeviceStatusData>();
        #endregion
 
        #region 构造函数
        /// <summary>
        /// 构造函数
        /// </summary>
        public RunAgoTips(RunWnd lauchView)
        {
            InitializeComponent();
            m_lauchView = lauchView;
            this.Owner = (Window)Shared.Main;
        }
        #endregion
 
        #region 初始化
        /// <summary>
        /// 初始化,枪头盒不支持叠放
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                #region 枪头类型 
                var platformNodeList = m_lauchView.xmlDocument.SelectSingleNode("root/env").SelectNodes("platform");
 
                // 从台面获取所有枪头
                List<Labware> labwares = new List<Labware>();
                foreach (XmlNode platformNodeItem in platformNodeList)
                {
                    var a = platformNodeItem.SelectNodes("labware");
                    if (platformNodeItem.SelectNodes("labware")==null|| platformNodeItem.SelectNodes("labware").Count==0)
                    {
                        continue;
                    }
                    string labwareId = platformNodeItem.SelectNodes("labware")[0].SelectSingleNode("labware_id").InnerText;
                    if(labwareId==null||labwareId.Equals(string.Empty))
                    {
                        continue;
                    }
                    Labware labWare = LabwareDB.GetLabware(labwareId);
 
                    if (labWare.labware_type_id == EnumManagement.GetEnumValue(ConsumableTypeEnum.TipsBox).ToString())  // 吸头盒
                    {
                        labwares.Add(labWare);
                    }
                }
 
                labwares = labwares.Distinct().ToList();
                labwares = labwares.GroupBy(item => item.labware_id).Select(group => group.First()).ToList();
 
                comboboxLabwareType.ItemsSource = labwares;
                if (labwares.Count > 0)
                {
                    comboboxLabwareType.SelectedIndex = 0;
                }
                #endregion
 
                #region 设备状态
                var deviceConfigResult = DeviceConfigDB.GetDeviceConfigListByProjectId(Shared.SoftwareInformation.software_information_id);
 
                foreach (var item in deviceConfigResult)
                {
                    DeviceStatusData deviceStatus = new DeviceStatusData();
                    deviceStatus.DeviceName = item.Name;
                    deviceStatus.DeviceId = item.EquipmentId;
                    deviceStatus.VirtualConnectionState = item.VirtualConnectionState == EnumManagement.GetEnumValue(VirtualConnectionStateEnum.Virtually) ? "是" : "否";
 
                    if (item.CommunicateType == EnumManagement.GetEnumValue(CommunicateTypeEnum.Socket))    //Socket
                    {
                        var checkConnectedResult = HxSocketParameterService.CheckConnected(item.Type, item.Ip, Convert.ToInt32(item.Port), item.EquipmentId);
                        if (checkConnectedResult != null && checkConnectedResult.status == StateEnum_Equipment.Completed)
                        {
                            deviceStatus.DeviceStatus = true;
                        }
                        else
                        {
                            deviceStatus.DeviceStatus = false;
                        }
                    }
 
                    m_deviceStatusList.Add(deviceStatus);
                }
 
                dgDeviceData.ItemsSource = m_deviceStatusList;
                #endregion
            }
            catch (Exception ex)
            {
                LoggerHelper.ErrorLog("ERROR:", ex);
            }
        }
        #endregion
 
        #region 清除缓存数据
        /// <summary>
        /// 清除缓存数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
 
        private void btnClearData_Click(object sender, RoutedEventArgs e)
        {
            if (m_lauchView != null)
            {
                // 清除Tip缓存数据
                ControlCom.ClearTipData(m_lauchView);
            }
 
            string directoryBase = System.AppDomain.CurrentDomain.BaseDirectory;
            string xmlFilePath = directoryBase + "Config\\" + "CurrentUsedTips.xml";
            if (File.Exists(xmlFilePath))
            {
                File.Delete(xmlFilePath);
            }
        }
        #endregion
 
        #region 确定
        /// <summary>
        /// 确定
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnOk_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = true;
            this.Close();
        }
        #endregion
 
        #region 拖动窗体
        /// <summary>
        /// 拖动窗体
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Grid_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if (e.ChangedButton == MouseButton.Left)
            {
                this.DragMove();
            }
        }
        #endregion
 
        #region 关闭页面
        /// <summary>
        /// 关闭页面
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnClose_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
            this.Close();
        }
        #endregion
 
        #region ESC关闭画面
        /// <summary>
        /// ESC关闭画面
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Window_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Escape)
            {
                this.DialogResult = false;
                this.Close();
            }
        }
        #endregion
 
        #region 枪头类型选择变更
        private void comboboxLabwareType_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
        {
            if (comboboxLabwareType.SelectedIndex < 0)
            {
                return;
            }
 
            // 根据选择的类型加载枪头数量
            if (m_lauchView.xmlDocument != null)
            {
                Labware labwareT = (Labware)(comboboxLabwareType.SelectedItem as Labware);
                XmlNode latticeXn = m_lauchView.xmlDocument.SelectSingleNode("root/env");
 
                //XmlNodeList labwareNode = latticeXn.SelectNodes("platform[lattice_id=" + ControlCom.GetLatticeId(Convert.ToInt32(gripTransportData.srcPositionValue), false) + "]/labware");
                //int countOfLabware = labwareNode.Count;
                //var latticeDes = latticeXn.SelectSingleNode("platform[lattice_id=" + ControlCom.GetLatticeId(Convert.ToInt32(gripTransportData.srcPositionValue), false) + "]/labware[@id=" + (countOfLabware - gripTransportData.transportCount + 1).ToString() + "][labware_id='" + labwareT.labware_id + "']");
 
                XmlNodeList platFormXmlNodeList = latticeXn.SelectNodes("platform");// [labware_id='" + labwareT.labware_id + "']");
                int totalCountTip = ((int)labwareT.number_row * (int)labwareT.number_column);
 
                int usedAllTotalTips = 0;
                foreach (XmlNode p in platFormXmlNodeList)
                {
                    XmlNodeList labwareNodeList = p.SelectNodes("labware");
                    int countOfLabware = labwareNodeList.Count;
                    XmlNode xn= p.SelectSingleNode("labware[@id=" + (countOfLabware).ToString() + "][labware_id='" + labwareT.labware_id + "']");
 
                    if (xn != null)
                    {
                        List<string> lstResidueValidWells = ComUtility.GetValidWells(xn.SelectSingleNode("residueValidWells").InnerText);
                        usedAllTotalTips = usedAllTotalTips + (totalCountTip - lstResidueValidWells.Count());
                    }
                }
                tbkUsedCount.Text = usedAllTotalTips.ToString();
            }
        }
        #endregion
 
        #region 当前类型重置
        /// <summary>
        /// 当前类型重置
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnResetCurrentTipType_Click(object sender, RoutedEventArgs e)
        {
            if(comboboxLabwareType.SelectedIndex<0)
            {
                ShowTip.ShowNotice("请选择枪头类型", InfoType.Warning);
                return;
            }
 
            Labware labwareTip = (Labware)(comboboxLabwareType.SelectedItem as Labware);
 
            if (m_lauchView != null)
            {
                // 清除Tip缓存数据
                ControlCom.ClearTipData(m_lauchView, labwareTip);
            }
 
            string directoryBase = System.AppDomain.CurrentDomain.BaseDirectory;
            string xmlFilePath = directoryBase + "Config\\" + "CurrentUsedTips.xml";
            if (File.Exists(xmlFilePath))
            {
                File.Delete(xmlFilePath);
            }
 
            tbkUsedCount.Text = "0";
            ShowTip.ShowNotice("重置成功", InfoType.Success);
        }
        #endregion
 
        /// <summary>
        /// 全部重置
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnResetAllTipType_Click(object sender, RoutedEventArgs e)
        {
            if (m_lauchView != null)
            {
                // 清除Tip缓存数据
                ControlCom.ClearTipData(m_lauchView);
            }
 
            string directoryBase = System.AppDomain.CurrentDomain.BaseDirectory;
            string xmlFilePath = directoryBase + "Config\\" + "CurrentUsedTips.xml";
            if (File.Exists(xmlFilePath))
            {
                File.Delete(xmlFilePath);
            }
 
            tbkUsedCount.Text = "0";
            ShowTip.ShowNotice("重置成功", InfoType.Success);
        }
    }
}