Example #1
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);
        }
Example #2
0
        private int GetSiteVisitNumber(int siteId)
        {
            // test to see if an internal visit number is present in the incoming dataset
            var existingSiteVisitId = Get("SiteVisit.ExistingSiteVisitID");

            if (!String.IsNullOrEmpty(existingSiteVisitId))
            {
                var visit = MaterialService.GetSiteVisit(Int32.Parse(existingSiteVisitId));
                if (visit != null)
                {
                    return(visit.SiteVisitID);
                }
            }
            // No existing visit found? need to create it

            var iDateType        = FIXED_DATE;
            var strSiteVisitName = Get("SiteVisit.Visit Name");
            var strCollector     = Get("SiteVisit.Collector(s)");

            var strCasualDate = Get("SiteVisit.Casual time");

            int?startDate = GetConvert <int?>("SiteVisit.Start Date", null, false);

            if (!startDate.HasValue)
            {
                iDateType = CASUAL_DATE;
            }
            else
            {
                strCasualDate = Get("SiteVisit.Start Date", strCasualDate);
            }

            int?endDate = GetConvert <int?>("SiteVisit.End Date", null);

            if (!endDate.HasValue)
            {
                var sEndDate = Get("SiteVisit.End Date");
                if (!string.IsNullOrWhiteSpace(sEndDate))
                {
                    if (iDateType == FIXED_DATE)
                    {
                        throw new Exception("Invalid end date value - start date is in fixed format, end date is not");
                    }
                    else
                    {
                        if (string.IsNullOrWhiteSpace(strCasualDate))
                        {
                            strCasualDate = sEndDate;
                        }
                    }
                }
            }

            var timeStart = GetConvert <int?>("SiteVisit.Start Time", null);
            var timeEnd   = GetConvert <int?>("SiteVisit.End Time");

            var strFieldNumber = Get("SiteVisit.Field number");

            if (string.IsNullOrWhiteSpace(strSiteVisitName))
            {
                if (startDate.HasValue && startDate.Value > 0)
                {
                    if (iDateType == FIXED_DATE)
                    {
                        strSiteVisitName = strCollector + ", " + DateUtils.BLDateToStr(startDate.Value);
                    }
                    else
                    {
                        strSiteVisitName = strCollector + ", " + strCasualDate;
                    }
                }
                else
                {
                    if (endDate.HasValue && endDate.Value > 0)
                    {
                        if (iDateType == FIXED_DATE)
                        {
                            strSiteVisitName = strCollector + ", " + DateUtils.BLDateToStr(endDate.Value);
                        }
                        else
                        {
                            strSiteVisitName = strCollector + ", " + strCasualDate;
                        }
                    }
                    else
                    {
                        strSiteVisitName = strCollector;
                    }
                }
            }

            if (_lastSiteVisit != null && _lastSiteVisit.Equals(siteId, strSiteVisitName, strCollector, startDate, endDate, timeStart, timeEnd, strFieldNumber, strCasualDate))
            {
                return(_lastSiteVisit.SiteVisitID);
            }
            else
            {
                var visit = new SiteVisit {
                    SiteVisitName = strSiteVisitName,
                    SiteID        = siteId,
                    FieldNumber   = strFieldNumber,
                    Collector     = strCollector,
                    DateType      = iDateType,
                    DateStart     = startDate,
                    DateEnd       = endDate,
                    TimeStart     = timeStart,
                    TimeEnd       = timeEnd,
                    CasualTime    = strCasualDate
                };

                var siteVisitID = Service.ImportSiteVisit(visit);
                _lastSiteVisit = new CachedSiteVisit {
                    SourceRowID = CurrentRowId, SiteVisitID = siteVisitID, SiteID = siteId, Collector = strCollector, FieldNumber = strFieldNumber, SiteVisitName = strSiteVisitName, DateEnd = endDate, DateStart = startDate, TimeEnd = timeEnd, TimeStart = timeStart, CasualDate = strCasualDate
                };
                return(siteVisitID);
            }
        }
Example #3
0
        private int GetSiteVisitNumber(int siteId)
        {
            // test to see if an internal visit number is present in the incoming dataset
            var existingSiteVisitId = Get("SiteVisit.ExistingSiteVisitID");
            if (!String.IsNullOrEmpty(existingSiteVisitId)) {
                var visit = MaterialService.GetSiteVisit(Int32.Parse(existingSiteVisitId));
                if (visit != null) {
                    return visit.SiteVisitID;
                }
            }
            // No existing visit found? need to create it

            var iDateType = FIXED_DATE;
            var strSiteVisitName = Get("SiteVisit.Visit Name");
            var strCollector = Get("SiteVisit.Collector(s)");

            var strCasualDate = Get("SiteVisit.Casual time");

            int? startDate = GetConvert<int?>("SiteVisit.Start Date", null, false);
            if (!startDate.HasValue) {
                iDateType = CASUAL_DATE;
            } else {
                strCasualDate = Get("SiteVisit.Start Date", strCasualDate);
            }

            int? endDate = GetConvert<int?>("SiteVisit.End Date", null);
            if (!endDate.HasValue) {
                var sEndDate = Get("SiteVisit.End Date");
                if (!string.IsNullOrWhiteSpace(sEndDate)) {
                    if (iDateType == FIXED_DATE) {
                        throw new Exception("Invalid end date value - start date is in fixed format, end date is not");
                    } else {
                        if (string.IsNullOrWhiteSpace(strCasualDate)) {
                            strCasualDate = sEndDate;
                        }
                    }
                }
            }

            var timeStart = GetConvert<int?>("SiteVisit.Start Time", null);
            var timeEnd = GetConvert<int?>("SiteVisit.End Time");

            var strFieldNumber = Get("SiteVisit.Field number");

            if (string.IsNullOrWhiteSpace(strSiteVisitName)) {
                if (startDate.HasValue && startDate.Value > 0) {
                    if (iDateType == FIXED_DATE) {
                        strSiteVisitName = strCollector + ", " + DateUtils.BLDateToStr(startDate.Value);
                    } else {
                        strSiteVisitName = strCollector + ", " + strCasualDate;
                    }
                } else {
                    if (endDate.HasValue && endDate.Value > 0) {
                        if (iDateType == FIXED_DATE) {
                            strSiteVisitName = strCollector + ", " + DateUtils.BLDateToStr(endDate.Value);
                        } else {
                            strSiteVisitName = strCollector + ", " + strCasualDate;
                        }
                    } else {
                        strSiteVisitName = strCollector;
                    }
                }
            }

            if (_lastSiteVisit != null && _lastSiteVisit.Equals(siteId, strSiteVisitName, strCollector, startDate, endDate, timeStart, timeEnd, strFieldNumber, strCasualDate)) {
                return _lastSiteVisit.SiteVisitID;
            } else {

                var visit = new SiteVisit {
                    SiteVisitName = strSiteVisitName,
                    SiteID = siteId,
                    FieldNumber = strFieldNumber,
                    Collector = strCollector,
                    DateType = iDateType,
                    DateStart = startDate,
                    DateEnd = endDate,
                    TimeStart = timeStart,
                    TimeEnd = timeEnd,
                    CasualTime = strCasualDate
                };

                var siteVisitID = Service.ImportSiteVisit(visit);
                _lastSiteVisit = new CachedSiteVisit { SourceRowID = CurrentRowId, SiteVisitID = siteVisitID, SiteID = siteId, Collector = strCollector, FieldNumber = strFieldNumber, SiteVisitName = strSiteVisitName, DateEnd = endDate, DateStart = startDate, TimeEnd = timeEnd, TimeStart = timeStart, CasualDate = strCasualDate };
                return siteVisitID;
            }
        }
Example #4
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);
        }