using Bricscad.EditorInput; using Bricscad.ApplicationServices; using Prism.Dialogs; using SWS.CAD.Models; using SWS.CAD.Services; using SWS.CAD.ViewModels.myViewModelBase; using SWS.CAD.Views; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Globalization; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Input; using Telerik.Windows.Controls; using Unity; using System.Windows; using System.Runtime.Remoting.Channels; using static SWS.CAD.GlobalObject; using static SWS.CAD.Services.WireGroupService; using System.ComponentModel; using static System.Net.Mime.MediaTypeNames; using System.Text.RegularExpressions; using Aspose.Cells.Drawing.Texts; using Telerik.Windows.Controls.Primitives; using SWS.CAD.Views.SignalManagementViews; using DryIoc.ImTools; using System.Diagnostics.Eventing.Reader; namespace SWS.CAD.ViewModels { public class DialogSignalNoticeViewModel : DialogBase, IDialogAware { #region 属性 private ObservableCollection _MySignalNotices = new ObservableCollection(); /// /// 表格数据源 /// public ObservableCollection MySignalNotices { get { return _MySignalNotices; } set { _MySignalNotices = value; RaisePropertyChanged(nameof(MySignalNotices)); } } private SignalNotice _SelectedSignalNotice; /// /// 选中行 /// public SignalNotice SelectedSignalNotice { get { return _SelectedSignalNotice; } set { _SelectedSignalNotice = value; RaisePropertyChanged(nameof(SelectedSignalNotice)); } } /// /// 信号接口服务 /// WireGroupService _wireGroupService; public DialogSignalNotice SignalNoticeView { get; set; } #endregion public DialogSignalNoticeViewModel() { title = "通知信息"; _wireGroupService = GlobalObject.container.Resolve(); } public DialogCloseListener RequestClose { get; } public bool CanCloseDialog() { return true; } public void OnDialogClosed() { } private List SignalNotices; public async void OnDialogOpened(IDialogParameters parameters) { SignalNotices = await _wireGroupService.GetNotification(); int index = 0; foreach (var item in SignalNotices) { index++; SignalNotice s= new SignalNotice(item); s.ID = index; MySignalNotices.Add(s); } } public override void ExecuteOKCommandAsync(object para) { Prism.Dialogs.DialogParameters res = new Prism.Dialogs.DialogParameters(); //res.Add(GlobalObject.dialogPar.info.ToString(), $"{TextInfo}"); 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 StatusButtonCmd => new DelegateCommand(StatusButton_Click); /// /// 显示状态按钮 /// /// public virtual async void StatusButton_Click(object parameter) { MySignalNotices = new ObservableCollection(); SignalNotices = await _wireGroupService.GetNotification(); if (!parameter.Equals("All")) { SignalNotices = SignalNotices.Where(s => s.CheckFLG.ToString().Equals(parameter)).ToList(); } int index = 0; foreach (var item in SignalNotices) { index++; SignalNotice s = new SignalNotice(item); s.ID = index; MySignalNotices.Add(s); } } #endregion #region 右侧按钮 public ICommand ButtonCmd => new DelegateCommand(Button_Click); /// /// 页面右侧按钮 /// /// public virtual async void Button_Click(object parameter) { #region 确定 if (parameter.Equals("确定")) { List noticeIds = new List(); foreach (var item in MySignalNotices) { noticeIds = MySignalNotices.Where(e => e.IsModified == true).Select(e => e.WireGroupNoticeID).ToList(); } List ReNotices = await _wireGroupService.ReadNotification(noticeIds); foreach (var item in ReNotices) { var ent = MySignalNotices.FirstOrDefault(x => x.WireGroupNoticeID == item.WireGroupNoticeID); if (ent != null) { ent.UpdateTime = item.UpdateTime; } } RequestClose.Invoke(ButtonResult.Cancel); this.Dispose(); } #endregion #region 取消 if (parameter.Equals("取消")) { RequestClose.Invoke(ButtonResult.Cancel); this.Dispose(); } #endregion #region 已阅 if (parameter.Equals("已阅")) { if (SelectedSignalNotice == null) { return; } else { if (!SelectedSignalNotice.CheckFLG) { SelectedSignalNotice.CheckFLG = true; SelectedSignalNotice.IsModified = true; } } } #endregion #region 全部已阅 if (parameter.Equals("全部已阅")) { foreach (var item in MySignalNotices) { if (!item.CheckFLG) { item.CheckFLG = true; item.IsModified = true; } } } #endregion } #endregion } public class SignalNotice: DialogBase { #region 属性 private int _ID; /// /// 序号 /// public int ID { get { return _ID; } set { _ID = value; } } private string _WireGroupNoticeID; /// /// 信号通知ID /// public string WireGroupNoticeID { get { return _WireGroupNoticeID; } set { _WireGroupNoticeID = value; } } private string _Group_Name; /// /// CH.NO /// public string Group_Name { get { return _Group_Name; } set { _Group_Name = value; } } private string _Group_Desc; /// /// z中文描述 /// public string Group_Desc { get { return _Group_Desc; } set { _Group_Desc = value; } } private string _Group_Desc_EN; /// /// 英文描述 /// public string Group_Desc_EN { get { return _Group_Desc_EN; } set { _Group_Desc_EN = value; } } private string _IO_Type; /// /// 信号类型 /// public string IO_Type { get { return _IO_Type; } set { _IO_Type = value; } } private Models.Action _ActionID; /// /// 操作ID /// public Models.Action ActionID { get { return _ActionID; } set { _ActionID = value; } } private string _Action; /// /// 操作 /// public string Action { get { return _Action; } set { _Action = value; } } private string _CreateUserName; /// /// 发出者 /// public string CreateUserName { get { return _CreateUserName; } set { _CreateUserName = value; } } private DateTime? _CreateTime; /// /// 操作时间 /// public DateTime? CreateTime { get { return _CreateTime; } set { _CreateTime = value; } } private string _UpdateUserName; /// /// 已阅人 /// public string UpdateUserName { get { return _UpdateUserName; } set { _UpdateUserName = value; } } private DateTime? _UpdateTime; /// /// 已阅时间 /// public DateTime? UpdateTime { get { return _UpdateTime; } set { _UpdateTime = value; } } private string _Message; /// /// 操作信息 /// public string Message { get { return _Message; } set { _Message = value; } } private bool _CheckFLG; /// /// 是否已读 /// public bool CheckFLG { get { return _CheckFLG; } set { _CheckFLG = value; } } private bool _IsModified; /// /// 是否修改 /// public bool IsModified { get { return _IsModified; } set { _IsModified = value; RaisePropertyChanged(nameof(IsModified)); } } private bool _IsReadOnly; /// /// 是否可编辑 /// public bool IsReadOnly { get { return _IsReadOnly; } set { _IsReadOnly = value; RaisePropertyChanged(nameof(IsReadOnly)); } } #endregion #region 方法 public SignalNotice() { } public SignalNotice(ec_wire_group_notice ec_Notice) { #region 前端表格对应列 this.Group_Name = ec_Notice.Group_Name; this.Group_Desc = ec_Notice.Group_Desc; this.Group_Desc_EN = ec_Notice.Group_Desc_EN; this.IO_Type = ec_Notice.IO_Type; this.Action = ec_Notice.Action; this.CreateUserName = ec_Notice.CreateUserName; this.CreateTime = ec_Notice.CreateTime; this.UpdateUserName = ec_Notice.UpdateUserName; this.UpdateTime = ec_Notice.UpdateTime; this.Message = ec_Notice.Message; #endregion this.WireGroupNoticeID = ec_Notice.WireGroupNoticeID; this.CheckFLG = ec_Notice.CheckFLG; this.IsReadOnly = ec_Notice.CheckFLG; } /// /// 设置数据 /// public void setData() { } #endregion } }