Esempio n. 1
0
        /// <summary>
        /// Converts a cell value to a bool cell
        /// </summary>
        /// <param name="AWValue"></param>
        /// <returns></returns>
        public static Cell ToBOOL(Cell Value)
        {
            if (Value.Affinity == CellAffinity.BOOL)
            {
                return(Value);
            }

            if (Value.IsNull)
            {
                return(CellValues.NullBOOL);
            }

            if (Value.BINARY == null && Value.AFFINITY == CellAffinity.BINARY)
            {
                return(CellValues.NullBOOL);
            }

            if (Value.BSTRING == null && Value.AFFINITY == CellAffinity.BSTRING)
            {
                return(CellValues.NullBOOL);
            }

            if (Value.CSTRING == null && Value.AFFINITY == CellAffinity.CSTRING)
            {
                return(CellValues.NullBOOL);
            }

            if (Value.AFFINITY == CellAffinity.EQUATION)
            {
                return(CellValues.NullBOOL);
            }

            switch (Value.AFFINITY)
            {
            case CellAffinity.BYTE:
                if (Value.BYTE != 0)
                {
                    return(CellValues.True);
                }
                else
                {
                    return(CellValues.False);
                }

            case CellAffinity.SHORT:
                if (Value.SHORT != 0)
                {
                    return(CellValues.True);
                }
                else
                {
                    return(CellValues.False);
                }

            case CellAffinity.INT:
                if (Value.INT != 0)
                {
                    return(CellValues.True);
                }
                else
                {
                    return(CellValues.False);
                }

            case CellAffinity.LONG:
                if (Value.LONG != 0)
                {
                    return(CellValues.True);
                }
                else
                {
                    return(CellValues.False);
                }

            case CellAffinity.SINGLE:
                if (Value.SINGLE != 0)
                {
                    return(CellValues.True);
                }
                else
                {
                    return(CellValues.False);
                }

            case CellAffinity.DOUBLE:
                if (Value.DOUBLE != 0)
                {
                    return(CellValues.True);
                }
                else
                {
                    return(CellValues.False);
                }

            case CellAffinity.BINARY:
                if (Value.BINARY.Length == 0)
                {
                    return(CellValues.NullBOOL);
                }
                if (Value.BINARY[0] != 0)
                {
                    return(CellValues.True);
                }
                else
                {
                    return(CellValues.False);
                }

            case CellAffinity.BSTRING:
                if (BString.CompareStrictIgnoreCase(Value.BSTRING, Cell.TRUE_BSTRING) == 0)
                {
                    Value.BOOL = true;
                }
                else if (BString.CompareStrictIgnoreCase(Value.BSTRING, Cell.FALSE_BSTRING) == 0)
                {
                    Value.BOOL = false;
                }
                else
                {
                    return(CellValues.NullBOOL);
                }
                break;

            case CellAffinity.CSTRING:
                if (StringComparer.OrdinalIgnoreCase.Compare(Value.CSTRING, Cell.TRUE_STRING) == 0)
                {
                    Value.BOOL = true;
                }
                else if (StringComparer.OrdinalIgnoreCase.Compare(Value.CSTRING, Cell.FALSE_STRING) == 0)
                {
                    Value.BOOL = false;
                }
                else
                {
                    return(CellValues.NullBOOL);
                }
                break;

            case CellAffinity.ARRAY:
                return(CellValues.NullBOOL);
            }

            return(CellValues.NullBOOL);
        }