Esempio n. 1
0
 public override void Validate(ValidationMessages messages)
 {
     var service = new TaxaService(PluginManager.Instance.User);
     if (!service.SafeToDeleteTaxon(Taxon.TaxaID.Value)) {
         messages.Warn("There are material and or associations that will be orphaned if you delete this taxon.");
     }
 }
        public override DataMatrix ExtractReportData(IProgressObserver progress)
        {
            var service = new TaxaService(User);

            progress.ProgressStart(String.Format("Preparing Darwin Core records for {0} specimens...", _idSet.Count));

            DataMatrix result = null;
            var idSet = new LinkedList<int>(_idSet);
            int chunkSize = 2000;
            var helper = new DarwinCoreReportHelper();
            var chunk = new List<int>();
            var count = 0;
            while (idSet.Count > 0) {
                chunk.Add(idSet.First.Value);
                idSet.RemoveFirst();
                count++;
                if (chunk.Count >= chunkSize || idSet.Count == 0) {

                    var percentComplete = ((double) count / (double) _idSet.Count) * 100;

                    progress.ProgressMessage(String.Format("Preparing Darwin Core records {0} of {1}", count, _idSet.Count), percentComplete);
                    var where = "tblMaterial.intMaterialID in (" + chunk.Join(",") + ")";
                    var dataChunk = helper.RunDwcQuery(service, where);
                    if (result == null) {
                        result = dataChunk;
                    } else {
                        result.AppendMatrix(dataChunk);
                    }
                    chunk = new List<int>();
                }
            }
            progress.ProgressEnd(String.Format("{0} Darwin Core records retrieved.", count));

            return result;
        }
Esempio n. 3
0
        void TaxonTooltipContent_Loaded(object sender, RoutedEventArgs e)
        {
            var service = new TaxaService(PluginManager.Instance.User);
            var Model = service.GetTaxon(TaxonID);
            if (Model == null) {
                return;
            }

            var elementRank = service.GetTaxonRank(Model);

            var header = Model.TaxaFullName;

            if (Model.AvailableName.ValueOrFalse()) {
                header += " (Available name)";
            } else if (Model.LiteratureName.ValueOrFalse()) {
                header += " (Literature name)";
            }

            lblHeader.Content = header;
            var rankName = (elementRank == null ? "Unranked" : elementRank.LongName + (Model.AvailableName.ValueOrFalse() ? " Available Name" : ""));

            var kingdom = string.IsNullOrEmpty(Model.KingdomCode) ? "No Kingdom" : Model.KingdomCode;

            lblSystem.Content = string.Format("[{0}] {1} <{2}> Last updated: {3:g} by {4}", Model.TaxaID.Value, rankName, kingdom, Model.DateLastUpdated, Model.WhoLastUpdated);
            imgIcon.Source = TaxonViewModel.ConstructIcon(Model.AvailableName.ValueOrFalse() || Model.LiteratureName.ValueOrFalse(), Model.ElemType, false);

            // Ancestry
            var bits = Model.Parentage.Split('\\');

            int i = bits.Length - 1;
            int j = 0;
            var parents = new Stack<Taxon>();
            while (--i >= 0 && j++ < 3) {
                if (!string.IsNullOrEmpty(bits[i])) {
                    var parentId = Int32.Parse(bits[i]);
                    var parent = service.GetTaxon(parentId);
                    parents.Push(parent);
                }
            }

            i = 0;
            grdAncestry.Children.Clear();

            foreach (Taxon t in parents) {
                var parentPanel = new StackPanel() { Orientation = Orientation.Horizontal, Margin = new Thickness(i * 15, i * 25, 0, 0) };
                var parentIcon = new Image() { VerticalAlignment = System.Windows.VerticalAlignment.Top, UseLayoutRounding = true, SnapsToDevicePixels = true, Stretch = Stretch.None, Margin = new Thickness(6, 0, 6, 0) };
                parentIcon.Source = TaxonViewModel.ConstructIcon(t.AvailableName.ValueOrFalse() || t.LiteratureName.ValueOrFalse(), t.ElemType, false);
                parentPanel.Children.Add(parentIcon);
                var rank = service.GetTaxonRank(t);
                rankName = (rank == null ? "Unranked" : rank.LongName);
                var txt = new TextBlock() {VerticalAlignment = System.Windows.VerticalAlignment.Top, Text = string.Format("{1}   ({0})", rankName, t.TaxaFullName) };
                parentPanel.Children.Add(txt);
                grdAncestry.Children.Add(parentPanel);
                i++;
            }
        }
Esempio n. 4
0
        public SelectRankWindow()
        {
            InitializeComponent();

            var service = new TaxaService(PluginManager.Instance.User);
            _map = service.GetTaxonRankMap();

            var kingdoms = service.GetKingdomList().Where((kingdom) => {
                return !string.IsNullOrWhiteSpace(kingdom.KingdomCode);
            });

            cmbKingdom.SelectionChanged += new SelectionChangedEventHandler(cmbKingdom_SelectionChanged);

            cmbKingdom.ItemsSource = kingdoms;
            if (kingdoms.Count() > 0) {
                cmbKingdom.SelectedIndex = 0;
            }

            this.DataContext = this;
        }
Esempio n. 5
0
        public XMLExportOptions(User user, List<int> taxonIds)
        {
            InitializeComponent();
            TaxonIDs = taxonIds;
            this.User = user;

            var lastFile = Config.GetUser(User, "XMLIOExport.LastExportFile", "");
            if (!string.IsNullOrEmpty(lastFile)) {
                if (taxonIds.Count == 1) {
                    var service = new TaxaService(user);
                    var taxon = service.GetTaxon(taxonIds[0]);
                    if (taxon != null) {
                        var f = new FileInfo(lastFile);
                        var directory = f.DirectoryName;
                        var taxaName = taxon.TaxaFullName == null ? "Unnamed" : taxon.TaxaFullName;
                        txtFilename.Text = System.IO.Path.Combine(f.DirectoryName, SystemUtils.StripIllegalFilenameChars(taxaName) + ".xml");
                    }
                } else {
                    txtFilename.Text = lastFile;
                }
            }
        }
        public List<HierarchicalViewModelBase> LoadModel(HierarchicalViewModelBase parent)
        {
            var service = new TaxaService(User);
            List<Taxon> model = null;
            if (parent == null) {
                model = service.GetTopLevelTaxa();
            } else {
                model = service.GetTaxaForParent((parent as TaxonViewModel).TaxaID.Value);
            }

            if (model != null) {

                var temp = model.Where((taxon) => {
                    return _options == LookupOptions.TaxonExcludeAvailableNames ? !taxon.AvailableName.ValueOrFalse() : true;
                }).Select((m) => {
                    return new TaxonViewModel(parent, m, _explorer.GenerateTaxonDisplayLabel);
                });

                var list = new List<HierarchicalViewModelBase>(temp);
                return list;
            }

            return null;
        }
 public override Data.DataMatrix ExtractReportData(IProgressObserver progress)
 {
     var service = new TaxaService(User);
     return service.TaxaForDistributionRegionReport(DistributionRegion.DistRegionID, TaxonID);
 }
Esempio n. 8
0
        public DataMatrix GetTaxaForSites(bool includeLocations, string itemType, int itemID, int biotaID, string criteriaText)
        {
            var taxonService = new TaxaService(User);
            var rtf = new RTFReportBuilder();

            // Create the Header inforrmation
            rtf.AppendFullHeader();

            // Create the title information
            rtf.Append(@"\pard\fs36\b Taxa for Site/Region Report\b0\pard\par\fs24 ").Append(criteriaText);
            rtf.Append(@"\pard\par\fs24 Produced: ").AppendCurrentDate();

            // extract the parentage string from the database.
            // Loop through the recordset and build the report output.
            int lngLastBiotaID = -1;
            int lngLastRegionID = -1;
            int lngLastSiteID = -1;
            string strOrderRank = "";
            string strFamilyRank = "";

            StoredProcReaderForEach("spReportTaxaForSites", (reader) => {
                // If there is a change in taxa, print the header.
                int currentBiotaID = (int) reader["BiotaID"];
                if (lngLastBiotaID != currentBiotaID) {
                    lngLastBiotaID = currentBiotaID;
                    lngLastRegionID = -1;
                    lngLastSiteID = -1;
                    rtf.Par().Par().Append(@"\pard\sb20\fs28\b ");
                    rtf.Append(AsString(reader["BiotaFullName"])).Append(@"\b0");

                    // extract the family and order
                    strOrderRank = taxonService.GetBiotaRankElemType(currentBiotaID, "O");
                    strFamilyRank = taxonService.GetBiotaRankElemType(currentBiotaID, "F");

                    if (!string.IsNullOrWhiteSpace(strOrderRank) && string.IsNullOrWhiteSpace(strFamilyRank)) {
                        rtf.Append("  [").Append(strOrderRank).Append("]");
                    } else if ((!string.IsNullOrWhiteSpace(strOrderRank) || (!string.IsNullOrWhiteSpace(strFamilyRank)))) {
                        rtf.Append("  [").Append(strOrderRank).Append(": ").Append(strFamilyRank).Append("]");
                    }
                }

                if (includeLocations) {
                    // Add the region group
                    int currentRegionID = (int) reader["RegionID"];
                    if (lngLastRegionID != currentRegionID) {
                        // Add the region
                        lngLastRegionID = currentRegionID;
                        rtf.Par().Append(@"\pard\sb10\fs20\li600 ");
                        rtf.Append(AsString(reader["FullRegion"]));
                    }

                    int currentSiteID = (int) reader["SiteID"];

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

                       // Add the long and lat.
                        int areaType = (int) reader.Get<byte>("AreaType", (byte) 0);

                        double? lat = reader.Get<double?>("Lat");
                        double? lon = reader.Get<double?>("Long");

                        double? lat2 = reader.Get<double?>("Lat2");
                        double? lon2 = reader.Get<double?>("Long2");

                        switch (areaType) {
                            case 1:   // Point

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

                    }
                }

            }, _P("vchrItemType", itemType), _P("intItemID", itemID), _P("intBiotaID", biotaID));

            rtf.Append(" }");

            return rtf.GetAsMatrix();
        }
Esempio n. 9
0
        public DataMatrix GetDarwinCoreForBiotaID(int biotaID)
        {
            var taxon = new TaxaService(User).GetTaxon(biotaID);

            if (taxon == null) {
                return new DataMatrix();
            }

            return new DarwinCoreReportHelper().RunDwcQuery(this, String.Format("tblBiota.vchrParentage LIKE '{0}\\%'", taxon.Parentage));
        }
Esempio n. 10
0
        private void BuildTaxaChildrenViewModel(HierarchicalViewModelBase item, int taxaID)
        {
            // The model node is a Taxon favorites, so we can get the 'real' taxon children for it...
            item.Children.Clear();

            var taxaService = new TaxaService(User);
            List<Taxon> taxa = taxaService.GetTaxaForParent(taxaID);
            foreach (Taxon taxon in taxa) {
                TaxonViewModel child = new TaxonViewModel(item, taxon, null);
                if (child.NumChildren > 0) {
                    child.LazyLoadChildren += new HierarchicalViewModelAction(viewModel_LazyLoadChildren);
                    child.Children.Add(new ViewModelPlaceholder("Loading..."));
                }
                item.Children.Add(child);
            }
        }
Esempio n. 11
0
        protected override List<RefLink> SelectReferences(IProgressObserver progress)
        {
            var service = new SupportService(User);
            var taxaService = new TaxaService(User);
            if (progress != null) {
                progress.ProgressMessage("Retrieving Reference links...");
            }
            var reflinks = service.GetReferenceLinks(TraitCategoryType.Taxon.ToString(), Taxon.TaxaID.Value);
            if (Options.IncludeChildReferences == true) {
                var children = taxaService.GetExpandFullTree(Taxon.TaxaID.Value);

                var elementCount = 0;
                int total = children.Count;

                if (progress != null) {
                    progress.ProgressStart("Extracting references for children...");
                }

                foreach (Taxon child in children) {

                    if (progress != null) {
                        double percent = (((double)elementCount) / ((double)total)) * 100.0;
                        progress.ProgressMessage(string.Format("Processing {0}", child.TaxaFullName), percent);
                    }
                    elementCount++;

                    var links = service.GetReferenceLinks(TraitCategoryType.Taxon.ToString(), child.TaxaID.Value);
                    foreach (RefLink link in links) {
                        reflinks.Add(link);
                    }
                }

                if (progress != null) {
                    progress.ProgressEnd("");
                }

            }

            return reflinks;
        }
Esempio n. 12
0
 protected override void ProcessImpl(User user)
 {
     var service = new TaxaService(user);
     service.UpdateTaxon(Taxon);
 }
Esempio n. 13
0
 protected override void ProcessImpl(User user)
 {
     var service = new TaxaService(user);
     service.MoveTaxon(Taxon.TaxaID.Value, NewParent.TaxaID.Value);
 }
Esempio n. 14
0
 protected override void ProcessImpl(User user)
 {
     var service = new TaxaService(user);
     service.MergeTaxon(Source.TaxaID.Value, Target.TaxaID.Value, CreateNewIDRecord);
     service.DeleteTaxon(Source.TaxaID.Value);
 }
Esempio n. 15
0
 protected override void ProcessImpl(User user)
 {
     var service = new TaxaService(user);
     service.InsertTaxon(Taxon.Taxon);
     // The service will have updated the new taxon with its database identity.
     // If this taxon has any children we can update their identity too.
     foreach (HierarchicalViewModelBase child in Taxon.Children) {
         TaxonViewModel tvm = child as TaxonViewModel;
         tvm.TaxaParentID = Taxon.Taxon.TaxaID;
     }
 }
Esempio n. 16
0
        private void DoFind(string searchTerm)
        {
            if (String.IsNullOrEmpty(searchTerm)) {
                return;
            }

            _searchModel.Clear();

            using (new OverrideCursor(Cursors.Wait)) {
                if (Owner == null) {
                    return;
                }
                List<TaxonSearchResult> results = new TaxaService(Owner.User).FindTaxa(searchTerm);

                if (!PluginManager.Instance.CheckSearchResults(results)) {
                    return;
                }

                tvwResults.InvokeIfRequired(() => {
                    foreach (Taxon t in results) {
                        var item = new TaxonViewModel(null, t, GenerateTaxonDisplayLabel);
                        if (item.NumChildren > 0) {
                            item.LazyLoadChildren += new HierarchicalViewModelAction(item_LazyLoadChildren);
                            item.Children.Add(new ViewModelPlaceholder(_R("TaxonExplorer.explorer.loading", item.Epithet)));
                        }

                        _searchModel.Add(item);
                    }

                });
            }
        }
Esempio n. 17
0
        private void TreeViewItem_MouseRightButtonDown(object sender, MouseEventArgs e)
        {
            TreeViewItem item = sender as TreeViewItem;

            if (item == null) {
                return;
            }

            item.Focus();
            e.Handled = true;

            var model = tvwFavorites.SelectedItem as HierarchicalViewModelBase;

            Debug.Assert(model != null);

            int? favoriteId = null;

            TaxonViewModel tvm = null;

            bool isGroup = false;

            if (model is TaxonFavoriteViewModel) {
                var fav = model as TaxonFavoriteViewModel;
                favoriteId = fav.FavoriteID;
                if (!fav.IsGroup) {
                    var taxon = new TaxaService(User).GetTaxon(fav.TaxaID);
                    tvm = new TaxonViewModel(null, taxon, TaxonExplorer.GenerateTaxonDisplayLabel);
                } else {
                    isGroup = true;
                }

            } else if (model is TaxonViewModel) {
                tvm = model as TaxonViewModel;
            }

            if (tvm != null) {
                TaxonMenuFactory f = new TaxonMenuFactory(tvm, TaxonExplorer, TaxonExplorer._R);
                tvwFavorites.ContextMenu = f.BuildFavoritesMenu(model);
            } else {
                var builder = new ContextMenuBuilder(null);

                builder.New("Add favorite group").Handler(() => { AddFavoriteGroup(model); }).End();
                if (isGroup) {
                    builder.New("Rename group").Handler(() => { RenameFavoriteGroup(model as TaxonFavoriteViewModel); }).End();
                    builder.New("Remove favorite group").Handler(() => { DeleteFavoriteGroup(model); }).End();
                }

                tvwFavorites.ContextMenu = builder.ContextMenu;
            }
        }
Esempio n. 18
0
        public List<HierarchicalViewModelBase> Search(string searchTerm)
        {
            var service = new TaxaService(User);

            var list = service.FindTaxa(searchTerm).Where((taxon) => {
                return _options == LookupOptions.TaxonExcludeAvailableNames ? !taxon.AvailableName.ValueOrFalse() : true;
            });

            var results = new List<HierarchicalViewModelBase>(list.Select((m) => {
                return new TaxonViewModel(null, m, _explorer.GenerateTaxonDisplayLabel);
            }));

            results.Sort(new TaxonComparer());

            //(vm1, vm2) => {
            //    var t1 = vm1 as TaxonViewModel;
            //    var t2 = vm2 as TaxonViewModel;
            //    return StringComparer.CurrentCultureIgnoreCase.Compare(t2.DefaultSortOrder, t1.DefaultSortOrder);
            //});

            return results;
        }
Esempio n. 19
0
 protected override void InitImportImpl()
 {
     LogMsg("Caching rank data...");
     var taxonService = new TaxaService(User);
     _ranks = taxonService.GetOrderedRanks();
 }
Esempio n. 20
0
 protected override void ProcessImpl(User user)
 {
     var service = new TaxaService(user);
     service.DeleteTaxon(Taxon.TaxaID.Value);
 }