using AutoMapper; using CapMachine.Core; using CapMachine.Model; using CapMachine.Wpf.Dtos; 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 { public class DialogChartGroupTabViewModel : DialogViewModel { public DialogChartGroupTabViewModel(IFreeSql freeSql, IMapper mapper) { this.Title = "曲线分组编辑"; FreeSql = freeSql; Mapper = mapper; var ChartTabGroupDtoData = Mapper.Map>(FreeSql.Select().ToList()); ListChartTabGroupDto = new ObservableCollection(ChartTabGroupDtoData); } public IFreeSql FreeSql { get; } public IMapper Mapper { get; } private string name; /// /// 名称 /// public string Name { get { return name; } set { name = value; RaisePropertyChanged(); } } private ObservableCollection _ListChartTabGroupDto; /// /// 数据集合 /// public ObservableCollection ListChartTabGroupDto { get { return _ListChartTabGroupDto; } set { _ListChartTabGroupDto = value; RaisePropertyChanged(); } } private DelegateCommand saveCmd; /// /// 保存命令 /// public DelegateCommand SaveCmd { set { saveCmd = value; } get { if (saveCmd == null) { saveCmd = new DelegateCommand(() => SaveCmdMethod()); } return saveCmd; } } /// /// 保存命令方法 /// /// private void SaveCmdMethod() { if (ListChartTabGroupDto.Where(a=>a.IsEnable==true).Count()==0) { MessageBox.Show("未发现【启用】的选型,这将要导致没有任何显示!,请检查后再提交"); return; } foreach (var item in ListChartTabGroupDto) { FreeSql.Update() .Set(a=>a.Name,item.Name) .Set(a=>a.IsEnable,item.IsEnable) .Where(a=>a.Index==item.Index) .ExecuteAffrows(); } DialogParameters pars = new DialogParameters { { "NewData", ListChartTabGroupDto.Where(a=>a.IsEnable==true).ToList() } }; RaiseRequestClose(new DialogResult(ButtonResult.OK, pars)); } private DelegateCommand cancelCmd; /// /// 保存命令 /// public DelegateCommand CancelCmd { set { cancelCmd = value; } get { if (cancelCmd == null) { cancelCmd = new DelegateCommand(() => CancelCmdMethod()); } return cancelCmd; } } /// /// 取消命令方法 /// /// private void CancelCmdMethod() { RaiseRequestClose(new DialogResult(ButtonResult.Cancel)); } /// /// 窗口打开时的传递的参数 /// /// public override void OnDialogOpened(IDialogParameters parameters) { Name = parameters.GetValue("Name"); } } }