using DataEntity.Share;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using XCommon.Log;
using XHandler.Class.DataEx;
using XImagingXhandler.XDAL;
using XHandler.Class;
using HandyControl.Expression.Shapes;
using NPOI.SS.Formula.Functions;
using DataRWDAL;
namespace XHandler.View.MethodProperty
{
///
/// UnLoadTipsProperty.xaml 的交互逻辑
///
public partial class UnLoadTipsProperty : UserControl, IMethodProperty,IDeviceArmObserver
{
public MethodUnloadTips methodUnLoadTips { get; set; }
private Labware selectedLabware = null;
int curArmSelectedIndex = -1;
string curName = string.Empty;
bool isPutIntoSource = false;
private int[] channels = Shared.ChannelsId;
public UnLoadTipsProperty()
{
InitializeComponent();
}
///
/// 通道设置变更后,更新节点
///
///
public void ReceiveAndUpdate()
{
// 获取当前设备臂信息
List deviceArmList = DeviceArmDB.GetDeviceArmFromdb(Shared.SoftwareInformation.software_information_id);
Shared.DeviceArmList = deviceArmList;
DeviceArm deviceArm = Shared.DeviceArmList.SingleOrDefault(x => x.software_information_id.Equals(Shared.SoftwareInformation.software_information_id) && x.device_arm_id.Equals((cbArm.SelectedItem as DeviceArm).device_arm_id) && x.arm_type.Equals(1));
tipsChannel.TotalChannels = deviceArm.channels;
tipsChannel.SetTotalChannelCount(deviceArm.channels);
if (deviceArm.device_arm_property == "")
{
tipsChannel.SelectedChannels = new List { };
tipsChannel.SetSelectedChannels();
//Shared.ChannelsId = new int[];
return;
}
string[] strChannels = deviceArm.device_arm_property.Trim().Split(',');
int[] iChannels = new int[strChannels.Length];
for (int j = 0; j < strChannels.Length; j++)
{
iChannels[j] = Convert.ToInt32(strChannels[j]);
}
if (iChannels.Length > 0)
{
tipsChannel.SelectedChannels = iChannels.ToList();
tipsChannel.SetSelectedChannels();
}
if (methodUnLoadTips != null)
{
methodUnLoadTips.channels = iChannels;
}
}
public UnLoadTipsProperty(MethodEx method)
{
InitializeComponent();
curArmSelectedIndex = 0;
List armList = DataModule.getInstance().GetDeviceArm();
cbArm.ItemsSource = armList;
if (armList.Count == 2) //只有一个臂的情况下默认选中该臂
curArmSelectedIndex = 1;
else
curArmSelectedIndex = 0;
methodUnLoadTips = new MethodUnloadTips();
methodUnLoadTips.isrun = "disable";
methodUnLoadTips.status = (method.isEnabled == true ? "enable" : "disable");
methodUnLoadTips.name = method.method_name;
methodUnLoadTips.label = method.method_name;
methodUnLoadTips.strIndex = method.strIndex;
this.DataContext = methodUnLoadTips;
if (Shared.ChannelCount > 1)
{
tipsChannel.CanEdit = true;
if (Shared.ChannelCount.Equals(96))
{
tipsChannel.Visibility = Visibility.Collapsed;
}
}
if (method.tag != null)
{
methodUnLoadTips = (MethodUnloadTips)method.tag;
tipsChannel.SelectedChannels = methodUnLoadTips.channels.ToList();
tipsChannel.SetSelectedChannels();
curName = methodUnLoadTips.name;
isPutIntoSource = methodUnLoadTips.isputToSource;
channels = methodUnLoadTips.channels;
}
}
public void SetTableName(string tableName, Labware lb)
{
if (methodUnLoadTips != null)
{
methodUnLoadTips.positionText = tableName;
}
tbxLatticeName.Text = tableName;
selectedLabware = lb;
}
private void cbArm_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
try
{
if (methodUnLoadTips != null)
{
DeviceArm arm = cbArm.SelectedItem as DeviceArm;
methodUnLoadTips.armText = arm.device_arm_name;
methodUnLoadTips.armValue = arm.device_arm_id.ToString();
methodUnLoadTips.headType = arm.head_type;
if (arm.arm_type.Equals(0))
{
gdContent.RowDefinitions[3].Height = new GridLength(0);
return;
}
else
{
gdContent.RowDefinitions[3].Height = new GridLength(80);
}
}
if (Shared.ChannelCount.Equals(96))
{
curArmSelectedIndex = cbArm.SelectedIndex;
methodUnLoadTips.channels = new int[] {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};
}
else
{
// 臂未选择
if (cbArm.SelectedIndex < 0 || cbArm.SelectedIndex == 0)
{
tipsChannel.SetTotalChannelCount(0);
tipsChannel.SelectedChannels = new List();
tipsChannel.SetSelectedChannels();
tipsChannel_SelectedChangedEvent(null, null);
return;
}
curArmSelectedIndex = cbArm.SelectedIndex;
string armName = ((DeviceArm)cbArm.SelectedItem).device_arm_name.ToString();
tipsChannel.SelectedChannels = Shared.ChannelsId.ToList();
tipsChannel.SetTotalChannelCount(Shared.ChannelCount);
tipsChannel.SetSelectedChannels();
tipsChannel_SelectedChangedEvent(null, null);
}
ReceiveAndUpdate();
//methodUnLoadTips.channels = arm.channels;
}
catch (Exception ex)
{
LoggerHelper.ErrorLog("ERROR:", ex);
}
}
public void UserControl_Loaded(object sender, RoutedEventArgs e)
{
try
{
if (!string.IsNullOrEmpty(methodUnLoadTips.armText))
{
cbArm.SelectedValue = methodUnLoadTips.armValue;
DeviceArm arm = cbArm.SelectedItem as DeviceArm;
if (Shared.ChannelCount.Equals(96))
{
}
else
{
tipsChannel.SelectedChannels = channels.ToList();
tipsChannel.SetSelectedChannels();
tipsChannel_SelectedChangedEvent(null, null);
}
tbxName.Text = methodUnLoadTips.name;
tbxLatticeName.Text = methodUnLoadTips.positionText;
cbPutIntoSource.IsChecked = methodUnLoadTips.isputToSource;
}
else
{
cbArm.SelectedIndex = curArmSelectedIndex;
if (cbArm.Items.Count > 1)
{
cbArm.SelectedIndex = 1;
}
//加载出默认的垃圾桶
List lattice = LatticeDB.GetTrashLatticeDataByIdFromdb(cbArm.SelectedValue.ToString(), Shared.SoftwareInformation.software_device_number); // 获取当前垃圾桶台面板位信息
if (lattice != null && lattice.Count > 0)
{
tbxLatticeName.Text = lattice[0].lattice_num.ToString();
}
}
ReceiveAndUpdate();
}
catch (Exception ex)
{
LoggerHelper.ErrorLog("ERROR:", ex);
}
}
private void tbxName_TextChanged(object sender, TextChangedEventArgs e)
{
try
{
if (methodUnLoadTips != null)
{
methodUnLoadTips.name = tbxName.Text;
}
}
catch (Exception ex)
{
LoggerHelper.ErrorLog("ERROR:", ex);
}
}
private void tbxLatticeName_TextChanged(object sender, TextChangedEventArgs e)
{
try
{
if (!string.IsNullOrEmpty(tbxLatticeName.Text))
{
cbPutIntoSource.IsChecked = false;
}
else
{
cbPutIntoSource.IsChecked = true;
}
if (methodUnLoadTips != null)
{
methodUnLoadTips.positionText = tbxLatticeName.Text;
}
}
catch (Exception ex)
{
LoggerHelper.ErrorLog("ERROR:", ex);
}
}
private void cbPutIntoSource_Click(object sender, RoutedEventArgs e)
{
try
{
if (cbPutIntoSource.IsChecked == true)
{
if (methodUnLoadTips != null)
{
methodUnLoadTips.isputToSource = true;
}
tbxLatticeName.Text = "";
}
else
{
if (methodUnLoadTips != null)
{
methodUnLoadTips.isputToSource = false;
}
}
}
catch (Exception ex)
{
LoggerHelper.ErrorLog("ERROR:", ex);
}
}
#region 可用通道鼠标选择变更事件
///
/// 可用通道鼠标选择变更事件
///
///
///
private void tipsChannel_SelectedChangedEvent(object sender, EventArgs e)
{
if (Shared.ChannelCount.Equals(96))
{
methodUnLoadTips.channels = new int[] {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};
}
else
{
methodUnLoadTips.channels = tipsChannel.SelectedChannels.ToArray();
}
}
#endregion
}
}