123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- using Prism.Commands;
- using Prism.Events;
- using ProjectManagementSystem.Common.Core;
- using ProjectManagementSystem.Common.Logger;
- using ProjectManagementSystem.Language;
- using ProjectManagementSystemView.Infrastructure.Events;
- using ProjectManagementSystemView.Infrastructure.Extensions;
- using ProjectManagementSystemView.Infrastructure.Models;
- using PropertyChanged;
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- namespace ProjectManagementSystemView.ViewModels
- {
- [AddINotifyPropertyChangedInterface]
- public class DebugRollerHxViewModel
- {
- public bool IsVisible { get; set; }
- public byte ActionCode { get; set; }
- public VmInfoRollerHx SelectedVmData { get; set; }
- public ObservableCollection<VmInfoRollerHx> VmDatas { get; set; } = new ObservableCollection<VmInfoRollerHx>();
- public ObservableCollection<byte> ActionCodeCollection { get; set; } = new ObservableCollection<byte>();
- public DelegateCommand<object> SendCommand { get; set; }
- public DelegateCommand<object> QueryCommand { get; set; }
- public DebugRollerHxViewModel(IEventAggregator eventAggregator)
- {
- ActionCodeCollection.Add(1);
- ActionCodeCollection.Add(2);
- SendCommand = new DelegateCommand<object>(arg =>
- {
- RollerHxOpreate(arg);
- });
- QueryCommand = new DelegateCommand<object>(arg =>
- {
- DeviceControl.Instance.RollerHxQuery(SelectedVmData?.DeviceId ?? 0);
- });
- eventAggregator.GetEvent<UpdateViewEvent>().Subscribe(UpdateView);
- }
- private void UpdateView()
- {
- if (!IsVisible) return;
- var dataList = DeviceControl.Instance.Communication.InfoRollerHxDictionary.Values;
- VmDatas.Update(dataList, (s, v) => s.DeviceId == v.DeviceId);
- }
- private void RollerHxOpreate(object sender)
- {
- var deviceId = SelectedVmData?.DeviceId ?? 0;
- if (deviceId <= 0) return;
- if (ActionCode <= 0) return;
- string text = $"{sender}? {Langs.DeviceId}:{deviceId} {Langs.ActionCode}:{ActionCode}";
- var dialogResult = MessageBox.Show(text, Langs.Prompt, MessageBoxButton.OKCancel, MessageBoxImage.Question, MessageBoxResult.Cancel);
- if (dialogResult != MessageBoxResult.OK)
- {
- return;
- }
- DeviceControl.Instance.RollerHxOperate(deviceId, ActionCode);
- CLog.Instance.TaskLog.WriteInfo(Langs.RollerHxViewManualOperation, $"{Langs.DeviceId}:{deviceId} {Langs.ActionCode}:{ActionCode}");
- }
- }
- }
|