添加项目文件。
This commit is contained in:
376
SamplePreSystem.UI/ViewModel/SopManager/SopMangerViewModel.cs
Normal file
376
SamplePreSystem.UI/ViewModel/SopManager/SopMangerViewModel.cs
Normal file
@@ -0,0 +1,376 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using Models.Const;
|
||||
using Models.Models;
|
||||
using SamplePre.Models;
|
||||
using SamplePre.Models.Ext;
|
||||
using SamplePre.ProcessBll.BLL;
|
||||
using SamplePre.UIWpf.ParamManager.chirld;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
|
||||
namespace SamplePreSystem.UI.ViewModel.SopManager
|
||||
{
|
||||
public partial class SopMangerViewModel : ObservableObject
|
||||
{
|
||||
|
||||
SOPManagerBll sopManagerBll = new SOPManagerBll();
|
||||
|
||||
SystemBll systemBll = new SystemBll();
|
||||
|
||||
|
||||
public SopMangerViewModel()
|
||||
{
|
||||
//初始化标准
|
||||
InitStandardData();
|
||||
|
||||
//初始化动作
|
||||
InitActionData();
|
||||
//sop
|
||||
GetSopData("111");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// sop列表
|
||||
/// </summary>
|
||||
public List<DataGroup> StandardGroups { get; set; } = new List<DataGroup>();
|
||||
|
||||
/// <summary>
|
||||
/// sop列表
|
||||
/// </summary>
|
||||
|
||||
private List<sys_standard_action_ext> _sopList = new List<sys_standard_action_ext>();
|
||||
|
||||
public List<sys_standard_action_ext> SopList
|
||||
{
|
||||
get { return _sopList; }
|
||||
set {
|
||||
SetProperty(ref _sopList, value);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 选择的动作
|
||||
/// </summary>
|
||||
private sys_standard_action_ext _selectItem;
|
||||
|
||||
public sys_standard_action_ext SelectItem
|
||||
{
|
||||
get { return _selectItem; }
|
||||
set {
|
||||
SetProperty(ref _selectItem, value);
|
||||
|
||||
OnSelectedActionChanged();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 选择的参数
|
||||
/// </summary>
|
||||
private sys_standard_action_parm_ext _selectParamItem;
|
||||
|
||||
public sys_standard_action_parm_ext SelectParamItem
|
||||
{
|
||||
get { return _selectParamItem; }
|
||||
set
|
||||
{
|
||||
SetProperty(ref _selectParamItem, value);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 动作参数列表
|
||||
/// </summary>
|
||||
private List<sys_standard_action_parm_ext> _actionParamList = new List<sys_standard_action_parm_ext>();
|
||||
|
||||
public List<sys_standard_action_parm_ext> ActionParamList
|
||||
{
|
||||
get { return _actionParamList; }
|
||||
set {
|
||||
|
||||
SetProperty(ref _actionParamList, value);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void OnSelectedActionChanged()
|
||||
{
|
||||
if (SelectItem == null) return;
|
||||
//获取动作下的参数
|
||||
List<sys_standard_action_parm_ext> paramList = sopManagerBll.GetStrandActionParamByStrandId(SelectItem.standard_id);
|
||||
ActionParamList = paramList.Where(p => p.action_id == SelectItem.process_id && p.action_seqno == SelectItem.process_no).ToList();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void InitStandardData()
|
||||
{
|
||||
|
||||
SystemConst.dictDatas = systemBll.QueryDictData();
|
||||
|
||||
List<TreeListItem> treeListItems = sopManagerBll.GetStandardData();
|
||||
|
||||
|
||||
|
||||
var group = treeListItems.Where(p=>p.ParentID == "0").ToList();
|
||||
foreach (TreeListItem item in group)
|
||||
{
|
||||
DataGroup sopGroup = new DataGroup();
|
||||
sopGroup.Id = item.ID;
|
||||
sopGroup.SopName = item.DisplayText;
|
||||
|
||||
sopGroup.ListItems = treeListItems.Where(p => p.ParentID == item.ID).ToList();
|
||||
|
||||
StandardGroups.Add(sopGroup);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public List<DataGroup> ActionGroups { get; set; } = new List<DataGroup>();
|
||||
|
||||
/// <summary>
|
||||
/// 初始化动作字典
|
||||
/// </summary>
|
||||
public void InitActionData()
|
||||
{
|
||||
|
||||
//获取动作
|
||||
List<sys_action_ext> actions = sopManagerBll.QuerySysAction();
|
||||
|
||||
//拼装组
|
||||
var groups = actions.GroupBy(p => new { p.action_unitname, p.action_unit }).ToList();
|
||||
foreach (var item in groups)
|
||||
{
|
||||
DataGroup sopGroup = new DataGroup();
|
||||
sopGroup.Id = item.Key.action_unit;
|
||||
sopGroup.SopName = item.Key.action_unitname;
|
||||
|
||||
var itemList = actions.Where(p => p.action_unit == item.Key.action_unit).ToList();
|
||||
foreach(var it in itemList)
|
||||
{
|
||||
sopGroup.ListItems.Add(new TreeListItem() { ID = it.id, DisplayText = it.action_name, ParentID = item.Key.action_unit });
|
||||
}
|
||||
|
||||
|
||||
ActionGroups.Add(sopGroup);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public string m_standradId;
|
||||
|
||||
public void GetSopData(string standradId)
|
||||
{
|
||||
m_standradId = standradId;
|
||||
SopList = sopManagerBll.QueryStandardProcessByStandardId(standradId);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 拖拽新增动作
|
||||
/// </summary>
|
||||
/// <param name="dropItem"></param>
|
||||
[RelayCommand]
|
||||
public void AddDragSopAction(TreeListItem dropItem)
|
||||
{
|
||||
List<sys_standard_action_ext> actionList = SopList;
|
||||
|
||||
if (string.IsNullOrEmpty(m_standradId)) return;
|
||||
|
||||
if (dropItem != null && actionList != null)
|
||||
{
|
||||
int maxSeqno = 0;
|
||||
//取最后的动作序号+1;
|
||||
if (actionList.Count > 0)
|
||||
{
|
||||
maxSeqno = actionList[actionList.Count - 1].process_no + 1;
|
||||
}
|
||||
|
||||
|
||||
sys_standard_action procemodel = new sys_standard_action()
|
||||
{
|
||||
id = Guid.NewGuid().ToString(),
|
||||
process_id = dropItem.ID,
|
||||
//process_name = process.process_name,
|
||||
process_no = maxSeqno,//actionList.Count + 1,
|
||||
standard_id = m_standradId
|
||||
};
|
||||
|
||||
//保存标准动作表、动作参数表
|
||||
sopManagerBll.SaveStandardAction_param(procemodel);
|
||||
|
||||
//=======================================================
|
||||
//查询标准下的SOP
|
||||
GetSopData(m_standradId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 移除动作
|
||||
/// </summary>
|
||||
public void RemoveAction()
|
||||
{
|
||||
|
||||
sys_standard_action_ext pro = SelectItem; //this.gridView1.GetRow(rows[0]) as sys_standard_action_ext;
|
||||
if (pro == null) return;
|
||||
if (MessageBox.Show($"确定移除:{pro.action_name}", "提示", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
|
||||
{
|
||||
//移除标准下的动作
|
||||
sopManagerBll.removeStandAction(pro);
|
||||
|
||||
|
||||
//查询标准下的SOP
|
||||
GetSopData(pro.standard_id);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 上移动作操作
|
||||
/// </summary>
|
||||
public void UpMove()
|
||||
{
|
||||
sys_standard_action_ext[] temp_list = new sys_standard_action_ext[SopList.Count];
|
||||
SopList.CopyTo(temp_list);
|
||||
|
||||
for (int i = 0;i < temp_list.Length;i++)
|
||||
{
|
||||
if (i != 0 && temp_list[i] == SelectItem)
|
||||
{
|
||||
|
||||
var item = temp_list[i - 1];
|
||||
temp_list[i - 1] = SelectItem;
|
||||
temp_list[i] = item;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
SopList = temp_list.ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 下移动作操作
|
||||
/// </summary>
|
||||
public void DownMove()
|
||||
{
|
||||
sys_standard_action_ext[] temp_list = new sys_standard_action_ext[SopList.Count];
|
||||
SopList.CopyTo(temp_list);
|
||||
|
||||
for (int i = 0; i < temp_list.Length; i++)
|
||||
{
|
||||
if (i < temp_list.Length - 1 && temp_list[i] == SelectItem)
|
||||
{
|
||||
|
||||
var item = temp_list[i + 1];
|
||||
temp_list[i + 1] = SelectItem;
|
||||
temp_list[i] = item;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
SopList = temp_list.ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新序号
|
||||
/// </summary>
|
||||
public void UpdateSeqno()
|
||||
{
|
||||
//List<sys_standard_action_ext> sopList = gridActions.DataSource as List<sys_standard_action_ext>;
|
||||
|
||||
int seqno = 1;
|
||||
string standradId = "";
|
||||
foreach (var action in SopList)
|
||||
{
|
||||
//sys_standard_action_ext action = tree_Actions.GetDataRecordByNode(node) as sys_standard_action_ext;
|
||||
standradId = action.standard_id;
|
||||
|
||||
action.new_action_seqno = seqno;
|
||||
|
||||
sopManagerBll.UpdateActionSeqno(action);
|
||||
seqno++;
|
||||
}
|
||||
GetSopData(standradId);
|
||||
}
|
||||
|
||||
public void AddParamShow()
|
||||
{
|
||||
if (SelectItem != null)
|
||||
{
|
||||
SelectParmListWindow frm = new SelectParmListWindow(SelectItem);
|
||||
if(frm.ShowDialog() == true)
|
||||
{
|
||||
OnSelectedActionChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveParam()
|
||||
{
|
||||
|
||||
if (SelectItem != null && SelectParamItem != null)
|
||||
{
|
||||
if (MessageBox.Show($"是否移除【{SelectParamItem.title}】参数?", "提示", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
|
||||
{
|
||||
sopManagerBll.removeActionParmByParamId(SelectItem.standard_id, SelectItem.process_id, SelectItem.process_no, SelectParamItem.parm_id);
|
||||
|
||||
OnSelectedActionChanged();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
internal void AddEidtParam()
|
||||
{
|
||||
if(ActionParamList.Count > 0)
|
||||
{
|
||||
//List<sys_standard_action_parm> list = uCActionParam.GetEditVal();
|
||||
//if (list == null) return;
|
||||
foreach (var item in ActionParamList)
|
||||
{
|
||||
sopManagerBll.updateStandardActionParm(item);
|
||||
}
|
||||
|
||||
MessageBox.Show("修改成功!");
|
||||
|
||||
OnSelectedActionChanged();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 标准选择命令
|
||||
/// </summary>
|
||||
/// <param name="selectItem"></param>
|
||||
[RelayCommand]
|
||||
public void StandSelectedItemChanged(object obj)
|
||||
{
|
||||
TreeListItem selectItem = obj as TreeListItem;
|
||||
if (selectItem == null) return;
|
||||
GetSopData(selectItem.ID);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user