Ejemplo n.º 1
0
        protected async void SetParcelsHistoric()
        {
            #region Set parcels historic
            string errorMessage = await QueuedTask.Run(async() =>
            {
                var myParcelFabricLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType <ParcelLayer>().FirstOrDefault();
                if (myParcelFabricLayer == null)
                {
                    return("Please add a parcel fabric to the map");
                }
                try
                {
                    FeatureLayer destPolygonL = null;
                    //find the first layer that is a parcel type, is non-historic, and has a selection
                    bool bFound         = false;
                    var ParcelTypesEnum = await myParcelFabricLayer.GetParcelTypeNames();
                    foreach (FeatureLayer mapFeatLyr in MapView.Active.Map.GetLayersAsFlattenedList().OfType <FeatureLayer>())
                    {
                        foreach (string ParcelType in ParcelTypesEnum)
                        {
                            var layerEnum = await myParcelFabricLayer.GetParcelPolygonLayerByTypeName(ParcelType);
                            foreach (FeatureLayer flyr in layerEnum)
                            {
                                if (flyr == mapFeatLyr)
                                {
                                    bFound       = mapFeatLyr.SelectionCount > 0;
                                    destPolygonL = mapFeatLyr;
                                    break;
                                }
                            }
                            if (bFound)
                            {
                                break;
                            }
                        }
                        if (bFound)
                        {
                            break;
                        }
                    }
                    if (!bFound)
                    {
                        return("Please select parcels to set as historic.");
                    }

                    var theActiveRecord = myParcelFabricLayer.GetActiveRecord();
                    if (theActiveRecord == null)
                    {
                        return("There is no Active Record. Please set the active record and try again.");
                    }

                    var ids = new List <long>(destPolygonL.GetSelection().GetObjectIDs());
                    //can do multi layer selection but using single per code above
                    var kvp            = new KeyValuePair <MapMember, List <long> >(destPolygonL, ids);
                    var sourceFeatures = new List <KeyValuePair <MapMember, List <long> > > {
                        kvp
                    };
                    var editOper = new EditOperation()
                    {
                        Name            = "Set Parcels Historic",
                        ProgressMessage = "Set Parcels Historic...",
                        ShowModalMessageAfterFailure = true,
                        SelectNewFeatures            = true,
                        SelectModifiedFeatures       = false
                    };
                    editOper.SetParcelHistoryRetired(myParcelFabricLayer, sourceFeatures, theActiveRecord);
                    if (!editOper.Execute())
                    {
                        return(editOper.ErrorMessage);
                    }
                }
                catch (Exception ex)
                {
                    return(ex.Message);
                }
                return("");
            });

            if (!string.IsNullOrEmpty(errorMessage))
            {
                MessageBox.Show(errorMessage, "Set Parcels Historic.");
            }
            #endregion
        }