コード例 #1
0
        private static Control[] FindControls(Control container, string type, string alias, int index, string name, bool searchChildren)
        {
            IList <Control> ctrlist = new List <Control>();

            string[] types = StrUtil.GetSplitList(type, ",");
            if (types != null && types.Length > 0)
            {
                Control[] ctrls;
                string    key;
                foreach (string maintype in types)
                {
                    key = string.Format("{0}{1}{2}", maintype, alias, index > 0 ? Convert.ToString(index) : "");
                    if (!key.Equals(""))
                    {
                        ctrls = container.Controls.Find(key, searchChildren);
                        foreach (Control ctrl in ctrls)
                        {
                            ctrlist.Add(ctrl);
                        }
                    }
                    key = string.Format("{0}{1}{2}", maintype, alias, name);
                    if (!key.Equals(""))
                    {
                        ctrls = container.Controls.Find(key, searchChildren);
                        foreach (Control ctrl in ctrls)
                        {
                            ctrlist.Add(ctrl);
                        }
                    }
                }
            }
            return(ctrlist.ToArray());
        }
コード例 #2
0
        public static bool CheckConstraints(object value, RuleColumn rc, ref string message)
        {
            if (value == null && !rc.IsNullable)
            {
                message = "“" + rc.Label + "”不能为空值!";
                return(false);
            }

            if (rc != null && rc.HasConstraints)
            {
                string constraints = rc.Constraints.Trim();

                message = rc.ErrorMessage.Trim();

                if (constraints.ToUpper().StartsWith("REGEXP:"))
                {
                    return(ExecRegexp(constraints.Substring(7, constraints.Length - 7), (string)value, ref message));
                }
                else if (constraints.ToUpper().StartsWith("NEGREGEXP:"))
                {
                    return(ExecNegRegexp(constraints.Substring(10, constraints.Length - 10), (string)value, ref message));
                }
                else if (constraints.ToUpper().StartsWith("JAVASCRIPT:"))
                {
                    string script = constraints.Substring(11, constraints.Length - 11);
                    if (script != null && !script.Equals(""))
                    {
                        return(ExecScript("JavaScript", script, (string)value, ref message));
                    }
                }
                else if (constraints.ToUpper().IndexOf("</CHECK>") > 0)
                {
                    string[] checks = StrUtil.GetSplitList(constraints, "</CHECK>");
                    if (checks != null && checks.Length > 0)
                    {
                        string scripttype, script;
                        int    index;

                        foreach (string check in checks)
                        {
                            scripttype = "";
                            script     = "";

                            index = check.ToUpper().IndexOf("<CHECK TYPE=\"");
                            if (index >= 0)
                            {
                                script = check.Substring(index + 13, check.Length - index - 13);

                                index = script.ToUpper().IndexOf("\">");
                                if (index >= 0)
                                {
                                    scripttype = script.Substring(0, index).Trim().ToUpper();
                                    script     = script.Substring(index + 2, script.Length - index - 2);
                                }
                            }

                            if (script != null && !script.Equals(""))
                            {
                                if (scripttype.Equals("REGEXP"))
                                {
                                    if (!ExecRegexp(script, (string)value, ref message))
                                    {
                                        return(false);
                                    }
                                }
                                else if (scripttype.Equals("NEGREGEXP"))
                                {
                                    if (!ExecNegRegexp(script, (string)value, ref message))
                                    {
                                        return(false);
                                    }
                                }
                                else if (scripttype != null && !scripttype.Equals(""))
                                {
                                    if (!ExecScript(scripttype, script, (string)value, ref message))
                                    {
                                        return(false);
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    return(ExecRegexp(constraints, (string)value, ref message));
                }
            }
            return(true);
        }