using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; using Models.Ext; using Models.Models; using SamplePre.Models.Ext; using SamplePre.ProcessBll.BLL; using SamplePre.UIWpf.ParamManager.chirld; using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Data; namespace SamplePreSystem.UI.ViewModel.SopManager { public partial class ActionManagerViewModel : ObservableObject { ActionMangerBll actionMangerBll = new ActionMangerBll(); SOPManagerBll sopBll = new SOPManagerBll(); public ActionManagerViewModel() { ///获取所有动作 InitActionData(); } /// /// 所有动作列表 /// [ObservableProperty] public List sysActions = new List(); /// /// 获取所有动作 /// public void InitActionData() { SysActions = actionMangerBll.QuerySysAction(); } [ObservableProperty] public List actionParams; private sys_action_ext _selectItem; /// /// 选中的动作行 /// public sys_action_ext SelectItem { get { return _selectItem; } set { SetProperty(ref _selectItem, value); OnSelectedActionChanged(); } } /// /// 选中的参数 /// private sys_action_parm_map_ext _selectParam; public sys_action_parm_map_ext SelectParam { get { return _selectParam; } set { SetProperty(ref _selectParam, value); } } /// /// 查询动作下参数 /// /// public void GetParmData(string actionId) { ActionParams = actionMangerBll.GetProcess_parm_mapByProcessId(actionId); } /// /// 获取动作下的参数 /// private void OnSelectedActionChanged() { if (SelectItem == null) return; //获取动作下的参数 GetParmData(SelectItem.id); } public void DeleAction() { if (SelectItem == null) return; sys_action_ext action = SelectItem; if (action.action_unit == "0") return; if (MessageBox.Show($"确定删除:{action.action_name}", "提示", MessageBoxButton.OKCancel) == MessageBoxResult.OK) { //校验动作是否已经被使用 if (CheckAction(action) == false) { return; } //删除动作 actionMangerBll.DelSysActionData(action.id); //=====刷新列表=================== InitActionData(); } } private bool CheckAction(sys_action process) { bool isExis = sopBll.IsExisAction(process.id); if (isExis) { MessageBox.Show("该动作已经被使用,不能删除!"); return false; } return true; } public void SelectShowParmList() { if(SelectItem == null) { MessageBox.Show("请先选择动作!"); return; } SelectParmListWindow frm = new SelectParmListWindow(SelectItem); if(frm.ShowDialog() == true) { //获取动作下的参数 GetParmData(SelectItem.id); } } /// /// 删除参数 /// public void DeleParam() { if (SelectItem == null || SelectParam == null) return;//SelectItem sys_action_parm_map_ext process = SelectParam; int id = process.id; string parm_name = process.title; if (MessageBox.Show($"确定删除:{parm_name}", "提示",MessageBoxButton.OKCancel) == MessageBoxResult.OK) { actionMangerBll.DelProcessParmMap(id); GetParmData(process.process_id); } } /// /// 新增动作 /// /// /// [RelayCommand] public void BtnAddActionClick() { NewActionWindow frm = new NewActionWindow(this); if (frm.ShowDialog() == true) { //刷新列表 InitActionData(); //刷新列表 ListCollectionView view = (ListCollectionView)CollectionViewSource.GetDefaultView(SysActions);//获取数据视图 ////分组 //view.SortDescriptions.Add(new SortDescription("action_seqno", ListSortDirection.Ascending)); view.GroupDescriptions.Clear(); view.GroupDescriptions.Add(new PropertyGroupDescription("action_unitname")); } } /// /// 删除动作 /// /// /// [RelayCommand] public void BtnDelActionClick() { DeleAction(); //刷新列表 ListCollectionView view = (ListCollectionView)CollectionViewSource.GetDefaultView(SysActions);//获取数据视图 ////分组 view.GroupDescriptions.Clear(); view.GroupDescriptions.Add(new PropertyGroupDescription("action_unitname")); } /// /// 动作下新增参数 /// /// /// [RelayCommand] public void BtnSelectParamClick() { SelectShowParmList(); } /// /// 删除动作下参数 /// [RelayCommand] public void BtnDelParmClick() { DeleParam(); } } }