274 lines
8.8 KiB
C#
274 lines
8.8 KiB
C#
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
|
|
{
|
|
/// <summary>
|
|
/// 机种编辑
|
|
/// </summary>
|
|
partial class MainWindowVM
|
|
{
|
|
#region 已启用的机种集合
|
|
private ObservableCollection<MachineModel> enableMachineList;
|
|
/// <summary>
|
|
/// 已启用的机种集合
|
|
/// </summary>
|
|
public ObservableCollection<MachineModel> EnableMachineList
|
|
{
|
|
get { return enableMachineList; }
|
|
set
|
|
{
|
|
enableMachineList = value;
|
|
this.RaisePropertyChanged("EnableMachineList");
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 所有机种集合
|
|
private ObservableCollection<MachineModel> allMachineList;
|
|
/// <summary>
|
|
/// 所有机种结合
|
|
/// </summary>
|
|
public ObservableCollection<MachineModel> AllMachineList
|
|
{
|
|
get { return allMachineList; }
|
|
set
|
|
{
|
|
allMachineList = value;
|
|
this.RaisePropertyChanged("AllMachineList");
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 各种方法
|
|
/// <summary>
|
|
/// 新增机种
|
|
/// </summary>
|
|
public DelegateCommand AddMachineCommand { get; set; }
|
|
/// <summary>
|
|
/// 更新机种
|
|
/// </summary>
|
|
public DelegateCommand UpdateMachineCommand { get; set; }
|
|
/// <summary>
|
|
/// 生产计数清零
|
|
/// </summary>
|
|
public DelegateCommand CountClearedCommand { get; set; }
|
|
|
|
#endregion
|
|
|
|
#region 选中的要编辑机种
|
|
private MachineModel selectMachine;
|
|
/// <summary>
|
|
/// 选中的要编辑机种
|
|
/// </summary>
|
|
public MachineModel SelectMachine
|
|
{
|
|
get { return selectMachine; }
|
|
set
|
|
{
|
|
selectMachine = value;
|
|
|
|
this.RaisePropertyChanged("SelectMachine");
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 初始化机种编辑类
|
|
/// <summary>
|
|
/// 初始化机种编辑类
|
|
/// </summary>
|
|
public void InitializeMachineEditor()
|
|
{
|
|
|
|
|
|
//1、获取已启用的机种集合
|
|
|
|
AllMachineList = dal.GetALLMachineList();
|
|
EnableMachineList = new ObservableCollection<MachineModel>(AllMachineList.Where(w => w.EnableS == true).ToList()); //dal.GetEnableMachineList();
|
|
AddMachineCommand = new DelegateCommand();
|
|
AddMachineCommand.ExecuteAction = new Action<object>(AddMachine);
|
|
|
|
UpdateMachineCommand = new DelegateCommand();
|
|
UpdateMachineCommand.ExecuteAction = new Action<object>(UpdateMachine);
|
|
|
|
CountClearedCommand = new DelegateCommand();
|
|
CountClearedCommand.ExecuteAction = new Action<object>(CountCleared);
|
|
|
|
//获取当前生产机种
|
|
CurrentMachineID = SystemPar.DefaultMachineID;
|
|
}
|
|
#endregion
|
|
|
|
#region 生产计数清零
|
|
/// <summary>
|
|
/// 生产计数清零
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
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 更新机种
|
|
|
|
/// <summary>
|
|
/// 更新机种
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
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 新增机种
|
|
/// <summary>
|
|
/// 新增机种
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
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);
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
//添加站别
|
|
//if(CurrentMachine.StandList!=null)
|
|
//{
|
|
// foreach (var item in CurrentMachine.StandList)
|
|
// {
|
|
// item.ParentID = mt.ID;
|
|
// dal.AddStandModel(item);
|
|
// }
|
|
//}
|
|
|
|
|
|
|
|
|
|
EnableMachineList = dal.GetEnableMachineList();
|
|
AllMachineList = dal.GetALLMachineList();
|
|
CurrentMachineID = 0;
|
|
CurrentMachineID = SystemPar.DefaultMachineID;
|
|
MessageBox.Show("新增机种成功");
|
|
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show("新增机种失败");
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
|
|
MessageBox.Show("新增机种失败" + ex.ToString());
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
}
|