using DataEntity.Share;
using DataRWDAL;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using XCommon.Log;
using XCore;
using XHandler.Class.DataEx;
using XHandler.Controls;
using XHandler.View.MethodProperty;
using XImagingXhandler.XDAL;
namespace XHandler.View.BacteriaProperty
{
///
/// 挑选转板方法属性页面
///
public partial class PickAndTransferProperty : UserControl, IMethodProperty
{
#region 变量
private TransferFileBll transferFileBll = new TransferFileBll();
private static int mark = 0;
private PromptTextBox labwareTextBox = null; // 耗材类型文本框
public MethodChoiceAndTransfer methodChoice = null;
private int[] channels = Shared.ChannelsId;
#endregion
#region 构造函数
///
/// 构造函数
///
///
public PickAndTransferProperty(MethodEx method)
{
InitializeComponent();
mark = 0;
methodChoice = new MethodChoiceAndTransfer();
methodChoice.strIndex = method.strIndex;
methodChoice.label = method.method_name; // 命令标签
methodChoice.name = method.method_name; // 命令名称
methodChoice.status = (method.isEnabled == true ? "enable" : "disable"); // 使能状态
this.DataContext = methodChoice;
#region 获取机械臂信息
methodChoice.channels = Shared.ChannelsId;
List armList = DataModule.getInstance().GetDeviceArm();
cbArm.ItemsSource = armList;
// 只有一个臂的情况下默认选中该臂
cbArm.SelectedIndex = armList.Count == 2 ? 1 : 0;
#endregion
#region 获取菌的信息
cbBacteria.ItemsSource = DataModule.getInstance().GetBacterias();
cbBacteria.SelectedIndex = 0;
#endregion
#region 获取挑菌方式
cbPickMode.ItemsSource = DataModule.getInstance().GetChoiceMode(Shared.SoftwareInformation.software_device_number);
cbPickMode.SelectedIndex = 0;
#endregion
if (Shared.ChannelCount > 1)
{
tipsChannel.CanEdit = true;
}
methodChoice.autoOpenCloseCover = 0;
if (method.tag != null)
{
methodChoice = (MethodChoiceAndTransfer)method.tag;
channels = methodChoice.channels;
}
}
#endregion
#region 界面初期表示事件
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
mark += 1;
try
{
if (mark > 1)
{
return;
}
#region 机械臂
if (!string.IsNullOrEmpty(methodChoice.armText))
{
tbxCommandName.Text = methodChoice.name;
cbArm.SelectedValue = methodChoice.armValue;
cbBacteria.SelectedValue = methodChoice.bacteriaValue;
DeviceArm arm = cbArm.SelectedItem as DeviceArm;
textboxArmHead.Text = arm.head_type;
// 通道
tipsChannel.SelectedChannels = channels.ToList();
tipsChannel_SelectedChangedEvent(null, null);
}
else
{
cbArm.SelectedIndex = 0;
DeviceArm arm = cbArm.SelectedItem as DeviceArm;
if (arm != null)
{
textboxArmHead.Text = arm.head_type;
}
}
#endregion
#region 挑菌前环境设置
ChoiceAgoAspirateChildProperty choiceAgoAspirateChildProperty = new ChoiceAgoAspirateChildProperty(methodChoice.choiceAgoAspirateData);
gridChoiceAgoAspirateChild.Children.Add(choiceAgoAspirateChildProperty);
#endregion
#region 挑菌方式
cbPickMode.SelectedValue = methodChoice.choiceMode.ToString();
#endregion
#region 挑菌耗材
pickLabware.Tag = methodChoice.choiceLabwareValue;
pickLabware.Text = methodChoice.choiceLabwareText;
#endregion
#region 挑菌耗材
tipsLabware.Tag = methodChoice.tipsLabwareValue;
tipsLabware.Text = methodChoice.tipsLabwareText;
#endregion
#region 自动开关盖
ckbAutoOpenCloseCover.IsChecked = methodChoice.autoOpenCloseCover == 1;
#endregion
#region 调高
tbxChoiceOffset.Text = methodChoice.choiceOffset.ToString();
#endregion
#region 超声探测
UltrasonicChildProperty property = new UltrasonicChildProperty(methodChoice.ultrasonicData, true);
gridUltrasonicProperty.Children.Add(property);
cbxEnableUltrasonic.IsChecked = methodChoice.isEnableultrasonic;
#endregion
}
catch (Exception ex)
{
LoggerHelper.ErrorLog("ERROR:", ex);
}
}
#endregion
#region 方法标签文件更改事件
///
/// 方法标签文件更改事件
///
///
///
private void tbxCommandLabel_TextChanged(object sender, TextChangedEventArgs e)
{
try
{
if (mark != 0)
{
methodChoice.label = tbxCommandLabel.Text;
}
}
catch (Exception ex)
{
LoggerHelper.ErrorLog("ERROR:", ex);
}
}
#endregion
#region 方法名称更改事件
///
/// 方法名称更改事件
///
///
///
private void tbxCommandName_TextChanged(object sender, TextChangedEventArgs e)
{
try
{
if (mark != 0)
{
methodChoice.name = tbxCommandName.Text;
}
}
catch (Exception ex)
{
LoggerHelper.ErrorLog("ERROR:", ex);
}
}
#endregion
#region 机械臂选择变更事件
///
/// 机械臂选择变更事件
///
///
///
private void cbArm_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
// 臂未选择
if (cbArm.SelectedIndex < 0 || cbArm.SelectedIndex == 0)
{
methodChoice.armText = ""; // 机械臂
methodChoice.armValue = "";
textboxArmHead.Text = ""; // 挑菌枪
tipsChannel.SetTotalChannelCount(0);
tipsChannel.SelectedChannels = new List();
tipsChannel.SetSelectedChannels();
tipsChannel_SelectedChangedEvent(null, null);
return;
}
#region 设置移液枪信息
tipsChannel.SelectedChannels = Shared.ChannelsId.ToList();
tipsChannel.SetTotalChannelCount(Shared.ChannelCount);
tipsChannel.SetSelectedChannels();
tipsChannel_SelectedChangedEvent(null, null);
#endregion
DeviceArm arm = cbArm.SelectedItem as DeviceArm;
methodChoice.armText = arm.device_arm_name;
methodChoice.armValue = methodChoice.choiceAgoAspirateData.armValue = arm.device_arm_id.ToString();
methodChoice.headType = arm.head_type;
textboxArmHead.Text = arm.head_type;
}
#endregion
#region 菌名称选择变更事件
///
/// 菌名称选择变更事件
///
///
///
private void cbBacteria_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (cbBacteria.SelectedIndex < 0)
return;
if (methodChoice == null)
return;
Bacteria bacteria = cbBacteria.SelectedItem as Bacteria;
methodChoice.bacteriaValue = bacteria.bacteria_id;
methodChoice.bacteriaText = bacteria.bacteria_name;
}
#endregion
#region 挑选耗材类型文字变更事件
///
/// 挑选耗材类型文字变更事件
///
///
///
private void pickLabware_TextChanged(object sender, TextChangedEventArgs e)
{
methodChoice.choiceLabwareText = pickLabware.Text;
methodChoice.choiceLabwareValue = pickLabware.Tag.ToString();
}
///
/// 耗材文本框获得焦点事件
///
///
///
private void labware_GotFocus(object sender, RoutedEventArgs e)
{
labwareTextBox = (PromptTextBox)sender;
}
#endregion
#region 枪头类型耗材类型文字变更事件
///
/// 枪头类型耗材类型文字变更事件
///
///
///
private void tipsLabware_TextChanged(object sender, TextChangedEventArgs e)
{
methodChoice.tipsLabwareText = tipsLabware.Text;
methodChoice.tipsLabwareValue = tipsLabware.Tag.ToString();
}
#endregion
#region 挑选模式选择变更事件
///
/// 挑选模式选择变更事件
///
///
///
private void cbPickMode_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (cbPickMode.SelectedIndex < 0 ||
methodChoice == null)
{
return;
}
DropdownName dpdItem = (DropdownName)cbPickMode.SelectedItem;
methodChoice.choiceMode = Convert.ToInt32(dpdItem.dropdown_id);
#region 自动勾选【开启挑菌前吸液】
if (gridChoiceAgoAspirateChild.Children.Count > 0)
{
ChoiceAgoAspirateChildProperty choiceAgoAspirateChildProperty = (ChoiceAgoAspirateChildProperty)gridChoiceAgoAspirateChild.Children[0];
choiceAgoAspirateChildProperty.ChangeDisp(methodChoice.choiceMode);
}
#endregion
}
#endregion
#region 自动开关盖点击事件
///
/// 自动开关盖点击事件
///
///
///
private void ckbAutoOpenCloseCover_Click(object sender, RoutedEventArgs e)
{
methodChoice.autoOpenCloseCover = ckbAutoOpenCloseCover.IsChecked == true ? 1 : 0;
}
#endregion
#region 设置已选择的台面数据
public void SetTableName(string tableName, Labware lb)
{
if (lb == null || string.IsNullOrEmpty(lb.labware_id))
{
return;
}
List latticeList = LatticeDB.GetLatticeDataFromdb(Shared.SoftwareInformation.software_device_number, Convert.ToInt32(methodChoice.armValue));
Lattice lattice = latticeList.Find(s => s.lattice_num == tableName);
if (lattice == null)
{
LoggerHelper.InfoLog("Error: Can't find lattice with lattice_num=" + tableName);
return;
}
if (gridLiquidParam.Visibility == Visibility.Visible)
{
if (gridChoiceAgoAspirateChild.Children.Count > 0)
{
ChoiceAgoAspirateChildProperty choiceAgoAspirateChildProperty = (ChoiceAgoAspirateChildProperty)gridChoiceAgoAspirateChild.Children[0];
choiceAgoAspirateChildProperty.SetTableName(tableName, lb);
}
}
else
{
if (labwareTextBox != null)
{
labwareTextBox.Tag = lb.labware_id;
labwareTextBox.Text = lb.labware_name;
}
}
}
#endregion
#region 调高变更事件
///
/// 调高变更事件
///
///
///
private void tbxChoiceOffset_TextChanged(object sender, TextChangedEventArgs e)
{
float choiceOffset = 0;
methodChoice.choiceOffset = choiceOffset;
if (float.TryParse(tbxChoiceOffset.Text, out choiceOffset))
{
methodChoice.choiceOffset = choiceOffset;
}
}
#endregion
#region 超声探测
///
/// 开启超声探测
///
///
///
private void cbxEnableUltrasonic_Click(object sender, RoutedEventArgs e)
{
methodChoice.isEnableultrasonic = (bool)cbxEnableUltrasonic.IsChecked;
}
#endregion
#region 超声探测 下一步
private void btnUltrasonicNext_Click(object sender, RoutedEventArgs e)
{
stepBar.Next();
gridUltrasonic.Visibility = Visibility.Collapsed;
gridLiquidParam.Visibility = Visibility.Visible;
//scrollViewer.ScrollToTop();
}
#endregion
#region 挑菌前环境设置 上一步
private void btnLiquidParamPrev_Click(object sender, RoutedEventArgs e)
{
stepBar.Prev();
gridUltrasonic.Visibility = Visibility.Visible;
gridLiquidParam.Visibility = Visibility.Collapsed;
//scrollViewer.ScrollToTop();
}
#endregion
#region 可用通道鼠标选择变更事件
///
/// 可用通道鼠标选择变更事件
///
///
///
private void tipsChannel_SelectedChangedEvent(object sender, EventArgs e)
{
methodChoice.channels = tipsChannel.SelectedChannels.ToArray();
}
#endregion
}
}