diff options
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ActionLogs/ViewModels/MainViewVM.cs')
| -rw-r--r-- | Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ActionLogs/ViewModels/MainViewVM.cs | 75 |
1 files changed, 62 insertions, 13 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ActionLogs/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ActionLogs/ViewModels/MainViewVM.cs index a550a1911..5f2d86b40 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ActionLogs/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ActionLogs/ViewModels/MainViewVM.cs @@ -2,14 +2,18 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Data.Entity; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Windows; using Tango.BL; using Tango.BL.Builders; using Tango.BL.Entities; using Tango.BL.Enumerations; +using Tango.BL.ValueObjects; using Tango.Core.Commands; +using Tango.Core.ExtensionMethods; using Tango.MachineStudio.Common; using Tango.SharedUI.Components; @@ -17,6 +21,8 @@ namespace Tango.MachineStudio.ActionLogs.ViewModels { public class MainViewVM : StudioViewModel { + #region properties + private DateTime _startSelectedDate; public DateTime StartSelectedDate { @@ -49,48 +55,83 @@ namespace Tango.MachineStudio.ActionLogs.ViewModels public SelectedObjectCollection<ActionLogType> SelectedActionLogTypes { get { return _selectedActionLogTypes; } - set { _selectedActionLogTypes = value; RaisePropertyChanged(nameof(SelectedActionLogTypes)); } + set { _selectedActionLogTypes = value; + RaisePropertyChanged(nameof(SelectedActionLogTypes)); } } + private ActionLog _selectedActionLog = null; + public ActionLog SelectedActionLog + { + get { return _selectedActionLog; } + set { _selectedActionLog = value; + SelectedItemChanged(); + RaisePropertyChangedAuto(); + InvalidateRelayCommands(); + } + } + + private ActionLogDifference _differenceObject; + public ActionLogDifference DifferenceObject + { + get { return _differenceObject; } + set { _differenceObject = value; RaisePropertyChangedAuto(); } + } + + + private bool _isRunning; + public bool IsRunning + { + get { return _isRunning; } + set { _isRunning = value; } + } + + #endregion + public RelayCommand SearchCommand { get; set; } public RelayCommand CopyToClipBoardCommand { get; set; } public MainViewVM() { ActionLogs = new ObservableCollection<ActionLog>(); - SearchCommand = new RelayCommand(Search); - CopyToClipBoardCommand = new RelayCommand(CopyToClipBoard); - DateTime now = DateTime.Now; ; + SearchCommand = new RelayCommand(GetActionLogs, ()=> !IsRunning); + CopyToClipBoardCommand = new RelayCommand(CopyToClipBoard, () => SelectedActionLog != null && SelectedActionLog.DifferenceObject != null); + DateTime now = DateTime.Now; StartSelectedDate = now.AddMonths(-1); EndSelectedDate = now; - + _isRunning = false; var source = Enum.GetValues(typeof(ActionLogType)).Cast<ActionLogType>().ToObservableCollection(); var syncedSource = Enum.GetValues(typeof(ActionLogType)).Cast<ActionLogType>().ToObservableCollection(); SelectedActionLogTypes = new SelectedObjectCollection<ActionLogType>(source, syncedSource); - - //SelectedActionLogTypes.ToList().ForEach(x => x.IsSelected = true); } public override void OnApplicationReady() { } - - private void Search() - { - GetActionLogs(); - } + private void CopyToClipBoard() { + DataObject data = new DataObject(SelectedActionLog.DifferenceObject.ToJsonString()); + System.Windows.Clipboard.SetDataObject(data); + } + + /// <summary> + /// New Database Query with search parameters. Initialization ActionLogs property. + /// </summary> private async void GetActionLogs() { string filter = SearchFilter?.ToLower(); + if (String.IsNullOrWhiteSpace(filter)) filter = null; + using (ObservablesContext db = ObservablesContext.CreateDefault()) { - ActionLogs = await new ActionLogsCollectionBuilder(db).Set(x => x.LastUpdated < EndSelectedDate && x.LastUpdated >= StartSelectedDate) + DateTime startUtc = StartSelectedDate.ToUniversalTime(); + DateTime endUtc = EndSelectedDate.ToUniversalTime() + DateTime.Now.TimeOfDay; + IsRunning = true; + ActionLogs = await new ActionLogsCollectionBuilder(db).Set(x => x.LastUpdated <= DbFunctions.TruncateTime(endUtc) && x.LastUpdated >= DbFunctions.TruncateTime(startUtc.Date)) .WithUsers() .WithActionType(SelectedActionLogTypes.SynchedSource.ToArray()) .Query(y => y.Where @@ -99,7 +140,15 @@ namespace Tango.MachineStudio.ActionLogs.ViewModels || (x.RelatedObjectName != null && x.RelatedObjectName.ToLower().StartsWith(filter)) || (x.User != null && x.User.Contact != null && x.User.Contact.FullName.ToLower().StartsWith(filter))))) .BuildAsync(); + IsRunning = false; } } + + private void SelectedItemChanged() + { + if (SelectedActionLog == null || SelectedActionLog.DifferenceObject== null) + return; + DifferenceObject = SelectedActionLog.DifferenceObject; + } } } |
