| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236 |
- using OHV.Common.Events;
- using Prism.Commands;
- using Prism.Events;
- using Prism.Mvvm;
- using Prism.Services.Dialogs;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Input;
- namespace OHV.Module.Interactivity.PopUp
- {
- public class OpticalReadingConfigViewModel : BindableBase, IDialogAware
- {
- private DelegateCommand<string> _closeDialogCommand;
- public DelegateCommand<string> CloseDialogCommand =>
- _closeDialogCommand ?? ( _closeDialogCommand = new DelegateCommand<string>( CloseDialog ) );
- Brush _opReaderOutFirst = Brushes.Gray;
- Brush _opReaderOutSecond = Brushes.Gray;
- Brush _opReaderOutThird = Brushes.Gray;
- public Brush OpReaderOutFirst
- {
- get { return this._opReaderOutFirst; }
- set { this.SetProperty( ref this._opReaderOutFirst , value ); }
- }
- public Brush OpReaderOutSecond
- {
- get { return this._opReaderOutSecond; }
- set { this.SetProperty( ref this._opReaderOutSecond , value ); }
- }
- public Brush OpreaderOutThird
- {
- get { return this._opReaderOutThird; }
- set { this.SetProperty( ref this._opReaderOutThird , value ); }
- }
- private int _curvePatternResult;
- public int CurvePatternResult
- {
- get { return this._curvePatternResult; }
- set { this.SetProperty( ref this._curvePatternResult , value ); }
- }
- private int _drivePatternResult;
- public int DrivePatternResult
- {
- get { return this._drivePatternResult; }
- set { this.SetProperty( ref this._drivePatternResult , value ); }
- }
- private bool _resultPatternOne;
- public bool ResultPatternOne
- {
- get { return this._resultPatternOne; }
- set
- {
- this.SetProperty( ref this._resultPatternOne , value );
- }
- }
- private bool _resultPatternTwo;
- public bool ResultPatternTwo
- {
- get { return this._resultPatternTwo; }
- set
- {
- this.SetProperty( ref this._resultPatternTwo , value );
- }
- }
- private bool _resultPatternThree;
- public bool ResultPatternThree
- {
- get { return this._resultPatternThree; }
- set
- {
- this.SetProperty( ref this._resultPatternThree , value );
- }
- }
- private bool _resultPatternFour;
- public bool ResultPatternFour
- {
- get { return this._resultPatternFour; }
- set
- {
- this.SetProperty( ref this._resultPatternFour , value );
- }
- }
- private bool _resultPatternFive;
- public bool ResultPatternFive
- {
- get { return this._resultPatternFive; }
- set
- {
- this.SetProperty( ref this._resultPatternFive , value );
- }
- }
- private string _title = "SteeringConfigView";
- public string Title
- {
- get { return this._title; }
- set
- {
- this.SetProperty( ref this._title , value );
- }
- }
- private int _obstacleDrive;
- public int ObstacleDrive
- {
- get { return this._obstacleDrive; }
- set { this.SetProperty( ref this._obstacleDrive , value ); }
- }
- private int _obstacleCurve;
- public int ObstacleCurve
- {
- get { return this._obstacleCurve; }
- set { this.SetProperty( ref this._obstacleCurve , value ); }
- }
- public ICommand DetectPatternSave { get; set; }
- public ICommand ResultPattern { get; set; }
- public ICommand PatternResultKyein { get; set; }
- public event Action<IDialogResult> RequestClose;
- IEventAggregator eventAggregator;
- MessageController messageController;
- public OpticalReadingConfigViewModel( IEventAggregator _ea, MessageController _msg )
- {
- this.eventAggregator = _ea;
- this.eventAggregator.GetEvent<GUIMessagePubSubEvent>().Unsubscribe( UICallbackCommunication );
- this.eventAggregator.GetEvent<GUIMessagePubSubEvent>().Subscribe( UICallbackCommunication, ThreadOption.UIThread );
- this.messageController = _msg;
- this.DetectPatternSave = new DelegateCommand( ExecuteDetectPatternSave );
- this.ResultPattern = new DelegateCommand<object>( ExecuteResultPattern );
- this.PatternResultKyein = new DelegateCommand<object>( ExecutePatternResultKyein );
- }
- private void UICallbackCommunication( GUIMessageEventArgs obj )
- {
- }
- private void ExecutePatternResultKyein( object obj)
- {
- var numpad = new CalcuratorView();
- var result = numpad.ShowDialog(0);
- var pattern = obj.ToString();
- switch(pattern)
- {
- case "C":
- this.CurvePatternResult = Convert.ToInt32( result );
- break;
- case "D":
- this.DrivePatternResult = Convert.ToInt32( result );
- break;
- }
- }
- private void ExecuteResultPattern(object _obj)
- {
- }
- private byte ConvertToByte( BitArray _bitArray)
- {
- byte[] bytes = new byte[ 1 ];
- _bitArray.CopyTo( bytes , 0 );
- return bytes[ 0 ];
- }
- private void ExecuteDetectPatternSave( )
- {
- this.messageController.ShowConfirmationPopupView( "Pattern Save ?" , r =>
- {
- if ( r.Result == ButtonResult.OK )
- {
- //bool[] bitResult = new bool[] { this.ResultPatternOne , this.ResultPatternTwo , this.ResultPatternThree , this.ResultPatternFour , this.ResultPatternFive };
- //var result = new System.Collections.BitArray( bitResult );
- //this.PatternResult = ConvertToByte( result );
- //this.Publish(this.PatternResult);
- }
- } );
- }
- #region Dialog Function
- public bool CanCloseDialog( )
- {
- return true;
- }
- public void OnDialogClosed( )
- {
- }
- public void OnDialogOpened( IDialogParameters parameters )
- {
- }
- private void CloseDialog( string parameter )
- {
- ButtonResult result = ButtonResult.None;
- if ( parameter?.ToLower() == "true" )
- result = ButtonResult.OK;
- else if ( parameter?.ToLower() == "false" )
- result = ButtonResult.Cancel;
- RaiseRequestClose( new DialogResult( result ) );
- }
- public virtual void RaiseRequestClose( IDialogResult dialogResult )
- {
- RequestClose?.Invoke( dialogResult );
- }
- #endregion
- }
- }
|