Exemple #1
0
        private int GetRegionNumber()
        {
            // test to see if an internal number is present in the incoming dataset
            var existingRegionId = Get("Region.ExistingRegionID");

            if (!String.IsNullOrEmpty(existingRegionId))
            {
                var region = MaterialService.GetRegion(Int32.Parse(existingRegionId));
                if (region != null)
                {
                    return(region.PoliticalRegionID);
                }
            }
            // No existing region found? need to create it

            var politicalRegion = Get("Region.Region", "[Imported Data]");
            var strCountry      = Get("Region.Country");
            var strState        = Get("Region.State/Province");
            var strCounty       = Get("Region.County");

            if (string.IsNullOrWhiteSpace(politicalRegion))
            {
                politicalRegion = "[Imported Data]";
            }

            if (_lastRegion != null && _lastRegion.Equals(politicalRegion, strCountry, strState, strCounty))
            {
                return(_lastRegion.RegionID);
            }
            else
            {
                var lngRegionID = Service.ImportRegion(politicalRegion, 0, "Region");
                if (!string.IsNullOrWhiteSpace(strCountry))
                {
                    lngRegionID = Service.ImportRegion(strCountry, lngRegionID, "Country");
                }
                if (!string.IsNullOrWhiteSpace(strState))
                {
                    lngRegionID = Service.ImportRegion(strState, lngRegionID, "State/Province");
                }
                if (!string.IsNullOrWhiteSpace(strCounty))
                {
                    lngRegionID = Service.ImportRegion(strCounty, lngRegionID, "County");
                }

                _lastRegion = new CachedRegion {
                    SourceRowID = CurrentRowId, RegionID = lngRegionID, PoliticalRegion = politicalRegion, Country = strCountry, State = strState, County = strCounty
                };

                return(lngRegionID);
            }
        }
Exemple #2
0
        protected override void RollbackRow(int rowId)
        {
            // The current row has been rolled back, so we need to invalidate any cached objects that originated from this row.
            if (_lastRegion.SourceRowID == rowId)
            {
                _lastRegion = null;
            }

            if (_lastSiteVisit.SourceRowID == rowId)
            {
                _lastSiteVisit = null;
            }

            _siteCache.RemoveAll((cachedSite) => cachedSite.SourceRowID == rowId);
            _taxonCache.RemoveAll((cachedTaxon) => cachedTaxon.SourceRowID == rowId);
        }
        private int GetRegionNumber()
        {
            // test to see if an internal number is present in the incoming dataset
            var existingRegionId = Get("Region.ExistingRegionID");
            if (!String.IsNullOrEmpty(existingRegionId)) {
                var region = MaterialService.GetRegion(Int32.Parse(existingRegionId));
                if (region != null) {
                    return region.PoliticalRegionID;
                }
            }
            // No existing region found? need to create it

            var politicalRegion = Get("Region.Region", "[Imported Data]");
            var strCountry = Get("Region.Country");
            var strState = Get("Region.State/Province");
            var strCounty = Get("Region.County");

            if (string.IsNullOrWhiteSpace(politicalRegion)) {
                politicalRegion = "[Imported Data]";
            }

            if (_lastRegion != null && _lastRegion.Equals(politicalRegion, strCountry, strState, strCounty)) {
                return _lastRegion.RegionID;
            } else {
                var lngRegionID = Service.ImportRegion(politicalRegion, 0, "Region");
                if (!string.IsNullOrWhiteSpace(strCountry)) {
                    lngRegionID = Service.ImportRegion(strCountry, lngRegionID, "Country");
                }
                if (!string.IsNullOrWhiteSpace(strState)) {
                    lngRegionID = Service.ImportRegion(strState, lngRegionID, "State/Province");
                }
                if (!string.IsNullOrWhiteSpace(strCounty)) {
                    lngRegionID = Service.ImportRegion(strCounty, lngRegionID, "County");
                }

                _lastRegion = new CachedRegion { SourceRowID = CurrentRowId, RegionID = lngRegionID, PoliticalRegion = politicalRegion, Country = strCountry, State = strState, County = strCounty };

                return lngRegionID;
            }
        }
        protected override void RollbackRow(int rowId)
        {
            // The current row has been rolled back, so we need to invalidate any cached objects that originated from this row.
            if (_lastRegion.SourceRowID == rowId) {
                _lastRegion = null;
            }

            if (_lastSiteVisit.SourceRowID == rowId) {
                _lastSiteVisit = null;
            }

            _siteCache.RemoveAll((cachedSite) => cachedSite.SourceRowID == rowId);
            _taxonCache.RemoveAll((cachedTaxon) => cachedTaxon.SourceRowID == rowId);
        }