Exemplo n.º 1
0
 //Perform a type specific check
 //Return true if value is in range
 public bool InRange(string value)
 {
     if (FieldTypeUtil.Compare(value, MinVal, _list.RangeListType) >= 0 && FieldTypeUtil.Compare(value, MaxVal, _list.RangeListType) <= 0)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 2
0
            /*
             * Given a string that's an item in the list
             * first check to see if its an single item x
             * or a range x thru y.
             *
             * Throw an ArgumentException if items can't
             * be converted to itemType
             */
            public Range(string item, RangeList list)
            {
                _list = list;

                string[] sArr = item.Trim().Split(new string[] { "thru" }, StringSplitOptions.RemoveEmptyEntries);

                if (sArr.Length == 1)
                {
                    //single item. Check that it can be converted to list type and set min/max val
                    if (FieldTypeUtil.CheckType(sArr[0].Trim(), list.RangeListType) == false)
                    {
                        throw new ArgumentException(string.Format("Item not valid. Can't convert {0} to {1}", sArr[0], list.RangeListType));
                    }
                    else
                    {
                        MinVal = sArr[0];
                        MaxVal = sArr[0];
                    }
                }
                else if (sArr.Length == 2)
                {
                    //range
                    if (FieldTypeUtil.CheckType(sArr[0].Trim(), list.RangeListType) == false)
                    {
                        throw new ArgumentException(string.Format("Item not valid. Can't convert {0} to {1}", sArr[0], list.RangeListType));
                    }
                    else if (FieldTypeUtil.CheckType(sArr[1].Trim(), list.RangeListType) == false)
                    {
                        throw new ArgumentException(string.Format("Item not valid. Can't convert {0} to {1}", sArr[1], list.RangeListType));
                    }
                    else if (FieldTypeUtil.Compare(sArr[0], sArr[1], list.RangeListType) > 0)
                    {
                        throw new ArgumentException("Item not valid. In a range x thru y, x must be less than or equal to y.");
                    }
                    else
                    {
                        MinVal = sArr[0];
                        MaxVal = sArr[1];
                    }
                }
                else
                {
                    //must have 1 or 2 items
                    throw new ArgumentException("Item not valid.");
                }
            }