public DataMatrix TaxaForSites(int siteOrRegionID, int taxonID, string itemType, string criteriaDisplayText, bool includeLocations)
        {
            var rtf = new RTFReportBuilder();

            rtf.AppendFullHeader();
            rtf.ReportHeading("Taxa for Site/Region Report");
            rtf.Append(criteriaDisplayText);
            rtf.Append(@"\pard\par\fs24 Produced: ").AppendCurrentDate();

            int lngLastBiotaID  = -1;
            int lngLastRegionID = -1;
            int lngLastSiteID   = -1;

            bool hasResults = false;

            StoredProcReaderForEach("spReportTaxaForSites", (reader) => {
                hasResults = true;
                // If there is a change in taxa, print the header.
                int biotaID = (Int32)reader["BiotaID"];
                if (lngLastBiotaID != biotaID)
                {
                    lngLastBiotaID  = biotaID;
                    lngLastRegionID = -1;
                    lngLastSiteID   = -1;
                    rtf.Par().Par().Append(@"\pard\sb20\fs28\b ");
                    rtf.Append(AsString(reader["BiotaFullName"])).Append(@"\b0");
                    // extract the family and order
                    string orderRank  = GetBiotaRankElemType(lngLastBiotaID, "O");
                    string familyRank = GetBiotaRankElemType(lngLastBiotaID, "F");

                    if (!string.IsNullOrWhiteSpace(orderRank) && string.IsNullOrWhiteSpace(familyRank))
                    {
                        rtf.Append("  [").Append(orderRank).Append("]");
                    }
                    else if (!string.IsNullOrWhiteSpace(orderRank) && !string.IsNullOrWhiteSpace(familyRank))
                    {
                        rtf.Append("  [").Append(orderRank).Append(": ").Append(familyRank).Append("]");
                    }
                }

                if (includeLocations)
                {
                    // Add the region group
                    int regionID = (Int32)reader["RegionID"];

                    if (lngLastRegionID != regionID)
                    {
                        // Add the region
                        lngLastRegionID = regionID;
                        rtf.Par().Append(@"\pard\sb10\fs20\li600\b ").Append(AsString(reader["FullRegion"])).Append(@"\b0 ");
                    }

                    int siteID = (Int32)reader["SiteID"];
                    if (lngLastSiteID != siteID)
                    {
                        lngLastSiteID = siteID;
                        // Add the Site
                        rtf.Par().Append(@"\pard\sb10\fs20\li1200 ");
                        // Add the locality
                        byte localType = (byte)reader["LocalType"];
                        switch (localType)
                        {
                        case 0:
                            rtf.Append(reader["Local"] as string);
                            break;

                        case 1:
                            rtf.Append(reader["DistanceFromPlace"]).Append(" ").Append(reader["DirFromPlace"]).Append(" of ").Append(reader["Local"]);
                            break;

                        default:
                            rtf.Append(reader["Local"] as string);
                            break;
                        }

                        // Add the long and lat.

                        byte areaType = (byte)reader["AreaType"];
                        double?lat    = reader["Lat"] as double?;
                        double?lon    = reader["Long"] as double?;
                        double?lat2   = reader["Lat2"] as double?;
                        double?lon2   = reader["Long2"] as double?;

                        if (!lat.HasValue || !lon.HasValue)
                        {
                            rtf.Append("; No position data");
                        }
                        else
                        {
                            switch (areaType)
                            {
                            case 1:
                                rtf.Append("; ");
                                rtf.Append(GeoUtils.DecDegToDMS(lat.Value, CoordinateType.Latitude));
                                rtf.Append(", ");
                                rtf.Append(GeoUtils.DecDegToDMS(lon.Value, CoordinateType.Longitude));
                                break;

                            case 2:
                                rtf.Append("; Box: ");
                                rtf.Append(GeoUtils.DecDegToDMS(lat.Value, CoordinateType.Latitude));
                                rtf.Append(", ");
                                rtf.Append(GeoUtils.DecDegToDMS(lon.Value, CoordinateType.Longitude));
                                rtf.Append("; ");
                                if (!lat2.HasValue || !lon2.HasValue)
                                {
                                    rtf.Append("; No position data for second coordinate");
                                }
                                else
                                {
                                    rtf.Append(GeoUtils.DecDegToDMS(lat2.Value, CoordinateType.Latitude));
                                    rtf.Append(", ");
                                    rtf.Append(GeoUtils.DecDegToDMS(lon2.Value, CoordinateType.Longitude));
                                }
                                break;

                            case 3:
                                rtf.Append("; Line: ");
                                rtf.Append(GeoUtils.DecDegToDMS(lat.Value, CoordinateType.Latitude));
                                rtf.Append(", ");
                                rtf.Append(GeoUtils.DecDegToDMS(lon.Value, CoordinateType.Longitude));
                                rtf.Append("; ");
                                if (!lat2.HasValue || !lon2.HasValue)
                                {
                                    rtf.Append("; No position data for second coordinate");
                                }
                                else
                                {
                                    rtf.Append(GeoUtils.DecDegToDMS(lat2.Value, CoordinateType.Latitude));
                                    rtf.Append(", ");
                                    rtf.Append(GeoUtils.DecDegToDMS(lon2.Value, CoordinateType.Longitude));
                                }

                                break;

                            default:
                                break;
                            }
                        }
                    }
                }
            }, _P("vchrItemType", itemType), _P("intItemID", siteOrRegionID), _P("intBiotaID", taxonID));

            if (!hasResults)
            {
                rtf.Par().Par().Append("No results.");
            }


            rtf.Append("}");

            return(rtf.GetAsMatrix());
        }
        public DataMatrix TaxaForDistributionRegionReport(int regionId, int taxonId)
        {
            var region = new SupportService(User).GetDistributionRegion(regionId);

            if (region == null)
            {
                throw new Exception("Could not retrieve region: " + regionId);
            }

            Taxon taxon = null;

            if (taxonId > 0)
            {
                taxon = GetTaxon(taxonId);
                if (taxon == null)
                {
                    throw new Exception("Could not retrieve taxon: " + taxonId);
                }
            }

            var rtf = new RTFReportBuilder();

            rtf.AppendFullHeader();
            rtf.ReportHeading("Taxa for Distribution Region Report");
            rtf.Append("Region: {0}", region.DistRegionName);
            if (taxon != null)
            {
                rtf.Append(" Taxon: {0}", taxon.TaxaFullName);
            }

            rtf.Append(@"\pard\par\fs24 Produced: ").AppendCurrentDate();

            int rowCount     = 0;
            int lastRegionId = -1;
            int lastTaxonId  = -1;

            StoredProcReaderForEach("spReportTaxaForDistRegion", (reader) => {
                rowCount++;
                int currentRegionId = (int)reader["DistRegionID"];
                if (lastRegionId != currentRegionId)
                {
                    lastRegionId   = currentRegionId;
                    lastTaxonId    = -1;
                    var regionName = reader["DistRegion"] as string;
                    regionName     = regionName.Replace('\\', ':');
                    rtf.Par().Par().Append(@"\pard\sb20\fs24\b ").Append(regionName).Append(@"\b0 ");
                }

                var currentTaxonId = (int)reader["BiotaID"];
                if (lastTaxonId != currentTaxonId)
                {
                    lastTaxonId = currentTaxonId;
                    rtf.Par().Append(@"\pard\sb10\fs20\li600 ").Append(reader["Biota"].ToString());
                }
            }, _P("intDistributionRegionID", regionId), _P("intBiotaID", taxonId));

            if (rowCount == 0)
            {
                rtf.Par().Append("No results...");
            }

            rtf.Append(" }");

            return(rtf.GetAsMatrix());
        }
Exemple #3
0
        public DataMatrix TaxaForDistributionRegionReport(int regionId, int taxonId)
        {
            var region = new SupportService(User).GetDistributionRegion(regionId);
            if (region == null) {
                throw new Exception("Could not retrieve region: " + regionId);
            }

            Taxon taxon = null;
            if (taxonId > 0) {
                taxon = GetTaxon(taxonId);
                if (taxon == null) {
                    throw new Exception("Could not retrieve taxon: " + taxonId);
                }
            }

            var rtf = new RTFReportBuilder();
            rtf.AppendFullHeader();
            rtf.ReportHeading("Taxa for Distribution Region Report");
            rtf.Append("Region: {0}", region.DistRegionName);
            if (taxon != null) {
                rtf.Append(" Taxon: {0}", taxon.TaxaFullName);
            }

            rtf.Append(@"\pard\par\fs24 Produced: ").AppendCurrentDate();

            int rowCount = 0;
            int lastRegionId = -1;
            int lastTaxonId = -1;
            StoredProcReaderForEach("spReportTaxaForDistRegion", (reader) => {
                rowCount++;
                int currentRegionId = (int) reader["DistRegionID"];
                if (lastRegionId != currentRegionId) {
                    lastRegionId = currentRegionId;
                    lastTaxonId = -1;
                    var regionName = reader["DistRegion"] as string;
                    regionName = regionName.Replace('\\', ':');
                    rtf.Par().Par().Append(@"\pard\sb20\fs24\b ").Append(regionName).Append(@"\b0 ");
                }

                var currentTaxonId = (int)reader["BiotaID"];
                if (lastTaxonId != currentTaxonId) {
                    lastTaxonId = currentTaxonId;
                    rtf.Par().Append(@"\pard\sb10\fs20\li600 ").Append(reader["Biota"].ToString());
                }

            }, _P("intDistributionRegionID", regionId), _P("intBiotaID", taxonId));

            if (rowCount == 0) {
                rtf.Par().Append("No results...");
            }

            rtf.Append(" }");

            return rtf.GetAsMatrix();
        }
Exemple #4
0
        public DataMatrix TaxaForSites(int siteOrRegionID, int taxonID, string itemType, string criteriaDisplayText, bool includeLocations)
        {
            var rtf = new RTFReportBuilder();
            rtf.AppendFullHeader();
            rtf.ReportHeading("Taxa for Site/Region Report");
            rtf.Append(criteriaDisplayText);
            rtf.Append(@"\pard\par\fs24 Produced: ").AppendCurrentDate();

            int lngLastBiotaID = -1;
            int lngLastRegionID = -1;
            int lngLastSiteID = -1;

            bool hasResults = false;
            StoredProcReaderForEach("spReportTaxaForSites", (reader) => {
                hasResults = true;
                // If there is a change in taxa, print the header.
                int biotaID = (Int32) reader["BiotaID"];
                if (lngLastBiotaID != biotaID) {
                    lngLastBiotaID = biotaID;
                    lngLastRegionID = -1;
                    lngLastSiteID = -1;
                    rtf.Par().Par().Append(@"\pard\sb20\fs28\b ");
                    rtf.Append(AsString(reader["BiotaFullName"])).Append(@"\b0");
                    // extract the family and order
                    string orderRank = GetBiotaRankElemType(lngLastBiotaID, "O");
                    string familyRank = GetBiotaRankElemType(lngLastBiotaID, "F");

                    if (!string.IsNullOrWhiteSpace(orderRank) && string.IsNullOrWhiteSpace(familyRank)) {
                        rtf.Append("  [").Append(orderRank).Append("]");
                    } else if (!string.IsNullOrWhiteSpace(orderRank) && !string.IsNullOrWhiteSpace(familyRank)) {
                        rtf.Append("  [").Append(orderRank).Append(": ").Append(familyRank).Append("]");
                    }
                }

                if (includeLocations) {
                    // Add the region group
                    int regionID = (Int32)reader["RegionID"];

                    if (lngLastRegionID != regionID) {
                        // Add the region
                        lngLastRegionID = regionID;
                        rtf.Par().Append(@"\pard\sb10\fs20\li600\b ").Append(AsString(reader["FullRegion"])).Append(@"\b0 ");
                    }

                    int siteID = (Int32)reader["SiteID"];
                    if (lngLastSiteID != siteID) {
                        lngLastSiteID = siteID;
                        // Add the Site
                        rtf.Par().Append(@"\pard\sb10\fs20\li1200 ");
                        // Add the locality
                        byte localType = (byte) reader["LocalType"];
                        switch (localType) {
                            case 0:
                                rtf.Append(reader["Local"] as string);
                                break;
                            case 1:
                                rtf.Append(reader["DistanceFromPlace"]).Append(" ").Append(reader["DirFromPlace"]).Append(" of ").Append(reader["Local"]);
                                break;
                            default:
                                rtf.Append(reader["Local"] as string);
                                break;
                        }

                        // Add the long and lat.

                        byte areaType = (byte) reader["AreaType"];
                        double? lat = reader["Lat"] as double?;
                        double? lon = reader["Long"] as double?;
                        double? lat2 = reader["Lat2"] as double?;
                        double? lon2 = reader["Long2"] as double?;

                        if (!lat.HasValue || !lon.HasValue) {
                            rtf.Append("; No position data");
                        } else {
                            switch (areaType) {
                                case 1:
                                    rtf.Append("; ");
                                    rtf.Append(GeoUtils.DecDegToDMS(lat.Value, CoordinateType.Latitude));
                                    rtf.Append(", ");
                                    rtf.Append(GeoUtils.DecDegToDMS(lon.Value, CoordinateType.Longitude));
                                    break;
                                case 2:
                                    rtf.Append("; Box: ");
                                    rtf.Append(GeoUtils.DecDegToDMS(lat.Value, CoordinateType.Latitude));
                                    rtf.Append(", ");
                                    rtf.Append(GeoUtils.DecDegToDMS(lon.Value, CoordinateType.Longitude));
                                    rtf.Append("; ");
                                    if (!lat2.HasValue || !lon2.HasValue) {
                                        rtf.Append("; No position data for second coordinate");
                                    } else {
                                        rtf.Append(GeoUtils.DecDegToDMS(lat2.Value, CoordinateType.Latitude));
                                        rtf.Append(", ");
                                        rtf.Append(GeoUtils.DecDegToDMS(lon2.Value, CoordinateType.Longitude));
                                    }
                                    break;
                                case 3:
                                    rtf.Append("; Line: ");
                                    rtf.Append(GeoUtils.DecDegToDMS(lat.Value, CoordinateType.Latitude));
                                    rtf.Append(", ");
                                    rtf.Append(GeoUtils.DecDegToDMS(lon.Value, CoordinateType.Longitude));
                                    rtf.Append("; ");
                                    if (!lat2.HasValue || !lon2.HasValue) {
                                        rtf.Append("; No position data for second coordinate");
                                    } else {
                                        rtf.Append(GeoUtils.DecDegToDMS(lat2.Value, CoordinateType.Latitude));
                                        rtf.Append(", ");
                                        rtf.Append(GeoUtils.DecDegToDMS(lon2.Value, CoordinateType.Longitude));
                                    }

                                    break;
                                default:
                                    break;
                            }

                        }
                    }
                }
            }, _P("vchrItemType", itemType), _P("intItemID", siteOrRegionID), _P("intBiotaID", taxonID));

            if (!hasResults) {
                rtf.Par().Par().Append("No results.");
            }

            rtf.Append("}");

            return rtf.GetAsMatrix();
        }
        public System.Windows.FrameworkElement ConstructView(IBioLinkReport report, DataMatrix reportData, IProgressObserver progress)
        {
            var options = (report as ReferenceLinksReport).Options;

            var viewer = new RTFReportViewer {ReportName = report.Name};
            var rtf = new RTFReportBuilder();
            rtf.AppendFullHeader();
            rtf.ReportHeading(options.BibliographyTitle);

            var idx = 1;
            var colIndex = reportData.IndexOf("RefID");

            var refIds = new List<Int32>();
            for (var i = 0; i < reportData.Rows.Count; ++i ) {
                refIds.Add(i);
            }

            int sortColumnIdx = reportData.IndexOf(options.SortColumn);
            int refTypeIndex = reportData.IndexOf("RefType");
            refIds.Sort((idx1, idx2) => {
                            // If grouping, first check the ref type
                            if (options.GroupByReferenceType) {
                                var refType1 = reportData.Rows[idx1][refTypeIndex] as String;
                                var refType2 = reportData.Rows[idx2][refTypeIndex] as String;
                                if (!refType1.Equals(refType2)) {
                                    return String.Compare(refType1, refType2, true);
                                }
                            }

                            // then by the nominated sort column
                            var objVal1 = reportData.Rows[idx1][sortColumnIdx];
                            var objVal2 = reportData.Rows[idx2][sortColumnIdx];
                            var val1 = RTFUtils.StripMarkup(objVal1 == null ? "" : objVal1.ToString());
                            var val2 = RTFUtils.StripMarkup(objVal2 == null ? "" : objVal2.ToString());

                            if (options.SortAscending) {
                                return String.Compare((String)val1, (String)val2, true);
                            } else {
                                return String.Compare((String)val2, (String)val1, true);
                            }
                        });

            var lastRefType = "";
            String[] allowedKeywords = { "b", "i", "sub", "super", "strike", "ul", "ulnone", "nosupersub" };
            foreach (var rowIdx in refIds) {
                var row = reportData.Rows[rowIdx];

                if (options.GroupByReferenceType) {
                    var refType = row["RefType"] as String;
                    if (!String.Equals(refType, lastRefType, StringComparison.CurrentCultureIgnoreCase)) {
                        rtf.Par();
                        rtf.Append(@" \pard\fs24\b\f1 ");
                        rtf.Append(refType);
                        rtf.Append(@" \b0");
                        rtf.Par();
                        lastRefType = refType;
                    }
                }

                rtf.Par();
                rtf.Append(@" \pard\fs20\f1 ");
                if (options.BibliographyIndexStyle != BibliographyIndexStyle.None) {
                    rtf.Append("[");
                    switch (options.BibliographyIndexStyle) {
                        case BibliographyIndexStyle.Number:
                            rtf.Append(idx);
                            break;
                        case BibliographyIndexStyle.RefCode:
                            rtf.Append(row["RefCode"]);
                            break;
                    }
                    rtf.Append("] ");
                }
                idx++;

                var fullRTF = RTFUtils.filter(row["FullRTF"] as string, true, false, allowedKeywords);
                rtf.Append(fullRTF);

                var bits = new List<String>();
                if (!String.IsNullOrWhiteSpace(row["LinkPage"] as String)) {
                    bits.Add(String.Format("page {0}", row["LinkPage"] as String));
                }

                if (options.IncludeQualification) {
                    var qual = row["LinkQualificationRTF"] as string;
                    if (!String.IsNullOrEmpty(qual)  ) {
                        bits.Add(RTFUtils.filter(qual, true, true, allowedKeywords).Trim());
                    }
                }

                if (bits.Count > 0) {
                    rtf.Append(" (").Append(bits.Join("; ").Trim()).Append(")");
                }

                rtf.Par();
            }

            Console.WriteLine(rtf.RTF);

            viewer.rtf.Rtf = rtf.RTF;

            return viewer;
        }