using DataEntity.Share;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Controls;
using XCommon.Log;
using XCore;
using XHandler.Class;
using XHandler.Class.DataEx;
using XImagingXhandler.XDAL;
namespace XHandler.View.MethodProperty
{
///
/// GripMoveProperty.xaml 的交互逻辑
///
public partial class GripMoveProperty : UserControl, IMethodProperty
{
public MethodGripMove methodGripMove { get; set; }
public MethodGripMove currmethodGripMove = null;
AspirateBll aspirateBll = new AspirateBll();
List lattices = new List();
int curArmSelectedIndex = -1;
int curLatticeSelectedIndex = -1;
#region 全局属性变量
string isrun = "";
string status = "";
string name = "";
string label = "";
string armText = "";
string armValue = "";
string latticeText = "";
string latticeValue = "";
int mark = 0;
#endregion
public GripMoveProperty()
{
InitializeComponent();
}
public GripMoveProperty(MethodEx method)
{
InitializeComponent();
mark = 0;
curArmSelectedIndex = 0;
curLatticeSelectedIndex = 0;
List deviceArms = aspirateBll.ProviderDeviceArmList();
cbArm.ItemsSource = deviceArms;
if (deviceArms.Count == 2) //只有一个臂的情况下默认选中该臂
curArmSelectedIndex = 1;
else
curArmSelectedIndex = 0;
//lattices = aspirateBll.ProviderLatticeList(Shared.SoftwareInformation.software_device_number, Convert.ToInt32(cbArm.SelectedValue));
//cbLattice.ItemsSource = lattices;
methodGripMove = new MethodGripMove();
methodGripMove.name = method.method_name;
methodGripMove.label = method.method_name;
methodGripMove.status = (method.isEnabled == true ? "enable" : "disable");
methodGripMove.strIndex = method.strIndex;
this.DataContext = methodGripMove;
if (method.tag != null)
{
methodGripMove = (MethodGripMove)method.tag;
currmethodGripMove = methodGripMove;
isrun = methodGripMove.isrun;
status = methodGripMove.status;
name = methodGripMove.name;
label = methodGripMove.label;
armText = methodGripMove.armText;
armValue = methodGripMove.armValue;
latticeText = methodGripMove.latticeText;
latticeValue = methodGripMove.latticeValue;
}
}
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
mark += 1;
try
{
if (mark > 1)
{
return;
}
if (!string.IsNullOrEmpty(armText))
{
tbxCommandName.Text = name;
cbArm.SelectedValue = armValue;
cbLattice.SelectedValue = latticeValue;
if (currmethodGripMove != null)
{
methodGripMove = currmethodGripMove;
}
}
else
{
cbArm.SelectedIndex = curArmSelectedIndex;
cbLattice.SelectedIndex = curLatticeSelectedIndex;
if (currmethodGripMove != null)
{
methodGripMove = currmethodGripMove;
}
}
}
catch (Exception ex)
{
LoggerHelper.ErrorLog("ERROR:", ex);
}
}
private void cbArm_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (cbArm.SelectedIndex < 0)
return;
curArmSelectedIndex = cbArm.SelectedIndex;
DeviceArm arm = cbArm.SelectedItem as DeviceArm;
if (methodGripMove != null)
{
methodGripMove.armText = arm.device_arm_name;
methodGripMove.armValue = arm.device_arm_id.ToString();
}
lattices = aspirateBll.ProviderLatticeList(Shared.SoftwareInformation.software_device_number, Convert.ToInt32(cbArm.SelectedValue));
cbLattice.ItemsSource = lattices;
}
private void cbLattice_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if(cbLattice.SelectedIndex < 0)
return;
curLatticeSelectedIndex= cbLattice.SelectedIndex;
if(curLatticeSelectedIndex>0)
{
Lattice l = cbLattice.SelectedItem as Lattice;
if (methodGripMove != null)
{
methodGripMove.latticeText = l.lattice_num;
methodGripMove.latticeValue = l.lattice_id;
}
}
}
public void SetTableName(string name, Labware labware)
{
TextBox tb = Utilities.FindVisualChild(cbLattice);
if (tb.IsFocused)
{
Lattice l = lattices.Find(s => s.lattice_num == name);
cbLattice.SelectedItem = l;
}
}
private void tbxCommandName_TextChanged(object sender, TextChangedEventArgs e)
{
try
{
if (methodGripMove != null)
{
methodGripMove.name = tbxCommandName.Text;
}
}
catch (Exception ex)
{
LoggerHelper.ErrorLog("ERROR:", ex);
}
}
}
}