using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Controls; using System.Windows; using Prism.Common; using Prism.Dialogs; using SWS.CAD.Services; using SWS.CAD.ViewModels.myViewModelBase; using SWS.CAD.Views.CustomControl; using SWS.CAD.Models; using Bricscad.EditorInput; using System.Windows.Input; using Telerik.Windows.Controls; namespace SWS.CAD.ViewModels { public class DialogNewStripViewModel : DialogBase, IDialogAware { #region 字段 private ObservableCollection _StripParametersInfos = new ObservableCollection(); /// /// 端子排参数信息列表 /// public ObservableCollection StripParametersInfos { get { return _StripParametersInfos; } set { _StripParametersInfos = value; RaisePropertyChanged(nameof(StripParametersInfos)); } } private StripParametersInfo _SelectedStripParametersInfo; /// /// 当前选中的信号类型 /// public StripParametersInfo SelectedStripParametersInfo { get { return _SelectedStripParametersInfo; } set { _SelectedStripParametersInfo = value; RaisePropertyChanged(nameof(SelectedStripParametersInfo)); } } private bool _IsReadOnly; /// /// 是否可编辑 /// public bool IsReadOnly { get { return _IsReadOnly; } set { _IsReadOnly = value; RaisePropertyChanged(nameof(IsReadOnly)); } } #region 表格下拉列表 private List _TermNamingType_ls = new List() { "数字", "字母" }; /// /// 端子编号类型 /// public List TermNamingType_ls { get { return _TermNamingType_ls; } set { _TermNamingType_ls = value; RaisePropertyChanged(nameof(TermNamingType_ls)); } } private List _TermNamingRule_ls = new List() { "按端子排全局编号", "按通道内端子编号", "按通道编号" }; /// /// 端子编号规则 /// public List TermNamingRule_ls { get { return _TermNamingRule_ls; } set { _TermNamingRule_ls = value; RaisePropertyChanged(nameof(TermNamingRule_ls)); } } private List _TermNamePrefix_ls = new List() { "通道编号", "+,-,s", "无" }; /// /// 端子前缀 /// public List TermNamePrefix_ls { get { return _TermNamePrefix_ls; } set { _TermNamePrefix_ls = value; RaisePropertyChanged(nameof(TermNamePrefix_ls)); } } private List _TermNameSuffix_ls = new List() { "通道编号", "+,-,s", "无" }; /// /// 端子后缀 /// public List TermNameSuffix_ls { get { return _TermNameSuffix_ls; } set { _TermNameSuffix_ls = value; RaisePropertyChanged(nameof(TermNameSuffix_ls)); } } #endregion #endregion public DialogCloseListener RequestClose { get; } public bool CanCloseDialog() { return true; } public void OnDialogClosed() { } public async void OnDialogOpened(IDialogParameters parameters) { //title = parameters.GetValue(GlobalObject.dialogPar.title.ToString()); title = "端子排模版"; _StripParametersInfos = parameters.GetValue>(GlobalObject.dialogPar.para1.ToString()); _IsReadOnly = parameters.GetValue(GlobalObject.dialogPar.para2.ToString()); } public override void ExecuteOKCommandAsync(object para) { Prism.Dialogs.DialogParameters res = new Prism.Dialogs.DialogParameters(); if (IsReadOnly)//页面是公共的,为只读时是新增端子排的页面,传回去的事选中的项数据 { res.Add(GlobalObject.dialogPar.para1.ToString(), SelectedStripParametersInfo); } else { res.Add(GlobalObject.dialogPar.para1.ToString(), StripParametersInfos.ToList()); } RequestClose.Invoke(res, ButtonResult.Yes); } public override void ExecuteCloseCommand(object parameter) { if (parameter as string == "ClickNo") { RequestClose.Invoke(ButtonResult.No); } else { RequestClose.Invoke(ButtonResult.Cancel); } this.Dispose(); } #region 方法 public ICommand EditEndCmd => new DelegateCommand(EditEnd); /// /// 编辑结束事件 /// /// public virtual void EditEnd(object parameter) { //做个标记表示该项修改过 SelectedStripParametersInfo.IsModified = true; } #endregion } public class StripParametersInfo : DialogBase { #region 页面渲染字段 private int _Index; /// /// 序号 /// public int Index { get { return _Index; } set { _Index = value; RaisePropertyChanged(nameof(Index)); } } private string _IoType; /// /// 信号类型 /// public string IoType { get { return _IoType; } set { _IoType = value; RaisePropertyChanged(nameof(Index)); } } private string _MaxCount; /// /// 最大数量 /// public string MaxCount { get { return _MaxCount; } set { _MaxCount = value; RaisePropertyChanged(nameof(MaxCount)); } } private string _CHNoPerStrip; /// /// 通道数量 /// public string CHNoPerStrip { get { return _CHNoPerStrip; } set { _CHNoPerStrip = value; RaisePropertyChanged(nameof(CHNoPerStrip)); } } private string _TermNoPerCh; /// /// 每通道端子数 /// public string TermNoPerCh { get { return _TermNoPerCh; } set { _TermNoPerCh = value; RaisePropertyChanged(nameof(TermNoPerCh)); } } private string _ChNamePrefix; /// /// 通道前缀 /// public string ChNamePrefix { get { return _ChNamePrefix; } set { _ChNamePrefix = value; RaisePropertyChanged(nameof(ChNamePrefix)); } } private string _ChNameStartIndex; /// /// 通道起始编号 /// public string ChNameStartIndex { get { return _ChNameStartIndex; } set { _ChNameStartIndex = value; RaisePropertyChanged(nameof(ChNameStartIndex)); } } private string _TermNamingType; /// /// 端子编号类型 /// public string TermNamingType { get { return _TermNamingType; } set { _TermNamingType = value; RaisePropertyChanged(nameof(TermNamingType)); } } private string _TermNamingRule; /// /// 端子编号规则 /// public string TermNamingRule { get { return _TermNamingRule; } set { _TermNamingRule = value; RaisePropertyChanged(nameof(TermNamingRule)); } } private string _TermNamePrefix; /// /// 端子前缀 /// public string TermNamePrefix { get { return _TermNamePrefix; } set { _TermNamePrefix = value; RaisePropertyChanged(nameof(TermNamePrefix)); } } private string _TermNameSuffix; /// /// 端子后缀 /// public string TermNameSuffix { get { return _TermNameSuffix; } set { _TermNameSuffix = value; RaisePropertyChanged(nameof(TermNameSuffix)); } } #endregion #region 扩展字段 private bool _IsModified; /// /// 表示是否修改过 /// public bool IsModified { get { return _IsModified; } set { _IsModified = value; RaisePropertyChanged(nameof(IsModified)); } } #endregion } }