using Model.Vision; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Community; using System.Collections.ObjectModel; using System.Windows; using System.Windows.Controls; using Views.Vision; using MahApps.Metro.Controls.Dialogs; namespace ViewModel.Vision { /// /// 功能编辑 /// partial class HalconVisual { #region 功能显示控件 private UserControl showControl; /// /// 功能显示控件 /// public UserControl ShowControl { get { return showControl; } set { showControl = value; this.RaisePropertyChanged("ShowControl"); } } #endregion #region 选中的视觉工程项目 private VisualEngineering selectVE; /// /// 选中的视觉工程项目 /// public VisualEngineering SelectVE { get { return selectVE; } set { selectVE = value; this.RaisePropertyChanged("SelectVE"); } } #endregion #region 选中的视觉工程项目功能 private VisualEngineeringItems selectVEI; /// /// 选中的视觉工程项目功能 /// public VisualEngineeringItems SelectVEI { get { return selectVEI; } set { selectVEI = value; ControlDeployment(value); this.RaisePropertyChanged("SelectVEI"); } } /// /// 功能显示控件调度 /// /// private void ControlDeployment(VisualEngineeringItems value) { if (value != null && value.ID > 0) { SelectModel = value.MyRectangleModel; switch (value.HandleType) { case 1: ShowControl = new V_ScanCode(); break; case 2: ShowControl = new V_Location(); break; case 3: case 23://抓螺柱 ShowControl = new V_Inspect(); break; case 4: ShowControl = new V_Measure(); break; case 5: ShowControl = new V_OCR(); break; } } else { ShowControl = null; } } #endregion #region 各种方法 /// /// 新增工程 /// public DelegateCommand AddVeCommand { get; set; } /// /// 更新工程项目 /// public DelegateCommand UpdateVeCommand { get; set; } /// /// 删除工程 /// public DelegateCommand DeleteVeCommand { get; set; } /// /// 新增视觉工程项目 /// public DelegateCommand AddVeiCommand { get; set; } /// /// 保存视觉工程项目 /// public DelegateCommand UpdateVeiCommand { get; set; } /// /// 删除视觉功能项目 /// public DelegateCommand DeleteVeiCommand { get; set; } #endregion #region 初始化视觉工程项目编辑类 /// /// 初始化视觉工程项目编辑类 /// private void InitializationFunctionEditing() { AddVeCommand = new DelegateCommand(); AddVeCommand.ExecuteAction = new Action(AddVe); UpdateVeCommand = new DelegateCommand(); UpdateVeCommand.ExecuteAction = new Action(UpdateVe); DeleteVeCommand = new DelegateCommand(); DeleteVeCommand.ExecuteAction = new Action(DeleteVe); AddVeiCommand = new DelegateCommand(); AddVeiCommand.ExecuteAction = new Action(AddVei); UpdateVeiCommand = new DelegateCommand(); UpdateVeiCommand.ExecuteAction = new Action(UpdateVei); DeleteVeiCommand = new DelegateCommand(); DeleteVeiCommand.ExecuteAction = new Action(DeleteVei); } #endregion #region 更新工程项目 /// /// 更新工程项目 /// /// private void UpdateVe(object obj) { if (SelectVE == null) { return; } int a = Vdal.UpdateVisualEngineering(SelectVE); if (a > 0) { MyMessageBox.Show("保存成功"); VisualEngineeringList = Vdal.GetVisualEngineeringList(MachineObj.ID, Camera.ID); //获取相机对应的视觉工程项目集合 } else { MyMessageBox.Show("失败"); } } #endregion #region 新增工程 /// /// 新增工程 /// /// private void AddVe(object obj) { if (MyMessageBox.Show("你确定要新增视觉工程吗?", "提醒", MessageDialogStyle.AffirmativeAndNegative) == MessageDialogResult.Affirmative) { VisualEngineering ve = new VisualEngineering() { EName = "新来的", MachineID = MachineObj.ID, CameraID = Camera.ID, Enable = false, Notes = "新手,没有备注" }; VisualEngineeringList.Add(ve); } } #endregion #region 删除工程 /// /// 删除工程 /// /// private void DeleteVe(object obj) { if (SelectVE != null) { if (Vdal.DelVisualEngineering(SelectVE) > 0) { MyMessageBox.Show("删除成功"); VisualEngineeringList = Vdal.GetVisualEngineeringList(MachineObj.ID, Camera.ID); //获取相机对应的视觉工程项目集合 } else { MyMessageBox.Show("删除失败"); } } } #endregion #region 更新功能 /// /// 更新功能 /// /// private void UpdateVei(object obj) { if (SelectVEI == null) { return; } int res = Vdal.UpdateVisualEngineeringItems(SelectVEI); if (res > 0) { MyMessageBox.Show("保存成功"); } else { MyMessageBox.Show("失败"); } } #endregion #region 添加功能 /// /// 添加功能 /// /// private void AddVei(object obj) { if (SelectVE != null) { if (MyMessageBox.Show("你确定要新增视觉工程项目吗?", "提醒", MessageDialogStyle.AffirmativeAndNegative) == MessageDialogResult.Affirmative) { VisualEngineeringItems vei = new VisualEngineeringItems() { HandleType = 3, VEIname = "新来的", Notes = "新添加的还未保存", VisualEngineeringID = SelectVE.ID }; SelectVE.VisualEngineeringItemsList.Add(vei); } } } #endregion #region 删除功能 /// /// 删除功能 /// /// private void DeleteVei(object obj) { if (SelectVEI != null) { if (Vdal.DelVisualEngineeringItems(SelectVEI) > 0) { MyMessageBox.Show("删除成功"); SelectVE.VisualEngineeringItemsList = Vdal.GetVisualEngineeringItemsList(SelectVE.ID); } else { MyMessageBox.Show("删除失败"); } } } #endregion } }