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.View.MethodProperty; using XImagingXhandler.XDAL; namespace XHandler.View.Consumables { /// /// PiledPlateSet.xaml 的交互逻辑 /// public partial class PiledPlateSet : Window { ObservableCollection labwaresAll = new ObservableCollection(); Labware srcLabware = new Labware(); List checkBoxes = new List(); public PiledPlateSet(ObservableCollection labwares, Labware sLabware) { InitializeComponent(); this.Owner = (Window)Shared.Main; try { //加载所有的labware labwaresAll = LabwareDB.GetLabware(2); 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); } } 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; tbxPiledcoordinateX.Text = labware.x; tbxPiledcoordinateY.Text = labware.y; tbxPiledcoordinateZ.Text = labware.z; } // 最好修改SelectedIndex //listboxPlates.SelectedIndex = -1; } private void btnClose_Click(object sender, RoutedEventArgs e) { this.Close(); } private void cbx_Click(object sender, RoutedEventArgs e) { //CheckBox cbx = (CheckBox)sender; //if(cbx!=null) //{ // Labware lab = (Labware)cbx.Tag; // tbxPiledcoordinateX.Text = lab.x.ToString(); // tbxPiledcoordinateY.Text = lab.y.ToString(); // tbxPiledcoordinateZ.Text = lab.z.ToString(); //} } private void btnConfirm_Click(object sender, RoutedEventArgs e) { try { string x = tbxPiledcoordinateX.Text; string y = tbxPiledcoordinateY.Text; string z = tbxPiledcoordinateZ.Text; if (double.TryParse(x, out double numx) && double.TryParse(y, out double numy) && double.TryParse(z, out double numz)) { //获取范围数组 if ((0.0 > numx || numx > 10.0) || (0.0 > numy || numy > 10.0) || (0.0 > numz || numz > 10.0)) { txtError.Text = "请输入[0.0-10.0]内的值"; return; } } else { txtError.Text = "请输入正确的值"; return; } if (string.IsNullOrEmpty(x) || string.IsNullOrEmpty(y) || string.IsNullOrEmpty(z)) { txtError.Text = "不能为空"; return; } if (x.Contains("-") || y.Contains("-") || z.Contains("-")) { txtError.Text = "不能为负数"; return; } if (listboxPlates.Items.Count > 0) { string strResultHead = string.Empty; strResultHead = "{list:["; string strResultContent = string.Empty; 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) { strResultContent += "{labwereid:\"" + id.labware_id + "\",x:" + id.x + ",y:" + id.y + ",z:" + id.z + "},"; } } } } string strResult = string.Empty; if (string.IsNullOrEmpty(strResultContent)) { strResult = strResultHead + "]}"; } else { strResult = strResultHead + strResultContent.Substring(0, strResultContent.Length - 1) + "]}"; } //更新 srcLabware.piled_script = strResult; 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; labware.x = tbxPiledcoordinateX.Text; //labware.y= tbxPiledcoordinateY.Text; //labware.z= tbxPiledcoordinateZ.Text; } } private void tbxPiledcoordinateY_TextChanged(object sender, TextChangedEventArgs e) { if (currentSelectItem != null) { CheckBox checkBox = (CheckBox)currentSelectItem; Labware labware = (Labware)checkBox.Tag; //labware.x= tbxPiledcoordinateX.Text; labware.y = tbxPiledcoordinateY.Text; //labware.z= tbxPiledcoordinateZ.Text; } } private void tbxPiledcoordinateZ_TextChanged(object sender, TextChangedEventArgs e) { if (currentSelectItem != null) { CheckBox checkBox = (CheckBox)currentSelectItem; Labware labware = (Labware)checkBox.Tag; //labware.x = tbxPiledcoordinateX.Text; //labware.y = tbxPiledcoordinateY.Text; labware.z = tbxPiledcoordinateZ.Text; } } #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 } }