Exemplo n.º 1
0
        /// <summary>
        /// Creates route and initializes route's fields by default values if possible.
        /// </summary>
        /// <returns>Created route.</returns>
        private Route _CreateRouteWithDefaultValues()
        {
            Route route = App.Current.Project.CreateRoute();

            // set default driver
            Collection <ESRI.ArcLogistics.Data.DataObject> usedDrivers = RoutesHelper.CreateUsedDriversCollection();
            Collection <Driver> freeDrivers = new Collection <Driver>();

            foreach (Driver driver in App.Current.Project.Drivers)
            {
                if (!usedDrivers.Contains(driver))
                {
                    freeDrivers.Add(driver);
                }
            }

            if (freeDrivers.Count == 1)
            {
                route.Driver = freeDrivers[0];
            }

            // set default vehicle
            Collection <ESRI.ArcLogistics.Data.DataObject> usedVehicles = RoutesHelper.CreateUsedVehiclesCollection();
            Collection <Vehicle> freeVehicles = new Collection <Vehicle>();

            foreach (Vehicle vehicle in App.Current.Project.Vehicles)
            {
                if (!usedVehicles.Contains(vehicle))
                {
                    freeVehicles.Add(vehicle);
                }
            }

            if (freeVehicles.Count == 1)
            {
                route.Vehicle = freeVehicles[0];
            }

            // set default locations
            if (App.Current.Project.Locations.Count == 1)
            {
                route.StartLocation = App.Current.Project.Locations[0];
                route.EndLocation   = App.Current.Project.Locations[0];
            }

            // set default color
            route.Color = RouteColorManager.Instance.NextRouteColor(_routes);

            return(route);
        }
        protected override void _BuildAvailableCollection()
        {
            base._BuildAvailableCollection();

            Collection <ESRI.ArcLogistics.Data.DataObject> usedItems = new Collection <ESRI.ArcLogistics.Data.DataObject>();

            if (ItemType != null && ItemType.Equals(typeof(ArcLogistics.DomainObjects.Vehicle)))
            {
                usedItems = RoutesHelper.CreateUsedVehiclesCollection();
            }
            else if (ItemType != null && ItemType.Equals(typeof(ArcLogistics.DomainObjects.Driver)))
            {
                usedItems = RoutesHelper.CreateUsedDriversCollection();
            }

            foreach (ESRI.ArcLogistics.Data.DataObject obj in usedItems)
            {
                if (obj != SelectedItem)
                {
                    AvailableCollection.Remove(obj);
                }
            }
        }