逻辑规则的初步增加工能:
1)规则的界面的增删改查 2)规则服务的初步测试,目前测试是OK的
This commit is contained in:
233
CapMachine.Wpf/ViewModels/DialogLogicRuleViewModel.cs
Normal file
233
CapMachine.Wpf/ViewModels/DialogLogicRuleViewModel.cs
Normal file
@@ -0,0 +1,233 @@
|
||||
using AutoMapper;
|
||||
using CapMachine.Core;
|
||||
using CapMachine.Model;
|
||||
using CapMachine.Wpf.Dtos;
|
||||
using CapMachine.Wpf.Services;
|
||||
using Masuit.Tools;
|
||||
using Prism.Commands;
|
||||
using Prism.Services.Dialogs;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
|
||||
namespace CapMachine.Wpf.ViewModels
|
||||
{
|
||||
/// <summary>
|
||||
/// 逻辑规则配置的弹窗
|
||||
/// </summary>
|
||||
public class DialogLogicRuleViewModel : DialogViewModel
|
||||
{
|
||||
public DialogLogicRuleViewModel(IFreeSql freeSql, IMapper mapper, LogicRuleService logicRuleService)
|
||||
{
|
||||
Title = "逻辑规则创建";
|
||||
|
||||
FreeSql = freeSql;
|
||||
Mapper = mapper;
|
||||
LogicRuleService = logicRuleService;
|
||||
|
||||
//var Data = Mapper.Map<List<LogicRuleDto>>(LogicRuleService.LogicRuleDtos);
|
||||
|
||||
ListLogicRuleDto = LogicRuleService.LogicRuleDtos;
|
||||
|
||||
}
|
||||
public IFreeSql FreeSql { get; }
|
||||
public IMapper Mapper { get; }
|
||||
public LogicRuleService LogicRuleService { get; }
|
||||
|
||||
private ObservableCollection<LogicRuleDto> _ListLogicRuleDto;
|
||||
/// <summary>
|
||||
/// 数据集合
|
||||
/// </summary>
|
||||
public ObservableCollection<LogicRuleDto> ListLogicRuleDto
|
||||
{
|
||||
get { return _ListLogicRuleDto; }
|
||||
set { _ListLogicRuleDto = value; RaisePropertyChanged(); }
|
||||
}
|
||||
|
||||
private LogicRuleDto _selectedRule;
|
||||
/// <summary>
|
||||
/// 当前选中的规则
|
||||
/// </summary>
|
||||
public LogicRuleDto SelectedRule
|
||||
{
|
||||
get { return _selectedRule; }
|
||||
set { _selectedRule = value; RaisePropertyChanged(); }
|
||||
}
|
||||
|
||||
private DelegateCommand<object> _GridSelectionChangedCmd;
|
||||
/// <summary>
|
||||
/// 选中行数据命令
|
||||
/// </summary>
|
||||
public DelegateCommand<object> GridSelectionChangedCmd
|
||||
{
|
||||
set
|
||||
{
|
||||
_GridSelectionChangedCmd = value;
|
||||
}
|
||||
get
|
||||
{
|
||||
if (_GridSelectionChangedCmd == null)
|
||||
{
|
||||
_GridSelectionChangedCmd = new DelegateCommand<object>((par) => GridSelectionChangedCmdMethod(par));
|
||||
}
|
||||
return _GridSelectionChangedCmd;
|
||||
}
|
||||
}
|
||||
private void GridSelectionChangedCmdMethod(object par)
|
||||
{
|
||||
var selectedItem = par as LogicRuleDto;
|
||||
if (selectedItem != null)
|
||||
{
|
||||
//先判断是否是正确的集合数据,防止DataGrid的数据源刷新导致的触发事件
|
||||
SelectedRule = selectedItem.DeepClone();
|
||||
}
|
||||
|
||||
////选中的行数据
|
||||
|
||||
}
|
||||
|
||||
|
||||
private DelegateCommand<string> _RuleCmd;
|
||||
/// <summary>
|
||||
/// 选中行数据命令
|
||||
/// </summary>
|
||||
public DelegateCommand<string> RuleCmd
|
||||
{
|
||||
set
|
||||
{
|
||||
_RuleCmd = value;
|
||||
}
|
||||
get
|
||||
{
|
||||
if (_RuleCmd == null)
|
||||
{
|
||||
_RuleCmd = new DelegateCommand<string>((par) => RuleCmdMethod(par));
|
||||
}
|
||||
return _RuleCmd;
|
||||
}
|
||||
}
|
||||
private void RuleCmdMethod(string par)
|
||||
{
|
||||
if (SelectedRule==null)
|
||||
{
|
||||
MessageBox.Show("选中后再操作数据");
|
||||
return;
|
||||
}
|
||||
//先判断是否是正确的集合数据,防止DataGrid的数据源刷新导致的触发事件
|
||||
switch (par)
|
||||
{
|
||||
case "Create":
|
||||
//SelectedRule
|
||||
LogicRuleService.AddRule(Mapper.Map<LogicRule>(SelectedRule));
|
||||
break;
|
||||
case "Update":
|
||||
LogicRuleService.UpdateRule(Mapper.Map<LogicRule>(SelectedRule));
|
||||
break;
|
||||
case "Delete":
|
||||
LogicRuleService.DeleteRule(SelectedRule.Name);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
////选中的行数据
|
||||
|
||||
}
|
||||
|
||||
#region 基础弹窗配置
|
||||
|
||||
|
||||
|
||||
private string name;
|
||||
/// <summary>
|
||||
/// 名称
|
||||
/// </summary>
|
||||
public string Name
|
||||
{
|
||||
get { return name; }
|
||||
set { name = value; RaisePropertyChanged(); }
|
||||
}
|
||||
|
||||
|
||||
|
||||
private DelegateCommand saveCmd;
|
||||
/// <summary>
|
||||
/// 保存命令
|
||||
/// </summary>
|
||||
public DelegateCommand SaveCmd
|
||||
{
|
||||
set
|
||||
{
|
||||
saveCmd = value;
|
||||
}
|
||||
get
|
||||
{
|
||||
if (saveCmd == null)
|
||||
{
|
||||
saveCmd = new DelegateCommand(() => SaveCmdMethod());
|
||||
}
|
||||
return saveCmd;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存命令方法
|
||||
/// </summary>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
private void SaveCmdMethod()
|
||||
{
|
||||
DialogParameters pars = new DialogParameters
|
||||
{
|
||||
{ "NewData", "" }
|
||||
};
|
||||
|
||||
RaiseRequestClose(new DialogResult(ButtonResult.OK, pars));
|
||||
}
|
||||
|
||||
private DelegateCommand cancelCmd;
|
||||
/// <summary>
|
||||
/// 保存命令
|
||||
/// </summary>
|
||||
public DelegateCommand CancelCmd
|
||||
{
|
||||
set
|
||||
{
|
||||
cancelCmd = value;
|
||||
}
|
||||
get
|
||||
{
|
||||
if (cancelCmd == null)
|
||||
{
|
||||
cancelCmd = new DelegateCommand(() => CancelCmdMethod());
|
||||
}
|
||||
return cancelCmd;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 取消命令方法
|
||||
/// </summary>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
private void CancelCmdMethod()
|
||||
{
|
||||
RaiseRequestClose(new DialogResult(ButtonResult.Cancel));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 窗口打开时的传递的参数
|
||||
/// </summary>
|
||||
/// <param name="parameters"></param>
|
||||
public override void OnDialogOpened(IDialogParameters parameters)
|
||||
{
|
||||
Name = parameters.GetValue<string>("Name");
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user