Exemple #1
0
/// <summary>
/// Get the root table associated with a compound id prefix
/// </summary>
/// <param name="cid"></param>
/// <param name="mt"></param>
/// <returns></returns>

        public static MetaTable GetRootMetaTableFromCid(
            string cid,
            MetaTable mt)
        {
            RootTable rti;
            MetaTable rootMt;
            string    prefix, suffix, remainder, table;
            bool      dashBeforeNumber, canFormat;
            int       number;

            if (mt != null)             // if metatable is defined see if it is a root table
            {
                if (mt.IsRootTable)
                {
                    return(mt);                                // if this is a root table then we're done
                }
                if (RootTable.IsMultiplePrefixTable(mt))
                {
                    return(mt);                    // if isolated then ignore prefix & use this table
                }
            }

            AnalyzeCid(cid, mt, out prefix, out dashBeforeNumber, out number, out suffix, out remainder, out rti, out rootMt, out canFormat);
            return(rootMt);
        }
Exemple #2
0
/// <summary>
/// Analyze compound id string
/// </summary>
/// <param name="cid"></param>
/// <param name="mt"></param>
/// <param name="prefix"></param>
/// <param name="dashBeforeNumber"></param>
/// <param name="number"></param>
/// <param name="suffix"></param>
/// <param name="remainder"></param>
/// <param name="rti"></param>
/// <param name="rootMt"></param>
/// <param name="canFormat"></param>

        public static void AnalyzeCid(
            string cid,
            MetaTable mt,
            out string prefix,
            out bool dashBeforeNumber,
            out int number,
            out string suffix,
            out string remainder,
            out RootTable rti,
            out MetaTable rootMt,
            out bool canFormat)
        {
// Tests for proper cid conversions
// 1. Quick search
// 2. Key match, equality
// 3. Key match, list editor
// 4. Retrieve without structure & check that struct pops up on mouseover of cid
// 5. Add structure search for struct model retrieved using key
// 6. Run BQ12 to be sure multidatabase search is working (once only)

            canFormat = true;

            ParseCid(cid, out prefix, out dashBeforeNumber, out number, out suffix, out remainder);
            if (prefix == "CorpId")
            {
                prefix = "";                                   // fix for old lists containing CorpId prefix
            }
            if (mt != null && mt.IsUserDatabaseStructureTable) // user database structure table
            {
                rti    = RootTable.GetFromPrefix("USERDATABASE");
                rootMt = mt;
            }

            else
            {
                GetRootMetaTableFromPrefix(prefix, out rti, out rootMt);              // normal case
            }
            if (RootTable.IsMultiplePrefixTable(mt))
            {
                canFormat = false;                 // can't format if multiple prefix table
            }
            if (rti == null)
            {
                canFormat = false;
            }

            return;
        }
Exemple #3
0
/// <summary>
/// Convert a compound number from internal to external format
/// </summary>
/// <param name="cid"></param>
/// <param name="mt"></param>
/// <returns></returns>

        public static string Format(
            string normalizedCid,
            MetaTable mt)
        {
            string    prefix = "", suffix = "", remainder = "", nTxt, fmt, fCid;
            bool      dashBeforeNumber, canFormat;
            RootTable rti = null, rtiBase;
            MetaTable rootMt;
            int       number = -1;

            //if (mt == null) mt = mt; // debug

            string cid = normalizedCid;

            if (String.IsNullOrEmpty(cid))
            {
                return(cid);
            }

            if (mt != null && !RootTable.IsStructureDatabaseRootTable(mt.Root))             // non structure root table
            {
                if (mt.Root.KeyMetaColumn.IsNumeric && Lex.IsInteger(cid))
                {                 // if numeric then return as simple integer with leading zeros removed
                    number = int.Parse(cid);
                    fCid   = number.ToString();
                    return(fCid);
                }

                else
                {
                    return(cid);                 // just return as is
                }
            }

            cid = Lex.RemoveAllQuotes(cid.Trim()).Trim();             // clean up
            if (cid.Length == 0)
            {
                return("");                           // something really there
            }
            if (mt != null && UserObject.IsUserDatabaseStructureTableName(mt.Root.Name))
            {                           // user database
                if (Lex.IsInteger(cid)) // if number format with no leading zeros
                {
                    return(Int32.Parse(cid).ToString());
                }
                else
                {
                    return(cid);                 // otherwise return as is
                }
            }

            if (RootTable.IsMultiplePrefixTable(mt))
            {
                return(cid);                // no formatting just return as is
            }
            AnalyzeCid(cid, mt, out prefix, out dashBeforeNumber, out number, out suffix, out remainder, out rti, out rootMt, out canFormat);
            if (!canFormat)
            {
                return(cid);
            }

            if (prefix == "")
            {
                prefix = "none";
            }

            rti = RootTable.GetFromPrefix(prefix);

            if (rti == null || Lex.IsNullOrEmpty(rti.ExternalNumberFormat))
            {
                fmt = "{0}";                 // unknown prefix
            }
            else
            {
                fmt = "{0," + rti.ExternalNumberFormat + "}";
            }

            if (prefix == "none")
            {
                prefix = "";
            }

            if (number < 0)
            {
                nTxt = "";
            }
            else
            {
                try { nTxt = String.Format(fmt, number); }
                catch (Exception ex) { nTxt = number.ToString(); }
            }

            AddDashIfAppropriate(ref prefix, dashBeforeNumber, rti);

            fCid = prefix + nTxt + suffix;

            if (fCid == "")
            {
                return(cid);
            }
            return(fCid);
        }
Exemple #4
0
/// <summary>
/// Normalize compound number for database searching/storage
/// </summary>
/// <param name="cid"></param>
/// <param name="mt"></param>
/// <returns></returns>

        public static string NormalizeForDatabase(
            string unnormalizedCid,
            MetaTable mt)
        {
            RootTable rti = null;
            MetaTable rootMt;
            string    cid, prefix = "", suffix = "", remainder = "", nTxt = "", fmt, nCid;
            bool      dashBeforeNumber = false, canFormat;
            int       number = -1;

//			if (cid.Contains("91341")) cid = cid; // debug
//			if (mt == null) mt = mt; // debug

            cid = NormalizeCase(unnormalizedCid, mt);
            if (String.IsNullOrEmpty(cid))
            {
                return(cid);
            }

            if (cid.Contains(" "))
            {
                cid = cid.Replace(" ", "_");                                // replace any spaces with underscores
            }
            if (cid.Contains("\n"))
            {
                cid = cid.Replace("\n", "");                                 // remove newlines
            }
            if (cid.Contains("\r"))
            {
                cid = cid.Replace("\r", "");                                 // remove returns
            }
            if (mt != null && !RootTable.IsStructureDatabaseRootTable(mt.Root))
            {
                return(cid);
            }

            if (RootTable.IsMultiplePrefixTable(mt))
            {
                return(cid);                // no formatting just return as is
            }
            if (mt != null && UserObject.IsUserDatabaseStructureTableName(mt.Root.Name))
            {                            // user database
                prefix = "userdatabase"; // used to lookup format
                if (Lex.IsInteger(cid))
                {
                    number = Int32.Parse(cid);
                }
                else
                {
                    suffix = cid;
                }
            }

            else             // other database
            {
                if (mt != null && RootTable.GetFromTableName(mt.Root.Name) == null)
                {
                    return(cid);                    // if not a recognized database return cid as is
                }
                AnalyzeCid(cid, mt, out prefix, out dashBeforeNumber, out number, out suffix, out remainder, out rti, out rootMt, out canFormat);
                if (!canFormat)
                {
                    return(cid);
                }

                string mtPrefix = "";
                if (mt != null)                 // get any prefix for metatable
                {
                    mtPrefix = GetPrefixFromRootTable(mt);
                }

                if (mtPrefix.EndsWith("-") && prefix != "" && !prefix.EndsWith("-"))
                {                 // adjust to allow prefix match
                    prefix          += "-";
                    dashBeforeNumber = false;
                }

                if (prefix == "")                 // if no prefix in number then add any metatable prefix
                {
                    if (mtPrefix != "")
                    {
                        prefix = mtPrefix;
                    }
                    else
                    {
                        prefix = "none";
                    }
                }

                else if (mt != null && !Lex.Eq(prefix, mtPrefix))
                {
                    return(null);                    // if prefix invalid for database return null
                }
            }

            rti = RootTable.GetFromPrefix(prefix);
            if (rti == null && prefix == "userdatabase")
            {
                fmt    = "{0,8:00000000}";              // default format for user databases
                prefix = "";
            }

            else if (rti == null || Lex.IsNullOrEmpty(rti.InternalNumberFormat))
            {                // unknown format
                fmt = "{0}"; // default format
                if (rti != null && !rti.PrefixIsStored)
                {
                    prefix = "";                                                     // database doesn't contain prefix
                }
            }

            else             // use supplied format
            {
                fmt = "{0," + rti.InternalNumberFormat + "}";
                if (!rti.PrefixIsStored)
                {
                    prefix = "";                                      // database doesn't contain prefix
                }
            }

            if (number < 0)
            {
                nTxt = "";
            }
            else
            {
                try { nTxt = String.Format(fmt, number); }
                catch (Exception ex) { nTxt = number.ToString(); }
            }

            //if (Lex.StartsWith(cid, "GGO-")) nTxt = "-" + nTxt; // hack for GeneGo database, fix later

            if (prefix == "none")
            {
                prefix = "";
            }

            AddDashIfAppropriate(ref prefix, dashBeforeNumber, rti);

            nCid = (prefix + nTxt + suffix).ToUpper();
            if (nCid.Contains(" "))
            {
                nCid = nCid.Replace(" ", "_");                                 // replace any internal spaces with underscores
            }
            return(nCid);
        }