| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Input;
- using OHV.Common.Events;
- using OHV.Common.Model;
- using OHV.Common.Shareds;
- using OHV.Module.Interactivity;
- using OHV.SqliteDAL;
- using Prism.Commands;
- using Prism.Events;
- using Prism.Mvvm;
- namespace OHV.Module.ListViews.Views
- {
- class CommandListViewModel : BindableBase
- {
- #region Binding Properties
- private ObservableCollection<Command> _commandList;
- public ObservableCollection<Command> CommandList
- {
- get { return this._commandList; }
- set { SetProperty(ref this._commandList, value); }
- }
- private string targetID;
- public string TargetID
- {
- get { return targetID; }
- set { SetProperty(ref this.targetID, value); }
- }
- private eCommandType selectedCommandType;
- public eCommandType SelectedCommandType
- {
- get { return selectedCommandType; }
- set { SetProperty(ref this.selectedCommandType, value); }
- }
- private List<string> targetIDList;
- public List<string> TargetIDList
- {
- get { return targetIDList; }
- set { SetProperty(ref this.targetIDList, value); }
- }
- #endregion
- public ICommand SaveCommand { get; set; }
- public ICommand DeleteCommand { get; set; }
- IEventAggregator eventAggregator;
- SqliteManager sql;
- MessageController messageController;
- public CommandListViewModel(IEventAggregator ea, SqliteManager sql, MessageController msgController )
- {
- this.eventAggregator = ea;
- this.messageController = msgController;
- this.sql = sql;
- this.sql.CommandDAL.ChangedProperty += this.RefreshCommandLIst;
- this.CommandList = new ObservableCollection<Command>(sql.CommandDAL.All);
- this.TargetIDList = sql.RouteDal.All.Select(x => x.Name).ToList();
- this.TargetIDList.Add("None");
- this.SaveCommand = new DelegateCommand(ExecuteSaveCommand);
- this.DeleteCommand = new DelegateCommand(ExecuteDeleteCommand);
- this.eventAggregator.GetEvent<VehicleCommandListChanged>().Unsubscribe(UICallbackCommunication);
- this.eventAggregator.GetEvent<VehicleCommandListChanged>().Subscribe(UICallbackCommunication, ThreadOption.UIThread);
- }
- private void UICallbackCommunication(string obj)
- {
- //RefreshCommandLIst(null, null);
- }
- private void ExecuteDeleteCommand()
- {
- List<Command> deleteList = new List<Command>();
- foreach (var item in this.CommandList)
- {
- if (item.IsSelected)
- {
- deleteList.Add(item);
- }
- }
- deleteList.ForEach(x => { this.sql.CommandDAL.Delete(x); });
- //RefreshCommandLIst();
- }
- private void ExecuteSaveCommand()
- {
- Command cmd = new Command() { TargetID = TargetID, Type = SelectedCommandType };
- var route = sql.RouteDal.GetRoute( TargetID );
- if (route ==null )
- messageController.ShowNotificationView( "Not Found TargetID" );
- else
- sql.CommandDAL.Add(cmd);
- this.TargetID = "None";
- this.SelectedCommandType = eCommandType.Move;
- }
- void RefreshCommandLIst()
- {
- Application.Current.Dispatcher.Invoke(() =>
- {
- this.CommandList.Clear();
- this.CommandList.AddRange(sql.CommandDAL.All);
- });
- }
- }
- }
|