Ejemplo n.º 1
0
        public void Parse()
        {
            try {
                SqlInt16.Parse(null);
                Assert.Fail("Test#1");
            } catch (ArgumentNullException e) {
                Assert.AreEqual(typeof(ArgumentNullException), e.GetType(), "Test#2");
            }

            try {
                SqlInt16.Parse("not-a-number");
                Assert.Fail("Test#3");
            } catch (FormatException e) {
                Assert.AreEqual(typeof(FormatException), e.GetType(), "Test#4");
            }

            try {
                int OverInt = (int)SqlInt16.MaxValue + 1;
                SqlInt16.Parse(OverInt.ToString());
                Assert.Fail("Test#5");
            } catch (OverflowException e) {
                Assert.AreEqual(typeof(OverflowException), e.GetType(), "Test#6");
            }

            Assert.AreEqual((short)150, SqlInt16.Parse("150").Value, "Test#7");
        }
Ejemplo n.º 2
0
        public void Parse()
        {
            try
            {
                SqlInt16.Parse(null);
                Assert.False(true);
            }
            catch (ArgumentNullException e)
            {
                Assert.Equal(typeof(ArgumentNullException), e.GetType());
            }

            try
            {
                SqlInt16.Parse("not-a-number");
                Assert.False(true);
            }
            catch (FormatException e)
            {
                Assert.Equal(typeof(FormatException), e.GetType());
            }

            try
            {
                int OverInt = (int)SqlInt16.MaxValue + 1;
                SqlInt16.Parse(OverInt.ToString());
                Assert.False(true);
            }
            catch (OverflowException e)
            {
                Assert.Equal(typeof(OverflowException), e.GetType());
            }

            Assert.Equal((short)150, SqlInt16.Parse("150").Value);
        }
Ejemplo n.º 3
0
        public void Parse()
        {
            Assert.Throws <ArgumentNullException>(() => SqlInt16.Parse(null));

            Assert.Throws <FormatException>(() => SqlInt16.Parse("not-a-number"));

            Assert.Throws <OverflowException>(() => SqlInt16.Parse(((int)SqlInt16.MaxValue + 1).ToString()));

            Assert.Equal((short)150, SqlInt16.Parse("150").Value);
        }
Ejemplo n.º 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="s"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public static PInt16 Parse(string s, PValueType type)
        {
            PInt16 sp;

            if (string.IsNullOrEmpty(s))
            {
                sp = new PInt16(type);
            }
            else
            {
                sp = SqlInt16.Parse(s);
            }

            return(sp);
        }
Ejemplo n.º 5
0
        public static PInt16 Parse(string s, PValueType type)
        {
            var sp = string.IsNullOrEmpty(s) ? new PInt16(type) : SqlInt16.Parse(s);

            return(sp);
        }
Ejemplo n.º 6
0
        public static SqlInt16RegularArray Parse(SqlString s)
        {
            if (s.IsNull)
            {
                return(Null);
            }

            return(new SqlInt16RegularArray(SqlFormatting.ParseRegular <Int16?>(s.Value,
                                                                                t => !t.Equals(SqlFormatting.NullText, StringComparison.InvariantCultureIgnoreCase) ? SqlInt16.Parse(t).Value : default(Int16?))));
        }
Ejemplo n.º 7
0
 public override object FromStringValue(string xml)
 {
     return(SqlInt16.Parse(xml));
 }
Ejemplo n.º 8
0
        List <Tag> SelectTags(string oldid)
        {
            if (oldid.Length > 0)
            {
                string    sql    = "select siteid from tblsite where oldid='" + oldid.Split('-')[1] + "' and state like '" + oldid.Split('-')[0] + "'";
                DataTable tbl    = data.GetData(sql);
                int       siteid = int.Parse(tbl.Rows[0][0].ToString());

                List <Tag> resultList = new List <Tag>();

                foreach (var config in _configs)
                {
                    if (!config.IsSelected)
                    {
                        continue;
                    }

                    int index = _configs.IndexOf(config);

                    DateTime _start = default(DateTime);
                    DateTime _end   = default(DateTime);
                    if (!UseDateRange)
                    {
                        _start = DateTime.Parse(ConfigDates[index][0].ToShortDateString() + " 00:00:00");
                        _end   = DateTime.Parse(ConfigDates[index][1].ToShortDateString() + " 00:00:00");
                    }
                    else
                    {
                        _start = start;
                        _end   = end;
                    }
                    sql = "exec procsitecomp '" + _start.ToShortDateString() + "','" + _end.ToShortDateString() + "'," + siteid;

                    tbl = data.GetData(sql);

                    double   height      = 0.0;
                    double   orientation = 0.0;
                    SqlInt16 sensortype  = 0;

                    foreach (DataRow dr in tbl.Rows)
                    {
                        string temp = dr[4].ToString();
                        if (temp.Length > 0)
                        {
                            height = double.Parse(temp);
                        }

                        temp = dr[5].ToString().Replace("°", "");
                        if (temp.Length > 0)
                        {
                            orientation = double.Parse(temp);
                        }

                        temp = dr["comptypeid"].ToString();
                        if (temp.Length > 0)
                        {
                            sensortype = SqlInt16.Parse(temp);
                        }

                        sql = "select pitag from tblpitag pt join tblscvpitag scvp on scvp.pitagid=pt.pitagid where sitecompversid=" + dr["SiteCompVersID"].ToString();
                        tbl = data.GetData(sql);
                        if (tbl != null)
                        {
                            foreach (DataRow drow in tbl.Rows)
                            {
                                Tag tag = new Tag(drow["PiTag"].ToString(), _start, _end)
                                {
                                    Height = height, Orientation = orientation, SensorType = sensortype
                                };
                                resultList.Add(tag);
                            }
                        }
                    }
                }
                //select only tags from the list that the user wants
                var finalResult = from tag in resultList
                                  where tag.TagNameElement(4).Equals(_selectedDataType)
                                  select tag;

                return(finalResult.DefaultIfEmpty().ToList());
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 9
0
        private bool CheckColumnValue(ref StringBuilder value)
        {
            long curline = lines + 1;

            if (value.Length == 0 || value.ToString().ToUpper() == globals.nullstr)
            {
                if (globals.Columns[curcol].Nullable == true)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            switch (globals.Columns[curcol].Type)
            {
            case "char":
            case "nchar":
            case "varchar":
            case "nvarchar":
                if (globals.Columns[curcol].Length != -1 && value.Length > globals.Columns[curcol].Length)
                {
                    return(OutputValueErrMsg(ref value, "String truncation", "\0x1A"));
                }
                break;

            case "int":
                try
                {
                    SqlInt32 i = SqlInt32.Parse(value.ToString());
                }
                catch (Exception e)
                {
                    return(OutputValueErrMsg(ref value, e.Message, "-28"));
                }
                break;

            case "bigint":
                try
                {
                    SqlInt64 i = SqlInt64.Parse(value.ToString());
                }
                catch (Exception e)
                {
                    return(OutputValueErrMsg(ref value, e.Message, "-28"));
                }
                break;

            case "tinyint":
                try
                {
                    SqlByte i = SqlByte.Parse(value.ToString());
                }
                catch (Exception e)
                {
                    return(OutputValueErrMsg(ref value, e.Message, "28"));
                }
                break;

            case "smallint":
                try
                {
                    SqlInt16 i = SqlInt16.Parse(value.ToString());
                }
                catch (Exception e)
                {
                    return(OutputValueErrMsg(ref value, e.Message, "-28"));
                }
                break;

            case "numeric":
            case "decimal":
                try
                {
                    // SqlDecimal d = SqlDecimal.Parse(value.ToString());       // for very large values this may work, while .Net decimal overflows
                    decimal d = decimal.Parse(value.ToString());                    // the DataTable uses .Net types, so overflows will cause exceptions in outer loop
                }
                catch (Exception e)
                {
                    return(OutputValueErrMsg(ref value, e.Message, "-28.28"));
                }
                break;

            case "float":
            case "real":
                try
                {
                    SqlSingle s = SqlSingle.Parse(value.ToString());
                }
                catch (Exception e)
                {
                    return(OutputValueErrMsg(ref value, e.Message, "-28.28"));
                }
                break;

            case "datetime":
            case "datetime2":
            case "smalldatetime":
                try
                {
                    if (Convert.ToInt32(value.ToString().Substring(0, 4)) < (globals.Columns[curcol].Type == "datetime" ? 1753 : (globals.Columns[curcol].Type == "datetime2" ? 1 : 1900)))
                    {
                        return(OutputValueErrMsg(ref value, "Year value is too small", null));
                    }
                    int dot = value.ToString().IndexOf(".");
                    if (dot > 0)                                                                        // fractional seconds given?
                    {
                        if (globals.Columns[curcol].Type == "smalldatetime")                            // strip fractional seconds off smalldatetime
                        {
                            string tmp = value.ToString();
                            value.Clear();
                            value.Append(tmp.Substring(0, tmp.IndexOf('.')));
                        }
                        else
                        {
                            if (value.Length - dot > 3)
                            {
                                string tmp = value.ToString();
                                value.Clear();
                                value.Append(tmp.Substring(0, dot + 3));                                // limitation here is .NET datetime - in theory this could be a datetime2(1), which would fail...
                            }
                        }
                    }
                    SqlDateTime dt = SqlDateTime.Parse(value.ToString());
                }
                catch (Exception e)
                {
                    return(OutputValueErrMsg(ref value, e.Message, null));
                }
                break;

            case "date":
            case "time":
                try
                {
                    DateTime d = DateTime.Parse(value.ToString());
                }
                catch (Exception e)
                {
                    return(OutputValueErrMsg(ref value, e.Message, null));
                }
                break;

            case "uniqueidentifier":
                try
                {
                    SqlGuid u = SqlGuid.Parse(value.ToString());
                }
                catch (Exception e)
                {
                    return(OutputValueErrMsg(ref value, e.Message, "00000000-0000-0000-0000-000000000000"));
                }
                break;

            case "bit":
                try
                {
                    SqlBoolean u = SqlBoolean.Parse(value.ToString());
                }
                catch (Exception e)
                {
                    return(OutputValueErrMsg(ref value, e.Message, "0"));
                }
                break;
            }
            return(true);
        }
Ejemplo n.º 10
0
    public static SqlBoolean InitMethod([SqlFacet(MaxSize = -1)] SqlString sqlDataValue, SqlString sqlDataType)
    {
        String          dataValue     = sqlDataValue.ToString().Trim();
        String          dataType      = sqlDataType.ToString().Trim();
        GroupCollection typeGroups    = splitType.Match(dataType).Groups;
        String          typeText      = typeGroups["type"].Value;
        String          typePrecision = typeGroups["precision"].Value;
        String          typeScale     = typeGroups["scale"].Value;

        try {
            switch (typeText.ToLower())
            {
            case "bit":
                SqlBoolean.Parse(dataValue);
                break;

            case "tinyint":
                SqlByte.Parse(dataValue);
                break;

            case "smallint":
                SqlInt16.Parse(dataValue);
                break;

            case "int":
                SqlInt32.Parse(dataValue);
                break;

            case "bigint":
                SqlInt64.Parse(dataValue);
                break;

            case "smallmoney":
                if (NumberOfDecimals(dataValue) > 4)
                {
                    throw new OverflowException();
                }
                SqlMoney smallmoneyValue = SqlMoney.Parse(dataValue);
                if (SqlMoney.LessThan(smallmoneyValue, smallmoneyMinValue) || SqlMoney.GreaterThan(smallmoneyValue, smallmoneyMaxValue))
                {
                    throw new OverflowException();
                }
                break;

            case "money":
                if (NumberOfDecimals(dataValue) > 4)
                {
                    throw new OverflowException();
                }
                SqlMoney.Parse(dataValue);
                break;

            case "decimal":
            case "numeric":
                if (NumberOfDecimals(dataValue) > Convert.ToInt32(typeScale))
                {
                    throw new OverflowException();
                }
                SqlDecimal.Parse(dataValue);
                break;

            case "real":
                SqlSingle singleValue = SqlSingle.Parse(dataValue);
                if (singleValue.ToString().Length != dataValue.Length + (NumberOfWholes(dataValue) == 0 ? 1 : 0))
                {
                    throw new OverflowException();
                }
                break;

            case "float":
                SqlDouble doubleValue = SqlDouble.Parse(dataValue);
                if (doubleValue.ToString().Length != dataValue.Length + (NumberOfWholes(dataValue) == 0 ? 1 : 0))
                {
                    throw new OverflowException();
                }
                break;

            case "date":
            case "datetime":
            case "datetime2":
                SqlDateTime.Parse(dataValue);
                break;

            case "char":
            case "varchar":
            case "nchar":
            case "nvarchar":
                if (typePrecision != "max" && dataValue.Length > Convert.ToInt32(typePrecision))
                {
                    throw new OverflowException();
                }
                break;

            case "uniqueidentifier":
                SqlGuid.Parse(dataValue);
                break;

            case "geometry":
                SqlGeometry.Parse(dataValue);
                break;

            case "geography":
                SqlGeography.Parse(dataValue);
                break;

            // we do not handle these at this time
            case "xml":
            case "time":
            case "datetimeoffset":
            case "hierarchyid":
            case "image":
            case "text":
            case "ntext":
            case "rowversion":
            case "sql_variant":
            case "table":
            case "timestamp":
            case "varbinary":
            default:
                break;
            }
            return(SqlBoolean.True);
        }
        catch {
            return(SqlBoolean.False);
        }
    }