using DataEntity.Share;
using DriverLib.Engine;
using HxEnum;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data;
using System.Xml;
using XCommon;
using XCoreBLL.Resource;
using XImagingXhandler.XDAL;
namespace XCore
{
public class CoatingFileBll
{
string strCurrentCulture = "";
public CoatingFileBll()
{
strCurrentCulture = System.Threading.Thread.CurrentThread.CurrentCulture.Name;
}
public MethodCoatingFile GenerateMethodCoatingFileDataByXmlNode(XmlNode xmlNode)
{
MethodCoatingFile methodCoatingFile = new MethodCoatingFile();
methodCoatingFile.isrun = xmlNode.SelectSingleNode("isrun").InnerText;
methodCoatingFile.status = xmlNode.SelectSingleNode("status").InnerText;
methodCoatingFile.name = xmlNode.SelectSingleNode("name").InnerText;
methodCoatingFile.label = xmlNode.SelectSingleNode("label").InnerText;
methodCoatingFile.strIndex = xmlNode.SelectSingleNode("strIndex").InnerText;
methodCoatingFile.armText = xmlNode.SelectSingleNode("arm/text").InnerText;
methodCoatingFile.armValue = xmlNode.SelectSingleNode("arm/value").InnerText;
methodCoatingFile.labwaretipText = xmlNode.SelectSingleNode("labwaretip/text").InnerText;
methodCoatingFile.labwaretipValue = xmlNode.SelectSingleNode("labwaretip/value").InnerText;
string strchs = xmlNode.SelectSingleNode("channels").InnerText;
methodCoatingFile.channels = ComUtility.GetChannelsFromXml(strchs);
methodCoatingFile.filePath = xmlNode.SelectSingleNode("filePath").InnerText;
methodCoatingFile.beginLine = Convert.ToInt32(xmlNode.SelectSingleNode("beginLine").InnerText);
//到原始路径下,重新获取一下数据表
methodCoatingFile.transferDataTable = GenerateTransferFileDataTable(xmlNode);
methodCoatingFile.sourceLabware = xmlNode.SelectSingleNode("sourceLabware").InnerText;
methodCoatingFile.sourceWell = xmlNode.SelectSingleNode("sourceWell").InnerText;
if (xmlNode.SelectSingleNode("coatingOffset") != null)
{
methodCoatingFile.coatingOffset = Convert.ToDouble(xmlNode.SelectSingleNode("coatingOffset").InnerText);
}
else
{
methodCoatingFile.coatingOffset = 0d;
}
methodCoatingFile.destinationLabware = xmlNode.SelectSingleNode("destinationLabware").InnerText;
methodCoatingFile.destinationWell = xmlNode.SelectSingleNode("destinationWell").InnerText;
methodCoatingFile.bacteriaText = xmlNode.SelectSingleNode("bacteria/text").InnerText;
methodCoatingFile.bacteriaValue = xmlNode.SelectSingleNode("bacteria/value").InnerText;
if (xmlNode.SelectSingleNode("choiceCategory") != null)
{
// 挑菌方式 1:单选; 2:穿刺; 3:吸放液; 4:放液
methodCoatingFile.choiceCategory = Convert.ToInt32(xmlNode.SelectSingleNode("choiceCategory").InnerText);
}
else
{
methodCoatingFile.choiceCategory = 0;
}
// 多块目标板涂布前要挑菌
methodCoatingFile.pickEveryTime = (xmlNode.SelectSingleNode("pickEveryTime").InnerText.ToLower().ToString() == "true" ? true : false);
// 多块目标板挑菌前要换枪头
methodCoatingFile.pickAgoChangeTipEveryTime = (xmlNode.SelectSingleNode("pickAgoChangeTipEveryTime").InnerText.ToLower().ToString() == "true" ? true : false);
// 涂布方式 1:回字型 2:Z字型;3:上下移动
methodCoatingFile.coatingModeValue = Convert.ToInt32(xmlNode.SelectSingleNode("coatingmodeValue").InnerText);
if (methodCoatingFile.coatingModeValue == EnumManagement.GetEnumValue(CoatingModeEnum.UpDownMode))
{
// 涂布方式为上下移动时次数
methodCoatingFile.shakeCountValue = Convert.ToInt32(xmlNode.SelectSingleNode("shakeCountValue").InnerText);
// 涂布方式为上下移动时的距离
methodCoatingFile.shakeDistanceValue = Convert.ToDouble(xmlNode.SelectSingleNode("shakeDistanceValue").InnerText);
}
// 同时挑菌的通道数量
methodCoatingFile.coatingCount = Convert.ToInt32(xmlNode.SelectSingleNode("coatingCount").InnerText);
// 涂布自动开关盖
methodCoatingFile.autoOpenCloseCoverCoating = (xmlNode.SelectSingleNode("autoOpenCloseCoverCoating").InnerText.ToLower().ToString() == "true" ? true : false);
if (methodCoatingFile.coatingModeValue == EnumManagement.GetEnumValue(CoatingModeEnum.AspirateDispenseMode)) // 涂布方式 = 4:吸放液
{
#region 吸放液
methodCoatingFile.liquididText = xmlNode.SelectSingleNode("liquidid/text").InnerText;
methodCoatingFile.liquididValue = xmlNode.SelectSingleNode("liquidid/value").InnerText;
methodCoatingFile.liquidrangeidText = xmlNode.SelectSingleNode("liquidrangeid/text").InnerText;
methodCoatingFile.liquidrangeidValue = xmlNode.SelectSingleNode("liquidrangeid/value").InnerText;
methodCoatingFile.liquidpidText = xmlNode.SelectSingleNode("liquidpid/text").InnerText;
methodCoatingFile.liquidpidValue = xmlNode.SelectSingleNode("liquidpid/value").InnerText;
methodCoatingFile.bMix = xmlNode.SelectSingleNode("enableMix").InnerText.ToLower() == "true" ? true : false;
methodCoatingFile.mixvolume = Convert.ToDouble(xmlNode.SelectSingleNode("mixvolume").InnerText);
methodCoatingFile.mixcount = Convert.ToInt32(xmlNode.SelectSingleNode("mixcount").InnerText);
methodCoatingFile.mixAspiratePositionText = xmlNode.SelectSingleNode("mixAspiratePosition/text").InnerText;
methodCoatingFile.mixAspiratePositionValue = Convert.ToInt32(xmlNode.SelectSingleNode("mixAspiratePosition/value").InnerText);
methodCoatingFile.mixAspirateDistance = Convert.ToDouble(xmlNode.SelectSingleNode("mixAspirateDistance").InnerText);
methodCoatingFile.mixAspirateSpeed = Convert.ToDouble(xmlNode.SelectSingleNode("mixAspirateSpeed").InnerText);
methodCoatingFile.mixDispensePositionText = xmlNode.SelectSingleNode("mixDispensePosition/text").InnerText;
methodCoatingFile.mixDispensePositionValue = Convert.ToInt32(xmlNode.SelectSingleNode("mixDispensePosition/value").InnerText);
methodCoatingFile.mixDispenseDistance = Convert.ToDouble(xmlNode.SelectSingleNode("mixDispenseDistance").InnerText);
methodCoatingFile.mixDispenseSpeed = Convert.ToDouble(xmlNode.SelectSingleNode("mixDispenseSpeed").InnerText);
#endregion
}
// 获取挑菌前环境设置参数
if (xmlNode.SelectSingleNode("bEnableBeforeAspirate") != null)
{
methodCoatingFile.choiceAgoAspirateData = CommonBll.GenerateChoiceAgoAspirateChildDataByXmlNode(xmlNode);
}
// 是否开启超声
methodCoatingFile.isEnableultrasonic = false;
if (xmlNode.SelectSingleNode("enableUltrasonic") != null)
{
methodCoatingFile.isEnableultrasonic = (xmlNode.SelectSingleNode("enableUltrasonic").InnerText.ToLower().ToString() == "true" ? true : false);
if (methodCoatingFile.isEnableultrasonic)
{
// 获取圆形皿耗材超声属性
methodCoatingFile.ultrasonicDishObjectList = GenerateUltrasonicDishObjectData(xmlNode);
// 获取非圆形皿耗材超声属性
methodCoatingFile.ultrasonicObjectList = GenerateUltrasonicObjectData(xmlNode);
}
}
return methodCoatingFile;
}
///
/// 获取圆形皿耗材超声属性
///
///
///
public List GenerateUltrasonicDishObjectData(XmlNode xmlNode)
{
XmlNode xmlNode2 = xmlNode.SelectSingleNode("ultrasonicDishObject");
List data = new List();
foreach (XmlNode childNode in xmlNode2.ChildNodes)
{
UltrasonicDishObject ultrasonicDishObject = new UltrasonicDishObject();
ultrasonicDishObject.labwareValue = childNode.SelectSingleNode("labwareValue").InnerText.ToString();
ultrasonicDishObject.labwareText = childNode.SelectSingleNode("labwareText").InnerText.ToString();
ObservableCollection list = new ObservableCollection();
var a = childNode.SelectNodes("pointList/point");
if (a != null)
{
for (int i = 0; i < a.Count; i++)
{
DropdownName dropdownName = new DropdownName();
dropdownName.dropdown_id = a[i].SelectSingleNode("xAxisVal").InnerText.ToString();
dropdownName.dropdown_name = a[i].SelectSingleNode("yAxisVal").InnerText.ToString();
dropdownName.index_id = i + 1;
list.Add(dropdownName);
}
}
ultrasonicDishObject.pointList = list;
data.Add(ultrasonicDishObject);
}
return data;
}
///
/// 获取非圆形皿耗材超声属性
///
///
///
public List GenerateUltrasonicObjectData(XmlNode xmlNode)
{
XmlNode xmlNode2 = xmlNode.SelectSingleNode("ultrasonicObject");
List data = new List();
foreach (XmlNode childNode in xmlNode2.ChildNodes)
{
UltrasonicObject ultrasonicObject = new UltrasonicObject();
ultrasonicObject.labwareValue = childNode.SelectSingleNode("labwareValue").InnerText.ToString();
ultrasonicObject.labwareText = childNode.SelectSingleNode("labwareText").InnerText.ToString();
ultrasonicObject.rowNum = Convert.ToInt32(childNode.SelectSingleNode("rowNum").InnerText.ToString());
ultrasonicObject.columnNum = Convert.ToInt32(childNode.SelectSingleNode("columnNum").InnerText.ToString());
ultrasonicObject.closeTopVal = Convert.ToDouble(childNode.SelectSingleNode("closeTopVal").InnerText.ToString());
ultrasonicObject.closeLeftVal = Convert.ToDouble(childNode.SelectSingleNode("closeLeftVal").InnerText.ToString());
ultrasonicObject.xAxisVal = Convert.ToDouble(childNode.SelectSingleNode("xAxisVal").InnerText.ToString());
ultrasonicObject.yAxisVal = Convert.ToDouble(childNode.SelectSingleNode("yAxisVal").InnerText.ToString());
data.Add(ultrasonicObject);
}
return data;
}
public DataTable GenerateTransferFileDataTable(XmlNode xmlNode)
{
XmlNode xmlNode2 = xmlNode.SelectSingleNode("transferDataTable");
DataTable dataTable = new DataTable();
foreach (XmlNode childNode in xmlNode2.ChildNodes)
{
DataColumn dataColumn = new DataColumn();
dataColumn.ColumnName = childNode.Name.ToString();
dataTable.Columns.Add(dataColumn);
}
if (xmlNode2.ChildNodes[0] != null)
{
for (int i = 0; i < xmlNode2.ChildNodes[0].ChildNodes.Count; i++)
{
DataRow dataRow = dataTable.NewRow();
for (int j = 0; j < xmlNode2.ChildNodes.Count; j++)
{
dataRow[j] = xmlNode2.ChildNodes[j].ChildNodes[i].InnerText;
}
dataTable.Rows.Add(dataRow);
}
}
return dataTable;
}
#region 检查所有属性设置是否满足要求
///
/// 检查所有属性设置是否满足要求
///
/// 涂布文件属性对象
/// 检查所有属性设置是否满足要求
public MethodPropertyInfo CheckProperty(MethodCoatingFile methodCoatingFile)
{
MethodPropertyInfo methodPropertyInfo = new MethodPropertyInfo();
if (strCurrentCulture == "zh-CN")
{
methodPropertyInfo.property_tips_info = CoatingFileResourceCHS.tipsInfo.ToString();
if (methodCoatingFile.filePath == null || methodCoatingFile.filePath == "")
{
methodPropertyInfo.property_name_info = CoatingFileResourceCHS.filePath.ToString();
}
if (methodCoatingFile.transferDataTable == null || methodCoatingFile.transferDataTable.Rows.Count == 0)
{
methodPropertyInfo.property_name_info = CoatingFileResourceCHS.transferDataTable.ToString();
}
if (methodCoatingFile.sourceLabware == null || methodCoatingFile.sourceLabware == "")
{
methodPropertyInfo.property_name_info = CoatingFileResourceCHS.sourceLabware.ToString();
}
if (methodCoatingFile.sourceWell == null || methodCoatingFile.sourceWell == "")
{
methodPropertyInfo.property_name_info = CoatingFileResourceCHS.sourceWell.ToString();
}
if (methodCoatingFile.destinationLabware == null || methodCoatingFile.destinationLabware == "")
{
methodPropertyInfo.property_name_info = CoatingFileResourceCHS.destinationLabware.ToString();
}
if (methodCoatingFile.destinationWell == null || methodCoatingFile.destinationWell == "")
{
methodPropertyInfo.property_name_info = CoatingFileResourceCHS.destinationWell.ToString();
}
if (methodCoatingFile.bacteriaText == null || methodCoatingFile.bacteriaText == "")
{
methodPropertyInfo.property_name_info = CoatingFileResourceCHS.bacteriaText.ToString();
}
}
else if (strCurrentCulture == "en-US")
{
methodPropertyInfo.property_tips_info = CoatingFileResourceENU.tipsInfo.ToString();
if (methodCoatingFile.filePath == null || methodCoatingFile.filePath == "")
{
methodPropertyInfo.property_name_info = CoatingFileResourceENU.filePath.ToString();
}
if (methodCoatingFile.transferDataTable == null || methodCoatingFile.transferDataTable.Rows.Count == 0)
{
methodPropertyInfo.property_name_info = CoatingFileResourceENU.transferDataTable.ToString();
}
if (methodCoatingFile.sourceLabware == null || methodCoatingFile.sourceLabware == "")
{
methodPropertyInfo.property_name_info = CoatingFileResourceENU.sourceLabware.ToString();
}
if (methodCoatingFile.sourceWell == null || methodCoatingFile.sourceWell == "")
{
methodPropertyInfo.property_name_info = CoatingFileResourceENU.sourceWell.ToString();
}
if (methodCoatingFile.destinationLabware == null || methodCoatingFile.destinationLabware == "")
{
methodPropertyInfo.property_name_info = CoatingFileResourceENU.destinationLabware.ToString();
}
if (methodCoatingFile.destinationWell == null || methodCoatingFile.destinationWell == "")
{
methodPropertyInfo.property_name_info = CoatingFileResourceENU.destinationWell.ToString();
}
if (methodCoatingFile.bacteriaText == null || methodCoatingFile.bacteriaText == "")
{
methodPropertyInfo.property_name_info = CoatingFileResourceENU.bacteriaText.ToString();
}
}
return methodPropertyInfo;
}
#endregion
#region 执行涂布文件,返回结果对象
///
/// 执行涂布文件,返回结果对象
///
/// 卸载吸头的板位节点对象
/// 是否虚拟运行
/// 挑选执行结果
public HxResult ExecuteChoice(ChoiceMParam choiceMParam, bool isSimulator)
{
HxResult ret = new HxResult();
if (!isSimulator)
{
ret = MethodAction.Instance.Choice(choiceMParam);
}
else
{
ret.Result = ResultType.Success;
}
return ret;
}
#endregion
#region 执行涂布文件,返回结果对象
///
/// 执行涂布文件,返回结果对象
///
/// 卸载吸头的板位节点对象
/// 是否虚拟运行
/// 挑选执行结果
public HxResult ExecuteChoice(ChoiceMParamWH choiceMParam, bool isSimulator)
{
HxResult ret = new HxResult();
if (!isSimulator)
{
ret = MethodAction.Instance.Choice(choiceMParam);
}
else
{
ret.Result = ResultType.Success;
}
return ret;
}
#endregion
#region 获取涂布通道数量
///
/// 获取涂布通道数量
///
///
///
public List GenerateCoatingCountOfChannel(string softwareDeviceNumber)
{
List dropdownNames = new List();
int channelCnt = Shared.ChannelCount;
#region Del
//if (softwareDeviceNumber.Equals(DeviceCategory.DeviceChoice))
//{
// channelCnt = 6;
//}
//else if (softwareDeviceNumber.Equals(DeviceCategory.DeviceLiteChoice) ||
// softwareDeviceNumber.Equals(DeviceCategory.DeviceT200))
//{
// channelCnt = 1;
//}
#endregion
for (int i = 1; i <= channelCnt; i++)
{
DropdownName dropdownName = new DropdownName();
dropdownName.dropdown_id = i.ToString();
dropdownName.dropdown_name = i.ToString();
dropdownNames.Add(dropdownName);
}
return dropdownNames;
}
#endregion
#region 把ObservableCollection转化为DataTable
public DataTable ManualChoiceDataTypeChangeToDataTable(ObservableCollection manualChoiceDatas)
{
DataTable dataTable = new DataTable();
DataColumn dc = new DataColumn();
dc.ColumnName = "SourceA";
dataTable.Columns.Add(dc);
dc = new DataColumn();
dc.ColumnName = "SourceBarcode";
dataTable.Columns.Add(dc);
dc = new DataColumn();
dc.ColumnName = "SourceCoordinate";
dataTable.Columns.Add(dc);
dc = new DataColumn();
dc.ColumnName = "TargetB";
dataTable.Columns.Add(dc);
dc = new DataColumn();
dc.ColumnName = "TargetBarcode";
dataTable.Columns.Add(dc);
dc = new DataColumn();
dc.ColumnName = "TargetWell";
dataTable.Columns.Add(dc);
dc = new DataColumn();
dc.ColumnName = "IsNewPlateBatch";
dataTable.Columns.Add(dc);
dc = new DataColumn();
dc.ColumnName = "IsPlateLastWell";
dataTable.Columns.Add(dc);
if (manualChoiceDatas != null)
{
foreach (ManualChoiceData manualChoiceData in manualChoiceDatas)
{
DataRow dr = dataTable.NewRow();
dr["SourceA"] = manualChoiceData.sourceplate;
dr["SourceBarcode"] = manualChoiceData.sourceplate_num;
dr["SourceCoordinate"] = manualChoiceData.machine_coordinate;
dr["TargetB"] = manualChoiceData.targetplate;
dr["TargetBarcode"] = manualChoiceData.targetplate_num;
dr["TargetWell"] = manualChoiceData.targetplate_well;
dr["IsNewPlateBatch"] = manualChoiceData.is_new_plate_batch;
dr["IsPlateLastWell"] = manualChoiceData.is_plate_last_well;
dataTable.Rows.Add(dr);
}
}
return dataTable;
}
#endregion
}
}