コード例 #1
0
            public static void check(ParmsAttr pa, int v)
            {
                if (pa.req && v == 0)
                {
                    throw new XExcep("0x0003", pa.name);
                }

                int?min = null, max = null;

                if (pa.min != null)
                {
                    min = (int)pa.min;
                }
                if (pa.max != null)
                {
                    max = (int)pa.max;
                }

                if (min != null && v < min)
                {
                    throw new XExcep("0x0004", String.Format("{0}的值要大于{1}", pa.name, min));
                }
                if (max != null && v > max)
                {
                    throw new XExcep("0x0004", String.Format("{0}的值要小于{1}", pa.name, min));
                }
            }
コード例 #2
0
            public static void check(ParmsAttr pa, string v)
            {
                if (pa.req && string.IsNullOrEmpty(v))
                {
                    throw new XExcep("0x0003", pa.name);
                }

                string min = (string)pa.min;
                string max = (string)pa.max;

                if (!string.IsNullOrEmpty(min) && v.CompareTo(min) < 0)
                {
                    throw new XExcep("0x0004", String.Format("{0}的值要大于{1}", pa.name, min));
                }
                if (!string.IsNullOrEmpty(max) && v.CompareTo(max) > 0)
                {
                    throw new XExcep("0x0004", String.Format("{0}的值要小于{1}", pa.name, max));
                }

                if (string.IsNullOrEmpty(pa.len))
                {
                    return;
                }
                var ls = pa.len.Split(',');

                if (ls.Length == 1 && v.Length != int.Parse(ls[0]))
                {
                    throw new XExcep("0x0004", String.Format("{0}应为{1}个字符", pa.name, ls[0]));
                }
                else if (ls.Length > 1)
                {
                    if (!string.IsNullOrEmpty(ls[0]) && v.Length < int.Parse(ls[0]))
                    {
                        throw new XExcep("0x0004", String.Format("{0}至少{1}个字符", pa.name, ls[0]));
                    }
                    if (!string.IsNullOrEmpty(ls[1]) && v.Length > int.Parse(ls[1]))
                    {
                        throw new XExcep("0x0004", String.Format("{0}最多{1}个字符", pa.name, ls[1]));
                    }
                }
            }
コード例 #3
0
            public static void check(ParmsAttr pa, DateTime v)
            {
                if (pa.req && v == null)
                {
                    throw new XExcep("0x0003", pa.name);
                }

                if (pa.min == null && pa.max == null)
                {
                    return;
                }
                DateTime min = (DateTime)pa.min;
                DateTime max = (DateTime)pa.max;

                if (v < min)
                {
                    throw new XExcep("0x0004", String.Format("{0}的值要大于{1}", pa.name, min));
                }
                if (v > max)
                {
                    throw new XExcep("0x0004", String.Format("{0}的值要小于{1}", pa.name, min));
                }
            }
コード例 #4
0
            public static void check(ParmsAttr pa, decimal v)
            {
                if (pa.req && v == 0)
                {
                    throw new XExcep("0x0003", pa.name);
                }

                if (pa.min == null && pa.max == null)
                {
                    return;
                }
                decimal min = (decimal)pa.min;
                decimal max = (decimal)pa.max;

                if (v < min)
                {
                    throw new XExcep("0x0004", String.Format("{0}的值要大于{1}", pa.name, min));
                }
                if (v > max)
                {
                    throw new XExcep("0x0004", String.Format("{0}的值要小于{1}", pa.name, min));
                }
            }