private DataMatrix BuildPointSetMatrix(PointSetViewModel vm)
        {
            if (vm == null)
            {
                return(null);
            }
            var result = new DataMatrix();

            result.Columns.Add(new MatrixColumn {
                Name = "Long"
            });
            result.Columns.Add(new MatrixColumn {
                Name = "Lat"
            });


            foreach (MapPoint p in vm.Model)
            {
                var row = result.AddRow();
                row[0] = p.Longitude;
                row[1] = p.Latitude;
            }

            return(result);
        }
        private void AddTaxonRow(DataMatrix results, Taxon taxa, MultimediaLink link, string multimediaSource = "Taxon", int?materialId = null)
        {
            // Filter the rows...
            bool addRow = true;

            if (!string.IsNullOrWhiteSpace(_extensionFilter))
            {
                addRow = _extensionFilter.Equals(link.Extension, StringComparison.CurrentCultureIgnoreCase);
            }

            if (addRow && !string.IsNullOrWhiteSpace(_typeFilter))
            {
                addRow = _typeFilter.Equals(link.MultimediaType, StringComparison.CurrentCultureIgnoreCase);
            }

            if (addRow)
            {
                var row = results.AddRow();
                row[0]  = link.MultimediaID;
                row[1]  = taxa.TaxaID.Value;
                row[2]  = link;
                row[3]  = taxa.TaxaFullName;
                row[4]  = taxa.Rank;
                row[5]  = link.Name;
                row[6]  = link.Extension;
                row[7]  = link.MultimediaType;
                row[8]  = link.SizeInBytes;
                row[9]  = multimediaSource;
                row[10] = materialId;
            }
        }
        private DataMatrix MergeItemMatrices(DataMatrix siteData, DataMatrix siteVisitData, DataMatrix materialData)
        {
            var result = new DataMatrix();

            // Create the final column set (based on the specified criteria)
            foreach (QueryCriteria c in Criteria)
            {
                result.Columns.Add(new MatrixColumn {
                    Name = c.Field.DisplayName
                });
            }

            // Now add the identity columns (as hidden columns, unless they already exist)
            string[] cols = { "Site Identifier", "Visit Identifier", "Material Identifier" };
            foreach (string col in cols)
            {
                if (result.IndexOf(col) < 0)
                {
                    result.Columns.Add(new MatrixColumn {
                        Name = col, IsHidden = true
                    });
                }
            }

            int          currentOrderNum = 1;
            LabelSetItem item            = null;

            while ((item = Items.FirstOrDefault((candidate) => { return(candidate.PrintOrder == currentOrderNum); })) != null)
            {
                if (item.NumCopies > 0)
                {
                    var row = result.AddRow();

                    if (item.SiteID > 0)
                    {
                        AddFieldData(row, item.SiteID, "Site Identifier", siteData);
                    }

                    if (item.VisitID > 0)
                    {
                        AddFieldData(row, item.VisitID, "Visit Identifier", siteVisitData);
                    }

                    if (item.MaterialID > 0)
                    {
                        AddFieldData(row, item.MaterialID, "Material Identifier", materialData);
                    }

                    if (item.NumCopies > 1)
                    {
                        CopyRow(result, row, item.NumCopies - 1);
                    }
                }

                currentOrderNum++;
            }

            return(result);
        }
        public override Data.DataMatrix ExtractReportData(Utilities.IProgressObserver progress)
        {
            DataMatrix matrix           = new DataMatrix();
            var        displayNameRegex = new Regex(@"^(\w+)\[(.+)\]$");
            // Cache the property getter
            Dictionary <String, MethodInfo> getters = new Dictionary <String, MethodInfo>();

            foreach (String colName in Columns)
            {
                string displayName = colName;
                string memberName  = colName;

                var m      = displayNameRegex.Match(colName);
                var hidden = false;
                if (m.Success)
                {
                    memberName  = m.Groups[1].Value;
                    displayName = m.Groups[2].Value;
                    if (displayName.Equals("hidden", StringComparison.CurrentCultureIgnoreCase))
                    {
                        displayName = memberName;
                        hidden      = true;
                    }
                }

                matrix.Columns.Add(new MatrixColumn {
                    Name = displayName, IsHidden = hidden
                });
                var p = typeof(T).GetProperty(memberName);
                if (p != null)
                {
                    getters[colName] = p.GetGetMethod();
                }
            }

            var model = ModelGenerator();

            foreach (T vm in model)
            {
                var row = matrix.AddRow();
                int i   = 0;
                foreach (String colName in Columns)
                {
                    Object value = null;
                    if (getters.ContainsKey(colName))
                    {
                        value = getters[colName].Invoke(vm, null);
                    }
                    row[i++] = value;
                }
            }

            return(matrix);
        }
 private void CopyRow(DataMatrix dest, MatrixRow srcRow, int numCopies)
 {
     for (int i = 0; i < numCopies; ++i)
     {
         var newRow = dest.AddRow();
         foreach (MatrixColumn col in dest.Columns)
         {
             int index = dest.IndexOf(col.Name);
             newRow[index] = srcRow[index];
         }
     }
 }
        private void ExportChildRegions(DistributionRegion parent, DataMatrix matrix)
        {
            // First add a row for this parent...
            var row = matrix.AddRow();

            row[0] = Service.GetDistributionFullPath(parent.DistRegionID);
            // Than add any direct children recursively
            if (parent.NumChildren > 0)
            {
                var list = Service.GetDistributionRegions(parent.DistRegionID);
                if (list != null && list.Count > 0)
                {
                    list.ForEach((region) => {
                        ExportChildRegions(region, matrix);
                    });
                }
            }
        }
Example #7
0
        public override void Append(MapPoint point)
        {
            int latIndex       = FindIndex(LatitudeColumn);
            int lonIndex       = FindIndex(LongitudeColumn);
            int siteIndex      = FindIndex(SiteIDColumn);
            int siteVisitIndex = FindIndex(SiteVisitIDColumn);
            int materialIndex  = FindIndex(MaterialIDColumn);

            var row = _data.AddRow();

            row[latIndex]       = point.Latitude;
            row[lonIndex]       = point.Longitude;
            row[siteIndex]      = point.SiteID;
            row[siteVisitIndex] = point.SiteVisitID;
            row[materialIndex]  = point.MaterialID;

            RaiseCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
        }
Example #8
0
        private void PreviewDataSet()
        {
            if (String.IsNullOrEmpty(Filename))
            {
                return;
            }

            var builder = new BVPImportSourceBuilder(Filename);

            this.RowSource = builder.BuildRowSource();
            // make a matrix of the data - for now all of it, but if it becomes too much, we can limit it to top 100 or so...
            var matrix = new DataMatrix();
            var view   = new GridView();

            for (int i = 0; i < RowSource.ColumnCount; ++i)
            {
                String name = RowSource.ColumnName(i);
                matrix.Columns.Add(new MatrixColumn {
                    Name = name
                });
                var column = new GridViewColumn {
                    Header = BuildColumnHeader(name), DisplayMemberBinding = new Binding(String.Format("[{0}]", i))
                };
                view.Columns.Add(column);
            }

            while (RowSource.MoveNext())
            {
                var row = matrix.AddRow();
                for (int i = 0; i < RowSource.ColumnCount; ++i)
                {
                    row[RowSource.ColumnName(i)] = RowSource[i];
                }
            }

            lvwPreview.ItemsSource = matrix.Rows;
            lvwPreview.View        = view;
        }
Example #9
0
        public override DataMatrix ExtractReportData(IProgressObserver progress)
        {
            var matrix = new DataMatrix();

            var service = new SupportService(User);

            matrix.Columns.Add(new MatrixColumn {
                Name = IntraCategoryIdColumnName, IsHidden = true
            });
            matrix.Columns.Add(new MatrixColumn {
                Name = "RefID", IsHidden = true
            });
            matrix.Columns.Add(new MatrixColumn {
                Name = "RefCode"
            });
            matrix.Columns.Add(new MatrixColumn {
                Name = "RefType"
            });
            matrix.Columns.Add(new MatrixColumn {
                Name = "LinkPage"
            });
            matrix.Columns.Add(new MatrixColumn {
                Name = "LinkQualification"
            });
            matrix.Columns.Add(new MatrixColumn {
                Name = "LinkQualificationRTF", IsHidden = true
            });

            matrix.Columns.Add(new MatrixColumn {
                Name = "Title"
            });
            matrix.Columns.Add(new MatrixColumn {
                Name = "Author"
            });
            matrix.Columns.Add(new MatrixColumn {
                Name = "BookTitle"
            });
            matrix.Columns.Add(new MatrixColumn {
                Name = "Edition"
            });
            matrix.Columns.Add(new MatrixColumn {
                Name = "Editor"
            });
            matrix.Columns.Add(new MatrixColumn {
                Name = "StartPage"
            });
            matrix.Columns.Add(new MatrixColumn {
                Name = "EndPage"
            });
            matrix.Columns.Add(new MatrixColumn {
                Name = "ActualDate"
            });
            matrix.Columns.Add(new MatrixColumn {
                Name = "ISBN"
            });
            matrix.Columns.Add(new MatrixColumn {
                Name = "ISSN"
            });
            matrix.Columns.Add(new MatrixColumn {
                Name = "JournalID", IsHidden = true
            });
            matrix.Columns.Add(new MatrixColumn {
                Name = "PartNo"
            });
            matrix.Columns.Add(new MatrixColumn {
                Name = "Place"
            });
            matrix.Columns.Add(new MatrixColumn {
                Name = "Possess"
            });
            matrix.Columns.Add(new MatrixColumn {
                Name = "Publisher"
            });
            matrix.Columns.Add(new MatrixColumn {
                Name = "RefType"
            });
            matrix.Columns.Add(new MatrixColumn {
                Name = "Series"
            });
            matrix.Columns.Add(new MatrixColumn {
                Name = "Source"
            });
            matrix.Columns.Add(new MatrixColumn {
                Name = "FullText"
            });
            matrix.Columns.Add(new MatrixColumn {
                Name = "FullRTF", IsHidden = true
            });
            matrix.Columns.Add(new MatrixColumn {
                Name = "JournalAbbrevName"
            });
            matrix.Columns.Add(new MatrixColumn {
                Name = "JournalAbbrevName2"
            });
            matrix.Columns.Add(new MatrixColumn {
                Name = "JournalAlias"
            });
            matrix.Columns.Add(new MatrixColumn {
                Name = "JournalFullName"
            });
            matrix.Columns.Add(new MatrixColumn {
                Name = "JournalNotes"
            });

            var reflinks = SelectReferences(progress);

            progress.ProgressMessage("Preparing view model...");
            foreach (RefLink link in reflinks)
            {
                if (Options.HonourIncludeInReportsFlag)
                {
                    if (!link.UseInReport.HasValue || !link.UseInReport.Value)
                    {
                        // skip this one as it hasn't got the use in reports flag set.
                        continue;
                    }
                }

                var reference = service.GetReference(link.RefID);
                if (reference != null)
                {
                    int i   = 0;
                    var row = matrix.AddRow();
                    row[i++] = link.IntraCatID.Value;
                    row[i++] = link.RefID;
                    row[i++] = reference.RefCode;
                    row[i++] = link.RefLinkType;
                    row[i++] = link.RefPage;
                    row[i++] = RTFUtils.StripMarkup(link.RefQual);
                    row[i++] = link.RefQual;


                    row[i++] = RTFUtils.StripMarkup(reference.Title);
                    row[i++] = reference.Author;
                    row[i++] = RTFUtils.StripMarkup(reference.BookTitle);
                    row[i++] = reference.Edition;
                    row[i++] = reference.Editor;
                    row[i++] = reference.StartPage;
                    row[i++] = reference.EndPage;
                    row[i++] = SupportService.FormatDate(reference.ActualDate, "yyyy-MM-dd");
                    row[i++] = reference.ISBN;
                    row[i++] = reference.ISSN;
                    row[i++] = reference.JournalID;
                    row[i++] = reference.PartNo;
                    row[i++] = reference.Place;
                    row[i++] = reference.Possess;
                    row[i++] = reference.Publisher;
                    row[i++] = reference.RefType;
                    row[i++] = reference.Series;
                    row[i++] = reference.Source;
                    row[i++] = reference.FullText;
                    row[i++] = reference.FullRTF;

                    if (reference.JournalID.HasValue && reference.JournalID.Value > 0)
                    {
                        var journal = service.GetJournal(reference.JournalID.Value);
                        row[i++] = journal.AbbrevName;
                        row[i++] = journal.AbbrevName2;
                        row[i++] = journal.Alias;
                        row[i++] = journal.FullName;
                        row[i++] = journal.Notes;
                    }
                }
            }

            progress.ProgressMessage("");

            return(matrix);
        }
        public override DataMatrix ExtractReportData(IProgressObserver progress)
        {
            var matrix = new DataMatrix();

            if (IsGroupedByTaxon)
            {
                matrix.Columns.Add(new MatrixColumn {
                    Name = "TaxonName"
                });
                matrix.Columns.Add(new MatrixColumn {
                    Name = "BiotaID", IsHidden = true
                });
            }

            matrix.Columns.Add(new MatrixColumn {
                Name = "Count"
            });

            foreach (string colname in SelectedColumns)
            {
                matrix.Columns.Add(new MatrixColumn {
                    Name = colname
                });
            }

            // Open the feature layer data
            SelectedFeatureLayer.DataSource.Open();

            var map = new Dictionary <string, FeatureCountPair>();

            if (progress != null)
            {
                progress.ProgressMessage("Counting points...", 0);
            }

            int pointCount = 0;

            foreach (VectorLayer pointLayer in SelectedPointLayers)
            {
                var ds = pointLayer.DataSource;
                ds.Open();
                pointCount += ds.GetFeatureCount();
            }

            if (progress != null)
            {
                progress.ProgressStart(String.Format("Processing {0} points...", pointCount));
            }

            int processed     = 0;
            int notFoundCount = 0;

            var materialService = new MaterialService(User);
            var taxaService     = new TaxaService(User);

            foreach (VectorLayer pointLayer in SelectedPointLayers)
            {
                var pointProvider = pointLayer.DataSource;
                pointProvider.Open();
                for (uint i = 0; i < pointProvider.GetFeatureCount(); ++i)
                {
                    var row = pointProvider.GetFeature(i);

                    Taxon taxon = null;
                    if (IsGroupedByTaxon)
                    {
                        int?materialId = (int?)row["MaterialID"];
                        if (materialId.HasValue)
                        {
                            var m = materialService.GetMaterial(materialId.Value);
                            if (m.BiotaID > 0)
                            {
                                if (_taxonCache.ContainsKey(m.BiotaID))
                                {
                                    taxon = _taxonCache[m.BiotaID];
                                }
                                else
                                {
                                    taxon = taxaService.GetTaxon(m.BiotaID);
                                    _taxonCache[m.BiotaID] = taxon;
                                }
                            }
                        }
                    }

                    SharpMap.Geometries.Point p = row.Geometry as Point;
                    if (!ProcessPoint(SelectedFeatureLayer.DataSource, pointLayer, p, map, taxon))
                    {
                        notFoundCount++;
                    }
                    processed++;
                    if (progress != null)
                    {
                        double percent = ((double)processed) / ((double)pointCount) * 100;
                        progress.ProgressMessage(String.Format("Processing {0} points...", pointCount), percent);
                    }
                }
            }

            if (progress != null)
            {
                progress.ProgressMessage("Constructing result set...", 100);
            }

            int countIndex   = matrix.IndexOf("Count");
            int taxaIndex    = matrix.IndexOf("TaxonName");
            int biotaIDIndex = matrix.IndexOf("BiotaID");

            foreach (FeatureCountPair pair in map.Values)
            {
                var matrixRow = matrix.AddRow();
                foreach (DataColumn col in pair.First.Table.Columns)
                {
                    if (SelectedColumns.Contains(col.ColumnName))
                    {
                        var index = matrix.IndexOf(col.ColumnName);
                        matrixRow[index] = pair.First[col];
                    }
                }
                matrixRow[countIndex] = pair.Second;
                if (IsGroupedByTaxon)
                {
                    matrixRow[taxaIndex]    = pair.Taxon == null ? "Unidentified" : pair.Taxon.TaxaFullName;
                    matrixRow[biotaIDIndex] = pair.Taxon == null ? -1 : pair.Taxon.TaxaID.Value;
                }
            }

            if (IncludeUnmatchedPointRow && notFoundCount > 0)
            {
                var unmatched = matrix.AddRow();
                unmatched[countIndex] = notFoundCount;
            }

            if (progress != null)
            {
                progress.ProgressEnd(String.Format("{0} points processed.", pointCount));
            }

            return(matrix);
        }