Exemple #1
0
        /// <summary>
        /// Populate the ListView with characters.
        /// </summary>
        /// <param name="bookFilter">0 = no filter. Otherwise, UID of book.</param>
        /// <param name="importFilter">Null = no filter. Otherwise, importance level to filter.</param>
        private void PopulateCharacterList(int bookFilter, ImportLevel? importFilter)
        {
            lstCharacters.Items.Clear();

            for (int i = 0; i < series.Characters.Count; i++)
            {
                Character ch = series.Characters[i];

                // Each boolean is true if no filtering or if
                // filter condition is met.
                bool bookApproved = (bookFilter == 0) ||
                    (ch.Appearances.Contains(bookAppearanceFilter));
                bool importApproved = (importFilter == null) ||
                    (ch.Importance == importFilter);

                if (bookApproved && importApproved)
                {
                    ListViewItem lvi = new ListViewItem(ch.Name);
                    lvi.SubItems.Add(ch.Nickname);
                    lvi.SubItems.Add(Utils.ToOneLine(ch.Description));
                    lvi.Tag = ch;

                    lstCharacters.Items.Add(lvi);
                }
            }
        }
Exemple #2
0
        private ImportLevel GetLevel(IEnumerable <ImportFieldMapping> mappings)
        {
            bool bRegion   = false;
            bool bSite     = false;
            bool bVisit    = false;
            bool bMaterial = false;
            bool bTaxa     = false;

            foreach (ImportFieldMapping mapping in mappings)
            {
                if (!string.IsNullOrWhiteSpace(mapping.TargetColumn))
                {
                    var category = mapping.TargetColumn.Substring(0, mapping.TargetColumn.IndexOf('.'));
                    switch (category)
                    {
                    case "Region":
                        bRegion = true;
                        break;

                    case "Site":
                        bSite = true;
                        break;

                    case "SiteVisit":
                        bVisit = true;
                        break;

                    case "Material":
                        bMaterial = true;
                        break;

                    case "Taxon":
                        bTaxa = true;
                        break;

                    default:
                        break;
                    }
                }
            }

            if (!bRegion && !bSite && !bVisit && !bMaterial && !bTaxa)
            {
                throw new Exception("Row has no recognisable data mapped!");
            }

            if (bMaterial)
            {
                if (bTaxa)
                {
                    return(ImportLevel.MaterialWithTaxa);
                }
                else
                {
                    return(ImportLevel.MaterialWithoutTaxa);
                }
            }

            if (bTaxa)
            {
                if (bRegion || bSite || bVisit)
                {
                    return(ImportLevel.MaterialWithTaxa);
                }
                else
                {
                    return(ImportLevel.TaxaOnly);
                }
            }

            ImportLevel ret = ImportLevel.Error;

            if (bRegion)
            {
                ret = ImportLevel.Region;
            }

            if (bSite)
            {
                ret = ImportLevel.Site;
            }

            if (bVisit)
            {
                ret = ImportLevel.Visit;
            }

            return(ret);
        }