添加项目文件。
This commit is contained in:
211
SamplePreSystem.UI/ViewModel/Child/ImportSampleViewModel.cs
Normal file
211
SamplePreSystem.UI/ViewModel/Child/ImportSampleViewModel.cs
Normal file
@@ -0,0 +1,211 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using Models.Models;
|
||||
using SamplePre.Models.Ext;
|
||||
using SamplePre.ProcessBll.SampleSequence;
|
||||
using SamplePreSystem.UI.ViewModel.SampleManager;
|
||||
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.Controls;
|
||||
using System.Windows.Data;
|
||||
using static MaterialDesignThemes.Wpf.Theme;
|
||||
|
||||
namespace SamplePreSystem.UI.ViewModel.Child
|
||||
{
|
||||
public partial class ImportSampleViewModel: ObservableObject
|
||||
{
|
||||
|
||||
SampleSequenceBll sampleSequenceBll = new SampleSequenceBll();
|
||||
|
||||
|
||||
|
||||
SampleExecViewModel sampleExecViewModel;
|
||||
|
||||
// 关闭窗口的委托
|
||||
public Action<bool> CloseAction { get; set; }
|
||||
|
||||
|
||||
|
||||
public ImportSampleViewModel(SampleExecViewModel _sampleExecViewModel)
|
||||
{
|
||||
GetData();
|
||||
|
||||
sampleExecViewModel = _sampleExecViewModel;
|
||||
}
|
||||
|
||||
|
||||
private DateTime _startDate = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00");
|
||||
|
||||
public DateTime StartDate
|
||||
{
|
||||
get { return _startDate; }
|
||||
set
|
||||
{
|
||||
|
||||
|
||||
SetProperty(ref _startDate, value);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private DateTime _endDate = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00");
|
||||
|
||||
public DateTime EndDate
|
||||
{
|
||||
get { return _endDate; }
|
||||
set
|
||||
{
|
||||
|
||||
SetProperty(ref _endDate, value);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private List<tube_input_ext> _sampleList = new List<tube_input_ext>();
|
||||
|
||||
|
||||
public List<tube_input_ext> SampleList
|
||||
{
|
||||
get { return _sampleList; }
|
||||
set {
|
||||
|
||||
SetProperty(ref _sampleList, value);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void GetData()
|
||||
{
|
||||
//DateTime dt1 = DateTime.Parse(dt_start.DateTime.ToString("yyyy-MM-dd") + " 00:00:00");
|
||||
//DateTime dt2 = DateTime.Parse(dt_end.DateTime.ToString("yyyy-MM-dd") + " 23:00:00");
|
||||
|
||||
var templist = sampleSequenceBll.GetTubeData(StartDate, EndDate); ///
|
||||
|
||||
List<tube_input_ext> samples = new List<tube_input_ext>();
|
||||
|
||||
foreach(var item in templist)
|
||||
{
|
||||
item.bach_no = $"批号:{item.bach_no}";
|
||||
|
||||
tube_input_ext model = new tube_input_ext();
|
||||
model.qrcode = item.qrcode;
|
||||
model.item_name = item.item_name;
|
||||
model.tube_type = item.tube_type;
|
||||
model.standrad_id = item.standrad_id;
|
||||
model.standrad = item.standrad;
|
||||
model.input_user = item.input_user;
|
||||
model.input_date = item.input_date;
|
||||
model.weight = item.weight;
|
||||
model.tube_count = item.tube_count;
|
||||
model.bach_no = $"批号:{item.bach_no}";
|
||||
model.IsSelected = false;
|
||||
samples.Add(model);
|
||||
}
|
||||
|
||||
SampleList = samples;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public bool? IsAllItems1Selected
|
||||
{
|
||||
get
|
||||
{
|
||||
var selected = SampleList.Select(item => item.IsSelected).Distinct().ToList();
|
||||
return selected.Count == 1 ? selected.Single() : false;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value.HasValue)
|
||||
{
|
||||
SelectAll(value.Value, SampleList);
|
||||
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 选择所有
|
||||
/// </summary>
|
||||
/// <param name="select"></param>
|
||||
/// <param name="models"></param>
|
||||
private static void SelectAll(bool select, IEnumerable<tube_input_ext> models)
|
||||
{
|
||||
foreach (var model in models)
|
||||
{
|
||||
model.IsSelected = select;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 选择组内数据
|
||||
/// </summary>
|
||||
/// <param name="bachCode"></param>
|
||||
/// <param name="isSelect"></param>
|
||||
public void SelectGroupData(string bachCode, bool isSelect)
|
||||
{
|
||||
foreach (var item in SampleList.Where(p => p.bach_no == bachCode))
|
||||
{
|
||||
item.IsSelected = isSelect;
|
||||
}
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
public void FindClick()
|
||||
{
|
||||
|
||||
GetData();
|
||||
|
||||
ListCollectionView view = (ListCollectionView)CollectionViewSource.GetDefaultView(SampleList);//获取数据视图
|
||||
//分组
|
||||
view.GroupDescriptions.Add(new PropertyGroupDescription("bach_no"));
|
||||
}
|
||||
|
||||
|
||||
[RelayCommand]
|
||||
public void ImportClick()
|
||||
{
|
||||
List<tube_input> samples = new List<tube_input>();
|
||||
foreach (var tube in SampleList)
|
||||
{
|
||||
|
||||
if (tube.IsSelected)
|
||||
{
|
||||
samples.Add(tube);
|
||||
}
|
||||
}
|
||||
|
||||
this.sampleExecViewModel.TubeInputs = samples;
|
||||
|
||||
CloseAction?.Invoke(true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 选中导入项
|
||||
/// </summary>
|
||||
[RelayCommand]
|
||||
public void CheckBoxClick(object groupName)
|
||||
{
|
||||
System.Windows.Controls.CheckBox checkBox = groupName as System.Windows.Controls.CheckBox;
|
||||
if (checkBox != null)
|
||||
{
|
||||
bool select = (bool)checkBox.IsChecked;
|
||||
string code = checkBox.Content.ToString();
|
||||
|
||||
SelectGroupData(code, select);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
120
SamplePreSystem.UI/ViewModel/Child/NewActionViewModel.cs
Normal file
120
SamplePreSystem.UI/ViewModel/Child/NewActionViewModel.cs
Normal file
@@ -0,0 +1,120 @@
|
||||
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<sys_dict> actionUnits;
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
public List<sys_dict> ActionUnits
|
||||
{
|
||||
get { return actionUnits; }
|
||||
set { actionUnits = value;
|
||||
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 选择的动作单元
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,171 @@
|
||||
using SamplePre.Models.Ext;
|
||||
using SamplePre.Models.Tables;
|
||||
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.ConfigManager
|
||||
{
|
||||
public class PermissionViewModel : INotifyPropertyChanged
|
||||
{
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
RolesBll rolesBll = new RolesBll();
|
||||
|
||||
config_role configRole;
|
||||
|
||||
public PermissionViewModel(RoleViewModel vm)
|
||||
{
|
||||
configRole = vm.ConfigRole;
|
||||
|
||||
RoleName = configRole.name;
|
||||
|
||||
GetData();
|
||||
}
|
||||
|
||||
protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
|
||||
private string _roleName;
|
||||
|
||||
public string RoleName
|
||||
{
|
||||
get { return _roleName; }
|
||||
set { _roleName = value; }
|
||||
}
|
||||
|
||||
|
||||
|
||||
private List<TreeItemModel> _funList = new List<TreeItemModel>();
|
||||
|
||||
public List<TreeItemModel> FunList
|
||||
{
|
||||
get { return _funList; }
|
||||
set { _funList = value;
|
||||
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void GetData()
|
||||
{
|
||||
var FunListTemp = rolesBll.GetFuncDataTree();
|
||||
|
||||
foreach (var item in FunListTemp.Where(p=>p.parent_id == 0))
|
||||
{
|
||||
// 根节点1
|
||||
var root1 = new TreeItemModel { Id = item.id, Name = item.name };
|
||||
foreach(var child in FunListTemp.Where(p => p.parent_id == item.id))
|
||||
{
|
||||
root1.Children.Add(new TreeItemModel { Id = child.id, Name = child.name, Parent = root1 });
|
||||
|
||||
}
|
||||
|
||||
FunList.Add(root1);
|
||||
}
|
||||
|
||||
|
||||
//选择中角色已有权限
|
||||
List<int> ids = rolesBll.GetPermission(configRole.id);
|
||||
LoadRolePermissions(ids);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载指定角色已分配的权限(用于编辑角色权限)
|
||||
/// </summary>
|
||||
/// <param name="roleFunctionIds">角色已拥有的功能ID列表</param>
|
||||
public void LoadRolePermissions(List<int> roleFunctionIds)
|
||||
{
|
||||
if (roleFunctionIds == null || roleFunctionIds.Count == 0) return;
|
||||
|
||||
foreach (var item in FunList)
|
||||
{
|
||||
bool isAll = true;
|
||||
foreach (var fuc in item.Children)
|
||||
{
|
||||
if (roleFunctionIds.Contains(fuc.Id))
|
||||
{
|
||||
fuc.IsChecked = true;
|
||||
//item.IsChecked = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
isAll = false;
|
||||
}
|
||||
}
|
||||
if(isAll)
|
||||
{
|
||||
item.IsChecked = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public bool SavePermission()
|
||||
{
|
||||
// 获取选中的功能ID列表
|
||||
List<int> selectedIds = GetSelectedFunctionIds();
|
||||
|
||||
if (selectedIds.Count == 0)
|
||||
{
|
||||
MessageBox.Show("请至少选择一个功能权限!", "提示");
|
||||
return false;
|
||||
}
|
||||
List<config_role_permisson> rolePermissonList = new List<config_role_permisson>();
|
||||
foreach (int item in selectedIds)
|
||||
{
|
||||
config_role_permisson rolePermisson = new config_role_permisson();
|
||||
rolePermisson.function_id = item;
|
||||
rolePermisson.role_id = configRole.id;
|
||||
rolePermissonList.Add(rolePermisson);
|
||||
}
|
||||
|
||||
|
||||
if (rolesBll.SavePermission(rolePermissonList) < 0)
|
||||
{
|
||||
MessageBox.Show("保存失败!");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private List<int> GetSelectedFunctionIds()
|
||||
{
|
||||
List<int> selectedIds = new List<int>();
|
||||
|
||||
foreach (var item in FunList)
|
||||
{
|
||||
foreach(var fuc in item.Children)
|
||||
{
|
||||
if(fuc.IsChecked)
|
||||
{
|
||||
//添加父节点功能id
|
||||
if(!selectedIds.Contains(item.Id))
|
||||
{
|
||||
selectedIds.Add(item.Id);
|
||||
}
|
||||
|
||||
selectedIds.Add(fuc.Id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return selectedIds;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
154
SamplePreSystem.UI/ViewModel/ConfigManager/RoleViewModel.cs
Normal file
154
SamplePreSystem.UI/ViewModel/ConfigManager/RoleViewModel.cs
Normal file
@@ -0,0 +1,154 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using SamplePre.Models.Tables;
|
||||
using SamplePre.ProcessBll.BLL;
|
||||
using SamplePre.UIWpf.ConfigManager.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.Controls;
|
||||
|
||||
namespace SamplePreSystem.UI.ViewModel.ConfigManager
|
||||
{
|
||||
public partial class RoleViewModel : ObservableObject
|
||||
{
|
||||
|
||||
RolesBll roleBll = new RolesBll();
|
||||
|
||||
public RoleViewModel()
|
||||
{
|
||||
|
||||
GetData();
|
||||
}
|
||||
|
||||
|
||||
|
||||
[ObservableProperty]
|
||||
private List<config_role> rolesList;
|
||||
|
||||
|
||||
[ObservableProperty]
|
||||
private config_role configRole = new config_role();
|
||||
|
||||
|
||||
|
||||
public void GetData()
|
||||
{
|
||||
|
||||
|
||||
RolesList = roleBll.GetRoles();
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存角色
|
||||
/// </summary>
|
||||
public bool SaveRole()
|
||||
{
|
||||
if(string.IsNullOrEmpty(ConfigRole.name.Trim()))
|
||||
{
|
||||
MessageBox.Show("角色名称不能为空!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(ConfigRole.id))
|
||||
{
|
||||
//new
|
||||
ConfigRole.id = Guid.NewGuid().ToString();
|
||||
|
||||
if (roleBll.SaveRoleData(ConfigRole) < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
if (roleBll.UpdateRoleData(ConfigRole) < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool DeleteRole()
|
||||
{
|
||||
if(!string.IsNullOrEmpty( ConfigRole.id ))
|
||||
{
|
||||
if (MessageBox.Show($"确定删除:{ConfigRole.name}", "提示",MessageBoxButton.OKCancel) == MessageBoxResult.OK)
|
||||
{
|
||||
if (roleBll.DeleteRole(ConfigRole) < 0)
|
||||
{
|
||||
MessageBox.Show("用户删除失败!");
|
||||
return false;
|
||||
}
|
||||
//刷新用户
|
||||
GetData();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 添加角色
|
||||
/// </summary>
|
||||
[RelayCommand]
|
||||
public void BtnAddClick()
|
||||
{
|
||||
ConfigRole = new config_role();
|
||||
NewRoleWindow frm = new NewRoleWindow(this);
|
||||
if (frm.ShowDialog() == true)
|
||||
{
|
||||
GetData();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 编辑角色
|
||||
/// </summary>
|
||||
[RelayCommand]
|
||||
public void BtnEditClick()
|
||||
{
|
||||
|
||||
|
||||
NewRoleWindow frm = new NewRoleWindow(this);
|
||||
if (frm.ShowDialog() == true)
|
||||
{
|
||||
GetData();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除角色
|
||||
/// </summary>
|
||||
[RelayCommand]
|
||||
public void BtnDeleClick()
|
||||
{
|
||||
DeleteRole();
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
public void BtnPermissonClick()
|
||||
{
|
||||
|
||||
|
||||
if (string.IsNullOrEmpty(ConfigRole.id)) return;
|
||||
PermissionWindow frm = new PermissionWindow(this);
|
||||
frm.ShowDialog();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,253 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using MaterialDesignThemes.Wpf;
|
||||
using Models.Models;
|
||||
using SamplePre.Models;
|
||||
using SamplePre.Models.Models;
|
||||
using SamplePre.ProcessBll.BLL;
|
||||
using SamplePreSystem.UI.ConfigManager.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.Controls;
|
||||
|
||||
namespace SamplePreSystem.UI.ViewModel.ConfigManager
|
||||
{
|
||||
public partial class SysConfigMangerViewModel : ObservableObject
|
||||
{
|
||||
|
||||
|
||||
SystemBll systemBll = new SystemBll();
|
||||
|
||||
public SysConfigMangerViewModel()
|
||||
{
|
||||
GetDictClassData();
|
||||
}
|
||||
|
||||
|
||||
private List<TreeItemModel> _dictClassList = new List<TreeItemModel>();
|
||||
|
||||
public List<TreeItemModel> DictClassList
|
||||
{
|
||||
get { return _dictClassList; }
|
||||
set {
|
||||
|
||||
SetProperty(ref _dictClassList, value);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private sys_dict_class _dictClass = new sys_dict_class();
|
||||
|
||||
public sys_dict_class DictClass
|
||||
{
|
||||
get { return _dictClass; }
|
||||
set {
|
||||
|
||||
SetProperty(ref _dictClass, value);
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取字典分类数据
|
||||
/// </summary>
|
||||
public void GetDictClassData()
|
||||
{
|
||||
List<TreeItemModel> list = new List<TreeItemModel>();
|
||||
//获取样本
|
||||
var dictClassTemp = systemBll.QueryDictClassData();
|
||||
|
||||
var root1 = new TreeItemModel() { Id = 0, Name = "系统配置", IconKind = PackIconKind.DnsOutline };
|
||||
foreach (var item in dictClassTemp)
|
||||
{
|
||||
root1.Children.Add(new TreeItemModel() { Id = item.id, Name = item.dict_type,Parent = root1 , IconKind = PackIconKind.FileDocumentOutline });
|
||||
}
|
||||
list.Add(root1);
|
||||
|
||||
DictClassList = list;
|
||||
}
|
||||
|
||||
|
||||
private List<sys_dict> _sysdicts = new List<sys_dict>();
|
||||
|
||||
public List<sys_dict> SysDicts
|
||||
{
|
||||
get { return _sysdicts; }
|
||||
set {
|
||||
|
||||
SetProperty(ref _sysdicts, value);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private sys_dict _sysDict = new sys_dict();
|
||||
|
||||
public sys_dict SysDict
|
||||
{
|
||||
get { return _sysDict; }
|
||||
set {
|
||||
|
||||
SetProperty(ref _sysDict, value);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 查询字典明细
|
||||
/// </summary>
|
||||
/// <param name="standID"></param>
|
||||
public void GetDictData(int classid)
|
||||
{
|
||||
//查询
|
||||
SysDicts = systemBll.QueryDictByClassId(classid);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public bool NewAddDict()
|
||||
{
|
||||
if (string.IsNullOrEmpty(this.DictClass.dict_type))
|
||||
{
|
||||
MessageBox.Show("内容不能为空");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
systemBll.SaveSysDictClass(DictClass);
|
||||
|
||||
//获取数据
|
||||
GetDictClassData();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void DeleteDict()
|
||||
{
|
||||
|
||||
if (MessageBox.Show($"确定移除:{DictClass.dict_type}", "提示",MessageBoxButton.OKCancel) == MessageBoxResult.OK)
|
||||
{
|
||||
//判断是否有子配置项
|
||||
if (this.systemBll.QueryDictByClassId(DictClass.id).Count > 0)
|
||||
{
|
||||
MessageBox.Show("存在配置子项目,不能删除!");
|
||||
return;
|
||||
}
|
||||
if (this.systemBll.DelDictClassById(DictClass.id) <= 0)
|
||||
{
|
||||
MessageBox.Show("删除失败!");
|
||||
return;
|
||||
}
|
||||
|
||||
//获取数据
|
||||
GetDictClassData();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public bool NewAddDictDetail()
|
||||
{
|
||||
if (SysDict == null || string.IsNullOrEmpty(this.SysDict.data_type) || string.IsNullOrEmpty(this.SysDict.data_value))
|
||||
{
|
||||
MessageBox.Show("内容不能为空");
|
||||
return false;
|
||||
}
|
||||
|
||||
SysDict.class_id = DictClass.id;
|
||||
SysDict.id = Guid.NewGuid().ToString();
|
||||
|
||||
|
||||
this.systemBll.SaveSysDict(SysDict);
|
||||
|
||||
//刷新
|
||||
GetDictData(DictClass.id);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void DeleteDictDetail()
|
||||
{
|
||||
|
||||
if (MessageBox.Show($"确定移除:{SysDict.data_type}", "提示", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
|
||||
{
|
||||
//移除
|
||||
this.systemBll.DelSysDictByid(SysDict);
|
||||
|
||||
//刷新
|
||||
GetDictData(DictClass.id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
public void AddClassClick()
|
||||
{
|
||||
//var vm = this.DataContext as SysConfigMangerViewModel;
|
||||
|
||||
//清空对象内容
|
||||
DictClass = new SamplePre.Models.Models.sys_dict_class();
|
||||
|
||||
NewDictClassWindow frm = new NewDictClassWindow(this);
|
||||
frm.ShowDialog();
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
public void DelClassClick()
|
||||
{
|
||||
DeleteDict();
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
public void TvDataSelectedItemChanged(RoutedPropertyChangedEventArgs<object> e)
|
||||
{
|
||||
//var vm = this.DataContext as SysConfigMangerViewModel;
|
||||
|
||||
var node = e.NewValue as TreeItemModel;
|
||||
|
||||
DictClass.dict_type = node.Name;
|
||||
DictClass.id = node.Id;
|
||||
|
||||
GetDictData(node.Id);
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
public void AddItemClick()
|
||||
{
|
||||
SysDict = new Models.Models.sys_dict();
|
||||
if (DictClass.id == null || DictClass.id == 0)
|
||||
{
|
||||
MessageBox.Show("请先选择分类");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
NewDictDetailWindow frm = new NewDictDetailWindow(this);
|
||||
frm.ShowDialog();
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
public void DelItemClick()
|
||||
{
|
||||
DeleteDictDetail();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
80
SamplePreSystem.UI/ViewModel/ConfigManager/TreeItemModel.cs
Normal file
80
SamplePreSystem.UI/ViewModel/ConfigManager/TreeItemModel.cs
Normal file
@@ -0,0 +1,80 @@
|
||||
using MaterialDesignThemes.Wpf;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SamplePreSystem.UI.ViewModel.ConfigManager
|
||||
{
|
||||
public class TreeItemModel : INotifyPropertyChanged
|
||||
{
|
||||
public bool IsUpdate = true;
|
||||
|
||||
private bool _isChecked;
|
||||
public bool IsChecked
|
||||
{
|
||||
get { return _isChecked; }
|
||||
set
|
||||
{
|
||||
_isChecked = value;
|
||||
|
||||
OnPropertyChanged();
|
||||
|
||||
if (Children.Count > 0)
|
||||
{
|
||||
SetChildrenCheck(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
//if (Parent != null) Parent.IsChecked = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
||||
|
||||
// 父节点改变子节点
|
||||
private void SetChildrenCheck(bool isChecked)
|
||||
{
|
||||
foreach (var child in Children)
|
||||
{
|
||||
child.IsChecked = isChecked;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 子节点改变后,更新父节点状态
|
||||
private void UpdateParentState(bool isChecked)
|
||||
{
|
||||
if (Parent == null) return;
|
||||
|
||||
//bool anyChecked = Parent.Children.Any(x => x.IsChecked);
|
||||
Parent.IsChecked = isChecked;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 子节点
|
||||
public List<TreeItemModel> Children { get; set; } = new List<TreeItemModel>();
|
||||
|
||||
// 父节点(用于联动)
|
||||
public TreeItemModel Parent { get; set; }
|
||||
|
||||
public PackIconKind IconKind { get; set; }
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
286
SamplePreSystem.UI/ViewModel/ConfigManager/UsersViewModel.cs
Normal file
286
SamplePreSystem.UI/ViewModel/ConfigManager/UsersViewModel.cs
Normal file
@@ -0,0 +1,286 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using SamplePre.Models.Ext;
|
||||
using SamplePre.Models.Tables;
|
||||
using SamplePre.ProcessBll.BLL;
|
||||
using SamplePre.UIWpf.ConfigManager.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.Controls;
|
||||
using System.Windows.Documents;
|
||||
|
||||
namespace SamplePreSystem.UI.ViewModel.ConfigManager
|
||||
{
|
||||
public partial class UsersViewModel : ObservableObject
|
||||
{
|
||||
|
||||
|
||||
UsersBll usersBll = new UsersBll();
|
||||
|
||||
// 关闭窗口的委托
|
||||
public Action<bool> CloseAction { get; set; }
|
||||
|
||||
public UsersViewModel()
|
||||
{
|
||||
//获取用户数据
|
||||
GetData();
|
||||
|
||||
}
|
||||
|
||||
private List<config_user_ext> _userList = new List<config_user_ext>();
|
||||
|
||||
public List<config_user_ext> UserList
|
||||
{
|
||||
get { return _userList; }
|
||||
set {
|
||||
SetProperty(ref _userList, value);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private config_user_ext _selectUser;
|
||||
|
||||
public config_user_ext SelectUser
|
||||
{
|
||||
get { return _selectUser; }
|
||||
set { _selectUser = value; }
|
||||
}
|
||||
|
||||
|
||||
|
||||
private config_user_ext _configUser =new config_user_ext();
|
||||
|
||||
public config_user_ext ConfigUser
|
||||
{
|
||||
get { return _configUser; }
|
||||
set {
|
||||
SetProperty(ref _configUser, value);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 查询用户
|
||||
/// </summary>
|
||||
public void GetData()
|
||||
{
|
||||
|
||||
UserList = usersBll.GetUsers();
|
||||
|
||||
}
|
||||
|
||||
private List<config_role_ext> roles = new List<config_role_ext>();
|
||||
|
||||
public List<config_role_ext> Roles
|
||||
{
|
||||
get { return roles; }
|
||||
set {
|
||||
SetProperty(ref roles, roles);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 绑定角色数据
|
||||
/// </summary>
|
||||
public void InitCheckedListBox()
|
||||
{
|
||||
Roles.Clear();
|
||||
var roleList = usersBll.GetRoles();
|
||||
|
||||
|
||||
|
||||
|
||||
foreach (var item in roleList)
|
||||
{
|
||||
config_role_ext model = new config_role_ext();
|
||||
model.id = item.id;
|
||||
model.name = item.name;
|
||||
model.description = item.description;
|
||||
model.IsSelected = false;
|
||||
|
||||
Roles.Add(model);
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (!string.IsNullOrEmpty(ConfigUser.id))
|
||||
{
|
||||
//获取用户的角色
|
||||
var userRoles = usersBll.GetUserRoles(ConfigUser.id);
|
||||
|
||||
foreach(var item in Roles)
|
||||
{
|
||||
if(userRoles.Where(p=>p.role_id == item.id).Count() > 0)
|
||||
{
|
||||
item.IsSelected = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private string isEnable = "启用";
|
||||
|
||||
public string IsEnable
|
||||
{
|
||||
get { return isEnable; }
|
||||
set {
|
||||
|
||||
SetProperty(ref isEnable, isEnable);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public bool SaveUser()
|
||||
{
|
||||
if (ConfigUser == null) return false;
|
||||
|
||||
//ConfigUser.username = this.txtUserName.Text;
|
||||
//ConfigUser.password = this.txtPwd.Text;
|
||||
ConfigUser.is_enabled = IsEnable == "启用" ? true : false;
|
||||
|
||||
if (string.IsNullOrEmpty(ConfigUser.id))
|
||||
{
|
||||
//new
|
||||
ConfigUser.id = Guid.NewGuid().ToString();
|
||||
|
||||
//选中的角色
|
||||
var roles = GetCheckedData();
|
||||
|
||||
if (usersBll.SaveUserData(ConfigUser, roles) < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
//update
|
||||
|
||||
//选中的角色
|
||||
var roles = GetCheckedData();
|
||||
|
||||
if (usersBll.UpdateUserData(ConfigUser, roles) < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取用户角色
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public List<config_user_role> GetCheckedData()
|
||||
{
|
||||
List<config_user_role> userRoles = new List<config_user_role>();
|
||||
|
||||
|
||||
foreach (var role in Roles)
|
||||
{
|
||||
if(role.IsSelected)
|
||||
{
|
||||
//config_role item = cbRoles.GetItem(i) as config_role;
|
||||
|
||||
config_user_role configUserRole = new config_user_role();
|
||||
configUserRole.role_id = role.id.ToString();
|
||||
configUserRole.user_id = ConfigUser.id;
|
||||
|
||||
userRoles.Add(configUserRole);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
return userRoles;
|
||||
}
|
||||
|
||||
|
||||
public bool DeleUser()
|
||||
{
|
||||
if(SelectUser != null)
|
||||
{
|
||||
config_user user = SelectUser;
|
||||
|
||||
if (MessageBox.Show($"是否真的删除{user.username}", "删除提示", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
|
||||
{
|
||||
if (usersBll.DeleteUser(user) < 0)
|
||||
{
|
||||
MessageBox.Show("用户删除失败!");
|
||||
return false;
|
||||
}
|
||||
//刷新用户
|
||||
GetData();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
[RelayCommand]
|
||||
public void BtnAddClick()
|
||||
{
|
||||
ConfigUser = new config_user_ext();
|
||||
|
||||
//初始化角色数据
|
||||
InitCheckedListBox();
|
||||
|
||||
NewUserWindow frm = new NewUserWindow(this);
|
||||
if (frm.ShowDialog() == true)
|
||||
{
|
||||
//刷新数据
|
||||
GetData();
|
||||
}
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
public void BtnEditClick()
|
||||
{
|
||||
ConfigUser = SelectUser;
|
||||
//初始化角色数据
|
||||
InitCheckedListBox();
|
||||
|
||||
NewUserWindow frm = new NewUserWindow(this);
|
||||
if (frm.ShowDialog() == true)
|
||||
{
|
||||
//刷新数据
|
||||
GetData();
|
||||
}
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
public void BtnDeleClick()
|
||||
{
|
||||
DeleUser();
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
public void BtnSaveUserClick()
|
||||
{
|
||||
|
||||
if (SaveUser() == true)
|
||||
{
|
||||
this.CloseAction?.Invoke(true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
118
SamplePreSystem.UI/ViewModel/Login/AppMainViewModel.cs
Normal file
118
SamplePreSystem.UI/ViewModel/Login/AppMainViewModel.cs
Normal file
@@ -0,0 +1,118 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using MaterialDesignThemes.Wpf;
|
||||
using Models.Const;
|
||||
using SamplePre.Communication;
|
||||
using SamplePre.Models.Tables;
|
||||
using SamplePre.ProcessBll.BLL;
|
||||
using SamplePreSystem.UI;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SamplePreSystem.UI.ViewModel.Login
|
||||
{
|
||||
public partial class AppMainViewModel:ObservableObject
|
||||
{
|
||||
|
||||
SystemBll systemBll = new SystemBll();
|
||||
|
||||
public AppMainViewModel() {
|
||||
|
||||
|
||||
|
||||
//初始化权限信息
|
||||
InitPermisson();
|
||||
|
||||
//GetFunctionList();
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 功能菜单
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
public List<MenuBarFuc> menuBars = new List<MenuBarFuc>();
|
||||
|
||||
/// <summary>
|
||||
/// 初始化权限信息
|
||||
/// </summary>
|
||||
private void InitPermisson()
|
||||
{
|
||||
|
||||
if (SystemConst.loginUserInfo.functions == null) return;
|
||||
|
||||
List<MenuBarFuc> newData = new List<MenuBarFuc>();
|
||||
|
||||
foreach (var item in SystemConst.loginUserInfo.functions.Where(p => p.parent_id == 0))
|
||||
{
|
||||
foreach (var newItem in SystemConst.loginUserInfo.functions.Where(p => p.parent_id == item.id).ToList())
|
||||
{
|
||||
MenuBarFuc menuBarFuc = new MenuBarFuc();
|
||||
menuBarFuc.id = newItem.id;
|
||||
menuBarFuc.name = newItem.name;
|
||||
menuBarFuc.code = newItem.code;
|
||||
menuBarFuc.description = item.name;
|
||||
menuBarFuc.parent_id = newItem.parent_id;
|
||||
menuBarFuc.packIconKind = GetIconKind(menuBarFuc.id);
|
||||
|
||||
|
||||
newData.Add(menuBarFuc);
|
||||
}
|
||||
|
||||
}
|
||||
MenuBars = newData;
|
||||
|
||||
|
||||
UserInfo = SystemConst.loginUserInfo.user.username;
|
||||
}
|
||||
|
||||
public string UserInfo { get; set; }
|
||||
|
||||
private PackIconKind GetIconKind(int id)
|
||||
{
|
||||
switch (id)
|
||||
{
|
||||
case 5:
|
||||
return PackIconKind.CameraMeteringMatrix;
|
||||
case 6:
|
||||
return PackIconKind.ClipboardListOutline;
|
||||
case 8:
|
||||
return PackIconKind.FileFindOutline;
|
||||
case 9:
|
||||
return PackIconKind.TagSearch;
|
||||
|
||||
case 10:
|
||||
return PackIconKind.CollapseAllOutline;
|
||||
case 11:
|
||||
return PackIconKind.ContentDuplicate;
|
||||
case 12:
|
||||
return PackIconKind.Console;
|
||||
|
||||
|
||||
case 13:
|
||||
return PackIconKind.AccountOutline;
|
||||
case 14:
|
||||
return PackIconKind.CardAccountDetails;
|
||||
case 15:
|
||||
return PackIconKind.CogOutline;
|
||||
|
||||
default:
|
||||
return PackIconKind.CogOutline;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
113
SamplePreSystem.UI/ViewModel/Login/LoginViewModel.cs
Normal file
113
SamplePreSystem.UI/ViewModel/Login/LoginViewModel.cs
Normal file
@@ -0,0 +1,113 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using SamplePre.ProcessBll.BLL;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Security.Principal;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace SamplePreSystem.UI.ViewModel.Login
|
||||
{
|
||||
public partial class LoginViewModel : ObservableObject
|
||||
{
|
||||
|
||||
|
||||
UsersBll usersBll = new UsersBll();
|
||||
|
||||
/// <summary>
|
||||
/// 关闭委托
|
||||
/// </summary>
|
||||
public Action<bool> ColseAction;
|
||||
|
||||
//保持用户名
|
||||
public Action<string> SaveUserAction;
|
||||
|
||||
public LoginViewModel()
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
[ObservableProperty]
|
||||
public string errInfo = "";
|
||||
|
||||
[ObservableProperty]
|
||||
public bool isSaveUser = false;
|
||||
|
||||
[ObservableProperty]
|
||||
public string userName = "";
|
||||
|
||||
|
||||
[ObservableProperty]
|
||||
public string userPwd = "";
|
||||
|
||||
|
||||
|
||||
public bool UserChecked()
|
||||
{
|
||||
|
||||
if (usersBll.CheckUser(UserName, UserPwd) == false)
|
||||
{
|
||||
|
||||
ErrInfo = "登录账号或密码错误!";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (IsSaveUser == true)
|
||||
{
|
||||
SaveUserAction?.Invoke(UserName);
|
||||
|
||||
}
|
||||
|
||||
ColseAction?.Invoke(true);
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 登录
|
||||
/// </summary>
|
||||
[RelayCommand]
|
||||
public void LoginButtonClick()
|
||||
{
|
||||
UserChecked();
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 回车登录
|
||||
/// </summary>
|
||||
/// <param name="e"></param>
|
||||
[RelayCommand]
|
||||
public void PwdKeyDown(KeyEventArgs e)
|
||||
{
|
||||
if (e.Key == Key.Enter)
|
||||
{
|
||||
UserChecked();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 退出
|
||||
/// </summary>
|
||||
[RelayCommand]
|
||||
public void CancelClick()
|
||||
{
|
||||
ColseAction?.Invoke(false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
20
SamplePreSystem.UI/ViewModel/Login/MenuBarFuc.cs
Normal file
20
SamplePreSystem.UI/ViewModel/Login/MenuBarFuc.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using MaterialDesignThemes.Wpf;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SamplePreSystem.UI.ViewModel.Login
|
||||
{
|
||||
public class MenuBarFuc
|
||||
{
|
||||
public int id { get; set; } // 功能ID
|
||||
public string name { get; set; } // 功能名称(如:用户管理、角色新增)
|
||||
public string code { get; set; } // 功能编码(唯一标识,如:User_Manage)
|
||||
public int parent_id { get; set; } // 父功能编码(用于构建菜单层级)
|
||||
public string description { get; set; } // 功能描述
|
||||
|
||||
public PackIconKind packIconKind { get; set; }
|
||||
}
|
||||
}
|
||||
72
SamplePreSystem.UI/ViewModel/Login/UserInfoViewModel.cs
Normal file
72
SamplePreSystem.UI/ViewModel/Login/UserInfoViewModel.cs
Normal file
@@ -0,0 +1,72 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Models.Const;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SamplePreSystem.UI.ViewModel.Login
|
||||
{
|
||||
public partial class UserInfoViewModel :ObservableObject
|
||||
{
|
||||
[ObservableProperty]
|
||||
public string userName;
|
||||
|
||||
[ObservableProperty]
|
||||
public string userRoles;
|
||||
|
||||
public UserInfoViewModel()
|
||||
{
|
||||
|
||||
InitializeUserInfo();
|
||||
}
|
||||
|
||||
|
||||
private void InitializeUserInfo()
|
||||
{
|
||||
// 获取当前登录用户信息
|
||||
if (SystemConst.loginUserInfo != null && SystemConst.loginUserInfo.user != null)
|
||||
{
|
||||
UserName = SystemConst.loginUserInfo.user.username;
|
||||
|
||||
// 这里需要获取用户角色信息
|
||||
// 由于当前登录用户信息中没有直接包含角色信息,我们需要通过查询获取
|
||||
// 这里暂时显示占位符,实际项目中需要从数据库查询
|
||||
UserRoles = "获取中...";
|
||||
|
||||
// 异步获取角色信息
|
||||
Task.Run(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
// 这里应该调用BLL层的方法获取用户角色
|
||||
// 由于系统中已有UsersBll类,我们可以使用它
|
||||
SamplePre.ProcessBll.BLL.UsersBll usersBll = new SamplePre.ProcessBll.BLL.UsersBll();
|
||||
var userExt = usersBll.GetUsers().FirstOrDefault(u => u.username == UserName);
|
||||
|
||||
if (userExt != null)
|
||||
{
|
||||
UserRoles = userExt.all_role_names;
|
||||
}
|
||||
else
|
||||
{
|
||||
UserRoles = "未知角色";
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
UserRoles = "获取角色失败";
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
UserName = "未登录";
|
||||
UserRoles = "无";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
57
SamplePreSystem.UI/ViewModel/Monitor/FaultInfo.cs
Normal file
57
SamplePreSystem.UI/ViewModel/Monitor/FaultInfo.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
//using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace SamplePreSystem.UI.ViewModel.Monitor
|
||||
{
|
||||
/// <summary>
|
||||
/// 监控故障信息实体
|
||||
/// </summary>
|
||||
public class FaultInfo :INotifyPropertyChanged
|
||||
{
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
public string FaultName { get; set; } // 故障名称
|
||||
|
||||
public string FaultDesc { get; set; } // 故障描述
|
||||
public FaultType FaultType { get; set; } // 故障类型
|
||||
|
||||
private Brush runColor = Brushes.Orange;
|
||||
|
||||
|
||||
|
||||
public Brush RunColor
|
||||
{
|
||||
get { return runColor; }
|
||||
set
|
||||
{
|
||||
runColor = value;
|
||||
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
// 定义故障类型枚举
|
||||
public enum FaultType
|
||||
{
|
||||
Warning = 0, // 警告
|
||||
Error = 1, // 错误
|
||||
Critical = 2, // 严重错误
|
||||
Run = 3 // 严重错误
|
||||
}
|
||||
}
|
||||
549
SamplePreSystem.UI/ViewModel/Monitor/MonitorViewModel.cs
Normal file
549
SamplePreSystem.UI/ViewModel/Monitor/MonitorViewModel.cs
Normal file
@@ -0,0 +1,549 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using MaterialDesignThemes.Wpf;
|
||||
using Models.Const;
|
||||
using Models.Models;
|
||||
using SamplePre.Common;
|
||||
using SamplePre.Communication.Communication;
|
||||
using SamplePre.Models;
|
||||
using SamplePre.Models.Ext;
|
||||
using SamplePre.ProcessBll.BLL;
|
||||
using SamplePre.ProcessBll.SampleSequence;
|
||||
using SamplePre.UIWpf.MonitorManager.chirld;
|
||||
using SamplePre.UIWpf.SampleManager.chirld;
|
||||
using SamplePreSystem.UI.Views.MonitorManager;
|
||||
|
||||
|
||||
//using SamplePre.UIWpf.Properties;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Threading;
|
||||
using static MaterialDesignThemes.Wpf.Theme.ToolBar;
|
||||
|
||||
namespace SamplePreSystem.UI.ViewModel.Monitor
|
||||
{
|
||||
public partial class MonitorViewModel: ObservableObject
|
||||
{
|
||||
|
||||
SampleSequenceBll sampleSequenceBll = new SampleSequenceBll();
|
||||
|
||||
ActionMangerBll actionMangerBll = new ActionMangerBll();
|
||||
|
||||
MonitorBll monitorBll = new MonitorBll();
|
||||
|
||||
CommunicationBll communicationBll = new CommunicationBll();
|
||||
|
||||
SOPManagerBll sopManagerBll = new SOPManagerBll();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 所有动作
|
||||
/// </summary>
|
||||
List<sys_action_ext> sys_Actions = new List<sys_action_ext>();
|
||||
|
||||
|
||||
public MonitorViewModel()
|
||||
{
|
||||
//所有动作
|
||||
sys_Actions = actionMangerBll.QuerySysAction();
|
||||
|
||||
GetSampleData();
|
||||
|
||||
//初始化功能单元
|
||||
InitWorkUnits();
|
||||
|
||||
///启动数据监控线程
|
||||
UpdateMonitorData();
|
||||
|
||||
Test();
|
||||
|
||||
|
||||
//获取当前SOP所有动作列表
|
||||
GetCurrentSopByID(this.CurrentSopID);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前SOP所有动作列表
|
||||
/// </summary>
|
||||
/// <param name="sopID"></param>
|
||||
public void GetCurrentSopByID(string sopID)
|
||||
{
|
||||
CurrentstandardActionList = sopManagerBll.QueryStandardActionByStandardId(sopID)?.OrderBy(p => p.process_no).ToList(); ;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 计算进度百分比
|
||||
/// </summary>
|
||||
/// <param name="actionID"></param>
|
||||
public void CalculationProgress(string actionID)
|
||||
{
|
||||
if (CurrentstandardActionList.Count <= 0) return;
|
||||
|
||||
var item = CurrentstandardActionList.Where(p => p.process_id == actionID && p.ExecFinishFlag == false).FirstOrDefault();
|
||||
if (item != null)
|
||||
{
|
||||
item.ExecFinishFlag = true;
|
||||
|
||||
int finishcount = CurrentstandardActionList.Count(p => p.ExecFinishFlag == true);
|
||||
int totalcount = CurrentstandardActionList.Count;
|
||||
|
||||
double percent = (float)finishcount / totalcount;
|
||||
|
||||
CurrentPercent = Math.Round(percent * 100,0);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 当前SOP_ID
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
public string currentSopID = "";
|
||||
|
||||
/// <summary>
|
||||
/// 当前百分比
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
public double currentPercent = 10;
|
||||
|
||||
/// <summary>
|
||||
/// 当前SOP动作
|
||||
/// </summary>
|
||||
public List<sys_standard_action_ext> CurrentstandardActionList = new List<sys_standard_action_ext>();
|
||||
|
||||
public void Test()
|
||||
{
|
||||
SopExecInfo.Add(new SopExecInfo()
|
||||
{
|
||||
sapmleName = "DCM固相萃取",
|
||||
actionName = "加液",
|
||||
starDate = DateTime.Now,
|
||||
endDate = DateTime.Now,
|
||||
state = "完成",
|
||||
doIngShow = false
|
||||
|
||||
});
|
||||
SopExecInfo.Add(new SopExecInfo()
|
||||
{
|
||||
sapmleName = "DCM固相萃取",
|
||||
actionName = "加液",
|
||||
starDate = DateTime.Now,
|
||||
endDate = DateTime.Now,
|
||||
state = "完成",
|
||||
doIngShow = false
|
||||
});
|
||||
SopExecInfo.Add(new SopExecInfo()
|
||||
{
|
||||
sapmleName = "DCM固相萃取",
|
||||
actionName = "加液",
|
||||
starDate = DateTime.Now,
|
||||
endDate = DateTime.Now,
|
||||
state = "完成",
|
||||
doIngShow = false
|
||||
|
||||
});
|
||||
SopExecInfo.Add(new SopExecInfo()
|
||||
{
|
||||
sapmleName = "DCM固相萃取",
|
||||
actionName = "离心",
|
||||
starDate = DateTime.Now,
|
||||
endDate = DateTime.Now,
|
||||
state = "执行",
|
||||
doIngShow = true
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
private List<sample_exec_detail_ext> _sampleExecList = new List<sample_exec_detail_ext>();
|
||||
|
||||
|
||||
public List<sample_exec_detail_ext> SampleExecList
|
||||
{
|
||||
get { return _sampleExecList; }
|
||||
set {
|
||||
|
||||
SetProperty(ref _sampleExecList, value);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private string _sopExecData;
|
||||
|
||||
public string SopExecData
|
||||
{
|
||||
get { return _sopExecData; }
|
||||
set {
|
||||
|
||||
SetProperty(ref _sopExecData, value);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取样本信息
|
||||
/// </summary>
|
||||
/// <param name="standID"></param>
|
||||
private void GetSampleData()
|
||||
{
|
||||
|
||||
List<sample_exec_detail_ext> samples = sampleSequenceBll.GetSampleExecDetails();
|
||||
SampleExecList = samples;
|
||||
|
||||
//设置当前SOP——ID
|
||||
string standrad_id = samples.FirstOrDefault()?.standrad_id;
|
||||
if (!string.IsNullOrEmpty(standrad_id))
|
||||
{
|
||||
if(standrad_id.Contains(","))
|
||||
{
|
||||
CurrentSopID = standrad_id.Split(",")[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
CurrentSopID = standrad_id;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private List<WorkUnit> _workUnits = new List<WorkUnit>();
|
||||
|
||||
public List<WorkUnit> WorkUnits
|
||||
{
|
||||
get { return _workUnits; }
|
||||
set {
|
||||
|
||||
SetProperty(ref _workUnits, value);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化功能岛
|
||||
/// </summary>
|
||||
public void InitWorkUnits()
|
||||
{
|
||||
|
||||
var list = SystemConst.dictDatas.Where(p => p.class_id == 2).ToList();
|
||||
foreach (var item in list)
|
||||
{
|
||||
string imgPath = GetIcon(item.id);
|
||||
|
||||
var icon = GetIconKind(item.id);
|
||||
|
||||
WorkUnits.Add(new WorkUnit() { actionName= "无", state = 0, StateName = "未连通", unitCode = item.id, unitName = item.data_type ,imgPath = imgPath,packIconKind = icon });
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 故障信息
|
||||
/// </summary>
|
||||
private ObservableCollection<FaultInfo> faultInfos = new ObservableCollection<FaultInfo>();
|
||||
|
||||
public ObservableCollection<FaultInfo> FaultInfos
|
||||
{
|
||||
get { return faultInfos; }
|
||||
set {
|
||||
|
||||
SetProperty(ref faultInfos, value);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 更新监控数据
|
||||
/// </summary>
|
||||
public void UpdateMonitorData()
|
||||
{
|
||||
//if (tileGroup2.Items.Count <= 0) return;
|
||||
|
||||
Task.Factory.StartNew(async () => {
|
||||
|
||||
try
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
//ushort[] data1 = SystemConst.MasterPLC.ReadArraysShort(100, 1000, 1000);
|
||||
ushort[] data1 = communicationBll.ReadSateData(100, 1000, 1000);
|
||||
|
||||
//跨线程
|
||||
Application.Current?.Dispatcher.Invoke(() =>
|
||||
{
|
||||
FaultInfos.Clear();
|
||||
});
|
||||
|
||||
//刷新功能岛
|
||||
UpdateWorkUnit(data1);
|
||||
|
||||
|
||||
//刷新样品列表
|
||||
GetSampleData();
|
||||
|
||||
await Task.Delay(3000);
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
LoggerHelper.Logger.Error("更新监控数据异常退出:" + ex.Message + ex.StackTrace);
|
||||
}
|
||||
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新功能岛信息
|
||||
/// </summary>
|
||||
/// <param name="data1"></param>
|
||||
public void UpdateWorkUnit(ushort[] data1)
|
||||
{
|
||||
//WorkUnits
|
||||
if (data1 != null && data1.Length > 0)
|
||||
{
|
||||
|
||||
foreach(var workUnit in WorkUnits)
|
||||
{
|
||||
var unit_actions = sys_Actions.Where(p => p.action_unit == workUnit.unitCode).ToList();
|
||||
foreach (var action in unit_actions)
|
||||
{
|
||||
int plcCode = int.Parse(action.plc_type);
|
||||
ushort state = data1[plcCode];//动作的状态码
|
||||
|
||||
//UCFunUnit uCFunUnit = this.dictUnits[unitCode];
|
||||
if(state >= 2)
|
||||
{
|
||||
//处理sop执行状态,计算执行百分比
|
||||
CalculationProgress(action.id);
|
||||
|
||||
}
|
||||
|
||||
if (state >= workUnit.state || state == 2)
|
||||
{ //发生改变再修改
|
||||
if (workUnit.state != state || workUnit.actionName != action.action_name)
|
||||
{
|
||||
workUnit.state = state;
|
||||
workUnit.StateName = SetStateData(state);
|
||||
workUnit.RunColor = WorkUnit.GetStateColor(state);
|
||||
workUnit.actionName = state < 2 ? "无" : action.action_name;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
//如果动作一样,状态发生变化,就要修改
|
||||
if (workUnit.state != state && workUnit.actionName == action.action_name)
|
||||
{
|
||||
workUnit.state = state;
|
||||
workUnit.StateName = SetStateData(state);
|
||||
workUnit.RunColor = WorkUnit.GetStateColor(state);
|
||||
workUnit.actionName = state < 2 ? "无" : action.action_name;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
//添加故障信息
|
||||
if (workUnit.state == 0)
|
||||
{
|
||||
Application.Current?.Dispatcher.BeginInvoke(new Action(() => {
|
||||
FaultInfos.Add(new FaultInfo { FaultName = workUnit.unitName + " - 未连通", FaultType = FaultType.Warning });
|
||||
}), DispatcherPriority.Normal);
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public string GetIcon(string code)
|
||||
{
|
||||
switch (code)
|
||||
{
|
||||
case "300":
|
||||
return "/Assets/机器人1.png";//Resources.机器人1;
|
||||
|
||||
case "301":
|
||||
return "/Assets/分液1.png";//Resources.分液1;
|
||||
|
||||
case "302":
|
||||
return "/Assets/离心机1.png";//Resources.离心机1;
|
||||
|
||||
case "303":
|
||||
return "/Assets/氮吹1.png";
|
||||
|
||||
case "304":
|
||||
return "/Assets/固相萃取1.png";//Resources.固相萃取1;
|
||||
|
||||
default:
|
||||
return "/Assets/机器人1.png";//Resources.机器人1;
|
||||
}
|
||||
}
|
||||
|
||||
public PackIconKind GetIconKind(string code)
|
||||
{
|
||||
switch (code)
|
||||
{
|
||||
case "300":
|
||||
return PackIconKind.RobotIndustrialOutline;//Resources.机器人1;
|
||||
|
||||
case "301":
|
||||
return PackIconKind.TestTube;//Resources.分液1;
|
||||
|
||||
case "302":
|
||||
return PackIconKind.GoogleCirclesCommunities;//Resources.离心机1;
|
||||
|
||||
case "303":
|
||||
return PackIconKind.GoogleCirclesGroup;
|
||||
|
||||
case "304":
|
||||
return PackIconKind.InboxMultiple;//Resources.固相萃取1;
|
||||
|
||||
default:
|
||||
return PackIconKind.ThermometerWater; //Resources.机器人1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public string SetStateData(int state)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
if (state == 0)
|
||||
{
|
||||
return "未连接";
|
||||
|
||||
|
||||
}
|
||||
if (state == 1)
|
||||
{
|
||||
return "待机";
|
||||
}
|
||||
else if (state == 2)
|
||||
{
|
||||
return "运行";
|
||||
|
||||
|
||||
}
|
||||
else if (state == 3)
|
||||
{
|
||||
return "完成";
|
||||
}
|
||||
|
||||
|
||||
return "未连接";
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LoggerHelper.Logger.Error(ex.Message + ex.StackTrace);
|
||||
return "未连接";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
SocketClient client;
|
||||
/// <summary>
|
||||
/// 启动socket
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task StarClientAsync()
|
||||
{
|
||||
client = new SocketClient();
|
||||
|
||||
//回调函数
|
||||
client.ReceiveMsgAction = UpdateSopExecInfo;
|
||||
|
||||
await client.StartClientAsync();
|
||||
}
|
||||
|
||||
public void SendSocketTest(string msg)
|
||||
{
|
||||
client.SendMsgAsync(msg);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新sop执行信息
|
||||
/// </summary>
|
||||
/// <param name="receiveData"></param>
|
||||
public void UpdateSopExecInfo(string receiveData)
|
||||
{
|
||||
SopExecData += receiveData + "\r\n";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// sop执行信息
|
||||
/// </summary>
|
||||
private List<SopExecInfo> sopExecInfo = new List<SopExecInfo>();
|
||||
|
||||
public List<SopExecInfo> SopExecInfo
|
||||
{
|
||||
get { return sopExecInfo; }
|
||||
set { sopExecInfo = value; }
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 打开详情窗口
|
||||
/// </summary>
|
||||
[RelayCommand]
|
||||
public void HLinkDetailClick(string unitName)
|
||||
{
|
||||
|
||||
var param = unitName;
|
||||
var item = SystemConst.dictDatas.Where(p => p.data_type == param.ToString() && p.class_id == 2).FirstOrDefault();
|
||||
if (item != null)
|
||||
{
|
||||
UnitDetailWindow frm = new UnitDetailWindow(item.id);
|
||||
frm.ShowDialog();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 打开明细进度窗口
|
||||
/// </summary>
|
||||
[RelayCommand]
|
||||
public void MouseDoubleDetailWindow()
|
||||
{
|
||||
SampleDetailWindow frm = new SampleDetailWindow();
|
||||
frm.ShowDialog();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
110
SamplePreSystem.UI/ViewModel/Monitor/UnitDetailViewModel.cs
Normal file
110
SamplePreSystem.UI/ViewModel/Monitor/UnitDetailViewModel.cs
Normal file
@@ -0,0 +1,110 @@
|
||||
using SamplePre.Models;
|
||||
using SamplePre.ProcessBll.BLL;
|
||||
using SamplePre.ProcessBll.SampleSequence;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SamplePreSystem.UI.ViewModel.Monitor
|
||||
{
|
||||
public class UnitDetailViewModel : INotifyPropertyChanged
|
||||
{
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
MonitorBll monitorBll = new MonitorBll();
|
||||
|
||||
CommunicationBll communicationBll = new CommunicationBll();
|
||||
|
||||
ActionMangerBll actionMangerBll = new ActionMangerBll();
|
||||
|
||||
string unitID;
|
||||
public UnitDetailViewModel(string _unitID)
|
||||
{
|
||||
unitID = _unitID;
|
||||
|
||||
ShowActionInfo();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 动作状态信息
|
||||
/// </summary>
|
||||
private ObservableCollection<FaultInfo> faultInfos = new ObservableCollection<FaultInfo>();
|
||||
|
||||
public ObservableCollection<FaultInfo> FaultInfos
|
||||
{
|
||||
get { return faultInfos; }
|
||||
set
|
||||
{
|
||||
faultInfos = value;
|
||||
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 设置异常数据显示
|
||||
/// </summary>
|
||||
public void ShowActionInfo()
|
||||
{
|
||||
//读取下位机状态
|
||||
ushort[] data1 = communicationBll.ReadSateData(100, 1000, 1000);
|
||||
if (data1 == null || data1.Length <= 0) return;
|
||||
|
||||
//查询该单元中的动作
|
||||
var sys_Actions = actionMangerBll.QuerySysAction();
|
||||
sys_Actions = sys_Actions.Where(p => p.action_unit == unitID).ToList();
|
||||
|
||||
|
||||
|
||||
foreach (var sys_action in sys_Actions)
|
||||
{
|
||||
|
||||
if (data1 != null && data1.Length > 0)
|
||||
{
|
||||
int state = data1[int.Parse(sys_action.plc_type)];
|
||||
//state = 2;
|
||||
if (state == 0)
|
||||
{
|
||||
FaultInfos.Add(new FaultInfo() { FaultName = sys_action.action_name, FaultDesc = "未连通", RunColor = WorkUnit.GetStateColor(state) });
|
||||
}
|
||||
if (state == 1)
|
||||
{
|
||||
FaultInfos.Add(new FaultInfo() { FaultName = sys_action.action_name, FaultDesc = "待机", RunColor = WorkUnit.GetStateColor(state) });
|
||||
}
|
||||
if (state == 2)
|
||||
{
|
||||
FaultInfos.Add(new FaultInfo() { FaultName = sys_action.action_name, FaultDesc = "运行", RunColor = WorkUnit.GetStateColor(state) });
|
||||
}
|
||||
if (state == 3)
|
||||
{
|
||||
FaultInfos.Add(new FaultInfo() { FaultName = sys_action.action_name, FaultDesc = "完成", RunColor = WorkUnit.GetStateColor(state) });
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
FaultInfos.Add(new FaultInfo() { FaultName = sys_action.action_name, FaultDesc = "待机", RunColor = WorkUnit.GetStateColor(0) });
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
149
SamplePreSystem.UI/ViewModel/Monitor/WorkUnit.cs
Normal file
149
SamplePreSystem.UI/ViewModel/Monitor/WorkUnit.cs
Normal file
@@ -0,0 +1,149 @@
|
||||
using MaterialDesignThemes.Wpf;
|
||||
using SamplePre.Common;
|
||||
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.Media;
|
||||
|
||||
namespace SamplePreSystem.UI.ViewModel.Monitor
|
||||
{
|
||||
public class WorkUnit : INotifyPropertyChanged
|
||||
{
|
||||
|
||||
private int _state;
|
||||
|
||||
public int state
|
||||
{
|
||||
get { return _state; }
|
||||
set { _state = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private string _stateName;
|
||||
|
||||
public string StateName
|
||||
{
|
||||
get { return _stateName; }
|
||||
set { _stateName = value;
|
||||
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private string _actionName;
|
||||
|
||||
public string actionName
|
||||
{
|
||||
get { return _actionName; }
|
||||
set { _actionName = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private string _unitName;
|
||||
|
||||
public string unitName
|
||||
{
|
||||
get { return _unitName; }
|
||||
set { _unitName = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private string _unitCode;
|
||||
|
||||
public string unitCode
|
||||
{
|
||||
get { return _unitCode; }
|
||||
set { _unitCode = value;
|
||||
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public string imgPath { get; set; }
|
||||
|
||||
public PackIconKind packIconKind { get; set; }
|
||||
|
||||
private Brush runColor = Brushes.Orange ;
|
||||
|
||||
public Brush RunColor
|
||||
{
|
||||
get { return runColor; }
|
||||
set { runColor = value;
|
||||
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取运行状态的颜色
|
||||
/// </summary>
|
||||
/// <param name="state"></param>
|
||||
/// <returns></returns>
|
||||
public static Brush GetStateColor(int state)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
if (state == 0)
|
||||
{
|
||||
return Brushes.Red;
|
||||
|
||||
|
||||
}
|
||||
if (state == 1)
|
||||
{
|
||||
return Brushes.Orange;
|
||||
}
|
||||
else if (state == 2)
|
||||
{
|
||||
return Brushes.LightGreen;
|
||||
|
||||
|
||||
}
|
||||
else if (state == 3)
|
||||
{
|
||||
return Brushes.Green;
|
||||
}
|
||||
|
||||
|
||||
return Brushes.Orange;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LoggerHelper.Logger.Error(ex.Message + ex.StackTrace);
|
||||
return Brushes.Orange;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using Models.Models;
|
||||
using SamplePre.ProcessBll.SampleSequence;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using OfficeOpenXml;
|
||||
|
||||
namespace SamplePreSystem.UI.ViewModel.QueryManager
|
||||
{
|
||||
public partial class SampleQueryViewModel : ObservableObject
|
||||
{
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
SampleSequenceBll sampleSequenceBll = new SampleSequenceBll();
|
||||
public SampleQueryViewModel()
|
||||
{
|
||||
GetData();
|
||||
}
|
||||
|
||||
private DateTime _startDate = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00");
|
||||
|
||||
public DateTime StartDate
|
||||
{
|
||||
get { return _startDate; }
|
||||
set {
|
||||
SetProperty(ref _startDate, value);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private DateTime _endDate = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00");
|
||||
|
||||
public DateTime EndDate
|
||||
{
|
||||
get { return _endDate; }
|
||||
set
|
||||
{
|
||||
|
||||
SetProperty(ref _endDate, value);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private List<tube_input> _sampleList = new List<tube_input>();
|
||||
|
||||
public List<tube_input> SampleList
|
||||
{
|
||||
get { return _sampleList; }
|
||||
set {
|
||||
|
||||
SetProperty(ref _sampleList, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
|
||||
|
||||
[RelayCommand]
|
||||
public void GetData()
|
||||
{
|
||||
DateTime dt1 = DateTime.Parse(StartDate.ToString("yyyy-MM-dd") + " 00:00:00");
|
||||
DateTime dt2 = DateTime.Parse(EndDate.ToString("yyyy-MM-dd") + " 23:00:00");
|
||||
|
||||
SampleList = sampleSequenceBll.GetTubeData(dt1, dt2);
|
||||
|
||||
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
public void ExportExcel()
|
||||
{
|
||||
if (SampleList == null || SampleList.Count == 0)
|
||||
{
|
||||
MessageBox.Show("没有数据可导出", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// 设置EPPlus许可证为个人使用
|
||||
ExcelPackage.LicenseContext = OfficeOpenXml.LicenseContext.NonCommercial;
|
||||
|
||||
// 创建保存文件对话框
|
||||
Microsoft.Win32.SaveFileDialog saveFileDialog = new Microsoft.Win32.SaveFileDialog();
|
||||
saveFileDialog.Filter = "Excel文件 (*.xlsx)|*.xlsx";
|
||||
saveFileDialog.FileName = "样品查询导出_" + DateTime.Now.ToString("yyyyMMddHHmmss");
|
||||
|
||||
if (saveFileDialog.ShowDialog() == true)
|
||||
{
|
||||
string filePath = saveFileDialog.FileName;
|
||||
|
||||
// 创建Excel包
|
||||
using (ExcelPackage package = new ExcelPackage())
|
||||
{
|
||||
// 创建工作表
|
||||
ExcelWorksheet worksheet = package.Workbook.Worksheets.Add("样品数据");
|
||||
|
||||
// 设置表头
|
||||
worksheet.Cells[1, 1].Value = "二维码";
|
||||
worksheet.Cells[1, 2].Value = "样品名称";
|
||||
worksheet.Cells[1, 3].Value = "标准ID";
|
||||
worksheet.Cells[1, 4].Value = "标准名称";
|
||||
worksheet.Cells[1, 5].Value = "录入人员";
|
||||
worksheet.Cells[1, 6].Value = "录入日期";
|
||||
worksheet.Cells[1, 7].Value = "批号";
|
||||
|
||||
// 设置表头样式
|
||||
using (var range = worksheet.Cells["A1:G1"])
|
||||
{
|
||||
range.Style.Font.Bold = true;
|
||||
range.Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
|
||||
range.Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.LightGray);
|
||||
range.Style.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.Center;
|
||||
}
|
||||
|
||||
// 填充数据
|
||||
for (int i = 0; i < SampleList.Count; i++)
|
||||
{
|
||||
var sample = SampleList[i];
|
||||
worksheet.Cells[i + 2, 1].Value = sample.qrcode;
|
||||
worksheet.Cells[i + 2, 2].Value = sample.item_name;
|
||||
worksheet.Cells[i + 2, 3].Value = sample.standrad_id;
|
||||
worksheet.Cells[i + 2, 4].Value = sample.standrad;
|
||||
worksheet.Cells[i + 2, 5].Value = sample.input_user;
|
||||
worksheet.Cells[i + 2, 6].Value = sample.input_date;
|
||||
worksheet.Cells[i + 2, 7].Value = sample.bach_no;
|
||||
}
|
||||
|
||||
// 自动调整列宽
|
||||
worksheet.Cells[worksheet.Dimension.Address].AutoFitColumns();
|
||||
|
||||
// 保存文件
|
||||
FileInfo file = new FileInfo(filePath);
|
||||
package.SaveAs(file);
|
||||
|
||||
MessageBox.Show("导出成功!", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("导出失败:" + ex.Message, "错误", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,656 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using Models.Const;
|
||||
using Models.Models;
|
||||
using SamplePre.Common;
|
||||
using SamplePre.Models;
|
||||
using SamplePre.Models.Ext;
|
||||
using SamplePre.Models.Models;
|
||||
using SamplePre.ProcessBll.BLL;
|
||||
using SamplePre.ProcessBll.SampleSequence;
|
||||
using SamplePre.UIWpf.ParamManager.chirld;
|
||||
using SamplePre.UIWpf.SampleManager.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 static MaterialDesignThemes.Wpf.Theme.ToolBar;
|
||||
|
||||
namespace SamplePreSystem.UI.ViewModel.SampleManager
|
||||
{
|
||||
public partial class SampleExecViewModel : ObservableObject
|
||||
{
|
||||
SampleSequenceBll sampleSequenceBll = new SampleSequenceBll();
|
||||
|
||||
CommunicationBll communicationBll = new CommunicationBll();
|
||||
|
||||
MonitorBll monitorBll = new MonitorBll();
|
||||
|
||||
// 关闭窗口的委托
|
||||
public Action<bool> CloseAction { get; set; }
|
||||
|
||||
public SampleExecViewModel()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
private tube_input _tubeInput = new tube_input();
|
||||
/// <summary>
|
||||
/// 样品录入实体
|
||||
/// </summary>
|
||||
public tube_input TubeInput
|
||||
{
|
||||
get { return _tubeInput; }
|
||||
set {
|
||||
SetProperty(ref _tubeInput, value);
|
||||
}
|
||||
}
|
||||
|
||||
private List<sys_dict> _sampleTypeDict;
|
||||
|
||||
/// <summary>
|
||||
/// 样品类型字典
|
||||
/// </summary>
|
||||
public List<sys_dict> SampleTypeDict
|
||||
{
|
||||
get { return _sampleTypeDict; }
|
||||
set {
|
||||
SetProperty(ref _sampleTypeDict, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 初始化绑定下拉框数据
|
||||
/// </summary>
|
||||
public void InitComboxData()
|
||||
{
|
||||
//绑定样本类型
|
||||
SampleTypeDict = SystemConst.dictDatas.Where(p => p.class_id == 3).ToList();
|
||||
|
||||
//二维码样本序号
|
||||
string strdate = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString("00") + DateTime.Now.Day.ToString("00");
|
||||
TubeInput.qrcode = strdate + GetQrcode();
|
||||
|
||||
}
|
||||
|
||||
private List<sys_standard_ext> _standardList = new List<sys_standard_ext>();
|
||||
|
||||
/// <summary>
|
||||
/// 执行标准列表
|
||||
/// </summary>
|
||||
public List<sys_standard_ext> StandardList
|
||||
{
|
||||
get { return _standardList; }
|
||||
set {
|
||||
SetProperty(ref _standardList, value);
|
||||
}
|
||||
}
|
||||
|
||||
private sys_standard _selectStandard;
|
||||
|
||||
/// <summary>
|
||||
/// 选中的标准
|
||||
/// </summary>
|
||||
public sys_standard SelectStandard
|
||||
{
|
||||
get { return _selectStandard; }
|
||||
set {
|
||||
SetProperty(ref _selectStandard, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private sys_dict _selectSampleType;
|
||||
|
||||
public sys_dict SelectSampleType
|
||||
{
|
||||
get { return _selectSampleType; }
|
||||
set {
|
||||
|
||||
SetProperty(ref _selectSampleType, value);
|
||||
//绑定标准
|
||||
BangdingComboxStandard();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 绑定执行标准下拉框
|
||||
/// </summary>
|
||||
public void BangdingComboxStandard()
|
||||
{
|
||||
|
||||
if (SelectSampleType == null) return;
|
||||
|
||||
StandardList.Clear();
|
||||
|
||||
List<sys_standard_ext> templist = new List<sys_standard_ext>();
|
||||
|
||||
var standardList_temp = sampleSequenceBll.QuerySysStandards(SelectSampleType.id);
|
||||
foreach(var item in standardList_temp)
|
||||
{
|
||||
sys_standard_ext ext = new sys_standard_ext();
|
||||
ext.id = item.id;
|
||||
ext.IsSelected = false;
|
||||
ext.standard_name = item.standard_name;
|
||||
ext.sample_id = item.sample_id;
|
||||
|
||||
templist.Add(ext);
|
||||
}
|
||||
|
||||
StandardList = templist;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 二维码编号
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string GetQrcode()
|
||||
{
|
||||
//string qrcode = dbHepler.QueryQrcode();
|
||||
string qrcode = sampleSequenceBll.QueryQrcode();
|
||||
|
||||
if (string.IsNullOrEmpty(qrcode))
|
||||
{
|
||||
MessageBox.Show("二维码编号获取失败!");
|
||||
}
|
||||
|
||||
return qrcode;
|
||||
}
|
||||
|
||||
private List<tube_input> _tubeInputs = new List<tube_input>();
|
||||
|
||||
public List<tube_input> TubeInputs
|
||||
{
|
||||
get { return _tubeInputs; }
|
||||
set {
|
||||
|
||||
SetProperty(ref _tubeInputs, value);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取样品批次
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string GetBathNo()
|
||||
{
|
||||
//批次号
|
||||
string bachNo = "";
|
||||
|
||||
|
||||
if (TubeInputs == null || TubeInputs.Count <= 0)
|
||||
{
|
||||
//产生新的批次
|
||||
bachNo = DateTime.Now.ToString("yyyyMMddHHmmss");
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
bachNo = TubeInputs[0].bach_no;
|
||||
}
|
||||
|
||||
//设置新的批次
|
||||
TubeInput.bach_no = bachNo;
|
||||
|
||||
return bachNo;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 保存样品
|
||||
/// </summary>
|
||||
public bool SaveSample()
|
||||
{
|
||||
List<tube_input> tempList = new List<tube_input>();
|
||||
|
||||
////二维码序号
|
||||
int sqno = int.Parse(TubeInput.qrcode.Substring(8));// int.Parse(txtSampleSeqno2.Text);
|
||||
string strDate = TubeInput.qrcode.Substring(0, 8);
|
||||
for (int i = 0; i < TubeInput.tube_count; i++)
|
||||
{
|
||||
tube_input qRcode = new tube_input();
|
||||
qRcode.qrcode = strDate + sqno.ToString(); //TubeInput.qrcode;
|
||||
qRcode.item_name = TubeInput.item_name;
|
||||
//qRcode.seqno = txtSampleSeqno.Text + txtSampleSeqno2.Text;
|
||||
//执行标准
|
||||
//ComboBoxListItem item1 = SelectStandard.//cmbStrand.SelectedItem as ComboBoxListItem;
|
||||
|
||||
List<string> ids = new List<string>();
|
||||
List<string> standNames = new List<string>();
|
||||
foreach (var item in StandardList)
|
||||
{
|
||||
if(item.IsSelected)
|
||||
{
|
||||
ids.Add(item.id);
|
||||
standNames.Add(item.standard_name);
|
||||
}
|
||||
}
|
||||
qRcode.standrad_id = string.Join(",", ids.ToArray());
|
||||
qRcode.standrad = string.Join(",", standNames.ToArray());
|
||||
|
||||
|
||||
|
||||
qRcode.input_user = TubeInput.input_user;
|
||||
qRcode.input_date = DateTime.Now;
|
||||
//试管类型
|
||||
//ComboBoxListItem item = cmbTubeType.SelectedItem as ComboBoxListItem;
|
||||
qRcode.bach_no = TubeInput.bach_no;
|
||||
|
||||
//qRcode.weight = textBox5.Text;
|
||||
qRcode.tube_count = TubeInput.tube_count; //int.Parse(txtCount.Text);
|
||||
|
||||
//保持数据库
|
||||
sys_dict sys_Dict = new sys_dict();
|
||||
//int sqno = int.Parse(txtSampleSeqno2.Text);
|
||||
sys_Dict.data_value = sqno.ToString();
|
||||
sqno++;
|
||||
//放入list
|
||||
tempList.Add(qRcode);
|
||||
|
||||
|
||||
//保存数据,更新二维码编号
|
||||
if (sampleSequenceBll.SaveDataAndQrcode(qRcode, sys_Dict) <= 0)
|
||||
{
|
||||
MessageBox.Show("保存失败!");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
//MessageBox.Show("保存成功!");
|
||||
|
||||
//合并已有数据
|
||||
tempList.AddRange(TubeInputs);
|
||||
//通知更新
|
||||
TubeInputs = tempList;
|
||||
|
||||
return true;
|
||||
|
||||
//this.DialogResult = DialogResult.OK;
|
||||
}
|
||||
|
||||
|
||||
private tube_input _selectSample;
|
||||
|
||||
/// <summary>
|
||||
/// 选中的样品
|
||||
/// </summary>
|
||||
public tube_input SelectSample
|
||||
{
|
||||
get { return _selectSample; }
|
||||
set {
|
||||
|
||||
SetProperty(ref _selectSample, value);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除样品
|
||||
/// </summary>
|
||||
public void DeleSelectSample()
|
||||
{
|
||||
|
||||
tube_input[] tube_Inputs = new tube_input[TubeInputs.Count];
|
||||
|
||||
TubeInputs.CopyTo(tube_Inputs);
|
||||
|
||||
if (SelectSample != null)
|
||||
{
|
||||
if (MessageBox.Show($"确定删除:{SelectSample.qrcode}", "提示", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
|
||||
{
|
||||
|
||||
sampleSequenceBll.DelTubeInputByCode(SelectSample.qrcode);
|
||||
|
||||
var tubes = tube_Inputs.ToList();
|
||||
tubes.Remove(SelectSample);
|
||||
|
||||
TubeInputs = tubes;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
private List<sample_exec_ext> _cmdList = new List<sample_exec_ext>();
|
||||
|
||||
public List<sample_exec_ext> CmdList
|
||||
{
|
||||
get { return _cmdList; }
|
||||
set {
|
||||
|
||||
SetProperty(ref _cmdList, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 创建指令集合
|
||||
/// </summary>
|
||||
public void CreateCmdList()
|
||||
{
|
||||
List<sample_exec_ext> temp_CmdList = new List<sample_exec_ext>();
|
||||
|
||||
//this.tubes = gridSamples.DataSource as List<tube_input>;
|
||||
|
||||
var groups = TubeInputs.GroupBy(p => new { p.standrad_id, p.standrad });
|
||||
|
||||
foreach (var g in groups)
|
||||
{
|
||||
sample_exec_ext sampleCmdExec = new sample_exec_ext();
|
||||
sampleCmdExec.id = Guid.NewGuid().ToString();
|
||||
sampleCmdExec.standrad_id = g.Key.standrad_id;
|
||||
sampleCmdExec.standradName = g.Key.standrad;
|
||||
|
||||
List<sample_exec_detail> details = new List<sample_exec_detail>();
|
||||
foreach (var item in g)
|
||||
{
|
||||
sampleCmdExec.sample_count++;
|
||||
sampleCmdExec.qrcodes += item.qrcode + "|";
|
||||
sample_exec_detail sample_Exec_Detail = new sample_exec_detail();
|
||||
details.Add(new sample_exec_detail() { master_id = sampleCmdExec.id, qrcode = item.qrcode });
|
||||
}
|
||||
|
||||
sampleCmdExec.sampleExecDetails = details;
|
||||
sampleCmdExec.exec_state = "未执行";
|
||||
temp_CmdList.Add(sampleCmdExec);
|
||||
|
||||
}
|
||||
CmdList = temp_CmdList;
|
||||
//BadingSopData(cmds);
|
||||
}
|
||||
|
||||
private sample_exec_ext _selectItemCmd;
|
||||
|
||||
public sample_exec_ext SelectItemCmd
|
||||
{
|
||||
get { return _selectItemCmd; }
|
||||
set {
|
||||
|
||||
SetProperty(ref _selectItemCmd,value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
List<string> sopList = new List<string>();
|
||||
/// <summary>
|
||||
/// 初始化指令集合
|
||||
/// </summary>
|
||||
public void InitCmdData()
|
||||
{
|
||||
actionParmList.Clear();
|
||||
sopList.Clear();
|
||||
|
||||
if (SelectItemCmd.standrad_id.Contains(","))
|
||||
{
|
||||
string[] standradIds = SelectItemCmd.standrad_id.Split(',');
|
||||
sopList.AddRange(standradIds);
|
||||
|
||||
foreach (var id in standradIds)
|
||||
{
|
||||
CreateData(id);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sopList.Add(SelectItemCmd.standrad_id);
|
||||
CreateData(SelectItemCmd.standrad_id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void CreateData(string standrad_id)
|
||||
{
|
||||
//查询标准下的动作
|
||||
var standardActions = sampleSequenceBll.GetStrandActionByStrandId(standrad_id);
|
||||
//动作排序
|
||||
standardActions = standardActions.OrderBy(p => p.process_no).ToList(); ;
|
||||
|
||||
//查询动作参数
|
||||
var sys_standard_process_parms = sampleSequenceBll.GetStrandActionParamByStrandId(standrad_id);
|
||||
|
||||
|
||||
if (sys_standard_process_parms.Count <= 0)
|
||||
{
|
||||
MessageBox.Show("没有流程数据!");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
GetData(standardActions, sys_standard_process_parms);
|
||||
}
|
||||
|
||||
public void GetData(List<sys_standard_action_ext> actions, List<sys_standard_action_parm_ext> standardProcessParmList)
|
||||
{
|
||||
|
||||
foreach (var actionItem in actions)
|
||||
{
|
||||
//判断是否有重复的【进样】动作
|
||||
if (actionItem.action_name == "进样" && actionParmList.Find(p => p.action_name == "进样") != null)
|
||||
{
|
||||
continue; //跳过
|
||||
}
|
||||
|
||||
//查询动作下的参数配置
|
||||
var paramData = standardProcessParmList.Where(p => p.action_id == actionItem.process_id && p.action_seqno == actionItem.process_no).ToList();
|
||||
if (paramData.Count <= 0)
|
||||
{
|
||||
sys_standard_action_parm_ext temp = new sys_standard_action_parm_ext();
|
||||
temp.action_name = actionItem.action_name;
|
||||
temp.action_seqno = actionItem.process_no;
|
||||
temp.title = "无";
|
||||
actionParmList.Add(temp);
|
||||
continue;
|
||||
}
|
||||
|
||||
actionParmList.AddRange(paramData);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
private List<sys_standard_action_parm_ext> actionParmList = new List<sys_standard_action_parm_ext>();
|
||||
|
||||
public List<sys_standard_action_parm_ext> ActionParmList
|
||||
{
|
||||
get { return actionParmList; }
|
||||
set {
|
||||
SetProperty(ref actionParmList, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
string sopStr = "";
|
||||
public void CmdDo()
|
||||
{
|
||||
if (!CmdExec()) return;
|
||||
|
||||
//保存下发记录
|
||||
|
||||
SelectItemCmd.exec_state = "执行中";
|
||||
SelectItemCmd.cmd_content = sopStr;
|
||||
SelectItemCmd.exec_date = DateTime.Now;
|
||||
MessageBox.Show("下发成功!");
|
||||
//保存主表
|
||||
sampleSequenceBll.SaveCmdExec(SelectItemCmd);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 发送测试指令
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private bool CmdExec()
|
||||
{
|
||||
//查询所有动作
|
||||
List<sys_action_ext> sysAction = sampleSequenceBll.QuerySysAction();
|
||||
////查询所有参数,及修改
|
||||
List<sys_standard_action_parm_ext> standardProcessParms = actionParmList;// GetEditVal();
|
||||
if (standardProcessParms == null)
|
||||
{
|
||||
//MessageBox.Show("指令生成错误!");
|
||||
return false;
|
||||
}
|
||||
sopStr = "";
|
||||
|
||||
//S7协议
|
||||
List<byte> sop = sampleSequenceBll.CreateCmdBytes(sysAction, sopList, standardProcessParms);
|
||||
|
||||
////modbus协议
|
||||
//List<ushort> sop = this.sampleSequenceBll.CreateCmdUshorts(sysAction, standardActions, standardProcessParms);
|
||||
|
||||
if (sop == null)
|
||||
{
|
||||
MessageBox.Show("指令生成错误!");
|
||||
return false;
|
||||
}
|
||||
|
||||
sopStr = string.Join("-", sop.ToArray());
|
||||
|
||||
//写入PLC
|
||||
bool val = communicationBll.WritePlcData(100, 0, sop.ToArray());
|
||||
|
||||
//bool val = monitorBll.WritePlcData(1, 0, sop.ToArray());
|
||||
return val;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 总复位
|
||||
/// </summary>
|
||||
[RelayCommand]
|
||||
public void InitPlcState()
|
||||
{
|
||||
Task.Run(() => {
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
int a = i+1;
|
||||
communicationBll.WriteSingleData("DB19.DBX0.0", true);
|
||||
Task.Delay(1000).Wait();
|
||||
LoggerHelper.Logger.Error("发生复位指令");
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
///// <summary>
|
||||
///// 导入样品
|
||||
///// </summary>
|
||||
///// <param name="list"></param>
|
||||
//public void ImportSamples(List<tube_input> list)
|
||||
//{
|
||||
// TubeInputs = list;
|
||||
//}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 新增样品
|
||||
/// </summary>
|
||||
[RelayCommand]
|
||||
public void BtnAddSampleClick()
|
||||
{
|
||||
|
||||
GetBathNo();
|
||||
|
||||
InitComboxData();
|
||||
|
||||
NewSampleWindow frm = new NewSampleWindow(this);
|
||||
|
||||
frm.ShowDialog();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除样品
|
||||
/// </summary>
|
||||
[RelayCommand]
|
||||
public void BtnDelSampleClick()
|
||||
{
|
||||
|
||||
DeleSelectSample();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 导入样品
|
||||
/// </summary>
|
||||
[RelayCommand]
|
||||
public void BtnImportSampleClick()
|
||||
{
|
||||
ImportSampleWindow frm = new ImportSampleWindow(this);
|
||||
if (frm.ShowDialog() == true)
|
||||
{
|
||||
//ImportSamples(frm.samples);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建指令
|
||||
/// </summary>
|
||||
[RelayCommand]
|
||||
public void BtnCreateCmdClick()
|
||||
{
|
||||
CreateCmdList();
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 打开命令下发
|
||||
/// </summary>
|
||||
[RelayCommand]
|
||||
public void RowDoubleClick()
|
||||
{
|
||||
ActionShowWindow frm = new ActionShowWindow(this);
|
||||
frm.ShowDialog();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 命令下发
|
||||
/// </summary>
|
||||
[RelayCommand]
|
||||
public void CmdDoClick()
|
||||
{
|
||||
|
||||
CmdDo();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存样本
|
||||
/// </summary>
|
||||
[RelayCommand]
|
||||
public void BtnOKClick()
|
||||
{
|
||||
|
||||
if (SaveSample())
|
||||
{
|
||||
this.CloseAction?.Invoke(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,255 @@
|
||||
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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 所有动作列表
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
public List<sys_action_ext> sysActions = new List<sys_action_ext>();
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有动作
|
||||
/// </summary>
|
||||
public void InitActionData()
|
||||
{
|
||||
|
||||
SysActions = actionMangerBll.QuerySysAction();
|
||||
|
||||
}
|
||||
|
||||
[ObservableProperty]
|
||||
public List<sys_action_parm_map_ext> actionParams;
|
||||
|
||||
|
||||
private sys_action_ext _selectItem;
|
||||
|
||||
/// <summary>
|
||||
/// 选中的动作行
|
||||
/// </summary>
|
||||
public sys_action_ext SelectItem
|
||||
{
|
||||
get { return _selectItem; }
|
||||
set {
|
||||
|
||||
SetProperty(ref _selectItem, value);
|
||||
|
||||
OnSelectedActionChanged();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 选中的参数
|
||||
/// </summary>
|
||||
|
||||
private sys_action_parm_map_ext _selectParam;
|
||||
|
||||
public sys_action_parm_map_ext SelectParam
|
||||
{
|
||||
get { return _selectParam; }
|
||||
set {
|
||||
SetProperty(ref _selectParam, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 查询动作下参数
|
||||
/// </summary>
|
||||
/// <param name="processId"></param>
|
||||
public void GetParmData(string actionId)
|
||||
{
|
||||
ActionParams = actionMangerBll.GetProcess_parm_mapByProcessId(actionId);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取动作下的参数
|
||||
/// </summary>
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除参数
|
||||
/// </summary>
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 新增动作
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
[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"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 删除动作
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
[RelayCommand]
|
||||
public void BtnDelActionClick()
|
||||
{
|
||||
|
||||
DeleAction();
|
||||
|
||||
//刷新列表
|
||||
ListCollectionView view = (ListCollectionView)CollectionViewSource.GetDefaultView(SysActions);//获取数据视图
|
||||
|
||||
////分组
|
||||
view.GroupDescriptions.Clear();
|
||||
view.GroupDescriptions.Add(new PropertyGroupDescription("action_unitname"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 动作下新增参数
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
[RelayCommand]
|
||||
public void BtnSelectParamClick()
|
||||
{
|
||||
|
||||
SelectShowParmList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除动作下参数
|
||||
/// </summary>
|
||||
[RelayCommand]
|
||||
public void BtnDelParmClick()
|
||||
{
|
||||
|
||||
DeleParam();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
18
SamplePreSystem.UI/ViewModel/SopManager/DataGroup.cs
Normal file
18
SamplePreSystem.UI/ViewModel/SopManager/DataGroup.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using SamplePre.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SamplePreSystem.UI.ViewModel.SopManager
|
||||
{
|
||||
public class DataGroup
|
||||
{
|
||||
public string Id { get; set; }
|
||||
|
||||
public string SopName { get; set; }
|
||||
|
||||
public List<TreeListItem> ListItems { get; set; } = new List<TreeListItem>();
|
||||
}
|
||||
}
|
||||
258
SamplePreSystem.UI/ViewModel/SopManager/ParamManagerViewModel.cs
Normal file
258
SamplePreSystem.UI/ViewModel/SopManager/ParamManagerViewModel.cs
Normal file
@@ -0,0 +1,258 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using Models.Const;
|
||||
using Models.Models;
|
||||
using SamplePre.ProcessBll.BLL;
|
||||
using SamplePre.UIWpf.ParamManager.chirld;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace SamplePreSystem.UI.ViewModel.SopManager
|
||||
{
|
||||
public partial class ParamManagerViewModel : ObservableObject
|
||||
{
|
||||
SysParamBll sysParamBll = new SysParamBll();
|
||||
|
||||
|
||||
|
||||
public ParamManagerViewModel()
|
||||
{
|
||||
//初始化标准
|
||||
InitParamData();
|
||||
|
||||
BangdingUnit();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 参数列表
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
public List<sys_parm> sysParams = new List<sys_parm>();
|
||||
|
||||
/// <summary>
|
||||
/// 选中的参数行
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
public sys_parm selectItem = new sys_parm();
|
||||
|
||||
List<sys_parm> allSysParams = new List<sys_parm>();
|
||||
|
||||
public void InitParamData()
|
||||
{
|
||||
allSysParams = sysParamBll.QuerySysParm()?.OrderBy(p => p.plc_type).ToList();
|
||||
|
||||
|
||||
OnFilterTypeChange();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 参数类型
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
public List<string> dataTypes = new List<string> { "通用", "耗材", "液体" };
|
||||
|
||||
/// <summary>
|
||||
/// 过滤类型
|
||||
/// </summary>
|
||||
private string filterType = "通用";
|
||||
|
||||
public string FilterType
|
||||
{
|
||||
get { return filterType; }
|
||||
set {
|
||||
|
||||
SetProperty(ref filterType, value);
|
||||
|
||||
OnFilterTypeChange();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void OnFilterTypeChange()
|
||||
{
|
||||
if (string.IsNullOrEmpty(FilterType))
|
||||
{
|
||||
SysParams = allSysParams;
|
||||
return;
|
||||
}
|
||||
|
||||
SysParams = allSysParams.Where(p => p.param_type == FilterType).ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 单位列表
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
public List<sys_dict> units = new List<sys_dict>();
|
||||
|
||||
|
||||
public void BangdingUnit()
|
||||
{
|
||||
Units = SystemConst.dictDatas.Where(p => p.class_id == 4).ToList();
|
||||
|
||||
//cmbUnit.BindingData<sys_dict>(units, "data_value", "id");
|
||||
//cmbUnit.SelectedIndex = 0;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 参数值绑定
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
public sys_parm sysParm = new sys_parm();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 保存参数
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public bool SaveParam()
|
||||
{
|
||||
if (string.IsNullOrEmpty(SysParm.title) || string.IsNullOrEmpty(SysParm.data_value))
|
||||
{
|
||||
MessageBox.Show("内容不能为空");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(SysParm.param_type))
|
||||
{
|
||||
MessageBox.Show("参数类型不能为空");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (SysParm.data_type == "数值")
|
||||
{
|
||||
string val = SysParm.data_value;
|
||||
if (float.TryParse(val, out _) == false)
|
||||
{
|
||||
MessageBox.Show("参数值格式不正确,请重新修改!");
|
||||
SysParm.data_value = "0";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (SysParm != null && !string.IsNullOrEmpty(SysParm.id))
|
||||
{
|
||||
//修改
|
||||
sysParamBll.UpdateSysParm(SysParm);
|
||||
}
|
||||
else
|
||||
{
|
||||
//判断plc编码是否重复
|
||||
if (sysParamBll.IsExtisPlCcode(SysParm.plc_type))
|
||||
{
|
||||
MessageBox.Show("存在相同plc编码,不能保存!");
|
||||
return false;
|
||||
}
|
||||
//新增
|
||||
SysParm.id = Guid.NewGuid().ToString();
|
||||
|
||||
sysParamBll.SaveSysParm(SysParm);
|
||||
}
|
||||
|
||||
//刷新参数列表
|
||||
InitParamData();
|
||||
OnFilterTypeChange();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 删除参数
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public bool DelParam()
|
||||
{
|
||||
sys_parm parm = SelectItem;
|
||||
string id = parm.id;
|
||||
string title = parm.title;
|
||||
|
||||
|
||||
if (MessageBox.Show($"确定删除:{title}", "提示",MessageBoxButton.OKCancel) == MessageBoxResult.OK)
|
||||
{
|
||||
//判断该参数是否已经被使用
|
||||
if (IsDelete(id) == false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
sysParamBll.DelSysParm(id);
|
||||
|
||||
//刷新参数列表
|
||||
InitParamData();
|
||||
OnFilterTypeChange();
|
||||
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
private bool IsDelete(string parmId)
|
||||
{
|
||||
bool isExit = sysParamBll.IsExtisActionParam(parmId);
|
||||
if (isExit)
|
||||
{
|
||||
MessageBox.Show("该参数已经被使用,不能删除!");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 新增参数
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
[RelayCommand]
|
||||
public void BtnAddParamClick()
|
||||
{
|
||||
SysParm = new sys_parm();
|
||||
NewStandParmWindow frm = new NewStandParmWindow(this);
|
||||
frm.ShowDialog();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 编辑参数
|
||||
/// </summary>
|
||||
[RelayCommand]
|
||||
public void BtnEditClick()
|
||||
{
|
||||
SysParm = SelectItem;
|
||||
|
||||
NewStandParmWindow frm = new NewStandParmWindow(this);
|
||||
frm.ShowDialog();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除参数
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
[RelayCommand]
|
||||
private void BtnDelParamClick()
|
||||
{
|
||||
DelParam();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
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