using DataEntity.Share;
|
using DriverLib.Engine;
|
using System;
|
using System.Collections.Generic;
|
using System.Text.RegularExpressions;
|
using System.Windows;
|
using System.Windows.Controls;
|
using System.Windows.Input;
|
using XCommon.Log;
|
using XHandler.Controls;
|
using XHandler.View.MethodProperty;
|
using XImagingXhandler.XDAL;
|
using System.Linq;
|
using System.Runtime.Remoting.Channels;
|
|
namespace XHandler.View
|
{
|
/// <summary>
|
/// 控制移液枪类
|
/// </summary>
|
public partial class ControlPipetteGun : Window
|
{
|
#region 变量
|
//private GetOrSetLattice getOrSetLattice = new GetOrSetLattice();
|
//private UnloadTipsBll unloadTipsBll = new UnloadTipsBll();
|
private UnloadTipsControl unloadTipsCtrl = new UnloadTipsControl(Shared.SoftwareInformation.currentculture);
|
#endregion
|
|
#region 构造函数
|
/// <summary>
|
/// 构造函数
|
/// </summary>
|
public ControlPipetteGun()
|
{
|
InitializeComponent();
|
}
|
#endregion
|
|
#region 初始化
|
/// <summary>
|
/// 初始化
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void ControlPipetteGun_Loaded(object sender, RoutedEventArgs e)
|
{
|
try
|
{
|
//获取当前系统的非夹爪通道数量
|
List<DeviceArm> deviceArmList = DeviceArmDB.GetDeviceArmFromdb(Shared.SoftwareInformation.software_information_id);
|
var armListResult = deviceArmList.Where(x => x.arm_type != 0);
|
if(armListResult.Any()&&armListResult.Count()==1)
|
{
|
cbxArmZ.Visibility = Visibility.Collapsed;
|
}
|
else
|
{
|
cbxArmZ.Visibility = Visibility.Visible;
|
cbxArmZ.ItemsSource= armListResult;
|
cbxArmZ.SelectedIndex = 0;
|
}
|
}
|
catch (Exception ex)
|
{
|
LoggerHelper.ErrorLog("ControlPipetteGun_Loaded ERROR:", ex);
|
}
|
}
|
#endregion
|
|
#region 关闭窗口
|
/// <summary>
|
/// 关闭窗口
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void btnClose_Click(object sender, RoutedEventArgs e)
|
{
|
try
|
{
|
this.Close();
|
}
|
catch (Exception ex)
|
{
|
LoggerHelper.ErrorLog("ERROR:", ex);
|
}
|
}
|
#endregion
|
|
#region X-轴偏移 TODO
|
/// <summary>
|
/// 往左偏移
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void btnLeft_Click(object sender, RoutedEventArgs e)
|
{
|
HxResult result = new HxResult();
|
result.Result = ResultType.Success;
|
|
try
|
{
|
// 判断输入值是否为空
|
if (!ValueIsEmpty(tBoxXOffset, "请输入X-轴偏移量"))
|
{
|
return;
|
}
|
|
this.Cursor = Cursors.Wait;
|
result = MethodAction.Instance.XMoveLeft(Shared.ChanelArmId, float.Parse(tBoxXOffset.Text));
|
}
|
catch (Exception ex)
|
{
|
LoggerHelper.ErrorLog("ERROR:", ex);
|
}
|
finally
|
{
|
this.Cursor = Cursors.Arrow;
|
|
// 判断结果是否失败
|
ResultIsFail(result, "移液枪X轴向右偏移");
|
}
|
}
|
|
/// <summary>
|
/// 往右偏移
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void btnRight_Click(object sender, RoutedEventArgs e)
|
{
|
HxResult result = new HxResult();
|
result.Result = ResultType.Success;
|
|
try
|
{
|
// 判断输入值是否为空
|
if (!ValueIsEmpty(tBoxXOffset, "请输入X-轴偏移量"))
|
{
|
return;
|
}
|
|
this.Cursor = Cursors.Wait;
|
result = MethodAction.Instance.XMoveRight(Shared.ChanelArmId, float.Parse(tBoxXOffset.Text));
|
}
|
catch (Exception ex)
|
{
|
LoggerHelper.ErrorLog("ERROR:", ex);
|
}
|
finally
|
{
|
this.Cursor = Cursors.Arrow;
|
|
// 判断结果是否失败
|
ResultIsFail(result, "移液枪X轴向左偏移");
|
}
|
}
|
#endregion
|
|
#region Y-轴偏移 TODO
|
/// <summary>
|
/// 往前偏移
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void btnFwd_Click(object sender, RoutedEventArgs e)
|
{
|
HxResult result = new HxResult();
|
result.Result = ResultType.Success;
|
|
try
|
{
|
// 判断输入值是否为空
|
if (!ValueIsEmpty(tBoxYOffset, "请输入Y-轴偏移量"))
|
{
|
return;
|
}
|
|
this.Cursor = Cursors.Wait;
|
result = MethodAction.Instance.ADPYMoveForward(Shared.ChanelArmId, float.Parse(tBoxYOffset.Text));
|
}
|
catch (Exception ex)
|
{
|
LoggerHelper.ErrorLog("ERROR:", ex);
|
}
|
finally
|
{
|
this.Cursor = Cursors.Arrow;
|
|
// 判断结果是否失败
|
ResultIsFail(result, "移液枪Y轴向前偏移");
|
}
|
}
|
|
/// <summary>
|
/// 往后偏移
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void btnBack_Click(object sender, RoutedEventArgs e)
|
{
|
HxResult result = new HxResult();
|
result.Result = ResultType.Success;
|
|
try
|
{
|
// 判断输入值是否为空
|
if (!ValueIsEmpty(tBoxYOffset, "请输入Y-轴偏移量"))
|
{
|
return;
|
}
|
|
this.Cursor = Cursors.Wait;
|
result = MethodAction.Instance.ADPYMoveBackward(Shared.ChanelArmId, float.Parse(tBoxYOffset.Text));
|
}
|
catch (Exception ex)
|
{
|
LoggerHelper.ErrorLog("ERROR:", ex);
|
}
|
finally
|
{
|
this.Cursor = Cursors.Arrow;
|
|
// 判断结果是否失败
|
ResultIsFail(result, "移液枪Y轴向后偏移");
|
}
|
}
|
#endregion
|
|
#region Z-轴偏移
|
/// <summary>
|
/// 向上偏移
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void btnUp_Click(object sender, RoutedEventArgs e)
|
{
|
HxResult result = new HxResult();
|
result.Result = ResultType.Success;
|
|
try
|
{
|
// 判断输入值是否为空
|
if (!ValueIsEmpty(tBoxZOffset, "请输入Z-轴偏移量"))
|
{
|
return;
|
}
|
|
Mouse.OverrideCursor = Cursors.Wait;
|
if (cbxArmZ.Visibility == Visibility.Visible)
|
{
|
DeviceArm deviceArm = (DeviceArm)cbxArmZ.SelectedItem;
|
string[] strArmProperty = deviceArm.device_arm_property.Trim().Split(',');
|
if (strArmProperty.Length > 0 && strArmProperty[0] != "")
|
{
|
if (deviceArm.channels >= 1 && strArmProperty.Length == 1)
|
{
|
Shared.ChannelsId = Array.ConvertAll<string, int>(strArmProperty, s => int.Parse(s));
|
Shared.ChannelCount = deviceArm.channels;
|
}
|
else
|
{
|
Array.ConvertAll<string, int>(strArmProperty, s => int.Parse(s));
|
Shared.ChannelsId = Array.ConvertAll<string, int>(strArmProperty, s => int.Parse(s));
|
Shared.ChannelCount = Shared.ChannelsId.Length;
|
}
|
}
|
result = MethodAction.Instance.ADPZUp(Convert.ToInt32(cbxArmZ.SelectedValue), float.Parse(tBoxZOffset.Text), Shared.ChannelsId);
|
}
|
else
|
{
|
result = MethodAction.Instance.ADPZUp(Shared.ChanelArmId, float.Parse(tBoxZOffset.Text), Shared.ChannelsId);
|
}
|
}
|
catch (Exception ex)
|
{
|
LoggerHelper.ErrorLog("ERROR:", ex);
|
}
|
finally
|
{
|
Mouse.OverrideCursor = null;
|
|
// 判断结果是否失败
|
ResultIsFail(result, "移液枪Z轴向上偏移");
|
}
|
}
|
|
/// <summary>
|
/// 向下偏移
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void btnDown_Click(object sender, RoutedEventArgs e)
|
{
|
HxResult result = new HxResult();
|
result.Result = ResultType.Success;
|
|
try
|
{
|
// 判断输入值是否为空
|
if (!ValueIsEmpty(tBoxZOffset, "请输入Z-轴偏移量"))
|
{
|
return;
|
}
|
|
Mouse.OverrideCursor = Cursors.Wait;
|
if (cbxArmZ.Visibility == Visibility.Visible)
|
{
|
DeviceArm deviceArm = (DeviceArm)cbxArmZ.SelectedItem;
|
string[] strArmProperty = deviceArm.device_arm_property.Trim().Split(',');
|
if (strArmProperty.Length > 0 && strArmProperty[0] != "")
|
{
|
if (deviceArm.channels >= 1 && strArmProperty.Length == 1)
|
{
|
Shared.ChannelsId = Array.ConvertAll<string, int>(strArmProperty, s => int.Parse(s));
|
Shared.ChannelCount = deviceArm.channels;
|
}
|
else
|
{
|
Array.ConvertAll<string, int>(strArmProperty, s => int.Parse(s));
|
Shared.ChannelsId = Array.ConvertAll<string, int>(strArmProperty, s => int.Parse(s));
|
Shared.ChannelCount = Shared.ChannelsId.Length;
|
}
|
}
|
result = MethodAction.Instance.ADPZDown(Convert.ToInt32(cbxArmZ.SelectedValue), float.Parse(tBoxZOffset.Text), Shared.ChannelsId);
|
}
|
else
|
{
|
|
result = MethodAction.Instance.ADPZDown(Shared.ChanelArmId, float.Parse(tBoxZOffset.Text), Shared.ChannelsId);
|
}
|
}
|
catch (Exception ex)
|
{
|
LoggerHelper.ErrorLog("ERROR:", ex);
|
}
|
finally
|
{
|
Mouse.OverrideCursor = null;
|
// 判断结果是否失败
|
ResultIsFail(result, "移液枪Z轴向下偏移");
|
}
|
}
|
#endregion
|
|
#region 移液量 TODO
|
/// <summary>
|
/// 吸液
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void btnAspirate_Click(object sender, RoutedEventArgs e)
|
{
|
HxResult result = new HxResult();
|
result.Result = ResultType.Success;
|
|
try
|
{
|
// 判断输入值是否为空
|
if (!ValueIsEmpty(tBoxPipetteOffset, "请输入吸液量"))
|
{
|
return;
|
}
|
this.Cursor = Cursors.Wait;
|
result = MethodAction.Instance.ADPAspirate(Shared.ChanelArmId, float.Parse(tBoxPipetteOffset.Text), Shared.ChannelsId);
|
}
|
catch (Exception ex)
|
{
|
LoggerHelper.ErrorLog("ERROR:", ex);
|
}
|
finally
|
{
|
this.Cursor = Cursors.Arrow;
|
|
// 判断结果是否失败
|
ResultIsFail(result, "移液枪吸液");
|
}
|
}
|
|
/// <summary>
|
/// 加液
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void btnDispense_Click(object sender, RoutedEventArgs e)
|
{
|
HxResult result = new HxResult();
|
result.Result = ResultType.Success;
|
|
try
|
{
|
// 判断输入值是否为空
|
if (!ValueIsEmpty(tBoxPipetteOffset, "请输入排液量"))
|
{
|
return;
|
}
|
this.Cursor = Cursors.Wait;
|
result = MethodAction.Instance.ADPDispense(Shared.ChanelArmId, float.Parse(tBoxPipetteOffset.Text), Shared.ChannelsId);
|
}
|
catch (Exception ex)
|
{
|
LoggerHelper.ErrorLog("ERROR:", ex);
|
}
|
finally
|
{
|
this.Cursor = Cursors.Arrow;
|
|
// 判断结果是否失败
|
ResultIsFail(result, "移液枪排液");
|
}
|
}
|
#endregion
|
|
#region Footer TODO
|
/// <summary>
|
/// 安装Tip
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void btnLoadTip_Click(object sender, RoutedEventArgs e)
|
{
|
HxResult result = new HxResult();
|
result.Result = ResultType.Success;
|
PlsToolTipWin plsToolTipWin = null;
|
try
|
{
|
this.Cursor = Cursors.Arrow;
|
System.Windows.Application.Current.Dispatcher.Invoke(new Action(() =>
|
{
|
plsToolTipWin = new PlsToolTipWin("暂不支持!");
|
plsToolTipWin.WindowStartupLocation = WindowStartupLocation.CenterScreen;
|
plsToolTipWin.ShowDialog();
|
}));
|
}
|
catch (Exception ex)
|
{
|
LoggerHelper.ErrorLog("ERROR:", ex);
|
}
|
finally
|
{
|
}
|
}
|
|
/// <summary>
|
/// 卸载Tip
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void btnUnLoadTip_Click(object sender, RoutedEventArgs e)
|
{
|
try
|
{
|
string strMsg = "卸载Tip成功!";
|
PlsToolTipWin plsToolTipWin = null;
|
|
// 卸载枪头
|
Mouse.OverrideCursor = Cursors.Wait;
|
string strMsgTip = unloadTipsCtrl.UnLoadTip();
|
if (!string.IsNullOrEmpty(strMsgTip))
|
{
|
strMsg = strMsgTip;
|
}
|
|
Mouse.OverrideCursor = null;
|
System.Windows.Application.Current.Dispatcher.Invoke(new Action(() =>
|
{
|
plsToolTipWin = new PlsToolTipWin(strMsg);
|
plsToolTipWin.btnCancel.Visibility = Visibility.Hidden;
|
plsToolTipWin.ShowDialog();
|
}));
|
}
|
catch (Exception ex)
|
{
|
LoggerHelper.ErrorLog("ERROR:", ex);
|
}
|
finally
|
{
|
Mouse.OverrideCursor = null;
|
}
|
}
|
|
/// <summary>
|
/// 取消
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void btnCancel_Click(object sender, RoutedEventArgs e)
|
{
|
try
|
{
|
this.Close();
|
}
|
catch (Exception ex)
|
{
|
LoggerHelper.ErrorLog("ERROR:", ex);
|
}
|
}
|
#endregion
|
|
#region 数据检查
|
/// <summary>
|
/// 只能输入正浮点数
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void tBoxPreviewTextInput(object sender, System.Windows.Input.TextCompositionEventArgs e)
|
{
|
TextBox textElem = (sender as TextBox);
|
// 解决连续输入很多.
|
if ((textElem.Text.StartsWith(".") ||
|
string.IsNullOrWhiteSpace(textElem.Text) ||
|
textElem.Text.Contains(".")) && e.Text == ".")
|
{
|
e.Handled = true;
|
return;
|
}
|
|
// 禁止在0前面继续输入0
|
int index = ((System.Windows.Controls.TextBox)e.Source).CaretIndex;
|
if (textElem.Text.StartsWith("0.") && index == 0 && e.Text == "0")
|
{
|
e.Handled = true;
|
return;
|
}
|
|
Regex re = new Regex("[^0-9.]+");
|
e.Handled = re.IsMatch(e.Text);
|
}
|
|
/// <summary>
|
/// 输入框失去焦点:限制一位小数
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void tBoxLostFocus(object sender, RoutedEventArgs e)
|
{
|
TextBox textElem = (sender as TextBox);
|
if (textElem.Text.Length > 0)
|
{
|
textElem.Text = Math.Round(double.Parse(textElem.Text), 1).ToString();
|
}
|
}
|
|
/// <summary>
|
/// 禁用快捷指令
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void tBoxPreviewPreviewCanExecute(object sender, CanExecuteRoutedEventArgs e)
|
{
|
if (e.Command == ApplicationCommands.Copy ||
|
e.Command == ApplicationCommands.Cut ||
|
e.Command == ApplicationCommands.Paste)
|
{
|
e.CanExecute = false;
|
e.Handled = true;
|
}
|
}
|
|
/// <summary>
|
/// 判断输入值是否为空
|
/// </summary>
|
/// <param name="tbox"></param>
|
/// <param name="strMsg"></param>
|
/// <returns></returns>
|
private bool ValueIsEmpty(TextBox tbox, string strMsg)
|
{
|
if (string.IsNullOrEmpty(tbox.Text))
|
{
|
PlsToolTipWin plsToolTipWin = new PlsToolTipWin(strMsg);
|
plsToolTipWin.btnCancel.Visibility = Visibility.Hidden;
|
plsToolTipWin.ShowDialog();
|
tbox.Focus();
|
return false;
|
}
|
|
return true;
|
}
|
|
/// <summary>
|
/// 判断结果是否失败
|
/// </summary>
|
/// <param name="result"></param>
|
/// <param name="strMsg"></param>
|
private void ResultIsFail(HxResult result, string strMsg)
|
{
|
if (result.Result != ResultType.Success)
|
{
|
System.Windows.Application.Current.Dispatcher.Invoke(new Action(() =>
|
{
|
PlsToolTipWin plsToolTipWin = new PlsToolTipWin(string.Format("{0}失败:{1}", strMsg, result.AlarmInfo));
|
plsToolTipWin.btnCancel.Visibility = Visibility.Hidden;
|
plsToolTipWin.ShowDialog();
|
}));
|
}
|
}
|
#endregion
|
}
|
}
|