添加项目文件。
This commit is contained in:
218
SamplePreSystem.UI/ViewModel/Child/SelectParmListViewModel.cs
Normal file
218
SamplePreSystem.UI/ViewModel/Child/SelectParmListViewModel.cs
Normal file
@@ -0,0 +1,218 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using Models.Models;
|
||||
using SamplePre.Models.Ext;
|
||||
using SamplePre.ProcessBll.BLL;
|
||||
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;
|
||||
|
||||
namespace SamplePreSystem.UI.ViewModel.Child
|
||||
{
|
||||
public partial class SelectParmListViewModel : ObservableObject
|
||||
{
|
||||
|
||||
ActionMangerBll actionMangerBll = new ActionMangerBll();
|
||||
|
||||
SOPManagerBll sopBll = new SOPManagerBll();
|
||||
|
||||
sys_standard_action_ext sysStandardAction = null;
|
||||
|
||||
sys_action_ext sysAction = null;
|
||||
|
||||
// 关闭窗口的委托
|
||||
public Action<bool> CloseAction { get; set; }
|
||||
|
||||
public SelectParmListViewModel(sys_standard_action_ext _sysStandardAction)
|
||||
{
|
||||
sysStandardAction = _sysStandardAction;
|
||||
GetData();
|
||||
|
||||
FilterData(FilterType);
|
||||
}
|
||||
|
||||
public SelectParmListViewModel(sys_action_ext _sysAction)
|
||||
{
|
||||
sysAction = _sysAction;
|
||||
GetData();
|
||||
|
||||
FilterData(FilterType);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 参数类型
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
public List<string> dataTypes = new List<string> { "通用", "耗材", "液体" };
|
||||
|
||||
/// <summary>
|
||||
/// 所有参数列表
|
||||
/// </summary>
|
||||
private List<sys_parm> allSysParams = new List<sys_parm>();
|
||||
|
||||
/// <summary>
|
||||
/// 过滤参数列表
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
public List<sys_parm> parms = new List<sys_parm>();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 选中的参数列表
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
public sys_parm selectParm = new sys_parm();
|
||||
|
||||
|
||||
|
||||
public void GetData()
|
||||
{
|
||||
if (Parms.Count <= 0)
|
||||
{
|
||||
//parms = standardDal.QuerySysParm();
|
||||
allSysParams = actionMangerBll.QuerySysParm();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private string filterType = "通用";
|
||||
/// <summary>
|
||||
/// 类型过滤属性
|
||||
/// </summary>
|
||||
public string FilterType
|
||||
{
|
||||
get { return filterType; }
|
||||
set {
|
||||
|
||||
SetProperty(ref filterType, value);
|
||||
|
||||
FilterData(value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void FilterData(string dataType)
|
||||
{
|
||||
if (string.IsNullOrEmpty(dataType))
|
||||
{
|
||||
Parms = allSysParams;
|
||||
return;
|
||||
}
|
||||
|
||||
Parms = allSysParams.Where(p => p.param_type == dataType).ToList();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public int SaveData(List<sys_parm> selectParam)
|
||||
{
|
||||
int val = -1;
|
||||
if (sysStandardAction != null)
|
||||
{
|
||||
val = SavaDataSop(selectParam);
|
||||
}
|
||||
else if(sysAction != null)
|
||||
{
|
||||
val = SavaDataActionParam(selectParam);
|
||||
}
|
||||
|
||||
|
||||
return val;
|
||||
|
||||
}
|
||||
|
||||
private int SavaDataActionParam(List<sys_parm> selectParam)
|
||||
{
|
||||
|
||||
//保存
|
||||
List<sys_action_parm_map> actionParams = new List<sys_action_parm_map>();
|
||||
foreach (var item in selectParam)
|
||||
{
|
||||
sys_action_parm_map map = new sys_action_parm_map();
|
||||
map.process_id = sysAction.id;
|
||||
map.parm_id = item.id;
|
||||
//standardDal.Save_process_parm_map(map);
|
||||
actionParams.Add(map);
|
||||
}
|
||||
|
||||
int val = actionMangerBll.SaveActionParm(actionParams);
|
||||
|
||||
return val;
|
||||
|
||||
}
|
||||
|
||||
private int SavaDataSop(List<sys_parm> selectParam)
|
||||
{
|
||||
//保存
|
||||
List<sys_standard_action_parm> actionParms = new List<sys_standard_action_parm>();
|
||||
foreach (var item in selectParam)
|
||||
{
|
||||
//保存标准动作参数表
|
||||
sys_standard_action_parm parmmodel = new sys_standard_action_parm()
|
||||
{
|
||||
id = Guid.NewGuid().ToString(),
|
||||
standard_id = sysStandardAction.standard_id,
|
||||
action_id = sysStandardAction.process_id,
|
||||
action_seqno = sysStandardAction.process_no,
|
||||
parm_id = item.id,
|
||||
data_value = item.data_value,
|
||||
parm_seqno = 0
|
||||
};
|
||||
|
||||
actionParms.Add(parmmodel);
|
||||
|
||||
}
|
||||
|
||||
int val = sopBll.SaveStandardActionParam(actionParms);
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 确定命令
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
[RelayCommand]
|
||||
public void BtnOKClick()
|
||||
{
|
||||
|
||||
if (SelectParm != null)
|
||||
{
|
||||
List<sys_parm> selectParams = new List<sys_parm>();
|
||||
|
||||
selectParams.Add(SelectParm);
|
||||
|
||||
if (selectParams.Count > 0)
|
||||
{
|
||||
|
||||
if (SaveData(selectParams) > 0)
|
||||
{
|
||||
CloseAction?.Invoke(true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 取消命令
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
[RelayCommand]
|
||||
public void BtnCancelClick()
|
||||
{
|
||||
CloseAction?.Invoke(false);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user