using DataEntity.Device; using DataEntity.Share; using DataRWDAL; using DataRWDAL.Device; using HandyControl.Data; using HxEnum; using NPOI.SS.Formula.Functions; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Configuration; using System.Linq; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Xml; using XCommon; using XCommon.Log; using XCommon.Tip; using XCommon.Xml; using XCore; using XHandler.Class; using XHandler.Class.DataEx; using XHandler.Controls; using XHandler.View.BacteriaProperty; using XHandler.View.Dialog; using XHandler.View.MethodProperty; using XImagingXhandler.XDAL; using XHandler.View.Consumables; using DataEntity; using MySqlX.XDevAPI.Relational; using XHandler.View.Liquids; using XHandler.View.Com; using DriverLibrary; using XHandler.View.MethodProperty.ElectroPart; using System.Reflection; namespace XHandler.View { /// /// TestDesign.xaml 的交互逻辑 /// public partial class TestDesign : UserControl,IConsumableObserver,IElseFromIfObserver { private int nTableRows = 4; // 台面行数 private int nTableColumns = 5; // 台面列数 private double zoomVal = 2.5; //真实台面与显示台面的比例 public ObservableCollection methodGroupCollection = new ObservableCollection(); public MethodEx rootMethod = new MethodEx(); private AdornerLayer mAdornerLayer = null; private bool isDragDrop = false; private MethodListBll methodListBll = new MethodListBll(); private int nTrashIndex = -1; // 垃圾桶耗材索引 private ObservableCollection labwareCollection; private LabwareEx copyLabware = null; private List copyMethod = null; private MainWindow mainWindow = null; public static List SelectLabwares = new List(); public bool IsIgnore = false; // 忽略拖动 public TestDesign() { InitializeComponent(); nTableRows = Shared.SoftwareInformation.rows; nTableColumns = Shared.SoftwareInformation.columns; mainWindow = (MainWindow)Application.Current.MainWindow; // 获取命令集 ObservableCollection methods = MethodDB.GetMethodFromdb(Shared.SoftwareInformation.software_device_number); // 获取命令分组 ObservableCollection group = MethodGroupDB.GetMethodGroupFromdb(); foreach (MethodGroup mg in group) { CMethodGroup cmg = new CMethodGroup(); cmg.GroupName = mg.method_group_name; var list = methods.Where(s => s.method_group_id == mg.method_group_id).ToList(); foreach (var item in list) { MethodEx mEx = new MethodEx(item); if (mEx.method_group_id == EnumManagement.GetEnumValue(MethodGroupEnum.ThirdPart)) { mEx.device = DeviceConfigDB.GetInfodById(mEx.method_id.ToString()); } cmg.Children.Add(mEx); } if (cmg.Children.Count > 0) { methodGroupCollection.Add(cmg); } } listboxCmd.ItemsSource = methodGroupCollection; // 获取耗材类型 ObservableCollection labwareTypeCollection = DataModule.getInstance().GetLabwareTypes(); if (labwareTypeCollection.FirstOrDefault(x => x.labwaretype_name.Equals("请选择")) == null) { labwareTypeCollection.Insert(0, new LabwareType { labwaretype_id = "-1", labwaretype_name = "请选择" }); } cbLabwareType.ItemsSource = labwareTypeCollection; // 获取耗材 labwareCollection = DataModule.getInstance().GetLabwares(); listviewConsumable.ItemsSource = labwareCollection; //判断当前系统使用的是什么台面模板 int latticeNum = 1; // PN TabletopTemplate tabletopTemplate= TabletopTemplateDB.GetCurrentAppTabletopTemplateCollectionFromdb(); if (tabletopTemplate == null) { // 获取当前台面板位信息数据 List latticeList = DataModule.getInstance().GetLattices(); if (Shared.SoftwareInformation.software_device_number.Equals(DeviceCategory.DeviceLiteChoice) || Shared.SoftwareInformation.software_device_number.Equals(DeviceCategory.DeviceT200)) { // 第6列是垃圾桶 nTableColumns++; } #region 台面布局 X行*Y列 for (int i = 0; i < nTableRows; i++) { gridTable.RowDefinitions.Add(new RowDefinition()); } for (int j = 0; j < nTableColumns; j++) { gridTable.ColumnDefinitions.Add(new ColumnDefinition()); } #endregion // 挑菌的板位号:P25/P16 string choiceLatticeId = ConfigurationManager.AppSettings["choiceLatticeId"].ToString(); for (int iColumnIndex = 0; iColumnIndex < nTableColumns; iColumnIndex++) { for (int iRowIndex = 0; iRowIndex < nTableRows; iRowIndex++) { // 板位索引 int latticeIndex = iColumnIndex * nTableRows + iRowIndex; if (latticeIndex + 1 > latticeList.Count) { break; } // 微牧:P16与P17合并单元格,不添加P14控件 if ((Shared.SoftwareInformation.software_device_number.Equals(DeviceCategory.DeviceLiteChoice) || Shared.SoftwareInformation.software_device_number.Equals(DeviceCategory.DeviceT200)) && latticeNum == mainWindow.ChoiceLatticeId + 1) { latticeNum++; continue; } // 是否是垃圾桶 bool isTrash = latticeList[latticeIndex].is_trash == 1; if (isTrash) nTrashIndex = latticeNum; // 添加台面布置格子 Canvas canvas = AddTableItems(iRowIndex, iColumnIndex, latticeNum, isTrash); latticeNum++; int ncol = nTableColumns - iColumnIndex - 1; int zindex = ncol * nTableRows + iRowIndex; Panel.SetZIndex(canvas, zindex); if (Shared.SoftwareInformation.software_device_number.Equals(DeviceCategory.DeviceLiteChoice) || Shared.SoftwareInformation.software_device_number.Equals(DeviceCategory.DeviceT200)) { if (latticeIndex == mainWindow.ChoiceLatticeId - 1) // P16、P17 { Labware lbe = LabwareDB.GetLabware(ConfigurationManager.AppSettings["choicelabwareId"].ToString()); ControlLabware control = new ControlLabware(); if (lbe.labware_type_id == EnumManagement.GetEnumValue(ConsumableTypeEnum.CircularDish).ToString()) // 圆形皿 { control.LabwareWidth = canvas.ActualWidth; control.LabwareHeight = canvas.ActualHeight; control.LeftSideColor = ComUtility.RGBToColor(lbe.labware_color_lside); control.FrontColor = ComUtility.RGBToColor(lbe.labware_color_front); control.TopColor = ComUtility.RGBToColor(lbe.labware_color_top); control.BorderColor = ComUtility.RGBToColor(lbe.labware_color_line); control.Rows = (int)lbe.number_row; control.Columns = (int)lbe.number_column; control.WellColor = Colors.White; control.IsFill = true; control.Label = canvas.Name; control.LabwareType = Convert.ToInt16(lbe.labware_type_id); control.ValidWells = ""; control.Width = canvas.ActualWidth; control.Height = canvas.ActualHeight + 4; } Canvas.SetLeft(control, 0); Canvas.SetBottom(control, 0); LabwareEx lb = new LabwareEx(lbe); lb.row = Grid.GetRow(canvas); lb.col = Grid.GetColumn(canvas); lb.position = canvas.Name; lb.validWells = control.ValidWells; canvas.DataContext = lb; canvas.Children.Add(control); control.SetValidWells(control.ValidWells); } } } } //borderTable.SizeChanged += BorderTable_SizeChanged; gridTable.SizeChanged += GridTable_SizeChanged; } else //使用加载当前使用的模板 { SetTabletopGraduated(); //加载台面板位 //加载该台面模板 ObservableCollection latticesList = TabletopTemplateDB.GetLatticesByTabletopTemplateId(tabletopTemplate.tabletopid); int iLatticeCount = latticesList.Count+1; foreach (Lattice lattice in latticesList) { // 是否是垃圾桶 bool isTrash = (lattice.is_trash == 1) ? true:false; if (isTrash) nTrashIndex = Convert.ToInt32(lattice.lattice_num.Substring(1, lattice.lattice_num.Length - 1)); // 添加台面布置格子 Canvas canvas = AddLatticeIntoTabletop(lattice, tabletopTemplate.tabletopid); //latticeNum++; //int ncol = nTableColumns - iColumnIndex - 1; int zindex = iLatticeCount--; Panel.SetZIndex(canvas, zindex); if (Shared.SoftwareInformation.software_device_number.Equals(DeviceCategory.DeviceLiteChoice) || Shared.SoftwareInformation.software_device_number.Equals(DeviceCategory.DeviceT200)) { if (Convert.ToInt32(lattice.lattice_num.Substring(1, lattice.lattice_num.Length - 1)) == mainWindow.ChoiceLatticeId - 1) // P16、P17 { Labware lbe = LabwareDB.GetLabware(ConfigurationManager.AppSettings["choicelabwareId"].ToString()); ControlLabware control = new ControlLabware(); if (lbe.labware_type_id == EnumManagement.GetEnumValue(ConsumableTypeEnum.CircularDish).ToString()) // 圆形皿 { control.LabwareWidth = canvas.ActualWidth; control.LabwareHeight = canvas.ActualHeight; control.LeftSideColor = ComUtility.RGBToColor(lbe.labware_color_lside); control.FrontColor = ComUtility.RGBToColor(lbe.labware_color_front); control.TopColor = ComUtility.RGBToColor(lbe.labware_color_top); control.BorderColor = ComUtility.RGBToColor(lbe.labware_color_line); control.Rows = (int)lbe.number_row; control.Columns = (int)lbe.number_column; control.WellColor = Colors.White; control.IsFill = true; control.Label = canvas.Name; control.LabwareType = Convert.ToInt16(lbe.labware_type_id); control.ValidWells = ""; control.Width = canvas.ActualWidth; control.Height = canvas.ActualHeight + 4; } Canvas.SetLeft(control, 0); Canvas.SetBottom(control, 0); LabwareEx lb = new LabwareEx(lbe); lb.row = Grid.GetRow(canvas); lb.col = Grid.GetColumn(canvas); lb.position = canvas.Name; lb.validWells = control.ValidWells; canvas.DataContext = lb; canvas.Children.Add(control); control.SetValidWells(control.ValidWells); } } else if (Shared.SoftwareInformation.software_device_number == DeviceCategory.DeviceHXELEC)//电泳切胶槽位置 { if (Convert.ToInt32(lattice.lattice_num.Substring(1, lattice.lattice_num.Length - 1)) == 1) // P1 { Labware lbe = LabwareDB.GetLabware(ConfigurationManager.AppSettings["choicelabwareId"].ToString()); ControlLabware control = new ControlLabware(); if (lbe.labware_type_id == EnumManagement.GetEnumValue(ConsumableTypeEnum.Electrophoto).ToString()) //电泳槽 { control.LabwareWidth = canvas.ActualWidth; control.LabwareHeight = canvas.ActualHeight; control.LabwareRealLength = lbe.labware_length; control.LabwareRealWidth = lbe.labware_width; control.Rows = (int)lbe.number_row; control.Columns = (int)lbe.number_column; control.WellColor = Colors.White; control.IsFill = true; control.Label = canvas.Name; control.LabwareName = lbe.labware_name; control.LabwareType = Convert.ToInt16(lbe.labware_type_id); control.ValidWells = ""; control.labwareWellInfoList = lbe.labwareWellInfoList; control.Loaded += ControlLabware_Loaded; control.Width = canvas.Width; control.Height = canvas.Height; } Canvas.SetLeft(control, 0); Canvas.SetTop(control, 0); LabwareEx lb = new LabwareEx(lbe); lb.row = Grid.GetRow(canvas); lb.col = Grid.GetColumn(canvas); lb.position = canvas.Name; lb.validWells = control.ValidWells; control.Height = canvas.Height; canvas.DataContext = lb; canvas.Children.Add(control); control.SetValidWells(control.ValidWells); labwareExes = new Stack(); labwareExes.Push(lb); canvas.Tag = labwareExes; } } } } #region 初始化工作流 latticeNum = 0; var mList = methods.Where(s => s.method_group_id == EnumManagement.GetEnumValue(MethodGroupEnum.None)).OrderBy(s => s.method_id); rootMethod.method_name = "root"; rootMethod.isEnabled = true; rootMethod.Level = -1; foreach (Method m in mList) { MethodEx mi = new MethodEx(m, rootMethod); mi.Index = rootMethod.Children.Count + 1; mi.strIndex = mi.Index.ToString(); mi.Moveable = false; if (latticeNum == 0) { mi.canDrop = false; } else if ((latticeNum + 1) == mList.Count()) { mi.canDrop = false; } rootMethod.Children.Add(mi); if (mi.method_id == "0") // 开始 { StartProperty property = new StartProperty(mi); mi.control = property; mi.method_isrun = "运行起点"; } else if (mi.method_id == "2") // 结束 { EndProperty property = new EndProperty(mi); mi.control = property; } latticeNum++; } treeviewWorkflow.ItemsSource = rootMethod.Children; TreeViewExtensions.testDesign = this; #endregion if (Shared.SoftwareInformation.software_device_number == DeviceCategory.DeviceHXELEC)//电泳切胶槽位置 { //imgdish.Visibility = Visibility.Visible; //imgdish1.Visibility = Visibility.Collapsed; } if (Shared.SoftwareInformation.software_device_number == DeviceCategory.DeviceChoice) { imgdish.Visibility = Visibility.Visible; //imgdish1.Visibility = Visibility.Collapsed; } else if (Shared.SoftwareInformation.software_device_number == DeviceCategory.DeviceLiteChoice || Shared.SoftwareInformation.software_device_number.Equals(DeviceCategory.DeviceT200)) { //imgdish1.Visibility = Visibility.Visible; imgdish.Visibility = Visibility.Collapsed; } else { imgdish.Visibility = Visibility.Collapsed; //imgdish1.Visibility = Visibility.Collapsed; } } #region 耗材加载后,重新设置高度 private void ControlLabware_Loaded(object sender, RoutedEventArgs e) { var controlLabware= sender as ControlLabware; if(controlLabware!=null) { controlLabware.Height = ((Canvas)(controlLabware.Parent)).Height; controlLabware.Width= ((Canvas)(controlLabware.Parent)).Width; } } #endregion #region 初始化新建流程 public void InitializeWorkFlow(ObservableCollection methods) { int latticeNum = 0; rootMethod.Children.Clear(); var mList = methods.Where(s => s.method_group_id == EnumManagement.GetEnumValue(MethodGroupEnum.None)).OrderBy(s => s.method_id); rootMethod.method_name = "root"; rootMethod.Level = -1; foreach (Method m in mList) { MethodEx mi = new MethodEx(m, rootMethod); mi.Index = rootMethod.Children.Count + 1; mi.strIndex = mi.Index.ToString(); mi.Moveable = false; if (latticeNum == 0) { mi.canDrop = false; } else if ((latticeNum + 1) == mList.Count()) { mi.canDrop = false; } rootMethod.Children.Add(mi); if (mi.method_id == "0") // 开始 { StartProperty property = new StartProperty(mi); mi.control = property; mi.method_isrun = "运行起点"; } else if (mi.method_id == "2") // 结束 { EndProperty property = new EndProperty(mi); mi.control = property; } latticeNum++; } treeviewWorkflow.ItemsSource = rootMethod.Children; TreeViewExtensions.testDesign = this; } #endregion #region 布局当前台面的大小 /// /// 布局当前台面的大小 /// public void SetTabletopGraduated() { double length = Shared.SoftwareInformation.realtabletoplength;//mm double width = Shared.SoftwareInformation.realtabletopwidth;//mm if(Shared.SoftwareInformation.software_device_number.Equals(DeviceCategory.DeviceHXELEC)) { zoomVal = 1.5; } gridTable.Width = length / zoomVal;//统一缩小,即1个像素代表2.5mm gridTable.Height = width / zoomVal; } #endregion #region 向新布局的台面中添加板位--板位用canvas public Canvas AddLatticeIntoTabletop(Lattice lattice,string tabletopid) { int latticeId = Convert.ToInt32(lattice.lattice_num.Substring(1, lattice.lattice_num.Length - 1)); bool bAllowDrop = true; if (latticeId == mainWindow.ChoiceLatticeId) { bAllowDrop = false; } else if ((Shared.SoftwareInformation.software_device_number.Equals(DeviceCategory.DeviceLiteChoice) || Shared.SoftwareInformation.software_device_number.Equals(DeviceCategory.DeviceT200)) && latticeId == 19) { latticeId = 0; } TabletopRelLattice tabletopRelLattice = TabletopRelLatticeDB.GetTabletopRelLatticeByTabletopIdAndLatticeId(tabletopid, Convert.ToInt32(lattice.lattice_id)); Canvas canvas = new Canvas() { Margin = new Thickness(6, 6, 6, 6), AllowDrop = bAllowDrop, Name = "P" + latticeId.ToString(), Width=LabwareDB.GetLabware(tabletopRelLattice.labware_id).labware_length/zoomVal, Height= LabwareDB.GetLabware(tabletopRelLattice.labware_id).labware_width/zoomVal }; TextBlock tb = new TextBlock(); tb.Text = "P" + latticeId.ToString(); tb.FontSize = 18; tb.Foreground = Brushes.Black; tb.VerticalAlignment = VerticalAlignment.Center; tb.HorizontalAlignment = HorizontalAlignment.Center; Border border = new Border() { Background = Brushes.DarkGray, CornerRadius = new CornerRadius(5), Child = tb, }; canvas.Children.Add(border); canvas.Drop += Canvas_Drop; canvas.PreviewMouseDown += Canvas_PreviewMouseDown; canvas.PreviewMouseMove += Canvas_PreviewMouseMove; canvas.QueryContinueDrag += DoQueryContinueDrag; canvas.PreviewDragOver += Canvas_PreviewDragOver; canvas.SizeChanged += Canvas_SizeChanged; canvas.ContextMenu = FindResource("tableMenu") as ContextMenu; canvas.Loaded += Canvas_Loaded; canvas.Tag = tabletopRelLattice; if (lattice.is_trash==1) { ControlLabware cl = new ControlLabware() { IsTrash = true, LabwareName = Properties.Resources.strTrash.ToString() }; LabwareEx lb = new LabwareEx(); lb.labware_name = Properties.Resources.strTrash; lb.row = 0; lb.col = 0; canvas.DataContext = lb; canvas.Children.Add(cl); } gridTable.Children.Add(canvas); //Grid.SetColumn(canvas, column); //Grid.SetRow(canvas, row); if (Shared.SoftwareInformation.software_device_number.Equals(DeviceCategory.DeviceLiteChoice) || Shared.SoftwareInformation.software_device_number.Equals(DeviceCategory.DeviceT200)) { #region 挑菌台面暂时屏蔽 /*if (lattice.is_trash == 1) { Grid.SetColumnSpan(canvas, 1); Grid.SetRowSpan(canvas, 3); } else if (latticeId == mainWindow.ChoiceLatticeId) { Grid.SetColumnSpan(canvas, 1); Grid.SetRowSpan(canvas, 2); // 将Image控件添加到Canvas上 Image image = new Image(); image.Source = (ImageSource)(new ImageSourceConverter()).ConvertFrom(new Uri(@"pack://application:,,,/XHandler;component/Assets/dish_LiteChoice.png")); image.Stretch = Stretch.Fill; image.Width = canvas.Width - 4; image.Height = canvas.Height - 23; Canvas.SetLeft(image, 2); Canvas.SetTop(image, 2); canvas.Children.Add(image); Panel.SetZIndex(image, 99); }*/ #endregion } return canvas; } #endregion #region 板位加载显示完成后,处理布局 private void Canvas_Loaded(object sender, RoutedEventArgs e) { Canvas canvasOfLattice = sender as Canvas; canvasOfLattice.HorizontalAlignment = HorizontalAlignment.Left; canvasOfLattice.VerticalAlignment = VerticalAlignment.Top; canvasOfLattice.Loaded -= Canvas_Loaded; //换算在新的平面坐标中,板位的位置 if (canvasOfLattice.Tag == null) { return; } if (canvasOfLattice.Tag.GetType().Name == "TabletopRelLattice") { if (((TabletopRelLattice)canvasOfLattice.Tag) == null) { return; } } else { return; } TabletopRelLattice tabletopRelLattice= (TabletopRelLattice)canvasOfLattice.Tag; double xPixelVal = tabletopRelLattice.lattice_pixel_x / (zoomVal / (double)2); double yPixelVal = tabletopRelLattice.lattice_pixel_y / (zoomVal / (double)2); canvasOfLattice.Margin = new Thickness(xPixelVal, yPixelVal, 0, 0); canvasOfLattice.Tag = null; } #endregion #region 观察者模式更新所有应用台面的板位 // 保存观察者耗材列表 public List observers = new List(); public void AddObserver(ILatticeObserver ob) { observers.Add(ob); } public void RemoveObserver(ILatticeObserver ob) { observers.Remove(ob); } public void Update() { // 遍历订阅者列表进行通知 foreach (ILatticeObserver ob in observers) { if (ob != null) { ob.ReceiveAndUpdate(this); } } } #endregion #region 观察者模式更新所有应用的等待参数 // 保存观察者等待参数列表 public List observerTimers = new List(); public void AddObserver(ITimerObserver ob) { observerTimers.Add(ob); } public void RemoveObserver(ITimerObserver ob) { observerTimers.Remove(ob); } public void UpdateWaitFor(MethodEx mEx) { //获取指定节点前的timer集合 List methodExesForTimerList = FindNodesFilterTimer(mEx.strIndex); List methodDuringTimerList = new List(); if (methodExesForTimerList != null) { foreach (MethodEx x in methodExesForTimerList) { DropdownName dropdownName = new DropdownName(); dropdownName.dropdown_id = x.strIndex; dropdownName.dropdown_name = (x.control!=null?(x.control as TimerProperty).methodTimer.name:x.method_name); methodDuringTimerList.Add(dropdownName); } } // 遍历订阅者列表进行通知 foreach (ITimerObserver ob in observerTimers) { if (ob != null) { if (((WaitforProperty)ob).method.strIndex == mEx.strIndex) { ob.ReceiveAndUpdate(methodDuringTimerList); break; } } } } #endregion public void ReceiveAndUpdate(ConsumableManagement consumableManagement) { //// 获取耗材类型 //ObservableCollection labwareTypeCollection = DataModule.getInstance().GetLabwareTypes(); //if (labwareTypeCollection.FirstOrDefault(x => x.labwaretype_name.Equals("请选择")) == null) //{ // labwareTypeCollection.Insert(0, new LabwareType { labwaretype_id = "-1", labwaretype_name = "请选择" }); //} //cbLabwareType.ItemsSource = labwareTypeCollection; //// 获取耗材 //labwareCollection = DataModule.getInstance().GetLabwares(); //listviewConsumable.ItemsSource = labwareCollection; //更新前先生成现有台面的xml节点对象; //清除所有耗材对象; //恢复保存的xml节点对象到台面 XmlHelper xmlHelper = new XmlHelper(); xmlHelper.xmlDoc = GenerateLaunchXmlDocument(); btnResetTable_Click(null, null); mainWindow.BindSetLatticesDataOnUI(xmlHelper.xmlDoc); } #region 在给定的树节点中加入或者移除else节点 public void ReceiveAndUpdate(MethodEx methodEx,bool containElse) { try { if(methodEx!=null) { if(containElse) { //在给定的节点同级别层次加入else节点 } else { //删除仅跟随在给定节点之后的else节点 } } } catch(Exception ex) { } } #endregion /// /// 添加第三方设备命令 /// /// private void AddThirdPartChildren(CMethodGroup cmg) { // 根据项目ID,获取设备列表 var lstDevice = DeviceConfigDB.GetDeviceConfigListByProjectId(Shared.SoftwareInformation.software_information_id); foreach (var deviceItem in lstDevice) { Method m = new Method(); m.method_id = deviceItem.Id==null? "0" : deviceItem.Id; m.method_name = deviceItem.Name; m.method_status = EnumManagement.GetEnumValue(MethodStatusEnum.Valid); // 有效 m.method_content = deviceItem.Name; m.method_Tipcontent = string.Empty; m.method_ico = deviceItem.EquipmentImg; // 设备图片 m.method_group_id = EnumManagement.GetEnumValue(MethodGroupEnum.ThirdPart); // 第三方设备 m.method_support = EnumManagement.GetEnumValue(MethodSupportEnum.Support); // 支持 m.method_type = EnumManagement.GetEnumValue(MethodTypeEnum.SingleStep); // 单指令 MethodEx mEx = new MethodEx(m); mEx.device = deviceItem; cmg.Children.Add(mEx); } } private void BorderTable_SizeChanged(object sender, SizeChangedEventArgs e) { if (borderTable.ActualWidth <= 0) return; borderTable.Height = borderTable.ActualWidth * 9 / 16; } private void GridTable_SizeChanged(object sender, SizeChangedEventArgs e) { if (gridTable.ActualWidth <= 0) return; //gridTable.Height = gridTable.ActualWidth * 9 / 15; wdy double w = gridTable.ActualWidth / nTableColumns; double h = gridTable.ActualHeight / nTableRows; imgdish.Width = w * 2 - 5; imgdish.Height = h * 2 - 5; //imgdish1.Width = w - 5; //imgdish1.Height = h * 2 - 5; } /// /// 添加台面布置格子 /// /// /// /// /// /// private Canvas AddTableItems(int row, int column, int latticeNum, bool isTrash) { bool bAllowDrop = true; if (latticeNum == mainWindow.ChoiceLatticeId) { bAllowDrop = false; } else if ((Shared.SoftwareInformation.software_device_number.Equals(DeviceCategory.DeviceLiteChoice) || Shared.SoftwareInformation.software_device_number.Equals(DeviceCategory.DeviceT200)) && latticeNum == 19) { latticeNum = 0; } Canvas canvas = new Canvas() { Margin = new Thickness(6, 6, 6, 6), AllowDrop = bAllowDrop, Name = "P" + latticeNum.ToString(), }; TextBlock tb = new TextBlock(); tb.Text = "P" + latticeNum.ToString(); tb.FontSize = 18; tb.Foreground = Brushes.Black; tb.VerticalAlignment = VerticalAlignment.Center; tb.HorizontalAlignment = HorizontalAlignment.Center; Border border = new Border() { Background = Brushes.DarkGray, CornerRadius = new CornerRadius(5), Child = tb, }; canvas.Children.Add(border); canvas.Drop += Canvas_Drop; canvas.PreviewMouseDown += Canvas_PreviewMouseDown; canvas.PreviewMouseMove += Canvas_PreviewMouseMove; canvas.QueryContinueDrag += DoQueryContinueDrag; canvas.PreviewDragOver += Canvas_PreviewDragOver; canvas.SizeChanged += Canvas_SizeChanged; canvas.ContextMenu = FindResource("tableMenu") as ContextMenu; if (isTrash) { ControlLabware cl = new ControlLabware() { IsTrash = true, LabwareName = Properties.Resources.strTrash.ToString() //LabwareName = string.Format("垃{0}圾{0}桶", Environment.NewLine) }; LabwareEx lb = new LabwareEx(); lb.labware_name = Properties.Resources.strTrash; //lb.labware_name = string.Format("垃{0}圾{0}桶", Environment.NewLine); lb.row = row; lb.col = column; canvas.DataContext = lb; canvas.Children.Add(cl); } gridTable.Children.Add(canvas); Grid.SetColumn(canvas, column); Grid.SetRow(canvas, row); if (Shared.SoftwareInformation.software_device_number.Equals(DeviceCategory.DeviceLiteChoice) || Shared.SoftwareInformation.software_device_number.Equals(DeviceCategory.DeviceT200)) { if (isTrash) { Grid.SetColumnSpan(canvas, 1); Grid.SetRowSpan(canvas, 3); } else if (latticeNum == mainWindow.ChoiceLatticeId) { Grid.SetColumnSpan(canvas, 1); Grid.SetRowSpan(canvas, 2); // 将Image控件添加到Canvas上 Image image = new Image(); image.Source = (ImageSource)(new ImageSourceConverter()).ConvertFrom(new Uri(@"pack://application:,,,/XHandler;component/Assets/dish_LiteChoice.png")); image.Stretch = Stretch.Fill; image.Width = canvas.Width - 4; image.Height = canvas.Height - 23; Canvas.SetLeft(image, 2); Canvas.SetTop(image, 2); canvas.Children.Add(image); Panel.SetZIndex(image, 99); } } return canvas; } #region 初始化 /// /// 初始化 /// /// /// private void UserControl_Loaded(object sender, RoutedEventArgs e) { cbLabwareType.SelectedIndex = 0; UpdateLabwareExData(); var scrollViewer = GetScrollViewer(treeviewWorkflow); if (scrollViewer != null) { scrollViewer.CanContentScroll = false; } } private void UpdateLabwareExData() { foreach (var item in gridTable.Children) { Canvas canvas = item as Canvas; if (canvas.DataContext != null) { LabwareEx l = canvas.DataContext as LabwareEx; if (!string.IsNullOrEmpty(l.labware_id)) { Labware labware = labwareCollection.Where(s => s.labware_id == l.labware_id).FirstOrDefault(); if (labware != null) { l.Update(labware); } else { //已拖出此耗材后删除该耗材导致的null PlsSetProperty plsSetProperty = new PlsSetProperty($"引用的耗材:{l.labware_name},加载失败,此耗材将自动从台面删除", false); plsSetProperty.closeEvent += PlsSetProperty_closeEvent; System.Windows.Window wnd = Application.Current.MainWindow; Grid parent = Utilities.FindVisualChild(wnd); parent.Children.Add(plsSetProperty); ControlLabware labwareError = Utilities.FindVisualChild(canvas); if (labwareError == null || labwareError.IsTrash) return; if (labwareError != null) { canvas.Children.Remove(labwareError); canvas.DataContext = null; } } } } } } #endregion #region 台面布置 #region 台面布置单元格中 松开拖拽 //一个存放Canvas的DataContext的集合对象 Stack labwareExes= new Stack(); public Canvas srcCanvas = null;//台面布局拖动更改后,更新关联的已有设计命令用 public Canvas targetCanvas = null;//台面布局拖动更改后,更新关联的已有设计命令用 private void Canvas_Drop(object sender, DragEventArgs e) { Canvas canvas = sender as Canvas; targetCanvas = canvas; // 挑菌位不可拖动 if (canvas.Name.Equals(ConfigurationManager.AppSettings["choiceLatticeId"].ToString())) { e.Handled = true; //LoggerHelper.DebugLog(string.Format("===================== Canvas_Drop, Handled = true, sender Canvas.Name = {0}=====================", canvas.Name)); return; } if (e.Effects == DragDropEffects.Move) { Canvas source = e.Data.GetData("Canvas") as Canvas; if (source.Name.Equals(ConfigurationManager.AppSettings["choiceLatticeId"].ToString())) { e.Handled = true; //LoggerHelper.DebugLog(string.Format("===================== Canvas_Drop, Handled = true, source Canvas.Name = {0}=====================", canvas.Name)); return; } ControlLabware clabware = (ControlLabware)Utilities.FindLastVisualChild(source); if (clabware != null) { labwareExes = (Stack)source.Tag; LabwareEx labwareExPop = new LabwareEx(); ; if (labwareExes.Count > 0) { labwareExes.Pop(); } source.Children.Remove(clabware); if (source.Children.Count > 1) { //source.DataContext = null; source.DataContext = labwareExes.Peek(); source.Tag = labwareExes; } else { source.DataContext = null; } } } LabwareEx lb = e.Data.GetData("LabwareEx") as LabwareEx; if (e.Effects == DragDropEffects.Copy || e.Effects == DragDropEffects.Move) { lb.label = canvas.Name; } ControlLabware control = new ControlLabware(); control.LeftSideColor = ComUtility.RGBToColor(lb.labware_color_lside); control.FrontColor = ComUtility.RGBToColor(lb.labware_color_front); control.TopColor = ComUtility.RGBToColor(lb.labware_color_top); control.BorderColor = ComUtility.RGBToColor(lb.labware_color_line); control.AllowDrop = true; //control.Drop += ControlLabware_Drop; if (lb.labware_type_id == EnumManagement.GetEnumValue(ConsumableTypeEnum.CircularDish).ToString()) // 圆形皿 { control.LabwareWidth = canvas.ActualWidth; control.LabwareHeight = canvas.ActualHeight;// canvas.ActualWidth*50/90; control.Rows = (int)lb.number_row; control.Columns = (int)lb.number_column; control.WellColor = Colors.White; control.IsFill = true; control.Label = lb.label; control.LabwareName = lb.labware_name; control.LabwareType = Convert.ToInt16(lb.labware_type_id); control.ValidWells = lb.validWells; control.Width = canvas.ActualWidth; control.Height = canvas.ActualHeight + 4; } else if (lb.labware_type_id == EnumManagement.GetEnumValue(ConsumableTypeEnum.TipsBox).ToString()) // 吸头盒 { control.LabwareWidth = canvas.ActualWidth; control.LabwareHeight = canvas.ActualHeight; control.Rows = (int)lb.number_row; control.Columns = (int)lb.number_column; control.WellColor = Colors.White; control.IsFill = true; control.Label = lb.label; control.LabwareName = lb.labware_name; control.LabwareType = Convert.ToInt16(lb.labware_type_id); } else if (lb.labware_type_id == EnumManagement.GetEnumValue(ConsumableTypeEnum.Tube).ToString()) // 管架 { control.LabwareWidth = canvas.ActualWidth; control.LabwareHeight = canvas.ActualHeight; control.LabwareRealLength = lb.labware_length; control.LabwareRealWidth = lb.labware_width; control.Rows = (int)lb.number_row; control.Columns = (int)lb.number_column; control.WellColor = Colors.White; control.IsFill = true; control.Label = lb.label; control.LabwareName = lb.labware_name; control.LabwareType = Convert.ToInt16(lb.labware_type_id); control.ValidWells = lb.validWells; control.labwareWellInfoList = lb.labwareWellInfoList; } else if (lb.labware_type_id == EnumManagement.GetEnumValue(ConsumableTypeEnum.Electrophoto).ToString()) // 电泳槽 { control.LabwareWidth = canvas.ActualWidth; control.LabwareHeight = canvas.ActualHeight; control.LabwareRealLength = lb.labware_length; control.LabwareRealWidth = lb.labware_width; control.Rows = (int)lb.number_row; control.Columns = (int)lb.number_column; control.WellColor = Colors.White; control.IsFill = true; control.Label = lb.label; control.LabwareName = lb.labware_name; control.LabwareType = Convert.ToInt16(lb.labware_type_id); control.ValidWells = lb.validWells; control.labwareWellInfoList = lb.labwareWellInfoList; } else { control.LabwareWidth = canvas.ActualWidth; control.LabwareHeight = canvas.ActualHeight; control.Rows = (int)lb.number_row; control.Columns = (int)lb.number_column; control.WellColor = Colors.White; control.IsFill = true; control.Label = lb.label; control.LabwareName = lb.labware_name; control.LabwareType = Convert.ToInt16(lb.labware_type_id); control.ValidWells = lb.validWells; } if (lb.labware_type_id == EnumManagement.GetEnumValue(ConsumableTypeEnum.TipsBox).ToString() || lb.labware_type_id == EnumManagement.GetEnumValue(ConsumableTypeEnum.Plate).ToString()) // 吸头盒、孔板 { // 设置有效孔位 string validWells = ComUtility.GetValidWells((int)lb.number_row, (int)lb.number_column); lb.validWells = control.ValidWells = validWells; } else { control.LabwareWidth = canvas.ActualWidth; control.LabwareHeight = canvas.ActualHeight; control.Rows = (int)lb.number_row; control.Columns = (int)lb.number_column; control.WellColor = Colors.White; control.IsFill = true; control.Label = lb.label; control.LabwareName = lb.labware_name; control.LabwareType = Convert.ToInt16(lb.labware_type_id); control.ValidWells = lb.validWells; } control.DataContext = (Labware)lb; Canvas.SetLeft(control, 0); Canvas.SetBottom(control, 0); lb.row = Grid.GetRow(canvas); lb.col = Grid.GetColumn(canvas); lb.position = canvas.Name; canvas.DataContext = lb; labwareExes = (Stack)canvas.Tag; if (labwareExes != null) { } else { labwareExes = new Stack(); } labwareExes.Push(lb); canvas.Tag = labwareExes; if (lb.labware_type_id == EnumManagement.GetEnumValue(ConsumableTypeEnum.Tips).ToString()) // 吸头 { return; } //根据重叠的层级,设置margin,用的是下层的耗材数据计算 double leftMargin = 0;//离左侧距离 double bottomMargin = 0;//离底部距离 for (int i=0;i< canvas.Children.Count;i++) { ControlLabware a = canvas.Children[i] as ControlLabware; if(a!=null) { leftMargin += a.LabwareDeep; bottomMargin += a.LabwareDeep; } } control.Margin = new Thickness(leftMargin , 0, 0, bottomMargin); canvas.Children.Add(control); SelectLabwares.Add(control); Border labelText = Utilities.FindVisualChild(canvas); if (labelText != null) { labelText.Width = canvas.ActualWidth; } //如果是第二及其以上耗材,要隐藏标签 if (labwareExes.Count > 1) { control.Label = ""; } else { } SetLabwareSelection(control); SetTableName(canvas.Name, lb); //引用 mainWindow.SetObserverNode(rootMethod); Update(); srcCanvas = null; targetCanvas = null; } //private void ControlLabware_Drop(object sender, DragEventArgs e) //{ // ControlLabware targetControlLabware = (ControlLabware)sender; // //判断耗材的物理高度,在某些项目中深孔板、试剂槽、圆形皿、枪头盒、管架、枪头不允许叠放; // if (e.Effects == DragDropEffects.Move) // { // ControlLabware source = e.Data.GetData("ControlLabware") as ControlLabware; // } //} #endregion #region 台面布置单元格中 鼠标点击 private void Canvas_PreviewMouseDown(object sender, MouseButtonEventArgs e) { if (e.ChangedButton == MouseButton.Left) { Canvas grid = sender as Canvas; // 挑菌位不可拖动 if (grid.Name.Equals(ConfigurationManager.AppSettings["choiceLatticeId"].ToString())) { e.Handled = true; //LoggerHelper.DebugLog(string.Format("===================== Canvas_PreviewMouseDown, Handled = true, Canvas.Name = {0}=====================", grid.Name)); return; } _lastMouseDown = e.GetPosition(grid); int row = Grid.GetRow(grid); int col = Grid.GetColumn(grid); int index = row * nTableColumns + col + 1; ControlLabware control = (ControlLabware)Utilities.FindLastVisualChild(grid); if (control == null) { SetTableName(grid.Name, null); } else { SetLabwareSelection(control); labwareExes = (Stack)grid.Tag; if (labwareExes!=null&&labwareExes.Count > 0) { SetTableName(grid.Name, labwareExes.Peek() as Labware); } else { SetTableName(grid.Name, grid.DataContext as Labware); } } srcCanvas = grid; //LoggerHelper.DebugLog(string.Format("===================== Canvas_PreviewMouseDown Canvas.Name = {0}=====================", grid.Name)); } } #endregion #region 台面布置单元格中 鼠标移动 private void Canvas_PreviewMouseMove(object sender, MouseEventArgs e) { if (e.LeftButton == MouseButtonState.Pressed) { Canvas grid = sender as Canvas; // 挑菌位不可拖动 if (grid.Name.Equals(ConfigurationManager.AppSettings["choiceLatticeId"].ToString())) { e.Handled = true; //LoggerHelper.DebugLog(string.Format("===================== Canvas_PreviewMouseMove, Handled = true, Canvas.Name = {0}=====================", grid.Name)); return; } Point currentPosition = e.GetPosition(grid); if ((Math.Abs(currentPosition.X - _lastMouseDown.X) > SystemParameters.MinimumHorizontalDragDistance) || (Math.Abs(currentPosition.Y - _lastMouseDown.Y) > SystemParameters.MinimumVerticalDragDistance)) { Canvas canvas = sender as Canvas; if (canvas.DataContext == null) { return; } ControlLabware control = (ControlLabware)Utilities.FindLastVisualChild(canvas); if (control == null || control.IsTrash) { return; } DragDropAdorner adorner = new DragDropAdorner((UIElement)control); mAdornerLayer = AdornerLayer.GetAdornerLayer(grid2); mAdornerLayer.Add(adorner); LabwareEx labware = canvas.DataContext as LabwareEx; DataObject data = new DataObject("LabwareEx", labware); data.SetData("Canvas", canvas); data.SetData("ControlLabware", control); DragDrop.DoDragDrop(canvas, data, DragDropEffects.Move); mAdornerLayer.Remove(adorner); mAdornerLayer = null; } //LoggerHelper.DebugLog(string.Format("===================== Canvas_PreviewMouseMove Canvas.Name = {0}=====================", grid.Name)); } } #endregion private void DoQueryContinueDrag(object sender, QueryContinueDragEventArgs e) { Canvas grid = sender as Canvas; // 挑菌位不可拖动 if (grid != null && grid.Name.Equals(ConfigurationManager.AppSettings["choiceLatticeId"].ToString())) { e.Handled = true; //LoggerHelper.DebugLog(string.Format("===================== DoQueryContinueDrag, Handled = true, Canvas.Name = {0}=====================", grid.Name)); return; } if (mAdornerLayer != null) { mAdornerLayer.Update(); } //LoggerHelper.DebugLog(string.Format("===================== DoQueryContinueDrag Canvas.Name = {0}=====================", grid.Name)); } #region 台面布置单元格 拖放结束 private void Canvas_PreviewDragOver(object sender, DragEventArgs e) { Canvas grid = sender as Canvas; // 挑菌位不可拖动 if (grid.Name.Equals(ConfigurationManager.AppSettings["choiceLatticeId"].ToString())) { e.Handled = true; //LoggerHelper.DebugLog(string.Format("===================== Canvas_PreviewDragOver, Handled = true, Canvas.Name = {0}=====================", grid.Name)); return; } if (!e.Data.GetDataPresent("LabwareEx")) { e.Effects = DragDropEffects.None; } else { ControlLabware cl = Utilities.FindVisualChild(grid); if (cl != null) { e.Effects = DragDropEffects.Copy; } } //e.Handled = true; //LoggerHelper.DebugLog(string.Format("===================== Canvas_PreviewDragOver Canvas.Name = {0}=====================", grid.Name)); } #endregion #region 台面布置单元格 尺寸变更 private void Canvas_SizeChanged(object sender, SizeChangedEventArgs e) { Canvas canvas = (Canvas)sender; if (canvas.Children.Count > 0) { Border bd = canvas.Children[0] as Border; bd.Width = canvas.ActualWidth; bd.Height = canvas.ActualHeight; //cl.LabwareWidth = canvas.ActualWidth - cl.LabwareDeep; } if (canvas.DataContext != null) { LabwareEx l = (LabwareEx)canvas.DataContext; if (string.IsNullOrEmpty(l.labware_type_id)) { ControlLabware cl = Utilities.FindVisualChild(canvas); if (cl != null) { cl.Width = canvas.ActualWidth; cl.Height = canvas.ActualHeight; } } else { if (canvas.Children.Count > 1) { ControlLabware cl = Utilities.FindVisualChild(canvas); if (cl == null) { return; } if (l.labware_type_id == EnumManagement.GetEnumValue(ConsumableTypeEnum.CircularDish).ToString()) // 圆形皿 { cl.LabwareWidth = canvas.ActualWidth; cl.LabwareHeight = canvas.ActualHeight; cl.Width = canvas.ActualWidth; cl.Height = canvas.ActualHeight + 4; } else { cl.LabwareWidth = canvas.ActualWidth; cl.LabwareHeight = canvas.ActualHeight; if (cl.ValidWells != null) { string wells = cl.ValidWells; cl.ValidWells = ""; cl.ValidWells = wells; } } } } } // 挑菌位图片大小适配 if (canvas.Name.Equals(ConfigurationManager.AppSettings["choiceLatticeId"].ToString())) { Image img = Utilities.FindVisualChild(canvas); if (img != null) { img.Width = canvas.ActualWidth - 4; img.Height = canvas.ActualHeight - 23; } ControlLabware cl = Utilities.FindVisualChild(canvas); if (cl != null) { cl.LabwareWidth = canvas.ActualWidth - 10; cl.LabwareHeight = 50; } } } #endregion #endregion #region 耗材一览 #region 耗材点击 private void listviewConsumable_PreviewMouseDown(object sender, MouseButtonEventArgs e) { if (e.ChangedButton == MouseButton.Left) { _lastMouseDown = e.GetPosition(listviewConsumable); } } #endregion #region 耗材移动 private void listviewConsumable_PreviewMouseMove(object sender, MouseEventArgs e) { if (e.LeftButton == MouseButtonState.Pressed) { Point currentPosition = e.GetPosition(listviewConsumable); if ((Math.Abs(currentPosition.X - _lastMouseDown.X) > SystemParameters.MinimumHorizontalDragDistance) || (Math.Abs(currentPosition.Y - _lastMouseDown.Y) > SystemParameters.MinimumVerticalDragDistance)) { HitTestResult result = VisualTreeHelper.HitTest(listviewConsumable, currentPosition); if (result == null) return; ListViewItem lvi = Utilities.FindVisualParent(result.VisualHit); if (lvi == null) return; if (listviewConsumable.SelectedItem == null) return; DragDropAdorner adorner = new DragDropAdorner((UIElement)lvi); mAdornerLayer = AdornerLayer.GetAdornerLayer(listviewConsumable); mAdornerLayer.Add(adorner); Labware lb = listviewConsumable.SelectedItem as Labware; LabwareEx labwareEx = new LabwareEx(lb); DataObject data = new DataObject("LabwareEx", labwareEx); DragDrop.DoDragDrop(lvi, data, DragDropEffects.Copy); if (mAdornerLayer == null) mAdornerLayer = AdornerLayer.GetAdornerLayer(listviewConsumable); { mAdornerLayer.Remove(adorner); mAdornerLayer = null; } } } } #endregion #endregion #region TreeView关联事件 #region 鼠标左键点击前事件 private Point _lastMouseDown; /// /// 鼠标左键点击前事件 /// /// /// private void treeviewWorkflow_PreviewMouseDown(object sender, MouseButtonEventArgs e) { if (e.ChangedButton == MouseButton.Left) { //LoggerHelper.DebugLog("========== PreviewMouseDown ==============="); _lastMouseDown = e.GetPosition(treeviewWorkflow); IsIgnore = Math.Abs(treeviewWorkflow.ActualWidth - _lastMouseDown.X) < 10 ? true : false; //treeviewWorkflow.ActualWidth //Point p = Mouse.GetPosition(e.Source as FrameworkElement); //Point pp = (e.Source as FrameworkElement).PointToScreen(p); //Point mousePostion = this.PointToScreen(new Point(this.ActualWidth, this.ActualHeight)); } } #endregion #region 鼠标移动前事件 /// /// 鼠标移动前事件 /// /// /// private void treeviewWorkflow_PreviewMouseMove(object sender, MouseEventArgs e) { if (IsIgnore) { //LoggerHelper.DebugLog("========== PreviewMouseMove LeftButton Skip ==============="); return; } if (e.LeftButton == MouseButtonState.Pressed && !IsIgnore) { //LoggerHelper.DebugLog("========== PreviewMouseMove LeftButton Pressed ==============="); Point currentPosition = e.GetPosition(treeviewWorkflow); //if (sender is TreeView) //{ // int a = 1; //} //if ((Math.Abs(currentPosition.X - _lastMouseDown.X) > SystemParameters.MinimumHorizontalDragDistance) // || (Math.Abs(currentPosition.Y - _lastMouseDown.Y) > SystemParameters.MinimumVerticalDragDistance)) //{ // HitTestResult result = VisualTreeHelper.HitTest(treeviewWorkflow, currentPosition); // if (result == null) // return; // TreeViewItem tvi = Utilities.FindVisualParent(result.VisualHit); // if (tvi == null) // return; // tvi.IsExpanded = true; // if (treeviewWorkflow.SelectedItem == null) // return; // isDragDrop = true; // DragDropAdorner adorner = new DragDropAdorner(tvi); // mAdornerLayer = AdornerLayer.GetAdornerLayer(gridCmdSet); // mAdornerLayer.Add(adorner); // DataObject data = new DataObject("MethodEx", treeviewWorkflow.SelectedItem); // data.SetData("TreeViewItem", tvi); // DragDrop.DoDragDrop(treeviewWorkflow, data, DragDropEffects.Move); // if (mAdornerLayer != null) // { // mAdornerLayer.Remove(adorner); // } // mAdornerLayer = null; // isDragDrop = false; //} if ((Math.Abs(currentPosition.X - _lastMouseDown.X) > SystemParameters.MinimumHorizontalDragDistance) || (Math.Abs(currentPosition.Y - _lastMouseDown.Y) > SystemParameters.MinimumVerticalDragDistance)) { HitTestResult result = VisualTreeHelper.HitTest(treeviewWorkflow, currentPosition); if (result == null) return; TreeViewItem tvi = Utilities.FindVisualParent(result.VisualHit); if (tvi == null) return; tvi.IsExpanded = true; if (treeviewWorkflow.SelectedItem == null) return; isDragDrop = true; List tviList = new List(); treeViewItems.Clear(); List allTreeViewItemList = Utilities.FindAllVisualChild(treeviewWorkflow); for (int i=0;i< allTreeViewItemList.Count;i++) { if (((MethodEx)allTreeViewItemList[i].Header).isSelected == true) { //tviList.Add(allTreeViewItemList[i]); treeViewItems.Add(allTreeViewItemList[i]); if (((MethodEx)allTreeViewItemList[i].Header).method_name=="if开始")//加入else { GetChildernTreeViewItems(allTreeViewItemList[i+1]); } if (treeViewItems.Count > 0) { tviList.AddRange(treeViewItems); treeViewItems.Clear(); } } else { if (tviList.Contains(allTreeViewItemList[i])) { continue; } else { GetChildernTreeViewItems(allTreeViewItemList[i]); } if (treeViewItems.Count > 0) { tviList.AddRange(treeViewItems); treeViewItems.Clear(); } } } DragDropAdorner adorner = new DragDropAdorner(tviList[0], tviList); mAdornerLayer = AdornerLayer.GetAdornerLayer(gridCmdSet); mAdornerLayer.Add(adorner); SelectedItemList.Clear(); //把已经选中的也要加进来 List methodExes = FindMethodExBySelected(rootMethod); SelectedItemList.AddRange(methodExes); DataObject data = new DataObject("MethodEx", SelectedItemList); data.SetData("TreeViewItem", tviList); DragDrop.DoDragDrop(treeviewWorkflow, data, DragDropEffects.Move); if (mAdornerLayer != null) { mAdornerLayer.Remove(adorner); } mAdornerLayer = null; isDragDrop = false; } } } #endregion List treeViewItems = new List();// 拖动时临时存储带拖动的条目数据 #region 递归获取拖动的条目对象 /// /// 递归获取拖动的条目对象 /// /// 要递归的当前条目 private void GetChildernTreeViewItems(TreeViewItem treeViewItem) { if (treeViewItem!=null) { if (((MethodEx)treeViewItem.Header).Children != null) { if (((MethodEx)treeViewItem.Header).isSelected==true)//((MethodEx)treeViewItem.Header).method_name == "if开始"&& { treeViewItems.Add(treeViewItem); } else if (((MethodEx)treeViewItem.Header).method_name == "else开始") { if (IsExistParentIf(treeViewItem)) { treeViewItems.Add(treeViewItem); } else { List subTreeViewItemList = Utilities.FindAllVisualChild(treeViewItem); foreach (TreeViewItem t in subTreeViewItemList) { GetChildernTreeViewItems(t); } } } else { List subTreeViewItemList = Utilities.FindAllVisualChild(treeViewItem); foreach (TreeViewItem t in subTreeViewItemList) { GetChildernTreeViewItems(t); } } } else { if (((MethodEx)treeViewItem.Header).isSelected == true)//((MethodEx)treeViewItem.Header).method_name == "if开始" && { treeViewItems.Add(treeViewItem); } else if (((MethodEx)treeViewItem.Header).method_name == "else开始") { if (IsExistParentIf(treeViewItem)) { treeViewItems.Add(treeViewItem); } else { List subTreeViewItemList = Utilities.FindAllVisualChild(treeViewItem); foreach (TreeViewItem t in subTreeViewItemList) { GetChildernTreeViewItems(t); } } } } } } #endregion #region 判断else对应的if是否已经选中成为拖动数据 /// /// 判断else对应的if是否已经选中成为拖动数据 /// /// else对应的TreeViewItem /// private bool IsExistParentIf(TreeViewItem treeViewItem) { bool result = false; if(treeViewItems!=null&& treeViewItems.Count>0) { string indexName = ((MethodEx)treeViewItem.Header).strIndex; string indexOfIf = string.Empty; if (indexName.Contains("-")) { string heardOfIndex = indexName.Substring(0, indexName.LastIndexOf("-")); string nextOfIndex = indexName.Substring(indexName.LastIndexOf("-") + 1, indexName.Length - indexName.LastIndexOf("-") - 1); indexOfIf = (heardOfIndex + "-" + (Convert.ToInt32(nextOfIndex) - 1)).ToString(); } else { indexOfIf = (Convert.ToInt32(indexName) - 1).ToString(); } foreach (TreeViewItem t in treeViewItems) { if(((MethodEx)t.Header).strIndex==indexOfIf) { result = true; break; } } } return result; } #endregion #region 拖动事件 /// /// 开始拖动前 /// /// /// private void treeviewWorkflow_PreviewDragOver(object sender, DragEventArgs e) { if (IsIgnore) { //LoggerHelper.DebugLog("========== PreviewDragOver Skip ==============="); return; } //LoggerHelper.DebugLog("========== PreviewDragOver ==============="); if (!e.Data.GetDataPresent("MethodEx")) { e.Effects = DragDropEffects.None; } else { List miList = e.Data.GetData("MethodEx") as List; if (miList == null) { MethodEx mi = e.Data.GetData("MethodEx") as MethodEx; if (!mi.Moveable) e.Effects = DragDropEffects.None; else { Point pos = e.GetPosition(treeviewWorkflow); HitTestResult result = VisualTreeHelper.HitTest(treeviewWorkflow, pos); if (result == null) return; TreeViewItem targetItem = Utilities.FindVisualParent(result.VisualHit); if (targetItem == null) return; targetItem.IsSelected = true; MethodEx targetData = targetItem.DataContext as MethodEx; if (!targetData.canDrop) { e.Effects = DragDropEffects.None; } else if (e.Effects == DragDropEffects.Move) { if (mi == targetData) { e.Effects = DragDropEffects.None; } else { bool check = CheckSourceHasTarget(mi, targetData); if (check) e.Effects = DragDropEffects.None; } } } } else { foreach (MethodEx mi in miList) { if (!mi.Moveable) { e.Effects = DragDropEffects.None; } else { Point pos = e.GetPosition(treeviewWorkflow); HitTestResult result = VisualTreeHelper.HitTest(treeviewWorkflow, pos); if (result == null) return; TreeViewItem targetItem = Utilities.FindVisualParent(result.VisualHit); if (targetItem == null) return; targetItem.IsSelected = true; MethodEx targetData = targetItem.DataContext as MethodEx; if (!targetData.canDrop) { e.Effects = DragDropEffects.None; } else if (e.Effects == DragDropEffects.Move) { if (mi == targetData) { e.Effects = DragDropEffects.None; } else { bool check = CheckSourceHasTarget(mi, targetData); if (check) e.Effects = DragDropEffects.None; } } } } } } e.Handled = true; } /// /// 开始拖动 /// /// /// private void treeviewWorkflow_DragOver(object sender, DragEventArgs e) { if (IsIgnore) { //LoggerHelper.DebugLog("========== DragOver Skip ==============="); return; } //LoggerHelper.DebugLog("========== DragOver ==============="); e.Effects = DragDropEffects.None; Point pos = e.GetPosition(treeviewWorkflow); HitTestResult result = VisualTreeHelper.HitTest(treeviewWorkflow, pos); if (result == null) return; TreeViewItem selectedItem = Utilities.FindVisualParent(result.VisualHit); if (selectedItem != null) selectedItem.IsSelected = true; e.Effects = DragDropEffects.Copy; } #endregion #region 拖动放下事件 /// /// 拖动放下(鼠标松开) /// /// /// private void treeviewWorkflow_Drop(object sender, DragEventArgs e) { if (IsIgnore) { //LoggerHelper.DebugLog("========== Drop Skip ==============="); return; } //LoggerHelper.DebugLog("========== Drop ==============="); Point pos = e.GetPosition(treeviewWorkflow); HitTestResult result = VisualTreeHelper.HitTest(treeviewWorkflow, pos); if (result == null) return; TreeViewItem selectedItem = Utilities.FindVisualParent(result.VisualHit); if (selectedItem == null) return; MethodEx targetItem = selectedItem.Header as MethodEx; mainWindow.SetObserverNode(rootMethod);//注册观察者 List dragItemList = e.Data.GetData("MethodEx") as List; bool currentItemIsTimer = false;//判断当前拖入的节点是否是timer if (dragItemList == null) //流程外新拖入 { MethodEx dragItem = e.Data.GetData("MethodEx") as MethodEx; if (targetItem != null && dragItem != null) { //判断下目标条目是否是if结束,目标条目的下一个条目是否是else开始,如果满足条件不能拖入 bool mResult = IsDrogIntoIfendMidElseStart(targetItem); if(mResult) { return; } if (e.Effects == DragDropEffects.Copy) InsertIntoWorkflow(dragItem, targetItem, selectedItem.IsExpanded); else if (e.Effects == DragDropEffects.Move) { MoveWorkflowItem(dragItem, targetItem); } if(dragItem.method_name.Equals("计时器")) { currentItemIsTimer = true; } ReOrderMethodIndex("", rootMethod); //更新下Waitfor 中的Timer //this.UpdateWaitFor(dragItem); } targetItem.isSelected = false; if (curSelectedMethod != null) curSelectedMethod.isSelected = true; } else //流程内重排 { for (int i= 0;i < dragItemList.Count;i++) { //if (dragItem.method_type == 2 && targetItem.method_type == 2 && targetItem.Children.Count > 0) // return; if (targetItem != null && dragItemList[i] != null) { //判断下目标条目是否是if结束,目标条目的下一个条目是否是else开始,如果满足条件不能拖入 bool mResult = IsDrogIntoIfendMidElseStart(targetItem); if (mResult) { return; } if (e.Effects == DragDropEffects.Copy) InsertIntoWorkflow(dragItemList[i], targetItem); else if (e.Effects == DragDropEffects.Move) { MoveWorkflowItem(dragItemList[i], targetItem,i); } if (dragItemList[i].method_name.Equals("计时器")) { currentItemIsTimer = true; } ReOrderMethodIndex("", rootMethod); if (dragItemList[i].method_name.Equals("等待")) { //更新下Waitfor 中的Timer //this.UpdateWaitFor(dragItemList[i]); } } targetItem.isSelected = false; if (curSelectedMethod != null) curSelectedMethod.isSelected = true; } } //更新下Waitfor 中的Timer //当前拖入的节点看是否包含timer,包含就更新,不包含就不更新 if (currentItemIsTimer) { updateWaitforOnWorkflow(); } } #endregion #region 鼠标右键点击事件 ignore /// /// 鼠标右键点击 /// /// /// private void treeviewWorkflow_PreviewMouseRightButtonDown(object sender, MouseButtonEventArgs e) { DependencyObject source = e.OriginalSource as DependencyObject; while (source != null && source.GetType() != typeof(TreeViewItem)) source = System.Windows.Media.VisualTreeHelper.GetParent(source); if (source != null) { TreeViewItem item = source as TreeViewItem; item.IsSelected = true; MethodEx method = item.DataContext as MethodEx; ContextMenu menu = FindResource("workflowMenu") as ContextMenu; // 开始、台面布置、结束 if ((method.method_id == "0") || (method.method_id == "1") || (method.method_id == "2")) { MenuItem menuItem = menu.Items[0] as MenuItem; menuItem.IsEnabled = false; menuItem = menu.Items[2] as MenuItem; menuItem.IsEnabled = false; menuItem = menu.Items[3] as MenuItem; menuItem.IsEnabled = false; // 开始、结束 if ((method.method_id == "0") || (method.method_id == "2")) { menuItem = menu.Items[1] as MenuItem; menuItem.IsEnabled = false; } else if (copyMethod == null) { menuItem = menu.Items[1] as MenuItem; menuItem.IsEnabled = false; } else { menuItem = menu.Items[1] as MenuItem; menuItem.IsEnabled = true; } } else { MenuItem menuItem = menu.Items[0] as MenuItem; menuItem.IsEnabled = true; if (copyMethod == null) { menuItem = menu.Items[1] as MenuItem; menuItem.IsEnabled = false; } else { menuItem = menu.Items[1] as MenuItem; menuItem.IsEnabled = true; } menuItem = menu.Items[3] as MenuItem; menuItem.IsEnabled = true; menuItem = menu.Items[2] as MenuItem; menuItem.IsEnabled = true; if (method.isEnabled) menuItem.Header = Properties.Resources.strDisable; else menuItem.Header = Properties.Resources.strEnable; } int a = 0; IsIgnore = true; } } #endregion #region 查找Tree中已经选中的节点 private List FindMethodExBySelected(MethodEx method) { List methodExes = new List(); if (method.isSelected == true) { if (method.method_name != "开始" || method.method_name != "台面布置" || method.method_name != "结束") { methodExes.Add(method); if (method.method_name == "if开始")//把可能存在的else也加进来 { string indexName = method.strIndex; string indexOfElse = string.Empty; MethodEx methodExElse = null; if (indexName.Contains("-")) { string heardOfIndex = indexName.Substring(0, indexName.LastIndexOf("-")); string nextOfIndex = indexName.Substring(indexName.LastIndexOf("-") + 1, indexName.Length - indexName.LastIndexOf("-") - 1); indexOfElse = (heardOfIndex + "-" + (Convert.ToInt32(nextOfIndex) + 1)).ToString(); methodExElse = SetRunningStatus(indexOfElse); } else { indexOfElse = (Convert.ToInt32(indexName) + 1).ToString(); methodExElse = SetRunningStatus(indexOfElse); } //if (methodExElse != null) //{ // methodExes.Add(methodExElse); //} } } } else { if (method.Children.Count > 0) { foreach (var m in method.Children) { List find = FindMethodExBySelected(m); if (find != null && find.Count != 0) { methodExes.AddRange(find); } } } } return methodExes; } #endregion public static ScrollViewer GetScrollViewer(DependencyObject depObj) { if (depObj is ScrollViewer) return depObj as ScrollViewer; for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++) { var child = VisualTreeHelper.GetChild(depObj, i); var result = GetScrollViewer(child); if (result != null) return result; } return null; } public List SelectedItemList = new List(); private MethodEx curSelectedMethod = null; private void treeviewWorkflow_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs e) { if (isDragDrop) return; MethodEx mEx = e.NewValue as MethodEx; if (mEx == null) return; curSelectedMethod = mEx; #region 记录多选指令 if (Keyboard.IsKeyDown(Key.LeftCtrl)) { SelectedItemList.Clear(); //把已经选中的也要加进来 List methodExes = FindMethodExBySelected(rootMethod); SelectedItemList.AddRange(methodExes); if (SelectedItemList.IndexOf(mEx) < 0) { if (mEx.method_name == "开始" || mEx.method_name == "台面布置" || mEx.method_name == "结束") { return; } SelectedItemList.Add(mEx); //样式标记 //WorkflowIsFlag(mEx); //if (mEx.Children.Count > 0) //{ // foreach (var item in mEx.Children) // { // WorkflowIsFlag(item); // } //} mEx.isSelected = true; } else { SelectedItemList.Remove(mEx); ////取消样式标记 //WorkflowIsFlag(mEx, false); //if (mEx.Children.Count > 0) //{ // foreach (var item in mEx.Children) // { // WorkflowIsFlag(item, false); // } //} mEx.isSelected = false; } if (SelectedItemList.Count > 0) { tbSelectCount.Text = $"已选择 {SelectedItemList.Count} 条指令"; } else { tbSelectCount.Text = ""; } } #endregion //#region 判断如果选中的是一个条件节点的话,要把可能有的关联else也标记为选中 //if(mEx.method_name=="if开始") //{ // string indexName = mEx.strIndex; // string indexOfElse = string.Empty; // if (indexName.Contains("-")) // { // string heardOfIndex=indexName.Substring(0,indexName.LastIndexOf("-")); // string nextOfIndex= indexName.Substring(indexName.LastIndexOf("-")+1, indexName.Length-indexName.LastIndexOf("-")-1); // indexOfElse = (heardOfIndex+"-"+ (Convert.ToInt32(nextOfIndex)+1)).ToString(); // MethodEx methodEx = SetRunningStatus(indexOfElse); // } // else // { // indexOfElse = (Convert.ToInt32(indexName)+1).ToString(); // MethodEx methodEx = SetRunningStatus(indexOfElse); // } //} //#endregion // 加载方法 LoadMethod(mEx); } #region 判断某个节点是否拖放到了if结束和else开始之间 /// /// 判断某个节点是否拖放到了if结束和else开始之间 /// /// 拖放的目标节点对象 /// true:是;false:否 private bool IsDrogIntoIfendMidElseStart(MethodEx method) { bool result = false; if (method.method_name == "if结束") { string indexName = method.Parent.strIndex; string indexOfElse = string.Empty; MethodEx methodExElse = null; if (indexName.Contains("-")) { string heardOfIndex = indexName.Substring(0, indexName.LastIndexOf("-")); string nextOfIndex = indexName.Substring(indexName.LastIndexOf("-") + 1, indexName.Length - indexName.LastIndexOf("-") - 1); indexOfElse = (heardOfIndex + "-" + (Convert.ToInt32(nextOfIndex) + 1)).ToString(); } else { indexOfElse = (Convert.ToInt32(indexName) + 1).ToString(); } MethodEx methodEx = FindMethodExByIndex(rootMethod, indexOfElse); if (methodEx != null) { if (methodEx.method_name == "else开始") { result = true; } } } return result; } #endregion /// /// 设置节点状态为选中 /// /// private MethodEx SetRunningStatus(string indexName) { MethodEx methodEx = FindMethodExByIndex(rootMethod, indexName); if (methodEx != null) { if (methodEx.method_name == "else开始") { methodEx.isSelected = true; //SelectedItemList.Add(methodEx); } } return methodEx; } private MethodEx FindMethodExByIndex(MethodEx method, string indexName) { if (method.strIndex == indexName) return method; else { if (method.Children.Count > 0) { foreach (var m in method.Children) { MethodEx find = FindMethodExByIndex(m, indexName); if (find != null) return find; } } else return null; } return null; } #region 查找指定的一个Waitfor节点之前的所有Timer节点 List methodExesForTimer = new List(); public List FindNodesFilterTimer(string indexName) { methodExesForTimer.Clear(); FindTimerMethodExBeforeWaitFor(rootMethod, indexName); if (methodExesForTimer.Count>0) { return methodExesForTimer; } else { return null; } } private int FindTimerMethodExBeforeWaitFor(MethodEx method, string indexName) { if (method.method_name.Equals("计时器") && method.strIndex != indexName) { methodExesForTimer.Add(method); if (method.Children.Count > 0) { foreach (var m in method.Children) { int ret=FindTimerMethodExBeforeWaitFor(m, indexName); if(ret==0) { return 0; } } return -1; } else { return -1; } } else if (method.strIndex == indexName) { return 0; } else { if (method.Children.Count > 0) { foreach (var m in method.Children) { int ret = FindTimerMethodExBeforeWaitFor(m, indexName); if (ret == 0) { return 0; } } return -1; } return -1; } } /// /// 更新最新流程中的所有等待节点内的Timer /// public void updateWaitforOnWorkflow() { waitForMethod.Clear(); FindMethodExByName(rootMethod, "等待"); if (waitForMethod != null) { foreach(MethodEx x in waitForMethod) { this.UpdateWaitFor(x); } } } List waitForMethod = new List();//所有waifor节点 private void FindMethodExByName(MethodEx method, string Name) { if (method.method_name == Name) { waitForMethod.Add(method); } else { if (method.Children.Count > 0) { foreach (var m in method.Children) { FindMethodExByName(m, Name); } } else { } } } #endregion /// /// 加载方法 /// /// private void LoadMethod(MethodEx mEx,bool isCopy=false) { switch (mEx.method_id) { case "0": Method_Start(mEx); break; case "1": Method_SetTable(); break; case "2": Method_End(mEx); break; case "3": Method_Aspirate(mEx,isCopy); break; case "4": Method_Dispense(mEx); break; case "5": Method_Reset(mEx); break; case "6": Method_File(mEx); break; case "7": Method_GripTransport(mEx); break; case "8": Method_Pause(mEx); break; case "9": Method_Mix(mEx); break; case "10": Method_LoadTips(mEx); break; case "11": Method_UnloadTips(mEx); break; case "12": Method_Loop(mEx); break; case "13": Method_IfElse(mEx); break; case "14": Method_SetVariable(mEx); break; case "15": //振荡 化学 Method_Shake(mEx,isCopy); break; case "17": Method_DataImport(mEx); break; case "18": Method_DataExport(mEx); break; case "19": Method_VariableCalculate(mEx); break; case "20": Method_GripMove(mEx); break; case "23": Method_Group(mEx); break; case "24": Method_Comment(mEx); break; case "25": Method_Capture(mEx); break; case "26": Method_FileCoating(mEx); break; case "27": Method_Pick(mEx); break; case "28": Method_Coating(mEx); break; case "29": Method_CoatingFileExport(mEx); break; case "30": // 超声探测 Method_Ultrasonic(mEx); break; case "31": // 挑选转板 Method_PickAndTransfer(mEx); break; case "32": // 涂布转板 Method_CoatingAndTransfer(mEx); break; case "33": // 梯度稀释 Method_Dilution(mEx); break; case "34": // 夹爪保持开始 Method_HoldingLabware(mEx); break; case "35": //变量导入 Method_VariableImport(mEx); break; case "36": //计时器 Method_Timer(mEx); break; case "37": //等待 { //获取该命令之前的所有timer List methodExesForTimerList= FindNodesFilterTimer(mEx.strIndex); List methodDuringTimerList = new List(); if (methodExesForTimerList!=null) { foreach(MethodEx x in methodExesForTimerList) { DropdownName dropdownName = new DropdownName(); dropdownName.dropdown_id = x.strIndex; dropdownName.dropdown_name = (x.control != null ? (x.control as TimerProperty).methodTimer.name : x.method_name); methodDuringTimerList.Add(dropdownName); } } Method_WaitFor(mEx, methodDuringTimerList); } break; case "38": //加液泵 Method_PumpDispense(mEx); break; case "39": //开关盖 Method_SwitchLid(mEx); break; case "40": //文件开关盖移液 Method_FileMoveLiquid(mEx); break; case "41": //文件转板 Method_FileMoveLabware(mEx); break; case "42": //子方法 Method_SubMethod(mEx); break; case "43": //文件切胶 Method_FileElectro(mEx); break; default: if (mEx.method_group_id == EnumManagement.GetEnumValue(MethodGroupEnum.ThirdPart)) { // 第三方设备 Method_ThirdPart(mEx); } break; } } #endregion private MethodEx CloneData(MethodEx method, MethodEx parent) { MethodEx data = new MethodEx(method, parent); data.tag = parent.tag; data.isEnabled = method.isEnabled; foreach (MethodEx me in method.Children) { MethodEx newData = CloneData(me, data); data.Children.Add(newData); } return data; } private MethodEx CloneDataForPaste(MethodEx method, MethodEx parent) { ////克隆节点属性参数 //if(method.control!=null) //{ // LoadMethod(method,true); //} MethodEx data = new MethodEx(method, parent,true); data.tag = parent.tag; data.isEnabled = method.isEnabled; foreach (MethodEx me in method.Children) { MethodEx newData = CloneDataForPaste(me, data); data.Children.Add(newData); } return data; } public void InsertIntoWorkflow(MethodEx source, MethodEx dest,bool isExpended=true) { //组合指令,需要加2个node(开始和结束) MethodEx sourceItem = new MethodEx(source); MethodEx sourceItemElse= new MethodEx(sourceItem); if (dest.Parent.method_name == "root"&&dest.Children.Count==0)//目标是首层节点 { sourceItem.isEnabled = true; } else { //判断目标是复合命令的结束,则启用状态和目标的父亲的父亲一致; if (dest.method_name == "循环结束" || dest.method_name == "if结束" || dest.method_name == "else结束" || dest.method_name == "组合结束" || dest.method_name == "夹爪保持结束") { sourceItem.isEnabled = dest.Parent.Parent.isEnabled; } //判断目标是符合命令的开始,则启用状态和目标的一致; else if (dest.method_name == "循环开始" || dest.method_name == "if开始" || dest.method_name == "else开始" || dest.method_name == "组合开始" || dest.method_name == "夹爪保持开始") { sourceItem.isEnabled = dest.isEnabled; } //判断目标是非首层节点 else { sourceItem.isEnabled = dest.Parent.isEnabled; } } //if (dest.Parent.method_name == "root"&& (dest.method_name != "循环开始" && dest.method_name != "if开始" && dest.method_name != "else开始" && dest.method_name != "组合开始" && dest.method_name != "夹爪保持开始")) //{ // sourceItem.isEnabled = true;//dest.Parent.isEnabled; //} //else //{ // if (dest.method_name == "循环开始" || dest.method_name == "if开始" || dest.method_name == "else开始" || dest.method_name == "组合开始" || dest.method_name == "夹爪保持开始") // { // sourceItem.isEnabled = dest.isEnabled; // } // else // { // if(dest.Parent.method_name == "循环开始" || dest.Parent.method_name == "if开始" || dest.Parent.method_name == "else开始" || dest.Parent.method_name == "组合开始" || dest.Parent.method_name == "夹爪保持开始") // { // if (dest.method_name == "循环结束" || dest.Parent.method_name == "if结束" || dest.Parent.method_name == "else结束" || dest.Parent.method_name == "组合结束" || dest.Parent.method_name == "夹爪保持结束") // { // sourceItem.isEnabled = dest.Parent.isEnabled; // } // else // { // if (dest.Parent.Parent.method_name == "root") // { // sourceItem.isEnabled = true; // } // else // { // sourceItem.isEnabled = dest.Parent.Parent.isEnabled; // } // } // } // else // { // sourceItem.isEnabled = dest.Parent.isEnabled; // } // } //} if (sourceItem.method_name == "条件判定") { sourceItem.method_ico = "开始If.png"; sourceItem.method_content = "if开始"; sourceItemElse.method_ico = "开始else.png"; sourceItemElse.method_content = "else开始"; sourceItemElse.method_name = "else"; sourceItemElse.Moveable = false; sourceItemElse.isEnabled = sourceItem.isEnabled; } if (dest.method_type == 2) { if (dest.Children.Count > 0 && isExpended) { dest.Children.Insert(0, sourceItem); sourceItem.SetParent(dest); if (sourceItem.method_name == "条件判定")//添加else { dest.Children.Insert(1, sourceItemElse); sourceItemElse.SetParent(dest); } } else if (dest.Children.Count > 0 && !isExpended) { int index = dest.Parent.Children.IndexOf(dest); dest.Parent.Children.Insert(index + 1, sourceItem); sourceItem.SetParent(dest.Parent); if (sourceItem.method_name == "条件判定")//添加else { dest.Parent.Children.Insert(index + 2, sourceItemElse); sourceItemElse.SetParent(dest.Parent); } } else { int index = dest.Parent.Parent.Children.IndexOf(dest.Parent); dest.Parent.Parent.Children.Insert(index + 1, sourceItem); sourceItem.SetParent(dest.Parent.Parent); if (sourceItem.method_name == "条件判定")//添加else { dest.Parent.Parent.Children.Insert(index + 2, sourceItemElse); sourceItemElse.SetParent(dest.Parent.Parent); } } } else { int index = dest.Parent.Children.IndexOf(dest); dest.Parent.Children.Insert(index + 1, sourceItem); sourceItem.SetParent(dest.Parent); if (sourceItem.method_name == "条件判定")//添加else { dest.Parent.Children.Insert(index + 2, sourceItemElse); sourceItemElse.SetParent(dest.Parent); } } if (source.method_type == 2) { string id = Guid.NewGuid().ToString(); sourceItem.method_name += Properties.Resources.strBegin; sourceItem.groupID = id; MethodEx endItem = new MethodEx(source, sourceItem); endItem.groupID = id; if (sourceItem.method_name == "条件判定开始") { endItem.method_name = "if"; } endItem.method_name += Properties.Resources.strEnd; if (sourceItem.method_name == "循环开始") { endItem.method_ico = "循环结束.png"; } else if (sourceItem.method_name == "组合开始") { endItem.method_ico = "组合结束.png"; } else if (sourceItem.method_name == "夹爪保持开始") { endItem.method_ico = "夹爪保持结束.png"; endItem.method_content = "夹爪保持结束"; } else if(sourceItem.method_name=="条件判定开始") { endItem.method_ico = "结束If.png"; endItem.method_content = "if结束"; MethodEx endItemElse = new MethodEx(source, sourceItemElse); sourceItemElse.method_name += Properties.Resources.strBegin; endItemElse.groupID = id; endItemElse.method_name = "else"; endItemElse.method_name += Properties.Resources.strEnd; endItemElse.method_ico = "结束else.png"; endItemElse.method_content = "else结束"; endItemElse.Moveable = false; endItemElse.isEnabled = sourceItemElse.isEnabled; sourceItemElse.Children.Add(endItemElse); sourceItem.method_name = "if开始"; } endItem.Moveable = false; endItem.isEnabled = sourceItem.isEnabled; sourceItem.Children.Add(endItem); } } private void MoveWorkflowItem(MethodEx source, MethodEx dest,int indexOfTarget=0) { if (source.Parent == dest.Parent) { //同一节点之间的拖放 int indexDest = source.Parent.Children.IndexOf(dest); int indexSource = source.Parent.Children.IndexOf(source); source.Parent.Children.Remove(source); //EnableNode(source, dest.isEnabled); if (dest.method_type == 2) { if (dest.Children.Count > 0) { dest.Children.Insert(0+ indexOfTarget, source); source.SetParent(dest); } else { indexDest = dest.Parent.Parent.Children.IndexOf(dest.Parent); dest.Parent.Parent.Children.Insert(indexDest+ indexOfTarget + 1, source); source.SetParent(dest.Parent.Parent); } } else { if (indexSource > indexDest) dest.Parent.Children.Insert(indexDest+ indexOfTarget + 1, source); else dest.Parent.Children.Insert(indexDest+ indexOfTarget, source); } } else { { int indexSource = source.Parent.Children.IndexOf(source); int indexDest = dest.Parent.Children.IndexOf(dest); source.Parent.Children.Remove(source); if (!dest.isEnabled) EnableNode(source, dest.isEnabled); if (dest.method_type == 2) { if (dest.Children.Count > 0) { dest.Children.Insert(0+ indexOfTarget, source); source.SetParent(dest); } else { indexDest = dest.Parent.Parent.Children.IndexOf(dest.Parent); dest.Parent.Parent.Children.Insert(indexDest+ indexOfTarget + 1, source); source.SetParent(dest.Parent.Parent); } } else { dest.Parent.Children.Insert(indexDest+ indexOfTarget + 1, source); source.SetParent(dest.Parent); } } } source.isSelected = true; } //private void ReOrderMethodIndex(string index, ObservableCollection children) //{ // int subIndex = 1; // foreach (var item in children) // { // item.Index = subIndex; // if (item.Level == 0) // item.strIndex = subIndex.ToString(); // else // item.strIndex = index + "-" + subIndex; // ReOrderMethodIndex(item.strIndex, item.Children); // subIndex++; // } //} public void ReOrderMethodIndex(string index, MethodEx method) { int subIndex = 1; foreach (var item in method.Children) { item.Index = subIndex; item.Level = method.Level + 1; if (item.Level == 0) item.strIndex = subIndex.ToString(); else item.strIndex = index + "-" + subIndex; ReOrderMethodIndex(item.strIndex, item); subIndex++; } } public void ReOrderMethodData(MethodEx method) { foreach (var item in method.Children) { ResetUIData((MethodEx)item); ReOrderMethodData(item); } } /// /// 判断target是否是source的子节点 /// /// /// /// private bool CheckSourceHasTarget(MethodEx source, MethodEx target) { bool ret = false; if (source.method_type != 2) return ret; if (target.Level > source.Level) { if (source == target.Parent) { return true; } else ret = CheckSourceHasTarget(source, target.Parent); } //for(int i= target.Level; i(items); if (scroll != null) { scroll.ScrollToVerticalOffset(scroll.VerticalOffset - e.Delta); } } catch (Exception ex) { LoggerHelper.ErrorLog("ERROR:", ex); } } #region 重置台面 private void btnResetTable_Click(object sender, RoutedEventArgs e) { foreach (Canvas canvas in gridTable.Children) { if (canvas == null) { continue; } if (canvas.Name.Equals(ConfigurationManager.AppSettings["choiceLatticeId"].ToString())) { continue; } if (canvas.DataContext != null) { LabwareEx labware = canvas.DataContext as LabwareEx; if (!string.IsNullOrEmpty(labware.labware_id)) { if (Shared.SoftwareInformation.software_device_number.Equals(DeviceCategory.DeviceHXELEC)) { if (canvas.Name.Equals("P1")) { continue; } } var item = canvas.Children[0]; canvas.Children.Clear(); canvas.Children.Add(item); canvas.Tag = null; } } } } #endregion private void ResetUIData(MethodEx mEx) { if (mEx == null) return; if (mEx.method_id != "1") { mEx.isSelected = true; } // 加载方法 LoadMethod(mEx); #region Del //switch (method.method_id) //{ // case "0": // Method_Start(method); // break; // case "1": // //Method_SetTable(); // break; // case "2": // Method_End(method); // break; // case "3": // Method_Aspirate(method); // break; // case "4": // Method_Dispense(method); // break; // case "5": // Method_Reset(method); // break; // case "6": // Method_File(method); // break; // case "7": // Method_GripTransport(method); // break; // case "8": // Method_Pause(method); // break; // case "9": // Method_Mix(method); // break; // case "10": // Method_LoadTips(method); // break; // case "11": // Method_UnloadTips(method); // break; // case "12": // Method_Loop(method); // break; // case "13": // Method_IfElse(); // break; // case "14": // Method_SetVariable(); // break; // case "17": // Method_DataImport(method); // break; // case "18": // Method_DataExport(method); // break; // case "19": // Method_VariableCaculation(); // break; // case "20": // Method_GripMove(method); // break; // case "23": // Method_Group(method); // break; // case "24": // Method_Comment(method); // break; // case "25": // Method_Capture(method); // break; // case "26": // Method_FileCoating(method); // break; // case "27": // Method_Pick(method); // break; // case "28": // Method_Coating(method); // break; // case "29": // Method_CoatingFileExport(method); // break; // case "31": // 挑选转板 // Method_PickAndTransfer(method); // break; // case "32": // 涂布转板 // Method_CoatingAndTransfer(method); // break; // default: // break; //} #endregion } private void HideConsumable() { borderConsumable.Visibility = Visibility.Collapsed; borderProperty.Visibility = Visibility.Visible; gridRowDef.Height = new GridLength(1, GridUnitType.Star); gridRowConsumable.Height = GridLength.Auto; //gridTable.Width = 350; wdy TabletopTemplate tabletopTemplate = TabletopTemplateDB.GetCurrentAppTabletopTemplateCollectionFromdb(); if (tabletopTemplate == null) { foreach (Canvas canvas in gridTable.Children) { canvas.Margin = new Thickness(3, 8, 3, 4); } imgdish.Margin = new Thickness(0, 10, 140, 0); } else { } } private void ShowConsumable() { try { borderConsumable.Visibility = Visibility.Visible; //borderTable.Margin = new Thickness(30, 5, 30, 110); borderProperty.Visibility = Visibility.Collapsed; gridRowDef.Height = GridLength.Auto; gridRowConsumable.Height = new GridLength(1, GridUnitType.Star); //gridTable.Width = borderTable.ActualWidth - 40; wdy //gridTable.Margin = new Thickness(20, 10, 20, 10); TabletopTemplate tabletopTemplate = TabletopTemplateDB.GetCurrentAppTabletopTemplateCollectionFromdb(); if (tabletopTemplate == null) { foreach (Canvas canvas in gridTable.Children) { canvas.Margin = new Thickness(6, 6, 6, 6); } imgdish.Margin = new Thickness(0, 10, 20, 0); } else { } //imgdish1.Margin = new Thickness(0, 10, 20, 0); } catch (Exception) { } } #region 开始 private void Method_Start(MethodEx method) { HideConsumable(); gridProperty.Children.Clear(); if (method.control == null) { StartProperty property = new StartProperty(method); if (mainWindow != null && !mainWindow.isOpenning) { gridProperty.Children.Add(property); } method.control = property; } else { if (method.control is StartProperty) { StartProperty property = method.control as StartProperty; gridProperty.Children.Add(property); } } } #endregion #region 台面布置 private void Method_SetTable() { ShowConsumable(); } #endregion #region 结束 public void Method_End(MethodEx method) { HideConsumable(); gridProperty.Children.Clear(); if (method.control == null) { EndProperty property = new EndProperty(method); if (mainWindow != null && !mainWindow.isOpenning) { gridProperty.Children.Add(property); } method.control = property; } else { if (method.control is EndProperty) { EndProperty property = method.control as EndProperty; gridProperty.Children.Add(property); } } } #endregion #region 安装枪头 public void Method_LoadTips(MethodEx method) { HideConsumable(); gridProperty.Children.Clear(); if (method.control == null) { LoadTipsProperty property = new LoadTipsProperty(method); //if (property.methodLoadTips != null) //{ // property.methodLoadTips.channels = property.tipsChannel.SelectedChannels.ToArray(); //} if (mainWindow != null && !mainWindow.isOpenning) { gridProperty.Children.Add(property); } method.control = property; } else { //原始创建 if (method.control is LoadTipsProperty) { LoadTipsProperty property = method.control as LoadTipsProperty; //property.methodLoadTips.channels = property.tipsChannel.SelectedChannels.ToArray(); if ((MethodLoadTips)method.tag != null) { property.methodLoadTips = (MethodLoadTips)method.tag; } gridProperty.Children.Add(property); } //打开创建 } } #endregion #region 卸载枪头 public void Method_UnloadTips(MethodEx method) { HideConsumable(); gridProperty.Children.Clear(); if (method.control == null) { UnLoadTipsProperty property = new UnLoadTipsProperty(method); if (mainWindow != null && !mainWindow.isOpenning) { gridProperty.Children.Add(property); } method.control = property; } else { if (method.control is UnLoadTipsProperty) { UnLoadTipsProperty property = method.control as UnLoadTipsProperty; //property.methodUnLoadTips.channels = property.tipsChannel.SelectedChannels.ToArray(); gridProperty.Children.Add(property); property.UserControl_Loaded("", new RoutedEventArgs()); } } } #endregion #region 备注 public void Method_Comment(MethodEx method) { HideConsumable(); gridProperty.Children.Clear(); if (method.control == null) { CommentProperty property = new CommentProperty(method); if (mainWindow != null && !mainWindow.isOpenning) { gridProperty.Children.Add(property); } method.control = property; } else { if (method.control is CommentProperty) { CommentProperty property = method.control as CommentProperty; if ((MethodRemark)method.tag != null) { property.methodRemark = (MethodRemark)method.tag; } gridProperty.Children.Add(property); } } } #endregion #region 变量计算 private void Method_VariableCaculation() { HideConsumable(); gridProperty.Children.Clear(); VariableCaculationProperty property = new VariableCaculationProperty(); gridProperty.Children.Add(property); } #endregion #region 设置变量 public void Method_SetVariable(MethodEx method) { HideConsumable(); gridProperty.Children.Clear(); if (method.control == null) { SetVariableProperty property = new SetVariableProperty(method); if (mainWindow != null && !mainWindow.isOpenning) { gridProperty.Children.Add(property); } method.control = property; } else { if (method.control is SetVariableProperty) { SetVariableProperty property = method.control as SetVariableProperty; if ((MethodSetVariable)method.tag != null) { property.methodSetVariable = (MethodSetVariable)method.tag; } gridProperty.Children.Add(property); } } } #endregion #region 变量计算 public void Method_VariableCalculate(MethodEx method) { HideConsumable(); gridProperty.Children.Clear(); if (method.control == null) { VariableCaculationProperty property = new VariableCaculationProperty(method); if (mainWindow != null && !mainWindow.isOpenning) { gridProperty.Children.Add(property); } method.control = property; } else { if (method.control is VariableCaculationProperty) { VariableCaculationProperty property = method.control as VariableCaculationProperty; if ((MethodVarCalc)method.tag != null) { property.methodVarCalc = (MethodVarCalc)method.tag; } gridProperty.Children.Add(property); } } } #endregion #region 文件导入变量 public void Method_VariableImport(MethodEx method) { HideConsumable(); gridProperty.Children.Clear(); if (method.control == null) { VariableImportProperty property = new VariableImportProperty(method); if (mainWindow != null && !mainWindow.isOpenning) { gridProperty.Children.Add(property); } method.control = property; } else { if (method.control is VariableImportProperty) { VariableImportProperty property = method.control as VariableImportProperty; if ((MethodVariableImport)method.tag != null) { property.methodVariableImport = (MethodVariableImport)method.tag; } gridProperty.Children.Add(property); } } } #endregion #region 条件判定 public void Method_IfElse(MethodEx method) { HideConsumable(); gridProperty.Children.Clear(); if (method.control == null) { if (method.method_name == "if结束") { return; } else if (method.method_name == "else结束") { return; } IfElseProperty property = new IfElseProperty(method); if (mainWindow != null && !mainWindow.isOpenning) { gridProperty.Children.Add(property); } method.control = property; } else { if (method.control is IfElseProperty) { IfElseProperty property = method.control as IfElseProperty; if ((MethodIfElse)method.tag != null) { property.methodIfElse = (MethodIfElse)method.tag; } gridProperty.Children.Add(property); } } } #endregion #region 循环 public void Method_Loop(MethodEx method) { HideConsumable(); gridProperty.Children.Clear(); if (method.control == null) { if (method.method_name == "循环结束") { return; } else if (method.method_name == "组合结束") { return; } LoopProperty property = new LoopProperty(method); if (mainWindow != null && !mainWindow.isOpenning) { gridProperty.Children.Add(property); } method.control = property; } else { if (method.control is LoopProperty) { LoopProperty property = method.control as LoopProperty; gridProperty.Children.Add(property); } } } #endregion #region 暂停 public void Method_Pause(MethodEx method) { HideConsumable(); gridProperty.Children.Clear(); if (method.control == null) { PauseProperty property = new PauseProperty(method); if (mainWindow != null && !mainWindow.isOpenning) { gridProperty.Children.Add(property); } method.control = property; } else { if (method.control is PauseProperty) { PauseProperty property = method.control as PauseProperty; if ((MethodPauseMove)method.tag != null) { property.methodPauseMove = (MethodPauseMove)method.tag; } gridProperty.Children.Add(property); } } } #endregion #region 计时器 public void Method_Timer(MethodEx method) { HideConsumable(); gridProperty.Children.Clear(); if (method.control == null) { TimerProperty property = new TimerProperty(method); if (mainWindow != null && !mainWindow.isOpenning) { gridProperty.Children.Add(property); } method.control = property; } else { if (method.control is TimerProperty) { TimerProperty property = method.control as TimerProperty; if ((MethodTimer)method.tag != null) { property.methodTimer = (MethodTimer)method.tag; } gridProperty.Children.Add(property); } } } #endregion #region 加液泵 public void Method_PumpDispense(MethodEx method) { HideConsumable(); gridProperty.Children.Clear(); if (method.control == null) { PumpDispenseProperty property = new PumpDispenseProperty(method); if (mainWindow != null && !mainWindow.isOpenning) { gridProperty.Children.Add(property); } method.control = property; } else { if (method.control is PumpDispenseProperty) { PumpDispenseProperty property = method.control as PumpDispenseProperty; if ((MethodPumpDispese)method.tag != null) { property.methodPumpDispese = (MethodPumpDispese)method.tag; } gridProperty.Children.Add(property); } } } #endregion #region 振荡 化学 public void Method_Shake(MethodEx method,bool isCopy=false) { HideConsumable(); gridProperty.Children.Clear(); if (method.control == null) { ShakeProperty property = new ShakeProperty(method); if (mainWindow != null && !mainWindow.isOpenning) { gridProperty.Children.Add(property); } method.control = property; } else { //if (!isCopy) //{ if (method.control is ShakeProperty) { ShakeProperty property = method.control as ShakeProperty; if ((MethodShake)method.tag != null) { property.methodShake = (MethodShake)method.tag; } gridProperty.Children.Add(property); } //} //else //{ // ShakeProperty property = new ShakeProperty(method); // if (mainWindow != null && !mainWindow.isOpenning) // { // gridProperty.Children.Add(property); // } // method.control = property; //} } } #endregion #region 开关盖 public void Method_SwitchLid(MethodEx method) { HideConsumable(); gridProperty.Children.Clear(); if (method.control == null) { SwitchLidProperty property = new SwitchLidProperty(method); if (mainWindow != null && !mainWindow.isOpenning) { gridProperty.Children.Add(property); } method.control = property; } else { if (method.control is SwitchLidProperty) { SwitchLidProperty property = method.control as SwitchLidProperty; if ((MethodSwitchLid)method.tag != null) { property.methodSwitchLid = (MethodSwitchLid)method.tag; } gridProperty.Children.Add(property); } } } #endregion #region 文件开关盖移液 public void Method_FileMoveLiquid(MethodEx method) { HideConsumable(); gridProperty.Children.Clear(); if (method.control == null) { FileMoveLiquidProperty property = new FileMoveLiquidProperty(method); if (mainWindow != null&&!mainWindow.isOpenning) { gridProperty.Children.Add(property); } method.control = property; } else { if (method.control is FileMoveLiquidProperty) { FileMoveLiquidProperty property = method.control as FileMoveLiquidProperty; if ((MethodFileMoveLiquid)method.tag != null) { property.methodFileMoveLiquid = (MethodFileMoveLiquid)method.tag; } gridProperty.Children.Add(property); } } } #endregion #region 文件转板 public void Method_FileMoveLabware(MethodEx method) { HideConsumable(); gridProperty.Children.Clear(); if (method.control == null) { FileMoveLabwareProperty property = new FileMoveLabwareProperty(method); if (mainWindow != null && !mainWindow.isOpenning) { gridProperty.Children.Add(property); } method.control = property; } else { if (method.control is FileMoveLabwareProperty) { FileMoveLabwareProperty property = method.control as FileMoveLabwareProperty; if ((MethodFileMoveLabware)method.tag != null) { property.methodFileMoveLabware = (MethodFileMoveLabware)method.tag; } gridProperty.Children.Add(property); } } } #endregion #region 等待 public void Method_WaitFor(MethodEx method,List duringTimerList) { HideConsumable(); gridProperty.Children.Clear(); if (method.control == null) { WaitforProperty property = new WaitforProperty(method, duringTimerList); if (mainWindow != null && !mainWindow.isOpenning) { gridProperty.Children.Add(property); } method.control = property; mainWindow.SetObserverNode(method);//注册观察者 } else { if (method.control is WaitforProperty) { WaitforProperty property = method.control as WaitforProperty; if ((MethodWaitFor)method.tag != null) { property.methodWaitFor = (MethodWaitFor)method.tag; } gridProperty.Children.Add(property); } } } #endregion #region 混合 public void Method_Mix(MethodEx method) { HideConsumable(); gridProperty.Children.Clear(); if (method.control == null) { MixProperty property = new MixProperty(method); if (mainWindow != null && !mainWindow.isOpenning) { gridProperty.Children.Add(property); } method.control = property; } else { if (method.control is MixProperty) { MixProperty property = method.control as MixProperty; if ((MethodMixing)method.tag != null) { property.methodMix = (MethodMixing)method.tag; } gridProperty.Children.Add(property); property.UserControl_Loaded("", new RoutedEventArgs()); } } } #endregion #region 文件 public void Method_File(MethodEx method) { HideConsumable(); gridProperty.Children.Clear(); if (method.control == null) { FileProperty property = new FileProperty(method); if (mainWindow != null && !mainWindow.isOpenning) { gridProperty.Children.Add(property); } method.control = property; } else { if (method.control is FileProperty) { FileProperty property = method.control as FileProperty; if ((MethodTransferFile)method.tag != null) { property.methodTransferFile = (MethodTransferFile)method.tag; } gridProperty.Children.Add(property); } } } #endregion #region 复位 public void Method_Reset(MethodEx method) { HideConsumable(); gridProperty.Children.Clear(); if (method.control == null) { ResetProperty property = new ResetProperty(method); if (mainWindow != null && !mainWindow.isOpenning) { gridProperty.Children.Add(property); } method.control = property; } else { if (method.control is ResetProperty) { ResetProperty property = method.control as ResetProperty; if ((MethodHome)method.tag != null) { property.methodHome = (MethodHome)method.tag; } gridProperty.Children.Add(property); } } } #endregion #region 组合 public void Method_Group(MethodEx method) { HideConsumable(); gridProperty.Children.Clear(); if (method.control == null) { if (method.method_name == "循环结束") { return; } else if (method.method_name == "组合结束") { return; } GroupProperty property = new GroupProperty(method); if (mainWindow != null && !mainWindow.isOpenning) { gridProperty.Children.Add(property); } method.control = property; } else { if (method.control is GroupProperty) { GroupProperty property = method.control as GroupProperty; gridProperty.Children.Add(property); } } } #endregion #region 吸液 public void Method_Aspirate(MethodEx method,bool isCopy=false) { HideConsumable(); gridProperty.Children.Clear(); if (method.control == null) { AspirateProperty property = new AspirateProperty(method); if (mainWindow != null && !mainWindow.isOpenning) { gridProperty.Children.Add(property); } method.control = property; } else { if (method.control is AspirateProperty) { AspirateProperty property = method.control as AspirateProperty; if ((MethodAspirate)method.tag != null) { property.methodAspirate = (MethodAspirate)method.tag; } gridProperty.Children.Add(property); property.UserControl_Loaded("", new RoutedEventArgs()); if(isCopy) { method.control = property; } } } } #endregion #region 放液 public void Method_Dispense(MethodEx method) { HideConsumable(); gridProperty.Children.Clear(); if (method.control == null) { DispenseProperty property = new DispenseProperty(method); if (mainWindow != null && !mainWindow.isOpenning) { gridProperty.Children.Add(property); } method.control = property; } else { if (method.control is DispenseProperty) { DispenseProperty property = method.control as DispenseProperty; if ((MethodDispense)method.tag != null) { property.methodDispense = (MethodDispense)method.tag; } gridProperty.Children.Add(property); property.UserControl_Loaded("", new RoutedEventArgs()); } } } #endregion #region 抓板转移 public void Method_GripTransport(MethodEx method) { HideConsumable(); gridProperty.Children.Clear(); if (method.control == null) { GripTransportProperty property = new GripTransportProperty(method); if (mainWindow != null && !mainWindow.isOpenning) { gridProperty.Children.Add(property); } method.control = property; } else { if (method.control is GripTransportProperty) { GripTransportProperty property = method.control as GripTransportProperty; if ((MethodGripTransport)method.tag != null) { property.methodGripTransport = (MethodGripTransport)method.tag; } gridProperty.Children.Add(property); } } } #endregion #region 移动夹爪 public void Method_GripMove(MethodEx method) { HideConsumable(); gridProperty.Children.Clear(); if (method.control == null) { GripMoveProperty property = new GripMoveProperty(method); if (mainWindow != null && !mainWindow.isOpenning) { gridProperty.Children.Add(property); } method.control = property; } else { if (method.control is GripMoveProperty) { GripMoveProperty property = method.control as GripMoveProperty; if ((MethodGripMove)method.tag != null) { property.methodGripMove = (MethodGripMove)method.tag; } gridProperty.Children.Add(property); } } } #endregion #region 抓板保持开始\抓板保持结束 public void Method_HoldingLabware(MethodEx method) { HideConsumable(); gridProperty.Children.Clear(); if (method.control == null) { if (method.method_name == "夹爪保持" || method.method_name == "夹爪保持开始") { BeginHoldingLabwareProperty property = new BeginHoldingLabwareProperty(method); if (mainWindow != null && !mainWindow.isOpenning) { gridProperty.Children.Add(property); } method.control = property; } else if (method.method_name == "夹爪保持结束") { EndHoldingLabwareProperty property = new EndHoldingLabwareProperty(method); if (mainWindow != null && !mainWindow.isOpenning) { gridProperty.Children.Add(property); } method.control = property; } } else { if (method.control is BeginHoldingLabwareProperty) { BeginHoldingLabwareProperty property = method.control as BeginHoldingLabwareProperty; gridProperty.Children.Add(property); } else if (method.control is EndHoldingLabwareProperty) { EndHoldingLabwareProperty property = method.control as EndHoldingLabwareProperty; gridProperty.Children.Add(property); } } } #endregion #region 数据导入 public void Method_DataImport(MethodEx method) { HideConsumable(); gridProperty.Children.Clear(); if (method.control == null) { DataImportProperty property = new DataImportProperty(method); if (mainWindow != null && !mainWindow.isOpenning) { gridProperty.Children.Add(property); } method.control = property; } else { if (method.control is DataImportProperty) { DataImportProperty property = method.control as DataImportProperty; if ((MethodDataImport)method.tag != null) { property.methodDataImport = (MethodDataImport)method.tag; } gridProperty.Children.Add(property); } } } #endregion #region 数据导出 public void Method_DataExport(MethodEx method) { HideConsumable(); gridProperty.Children.Clear(); if (method.control == null) { DataExportProperty property = new DataExportProperty(method); if (mainWindow != null && !mainWindow.isOpenning) { gridProperty.Children.Add(property); } method.control = property; } else { if (method.control is DataExportProperty) { DataExportProperty property = method.control as DataExportProperty; if ((MethodDataExport)method.tag != null) { property.methodDataExport = (MethodDataExport)method.tag; } gridProperty.Children.Add(property); } } } #endregion #region 拍照 public void Method_Capture(MethodEx method) { HideConsumable(); gridProperty.Children.Clear(); if (Shared.SoftwareInformation.software_device_number.Equals(DeviceCategory.DeviceHXELEC)) { if (method.control == null) { CaptureElectroProperty property = new CaptureElectroProperty(method); if (mainWindow != null && !mainWindow.isOpenning) { gridProperty.Children.Add(property); } method.control = property; } else { if (method.control is CaptureElectroProperty) { CaptureElectroProperty property = method.control as CaptureElectroProperty; if ((MethodTakePhotoForElectro)method.tag != null) { property.methodTakePhotoForElectro = (MethodTakePhotoForElectro)method.tag; } gridProperty.Children.Add(property); } } } else { if (method.control == null) { CaptureProperty property = new CaptureProperty(method); if (mainWindow != null && !mainWindow.isOpenning) { gridProperty.Children.Add(property); } method.control = property; } else { if (method.control is CaptureProperty) { CaptureProperty property = method.control as CaptureProperty; if ((MethodTakePhoto)method.tag != null) { property.methodTakePhoto = (MethodTakePhoto)method.tag; } gridProperty.Children.Add(property); } } } } #endregion #region 文件涂布 public void Method_FileCoating(MethodEx method) { HideConsumable(); gridProperty.Children.Clear(); if (method.control == null) { FileCoatingProperty property = new FileCoatingProperty(method); if (mainWindow != null && !mainWindow.isOpenning) { gridProperty.Children.Add(property); } method.control = property; } else { if (method.control is FileCoatingProperty) { FileCoatingProperty property = method.control as FileCoatingProperty; if ((MethodCoatingFile)method.tag != null) { property.methodCoatingFile = (MethodCoatingFile)method.tag; } gridProperty.Children.Add(property); } } } #endregion #region 挑菌 public void Method_Pick(MethodEx method) { HideConsumable(); gridProperty.Children.Clear(); if (method.control == null) { PickProperty property = new PickProperty(method); if (mainWindow != null && !mainWindow.isOpenning) { gridProperty.Children.Add(property); } method.control = property; } else { if (method.control is PickProperty) { PickProperty property = method.control as PickProperty; if ((MethodChoice)method.tag != null) { property.methodChoice = (MethodChoice)method.tag; } gridProperty.Children.Add(property); } } } #endregion #region 涂布 public void Method_Coating(MethodEx method) { HideConsumable(); gridProperty.Children.Clear(); if (method.control == null) { CoatingProperty property = new CoatingProperty(method); if (mainWindow != null && !mainWindow.isOpenning) { gridProperty.Children.Add(property); } method.control = property; } else { if (method.control is CoatingProperty) { CoatingProperty property = method.control as CoatingProperty; if ((MethodCoating)method.tag != null) { property.methodCoating = (MethodCoating)method.tag; } gridProperty.Children.Add(property); } } } #endregion #region 文件涂布 public void Method_CoatingFileExport(MethodEx method) { HideConsumable(); gridProperty.Children.Clear(); if (method.control == null) { CoatingFileExportProperty property = new CoatingFileExportProperty(method); if (mainWindow != null && !mainWindow.isOpenning) { gridProperty.Children.Add(property); } method.control = property; } else { if (method.control is CoatingFileExportProperty) { CoatingFileExportProperty property = method.control as CoatingFileExportProperty; if ((MethodCoatingReport)method.tag != null) { property.methodCoatingReport = (MethodCoatingReport)method.tag; } gridProperty.Children.Add(property); } } } #endregion #region 超声探测 public void Method_Ultrasonic(MethodEx method) { HideConsumable(); gridProperty.Children.Clear(); if (method.control == null) { UltrasonicProperty property = new UltrasonicProperty(method); if (mainWindow != null && !mainWindow.isOpenning) { gridProperty.Children.Add(property); } method.control = property; } else { if (method.control is UltrasonicProperty) { UltrasonicProperty property = method.control as UltrasonicProperty; if ((MethodUltrasonic)method.tag != null) { property.methodUltrasonic = (MethodUltrasonic)method.tag; } gridProperty.Children.Add(property); } } } #endregion #region 涂布+转板 public void Method_CoatingAndTransfer(MethodEx method) { HideConsumable(); gridProperty.Children.Clear(); if (method.control == null) { CoatingAndTransferProperty property = new CoatingAndTransferProperty(method); if (mainWindow != null && !mainWindow.isOpenning) { gridProperty.Children.Add(property); } method.control = property; } else { if (method.control is CoatingAndTransferProperty) { CoatingAndTransferProperty property = method.control as CoatingAndTransferProperty; if ((MethodCoatingAndTransfer)method.tag != null) { property.methodCoating = (MethodCoatingAndTransfer)method.tag; } gridProperty.Children.Add(property); } } } #endregion #region 挑菌+转板 public void Method_PickAndTransfer(MethodEx method) { HideConsumable(); gridProperty.Children.Clear(); if (method.control == null) { PickAndTransferProperty property = new PickAndTransferProperty(method); if (mainWindow != null && !mainWindow.isOpenning) { gridProperty.Children.Add(property); } method.control = property; } else { if (method.control is PickAndTransferProperty) { PickAndTransferProperty property = method.control as PickAndTransferProperty; if ((MethodChoiceAndTransfer)method.tag != null) { property.methodChoice = (MethodChoiceAndTransfer)method.tag; } gridProperty.Children.Add(property); } } } #endregion #region 第三方设备 public void Method_ThirdPart(MethodEx mEx) { HideConsumable(); mEx.device = DeviceConfigDB.GetInfodById(mEx.method_id.ToString()); if (mEx.device == null) { new MessageDialog(string.Format("【{0}】设备不存在!", mEx.method_name)).ShowDialog(); return; } gridProperty.Children.Clear(); if (mEx.control == null) { UserControl property = null; // Socket-TCP标准协议 if (mEx.device.CommunicateType == EnumManagement.GetEnumValue(CommunicateTypeEnum.Socket)) { property = new ThirdPartPropertySocketProperty(mEx); } if (mainWindow != null && !mainWindow.isOpenning) { gridProperty.Children.Add(property); } mEx.control = property; } else { if (mEx.control is ThirdPartPropertySocketProperty) { ThirdPartPropertySocketProperty property = mEx.control as ThirdPartPropertySocketProperty; if ((MethodThirdPart)mEx.tag != null) { property.methodProperty = (MethodThirdPart)mEx.tag; } gridProperty.Children.Add(property); } } } #endregion #region 梯度稀释 public void Method_Dilution(MethodEx method) { HideConsumable(); gridProperty.Children.Clear(); if (method.control == null) { DilutionProperty property = new DilutionProperty(method); if (mainWindow != null && !mainWindow.isOpenning) { gridProperty.Children.Add(property); } method.control = property; } else { if (method.control is DilutionProperty) { DilutionProperty property = method.control as DilutionProperty; if ((MethodDilution)method.tag != null) { property.methodDilution = (MethodDilution)method.tag; } gridProperty.Children.Add(property); } } } #endregion #region 子方法 public void Method_SubMethod(MethodEx method) { HideConsumable(); if (gridProperty != null) { gridProperty.Children.Clear(); } if (method.control == null) { SubMethodProperty property = new SubMethodProperty(method); if (gridProperty != null) { if (mainWindow != null && !mainWindow.isOpenning) { gridProperty.Children.Add(property); } } method.control = property; } else { if (method.control is SubMethodProperty) { SubMethodProperty property = method.control as SubMethodProperty; if (method.tag != null) { property.MethodSubMethod = (MethodSubMethod)method.tag; } if (gridProperty != null) { gridProperty.Children.Add(property); } } } } #endregion #region 文件切胶 public void Method_FileElectro(MethodEx method) { HideConsumable(); gridProperty.Children.Clear(); if (method.control == null) { FileElectroProperty property = new FileElectroProperty(method); if (mainWindow != null && !mainWindow.isOpenning) { gridProperty.Children.Add(property); } method.control = property; } else { if (method.control is FileElectroProperty) { FileElectroProperty property = method.control as FileElectroProperty; if ((MethodElectroFile)method.tag != null) { property.methodElectroFile = (MethodElectroFile)method.tag; } gridProperty.Children.Add(property); } } } #endregion /// /// 设置桌面Labware的选中属性,并清除其他Labware的选中属性 /// /// private void SetLabwareSelection(ControlLabware selectedControl) { foreach (Canvas grid in gridTable.Children) { ControlLabware control = (ControlLabware)Utilities.FindVisualChild(grid); if (control == null) continue; if (control == selectedControl) control.IsSelected = true; else control.IsSelected = false; } } private void SetTableName(string tableName, Labware lb) { if (treeviewWorkflow.SelectedItem != null) { MethodEx mi = treeviewWorkflow.SelectedItem as MethodEx; if (mi.control is IMethodProperty) { IMethodProperty property = (IMethodProperty)mi.control; property.SetTableName(tableName, lb); } } } #region 删除耗材 private void tableMenuDeleteLabware_Click(object sender, RoutedEventArgs e) { MenuItem mi = e.Source as MenuItem; ContextMenu menu = mi.Parent as ContextMenu; Canvas canvas = menu.PlacementTarget as Canvas; ControlLabware labware = Utilities.FindLastVisualChild(canvas); if (labware == null || labware.IsTrash) return; if (labware != null) { labwareExes = (Stack)canvas.Tag; LabwareEx labwareExPop = new LabwareEx(); ; if (labwareExes.Count > 0) { labwareExes.Pop(); } canvas.Children.Remove(labware); if (canvas.Children.Count > 1) { canvas.DataContext = labwareExes.Peek(); canvas.Tag = labwareExes; } else { canvas.DataContext = null; } SelectLabwares.Remove(labware); } } #region 属性 private void tableMenuProperty_Click(object sender, RoutedEventArgs e) { MenuItem mi = e.Source as MenuItem; ContextMenu menu = mi.Parent as ContextMenu; Canvas canvas = menu.PlacementTarget as Canvas; LabwareEx lb = canvas.DataContext as LabwareEx; if (lb == null) return; ControlLabware labware = Utilities.FindVisualChild(canvas); if (labware == null) return; Window wnd = Application.Current.MainWindow; Grid parent = Utilities.FindVisualChild(wnd); if ((labware.LabwareType == (int)ConsumableTypeEnum.TipsBox) || (labware.LabwareType == (int)ConsumableTypeEnum.Tips)) { SetTipsProperty setTipsProperty = new SetTipsProperty(labware, lb); setTipsProperty.closeEvent += SetLabelDlg_closeEvent; //setLabelDlg.OKEvent += SetLabelDlg_OKEvent; parent.Children.Add(setTipsProperty); } else { SetPlateProperty setPlateProperty = new SetPlateProperty(labware, lb); setPlateProperty.closeEvent += SetLabelDlg_closeEvent; //setLabelDlg.OKEvent += SetLabelDlg_OKEvent; parent.Children.Add(setPlateProperty); } } #endregion #region 点击标签 private void tableMenuLabel_Click(object sender, RoutedEventArgs e) { MenuItem mi = e.Source as MenuItem; ContextMenu menu = mi.Parent as ContextMenu; Canvas canvas = menu.PlacementTarget as Canvas; LabwareEx lb = canvas.DataContext as LabwareEx; if (lb == null) return; ControlLabware labware = Utilities.FindVisualChild(canvas); if (labware == null) return; Window wnd = Application.Current.MainWindow; Grid parent = Utilities.FindVisualChild(wnd); SetLabelDlg setLabelDlg = new SetLabelDlg(labware, lb); setLabelDlg.closeEvent += SetLabelDlg_closeEvent; setLabelDlg.OKEvent += SetLabelDlg_OKEvent; parent.Children.Add(setLabelDlg); } #endregion #region 复制耗材 private void tableMenuCopyLabware_Click(object sender, RoutedEventArgs e) { MenuItem mi = e.Source as MenuItem; ContextMenu menu = mi.Parent as ContextMenu; Canvas canvas = menu.PlacementTarget as Canvas; LabwareEx lb = canvas.DataContext as LabwareEx; if (lb == null) return; copyLabware = lb; MenuItem menuItem = menu.Items[3] as MenuItem; menuItem.IsEnabled = true; } #endregion #region 粘贴耗材 /// /// 粘贴耗材 /// /// /// private void tableMenuPasteLabware_Click(object sender, RoutedEventArgs e) { if (copyLabware == null) return; MenuItem mi = e.Source as MenuItem; ContextMenu menu = mi.Parent as ContextMenu; Canvas canvas = menu.PlacementTarget as Canvas; LabwareEx lb = canvas.DataContext as LabwareEx; LabwareEx labwareEx = new LabwareEx(copyLabware); ControlLabware control = new ControlLabware() { //Width = canvas.ActualWidth, //Height = canvas.ActualHeight, LabwareWidth = canvas.ActualWidth, LabwareHeight = canvas.ActualHeight, LeftSideColor = ComUtility.RGBToColor(labwareEx.labware_color_lside), FrontColor = ComUtility.RGBToColor(labwareEx.labware_color_front), TopColor = ComUtility.RGBToColor(labwareEx.labware_color_top), BorderColor = ComUtility.RGBToColor(labwareEx.labware_color_line), Rows = (int)labwareEx.number_row, Columns = (int)labwareEx.number_column, WellColor = Colors.White, IsFill = true, Label = canvas.Name, LabwareType = Convert.ToInt16(labwareEx.labware_type_id), ValidWells = labwareEx.validWells, }; Canvas.SetLeft(control, 0); Canvas.SetBottom(control, 0); labwareEx.row = Grid.GetRow(canvas); labwareEx.col = Grid.GetColumn(canvas); labwareEx.label = labwareEx.position = canvas.Name; canvas.DataContext = labwareEx; labwareExes = (Stack)canvas.Tag; if (labwareExes != null) { } else { labwareExes = new Stack(); } labwareExes.Push(labwareEx); canvas.Tag = labwareExes; //根据重叠的层级,设置margin,用的是下层的耗材数据计算 double leftMargin = 0;//离左侧距离 double bottomMargin = 0;//离底部距离 for (int i = 0; i < canvas.Children.Count; i++) { ControlLabware a = canvas.Children[i] as ControlLabware; if (a != null) { leftMargin += a.LabwareDeep; bottomMargin += a.LabwareDeep; } } control.Margin = new Thickness(leftMargin, 0, 0, bottomMargin); canvas.Children.Add(control); if (lb != null) { //如果是第二及其以上耗材,要隐藏标签 if (labwareExes.Count > 1) { control.Label = ""; } else { } } } #endregion private void SetLabelDlg_OKEvent(object sender, CustomRoutedEventArgs e) { string label = (string)e.param; Window wnd = Application.Current.MainWindow; Grid grid = Utilities.FindVisualChild(wnd); UIElement element = sender as UIElement; grid.Children.Remove(element); } private void SetLabelDlg_closeEvent(object sender, EventArgs e) { Window wnd = Application.Current.MainWindow; Grid grid = Utilities.FindVisualChild(wnd); UIElement element = sender as UIElement; grid.Children.Remove(element); } #endregion #region Workflow 菜单 #region 复制 private void workflowMenuCopy_Click(object sender, RoutedEventArgs e) { if (treeviewWorkflow.SelectedItem == null) return; if (SelectedItemList.Count > 0) { tbSelectCount.Text = $"已选择 {SelectedItemList.Count} 条指令"; } else { tbSelectCount.Text = ""; } SelectedItemList.Clear(); //把已经选中的也要加进来 List methodExes = FindMethodExBySelected(rootMethod); SelectedItemList.AddRange(methodExes); copyMethod = SelectedItemList;//treeviewWorkflow.SelectedItem as MethodEx; MenuItem mi = e.Source as MenuItem; if (mi != null) { ContextMenu menu = mi.Parent as ContextMenu; MenuItem menuItem = menu.Items[1] as MenuItem; menuItem.IsEnabled = true; } else { ContextMenu menu = FindResource("workflowMenu") as ContextMenu; MenuItem menuItem = menu.Items[1] as MenuItem; menuItem.IsEnabled = true; } } #endregion #region 粘贴 private void workflowMenuPaste_Click(object sender, RoutedEventArgs e) { if (SelectedItemList.Count > 0) { tbSelectCount.Text = $"已选择 {SelectedItemList.Count} 条指令"; } else { tbSelectCount.Text = ""; } //粘贴之前都要检查是否包含只有尾巴没有头的组合命令,如果有,不能粘贴 bool brokenMethodEx = ValidateSelectedItemOfTreeView(); if(!brokenMethodEx) { ShowTip.ShowNotice(string.Format("{0}失败{1}{2}", "粘贴", Environment.NewLine, "包含不完整的组合命令"), InfoType.Error); return; } if (SelectedItemList.Count() > 0) { for (int i= 0;i < SelectedItemList.Count;i++) { if (SelectedItemList[i] == null) return; MethodEx targetItem = treeviewWorkflow.SelectedItem as MethodEx; //WorkflowIsFlag(copyAMethod, false); //foreach (var item in copyAMethod.Children) //{ // WorkflowIsFlag(item, false); //} InsertCopyIntoWorkflow(SelectedItemList[i], targetItem,i); ReOrderMethodIndex("", rootMethod); } SelectedItemList.Clear(); tbSelectCount.Text = ""; copyMethod = null; } //else //{ // if (treeviewWorkflow.SelectedItem == null) // return; // if (copyMethod == null) // return; // MethodEx targetItem = treeviewWorkflow.SelectedItem as MethodEx; // // MethodEx sourceItem = new MethodEx(copyMethod); // InsertCopyIntoWorkflow(copyMethod, targetItem); // ReOrderMethodIndex("", rootMethod); //} } public bool ValidateSelectedItemOfTreeView() { bool result = true; foreach(MethodEx m in SelectedItemList) { if(m.groupID!=null) { if(!SelectedItemList.Contains(m.Parent)&&m.Parent.method_id!= "0") { result = false; } else if (SelectedItemList.Contains(m.Parent) ) { } } } return result; } public void InsertCopyIntoWorkflow(MethodEx source, MethodEx dest,int indexOfInsert) { MethodEx sourceItem = CloneDataForPaste(source, dest); if (dest.method_type == 2) // 1:单指令, 2:组合指令 { if (dest.Children.Count > 0) { dest.Children.Insert(indexOfInsert, sourceItem); sourceItem.SetParent(dest); } else { int index = dest.Parent.Parent.Children.IndexOf(dest.Parent); dest.Parent.Parent.Children.Insert(index+ indexOfInsert + 1, sourceItem); sourceItem.SetParent(dest.Parent.Parent); } } else { int index = dest.Parent.Children.IndexOf(dest); dest.Parent.Children.Insert(index+ indexOfInsert + 1, sourceItem); sourceItem.SetParent(dest.Parent); } } #endregion #region 禁用 private void workflowMenuDisable_Click(object sender, RoutedEventArgs e) { SelectedItemList.Clear(); //把已经选中的也要加进来 List methodExes = FindMethodExBySelected(rootMethod); SelectedItemList.AddRange(methodExes); if (SelectedItemList.Count() > 0) { foreach (var methodItem in SelectedItemList) { if (methodItem == null) return; //WorkflowIsFlag(methodItem, false); bool enable = true; if (currentKey==Key.F) { enable = false; } else if(currentKey == Key.E) { enable = true; } else { enable = !methodItem.isEnabled; } //enable = !methodItem.isEnabled; if (methodItem.method_type == 2 && methodItem.Children.Count == 0) //点击的是组合方法里的最后一个结束节点 { MethodEx parent = methodItem.Parent; EnableNode(parent, enable); } else if (enable) { EnableParentNode(methodItem, enable); EnableNode(methodItem, enable); } else EnableNode(methodItem, enable); } SelectedItemList.Clear(); tbSelectCount.Text = ""; } else { if (treeviewWorkflow.SelectedItem == null) return; MethodEx methodItem = treeviewWorkflow.SelectedItem as MethodEx; bool enable = true; if (currentKey == Key.F) { enable = false; } else if (currentKey == Key.E) { enable = true; } else { enable = !methodItem.isEnabled; } //bool enable = !methodItem.isEnabled; if (methodItem.method_type == 2 && methodItem.Children.Count == 0) //点击的是组合方法里的最后一个结束节点 { MethodEx parent = methodItem.Parent; EnableNode(parent, enable); } else if (enable) { EnableParentNode(methodItem, enable); EnableNode(methodItem, enable); } else EnableNode(methodItem, enable); } currentKey=Key.None; } #endregion #region 删除 private void workflowMenuDelete_Click(object sender, RoutedEventArgs e) { SelectedItemList.Clear(); //把已经选中的也要加进来 List methodExes = FindMethodExBySelected(rootMethod); SelectedItemList.AddRange(methodExes); if (SelectedItemList.Count > 0) { tbSelectCount.Text = $"已选择 {SelectedItemList.Count} 条指令"; } else { tbSelectCount.Text = ""; } if (SelectedItemList.Count() > 0) { foreach (var methodItem in SelectedItemList) { if (methodItem != null) { if(methodItem.method_name.Equals("开始")|| methodItem.method_name.Equals("结束")|| methodItem.method_name.Equals("台面布置")) { continue; } if (methodItem.method_type == 2 && methodItem.Children.Count == 0) { methodItem.Parent.Parent.Children.Remove(methodItem.Parent); if(mainWindow.consumableManagement!=null) { mainWindow.RemoveObserverNode(methodItem.Parent); } } else { methodItem.Parent.Children.Remove(methodItem); if (mainWindow.consumableManagement != null) { mainWindow.RemoveObserverNode(methodItem); } } ReOrderMethodIndex("", rootMethod); } } SelectedItemList.Clear(); tbSelectCount.Text = ""; } else { if (treeviewWorkflow.SelectedItem == null) return; MethodEx methodItem = treeviewWorkflow.SelectedItem as MethodEx; if (methodItem.method_name.Equals("结束")|| methodItem.method_name.Equals("开始")|| methodItem.method_name.Equals("台面布置")) { return; } if (methodItem.method_type == 2 && methodItem.Children.Count == 0) { methodItem.Parent.Parent.Children.Remove(methodItem.Parent); if (mainWindow.consumableManagement != null) { mainWindow.RemoveObserverNode(methodItem.Parent); } } else { methodItem.Parent.Children.Remove(methodItem); if (mainWindow.consumableManagement != null) { mainWindow.RemoveObserverNode(methodItem); } } ReOrderMethodIndex("", rootMethod); } updateWaitforOnWorkflow(); } #endregion #region 从此运行 private void workflowMenuRun_Click(object sender, RoutedEventArgs e) { if (treeviewWorkflow.SelectedItem == null) return; MethodEx methodItem = treeviewWorkflow.SelectedItem as MethodEx; if (methodItem.method_name.Equals("台面布置") || (methodItem.method_name.Contains("结束") && methodItem.groupID != null)) { ShowTip.ShowNotice(string.Format("{0}不能从此运行{1}{2}", "选中节点", Environment.NewLine, "此节点非命令"), InfoType.Error); return; } else { PlsToolTipWin plsToolTipWin = new PlsToolTipWin("请选择运行方式?"); plsToolTipWin.Height = this.ActualHeight; plsToolTipWin.Width = this.ActualWidth; SolidColorBrush mybtn1_Brush = new SolidColorBrush(System.Windows.Media.Color.FromArgb(70, 0, 0, 0)); plsToolTipWin.Background = (System.Windows.Media.Brush)mybtn1_Brush; plsToolTipWin.btnOK.Content = "模拟"; plsToolTipWin.btnCancel.Content = "真机"; plsToolTipWin.ShowDialog(); //遍历所有节点,把当前设置的节点设置为运行起点 SetLaunchNode(methodItem.strIndex); if (plsToolTipWin.DialogResult == true) { mainWindow.btnSimulator_Click(sender, e); } else { mainWindow.btnRun_Click(sender, e); } mainWindow.runWnd.btnPlay_Click(sender, e); } } #endregion /// /// 设置运行起点 /// /// private void SetLaunchNode(string indexName) { SetALaunchNode(rootMethod, indexName); } private void SetALaunchNode(MethodEx method, string indexName) { if (method.strIndex == indexName) { method.method_isrun = "运行起点"; } else { if (method.Children.Count > 0) { foreach (var m in method.Children) { SetALaunchNode(m, indexName); } } else { } method.method_isrun = ""; } } #region 单步运行 private void workflowMenuStepRun_Click(object sender, RoutedEventArgs e) { if (treeviewWorkflow.SelectedItem == null) return; MethodEx methodItem = treeviewWorkflow.SelectedItem as MethodEx; if (methodItem.method_name.Equals("台面布置")||(methodItem.method_name.Contains("结束")&&methodItem.groupID!=null)) { ShowTip.ShowNotice(string.Format("{0}不能单独运行{1}{2}", "选中节点", Environment.NewLine, "此节点非命令"), InfoType.Error); return; } else { PlsToolTipWin plsToolTipWin = new PlsToolTipWin("请选择运行方式?"); plsToolTipWin.Height = this.ActualHeight; plsToolTipWin.Width = this.ActualWidth; SolidColorBrush mybtn1_Brush = new SolidColorBrush(System.Windows.Media.Color.FromArgb(70, 0, 0, 0)); plsToolTipWin.Background = (System.Windows.Media.Brush)mybtn1_Brush; plsToolTipWin.btnOK.Content = "模拟"; plsToolTipWin.btnCancel.Content = "真机"; plsToolTipWin.ShowDialog(); if (plsToolTipWin.DialogResult == true) { mainWindow.btnSimulator_Click(sender, e); } else { mainWindow.btnRun_Click(sender, e); if(!mainWindow.connectedEquip) { return; } } mainWindow.runWnd.selectedMethodEx = methodItem; mainWindow.runWnd.btnPlay_Click(sender, e); } } #endregion private void EnableParentNode(MethodEx method, bool enable) { MethodEx parent = method.Parent; if (parent == null) return; if (parent.method_type == 2) { parent.isEnabled = enable; int count = parent.Children.Count; MethodEx last = parent.Children[count - 1]; last.isEnabled = enable; EnableParentNode(parent, enable); } } private void EnableNode(MethodEx method, bool enable) { method.isEnabled = enable; foreach (MethodEx me in method.Children) EnableNode(me, enable); } #endregion public MethodEx GetWorkFlow() { //MethodEx methodEx = DeepCopyByReflection.Copy(rootMethod); string methodName = ""; MethodEx methodEx = copyData(rootMethod, out methodName); if (methodEx == null) { PlsSetProperty plsSetProperty = new PlsSetProperty(methodName); plsSetProperty.closeEvent += PlsSetProperty_closeEvent; Window wnd = Application.Current.MainWindow; Grid parent = Utilities.FindVisualChild(wnd); parent.Children.Add(plsSetProperty); } return methodEx; } private void PlsSetProperty_closeEvent(object sender, EventArgs e) { Window wnd = Application.Current.MainWindow; Grid grid = Utilities.FindVisualChild(wnd); UIElement element = sender as UIElement; grid.Children.Remove(element); } public MethodEx copyData(MethodEx method, out string Name) { MethodEx ret = method.Clone() as MethodEx; Name = ret.method_name; if (method.Level == -1) { ret.Children = new ObservableCollection(); foreach (var item in method.Children) { string name = ""; MethodEx me = copyData(item, out name); if (me == null&& !item.isEnabled) { Name = name; return null; } if (me != null) { me.isSelected = false; ret.Children.Add(me); } else { Name = name; return null; } } } else { if (method.method_id == "1") { } else { if (ret.control == null) { if (ret.method_name == "循环结束" || ret.method_name == "组合结束"||ret.method_name=="if结束"||ret.method_name=="else结束") { } else { return null; } } ret.Children = new ObservableCollection(); foreach (var item in method.Children) { string name = ""; MethodEx me = copyData(item, out name); if (me == null && !item.isEnabled) { Name = name; return null; } ret.Children.Add(me); } } } return ret; } public List GetLabwaresOnTable() { List list = new List(); foreach (var item in gridTable.Children) { Canvas canvas = item as Canvas; if (canvas.DataContext != null) { List controlLabwares = Utilities.FindAllVisualChild(canvas); if (controlLabwares == null || controlLabwares.Count == 0) { continue; } if ((canvas.DataContext as LabwareEx)!=null&&(canvas.DataContext as LabwareEx).labware_name=="垃圾桶") { continue; } List l = ((Stack)canvas.Tag).ToList(); l.Reverse(); foreach (var i in l) { i.labware_sname = controlLabwares[0].Label; } list.AddRange(l); } } return list; } private void cbLabwareType_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (cbLabwareType.SelectedIndex < 0) return; listviewConsumable.ItemsSource = null; if (cbLabwareType.SelectedValue.ToString() == "-1") listviewConsumable.ItemsSource = labwareCollection; else { List list = labwareCollection.Where(s => s.labware_type_id == cbLabwareType.SelectedValue.ToString()).ToList(); listviewConsumable.ItemsSource = list; } } private void searchLabware_PreviewKeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Enter) { string search = searchLabware.Text.Trim(); listviewConsumable.ItemsSource = null; List list = labwareCollection.Where(s => s.labware_name.Contains(search)).ToList(); listviewConsumable.ItemsSource = list; } } private void searchLabware_clearEvent(object sender, EventArgs e) { listviewConsumable.ItemsSource = null; listviewConsumable.ItemsSource = labwareCollection; } private void searchMethod_PreviewKeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Enter) { string search = searchMethod.Text.Trim(); listboxCmd.ItemsSource = null; ObservableCollection grouplist = new ObservableCollection(); CMethodGroup group = new CMethodGroup(); group.GroupName = Properties.Resources.strSearchResult; List list = DataModule.getInstance().GetMethod().Where(s => s.method_name.Contains(search)).ToList(); foreach (var item in list) { MethodEx me = new MethodEx(item); group.Children.Add(me); } grouplist.Add(group); listboxCmd.ItemsSource = grouplist; } } private void searchMethod_clearEvent(object sender, EventArgs e) { listboxCmd.ItemsSource = null; listboxCmd.ItemsSource = methodGroupCollection; } #region 构建xml信息 public bool checkPropertyBreak = false; public XmlDocument GenerateLaunchXmlDocument() { XmlHelper xmlHelper = new XmlHelper(); try { if (rootMethod.Children.Count > 0) { //UpdateMethodIndexOnMethodListItem(); xmlHelper.CreateXMLHeader(); string choiceLatticeId = ConfigurationManager.AppSettings["choiceLatticeId"].ToString(); string choiceLabwareId = ConfigurationManager.AppSettings["choicelabwareId"].ToString(); List latticeRSLabwares = new List(); //台面数据 //如果是Tip头盒子要保存,可用的Tip头孔位信息数据 //如果是板子孔位,则要保存孔位内部液体名称和液体体积信息数据 for (int i = 0; i < gridTable.Children.Count; i++) { Canvas canvas = ((Canvas)gridTable.Children[i]); #region 有耗材 if (canvas.Children.Count > 1)//有耗材 { if (canvas.Tag == null)//排除垃圾桶 { continue; } List controlLabwares = Utilities.FindAllVisualChild(canvas); LatticeRSLabware latticeRSLabware = new LatticeRSLabware(); List labwareOnLattices = new List(); for (int j = 0; j < controlLabwares.Count; j++) { Stack labwareExes = (Stack)canvas.Tag; List labwareExesList=labwareExes.ToList(); labwareExesList.Reverse(); Labware lb = labwareExesList[j] as Labware; LabwareOnLattice labwareOnLattice = new LabwareOnLattice(); Labware labware = null; ObservableCollection labwares = null; { labwareOnLattice.labware_id = lb.labware_id; labwareOnLattice.labware_sname = controlLabwares[0].Label;//lb.labware_name; labwareOnLattice.labware_barcode = lb.labware_barcode;//lb.Barcode; labware = LabwareDB.GetLabware(labwareOnLattice.labware_id); if (labware != null) { string wellsTip = controlLabwares[j].ValidWells; if (!string.IsNullOrEmpty(wellsTip)) { labwareOnLattice.labware_tipwells = XHandler.Controls.Run.Com.ControlCom.SortWellName(wellsTip,labware.number_row,labware.number_column); if (!string.IsNullOrEmpty(labwareOnLattice.labware_tipwells)) { string[] wellNameList = labwareOnLattice.labware_tipwells.Split(','); for (int n = 0; n < wellNameList.Length; n++) { DropdownName currentAWellLattice = new DropdownName(); Lattice lattice = null; TabletopTemplate tabletopTemplate = TabletopTemplateDB.GetCurrentAppTabletopTemplateCollectionFromdb(); //增加台面模板判断 DeviceArm queryDeviceArm = Shared.DeviceArmList.FirstOrDefault(x => x.arm_type.Equals(1)); if (tabletopTemplate == null) { string latticeNumber = canvas.Name.ToString(); lattice = LatticeDB.GetLatticeDataByIdFromdb(latticeNumber, Convert.ToInt32(queryDeviceArm.device_arm_id), Shared.SoftwareInformation.software_device_number);//arm1 } else { string latticeNumber = canvas.Name.ToString(); lattice = LatticeDB.GetLatticeDataByLatticeNumAndTempIdFromdb(latticeNumber, Convert.ToInt32(queryDeviceArm.device_arm_id), Shared.SoftwareInformation.software_device_number, tabletopTemplate.tabletopid); } currentAWellLattice.dropdown_id = lattice.lattice_id; currentAWellLattice.dropdown_name = wellNameList[n]; var aWell = RunWnd.currentIsUsedWellLattice.FirstOrDefault(x => x.dropdown_id.Equals(currentAWellLattice.dropdown_id) && x.dropdown_name.Equals(currentAWellLattice.dropdown_name)); if (aWell != null) { RunWnd.currentIsUsedWellLattice.Remove(aWell); } } } } else { labwareOnLattice.labware_tipwells = ""; } labwares = LabwareDB.GetPiledlabwareOfALabware(labware); if (labwares.Count > 0) { labwareOnLattice.labware_withlid = "1";//耗材有盖子 } else { labwareOnLattice.labware_withlid = "0";//耗材无盖子 } ObservableCollection plateWellsDatas = ((controlLabwares[j].DataContext) as LabwareEx).plateWellDataList; ObservableCollection plateWellsLiquidDatas = new ObservableCollection(); if (plateWellsDatas != null) { foreach (PlateWellsData p in plateWellsDatas) { PlateWellsLiquidData plateWellsLiquidData = new PlateWellsLiquidData(); plateWellsLiquidData.liquidTypeID = p.liquidTypeID; plateWellsLiquidData.nIndex = p.nIndex; plateWellsLiquidData.nVolume = p.nVolume; plateWellsLiquidData.wells = p.wells; plateWellsLiquidData.liquidTypeName = p.liquidTypeName; plateWellsLiquidDatas.Add(plateWellsLiquidData); } labwareOnLattice.plateWellsLiquidData = plateWellsLiquidDatas; } else { labwareOnLattice.plateWellsLiquidData = new ObservableCollection(); } } else { labwareOnLattice.labware_tipwells = ""; labwareOnLattice.labware_withlid = "0";//耗材无盖子 labwareOnLattice.plateWellsLiquidData = new ObservableCollection(); } } labwareOnLattice.level = j+1; labwareOnLattices.Add(labwareOnLattice); } latticeRSLabware.lattice_id = canvas.Name.Substring(1); latticeRSLabware.labwareOnLattices= labwareOnLattices; latticeRSLabwares.Add(latticeRSLabware); } #endregion #region 无耗材 else { } #endregion } xmlHelper.CreateEnvironmentPlatformXmlNode(latticeRSLabwares); int indexOfCmd = 0;//命令的计数 for (int i = 0; i < rootMethod.Children.Count; i++) { MethodEx mEx = rootMethod.Children[i]; int iNum = methodListBll.getNumByMethodName(mEx.method_content); #region 开始 if (iNum == (int)MethodNameEnum.start) { StartProperty startProperty = mEx.control as StartProperty; xmlHelper.CreateStartXmlNode(startProperty.methodStart,mEx); } #endregion #region 吸液 else if (iNum == (int)MethodNameEnum.aspirate) { AspirateProperty ap = mEx.control as AspirateProperty; if (ap != null) { //ap.methodAspirate.channels = ap.tipsChannel.SelectedChannels.ToArray(); xmlHelper.CreateAspirateXmlNode(i + 1 + indexOfCmd, ap.methodAspirate, mEx); } else { MethodAspirate methodAspirate = new MethodAspirate(); methodAspirate.label = mEx.method_name; methodAspirate.name = mEx.method_name; methodAspirate.strIndex = mEx.strIndex; methodAspirate.status = (mEx.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateAspirateXmlNode(i + 1 + indexOfCmd, methodAspirate, mEx); } } #endregion #region 排液 else if (iNum == (int)MethodNameEnum.dispense) { DispenseProperty dp = mEx.control as DispenseProperty; if (dp != null) { xmlHelper.CreateDispenseXmlNode(i + 1 + indexOfCmd, dp.methodDispense, mEx); } else { MethodDispense methodDispense = new MethodDispense(); methodDispense.label = mEx.method_name; methodDispense.name = mEx.method_name; methodDispense.strIndex = mEx.strIndex; methodDispense.status = (mEx.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateDispenseXmlNode(i + 1 + indexOfCmd, methodDispense, mEx); } } #endregion #region 安装吸头 else if (iNum == (int)MethodNameEnum.loadtips) { LoadTipsProperty lp = mEx.control as LoadTipsProperty; //更新界面中未触发更新的 if (lp != null) { //lp.methodLoadTips.channels = lp.tipsChannel.SelectedChannels.ToArray(); xmlHelper.CreateLoadTipsXmlNode(i + 1 + indexOfCmd, lp.methodLoadTips, mEx); } else { MethodLoadTips methodLoadTips = new MethodLoadTips(); methodLoadTips.label = mEx.method_name; methodLoadTips.name = mEx.method_name; methodLoadTips.strIndex = mEx.strIndex; methodLoadTips.status = (mEx.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateLoadTipsXmlNode(i + 1 + indexOfCmd, methodLoadTips, mEx); } } #endregion #region 卸载吸头 else if (iNum == (int)MethodNameEnum.unloadtips) { UnLoadTipsProperty ulp = mEx.control as UnLoadTipsProperty; if (ulp != null) { //ulp.methodUnLoadTips.channels = ulp.tipsChannel.SelectedChannels.ToArray(); xmlHelper.CreateUnloadTipsXmlNode(i + 1 + indexOfCmd, ulp.methodUnLoadTips, mEx); } else { MethodUnloadTips methodUnLoadTips = new MethodUnloadTips(); methodUnLoadTips.label = mEx.method_name; methodUnLoadTips.name = mEx.method_name; methodUnLoadTips.strIndex = mEx.strIndex; methodUnLoadTips.status = (mEx.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateUnloadTipsXmlNode(i + 1 + indexOfCmd, methodUnLoadTips, mEx); } } #endregion #region 混合 else if (iNum == (int)MethodNameEnum.mixing) { MixProperty mp = mEx.control as MixProperty; if (mp != null) { //mp.methodMix.channels = mp.tipsChannel.SelectedChannels.ToArray(); xmlHelper.CreateMixingXmlNode(i + 1 + indexOfCmd, mp.methodMix, mEx); } else { MethodMixing methodMixing = new MethodMixing(); methodMixing.label = mEx.method_name; methodMixing.name = mEx.method_name; methodMixing.strIndex = mEx.strIndex; methodMixing.status = (mEx.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateMixingXmlNode(i + 1 + indexOfCmd, methodMixing, mEx); } } #endregion #region 抓板转移 else if (iNum == (int)MethodNameEnum.griptransport) { GripTransportProperty gtp = mEx.control as GripTransportProperty; if (gtp != null) { xmlHelper.CreateGripTransportXmlNode(i + 1 + indexOfCmd, gtp.methodGripTransport, mEx); } else { MethodGripTransport methodGripTransport = new MethodGripTransport(); methodGripTransport.label = mEx.method_name; methodGripTransport.name = mEx.method_name; methodGripTransport.strIndex = mEx.strIndex; methodGripTransport.status = (mEx.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateGripTransportXmlNode(i + 1 + indexOfCmd, methodGripTransport, mEx); } } #endregion #region 移动夹爪 else if (iNum == (int)MethodNameEnum.gripmove) { GripMoveProperty gtp = mEx.control as GripMoveProperty; if (gtp != null) { xmlHelper.CreateGripMoveXmlNode(i + 1 + indexOfCmd, gtp.methodGripMove, mEx); } else { MethodGripMove methodGripMove = new MethodGripMove(); methodGripMove.label = mEx.method_name; methodGripMove.name = mEx.method_name; methodGripMove.strIndex = mEx.strIndex; methodGripMove.status = (mEx.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateGripMoveXmlNode(i + 1 + indexOfCmd, methodGripMove, mEx); } } #endregion #region 夹爪保持开始 else if (iNum == (int)MethodNameEnum.holdingLabware) { BeginHoldingLabwareProperty fp = mEx.control as BeginHoldingLabwareProperty; if (fp != null) { xmlHelper.CreateBeginHoldingLabwareXmlNode(i + 1 + indexOfCmd, fp.methodHoldingLabware, mEx); //访问循环内的命令集合 if (mEx.Children.Count >= 1) { indexOfCmd = GenerateXmlNode(xmlHelper, mEx.Children, i + 1 + indexOfCmd); indexOfCmd = indexOfCmd - i; } } else { MethodHoldingLabware methodHoldingLabware = new MethodHoldingLabware(); methodHoldingLabware.label = mEx.method_name; methodHoldingLabware.name = mEx.method_name; methodHoldingLabware.strIndex = mEx.strIndex; methodHoldingLabware.status = (mEx.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateBeginHoldingLabwareXmlNode(i + 1 + indexOfCmd, methodHoldingLabware, mEx); //访问循环内的命令集合 if (mEx.Children.Count >= 1) { indexOfCmd = GenerateXmlNode(xmlHelper, mEx.Children, i + 1 + indexOfCmd); indexOfCmd = indexOfCmd - i; } } } #endregion #region 夹爪保持结束 else if (iNum == (int)MethodNameEnum.endHoldingLabware) { EndHoldingLabwareProperty fp = mEx.control as EndHoldingLabwareProperty; if (fp != null) { xmlHelper.CreateEndHoldingLabwareXmlNode(i + 1 + indexOfCmd, fp.methodHoldingLabware, mEx); } else { MethodHoldingLabware methodHoldingLabware = new MethodHoldingLabware(); methodHoldingLabware.label = mEx.method_name; methodHoldingLabware.name = mEx.method_name; methodHoldingLabware.strIndex = mEx.strIndex; methodHoldingLabware.status = (mEx.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateEndHoldingLabwareXmlNode(i + 1 + indexOfCmd, methodHoldingLabware, mEx); } } #endregion #region 暂停 else if (iNum == (int)MethodNameEnum.pause) { PauseProperty gtp = mEx.control as PauseProperty; if (gtp != null) { xmlHelper.CreatePauseMoveXmlNode(i + 1 + indexOfCmd, gtp.methodPauseMove, mEx); } else { MethodPauseMove methodPauseMove = new MethodPauseMove(); methodPauseMove.label = mEx.method_name; methodPauseMove.name = mEx.method_name; methodPauseMove.strIndex = mEx.strIndex; methodPauseMove.status = (mEx.isEnabled == true ? "enable" : "disable"); xmlHelper.CreatePauseMoveXmlNode(i + 1 + indexOfCmd, methodPauseMove, mEx); } } #endregion #region 结束 else if (iNum == (int)MethodNameEnum.end) { EndProperty endProperty = mEx.control as EndProperty; endProperty.methodEnd.strIndex = mEx.strIndex; xmlHelper.CreateEndXmlNode(i + 1 + indexOfCmd, endProperty.methodEnd, mEx); } #endregion #region 开始循环 else if (iNum == (int)MethodNameEnum.loop) { LoopProperty loopProperty = mEx.control as LoopProperty; if (loopProperty != null) { if (mEx.Children.Count >= 1) { loopProperty.methodLoop.endIndex = mEx.Children[mEx.Children.Count - 1].strIndex; } xmlHelper.CreateLoopXmlNode(i + 1 + indexOfCmd, loopProperty.methodLoop, mEx); //访问循环内的命令集合 if (mEx.Children.Count >= 1) { indexOfCmd = GenerateXmlNode(xmlHelper, mEx.Children, i + 1 + indexOfCmd); indexOfCmd = indexOfCmd - i - 1; } } else { MethodLoop methodLoop = new MethodLoop(); methodLoop.label = mEx.method_name; methodLoop.name = mEx.method_name; methodLoop.strIndex = mEx.strIndex; if (mEx.Children.Count >= 1) { methodLoop.endIndex = mEx.Children[mEx.Children.Count - 1].strIndex; } methodLoop.status = (mEx.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateLoopXmlNode(i + 1 + indexOfCmd, methodLoop, mEx); //访问循环内的命令集合 if (mEx.Children.Count >= 1) { indexOfCmd = GenerateXmlNode(xmlHelper, mEx.Children, i + 1 + indexOfCmd); indexOfCmd = indexOfCmd - i - 1; } } } #endregion #region 结束循环 else if (iNum == (int)MethodNameEnum.endloop) { xmlHelper.CreateEndLoopXmlNode(i + 1 + indexOfCmd, mEx.strIndex); } #endregion #region 文件 else if (iNum == (int)MethodNameEnum.transferfile) { FileProperty fp = mEx.control as FileProperty; if (fp != null) { //fp.methodTransferFile.channels = fp.tipsChannel.SelectedChannels.ToArray(); xmlHelper.CreateTransferFileXmlNode(i + 1 + indexOfCmd, fp.methodTransferFile, mEx); } else { MethodTransferFile methodTransferFile = new MethodTransferFile(); methodTransferFile.label = mEx.method_name; methodTransferFile.name = mEx.method_name; methodTransferFile.strIndex = mEx.strIndex; methodTransferFile.status = (mEx.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateTransferFileXmlNode(i + 1 + indexOfCmd, methodTransferFile, mEx); } } #endregion #region 复位 else if (iNum == (int)MethodNameEnum.home) { ResetProperty fp = mEx.control as ResetProperty; if (fp != null) { xmlHelper.CreateHomeXmlNode(i + 1 + indexOfCmd, fp.methodHome, mEx); } else { MethodHome methodHome = new MethodHome(); methodHome.label = mEx.method_name; methodHome.name = mEx.method_name; methodHome.strIndex = mEx.strIndex; methodHome.status = (mEx.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateHomeXmlNode(i + 1 + indexOfCmd, methodHome, mEx); } } #endregion #region 备注 else if (iNum == (int)MethodNameEnum.remark) { CommentProperty fp = mEx.control as CommentProperty; if (fp != null) { xmlHelper.CreateRemarkXmlNode(i + 1 + indexOfCmd, fp.methodRemark, mEx); } else { MethodRemark methodRemark = new MethodRemark(); methodRemark.label = mEx.method_name; methodRemark.name = mEx.method_name; methodRemark.strIndex = mEx.strIndex; methodRemark.status = (mEx.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateRemarkXmlNode(i + 1 + indexOfCmd, methodRemark, mEx); } } #endregion #region 数据导入 else if (iNum == (int)MethodNameEnum.dataimport) { DataImportProperty fp = mEx.control as DataImportProperty; if (fp != null) { xmlHelper.CreateDataImportXmlNode(i + 1 + indexOfCmd, fp.methodDataImport, mEx); } else { MethodDataImport methodDataImport = new MethodDataImport(); methodDataImport.label = mEx.method_name; methodDataImport.name = mEx.method_name; methodDataImport.strIndex = mEx.strIndex; methodDataImport.status = (mEx.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateDataImportXmlNode(i + 1 + indexOfCmd, methodDataImport, mEx); } } #endregion #region 数据导出 else if (iNum == (int)MethodNameEnum.dataexport) { DataExportProperty fp = mEx.control as DataExportProperty; if (fp != null) { xmlHelper.CreateDataExportXmlNode(i + 1 + indexOfCmd, fp.methodDataExport, mEx); } else { MethodDataExport methodDataExport = new MethodDataExport(); methodDataExport.label = mEx.method_name; methodDataExport.name = mEx.method_name; methodDataExport.strIndex = mEx.strIndex; methodDataExport.status = (mEx.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateDataExportXmlNode(i + 1 + indexOfCmd, methodDataExport, mEx); } } #endregion #region 组合 else if (iNum == (int)MethodNameEnum.group) { GroupProperty fp = mEx.control as GroupProperty; if (fp != null) { xmlHelper.CreateGroupXmlNode(i + 1 + indexOfCmd, fp.methodGroup, mEx); //访问循环内的命令集合 if (mEx.Children.Count >= 1) { indexOfCmd = GenerateXmlNode(xmlHelper, mEx.Children, i + 1 + indexOfCmd); indexOfCmd = indexOfCmd - i; } } else { MethodCombination methodCombination = new MethodCombination(); methodCombination.label = mEx.method_name; methodCombination.name = mEx.method_name; methodCombination.strIndex = mEx.strIndex; methodCombination.status = (mEx.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateGroupXmlNode(i + 1 + indexOfCmd, methodCombination, mEx); //访问循环内的命令集合 if (mEx.Children.Count >= 1) { indexOfCmd = GenerateXmlNode(xmlHelper, mEx.Children, i + 1 + indexOfCmd); indexOfCmd = indexOfCmd - i; } } } #endregion #region 结束组合 else if (iNum == (int)MethodNameEnum.endgroup) { xmlHelper.CreateEndGroupXmlNode(i + 1 + indexOfCmd, mEx.strIndex); } #endregion #region 拍照 else if (iNum == (int)MethodNameEnum.takephoto) { if (Shared.SoftwareInformation.software_device_number.Equals(DeviceCategory.DeviceHXELEC)) { CaptureElectroProperty fp = mEx.control as CaptureElectroProperty; if (fp != null) { xmlHelper.CreateTakePhotoForElectroXmlNode(i + 1 + indexOfCmd, fp.methodTakePhotoForElectro, mEx); //访问循环内的命令集合 if (mEx.Children.Count >= 1) { indexOfCmd = GenerateXmlNode(xmlHelper, mEx.Children, i + 1 + indexOfCmd); indexOfCmd = indexOfCmd - i; } } else { MethodTakePhotoForElectro methodTakePhotoForElectro = new MethodTakePhotoForElectro(); methodTakePhotoForElectro.label = mEx.method_name; methodTakePhotoForElectro.name = mEx.method_name; methodTakePhotoForElectro.strIndex = mEx.strIndex; methodTakePhotoForElectro.status = (mEx.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateTakePhotoForElectroXmlNode(i + 1 + indexOfCmd, methodTakePhotoForElectro, mEx); //访问循环内的命令集合 if (mEx.Children.Count >= 1) { indexOfCmd = GenerateXmlNode(xmlHelper, mEx.Children, i + 1 + indexOfCmd); indexOfCmd = indexOfCmd - i; } } } else { CaptureProperty fp = mEx.control as CaptureProperty; if (fp != null) { xmlHelper.CreateTakePhotoXmlNode(i + 1 + indexOfCmd, fp.methodTakePhoto, mEx); //访问循环内的命令集合 if (mEx.Children.Count >= 1) { indexOfCmd = GenerateXmlNode(xmlHelper, mEx.Children, i + 1 + indexOfCmd); indexOfCmd = indexOfCmd - i; } } else { MethodTakePhoto methodTakePhoto = new MethodTakePhoto(); methodTakePhoto.label = mEx.method_name; methodTakePhoto.name = mEx.method_name; methodTakePhoto.strIndex = mEx.strIndex; methodTakePhoto.status = (mEx.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateTakePhotoXmlNode(i + 1 + indexOfCmd, methodTakePhoto, mEx); //访问循环内的命令集合 if (mEx.Children.Count >= 1) { indexOfCmd = GenerateXmlNode(xmlHelper, mEx.Children, i + 1 + indexOfCmd); indexOfCmd = indexOfCmd - i; } } } } #endregion #region 挑选 else if (iNum == (int)MethodNameEnum.choice) { PickProperty fp = mEx.control as PickProperty; if (fp != null) { xmlHelper.CreateChoiceXmlNode(i + 1 + indexOfCmd, fp.methodChoice, mEx); //访问循环内的命令集合 if (mEx.Children.Count >= 1) { indexOfCmd = GenerateXmlNode(xmlHelper, mEx.Children, i + 1 + indexOfCmd); indexOfCmd = indexOfCmd - i; } } else { MethodChoice methodChoice = new MethodChoice(); methodChoice.label = mEx.method_name; methodChoice.name = mEx.method_name; methodChoice.strIndex = mEx.strIndex; methodChoice.status = (mEx.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateChoiceXmlNode(i + 1 + indexOfCmd, methodChoice, mEx); //访问循环内的命令集合 if (mEx.Children.Count >= 1) { indexOfCmd = GenerateXmlNode(xmlHelper, mEx.Children, i + 1 + indexOfCmd); indexOfCmd = indexOfCmd - i; } } } #endregion #region 涂布 else if (iNum == (int)MethodNameEnum.coating) { CoatingProperty fp = mEx.control as CoatingProperty; if (fp != null) { xmlHelper.CreateCoatingXmlNode(i + 1 + indexOfCmd, fp.methodCoating, mEx); //访问循环内的命令集合 if (mEx.Children.Count >= 1) { indexOfCmd = GenerateXmlNode(xmlHelper, mEx.Children, i + 1 + indexOfCmd); indexOfCmd = indexOfCmd - i; } } else { MethodCoating methodCoating = new MethodCoating(); methodCoating.label = mEx.method_name; methodCoating.name = mEx.method_name; methodCoating.strIndex = mEx.strIndex; methodCoating.status = (mEx.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateCoatingXmlNode(i + 1 + indexOfCmd, methodCoating, mEx); //访问循环内的命令集合 if (mEx.Children.Count >= 1) { indexOfCmd = GenerateXmlNode(xmlHelper, mEx.Children, i + 1 + indexOfCmd); indexOfCmd = indexOfCmd - i; } } } #endregion #region 涂布文件 else if (iNum == (int)MethodNameEnum.coatingfile) { FileCoatingProperty fp = mEx.control as FileCoatingProperty; if (fp != null) { xmlHelper.CreateCoatingFileXmlNode(i + 1 + indexOfCmd, fp.methodCoatingFile, mEx); //访问循环内的命令集合 if (mEx.Children.Count >= 1) { indexOfCmd = GenerateXmlNode(xmlHelper, mEx.Children, i + 1 + indexOfCmd); indexOfCmd = indexOfCmd - i; } } else { MethodCoatingFile methodCoatingFile = new MethodCoatingFile(); methodCoatingFile.label = mEx.method_name; methodCoatingFile.name = mEx.method_name; methodCoatingFile.strIndex = mEx.strIndex; methodCoatingFile.status = (mEx.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateCoatingFileXmlNode(i + 1 + indexOfCmd, methodCoatingFile, mEx); //访问循环内的命令集合 if (mEx.Children.Count >= 1) { indexOfCmd = GenerateXmlNode(xmlHelper, mEx.Children, i + 1 + indexOfCmd); indexOfCmd = indexOfCmd - i; } } } #endregion #region 涂布报告 else if (iNum == (int)MethodNameEnum.coatingReport) { CoatingFileExportProperty fp = mEx.control as CoatingFileExportProperty; if (fp != null) { xmlHelper.CreateCoatingReportXmlNode(i + 1 + indexOfCmd, fp.methodCoatingReport, mEx); //访问循环内的命令集合 if (mEx.Children.Count >= 1) { indexOfCmd = GenerateXmlNode(xmlHelper, mEx.Children, i + 1 + indexOfCmd); indexOfCmd = indexOfCmd - i; } } else { MethodCoatingReport methodCoatingReport = new MethodCoatingReport(); methodCoatingReport.label = mEx.method_name; methodCoatingReport.name = mEx.method_name; methodCoatingReport.strIndex = mEx.strIndex; methodCoatingReport.status = (mEx.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateCoatingReportXmlNode(i + 1 + indexOfCmd, methodCoatingReport, mEx); //访问循环内的命令集合 if (mEx.Children.Count >= 1) { indexOfCmd = GenerateXmlNode(xmlHelper, mEx.Children, i + 1 + indexOfCmd); indexOfCmd = indexOfCmd - i; } } } #endregion #region 超声探测 else if (iNum == (int)MethodNameEnum.ultrasonic) { UltrasonicProperty fp = mEx.control as UltrasonicProperty; if (fp != null) { xmlHelper.CreateUltrasonicXmlNode(i + 1 + indexOfCmd, fp.methodUltrasonic, mEx); //访问循环内的命令集合 if (mEx.Children.Count >= 1) { indexOfCmd = GenerateXmlNode(xmlHelper, mEx.Children, i + 1 + indexOfCmd); indexOfCmd = indexOfCmd - i; } } else { MethodUltrasonic methodUltrasonic = new MethodUltrasonic(); methodUltrasonic.label = mEx.method_name; methodUltrasonic.name = mEx.method_name; methodUltrasonic.strIndex = mEx.strIndex; methodUltrasonic.status = (mEx.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateUltrasonicXmlNode(i + 1 + indexOfCmd, methodUltrasonic, mEx); //访问循环内的命令集合 if (mEx.Children.Count >= 1) { indexOfCmd = GenerateXmlNode(xmlHelper, mEx.Children, i + 1 + indexOfCmd); indexOfCmd = indexOfCmd - i; } } } #endregion #region 挑选转板 else if (iNum == (int)MethodNameEnum.choiceTransfer) { PickAndTransferProperty fp = mEx.control as PickAndTransferProperty; if (fp != null) { xmlHelper.CreateChoiceAndTransferXmlNode(i + 1 + indexOfCmd, fp.methodChoice, mEx); //访问循环内的命令集合 if (mEx.Children.Count >= 1) { indexOfCmd = GenerateXmlNode(xmlHelper, mEx.Children, i + 1 + indexOfCmd); indexOfCmd = indexOfCmd - i; } } else { MethodChoiceAndTransfer methodChoice = new MethodChoiceAndTransfer(); methodChoice.label = mEx.method_name; methodChoice.name = mEx.method_name; methodChoice.strIndex = mEx.strIndex; methodChoice.status = (mEx.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateChoiceAndTransferXmlNode(i + 1 + indexOfCmd, methodChoice, mEx); //访问循环内的命令集合 if (mEx.Children.Count >= 1) { indexOfCmd = GenerateXmlNode(xmlHelper, mEx.Children, i + 1 + indexOfCmd); indexOfCmd = indexOfCmd - i; } } } #endregion #region 涂布转板 else if (iNum == (int)MethodNameEnum.coatingTransfer) { CoatingAndTransferProperty fp = mEx.control as CoatingAndTransferProperty; if (fp != null) { xmlHelper.CreateCoatingAndTransferXmlNode(i + 1 + indexOfCmd, fp.methodCoating, mEx); //访问循环内的命令集合 if (mEx.Children.Count >= 1) { indexOfCmd = GenerateXmlNode(xmlHelper, mEx.Children, i + 1 + indexOfCmd); indexOfCmd = indexOfCmd - i; } } else { MethodCoatingAndTransfer methodCoating = new MethodCoatingAndTransfer(); methodCoating.label = mEx.method_name; methodCoating.name = mEx.method_name; methodCoating.strIndex = mEx.strIndex; methodCoating.status = (mEx.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateCoatingAndTransferXmlNode(i + 1 + indexOfCmd, methodCoating, mEx); //访问循环内的命令集合 if (mEx.Children.Count >= 1) { indexOfCmd = GenerateXmlNode(xmlHelper, mEx.Children, i + 1 + indexOfCmd); indexOfCmd = indexOfCmd - i; } } } #endregion #region 梯度稀释 else if (iNum == (int)MethodNameEnum.dilution) { DilutionProperty fp = mEx.control as DilutionProperty; if (fp != null) { xmlHelper.CreateDilutionXmlNode(i + 1 + indexOfCmd, fp.methodDilution, mEx); //访问循环内的命令集合 if (mEx.Children.Count >= 1) { indexOfCmd = GenerateXmlNode(xmlHelper, mEx.Children, i + 1 + indexOfCmd); indexOfCmd = indexOfCmd - i; } } else { MethodDilution methodDilution = new MethodDilution(); methodDilution.label = mEx.method_name; methodDilution.name = mEx.method_name; methodDilution.strIndex = mEx.strIndex; methodDilution.status = (mEx.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateDilutionXmlNode(i + 1 + indexOfCmd, methodDilution, mEx); //访问循环内的命令集合 if (mEx.Children.Count >= 1) { indexOfCmd = GenerateXmlNode(xmlHelper, mEx.Children, i + 1 + indexOfCmd); indexOfCmd = indexOfCmd - i; } } } #endregion #region 第三方设备 else if (mEx.method_group_id == EnumManagement.GetEnumValue(MethodGroupEnum.ThirdPart)) { ThirdPartPropertySocketProperty fp = mEx.control as ThirdPartPropertySocketProperty; if (fp != null) { xmlHelper.CreateThirdPartXmlNode(i + 1 + indexOfCmd, fp.methodProperty, mEx); //访问循环内的命令集合 if (mEx.Children.Count >= 1) { indexOfCmd = GenerateXmlNode(xmlHelper, mEx.Children, i + 1 + indexOfCmd); indexOfCmd = indexOfCmd - i; } } else { MethodThirdPart methodThirdPart = new MethodThirdPart(); methodThirdPart.label = mEx.method_name; methodThirdPart.name = mEx.method_name; methodThirdPart.strIndex = mEx.strIndex; methodThirdPart.status = (mEx.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateThirdPartXmlNode(i + 1 + indexOfCmd, methodThirdPart, mEx); //访问循环内的命令集合 if (mEx.Children.Count >= 1) { indexOfCmd = GenerateXmlNode(xmlHelper, mEx.Children, i + 1 + indexOfCmd); indexOfCmd = indexOfCmd - i; } } } #endregion #region 设置变量 else if (iNum == (int)MethodNameEnum.setVariable) { SetVariableProperty gtp = mEx.control as SetVariableProperty; if (gtp != null) { xmlHelper.CreateSetVariableXmlNode(i + 1 + indexOfCmd, gtp.methodSetVariable, mEx); } else { MethodSetVariable methodSetVariable = new MethodSetVariable(); methodSetVariable.label = mEx.method_name; methodSetVariable.name = mEx.method_name; methodSetVariable.strIndex = mEx.strIndex; methodSetVariable.status = (mEx.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateSetVariableXmlNode(i + 1 + indexOfCmd, methodSetVariable, mEx); } } #endregion #region 文件导入变量 else if (iNum == (int)MethodNameEnum.VariableImport) { VariableImportProperty gtp = mEx.control as VariableImportProperty; if (gtp != null) { xmlHelper.CreateVariableImportXmlNode(i + 1 + indexOfCmd, gtp.methodVariableImport, mEx); } else { MethodVariableImport methodVariableImport = new MethodVariableImport(); methodVariableImport.label = mEx.method_name; methodVariableImport.name = mEx.method_name; methodVariableImport.strIndex = mEx.strIndex; methodVariableImport.status = (mEx.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateVariableImportXmlNode(i + 1 + indexOfCmd, methodVariableImport, mEx); } } #endregion #region if开始 else if (iNum == (int)MethodNameEnum.ifStart) { IfElseProperty ifElseProperty = mEx.control as IfElseProperty; if (ifElseProperty != null) { if (mEx.Children.Count >= 1) { ifElseProperty.methodIfElse.endIndex = mEx.Children[mEx.Children.Count - 1].strIndex; } xmlHelper.CreateIfStartXmlNode(i + 1 + indexOfCmd, ifElseProperty.methodIfElse, mEx); //访问循环内的命令集合 if (mEx.Children.Count >= 1) { indexOfCmd = GenerateXmlNode(xmlHelper, mEx.Children, i + 1 + indexOfCmd); indexOfCmd = indexOfCmd - i - 1; } } else { MethodIfElse methodIfElse = new MethodIfElse(); methodIfElse.label = mEx.method_name; methodIfElse.name = mEx.method_name; methodIfElse.strIndex = mEx.strIndex; if (mEx.Children.Count >= 1) { methodIfElse.endIndex = mEx.Children[mEx.Children.Count - 1].strIndex; } methodIfElse.status = (mEx.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateIfStartXmlNode(i + 1 + indexOfCmd, methodIfElse, mEx); //访问循环内的命令集合 if (mEx.Children.Count >= 1) { indexOfCmd = GenerateXmlNode(xmlHelper, mEx.Children, i + 1 + indexOfCmd); indexOfCmd = indexOfCmd - i - 1; } } } #endregion #region if结束 else if (iNum == (int)MethodNameEnum.ifEnd) { xmlHelper.CreateIfEndXmlNode(i + 1 + indexOfCmd, mEx.strIndex); } #endregion #region else开始 else if (iNum == (int)MethodNameEnum.elseStart) { IfElseProperty ifElseProperty = mEx.control as IfElseProperty; if (ifElseProperty != null) { if (mEx.Children.Count >= 1) { ifElseProperty.methodIfElse.endIndex = mEx.Children[mEx.Children.Count - 1].strIndex; } xmlHelper.CreateIfStartXmlNode(i + 1 + indexOfCmd, ifElseProperty.methodIfElse, mEx); //访问循环内的命令集合 if (mEx.Children.Count >= 1) { indexOfCmd = GenerateXmlNode(xmlHelper, mEx.Children, i + 1 + indexOfCmd); indexOfCmd = indexOfCmd - i - 1; } } else { MethodIfElse methodIfElse = new MethodIfElse(); methodIfElse.label = mEx.method_name; methodIfElse.name = mEx.method_name; methodIfElse.strIndex = mEx.strIndex; if (mEx.Children.Count >= 1) { methodIfElse.endIndex = mEx.Children[mEx.Children.Count - 1].strIndex; } methodIfElse.status = (mEx.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateIfStartXmlNode(i + 1 + indexOfCmd, methodIfElse, mEx); //访问循环内的命令集合 if (mEx.Children.Count >= 1) { indexOfCmd = GenerateXmlNode(xmlHelper, mEx.Children, i + 1 + indexOfCmd); indexOfCmd = indexOfCmd - i - 1; } } } #endregion #region else结束 else if (iNum == (int)MethodNameEnum.elseEnd) { xmlHelper.CreateElseEndXmlNode(i + 1 + indexOfCmd, mEx.strIndex); } #endregion #region 计时器 else if (iNum == (int)MethodNameEnum.timerSet) { TimerProperty gtp = mEx.control as TimerProperty; if (gtp != null) { xmlHelper.CreateTimerXmlNode(i + 1 + indexOfCmd, gtp.methodTimer, mEx); } else { MethodTimer methodTimer = new MethodTimer(); methodTimer.label = mEx.method_name; methodTimer.name = mEx.method_name; methodTimer.strIndex = mEx.strIndex; methodTimer.status = (mEx.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateTimerXmlNode(i + 1 + indexOfCmd, methodTimer, mEx); } } #endregion #region 等待 else if (iNum == (int)MethodNameEnum.waitFor) { WaitforProperty gtp = mEx.control as WaitforProperty; if (gtp != null) { xmlHelper.CreateWaitForXmlNode(i + 1 + indexOfCmd, gtp.methodWaitFor, mEx); } else { MethodWaitFor methodWaitFor = new MethodWaitFor(); methodWaitFor.label = mEx.method_name; methodWaitFor.name = mEx.method_name; methodWaitFor.strIndex = mEx.strIndex; methodWaitFor.status = (mEx.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateWaitForXmlNode(i + 1 + indexOfCmd, methodWaitFor, mEx); } } #endregion #region 泵加液 else if (iNum == (int)MethodNameEnum.pumpDispense) { PumpDispenseProperty fp = mEx.control as PumpDispenseProperty; if (fp != null) { xmlHelper.CreatePumpDispenseXmlNode(i + 1 + indexOfCmd, fp.methodPumpDispese, mEx); //访问循环内的命令集合 if (mEx.Children.Count >= 1) { indexOfCmd = GenerateXmlNode(xmlHelper, mEx.Children, i + 1 + indexOfCmd); indexOfCmd = indexOfCmd - i; } } else { MethodPumpDispese methodPumpDispese = new MethodPumpDispese(); methodPumpDispese.label = mEx.method_name; methodPumpDispese.name = mEx.method_name; methodPumpDispese.strIndex = mEx.strIndex; methodPumpDispese.status = (mEx.isEnabled == true ? "enable" : "disable"); xmlHelper.CreatePumpDispenseXmlNode(i + 1 + indexOfCmd, methodPumpDispese, mEx); //访问循环内的命令集合 if (mEx.Children.Count >= 1) { indexOfCmd = GenerateXmlNode(xmlHelper, mEx.Children, i + 1 + indexOfCmd); indexOfCmd = indexOfCmd - i; } } } #endregion #region 振荡化学 else if (iNum == (int)MethodNameEnum.shaker) { ShakeProperty fp = mEx.control as ShakeProperty; if (fp != null) { xmlHelper.CreateShakeXmlNode(i + 1 + indexOfCmd, fp.methodShake, mEx); //访问循环内的命令集合 if (mEx.Children.Count >= 1) { indexOfCmd = GenerateXmlNode(xmlHelper, mEx.Children, i + 1 + indexOfCmd); indexOfCmd = indexOfCmd - i; } } else { MethodShake methodShake = new MethodShake(); methodShake.label = mEx.method_name; methodShake.name = mEx.method_name; methodShake.strIndex = mEx.strIndex; methodShake.status = (mEx.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateShakeXmlNode(i + 1 + indexOfCmd, methodShake, mEx); //访问循环内的命令集合 if (mEx.Children.Count >= 1) { indexOfCmd = GenerateXmlNode(xmlHelper, mEx.Children, i + 1 + indexOfCmd); indexOfCmd = indexOfCmd - i; } } } #endregion #region 开关盖 else if (iNum == (int)MethodNameEnum.switchLid) { SwitchLidProperty fp = mEx.control as SwitchLidProperty; if (fp != null) { xmlHelper.CreateSwitchLidXmlNode(i + 1 + indexOfCmd, fp.methodSwitchLid, mEx); //访问循环内的命令集合 if (mEx.Children.Count >= 1) { indexOfCmd = GenerateXmlNode(xmlHelper, mEx.Children, i + 1 + indexOfCmd); indexOfCmd = indexOfCmd - i; } } else { MethodSwitchLid methodSwitchLid = new MethodSwitchLid(); methodSwitchLid.label = mEx.method_name; methodSwitchLid.name = mEx.method_name; methodSwitchLid.strIndex = mEx.strIndex; methodSwitchLid.status = (mEx.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateSwitchLidXmlNode(i + 1 + indexOfCmd, methodSwitchLid, mEx); //访问循环内的命令集合 if (mEx.Children.Count >= 1) { indexOfCmd = GenerateXmlNode(xmlHelper, mEx.Children, i + 1 + indexOfCmd); indexOfCmd = indexOfCmd - i; } } } #endregion #region 文件开关盖移液 else if (iNum == (int)MethodNameEnum.fileMoveLiquid) { FileMoveLiquidProperty fp = mEx.control as FileMoveLiquidProperty; if (fp != null) { xmlHelper.CreateFileMoveLiquidXmlNode(i + 1 + indexOfCmd, fp.methodFileMoveLiquid, mEx); //访问循环内的命令集合 if (mEx.Children.Count >= 1) { indexOfCmd = GenerateXmlNode(xmlHelper, mEx.Children, i + 1 + indexOfCmd); indexOfCmd = indexOfCmd - i; } } else { MethodFileMoveLiquid methodFileMoveLiquid = new MethodFileMoveLiquid(); methodFileMoveLiquid.label = mEx.method_name; methodFileMoveLiquid.name = mEx.method_name; methodFileMoveLiquid.strIndex = mEx.strIndex; methodFileMoveLiquid.status = (mEx.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateFileMoveLiquidXmlNode(i + 1 + indexOfCmd, methodFileMoveLiquid, mEx); //访问循环内的命令集合 if (mEx.Children.Count >= 1) { indexOfCmd = GenerateXmlNode(xmlHelper, mEx.Children, i + 1 + indexOfCmd); indexOfCmd = indexOfCmd - i; } } } #endregion #region 文件转板 else if (iNum == (int)MethodNameEnum.fileMoveLabware) { FileMoveLabwareProperty fp = mEx.control as FileMoveLabwareProperty; if (fp != null) { xmlHelper.CreateFileMoveLabwareXmlNode(i + 1 + indexOfCmd, fp.methodFileMoveLabware, mEx); //访问循环内的命令集合 if (mEx.Children.Count >= 1) { indexOfCmd = GenerateXmlNode(xmlHelper, mEx.Children, i + 1 + indexOfCmd); indexOfCmd = indexOfCmd - i; } } else { MethodFileMoveLabware methodFileMoveLabware = new MethodFileMoveLabware(); methodFileMoveLabware.label = mEx.method_name; methodFileMoveLabware.name = mEx.method_name; methodFileMoveLabware.strIndex = mEx.strIndex; methodFileMoveLabware.status = (mEx.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateFileMoveLabwareXmlNode(i + 1 + indexOfCmd, methodFileMoveLabware, mEx); //访问循环内的命令集合 if (mEx.Children.Count >= 1) { indexOfCmd = GenerateXmlNode(xmlHelper, mEx.Children, i + 1 + indexOfCmd); indexOfCmd = indexOfCmd - i; } } } #endregion #region 子方法 else if (iNum == (int)MethodNameEnum.subMethod) { SubMethodProperty fp = mEx.control as SubMethodProperty; if (fp != null) { xmlHelper.CreateSubMethodXmlNode(i + 1 + indexOfCmd, fp.MethodSubMethod, mEx); //访问循环内的命令集合 if (mEx.Children.Count >= 1) { indexOfCmd = GenerateXmlNode(xmlHelper, mEx.Children, i + 1 + indexOfCmd); indexOfCmd = indexOfCmd - i; } } else { MethodSubMethod methodSubMethod = new MethodSubMethod(); methodSubMethod.label = mEx.method_name; methodSubMethod.name = mEx.method_name; methodSubMethod.strIndex = mEx.strIndex; methodSubMethod.status = (mEx.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateSubMethodXmlNode(i + 1 + indexOfCmd, methodSubMethod, mEx); //访问循环内的命令集合 if (mEx.Children.Count >= 1) { indexOfCmd = GenerateXmlNode(xmlHelper, mEx.Children, i + 1 + indexOfCmd); indexOfCmd = indexOfCmd - i; } } } #endregion #region 变量计算 else if (iNum == (int)MethodNameEnum.varCalc) { VariableCaculationProperty fp = mEx.control as VariableCaculationProperty; if (fp != null) { xmlHelper.CreateVarCalcXmlNode(i + 1 + indexOfCmd, fp.methodVarCalc, mEx); //访问循环内的命令集合 if (mEx.Children.Count >= 1) { indexOfCmd = GenerateXmlNode(xmlHelper, mEx.Children, i + 1 + indexOfCmd); indexOfCmd = indexOfCmd - i; } } else { MethodVarCalc methodVarCalc = new MethodVarCalc(); methodVarCalc.label = mEx.method_name; methodVarCalc.name = mEx.method_name; methodVarCalc.strIndex = mEx.strIndex; methodVarCalc.status = (mEx.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateVarCalcXmlNode(i + 1 + indexOfCmd, methodVarCalc, mEx); //访问循环内的命令集合 if (mEx.Children.Count >= 1) { indexOfCmd = GenerateXmlNode(xmlHelper, mEx.Children, i + 1 + indexOfCmd); indexOfCmd = indexOfCmd - i; } } } #endregion #region 文件切胶 else if (iNum == (int)MethodNameEnum.cutGum) { FileElectroProperty fp = mEx.control as FileElectroProperty; if (fp != null) { xmlHelper.CreateFileElectroCutGumXmlNode(i + 1 + indexOfCmd, fp.methodElectroFile, mEx); //访问循环内的命令集合 if (mEx.Children.Count >= 1) { indexOfCmd = GenerateXmlNode(xmlHelper, mEx.Children, i + 1 + indexOfCmd); indexOfCmd = indexOfCmd - i; } } else { MethodElectroFile methodElectroFile = new MethodElectroFile(); methodElectroFile.label = mEx.method_name; methodElectroFile.name = mEx.method_name; methodElectroFile.strIndex = mEx.strIndex; methodElectroFile.status = (mEx.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateFileElectroCutGumXmlNode(i + 1 + indexOfCmd, methodElectroFile, mEx); //访问循环内的命令集合 if (mEx.Children.Count >= 1) { indexOfCmd = GenerateXmlNode(xmlHelper, mEx.Children, i + 1 + indexOfCmd); indexOfCmd = indexOfCmd - i; } } } #endregion } } } catch (Exception ex) { LoggerHelper.ErrorLog("ERROR:", ex); } //重新给method节点排序 XmlNodeList xmlNodeMethodList = xmlHelper.xmlDoc.SelectNodes("root/method"); for (int i = 1; i <= xmlNodeMethodList.Count; i++) { if (i >= 2) { xmlNodeMethodList[i - 1].Attributes["id"].Value = (i + 1).ToString(); } else { xmlNodeMethodList[i - 1].Attributes["id"].Value = i.ToString(); } } return xmlHelper.xmlDoc; } #endregion public int GenerateXmlNode(XmlHelper xmlHelper, ObservableCollection methodExes, int count) { count++;//当前索引 try { int currId = 0; for (int i = 0; i < methodExes.Count; i++) { currId = i + count; MethodEx mi = methodExes[i]; // 获取方法编号 int iNum = methodListBll.getNumByMethodName(mi.method_content); #region aspirate if (iNum == (int)MethodNameEnum.aspirate) { AspirateProperty ap = mi.control as AspirateProperty; if (ap != null) { //ap.methodAspirate.channels = ap.tipsChannel.SelectedChannels.ToArray(); ap.methodAspirate.strIndex = mi.strIndex; xmlHelper.CreateAspirateXmlNode(currId, ap.methodAspirate, mi); } else { MethodAspirate methodAspirate = new MethodAspirate(); methodAspirate.label = mi.method_name; methodAspirate.name = mi.method_name; methodAspirate.strIndex = mi.strIndex; methodAspirate.status = (mi.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateAspirateXmlNode(currId, methodAspirate, mi); } } #endregion #region dispense else if (iNum == (int)MethodNameEnum.dispense) { DispenseProperty dp = mi.control as DispenseProperty; if (dp != null) { dp.methodDispense.strIndex = mi.strIndex; xmlHelper.CreateDispenseXmlNode(currId, dp.methodDispense, mi); } else { MethodDispense methodDispense = new MethodDispense(); methodDispense.label = mi.method_name; methodDispense.name = mi.method_name; methodDispense.strIndex = mi.strIndex; methodDispense.status = (mi.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateDispenseXmlNode(currId, methodDispense, mi); } } #endregion #region loadtips else if (iNum == (int)MethodNameEnum.loadtips) { LoadTipsProperty lp = mi.control as LoadTipsProperty; // 更新界面中未触发更新的 if (lp != null) { //lp.methodLoadTips.channels = lp.tipsChannel.SelectedChannels.ToArray(); lp.methodLoadTips.strIndex = mi.strIndex; xmlHelper.CreateLoadTipsXmlNode(currId, lp.methodLoadTips, mi); } else { MethodLoadTips methodLoadTips = new MethodLoadTips(); methodLoadTips.label = mi.method_name; methodLoadTips.name = mi.method_name; methodLoadTips.strIndex = mi.strIndex; methodLoadTips.status = (mi.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateLoadTipsXmlNode(currId, methodLoadTips, mi); } } #endregion #region unloadtips else if (iNum == (int)MethodNameEnum.unloadtips) { UnLoadTipsProperty ulp = mi.control as UnLoadTipsProperty; if (ulp != null) { //ulp.methodUnLoadTips.channels = ulp.tipsChannel.SelectedChannels.ToArray(); ulp.methodUnLoadTips.strIndex = mi.strIndex; xmlHelper.CreateUnloadTipsXmlNode(currId, ulp.methodUnLoadTips, mi); } else { MethodUnloadTips methodUnLoadTips = new MethodUnloadTips(); methodUnLoadTips.label = mi.method_name; methodUnLoadTips.name = mi.method_name; methodUnLoadTips.strIndex = mi.strIndex; methodUnLoadTips.status = (mi.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateUnloadTipsXmlNode(currId, methodUnLoadTips, mi); } } #endregion #region mixing else if (iNum == (int)MethodNameEnum.mixing) { MixProperty mp = mi.control as MixProperty; if (mp != null) { //mp.methodMix.channels = mp.tipsChannel.SelectedChannels.ToArray(); xmlHelper.CreateMixingXmlNode(currId, mp.methodMix, mi); } else { MethodMixing methodMixing = new MethodMixing(); methodMixing.label = mi.method_name; methodMixing.name = mi.method_name; methodMixing.strIndex = mi.strIndex; methodMixing.status = (mi.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateMixingXmlNode(currId, methodMixing, mi); } } #endregion #region griptransport else if (iNum == (int)MethodNameEnum.griptransport) { GripTransportProperty gtp = mi.control as GripTransportProperty; if (gtp != null) { xmlHelper.CreateGripTransportXmlNode(currId, gtp.methodGripTransport, mi); } else { MethodGripTransport methodGripTransport = new MethodGripTransport(); methodGripTransport.label = mi.method_name; methodGripTransport.name = mi.method_name; methodGripTransport.strIndex = mi.strIndex; methodGripTransport.status = (mi.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateGripTransportXmlNode(currId, methodGripTransport, mi); } } #endregion #region gripmove else if (iNum == (int)MethodNameEnum.gripmove) { GripMoveProperty gtp = mi.control as GripMoveProperty; if (gtp != null) { xmlHelper.CreateGripMoveXmlNode(currId, gtp.methodGripMove, mi); } else { MethodGripMove methodGripMove = new MethodGripMove(); methodGripMove.label = mi.method_name; methodGripMove.name = mi.method_name; methodGripMove.strIndex = mi.strIndex; methodGripMove.status = (mi.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateGripMoveXmlNode(currId, methodGripMove, mi); } } #endregion #region holdingLabware else if (iNum == (int)MethodNameEnum.holdingLabware) { BeginHoldingLabwareProperty fp = mi.control as BeginHoldingLabwareProperty; if (fp != null) { xmlHelper.CreateBeginHoldingLabwareXmlNode(currId, fp.methodHoldingLabware, mi); //访问循环内的命令集合 if (mi.Children.Count >= 1) { count = GenerateXmlNode(xmlHelper, mi.Children, count + i); } } else { MethodHoldingLabware methodHoldingLabware = new MethodHoldingLabware(); methodHoldingLabware.label = mi.method_name; methodHoldingLabware.name = mi.method_name; methodHoldingLabware.strIndex = mi.strIndex; methodHoldingLabware.status = (mi.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateBeginHoldingLabwareXmlNode(currId, methodHoldingLabware, mi); //访问循环内的命令集合 if (mi.Children.Count >= 1) { count = GenerateXmlNode(xmlHelper, mi.Children, count + i); } } } #endregion #region endHoldingLabware else if (iNum == (int)MethodNameEnum.endHoldingLabware) { EndHoldingLabwareProperty fp = mi.control as EndHoldingLabwareProperty; if (fp != null) { xmlHelper.CreateEndHoldingLabwareXmlNode(currId, fp.methodHoldingLabware, mi); } else { MethodHoldingLabware methodHoldingLabware = new MethodHoldingLabware(); methodHoldingLabware.label = mi.method_name; methodHoldingLabware.name = mi.method_name; methodHoldingLabware.strIndex = mi.strIndex; methodHoldingLabware.status = (mi.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateEndHoldingLabwareXmlNode(currId, methodHoldingLabware, mi); } } #endregion #region pause else if (iNum == (int)MethodNameEnum.pause) { PauseProperty gtp = mi.control as PauseProperty; if (gtp != null) { xmlHelper.CreatePauseMoveXmlNode(currId, gtp.methodPauseMove, mi); } else { MethodPauseMove methodPauseMove = new MethodPauseMove(); methodPauseMove.label = mi.method_name; methodPauseMove.name = mi.method_name; methodPauseMove.strIndex = mi.strIndex; methodPauseMove.status = (mi.isEnabled == true ? "enable" : "disable"); xmlHelper.CreatePauseMoveXmlNode(currId, methodPauseMove, mi); } } #endregion #region end else if (iNum == (int)MethodNameEnum.end) { EndProperty endProperty = mi.control as EndProperty; endProperty.methodEnd.strIndex = mi.strIndex; xmlHelper.CreateEndXmlNode(currId, endProperty.methodEnd, mi); } #endregion #region loop else if (iNum == (int)MethodNameEnum.loop) { LoopProperty loopProperty = mi.control as LoopProperty; if (loopProperty != null) { if (mi.Children.Count >= 1) { loopProperty.methodLoop.endIndex = mi.Children[mi.Children.Count - 1].strIndex; } xmlHelper.CreateLoopXmlNode(currId, loopProperty.methodLoop, mi); //访问循环内的命令集合 if (mi.Children.Count >= 1) { count = GenerateXmlNode(xmlHelper, mi.Children, currId); } } else { MethodLoop methodLoop = new MethodLoop(); methodLoop.label = mi.method_name; methodLoop.name = mi.method_name; methodLoop.strIndex = mi.strIndex; if (mi.Children.Count >= 1) { methodLoop.endIndex = mi.Children[mi.Children.Count - 1].strIndex; } methodLoop.status = (mi.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateLoopXmlNode(currId, methodLoop, mi); //访问循环内的命令集合 if (mi.Children.Count >= 1) { count = GenerateXmlNode(xmlHelper, mi.Children, currId); } } } #endregion #region endloop else if (iNum == (int)MethodNameEnum.endloop) { xmlHelper.CreateEndLoopXmlNode(currId, mi.strIndex); } #endregion #region transferfile else if (iNum == (int)MethodNameEnum.transferfile) { FileProperty fp = mi.control as FileProperty; if (fp != null) { xmlHelper.CreateTransferFileXmlNode(currId, fp.methodTransferFile, mi); } else { MethodTransferFile methodTransferFile = new MethodTransferFile(); methodTransferFile.label = mi.method_name; methodTransferFile.name = mi.method_name; methodTransferFile.strIndex = mi.strIndex; methodTransferFile.status = (mi.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateTransferFileXmlNode(currId, methodTransferFile, mi); } } #endregion #region home else if (iNum == (int)MethodNameEnum.home) { ResetProperty fp = mi.control as ResetProperty; if (fp != null) { xmlHelper.CreateHomeXmlNode(currId, fp.methodHome, mi); } else { MethodHome methodHome = new MethodHome(); methodHome.label = mi.method_name; methodHome.name = mi.method_name; methodHome.strIndex = mi.strIndex; methodHome.status = (mi.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateHomeXmlNode(currId, methodHome, mi); } } #endregion #region remark else if (iNum == (int)MethodNameEnum.remark) { CommentProperty fp = mi.control as CommentProperty; if (fp != null) { xmlHelper.CreateRemarkXmlNode(currId, fp.methodRemark, mi); } else { MethodRemark methodRemark = new MethodRemark(); methodRemark.label = mi.method_name; methodRemark.name = mi.method_name; methodRemark.strIndex = mi.strIndex; methodRemark.status = (mi.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateRemarkXmlNode(currId, methodRemark, mi); } } #endregion #region dataimport else if (iNum == (int)MethodNameEnum.dataimport) { DataImportProperty fp = mi.control as DataImportProperty; if (fp != null) { xmlHelper.CreateDataImportXmlNode(currId, fp.methodDataImport, mi); } else { MethodDataImport methodDataImport = new MethodDataImport(); methodDataImport.label = mi.method_name; methodDataImport.name = mi.method_name; methodDataImport.strIndex = mi.strIndex; methodDataImport.status = (mi.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateDataImportXmlNode(currId, methodDataImport, mi); } } #endregion #region dataexport else if (iNum == (int)MethodNameEnum.dataexport) { DataExportProperty fp = mi.control as DataExportProperty; if (fp != null) { xmlHelper.CreateDataExportXmlNode(currId, fp.methodDataExport, mi); } else { MethodDataExport methodDataExport = new MethodDataExport(); methodDataExport.label = mi.method_name; methodDataExport.name = mi.method_name; methodDataExport.strIndex = mi.strIndex; methodDataExport.status = (mi.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateDataExportXmlNode(currId, methodDataExport, mi); } } #endregion #region group else if (iNum == (int)MethodNameEnum.group) { GroupProperty fp = mi.control as GroupProperty; if (fp != null) { xmlHelper.CreateGroupXmlNode(currId, fp.methodGroup, mi); //访问循环内的命令集合 if (mi.Children.Count >= 1) { count = GenerateXmlNode(xmlHelper, mi.Children, count + i); } } else { MethodCombination methodCombination = new MethodCombination(); methodCombination.label = mi.method_name; methodCombination.name = mi.method_name; methodCombination.strIndex = mi.strIndex; methodCombination.status = (mi.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateGroupXmlNode(currId, methodCombination, mi); //访问循环内的命令集合 if (mi.Children.Count >= 1) { count = GenerateXmlNode(xmlHelper, mi.Children, count + i); } } } #endregion #region endgroup else if (iNum == (int)MethodNameEnum.endgroup) { xmlHelper.CreateEndGroupXmlNode(currId, mi.strIndex); } #endregion #region takephoto else if (iNum == (int)MethodNameEnum.takephoto) { if (Shared.SoftwareInformation.software_device_number.Equals(DeviceCategory.DeviceHXELEC)) { CaptureElectroProperty fp = mi.control as CaptureElectroProperty; if (fp != null) { xmlHelper.CreateTakePhotoForElectroXmlNode(currId, fp.methodTakePhotoForElectro, mi); // 访问循环内的命令集合 if (mi.Children.Count >= 1) { count = GenerateXmlNode(xmlHelper, mi.Children, count + i); } } else { MethodTakePhotoForElectro methodTakePhotoForElectro = new MethodTakePhotoForElectro(); methodTakePhotoForElectro.label = mi.method_name; methodTakePhotoForElectro.name = mi.method_name; methodTakePhotoForElectro.strIndex = mi.strIndex; methodTakePhotoForElectro.status = (mi.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateTakePhotoForElectroXmlNode(currId, methodTakePhotoForElectro, mi); //访问循环内的命令集合 if (mi.Children.Count >= 1) { count = GenerateXmlNode(xmlHelper, mi.Children, count + i); } } } else { CaptureProperty fp = mi.control as CaptureProperty; if (fp != null) { xmlHelper.CreateTakePhotoXmlNode(currId, fp.methodTakePhoto, mi); // 访问循环内的命令集合 if (mi.Children.Count >= 1) { count = GenerateXmlNode(xmlHelper, mi.Children, count + i); } } else { MethodTakePhoto methodTakePhoto = new MethodTakePhoto(); methodTakePhoto.label = mi.method_name; methodTakePhoto.name = mi.method_name; methodTakePhoto.strIndex = mi.strIndex; methodTakePhoto.status = (mi.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateTakePhotoXmlNode(currId, methodTakePhoto, mi); //访问循环内的命令集合 if (mi.Children.Count >= 1) { count = GenerateXmlNode(xmlHelper, mi.Children, count + i); } } } } #endregion #region choice else if (iNum == (int)MethodNameEnum.choice) { PickProperty fp = mi.control as PickProperty; if (fp != null) { xmlHelper.CreateChoiceXmlNode(currId, fp.methodChoice, mi); //访问循环内的命令集合 if (mi.Children.Count >= 1) { count = GenerateXmlNode(xmlHelper, mi.Children, count + i); } } else { MethodChoice methodChoice = new MethodChoice(); methodChoice.label = mi.method_name; methodChoice.name = mi.method_name; methodChoice.strIndex = mi.strIndex; methodChoice.status = (mi.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateChoiceXmlNode(currId, methodChoice, mi); //访问循环内的命令集合 if (mi.Children.Count >= 1) { count = GenerateXmlNode(xmlHelper, mi.Children, count + i); } } } #endregion #region coating else if (iNum == (int)MethodNameEnum.coating) { CoatingProperty fp = mi.control as CoatingProperty; if (fp != null) { xmlHelper.CreateCoatingXmlNode(currId, fp.methodCoating, mi); //访问循环内的命令集合 if (mi.Children.Count >= 1) { count = GenerateXmlNode(xmlHelper, mi.Children, count + i); } } else { MethodCoating methodCoating = new MethodCoating(); methodCoating.label = mi.method_name; methodCoating.name = mi.method_name; methodCoating.strIndex = mi.strIndex; methodCoating.status = (mi.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateCoatingXmlNode(currId, methodCoating, mi); //访问循环内的命令集合 if (mi.Children.Count >= 1) { count = GenerateXmlNode(xmlHelper, mi.Children, count + i); } } } #endregion #region coatingfile else if (iNum == (int)MethodNameEnum.coatingfile) { FileCoatingProperty fp = mi.control as FileCoatingProperty; if (fp != null) { xmlHelper.CreateCoatingFileXmlNode(currId, fp.methodCoatingFile, mi); //访问循环内的命令集合 if (mi.Children.Count >= 1) { count = GenerateXmlNode(xmlHelper, mi.Children, count + i); } } else { MethodCoatingFile methodCoatingFile = new MethodCoatingFile(); methodCoatingFile.label = mi.method_name; methodCoatingFile.name = mi.method_name; methodCoatingFile.strIndex = mi.strIndex; methodCoatingFile.status = (mi.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateCoatingFileXmlNode(currId, methodCoatingFile, mi); //访问循环内的命令集合 if (mi.Children.Count >= 1) { count = GenerateXmlNode(xmlHelper, mi.Children, count + i); } } } #endregion #region coatingReport else if (iNum == (int)MethodNameEnum.coatingReport) { CoatingFileExportProperty fp = mi.control as CoatingFileExportProperty; if (fp != null) { xmlHelper.CreateCoatingReportXmlNode(currId, fp.methodCoatingReport, mi); //访问循环内的命令集合 if (mi.Children.Count >= 1) { count = GenerateXmlNode(xmlHelper, mi.Children, count + i); } } else { MethodCoatingReport methodCoatingReport = new MethodCoatingReport(); methodCoatingReport.label = mi.method_name; methodCoatingReport.name = mi.method_name; methodCoatingReport.strIndex = mi.strIndex; methodCoatingReport.status = (mi.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateCoatingReportXmlNode(currId, methodCoatingReport, mi); //访问循环内的命令集合 if (mi.Children.Count >= 1) { count = GenerateXmlNode(xmlHelper, mi.Children, count + i); } } } #endregion #region ultrasonic else if (iNum == (int)MethodNameEnum.ultrasonic) { UltrasonicProperty fp = mi.control as UltrasonicProperty; if (fp != null) { xmlHelper.CreateUltrasonicXmlNode(currId, fp.methodUltrasonic, mi); //访问循环内的命令集合 if (mi.Children.Count >= 1) { count = GenerateXmlNode(xmlHelper, mi.Children, count + i); } } else { MethodUltrasonic methodUltrasonic = new MethodUltrasonic(); methodUltrasonic.label = mi.method_name; methodUltrasonic.name = mi.method_name; methodUltrasonic.strIndex = mi.strIndex; methodUltrasonic.status = (mi.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateUltrasonicXmlNode(currId, methodUltrasonic, mi); //访问循环内的命令集合 if (mi.Children.Count >= 1) { count = GenerateXmlNode(xmlHelper, mi.Children, count + i); } } } #endregion #region choiceTransfer else if (iNum == (int)MethodNameEnum.choiceTransfer) { PickAndTransferProperty fp = mi.control as PickAndTransferProperty; if (fp != null) { xmlHelper.CreateChoiceAndTransferXmlNode(currId, fp.methodChoice, mi); // 访问循环内的命令集合 if (mi.Children.Count >= 1) { count = GenerateXmlNode(xmlHelper, mi.Children, count + i); } } else { MethodChoiceAndTransfer methodChoice = new MethodChoiceAndTransfer(); methodChoice.label = mi.method_name; methodChoice.name = mi.method_name; methodChoice.strIndex = mi.strIndex; methodChoice.status = (mi.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateChoiceAndTransferXmlNode(currId, methodChoice, mi); //访问循环内的命令集合 if (mi.Children.Count >= 1) { count = GenerateXmlNode(xmlHelper, mi.Children, count + i); } } } #endregion #region coatingTransfer else if (iNum == (int)MethodNameEnum.coatingTransfer) { CoatingAndTransferProperty fp = mi.control as CoatingAndTransferProperty; if (fp != null) { xmlHelper.CreateCoatingAndTransferXmlNode(currId, fp.methodCoating, mi); //访问循环内的命令集合 if (mi.Children.Count >= 1) { count = GenerateXmlNode(xmlHelper, mi.Children, count + i); } } else { MethodCoatingAndTransfer methodCoating = new MethodCoatingAndTransfer(); methodCoating.label = mi.method_name; methodCoating.name = mi.method_name; methodCoating.strIndex = mi.strIndex; methodCoating.status = (mi.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateCoatingAndTransferXmlNode(currId, methodCoating, mi); //访问循环内的命令集合 if (mi.Children.Count >= 1) { count = GenerateXmlNode(xmlHelper, mi.Children, count + i); } } } #endregion #region dilution else if (iNum == (int)MethodNameEnum.dilution) // 梯度稀释 { DilutionProperty fp = mi.control as DilutionProperty; if (fp != null) { xmlHelper.CreateDilutionXmlNode(currId, fp.methodDilution, mi); //访问循环内的命令集合 if (mi.Children.Count >= 1) { count = GenerateXmlNode(xmlHelper, mi.Children, count + i); } } else { MethodDilution methodDilution = new MethodDilution(); methodDilution.label = mi.method_name; methodDilution.name = mi.method_name; methodDilution.strIndex = mi.strIndex; methodDilution.status = (mi.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateDilutionXmlNode(currId, methodDilution, mi); //访问循环内的命令集合 if (mi.Children.Count >= 1) { count = GenerateXmlNode(xmlHelper, mi.Children, count + i); } } } #endregion #region ThirdPart if (mi.method_group_id == EnumManagement.GetEnumValue(MethodGroupEnum.ThirdPart))// 第三方设备 { ThirdPartPropertySocketProperty fp = mi.control as ThirdPartPropertySocketProperty; if (fp != null) { xmlHelper.CreateThirdPartXmlNode(currId, fp.methodProperty, mi); //访问循环内的命令集合 if (mi.Children.Count >= 1) { count = GenerateXmlNode(xmlHelper, mi.Children, count + i); } } else { MethodThirdPart methodThirdPart = new MethodThirdPart(); methodThirdPart.label = mi.method_name; methodThirdPart.name = mi.method_name; methodThirdPart.strIndex = mi.strIndex; methodThirdPart.status = (mi.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateThirdPartXmlNode(currId, methodThirdPart, mi); //访问循环内的命令集合 if (mi.Children.Count >= 1) { count = GenerateXmlNode(xmlHelper, mi.Children, count + i); } } } #endregion #region SetVariable else if (iNum == (int)MethodNameEnum.setVariable) { SetVariableProperty gtp = mi.control as SetVariableProperty; if (gtp != null) { xmlHelper.CreateSetVariableXmlNode(currId, gtp.methodSetVariable, mi); } else { MethodSetVariable methodSetVariable = new MethodSetVariable(); methodSetVariable.label = mi.method_name; methodSetVariable.name = mi.method_name; methodSetVariable.strIndex = mi.strIndex; methodSetVariable.status = (mi.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateSetVariableXmlNode(currId, methodSetVariable, mi); } } #endregion #region VariableCalculation else if (iNum == (int)MethodNameEnum.varCalc) { VariableCaculationProperty gtp = mi.control as VariableCaculationProperty; if (gtp != null) { xmlHelper.CreateVarCalcXmlNode(currId, gtp.methodVarCalc, mi); } else { MethodVarCalc methodVarCalc = new MethodVarCalc(); methodVarCalc.label = mi.method_name; methodVarCalc.name = mi.method_name; methodVarCalc.strIndex = mi.strIndex; methodVarCalc.status = (mi.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateVarCalcXmlNode(currId, methodVarCalc, mi); } } #endregion #region VariableImport else if (iNum == (int)MethodNameEnum.setVariable) { VariableImportProperty gtp = mi.control as VariableImportProperty; if (gtp != null) { xmlHelper.CreateVariableImportXmlNode(currId, gtp.methodVariableImport, mi); } else { MethodVariableImport methodVariableImport = new MethodVariableImport(); methodVariableImport.label = mi.method_name; methodVariableImport.name = mi.method_name; methodVariableImport.strIndex = mi.strIndex; methodVariableImport.status = (mi.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateVariableImportXmlNode(currId, methodVariableImport, mi); } } #endregion #region SetVariable else if (iNum == (int)MethodNameEnum.subMethod) { SubMethodProperty gtp = mi.control as SubMethodProperty; if (gtp != null) { xmlHelper.CreateSubMethodXmlNode(currId, gtp.MethodSubMethod, mi); } else { MethodSubMethod methodSubMethod = new MethodSubMethod(); methodSubMethod.label = mi.method_name; methodSubMethod.name = mi.method_name; methodSubMethod.strIndex = mi.strIndex; methodSubMethod.status = (mi.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateSubMethodXmlNode(currId, methodSubMethod, mi); } } #endregion #region ifStart else if (iNum == (int)MethodNameEnum.ifStart) { IfElseProperty ifElseProperty = mi.control as IfElseProperty; if (ifElseProperty != null) { if (mi.Children.Count >= 1) { ifElseProperty.methodIfElse.endIndex = mi.Children[mi.Children.Count - 1].strIndex; } xmlHelper.CreateIfStartXmlNode(currId, ifElseProperty.methodIfElse, mi); //访问循环内的命令集合 if (mi.Children.Count >= 1) { count = GenerateXmlNode(xmlHelper, mi.Children, currId); } } else { MethodIfElse methodIfElse = new MethodIfElse(); methodIfElse.label = mi.method_name; methodIfElse.name = mi.method_name; methodIfElse.strIndex = mi.strIndex; if (mi.Children.Count >= 1) { methodIfElse.endIndex = mi.Children[mi.Children.Count - 1].strIndex; } methodIfElse.status = (mi.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateIfStartXmlNode(currId, methodIfElse, mi); //访问循环内的命令集合 if (mi.Children.Count >= 1) { count = GenerateXmlNode(xmlHelper, mi.Children, currId); } } } #endregion #region ifend else if (iNum == (int)MethodNameEnum.ifEnd) { xmlHelper.CreateIfEndXmlNode(currId, mi.strIndex); } #endregion #region ifStart else if (iNum == (int)MethodNameEnum.elseStart) { IfElseProperty ifElseProperty = mi.control as IfElseProperty; if (ifElseProperty != null) { if (mi.Children.Count >= 1) { ifElseProperty.methodIfElse.endIndex = mi.Children[mi.Children.Count - 1].strIndex; } xmlHelper.CreateIfStartXmlNode(currId, ifElseProperty.methodIfElse, mi); //访问循环内的命令集合 if (mi.Children.Count >= 1) { count = GenerateXmlNode(xmlHelper, mi.Children, currId); } } else { MethodIfElse methodIfElse = new MethodIfElse(); methodIfElse.label = mi.method_name; methodIfElse.name = mi.method_name; methodIfElse.strIndex = mi.strIndex; if (mi.Children.Count >= 1) { methodIfElse.endIndex = mi.Children[mi.Children.Count - 1].strIndex; } methodIfElse.status = (mi.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateIfStartXmlNode(currId, methodIfElse, mi); //访问循环内的命令集合 if (mi.Children.Count >= 1) { count = GenerateXmlNode(xmlHelper, mi.Children, currId); } } } #endregion #region ifend else if (iNum == (int)MethodNameEnum.elseEnd) { xmlHelper.CreateElseEndXmlNode(currId, mi.strIndex); } #endregion #region timer else if (iNum == (int)MethodNameEnum.timerSet) { TimerProperty gtp = mi.control as TimerProperty; if (gtp != null) { xmlHelper.CreateTimerXmlNode(currId, gtp.methodTimer, mi); } else { MethodTimer methodTimer = new MethodTimer(); methodTimer.label = mi.method_name; methodTimer.name = mi.method_name; methodTimer.strIndex = mi.strIndex; methodTimer.status = (mi.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateTimerXmlNode(currId, methodTimer, mi); } } #endregion #region waitfor else if (iNum == (int)MethodNameEnum.waitFor) { WaitforProperty gtp = mi.control as WaitforProperty; if (gtp != null) { xmlHelper.CreateWaitForXmlNode(currId, gtp.methodWaitFor, mi); } else { MethodWaitFor methodWaitFor = new MethodWaitFor(); methodWaitFor.label = mi.method_name; methodWaitFor.name = mi.method_name; methodWaitFor.strIndex = mi.strIndex; methodWaitFor.status = (mi.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateWaitForXmlNode(currId, methodWaitFor, mi); } } #endregion #region pumpDispense if (iNum == (int)MethodNameEnum.pumpDispense) { PumpDispenseProperty ap = mi.control as PumpDispenseProperty; if (ap != null) { //ap.methodAspirate.channels = ap.tipsChannel.SelectedChannels.ToArray(); ap.methodPumpDispese.strIndex = mi.strIndex; xmlHelper.CreatePumpDispenseXmlNode(currId, ap.methodPumpDispese, mi); } else { MethodPumpDispese methodPumpDispese = new MethodPumpDispese(); methodPumpDispese.label = mi.method_name; methodPumpDispese.name = mi.method_name; methodPumpDispese.strIndex = mi.strIndex; methodPumpDispese.status = (mi.isEnabled == true ? "enable" : "disable"); xmlHelper.CreatePumpDispenseXmlNode(currId, methodPumpDispese, mi); } } #endregion #region shake chemistry if (iNum == (int)MethodNameEnum.shaker) { ShakeProperty ap = mi.control as ShakeProperty; if (ap != null) { ap.methodShake.strIndex = mi.strIndex; xmlHelper.CreateShakeXmlNode(currId, ap.methodShake, mi); } else { MethodShake methodShake = new MethodShake(); methodShake.label = mi.method_name; methodShake.name = mi.method_name; methodShake.strIndex = mi.strIndex; methodShake.status = (mi.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateShakeXmlNode(currId, methodShake, mi); } } #endregion #region switch Lid if (iNum == (int)MethodNameEnum.switchLid) { SwitchLidProperty ap = mi.control as SwitchLidProperty; if (ap != null) { ap.methodSwitchLid.strIndex = mi.strIndex; xmlHelper.CreateSwitchLidXmlNode(currId, ap.methodSwitchLid, mi); } else { MethodSwitchLid methodSwitchLid = new MethodSwitchLid(); methodSwitchLid.label = mi.method_name; methodSwitchLid.name = mi.method_name; methodSwitchLid.strIndex = mi.strIndex; methodSwitchLid.status = (mi.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateSwitchLidXmlNode(currId, methodSwitchLid, mi); } } #endregion #region file move Liquid if (iNum == (int)MethodNameEnum.fileMoveLiquid) { FileMoveLiquidProperty ap = mi.control as FileMoveLiquidProperty; if (ap != null) { ap.methodFileMoveLiquid.strIndex = mi.strIndex; xmlHelper.CreateFileMoveLiquidXmlNode(currId, ap.methodFileMoveLiquid, mi); } else { MethodFileMoveLiquid methodFileMoveLiquid = new MethodFileMoveLiquid(); methodFileMoveLiquid.label = mi.method_name; methodFileMoveLiquid.name = mi.method_name; methodFileMoveLiquid.strIndex = mi.strIndex; methodFileMoveLiquid.status = (mi.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateFileMoveLiquidXmlNode(currId, methodFileMoveLiquid, mi); } } #endregion #region file move Labware if (iNum == (int)MethodNameEnum.fileMoveLabware) { FileMoveLabwareProperty ap = mi.control as FileMoveLabwareProperty; if (ap != null) { ap.methodFileMoveLabware.strIndex = mi.strIndex; xmlHelper.CreateFileMoveLabwareXmlNode(currId, ap.methodFileMoveLabware, mi); } else { MethodFileMoveLabware methodFileMoveLabware = new MethodFileMoveLabware(); methodFileMoveLabware.label = mi.method_name; methodFileMoveLabware.name = mi.method_name; methodFileMoveLabware.strIndex = mi.strIndex; methodFileMoveLabware.status = (mi.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateFileMoveLabwareXmlNode(currId, methodFileMoveLabware, mi); } } #endregion #region file cut gum if (iNum == (int)MethodNameEnum.cutGum) { FileElectroProperty ap = mi.control as FileElectroProperty; if (ap != null) { ap.methodElectroFile.strIndex = mi.strIndex; xmlHelper.CreateFileElectroCutGumXmlNode(currId, ap.methodElectroFile, mi); } else { MethodElectroFile methodElectroFile = new MethodElectroFile(); methodElectroFile.label = mi.method_name; methodElectroFile.name = mi.method_name; methodElectroFile.strIndex = mi.strIndex; methodElectroFile.status = (mi.isEnabled == true ? "enable" : "disable"); xmlHelper.CreateFileElectroCutGumXmlNode(currId, methodElectroFile, mi); } } #endregion #region delete // else if (iNum == (int)MethodNameEnum.endgroup) // { // xmlHelper.CreateEndGroupXmlNode(i + 1, (int)im.Tag); // } // else if (iNum == (int)MethodNameEnum.shaker) // { // im.Tag = ((ShakerProperty)(((System.Windows.Controls.ListViewItem)(LBoxSort.Items[i])).Tag)).methodShaker; // xmlHelper.CreateShakerXmlNode(i + 1, ((ShakerProperty)(((System.Windows.Controls.ListViewItem)(LBoxSort.Items[i])).Tag)).methodShaker); // } // else if (iNum == (int)MethodNameEnum.home) // { // im.Tag = ((HomeProperty)(((System.Windows.Controls.ListViewItem)(LBoxSort.Items[i])).Tag)).methodHome; // xmlHelper.CreateHomeXmlNode(i + 1, ((HomeProperty)(((System.Windows.Controls.ListViewItem)(LBoxSort.Items[i])).Tag)).methodHome); // } // else if (iNum == (int)MethodNameEnum.remark) // { // im.Tag = ((RemarkProperty)(((System.Windows.Controls.ListViewItem)(LBoxSort.Items[i])).Tag)).methodRemark; // xmlHelper.CreateRemarkXmlNode(i + 1, ((RemarkProperty)(((System.Windows.Controls.ListViewItem)(LBoxSort.Items[i])).Tag)).methodRemark); // } // else if (iNum == (int)MethodNameEnum.choice) // { // im.Tag = ((ChoiceProperty)(((System.Windows.Controls.ListViewItem)(LBoxSort.Items[i])).Tag)).methodChoice; // xmlHelper.CreateChoiceXmlNode(i + 1, ((ChoiceProperty)(((System.Windows.Controls.ListViewItem)(LBoxSort.Items[i])).Tag)).methodChoice); // } // else if (iNum == (int)MethodNameEnum.coating) // { // im.Tag = ((CoatingProperty)(((System.Windows.Controls.ListViewItem)(LBoxSort.Items[i])).Tag)).methodCoating; // xmlHelper.CreateCoatingXmlNode(i + 1, ((CoatingProperty)(((System.Windows.Controls.ListViewItem)(LBoxSort.Items[i])).Tag)).methodCoating); // } // else if (iNum == (int)MethodNameEnum.setVariable) // { // im.Tag = ((SetVariableProperty)(((System.Windows.Controls.ListViewItem)(LBoxSort.Items[i])).Tag)).methodSetVariable; // xmlHelper.CreateSetVariableXmlNode(i + 1, ((SetVariableProperty)(((System.Windows.Controls.ListViewItem)(LBoxSort.Items[i])).Tag)).methodSetVariable); // } #endregion } count = currId; } catch (Exception ex) { LoggerHelper.ErrorLog("ERROR:", ex); } return count; } private void ListView_PreviewMouseMove(object sender, MouseEventArgs e) { if (e.LeftButton == MouseButtonState.Pressed) { ListView lv = sender as ListView; Point currentPosition = e.GetPosition(lv); if ((Math.Abs(currentPosition.X - _lastMouseDown.X) > SystemParameters.MinimumHorizontalDragDistance) || (Math.Abs(currentPosition.Y - _lastMouseDown.Y) > SystemParameters.MinimumVerticalDragDistance)) { HitTestResult result = VisualTreeHelper.HitTest(lv, currentPosition); if (result == null) return; ListViewItem lvi = Utilities.FindVisualParent(result.VisualHit); if (lvi == null) return; MethodEx mi = lv.SelectedItem as MethodEx; if (mi == null || mi.method_support == 0) return; isDragDrop = true; Image img = Utilities.FindVisualChild(lvi); DragDropAdorner adorner = new DragDropAdorner((UIElement)img); mAdornerLayer = AdornerLayer.GetAdornerLayer(gridCmdSet); mAdornerLayer.Add(adorner); DataObject data = new DataObject("MethodEx", lv.SelectedItem); DragDrop.DoDragDrop(lv, data, DragDropEffects.Copy); mAdornerLayer.Remove(adorner); mAdornerLayer = null; isDragDrop = false; } } } private void ListView_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { if (e.ChangedButton == MouseButton.Left) { ListView lv = sender as ListView; _lastMouseDown = e.GetPosition(lv); } } #region 右击设置条码 无效 private void tableMenuBarCode_Click(object sender, RoutedEventArgs e) { MenuItem mi = e.Source as MenuItem; ContextMenu menu = mi.Parent as ContextMenu; Canvas canvas = menu.PlacementTarget as Canvas; LabwareEx lb = canvas.DataContext as LabwareEx; if (lb == null) return; ControlLabware labware = Utilities.FindVisualChild(canvas); if (labware == null) return; Window wnd = Application.Current.MainWindow; Grid parent = Utilities.FindVisualChild(wnd); SetBarcodeDlg setLabelDlg = new SetBarcodeDlg(labware, lb); setLabelDlg.closeEvent += SetLabelDlg_closeEvent; setLabelDlg.OKEvent += SetLabelDlg_OKEvent; parent.Children.Add(setLabelDlg); } #endregion #region 去掉不要 /// /// 流程是否标记多选 /// /// /// private void WorkflowIsFlag(MethodEx methodEx, bool isFlag = true) { string name = methodEx.method_name; if (isFlag) { if (!name.Contains("*")) methodEx.method_name = name + "*"; } else { if (name.Contains("*")) methodEx.method_name = name.Replace("*", ""); } } #endregion #region 台面加载完成后,数据的处理 private void gridTable_Loaded(object sender, RoutedEventArgs e) { double xVal = gridTable.ActualWidth; double yVal = gridTable.ActualHeight; } #endregion private void UserControl_KeyDown(object sender, KeyEventArgs e) { } Key currentKey;//用于保存当前的key值 private void UserControl_PreviewKeyDown(object sender, KeyEventArgs e) { try { if (e.Key == Key.Delete)//删除流程选中节点 { workflowMenuDelete_Click(sender, e); //tableMenuDeleteLabware_Click(sender, e); } if(e.Key==Key.F)//流程选中节点禁止 { currentKey = e.Key; // 获取当前键盘焦点元素 DependencyObject focusedElement = (DependencyObject)Keyboard.FocusedElement; if (focusedElement != null && focusedElement.DependencyObjectType.Name.Equals("TreeViewItem")) { workflowMenuDisable_Click(sender, e); } } if (e.Key == Key.E)//流程选中节点启用 { currentKey = e.Key; // 获取当前键盘焦点元素 DependencyObject focusedElement = (DependencyObject)Keyboard.FocusedElement; if (focusedElement != null && focusedElement.DependencyObjectType.Name.Equals("TreeViewItem")) { workflowMenuDisable_Click(sender, e); } } if (e.KeyboardDevice.Modifiers == ModifierKeys.Control && e.Key == Key.C) { // 执行复制操作 workflowMenuCopy_Click(sender, e); // 阻止事件继续传播 e.Handled = true; } else if (e.KeyboardDevice.Modifiers == ModifierKeys.Control && e.Key == Key.V) { // 执行粘贴操作 workflowMenuPaste_Click(sender, e); // 阻止事件继续传播 e.Handled = true; } } catch(Exception ex) { LoggerHelper.ErrorLog("UserControl_PreviewKeyDown Error", ex); } } } }