Beispiel #1
0
        //protected static void OnPropertyChanged(DependencyObject target, DependencyPropertyChangedEventArgs e)
        //{
        //    var collectionSource = target as DataObjectCollectionSource;
        //    if (collectionSource == null) return;
        //    if (e.Property == ItemsSourceProperty)
        //    {
        //        bool hasNewValue = e.NewValue != null;
        //        collectionSource.AttachToEntitySource(hasNewValue, (IDataObjectCollection)e.NewValue);
        //    }
        //    else if (e.Property == RowSelectorProperty)
        //    {
        //        collectionSource._rowSelector = e.NewValue as IDataObjectSelector;
        //    }
        //    else if (e.Property == SorterProperty)
        //    {
        //        collectionSource._sorter = e.NewValue as IDataObjectSorter;
        //    }
        //    else if (e.Property == EntityFilterProperty)
        //    {
        //        collectionSource._dataObjectFilter = e.NewValue as IDataObjectFilter;
        //    }
        //}

        private void AttachToEntitySource(bool hasNewValue, IDataObjectCollection view)
        {
            if (_currentEntitySource != null)
            {
                _currentEntitySource.CollectionChanged     -= _weakEventHandler.Invoke;
                _currentEntitySource.EntityPropertyChanged -= _entityPropertyChangedHandler.Invoke;
            }
            _weakEventHandler             = null;
            _entityPropertyChangedHandler = null;
            if (hasNewValue)
            {
                _currentEntitySource                        = view;
                _weakEventHandler                           = new WeakEventHandler <NotifyCollectionChangedEventArgs>(ListChanged);
                _entityPropertyChangedHandler               = new WeakEventHandler <PropertyChangedEventArgs>(EntityPropertyChanged);
                _currentEntitySource.CollectionChanged     += _weakEventHandler.Invoke;
                _currentEntitySource.EntityPropertyChanged += _entityPropertyChangedHandler.Invoke;
                if (this.Selector != null)
                {
                    SelectRows();
                }
                else
                {
                    UpdateViewSource();
                }
            }
            else
            {
                _currentEntitySource = null;
                lock (_itemsSourceLock)
                {
                    _viewSource.Clear();
                }
            }
        }
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Method gets sorted collection.
        /// </summary>
        /// <returns>Sorted collection.</returns>
        private SortedDataObjectCollection <Zone> _GetSortedCollection()
        {
            IDataObjectCollection <Zone>      zones            = (IDataObjectCollection <Zone>)App.Current.Project.Zones;
            SortedDataObjectCollection <Zone> sortedCollection = new SortedDataObjectCollection <Zone>(zones, new CreationTimeComparer <Zone>());

            return(sortedCollection);
        }
        /// <summary>
        /// Constructor.
        /// </summary>
        public DefaultRoutesController(IDataObjectCollection <Route> routes)
        {
            // Check input parameter.
            Debug.Assert(routes != null);

            // Save routes as old default collection.
            _oldDefaultRoutes     = new List <Route>();
            _oldDefaultRouteLinks = new List <RouteLinks>();
            foreach (Route route in routes)
            {
                var tempRoute = route.CloneNoResults() as Route;
                _oldDefaultRoutes.Add(tempRoute);

                // Workaround: when application will call Project.Save method next time
                // all reference properties of tempRoute which points on database object
                // will be set to null, so we need to remeber this links. Do it by using
                // special structure with corresponding fields.
                RouteLinks tempRouteLinks = new RouteLinks();
                tempRouteLinks.StartLocation    = route.StartLocation;
                tempRouteLinks.EndLocation      = route.EndLocation;
                tempRouteLinks.Vehicle          = route.Vehicle;
                tempRouteLinks.Driver           = route.Driver;
                tempRouteLinks.Zones            = route.Zones;
                tempRouteLinks.RenewalLocations = route.RenewalLocations;
                tempRouteLinks.savedRouteID     = tempRoute.Id;
                _oldDefaultRouteLinks.Add(tempRouteLinks);
            }
        }
        /// <summary>
        /// Export route to GRF file.
        /// </summary>
        /// <param name="writer">XMLWriter.</param>
        /// <param name="route">Route to export.</param>
        /// <param name="stops">Route's stops.</param>
        /// <param name="project">Project, which contains this route.</param>
        /// <param name="geocoder">Geocoder.</param>
        /// <param name="solver">Solver.</param>
        /// <param name="orderPropertiesToExport">Collection of order properties, which must be
        /// exported.</param>
        /// <param name="compress">Flag, shows compress result file or not.</param>
        /// <returns>GrfExportResult which contains messages about exporting.</returns>
        public static GrfExportResult ExportToGRF(XmlWriter writer, Route route, ICollection <Stop> stops, Project project,
                                                  IGeocoder geocoder, IVrpSolver solver, ICollection <string> orderPropertiesToExport, bool compress)
        {
            GrfExportResult result = new GrfExportResult();

            writer.WriteStartElement(GRF_DOC_NODE_NAME);
            writer.WriteAttributeString(VERSION_ATTR_NAME, VERSION_VALUE);

            writer.WriteStartElement(ROUTEINFO_NODE_NAME);
            if (stops.Count > 0)
            {
                _SaveStops(
                    writer,
                    route,
                    stops,
                    orderPropertiesToExport,
                    project,
                    geocoder.AddressFields);
            }

            IDataObjectCollection <Barrier> barriers =
                (IDataObjectCollection <Barrier>)project.Barriers.Search(route.StartTime.Value.Date, true);

            _SaveBarriers(writer, barriers, result);
            _SaveRouteResults(writer, route, stops);
            writer.WriteEndElement();
            _SaveRouteSettings(writer, route, solver, result);
            writer.WriteEndElement();

            return(result);
        }
        /// <summary>
        /// Method unpacks dragging objects from dragging data
        /// </summary>
        /// <param name="draggingData"></param>
        /// <returns></returns>
        public Collection <Order> GetDraggingOrders(IDataObject draggingData)
        {
            Collection <Order> draggingObjects = new Collection <Order>();

            // get collection of dragging elements
            if (draggingData.GetDataPresent(DRAGGING_DATA_FORMAT_STRING))
            {
                // get data from  data.GetData("format");
                DraggingOrdersObject draggingObject = (DraggingOrdersObject)draggingData.GetData(DRAGGING_DATA_FORMAT_STRING);

                IDataObjectCollection <Order> ordersForDate = App.Current.Project.Orders.Search(draggingObject.OrdersPlannedDate);

                foreach (Order order in ordersForDate)
                {
                    foreach (Guid id in draggingObject.IDsCollection)
                    {
                        if (order.Id.Equals(id))
                        {
                            draggingObjects.Add(order);
                        }
                    }
                }
            }

            return(draggingObjects);
        }
        /// <summary>
        /// Writes stops content.
        /// </summary>
        /// <param name="data">Data keeper.</param>
        /// <param name="schedules">Schedules to export.</param>
        /// <param name="fields">Exported fields.</param>
        /// <param name="writeOnlyOrders">Write only orders flag.</param>
        /// <param name="tracker">Cancel tracker (can be null).</param>
        /// <param name="sw">Export writer.</param>
        private void _WriteStopsContent(DataKeeper data,
                                        ICollection <Schedule> schedules,
                                        ICollection <string> fields,
                                        bool writeOnlyOrders,
                                        ICancelTracker tracker,
                                        StreamWriter sw)
        {
            foreach (Schedule schedule in schedules)
            {
                Guid scheduleID = schedule.Id;
                foreach (Route route in schedule.Routes)
                {   // stops
                    IDataObjectCollection <Stop> stops = route.Stops;
                    foreach (Stop stop in stops)
                    {
                        _CheckCancelState(tracker);

                        if (!writeOnlyOrders ||
                            (writeOnlyOrders && (stop.StopType == StopType.Order)))
                        {
                            string exportString = _AssemblyStopString(fields,
                                                                      data,
                                                                      scheduleID,
                                                                      stop,
                                                                      tracker);
                            Debug.Assert(!string.IsNullOrEmpty(exportString));
                            sw.WriteLine(exportString);
                        }
                    }
                }

                _WriteUnassignedOrdersContent(data, schedule, fields, tracker, sw);
            }
        }
Beispiel #7
0
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        protected override void DoValidate(IDataObjectCollection <Zone> objectToValidate, object currentTarget, string key,
                                           ValidationResults validationResults)
        {
            if (null == objectToValidate)
            {
                return;
            }

            string        format = this.MessageTemplate;
            StringBuilder sb     = new StringBuilder();

            foreach (Zone zone in objectToValidate)
            {
                string error = zone.Error;
                if (!string.IsNullOrEmpty(error))
                {
                    sb.AppendLine(string.Format(format, zone.Name));
                }
            }

            string message = sb.ToString().Trim();

            if (!string.IsNullOrEmpty(message))
            {
                this.LogValidationResult(validationResults, message, currentTarget, key);
            }
        }
Beispiel #8
0
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Creates copy all elements.
        /// </summary>
        /// <param name="source">Source collection.</param>
        /// <returns>Collection with copy elements for source.</returns>
        private ICollection <T> _DoCopy <T>(ICollection <T> source)
            where T : ICloneable
        {
            var copy = new List <T>(source.Count);

            foreach (T obj in source)
            {
                T objCopy = (T)obj.Clone();

                // WORKAROUND: special routine for schedule - need init Unassigned Orders
                Schedule scheduleCopy = objCopy as Schedule;
                if (null != scheduleCopy)
                {
                    Schedule schedule = obj as Schedule;
                    Debug.Assert(null != obj);

                    IDataObjectCollection <Order> unassignedOrders = schedule.UnassignedOrders;
                    if (null != unassignedOrders)
                    {
                        scheduleCopy.UnassignedOrders = unassignedOrders;
                    }
                }

                copy.Add(objCopy);
            }

            return(copy);
        }
        /// <summary>
        /// Updates the first schedule of specified type with a new value and name.
        /// </summary>
        private void _UpdateSchedule(ScheduleType scheduleTypeToUpdate, Schedule newValue, string newName)
        {
            // get all schedules
            Project project = App.Current.Project;
            IDataObjectCollection <Schedule> schedules = project.Schedules.Search(newValue.PlannedDate.Value, false);

            // and try to find schedule of specified type.
            Schedule oldSchedule = null;

            foreach (Schedule schedule in schedules)
            {
                if (schedule.Type == scheduleTypeToUpdate)
                {
                    oldSchedule = schedule;
                    break;
                }
            }

            // delete old schedule if present
            if (oldSchedule != null)
            {
                project.Schedules.Remove(oldSchedule);
            }

            // create new schedule and add it to the project
            Schedule updatedSchedule = (Schedule)newValue.Clone();

            updatedSchedule.Type = scheduleTypeToUpdate;
            updatedSchedule.Name = newName;

            project.Schedules.Add(updatedSchedule);
        }
Beispiel #10
0
        /// <summary>
        /// Find order.
        /// </summary>
        private void _FindOrder()
        {
            Cursor = Cursors.Wait;

            try
            {
                // Get range.
                string keyword = txtOrderText.Text;

                DateTime   currentDate = DateTime.Now.Date;
                TimeRanges rangeType   = (TimeRanges)cbSearch.SelectedIndex;
                TimeRange  range       = null;
                if (rangeType == TimeRanges.SpecifiedTimeRange)
                {
                    if (dpFrom.SelectedDate.HasValue && dpTo.SelectedDate.HasValue)
                    {
                        range = new TimeRange(dpFrom.SelectedDate.Value.Date, dpTo.SelectedDate.Value.Date);
                    }
                }
                else
                {
                    range = TimeRangeHelper.GetRange(currentDate, rangeType);
                }

                // If range valid make search.
                if (range != null)
                {
                    if (_previousOrdersCollection != null)
                    {
                        _previousOrdersCollection.Dispose();
                        _previousOrdersCollection = null;
                    }

                    OrderManager manager = App.Current.Project.Orders;
                    IDataObjectCollection <Order> orders = manager.SearchByKeyword(range.Start, range.End.AddDays(1), keyword, true);

                    // Store orders collection to dispose.
                    _previousOrdersCollection = orders;

                    UpdateLayout();

                    _collectionSource.Source = null;
                    // Set orders collection.
                    _collectionSource.Source = orders;

                    // Save last search criteria.
                    Properties.Settings.Default.FindOrdersLastKeyword    = txtOrderText.Text;
                    Properties.Settings.Default.FindOrdersSearchCriteria =
                        TimeRangeHelper.GetRangeSettingsName(rangeType);
                    Properties.Settings.Default.Save();

                    _needToClearSelection = true;
                }
            }
            finally
            {
                Cursor = Cursors.Arrow;
            }
        }
Beispiel #11
0
        /// <summary>
        /// Inits collecton of grid items
        /// </summary>
        protected override void _InitDataGridCollection()
        {
            DataGridCollectionViewSource                  vehicleCollectionSource            = (DataGridCollectionViewSource)base.LayoutRoot.FindResource(COLLECTION_SOURCE_KEY);
            IDataObjectCollection <VehicleSpecialty>      vehiclesSpecialtiesCollection      = (IDataObjectCollection <VehicleSpecialty>)App.Current.Project.VehicleSpecialties;
            SortedDataObjectCollection <VehicleSpecialty> sortedVehicleSpecialtiesCollection = new SortedDataObjectCollection <VehicleSpecialty>(vehiclesSpecialtiesCollection, new CreationTimeComparer <VehicleSpecialty>());

            vehicleCollectionSource.Source = sortedVehicleSpecialtiesCollection;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="RoutesCollectionOwner"/> class.
        /// </summary>
        /// <param name="routes">A collection of routes owned by this instance.</param>
        public RoutesCollectionOwner(IDataObjectCollection <Route> routes)
        {
            CodeContract.RequiresNotNull("routes", routes);

            _routes = routes;
            _routes.CollectionChanged += _RoutesCollectionChanged;
            _TrackAssociations();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="RoutesCollectionOwner"/> class.
        /// </summary>
        /// <param name="routes">A collection of routes owned by this instance.</param>
        public RoutesCollectionOwner(IDataObjectCollection<Route> routes)
        {
            CodeContract.RequiresNotNull("routes", routes);

            _routes = routes;
            _routes.CollectionChanged += _RoutesCollectionChanged;
            _TrackAssociations();
        }
Beispiel #14
0
 /// <summary>
 /// Creates data object context for the specified data objects collection.
 /// </summary>
 /// <typeparam name="T">The type of data objects in the source collection.</typeparam>
 /// <param name="source">The reference to the data objects collection to create data object
 /// context for.</param>
 /// <returns>A new key-value pair containing <typeparamref name="T"/> as a key and
 /// data object context for the <paramref name="source"/> as a value.</returns>
 private static KeyValuePair <Type, IDataObjectContext> _MakeContext <T>(
     IDataObjectCollection <T> source)
     where T : DataObject
 {
     return(new KeyValuePair <Type, IDataObjectContext>(
                typeof(T),
                new RelatedDataObjectCollectionContext <T>(source)));
 }
        /// <summary>
        /// Returns orders.
        /// </summary>
        /// <param name="initialQuery">Intial query to the database.</param>
        /// <param name="queryParams">Parameters for the query.</param>
        /// <param name="filterClause">Filter clause used for syncronized data object collections.</param>
        /// <returns>Collection of founded orders.
        /// It is syncronized in <c>filterClause</c> isn't null.</returns>
        protected IDataObjectCollection <Order> _SearchOrders(string initialQuery,
                                                              ObjectParameter[] queryParams,
                                                              Expression <Func <DataModel.Orders, bool> > filterClause)
        {
            IDataObjectCollection <Order> result = _Search(initialQuery, queryParams, filterClause);

            return(result);
        }
Beispiel #16
0
        /// <summary>
        /// Initializes a new instance of the RelatedDataObjectCollectionContext class.
        /// </summary>
        /// <param name="source">Source collection of data objects to track changes for.</param>
        public RelatedDataObjectCollectionContext(IDataObjectCollection <T> source)
        {
            Debug.Assert(source != null);
            Debug.Assert(source.All(item => item != null));

            _source = source;
            _Reset();
        }
 private void _FilterDrivers(IDataObjectCollection <Route> routes, IList filterObjects,
                             ref Collection <ESRI.ArcLogistics.Data.DataObject> filtredObjects)
 {
     for (int index = 0; index < routes.Count; ++index)
     {
         _FilterObject(routes[index].Driver, filterObjects, ref filtredObjects);
     }
 }
        /// <summary>
        /// Checks is object present in object collection.
        /// </summary>
        /// <param name="currentObj">Object to check.</param>
        /// <param name="collection">Object's collection.</param>
        /// <returns>TRUE if cheked object present in collection.</returns>
        private bool _IsObjectPresentInCollection <T>(T currentObj,
                                                      IDataObjectCollection <T> collection)
            where T : DataObject
        {
            string objName = currentObj.ToString();

            return(collection.Any(obj =>
                                  obj.ToString().Equals(objName, StringComparison.OrdinalIgnoreCase)));
        }
Beispiel #19
0
 /// <summary>
 /// Filteres objects
 /// </summary>
 /// <param name="objects">Collection of objects to filtration</param>
 /// <param name="filterObjects">Filter collection</param>
 /// <param name="usedObjects">Filtred objects</param>
 /// <remarks>To filtredObjects adding unique object only from filterObjects</remarks>
 protected void _FilterObjects <T>(IDataObjectCollection <T> objects, IList filterObjects,
                                   ref Collection <ESRI.ArcLogistics.Data.DataObject> usedObjects)
     where T : ESRI.ArcLogistics.Data.DataObject
 {
     for (int specIndex = 0; specIndex < objects.Count; ++specIndex)
     {
         _FilterObject(objects[specIndex], filterObjects, ref usedObjects);
     }
 }
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////

        private void _Init(IDataObjectCollection <T> coll,
                           IComparer <T> comparer)
        {
            // fill collection
            _sortedList.AddRange(coll);

            // sort
            _sortedList.Sort(comparer);
        }
        /// <summary>
        /// Returns orders where clause on a expression.
        /// </summary>
        /// <param name="whereClause">Expression for filtation collections.</param>
        /// <param name="asSynchronized">Indicates whether collection remains syncronized
        /// when orders are added or deleted to the project database.</param>
        /// <returns>Syncronized collection of found orders.</returns>
        protected IDataObjectCollection <Order> _SearchOrders(
            Expression <Func <DataModel.Orders, bool> > whereClause,
            bool asSynchronized)
        {
            Expression <Func <DataModel.Orders, bool> > expression =
                asSynchronized ? whereClause : null;
            IDataObjectCollection <Order> result = _Search(whereClause, expression);

            return(result);
        }
Beispiel #22
0
        /// <summary>
        /// Method check is property value was really changed.
        /// </summary>
        /// <param name="propertyName"></param>
        /// <param name="editedRoute"></param>
        /// <returns></returns>
        private bool _WasPropetyValueChanged(string propertyName, Route editedRoute)
        {
            PropertyInfo newInfo = editedRoute.GetType().GetProperty(propertyName);

            object newValue = newInfo.GetValue(editedRoute, null);

            // check Zones value
            if (newValue is IDataObjectCollection <Zone> )
            {
                IDataObjectCollection <Zone> newCollection = (IDataObjectCollection <Zone>)newValue;
                ICollection <Zone>           oldCollection = (ICollection <Zone>)_initialRouteProperties[propertyName];

                if (newCollection.Count != oldCollection.Count)
                {
                    return(true);
                }
                foreach (Zone newLocation in newCollection)
                {
                    if (!oldCollection.Contains(newLocation))
                    {
                        return(true);
                    }
                }
                return(false);
            }

            // check Locations value
            if (newValue is IDataObjectCollection <Location> )
            {
                IDataObjectCollection <Location> newCollection = (IDataObjectCollection <Location>)newValue;
                ICollection <Location>           oldCollection = (ICollection <Location>)_initialRouteProperties[propertyName];

                if (newCollection.Count != oldCollection.Count)
                {
                    return(true);
                }
                foreach (Location newLocation in newCollection)
                {
                    if (!oldCollection.Contains(newLocation))
                    {
                        return(true);
                    }
                }
                return(false);
            }

            object newObjValue = newInfo.GetValue(editedRoute, null);

            if (newObjValue is Boolean)
            {
                return(!_initialRouteProperties[propertyName].Equals(newObjValue));
            }

            return(_initialRouteProperties[propertyName] != newObjValue);
        }
Beispiel #23
0
        private void _Reset(IDataObjectCollection <TDataObj> dataObjects)
        {
            _dataObjects.Clear();

            List <TDataObj> coll = new List <TDataObj>(dataObjects);

            foreach (TDataObj obj in coll)
            {
                _dataObjects.Add(obj);
            }
        }
Beispiel #24
0
 private void _FilterLocations(IDataObjectCollection <Route> routes, IList filterObjects,
                               ref Collection <ESRI.ArcLogistics.Data.DataObject> filtredObjects)
 {
     for (int index = 0; index < routes.Count; ++index)
     {
         Route route = routes[index];
         _FilterObject(route.StartLocation, filterObjects, ref filtredObjects);
         _FilterObject(route.EndLocation, filterObjects, ref filtredObjects);
         _FilterObjects(route.RenewalLocations, filterObjects, ref filtredObjects);
     }
 }
        /// <summary>
        /// Method sets grid data binding.
        /// </summary>
        private void _InitDataGridCollection()
        {
            IDataObjectCollection <Schedule> schedules = _ScheduleVersions;

            if (schedules != null)
            {
                schedules.Dispose();
            }

            schedules = (IDataObjectCollection <Schedule>)App.Current.Project.Schedules.Search(App.Current.CurrentDate, true);
            SortedDataObjectCollection <Schedule> sortedScheduleCollection = new SortedDataObjectCollection <Schedule>(schedules, new ScheduleVersionComparer());

            _DataGridSource.Source = sortedScheduleCollection;
        }
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Initializes a new instance of the <c>SortedDataObjectCollection</c> class.
        /// </summary>
        public SortedDataObjectCollection(IDataObjectCollection <T> coll,
                                          IComparer <T> comparer)
        {
            Debug.Assert(coll != null);
            Debug.Assert(comparer != null);

            _Init(coll, comparer);

            coll.CollectionChanged += new NotifyCollectionChangedEventHandler(
                _coll_CollectionChanged);

            _coll     = coll;
            _comparer = comparer;
        }
        /// <summary>
        /// Get objects, which must be in startup extent.
        /// </summary>
        /// <returns>Objects, which must be in startup extent.</returns>
        private List <object> _GetScheduleExtentCollection()
        {
            List <object> scheduleList = new List <object>();

            IDataObjectCollection <Order> unassignedOrders = (IDataObjectCollection <Order>)_unassignedOrdersColl;

            if (_stopOrders.Count + unassignedOrders.Count > 0)
            {
                if (_routesColl != null)
                {
                    // Add stops to extent.
                    foreach (Stop stop in _stopOrders)
                    {
                        scheduleList.Add(stop);
                    }

                    // Add routes to extent.
                    foreach (Route route in _routesColl)
                    {
                        scheduleList.Add(route);
                    }
                }

                if (_unassignedOrdersColl != null)
                {
                    // Add orders to extent.
                    foreach (Order order in _unassignedOrdersColl)
                    {
                        scheduleList.Add(order);
                    }
                }
            }
            else
            {
                // Add zones to extent.
                foreach (Zone zone in App.Current.Project.Zones)
                {
                    scheduleList.Add(zone);
                }

                // Add locations to extent.
                foreach (Location location in App.Current.Project.Locations)
                {
                    scheduleList.Add(location);
                }
            }

            return(scheduleList);
        }
        /// <summary>
        /// Creates violation messages for route's specialities.
        /// </summary>
        /// <param name="obj">Violation's object (can be any DataObject: Vehicle, Driver and etc).</param>
        /// <param name="relatedObjects">Related object's.</param>
        /// <returns>Created violation messages for route's specialities.</returns>
        private static ICollection <MessageDetail> _GetSpecialitiesRouteViolationMessages(DataObject obj,
                                                                                          ICollection <DataObject> relatedObjects)
        {
            Debug.Assert(obj is Route);

            Route route = obj as Route;
            IDataObjectCollection <VehicleSpecialty> routeVehSpecialties = route.Vehicle.Specialties;
            IDataObjectCollection <DriverSpecialty>  routeDrvSpecialties = route.Driver.Specialties;

            Collection <DataObject> ordersVehSpecNotSupported = new Collection <DataObject>();
            Collection <DataObject> ordersDrvSpecNotSupported = new Collection <DataObject>();

            foreach (DataObject relatedObj in relatedObjects)
            {
                Order order = relatedObj as Order;
                if (null != order)
                {
                    foreach (DriverSpecialty specialty in order.DriverSpecialties)
                    {
                        if (!routeDrvSpecialties.Contains(specialty))
                        {
                            ordersDrvSpecNotSupported.Add(specialty);
                        }
                    }

                    foreach (VehicleSpecialty specialty in order.VehicleSpecialties)
                    {
                        if (!routeVehSpecialties.Contains(specialty))
                        {
                            ordersVehSpecNotSupported.Add(specialty);
                        }
                    }
                }
            }

            Collection <MessageDetail> details = new Collection <MessageDetail>();

            if (0 < ordersDrvSpecNotSupported.Count)
            {
                details.Add(_GetRouteViolationMessageStr(obj, ordersDrvSpecNotSupported, "DriverSpecialitiesRouteViolationMessage"));
            }
            if (0 < ordersVehSpecNotSupported.Count)
            {
                details.Add(_GetRouteViolationMessageStr(obj, ordersVehSpecNotSupported, "VehicleSpecialitiesRouteViolationMessage"));
            }

            return(details);
        }
        /// <summary>
        /// Method makes new edited version of a schedule.
        /// </summary>
        /// <param name="baseSchedule">Source schedule version.</param>
        /// <param name="otherVersions">Existed schedule versions.</param>
        /// <returns>Copied schedule version.</returns>
        private Schedule _MakeScheduleVersion(Schedule baseSchedule, IDataObjectCollection <Schedule> otherVersions)
        {
            Debug.Assert(baseSchedule != null);

            Schedule newVersion = (Schedule)baseSchedule.Clone();

            int latestVersionIndex = _GetLatestVersionIndex(otherVersions);

            newVersion.Name = (latestVersionIndex == 0) ?
                              (string)App.Current.FindResource("ClonedScheduleNameFormatWithoutNumber") :
                              string.Format((string)App.Current.FindResource("ClonedScheduleNameFormat"), latestVersionIndex);

            newVersion.Type = ScheduleType.Edited;

            return(newVersion);
        }
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Get schedule by day
        /// </summary>
        /// <param name="schedule"></param>
        /// <returns></returns>
        public static Schedule GetCurrentScheduleByDay(DateTime day)
        {
            IDataObjectCollection <Schedule> schedules = App.Current.Project.Schedules.Search(day);

            Schedule selectedSchedule = null;

            foreach (Schedule schedule in schedules)
            {
                if (ScheduleType.Current == schedule.Type)
                {
                    selectedSchedule = schedule;
                    break;
                }
            }

            return(selectedSchedule);
        }
        /// <summary>
        /// Method inits collection of drivers.
        /// </summary>
        protected void _InitDataGridCollection()
        {
            try
            {
                DataGridCollectionViewSource collectionSource = (DataGridCollectionViewSource)LayoutRoot.FindResource(COLLECTION_SOURCE_KEY);


                IDataObjectCollection <Driver>      collection = (IDataObjectCollection <Driver>)App.Current.Project.Drivers;
                SortedDataObjectCollection <Driver> sortedDriversCollection = new SortedDataObjectCollection <Driver>(collection, new CreationTimeComparer <Driver>());
                collectionSource.Source = sortedDriversCollection;

                _isDataGridCollectionInited = true;
            }
            catch (Exception ex)
            {
                _isDataGridCollectionInited = false;
                Logger.Info(ex);
            }
        }
Beispiel #32
0
 /// <summary>
 /// When route added to or removed from schedule we need to subscribe(unsubscribe) from event.
 /// </summary>
 /// <param name="sender">Ignored.</param>
 /// <param name="e">CollectionChangeEventArgs.</param>
 void SchedulesReference_AssociationChanged(object sender, CollectionChangeEventArgs e)
 {
     // If we added this route to schedule, remember it schedule.routes, subscribe to
     // collection changed event and clear _DefaultsRoutes if we haven't done this before.
     if (e.Action == CollectionChangeAction.Add)
     {
         if (_ScheduledRoutesCollection == null ||
             _ScheduledRoutesCollection != Schedule.Routes)
         {
             _AddScheduledRoutesCollectionChangedHandler();
         }
     }
     // If we removed route from collection - then unsubscribe from this
     // collection changed event and clear reference to this collection.
     if (e.Action == CollectionChangeAction.Remove)
     {
         _ScheduledRoutesCollection.CollectionChanged -= _ScheduleCollectionChanged;
         _ScheduledRoutesCollection = null;
     }
 }
        /// <summary>
        /// Constructor.
        /// </summary>
        public DefaultRoutesController(IDataObjectCollection<Route> routes)
        {
            // Check input parameter.
            Debug.Assert(routes != null);

            // Save routes as old default collection.
            _oldDefaultRoutes = new List<Route>();
            _oldDefaultRouteLinks = new List<RouteLinks>();
            foreach (Route route in routes)
            {
                var tempRoute = route.CloneNoResults() as Route;
                _oldDefaultRoutes.Add(tempRoute);

                // Workaround: when application will call Project.Save method next time
                // all reference properties of tempRoute which points on database object
                // will be set to null, so we need to remeber this links. Do it by using
                // special structure with corresponding fields.
                RouteLinks tempRouteLinks = new RouteLinks();
                tempRouteLinks.StartLocation = route.StartLocation;
                tempRouteLinks.EndLocation = route.EndLocation;
                tempRouteLinks.Vehicle = route.Vehicle;
                tempRouteLinks.Driver = route.Driver;

                tempRouteLinks.Zones = tempRoute.Zones;
                tempRouteLinks.RenewalLocations = tempRoute.RenewalLocations;
                tempRouteLinks.savedRouteID = tempRoute.Id;
                _oldDefaultRouteLinks.Add(tempRouteLinks);
            }
        }
Beispiel #34
0
        /// <summary>
        /// Remember ref to current scheduled routes, subscribe to scheduled routes 
        /// collection changed event and clear default routes collection.
        /// </summary>
        private void _AddScheduledRoutesCollectionChangedHandler()
        {
            this.Schedule.RoutesCollectionInitialized -= _ScheduleRoutesCollectionInitialized;

            _ScheduledRoutesCollection = this.Schedule.Routes;
            _ScheduledRoutesCollection.CollectionChanged += _ScheduleCollectionChanged;
            if (_DefaultRoutesCollection != null)
                (this as ISupportOwnerCollection).OwnerCollection = null;
        }