schangxiang@126.com
2025-11-04 ca398287db3f5ea01f03aac4a85edb13b28100a6
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
309
310
311
312
313
314
using DataEntity.Share;
using DriverLib.Engine;
using HxSocket;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Windows;
using System.Windows.Media;
using System.Xml;
using XCommon;
using XCommon.Log;
using XCore;
using XHandler.Class;
using XHandler.Controls.Run.Com;
using XHandler.View;
using XHandler.View.MethodProperty;
using XImagingXhandler.XDAL;
 
namespace XHandler.Controls
{
    /// <summary>
    /// 文件移液控制逻辑类
    /// </summary>
    public class TransferFileControl
    {
        #region 类内变量、引用类对象实例等
        string strCurrentCulture = "";
        WellCalc wellCalc = new WellCalc();
        LatticeBll latticeBll = new LatticeBll();
        AspirateBll aspirateBll = new AspirateBll();
        public RunWnd launchView = null;
        MethodFrame methodFrame = new MethodFrame();
        CoatingFileBll coatingFileBll = new CoatingFileBll();
        CoatingBll coatingBll = new CoatingBll();
        //Operate.UIElement uiElement = new Operate.UIElement();//控件元素操作类对象
        TransferFileBll transferFileBll = new TransferFileBll();
        DispenseBll dispenseBll = new DispenseBll();
        LoadTipsBll loadTipsBll = new LoadTipsBll();
        public HxSocketClient socketTcpClientToRemote = null;
        #endregion
 
        public TransferFileControl(string strCurrentCulture)
        {
            this.strCurrentCulture = strCurrentCulture;
        }
 
        #region 加载文件数据
        /// <summary>
        /// 加载文件数据
        /// </summary>
        /// <param name="methodName"></param>
        /// <param name="file"></param>
        /// <returns></returns>
        private DataTable GetFileData(string methodName, string file)
        {
            DataTable transferData = null;
            if (!File.Exists(file))
            {
                if (strCurrentCulture.Equals("zh-CN"))
                {
                    launchView.AddLogs($"【{DateTime.Now.ToString("HH:mm:ss:fff")}】> Xhandler: 【{methodName}】{Properties.TransferFileResource.strFileNotExists} {file}");
                }
                else
                {
                    launchView.AddLogs($"【{DateTime.Now.ToString("HH:mm:ss:fff")}】> Xhandler: 【{methodName}】file not exists: {file}");
                }
 
                return transferData;
            }
 
            string ext = Path.GetExtension(file);
            if (string.Compare(ext, ".csv", true) == 0)
            {
                transferData = ExcelAndCsvHelper.GetDataTableFromCsvFile(file, false);
            }
            else
            {
                transferData = ExcelAndCsvHelper.GetDataTableFromExcelFile(file, true);
            }
 
            return transferData;
        }
        #endregion
 
        #region 执行移液文件,返回结果字符串
        /// <summary>
        /// 执行移液文件,返回结果字符串
        /// </summary>
        /// <param name="xmlEnv">所有放板的板位</param>
        /// <param name="methodNode">装载方法属性节点对象</param>
        /// <param name="channelNums">本次使用的通道</param>
        /// <param name="currentLengthOfTip">当前已加载的Tip头后枪增加的长度</param>
        /// <param name="zAxisVal">z轴安全距离</param>
        /// <param name="isSimulator">false:连接谁;true:仿真</param>
        /// <returns></returns>
        public bool ExecuteTransferFile(XmlNode xmlEnv, XmlNode methodNode, float zAxisVal, bool isSimulator)
        {
            bool result = true;
            var platformNodeList = xmlEnv.SelectNodes("platform");
            string methodName = methodNode.SelectSingleNode("name").InnerText;
 
            if (launchView._cancelSource.IsCancellationRequested)
            {
                result = false;
                return result;
            }
 
            if (strCurrentCulture.Equals("zh-CN"))
            {
                launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】> Xhandler: 【" + methodName + "】" + Properties.MachineRunResource.strStart.ToString());
            }
            else
            {
                launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】> Xhandler: 【" + methodName + "】start:");
            }
 
            #region 数据准备 
            string labwaretipText = methodNode.SelectSingleNode("labwaretip/text").InnerText;
            string strlabwaretipId = methodNode.SelectSingleNode("labwaretip/value").InnerText;
            string channelNums = methodNode.SelectSingleNode("channels").InnerText;
            string armName = methodNode.SelectSingleNode("arm/text").InnerText;
            string armId = methodNode.SelectSingleNode("arm/value").InnerText;
            string filePath = methodNode.SelectSingleNode("filePath").InnerText;
            int beginLine = Convert.ToInt32(methodNode.SelectSingleNode("beginLine").InnerText);
 
            MethodTransferFile methodTransferFile = methodFrame.GenerateMethodTransferFile(methodNode);//获取移液表
            methodTransferFile.transferDataTable = GetFileData(methodName, methodNode.SelectSingleNode("filePath").InnerText);
            string cnSourceLabware = methodNode.SelectSingleNode("sourceLabware").InnerText;//来源板列名
            string cnSourceWell = methodNode.SelectSingleNode("sourceWell").InnerText;//来源孔列名
            string cnDestinationLabware = methodNode.SelectSingleNode("destinationLabware").InnerText;//目标板列名
            string cnDestinationWell = methodNode.SelectSingleNode("destinationWell").InnerText;//目标孔列名
            string cnDestVolume = methodNode.SelectSingleNode("destVolume").InnerText;//目标体积列名
            string cnTipSet = methodNode.SelectSingleNode("tipSet").InnerText;//Tip设置
 
            int cnChangeTipsMode = Convert.ToInt32(methodNode.SelectSingleNode("changeTipsMode").InnerText);//更换枪头设置
            string cnChangeToTipText = methodNode.SelectSingleNode("changeToTipText").InnerText;//更换枪头设置下拉项名称
            string cnChangeToTipValue = methodNode.SelectSingleNode("changeToTipValue").InnerText;//更换枪头设置下拉项Id
            bool cnJump0Volume = methodNode.SelectSingleNode("jump0Volume").InnerText.ToLower() == "true" ? true : false;//是否跳过为0的体积
 
            string cnLiquididText = methodNode.SelectSingleNode("liquidid/text").InnerText;//液体名称
            string cnLiquididValue = methodNode.SelectSingleNode("liquidid/value").InnerText;//液体Id
            string cnliquidrangeidText = methodNode.SelectSingleNode("liquidrangeid/text").InnerText;//液体范围名称
            string cnliquidrangeidValue = methodNode.SelectSingleNode("liquidrangeid/value").InnerText;//液体范围Id
            string cnliquidpidText = methodNode.SelectSingleNode("liquidpid/text").InnerText;//液体参数名称
            string cnliquidpidVaue = methodNode.SelectSingleNode("liquidpid/value").InnerText;//液体参数Id
 
            bool enableMix = methodNode.SelectSingleNode("enableMix").InnerText.ToLower() == "true" ? true : false;//是否混合
            double mixvolume = Convert.ToDouble(methodNode.SelectSingleNode("mixvolume").InnerText);//混合体积
            int mixcount = Convert.ToInt32(methodNode.SelectSingleNode("mixcount").InnerText);//混合次数
            string mixAspiratePositionText = methodNode.SelectSingleNode("mixAspiratePosition/text").InnerText;//吸液混合位置名称
            string mixAspiratePositionValue = methodNode.SelectSingleNode("mixAspiratePosition/value").InnerText;//吸液混合位置Id
            double mixAspirateDistance = Convert.ToDouble(methodNode.SelectSingleNode("mixAspirateDistance").InnerText);//吸液混合时距离
            double mixAspirateSpeed = Convert.ToDouble(methodNode.SelectSingleNode("mixAspirateSpeed").InnerText);//吸液混合时速度
 
            string mixDispensePositionText = methodNode.SelectSingleNode("mixDispensePosition/text").InnerText;//排液混合位置名称
            string mixDispensePositionValue = methodNode.SelectSingleNode("mixDispensePosition/value").InnerText;//排液混合位置Id
            double mixDispenseDistance = Convert.ToDouble(methodNode.SelectSingleNode("mixDispenseDistance").InnerText);//排液混合时距离
            double mixDispenseSpeed = Convert.ToDouble(methodNode.SelectSingleNode("mixDispenseSpeed").InnerText);//排液混合时速度
 
            bool enableLiquidSensor = methodNode.SelectSingleNode("enableLiquidSensor").InnerText.ToLower() == "true" ? true : false;
            int liquidSensorCount = Convert.ToInt32(methodNode.SelectSingleNode("liquidSensorCount").InnerText);
            double liquidSensorDistance = Convert.ToDouble(methodNode.SelectSingleNode("liquidSensorDistance").InnerText);
            double liquidSensorEndDistance = Convert.ToDouble(methodNode.SelectSingleNode("liquidSensorEndDistance").InnerText);
            double liquidSensorSpeed = Convert.ToDouble(methodNode.SelectSingleNode("liquidSensorSpeed").InnerText);
            double liquidSensorRadio = Convert.ToDouble(methodNode.SelectSingleNode("liquidSensorRadio").InnerText);
            string liquidSensorDisIdText = methodNode.SelectSingleNode("liquidSensorDisId/text").InnerText;
            string liquidSensorDisIdValue = methodNode.SelectSingleNode("liquidSensorDisId/value").InnerText;
            bool enableLiquidFollow = methodNode.SelectSingleNode("enableLiquidFollow").InnerText.ToLower() == "true" ? true : false;
            int liquidFollowType = Convert.ToInt32(methodNode.SelectSingleNode("liquidFollowType/value").InnerText);
            string liquidFollowTypeName = methodNode.SelectSingleNode("liquidFollowType/text").InnerText;
            double liquidFollowSpeed = Convert.ToDouble(methodNode.SelectSingleNode("liquidFollowSpeed").InnerText);
            double liquidFollowDistance = Convert.ToDouble(methodNode.SelectSingleNode("liquidFollowDistance").InnerText);
            double liquidFollowArea = Convert.ToDouble(methodNode.SelectSingleNode("liquidFollowArea").InnerText);
            bool enableMixFollow = methodNode.SelectSingleNode("enableMixFollow").InnerText.ToLower() == "true" ? true : false;
 
            bool enableSensorBlock = methodNode.SelectSingleNode("enableSensorBlock").InnerText.ToLower() == "true" ? true : false;//是否开启堵塞探测
            //double liquidSensorBlockDistance = Convert.ToDouble(methodNode.SelectSingleNode("liquidSensorBlockDistance").InnerText);//堵塞探测距离
            //string liquidSensorBlockDisIdText = methodNode.SelectSingleNode("liquidSensorBlockDisId/text").InnerText;//未探测到堵塞时选项名称
            //int liquidSensorBlockDisIdValue = Convert.ToInt32(methodNode.SelectSingleNode("liquidSensorBlockDisId/value").InnerText);//未探测到堵塞时选项Id
            string aspirateBlockDisIdText = methodNode.SelectSingleNode("aspirateBlockDisId/text").InnerText;
            string aspirateBlockDisIdValue = methodNode.SelectSingleNode("aspirateBlockDisId/value").InnerText;
            string dispenseBlockDisIdText = methodNode.SelectSingleNode("dispenseBlockDisId/text").InnerText;
            string dispenseBlockDisIdValue = methodNode.SelectSingleNode("dispenseBlockDisId/value").InnerText;
            string[] charray = channelNums.Split(',');
            #endregion
 
            try
            {
                #region 文件数据检查
                // 移液文件不存在
                if (methodTransferFile.transferDataTable == null)
                {
                    result = false;
                    return result;
                }
 
                // 检查数据中的板子名称是否在台面存在
                string notExistlabwarename = "";
                bool isExistPlate = transferFileBll.CheckDataExist(methodTransferFile, xmlEnv, out notExistlabwarename);
                if (isExistPlate == false)
                {
                    if (strCurrentCulture.Equals("zh-CN"))
                    {
                        launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】> Xhandler: 【" + methodName + "】" + Properties.MachineRunResource.strProgress.ToString() + Properties.RunTransferFileResource.strWithoutLattice.ToString() + " 板位 " + notExistlabwarename);
                    }
                    else
                    {
                        launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】> Xhandler:【" + methodName + "】" + notExistlabwarename + " labware is not exist on lattice.");
                    }
                    result = false;
                    return result;
                }
 
                // 排序文件并检查文件是否完整
                List<LabwareRSLattice> labwareRSLattices = transferFileBll.GetLabwareEntities(methodTransferFile, xmlEnv);
 
                DataTable dtSorted = new DataTable();//保存重新排序后的数据
                dtSorted = methodTransferFile.transferDataTable.Clone();
                if (Shared.ChannelCount > 1)
                {
                    foreach (LabwareRSLattice l in labwareRSLattices)
                    {
                        #region Del 暂时不用
                        //bool b = transferFileBll.IsEntire6ChannelsSolidWells(methodTransferFile, l);
                        //if (b)
                        //{
                        //    if (strCurrentCulture.Equals("zh-CN"))
                        //    {
                        //        launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】> Xhandler: 【" + methodName + "】" + Properties.MachineRunResource.strProgress.ToString() + Properties.RunTransferFileResource.strNotEntireData.ToString());
                        //        LoggerRunHelper.InfoLog("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】> Xhandler: 【" + methodName + "】" + Properties.MachineRunResource.strProgress.ToString() + Properties.RunTransferFileResource.strNotEntireData.ToString());
                        //    }
                        //    else
                        //    {
                        //        launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】> Xhandler:【" + methodName + "】" + Properties.MachineRunResource.strError.ToString() + " table data is not whole.");
                        //        LoggerRunHelper.InfoLog("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】> Xhandler:【" + methodName + "】" + Properties.MachineRunResource.strError.ToString() + " table data is not whole.");
                        //    }
                        //    result = false;
                        //    return result;
                        //}
                        #endregion
 
                        DataTable d = transferFileBll.SortALabwareDataForChoiceSH(methodTransferFile, l);
                        if (d != null)
                        {
                            for (int i = 0; i < d.Rows.Count; i++)
                            {
                                dtSorted.ImportRow(d.Rows[i]);
                            }
                        }
                        else
                        {
                            if (strCurrentCulture.Equals("zh-CN"))
                            {
                                launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】> Xhandler: 【" + methodName + "】" + Properties.MachineRunResource.strProgress.ToString() + Properties.RunTransferFileResource.strWithErrorData.ToString());
                                LoggerRunHelper.InfoLog("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】> Xhandler: 【" + methodName + "】" + Properties.MachineRunResource.strProgress.ToString() + Properties.RunTransferFileResource.strWithErrorData.ToString());
                            }
                            else
                            {
                                launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】> Xhandler:【" + methodName + "】" + Properties.MachineRunResource.strError.ToString() + " table data is wrong.");
                                LoggerRunHelper.InfoLog("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】> Xhandler:【" + methodName + "】" + Properties.MachineRunResource.strError.ToString() + " table data is wrong.");
                            }
                            result = false;
                            return result;
                        }
                    }
                }
                else if (Shared.ChannelCount == 1)
                {
                    dtSorted = methodTransferFile.transferDataTable;
                }
                #endregion
 
                if (dtSorted.Rows.Count != 0)
                {
                    if (Shared.ChannelCount > 1)
                    {
                        int total = dtSorted.Rows.Count;    // 待移液的数据总条目数
                        string targetWellName = dtSorted.Rows[0][methodTransferFile.destinationWell].ToString();            // 目标板孔位
                        int targetWellIndex0 = Convert.ToInt32(targetWellName.Substring(1, targetWellName.Length - 1));     // 列号
 
                        // 首先取剩余列的Tip总数,直接装枪做完
                        // 满列Tip继续安装,循环执行剩余的待做总数
                        //    如果是接续的目标列,且目标板孔位间距小于18mm,则判断板位上下板位是否有耗材高于25mm,如果有则改成单孔一个个做,如果没有则直接做;
                        TransferFileSubSHControl transferFileSubSHControl = new TransferFileSubSHControl(Shared.SoftwareInformation.currentculture);
                        transferFileSubSHControl.launchView = this.launchView;
                        result = transferFileSubSHControl.ExecuteTransferFilegByWholeTipPriorForSH(xmlEnv, methodNode,
                            methodTransferFile.transferDataTable, zAxisVal, isSimulator);
                        return result;
                    }
                }
            }
            catch (Exception ex)
            {
                LoggerHelper.ErrorLog("ERROR:", ex);
 
                if (strCurrentCulture.Equals("zh-CN"))
                {
                    launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodNode.SelectSingleNode("name").InnerText + "】" + Properties.MachineRunResource.strError.ToString() + " 源 " + ex.Source + " 错误信息 " + ex.Message + ";");
                }
                else
                {
                    launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodNode.SelectSingleNode("name").InnerText + "】error:source:" + ex.Source + ";error:" + ex.Message + ";");
                }
                result = false;
            }
            return result;
        }
        #endregion
    }
}