Beispiel #1
0
        protected override void GetDetailText(BioLinkDataObject model, TextTableBuilder builder)
        {
            if (model != null)
            {
                switch (ElemType)
                {
                case "Site":
                    var site = model as Site;
                    builder.Add("Political Region", site.PoliticalRegion);
                    if (site.PosY1.HasValue && site.PosX1.HasValue)
                    {
                        builder.Add("Position", string.Format("{0}  {1}", GeoUtils.DecDegToDMS(site.PosX1.Value, CoordinateType.Longitude), GeoUtils.DecDegToDMS(site.PosY1.Value, CoordinateType.Latitude)));
                    }
                    else
                    {
                        builder.Add("Position", "No position recorded.");
                    }
                    break;

                case "SiteVisit":
                    var visit = model as SiteVisit;
                    builder.Add("Collector(s)", visit.Collector);
                    builder.AddFormat("Start Date", "{0}", DateUtils.BLDateToStr(visit.DateStart, "Not specified"));
                    builder.AddFormat("End Date", "{0}", DateUtils.BLDateToStr(visit.DateEnd, "Not specified"));
                    builder.Add("Site", visit.SiteName);
                    break;

                case "Material":
                    var mat = model as Data.Model.Material;
                    builder.Add("Site", mat.SiteName);
                    builder.Add("Site Visit", mat.SiteVisitName);
                    builder.Add("Accession No.", mat.AccessionNumber);
                    builder.Add("Registration No.", mat.RegistrationNumber);
                    builder.Add("Identification", mat.TaxaDesc);
                    break;

                case "Region":
                    var reg = model as Region;
                    if (string.IsNullOrWhiteSpace(reg.Rank))
                    {
                        builder.Add("Region type", "Not specified");
                    }
                    else
                    {
                        builder.Add("Region type", reg.Rank);
                    }
                    break;

                case "Trap":
                    var trap = model as Trap;
                    builder.Add("Site", trap.SiteName);
                    builder.Add("Trap type", trap.TrapType);
                    builder.Add("Description", trap.Description);
                    break;
                }
            }
        }
Beispiel #2
0
        private string FormatDate(int d, bool asRomanMonth = false)
        {
            if (d == 0)
            {
                return("");
            }

            if (asRomanMonth)
            {
                return(DateUtils.DateRomanMonth(d));
            }
            else
            {
                return(DateUtils.BLDateToStr(d));
            }
        }
Beispiel #3
0
        protected string BuildDate(string date)
        {
            if (date.Length < 0)
            {
                date = date.PadRight(8, '0');
            }

            if (string.IsNullOrWhiteSpace(date))
            {
                return("");
            }

            if (date.IsNumeric())
            {
                return(DateUtils.BLDateToStr(Int32.Parse(date)));
            }

            return("");
        }
Beispiel #4
0
        private static string SubstituteToken(string token, object source, string separator = "")
        {
            string        @default   = "";
            List <string> candidates = new List <string>();

            if (token.Contains('|'))
            {
                candidates.AddRange(token.Split('|'));
            }
            else
            {
                candidates.Add(token);
            }

            foreach (string candidate in candidates)
            {
                var p = source.GetType().GetProperty(candidate);
                if (p != null)
                {
                    var value = p.GetValue(source, null);
                    if (value != null)
                    {
                        String strVal = null;
                        if (typeof(int?).IsAssignableFrom(p.PropertyType) && candidate.Contains("Date"))
                        {
                            strVal = DateUtils.BLDateToStr((int)value);
                        }
                        else
                        {
                            strVal = value.ToString();
                        }

                        if (!string.IsNullOrWhiteSpace(strVal))
                        {
                            return(strVal + separator);
                        }
                    }
                }
            }

            return(@default);
        }
Beispiel #5
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);
            }
        }
        public void BLDateToStr5()
        {
            var result = DateUtils.BLDateToStr(-1);

            Assert.AreEqual(result, "");
        }
        public void BLDateToStr3()
        {
            var result = DateUtils.BLDateToStr(20110000);

            Assert.AreEqual(result, "2011");
        }
        public void BLDateToStr1()
        {
            var result = DateUtils.BLDateToStr(20110101);

            Assert.AreEqual(result, "1 Jan, 2011");
        }