예제 #1
0
        /// <summary>
        /// Adds the headers.
        /// </summary>
        /// <param name="worksheet">The worksheet.</param>
        private void AddHeaders(ExcelWorksheet worksheet)
        {
            Int32 columnIndex;

            columnIndex = 1;
            if (_options.OutputTaxonId)
            {
                _taxonIdColumnId = columnIndex++;
                worksheet.Cells[1, _taxonIdColumnId].Value = Resources.DyntaxaResource.ExportStraightColumnTaxonId;
            }

            if (_options.IsHierarchical)
            {
                _hierarchicalParentTaxaColumnId   = columnIndex;
                _hierarchicalParentTaxonColumnIds = new Dictionary <Int32, Int32>();
                foreach (ITaxonCategory taxonCategory in _options.GetFilteredTaxonCategories())
                {
                    _hierarchicalParentTaxonColumnIds.Add(taxonCategory.Id, columnIndex);
                    using (ExcelRange range = worksheet.Cells[1, columnIndex])
                    {
                        range.Value = taxonCategory.Name;
                        range.Style.Fill.PatternType = ExcelFillStyle.Solid;
                        range.Style.Fill.BackgroundColor.SetColor(GetHierarchicalColumnColor(columnIndex++));
                    }
                }
            }
            else if (_options.OutputTaxonCategory)
            {
                _taxonCategoryColumnId = columnIndex++;
                worksheet.Cells[1, _taxonCategoryColumnId].Value = Resources.DyntaxaResource.ExportStraightColumnTaxonCategory;
            }

            if (_options.OutputScientificName)
            {
                _scientificNameColumnId = columnIndex++;
                worksheet.Cells[1, _scientificNameColumnId].Value = Resources.DyntaxaResource.ExportStraightColumnScientificName;
            }

            if (_options.OutputAuthor)
            {
                _authorColumnId = columnIndex++;
                worksheet.Cells[1, _authorColumnId].Value = Resources.DyntaxaResource.ExportStraightColumnAuthor;
            }

            if (_options.OutputCommonName)
            {
                _commonNameColumnId = columnIndex++;
                worksheet.Cells[1, _commonNameColumnId].Value = Resources.DyntaxaResource.ExportStraightColumnCommonName;
            }

            if (_options.OutputGUID)
            {
                _guidColumnId = columnIndex++;
                worksheet.Cells[1, _guidColumnId].Value = Resources.DyntaxaResource.ExportStraightColumnGUID;
            }

            if (_options.OutputRecommendedGUID)
            {
                _recommendedGuidColumnId = columnIndex++;
                worksheet.Cells[1, _recommendedGuidColumnId].Value = Resources.DyntaxaResource.ExportStraightColumnRecommendedGUID;
            }

            if (_options.OutputTaxonUrl)
            {
                _taxonUrlColumnId = columnIndex++;
                worksheet.Cells[1, _taxonUrlColumnId].Value = Resources.DyntaxaResource.ExportStraightColumnTaxonInfoUrl;
            }

            if (_options.OutputSwedishOccurrence)
            {
                _swedishOccurrenceColumnId = columnIndex++;
                worksheet.Cells[1, _swedishOccurrenceColumnId].Value = Resources.DyntaxaResource.ExportStraightSwedishOccurrence;
            }

            if (_options.OutputSwedishHistory)
            {
                _swedishHistoryColumnId = columnIndex++;
                worksheet.Cells[1, _swedishHistoryColumnId].Value = Resources.DyntaxaResource.ExportStraightSwedishHistory;
            }

            if (_options.OutputSynonyms)
            {
                _synonymsColumnId = columnIndex++;
                worksheet.Cells[1, _synonymsColumnId].Value = Resources.DyntaxaResource.ExportStraightSynonyms;
            }

            if (_options.OutputProParteSynonyms)
            {
                _proParteSynonymsColumnId = columnIndex++;
                worksheet.Cells[1, _proParteSynonymsColumnId].Value = Resources.DyntaxaResource.ExportStraightProParteSynonyms;
            }
            if (_options.OutputProParteSynonyms)
            {
                _proParteSynonymsColumnId = columnIndex++;
                worksheet.Cells[1, _proParteSynonymsColumnId].Value = Resources.DyntaxaResource.ExportStraightProParteSynonyms;
            }
            if (_options.OutputMisappliedNames)
            {
                _misappliedNamesColumnId = columnIndex++;
                worksheet.Cells[1, _misappliedNamesColumnId].Value = Resources.DyntaxaResource.ExportStraightMisappliedNames;
            }
            if (_options.GetOutputTaxonCategories().IsNotEmpty())
            {
                _parentTaxonColumnIds = new List <Int32>();
                //_parentTaxaColumnId = columnIndex++;
                //worksheet.Cells[1, _parentTaxaColumnId].Value = Resources.DyntaxaResource.ExportStraightParentTaxa;

                foreach (ITaxonCategory taxonCategory in _options.GetOutputTaxonCategories())
                {
                    _parentTaxonColumnIds.Add(columnIndex);
                    worksheet.Cells[1, columnIndex++].Value = taxonCategory.Name;
                    _parentTaxaCategoryNames.Add(taxonCategory.Name);
                }
            }

            if (_options.GetOutputTaxonNameCategories().IsNotEmpty())
            {
                _taxonNameCategoryColumnIds = new List <Int32>();
                foreach (ITaxonNameCategory taxonNameCategory in _options.GetOutputTaxonNameCategories())
                {
                    _taxonNameCategoryColumnIds.Add(columnIndex);
                    worksheet.Cells[1, columnIndex++].Value = taxonNameCategory.Name;
                }
            }

            _columnCount = columnIndex - 1;

            if (_columnCount > 0)
            {
                using (ExcelRange range = worksheet.Cells[1, 1, 1, _columnCount])
                {
                    range.Style.Font.Bold = true;
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Method that generate a list of taxon items with the most basic set of parameters.
        /// </summary>
        /// <returns>Export taxon items.</returns>
        private List <ExportTaxonItem> GetExportTaxonItems()
        {
            Boolean                hasOutputTaxonNames;
            ExportTaxonItem        exportTaxonItem;
            Int32                  index;
            ITaxon                 taxon;
            List <ExportTaxonItem> exportTaxonList;
            List <TaxonNameList>   allTaxonNames = null;

            ArtDatabanken.Data.SpeciesFact speciesFact;
            Stopwatch         stopwatch;
            TaxonCategoryList outputTaxonCategories;
            TaxonList         filteredTaxa;

            stopwatch = new Stopwatch();
            stopwatch.Start();

            exportTaxonList       = new List <ExportTaxonItem>();
            hasOutputTaxonNames   = HasOutputTaxonNames();
            filteredTaxa          = _options.GetFilteredTaxa(this._userContext);
            outputTaxonCategories = _options.GetOutputTaxonCategories();
            if (filteredTaxa.IsNotEmpty())
            {
                if (hasOutputTaxonNames)
                {
                    allTaxonNames = CoreData.TaxonManager.GetTaxonNames(_userContext, filteredTaxa);
                }

                for (index = 0; index < filteredTaxa.Count; index++)
                {
                    taxon           = filteredTaxa[index];
                    exportTaxonItem = new ExportTaxonItem(
                        taxon,
                        _options.GetTaxonTreeNode(taxon),
                        outputTaxonCategories);

                    // Add swedish history information.
                    if (_options.OutputSwedishHistory)
                    {
                        speciesFact = _options.GetSpeciesFact(this._userContext, ArtDatabanken.Data.FactorId.SwedishHistory, exportTaxonItem.Taxon);
                        if (speciesFact.IsNotNull() &&
                            speciesFact.MainField.IsNotNull() &&
                            speciesFact.MainField.EnumValue.IsNotNull())
                        {
                            exportTaxonItem.SwedishHistory = speciesFact.MainField.EnumValue.OriginalLabel;
                        }
                    }

                    // Add swedish occurrence information.
                    if (_options.OutputSwedishOccurrence)
                    {
                        speciesFact = _options.GetSpeciesFact(this._userContext, ArtDatabanken.Data.FactorId.SwedishOccurrence, exportTaxonItem.Taxon);
                        if (speciesFact.IsNotNull() &&
                            speciesFact.MainField.IsNotNull() &&
                            speciesFact.MainField.EnumValue.IsNotNull())
                        {
                            exportTaxonItem.SwedishOccurrence = speciesFact.MainField.EnumValue.OriginalLabel;
                        }
                    }

                    // Add taxon name information.
                    if (hasOutputTaxonNames)
                    {
                        exportTaxonItem.TaxonNames = allTaxonNames[index];
                    }

                    // Synonyms
                    if (_options.OutputSynonyms)
                    {
                        exportTaxonItem.Synonyms = GetSynonyms(taxon);
                    }

                    // Synonyms
                    if (_options.OutputProParteSynonyms)
                    {
                        exportTaxonItem.ProParteSynonyms = GetProParteSynonyms(taxon);
                    }

                    // Synonyms
                    if (_options.OutputMisappliedNames)
                    {
                        exportTaxonItem.MisappliedNames = GetMisappliedNames(taxon);
                    }

                    // Synonyms excl. auktor
                    //if (_options.OutputExcludeAuctor)
                    //{
                    //    //exportTaxonItem.MisappliedNames = GetMisappliedNames(taxon);
                    //}

                    exportTaxonList.Add(exportTaxonItem);
                }
            }

            stopwatch.Stop();
            DyntaxaLogger.WriteMessage("Export: Get all data to populate Excel file: {0:N0} milliseconds", stopwatch.ElapsedMilliseconds);

            return(exportTaxonList);
        }