From 171f350d62cdd42766bf66698e8f8e1e780dcb23 Mon Sep 17 00:00:00 2001 From: Rudolf Jan Date: Wed, 29 Apr 2020 11:12:45 +0200 Subject: [PATCH] Fixed two display issues Timetable: service instance count update Servicesview: Calculated duration is not updated --- .../ViewModels/ServiceViewModel.cs | 48 +++++++++---------- .../ViewModels/TimeTableViewModel.cs | 6 ++- 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/TimeTableTool.Desktop/ViewModels/ServiceViewModel.cs b/TimeTableTool.Desktop/ViewModels/ServiceViewModel.cs index bfe342c..4f0b931 100644 --- a/TimeTableTool.Desktop/ViewModels/ServiceViewModel.cs +++ b/TimeTableTool.Desktop/ViewModels/ServiceViewModel.cs @@ -63,13 +63,13 @@ public ServiceModel SelectedService ServiceSelectedEvent serviceSelectedEvent = new ServiceSelectedEvent(); serviceSelectedEvent.SelectedService = _selectedService; _events.PublishOnUIThreadAsync(serviceSelectedEvent); - if(SelectedService!=null) + if (SelectedService != null) { - FullTimeEventsList= new BindableCollection(FullTimeEventDataAccess.GetAllFullTimeEventsPerService(SelectedService.Id)); + FullTimeEventsList = new BindableCollection(FullTimeEventDataAccess.GetAllFullTimeEventsPerService(SelectedService.Id)); } else { - FullTimeEventsList=null; + FullTimeEventsList = null; } NotifyOfPropertyChange(() => CanLoadTimeEvents); NotifyOfPropertyChange(() => SelectedService); @@ -221,7 +221,7 @@ public void EditService() SelectedServiceDirection = ServiceDirectionDataAccess.GetServiceDirectionById(ServiceDirectionId); ServiceDirectionName = SelectedServiceDirection.ServiceDirectionName; ServiceId = SelectedService.Id; - FullTimeEventsList= new BindableCollection(FullTimeEventDataAccess.GetAllFullTimeEventsPerService(SelectedService.Id)); + FullTimeEventsList = new BindableCollection(FullTimeEventDataAccess.GetAllFullTimeEventsPerService(SelectedService.Id)); NotifyOfPropertyChange(() => CanLoadTimeEvents); NotifyOfPropertyChange(() => CanEditService); NotifyOfPropertyChange(() => CanDeleteService); @@ -295,7 +295,7 @@ public void ClearService() ServiceDirectionName = ""; ServiceId = 0; NotifyOfPropertyChange(() => ServicesUI); - NotifyOfPropertyChange(()=>CanLoadTimeEvents); + NotifyOfPropertyChange(() => CanLoadTimeEvents); NotifyOfPropertyChange(() => CanEditService); } @@ -303,7 +303,7 @@ public bool CanLoadTimeEvents { get { - return SelectedService != null && (FullTimeEventsList==null || + return SelectedService != null && (FullTimeEventsList == null || FullTimeEventsList.Count == 0); } } @@ -317,34 +317,34 @@ public void LoadTimeEvents() public void SaveTimeEvents() { - foreach (var item in FullTimeEventsList) + foreach (var item in FullTimeEventsList) + { + if (item.EventType?.Length > 0) { - if (item.EventType?.Length > 0) + var timeEvent = new TimeEventModel(); + timeEvent.Id = item.Id; + timeEvent.EventType = item.EventType; + timeEvent.ArrivalTime = item.ArrivalTime; + timeEvent.WaitTime = item.WaitTime; + timeEvent.LocationId = item.LocationId; + timeEvent.ServiceId = item.ServiceId; + timeEvent.Order = item.Order; + if (item.Id > 0) { - var timeEvent = new TimeEventModel(); timeEvent.Id = item.Id; - timeEvent.EventType = item.EventType; - timeEvent.ArrivalTime = item.ArrivalTime; - timeEvent.WaitTime = item.WaitTime; - timeEvent.LocationId = item.LocationId; - timeEvent.ServiceId = item.ServiceId; - timeEvent.Order = item.Order; - if(item.Id>0) - { - timeEvent.Id=item.Id; TimeEventDataAccess.UpdateTimeEvent(timeEvent); } else - { + { TimeEventDataAccess.InsertTimeEventForService(timeEvent); } } } - int duration = FullTimeEventsList.Sum(x => x.ArrivalTime+x.WaitTime); - SelectedService.CalculatedDuration= duration; - ServiceDataAccess.UpdateServiceCalculatedDuration(duration,SelectedService.Id); - NotifyOfPropertyChange(()=>ServicesUI.ServiceList); - FullTimeEventsList= new BindableCollection(FullTimeEventDataAccess.GetAllFullTimeEventsPerService(SelectedService.Id)); + int duration = FullTimeEventsList.Sum(x => x.ArrivalTime + x.WaitTime); + SelectedService.CalculatedDuration = duration; + ServiceDataAccess.UpdateServiceCalculatedDuration(duration, SelectedService.Id); + ServicesUI.ServiceList.Refresh(); + FullTimeEventsList = new BindableCollection(FullTimeEventDataAccess.GetAllFullTimeEventsPerService(SelectedService.Id)); Log.Trace($"Time events for service {SelectedService.ServiceAbbreviation} saved", LogEventType.Event); } } diff --git a/TimeTableTool.Desktop/ViewModels/TimeTableViewModel.cs b/TimeTableTool.Desktop/ViewModels/TimeTableViewModel.cs index 3d2add6..1e9bbf5 100644 --- a/TimeTableTool.Desktop/ViewModels/TimeTableViewModel.cs +++ b/TimeTableTool.Desktop/ViewModels/TimeTableViewModel.cs @@ -264,8 +264,6 @@ protected override async void OnViewLoaded(object view) RouteId = rm.Id; TimetablesUI.TimetableList = new BindableCollection(TimetableDataAccess.GetAllTimetablesPerRoute(RouteId)); ServiceDirectionList = new BindableCollection(ServiceDirectionDataAccess.GetAllServiceDirectionsPerRoute(RouteId)); - - NotifyOfPropertyChange(() => TimetablesUI); } #endregion @@ -384,6 +382,7 @@ public void AddServiceInstance() ServiceInstancesDestinationList.Add(SelectedServiceInstanceSource); ConnectTtSiDataAccess.InsertConnection(SelectedServiceInstanceSource.Id, SelectedTimetable.Id); NotifyOfPropertyChange(() => ServiceInstancesDestinationList); + NotifyOfPropertyChange(()=>CopyStatus); } public bool CanRemoveServiceInstance @@ -398,6 +397,8 @@ public void RemoveServiceInstance() { ConnectTtSiDataAccess.DeleteConnection(SelectedServiceInstanceDestination.Id, SelectedTimetable.Id); ServiceInstancesDestinationList.Remove(SelectedServiceInstanceDestination); + NotifyOfPropertyChange(() => ServiceInstancesDestinationList); + NotifyOfPropertyChange(()=>CopyStatus); } @@ -415,6 +416,7 @@ public void CopyAllServiceInstances() ServiceInstancesDestinationList.Add(item); ConnectTtSiDataAccess.InsertConnection(item.Id, SelectedTimetable.Id); NotifyOfPropertyChange(() => ServiceInstancesDestinationList); + NotifyOfPropertyChange(()=>CopyStatus); } } }