using Models.Const; using Models.Models; using SamplePre.Models; using SamplePre.ProcessBll.BLL; using System; using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; using System.Windows; namespace SamplePreSystem.UI.ViewModel.Child { public class NewActionViewModel: INotifyPropertyChanged { ActionMangerBll actionMangerBll = new ActionMangerBll(); public NewActionViewModel() { BindingUnit(); } public void BindingUnit() { ActionUnits = SystemConst.dictDatas.Where(p => p.class_id == 2).ToList(); } private List actionUnits; public event PropertyChangedEventHandler PropertyChanged; public List ActionUnits { get { return actionUnits; } set { actionUnits = value; OnPropertyChanged(); } } /// /// 选择的动作单元 /// private sys_dict _selectSysDict; public sys_dict SelectSysDict { get { return _selectSysDict; } set { _selectSysDict = value; OnPropertyChanged(); } } protected void OnPropertyChanged([CallerMemberName] string propertyName = null) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } private sys_action sysAction = new sys_action(); public sys_action SysAction { get { return sysAction; } set { sysAction = value; OnPropertyChanged(); } } public int SaveNewData() { if (string.IsNullOrEmpty(SysAction.action_name)) { MessageBox.Show("内容不能为空"); return -1; } //判断plc编码是否重复 if (actionMangerBll.IsExtisPlCcode(SysAction.plc_type)) { MessageBox.Show("存在相同plc编码,不能保存!"); return -1; } sys_action process = new sys_action(); process.id = Guid.NewGuid().ToString(); process.action_name = SysAction.action_name; process.plc_type = SysAction.plc_type; process.remark = SysAction.remark; //var selectItem = cmbActionUnit.SelectedItem as ComboBoxListItem; process.action_unit = SelectSysDict.id; //process.action_adress = actionAdress.Text; int val = actionMangerBll.SaveSysAction(process); return val; } } }