using DataEntity.Share;
using DataRWDAL;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Xml.Linq;
using XCommon.Log;
using XHandler.Class.DataEx;
using XHandler.View.MethodProperty;
using XImagingXhandler.XDAL;
namespace XHandler.View.Consumables
{
///
/// 选择适配枪头
///
public partial class TipLoadedTypeSet : Window
{
ObservableCollection labwaresAll = new ObservableCollection();
ObservableCollection srcLabwares = new ObservableCollection();
Labware srcLabware = new Labware();
List checkBoxes = new List();
public TipLoadedTypeSet(ObservableCollection labwares, Labware sLabware)
{
InitializeComponent();
this.Owner = (Window)Shared.Main;
try
{
//加载所有的枪头
labwaresAll = LabwareDB.GetLabware(0, "", "枪头");
srcLabwares = labwares;
srcLabware = sLabware;
//绑定所有labwares
foreach (Labware labware in labwaresAll)
{
CheckBox checkBox = new CheckBox();
checkBox.Content = labware.labware_name;
checkBox.Click += new RoutedEventHandler(cbx_Click);
var a = labwares.FirstOrDefault(x => x.labware_id.Equals(labware.labware_id));
if (a != null)
{
checkBox.IsChecked = true;
checkBox.Tag = a;
}
else
{
checkBox.Tag = labware;
checkBox.IsChecked = false;
}
listboxPlates.Items.Add(checkBox);
checkBoxes.Add(checkBox);
}
listboxPlates.DataContext = labwaresAll;
//选中已经设置的labwares
}
catch (Exception ex)
{
LoggerHelper.ErrorLog("ERROR:", ex);
}
}
private void searchLabware_PreviewKeyDown(object sender, KeyEventArgs e)
{
try
{
if (e.Key == Key.Enter)
{
string search = searchLabware.Text.Trim();
listboxPlates.Items.Clear();
checkBoxes.Clear();
//绑定所有labwares
foreach (Labware labware in labwaresAll.Where(s => s.labware_name.Contains(search)).ToList())
{
CheckBox checkBox = new CheckBox();
checkBox.Content = labware.labware_name;
checkBox.Click += new RoutedEventHandler(cbx_Click);
var a = srcLabwares.FirstOrDefault(x => x.labware_id.Equals(labware.labware_id));
if (a != null)
{
checkBox.IsChecked = true;
checkBox.Tag = a;
}
else
{
checkBox.Tag = labware;
checkBox.IsChecked = false;
}
listboxPlates.Items.Add(checkBox);
checkBoxes.Add(checkBox);
}
//listboxPlates.DataContext = labwaresAll;
//选中已经设置的labwares
}
}
catch (Exception ex)
{
LoggerHelper.ErrorLog("ERROR:", ex);
}
}
object currentSelectItem = null;
private void listboxPlates_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (listboxPlates.SelectedIndex == -1)
{
return;
}
// 这里填写你所需要处理的代码
currentSelectItem = listboxPlates.SelectedItems[0];
if (currentSelectItem != null)
{
CheckBox checkBox = (CheckBox)currentSelectItem;
Labware labware = (Labware)checkBox.Tag;
}
// 最好修改SelectedIndex
//listboxPlates.SelectedIndex = -1;
}
private void btnClose_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
private void cbx_Click(object sender, RoutedEventArgs e)
{
}
private void btnConfirm_Click(object sender, RoutedEventArgs e)
{
try
{
if (listboxPlates.Items.Count > 0)
{
StringBuilder strResult = new StringBuilder();
for (int i = 0; i < checkBoxes.Count; i++)
{
CheckBox cbx = checkBoxes[i];
if (cbx != null)
{
if (cbx.IsChecked == true)
{
Labware id = (Labware)cbx.Tag;
var a = labwaresAll.FirstOrDefault(n => n.labware_id.Equals(id.labware_id));
if (a != null)
{
if(strResult.Length>=1)
{
txtError.Text = "仅支持一种Tip";
return;
}
strResult.Append(id.labware_id + ",");
}
}
}
}
//更新
srcLabware.tip_loaded_type = strResult.ToString().TrimEnd(',');
LabwareDB.UpdateLabwareIntodb(srcLabware);
}
this.Close();
}
catch (Exception ex)
{
LoggerHelper.ErrorLog("ERROR:", ex);
}
}
#region 查找控件的子控件,并返回子控件对象
public List GetChildObjects(DependencyObject obj, Type typename) where T : FrameworkElement
{
DependencyObject child = null;
List childList = new List();
for (int i = 0; i <= VisualTreeHelper.GetChildrenCount(obj) - 1; i++)
{
child = VisualTreeHelper.GetChild(obj, i);
if (child is T && (((T)child).GetType() == typename))
{
childList.Add((T)child);
}
childList.AddRange(GetChildObjects(child, typename));
}
return childList;
}
#endregion
private void tbxPiledcoordinateX_TextChanged(object sender, TextChangedEventArgs e)
{
if (currentSelectItem != null)
{
CheckBox checkBox = (CheckBox)currentSelectItem;
Labware labware = (Labware)checkBox.Tag;
}
}
private void tbxPiledcoordinateY_TextChanged(object sender, TextChangedEventArgs e)
{
if (currentSelectItem != null)
{
CheckBox checkBox = (CheckBox)currentSelectItem;
Labware labware = (Labware)checkBox.Tag;
}
}
private void tbxPiledcoordinateZ_TextChanged(object sender, TextChangedEventArgs e)
{
if (currentSelectItem != null)
{
CheckBox checkBox = (CheckBox)currentSelectItem;
Labware labware = (Labware)checkBox.Tag;
}
}
#region 拖动窗体
///
/// 拖动窗体
///
///
///
private void Grid_MouseDown(object sender, MouseButtonEventArgs e)
{
if (e.ChangedButton == MouseButton.Left)
{
this.DragMove();
}
}
#endregion
#region ESC关闭画面
///
/// ESC关闭画面
///
///
///
private void Window_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Escape)
{
this.Close();
}
}
#endregion
}
}