Exemplo n.º 1
0
/// <summary>
/// Check that each of the numbers in the list exist in the database
/// </summary>
/// <param name="list">String form of list as entered by user</param>
/// <param name="rootTableName">Root table to check against</param>
/// <returns></returns>

        public static string ValidateList(
            string listText,
            string rootTableName)
        {
            string cn, extCn, errorMsg;
            int    i1, i2;

            if (String.IsNullOrEmpty(rootTableName))
            {
                return(null);
            }
            MetaTable rootTable = MetaTableCollection.GetWithException(rootTableName);

            string[] cna = listText.Split(new Char[] { '\n', '\r', ' ' });

            int t0 = TimeOfDay.Milliseconds();

            for (i1 = 0; i1 < cna.Length; i1++)
            {
                if (i1 > 1000 || TimeOfDay.Milliseconds() - t0 > 3000)
                {
                    return(null);                                                                   // limit size & time of check
                }
                extCn = cna[i1].Trim();
                if (extCn == "" || extCn.StartsWith("("))
                {
                    continue;
                }

                i2 = extCn.IndexOf("(");                 // strip trailing text in parens
                if (i2 > 0)
                {
                    extCn = extCn.Substring(0, i2);
                }
                cn = CompoundId.BestMatch(extCn, rootTable);
                if (cn == "")
                {
                    cn = extCn;                           // nothing found, use original text
                }
                if (!CompoundIdUtil.Exists(cn, rootTable))
                {
                    return(extCn);
                }
            }

            return(null);
        }