using Community; using Model; using Model.MotionControl; using Model.Vision; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using ViewModel.Vision; namespace ViewModel { /// /// 机种编辑 /// partial class MainWindowVM { #region 已启用的机种集合 private ObservableCollection enableMachineList; /// /// 已启用的机种集合 /// public ObservableCollection EnableMachineList { get { return enableMachineList; } set { enableMachineList = value; this.RaisePropertyChanged("EnableMachineList"); } } #endregion #region 所有机种集合 private ObservableCollection allMachineList; /// /// 所有机种结合 /// public ObservableCollection AllMachineList { get { return allMachineList; } set { allMachineList = value; this.RaisePropertyChanged("AllMachineList"); } } #endregion #region 各种方法 /// /// 新增机种 /// public DelegateCommand AddMachineCommand { get; set; } /// /// 更新机种 /// public DelegateCommand UpdateMachineCommand { get; set; } /// /// 生产计数清零 /// public DelegateCommand CountClearedCommand { get; set; } #endregion #region 选中的要编辑机种 private MachineModel selectMachine; /// /// 选中的要编辑机种 /// public MachineModel SelectMachine { get { return selectMachine; } set { selectMachine = value; this.RaisePropertyChanged("SelectMachine"); } } #endregion #region 初始化机种编辑类 /// /// 初始化机种编辑类 /// public void InitializeMachineEditor() { //1、获取已启用的机种集合 AllMachineList = dal.GetALLMachineList(); EnableMachineList = new ObservableCollection(AllMachineList.Where(w => w.EnableS == true).ToList()); //dal.GetEnableMachineList(); AddMachineCommand = new DelegateCommand(); AddMachineCommand.ExecuteAction = new Action(AddMachine); UpdateMachineCommand = new DelegateCommand(); UpdateMachineCommand.ExecuteAction = new Action(UpdateMachine); CountClearedCommand = new DelegateCommand(); CountClearedCommand.ExecuteAction = new Action(CountCleared); //获取当前生产机种 CurrentMachineID = SystemPar.DefaultMachineID; } #endregion #region 生产计数清零 /// /// 生产计数清零 /// /// private void CountCleared(object obj) { if (MessageBox.Show("你确定要对当前机种生产计数清零?", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Exclamation) == MessageBoxResult.OK) { CurrentMachine.Quantitys = 0; CurrentMachine.RejectRatio = 0; CurrentMachine.ProductionTime = 0; CurrentMachine.Produce = 0; dal.UpdateProductionData(CurrentMachine); } } #endregion #region 更新机种 /// /// 更新机种 /// /// private void UpdateMachine(object obj) { if (MessageBox.Show("你确定更新当前选中机种吗?", "提示", MessageBoxButton.YesNo, MessageBoxImage.Exclamation) == MessageBoxResult.No) { return; } if (dal.UpdateMachineData(SelectMachine) > 0) { EnableMachineList = dal.GetEnableMachineList(); CurrentMachineID = SystemPar.DefaultMachineID; MessageBox.Show("更新成功"); } else { MessageBox.Show("更新失败"); } } #endregion #region 新增机种 /// /// 新增机种 /// /// private void AddMachine(object obj) { if (MessageBox.Show("你确定要新增机种吗?", "提示", MessageBoxButton.YesNo, MessageBoxImage.Exclamation) == MessageBoxResult.No) { return; } try { MachineModel mt = new MachineModel() { MachineName = "新来的", EnableS = true }; if (dal.AddMachineData(mt) > 0) { //添加机器人点位 if (SystemPar.RobotBool && Robot != null) { //新增机器人点位 if (Robot.RobotPointList != null && Robot.RobotPointList.Count > 0) { foreach (RobotPoint rp in Robot.RobotPointList) { if (rp.ID>0) { rp.MachineID = mt.ID; dal.AddRobotPoint(rp); } } } } //添加运动控制点位 if (SystemPar.MotionControlBool && MCVM != null) { if (MCVM.TrajListL != null && MCVM.TrajListL.Count > 0) { foreach (MotionTrajectoryModel item in MCVM.TrajListL) { item.SuperiorID = mt.ID; if (dal.AddMotionTrajectory(item) > 0) { foreach (MotionPointModel mp in item.PointList) { mp.MachineID = item.ID; dal.AddMotionPoint(mp); } } } } } //添加视觉 if (SystemPar.VisionBool && HVlist != null) { foreach (HalconVisual hv in HVlist) { foreach (VisualEngineering ve in hv.VisualEngineeringList) { ve.MachineID = mt.ID; if (Vdal.AddVisualEngineering(ve) > 0) { foreach (VisualEngineeringItems vei in ve.VisualEngineeringItemsList) { vei.VisualEngineeringID = ve.ID; Vdal.AddVisualEngineeringItems(vei); } } } } } EnableMachineList = dal.GetEnableMachineList(); AllMachineList = dal.GetALLMachineList(); CurrentMachineID = 0; CurrentMachineID = SystemPar.DefaultMachineID; MessageBox.Show("新增机种成功"); } else { MessageBox.Show("新增机种失败"); } } catch (Exception ex) { MessageBox.Show("新增机种失败" + ex.ToString()); } } #endregion } }