public long ExecDataTableLng(IDbCommand command)
        {
            DataTable dtt = ExecDataTable(command);

            if ((dtt == null) || (dtt.Rows.Count < 1))
            {
                return(0);
            }
            else
            {
                return(GConv.DbToLong(dtt.Rows[0][0]));
            }
        }
        public string ExecDataTableStr(IDbCommand command)
        {
            DataTable dtt = ExecDataTable(command);

            if ((dtt == null) || (dtt.Rows.Count < 1))
            {
                return(string.Empty);
            }
            else
            {
                return(GConv.DbToStr(dtt.Rows[0][0]));
            }
        }
        public int ExecDataTableInt(IDbCommand command)
        {
            DataTable dtt = ExecDataTable(command);

            if ((dtt == null) || (dtt.Rows.Count < 1))
            {
                return(0);
            }
            else
            {
                return(GConv.DbToInt(dtt.Rows[0][0]));
            }
        }
        public Guid ExecDataTableGid(IDbCommand command)
        {
            DataTable dtt = ExecDataTable(command);

            if ((dtt == null) || (dtt.Rows.Count < 1))
            {
                return(Guid.Empty);
            }
            else
            {
                return(GConv.DbToGid(dtt.Rows[0][0]));
            }
        }
        public DateTime ExecDataTableDt(IDbCommand command)
        {
            DataTable dtt = ExecDataTable(command);

            if ((dtt == null) || (dtt.Rows.Count < 1))
            {
                return(DateTime.MinValue);
            }
            else
            {
                return(GConv.DbToDt(dtt.Rows[0][0]));
            }
        }
        public decimal ExecDataTableDec(IDbCommand command)
        {
            DataTable dtt = ExecDataTable(command);

            if ((dtt == null) || (dtt.Rows.Count < 1))
            {
                return(0);
            }
            else
            {
                return(GConv.DbToDec(dtt.Rows[0][0]));
            }
        }
        public bool ExecDataTableBln(IDbCommand command)
        {
            DataTable dtt = ExecDataTable(command);

            if ((dtt == null) || (dtt.Rows.Count < 1))
            {
                return(false);
            }
            else
            {
                return(GConv.DbToBln(dtt.Rows[0][0]));
            }
        }
        public string ExecScalarStr(IDbCommand command)
        {
            string result = string.Empty;

            if (_auto_open_close)
            {
                Open();
            }
            command.Connection     = _connection;
            command.CommandTimeout = _command_timeout;
            result = GConv.DbToStr(command.ExecuteScalar());
            if (_auto_open_close)
            {
                Close();
            }
            return(result);
        }
        public long ExecScalarLng(IDbCommand command)
        {
            long result = 0;

            if (_auto_open_close)
            {
                Open();
            }
            command.Connection     = _connection;
            command.CommandTimeout = _command_timeout;
            result = GConv.DbToLong(command.ExecuteScalar());
            if (_auto_open_close)
            {
                Close();
            }
            return(result);
        }
        public int ExecScalarInt(IDbCommand command)
        {
            int result = 0;

            if (_auto_open_close)
            {
                Open();
            }
            command.Connection     = _connection;
            command.CommandTimeout = _command_timeout;
            result = GConv.DbToInt(command.ExecuteScalar());
            if (_auto_open_close)
            {
                Close();
            }
            return(result);
        }
        public Guid ExecScalarGid(IDbCommand command)
        {
            Guid result = Guid.Empty;

            if (_auto_open_close)
            {
                Open();
            }
            command.Connection     = _connection;
            command.CommandTimeout = _command_timeout;
            result = GConv.DbToGid(command.ExecuteScalar());
            if (_auto_open_close)
            {
                Close();
            }
            return(result);
        }
        public decimal ExecScalarDec(IDbCommand command)
        {
            Decimal result = 0;

            if (_auto_open_close)
            {
                Open();
            }
            command.Connection     = _connection;
            command.CommandTimeout = _command_timeout;
            result = GConv.DbToDec(command.ExecuteScalar());
            if (_auto_open_close)
            {
                Close();
            }
            return(result);
        }
        public bool ExecScalarBln(IDbCommand command)
        {
            bool result = false;

            if (_auto_open_close)
            {
                Open();
            }
            command.Connection     = _connection;
            command.CommandTimeout = _command_timeout;
            result = GConv.DbToBln(command.ExecuteScalar());
            if (_auto_open_close)
            {
                Close();
            }
            return(result);
        }
示例#14
0
        public static bool ObjectFromDataRow(object data, DataRow dr, bool include_underscores = false)
        {
            bool result   = true;
            Type dataType = data.GetType();

            PropertyInfo[] arrPropertyInfos = dataType.GetProperties();
            foreach (PropertyInfo dataPropertyInfo in arrPropertyInfos)
            {
                Type   tmpType = dataPropertyInfo.PropertyType;
                string tmpName = dataPropertyInfo.Name;
                if (tmpName.StartsWith("_") && (!include_underscores))
                {
                    continue;
                }
                if (!dr.Table.Columns.Contains(tmpName))
                {
                    continue;
                }
                if (tmpName.StartsWith("sync_ts"))
                {
                    dataPropertyInfo.SetValue(data, GConv.DbTsToLong(dr[tmpName]), null);
                    continue;
                }
                if (tmpType == typeof(string))
                {
                    dataPropertyInfo.SetValue(data, GConv.DbToStr(dr[tmpName]), null);
                }
                else if (tmpType == typeof(bool))
                {
                    dataPropertyInfo.SetValue(data, GConv.DbToBln(dr[tmpName]), null);
                }
                else if (tmpType == typeof(Byte))
                {
                    dataPropertyInfo.SetValue(data, GConv.DbToByte(dr[tmpName]), null);
                }
                else if (tmpType == typeof(Byte?))
                {
                    dataPropertyInfo.SetValue(data, GConv.DbToByteNull(dr[tmpName]), null);
                }
                else if (tmpType == typeof(Int16))
                {
                    dataPropertyInfo.SetValue(data, GConv.DbToShort(dr[tmpName]), null);
                }
                else if (tmpType == typeof(Int16?))
                {
                    dataPropertyInfo.SetValue(data, GConv.DbToShortNull(dr[tmpName]), null);
                }
                else if (tmpType == typeof(Int32))
                {
                    dataPropertyInfo.SetValue(data, GConv.DbToInt(dr[tmpName]), null);
                }
                else if (tmpType == typeof(Int32?))
                {
                    dataPropertyInfo.SetValue(data, GConv.DbToIntNull(dr[tmpName]), null);
                }
                else if (tmpType == typeof(Int64))
                {
                    dataPropertyInfo.SetValue(data, GConv.DbToLong(dr[tmpName]), null);
                }
                else if (tmpType == typeof(Int64?))
                {
                    dataPropertyInfo.SetValue(data, GConv.DbToLongNull(dr[tmpName]), null);
                }
                else if (tmpType == typeof(Single))
                {
                    dataPropertyInfo.SetValue(data, GConv.DbToFloat(dr[tmpName]), null);
                }
                else if (tmpType == typeof(Single?))
                {
                    dataPropertyInfo.SetValue(data, GConv.DbToFloatNull(dr[tmpName]), null);
                }
                else if (tmpType == typeof(Double))
                {
                    dataPropertyInfo.SetValue(data, GConv.DbToDbl(dr[tmpName]), null);
                }
                else if (tmpType == typeof(Double?))
                {
                    dataPropertyInfo.SetValue(data, GConv.DbToDblNull(dr[tmpName]), null);
                }
                else if (tmpType == typeof(Decimal))
                {
                    dataPropertyInfo.SetValue(data, GConv.DbToDec(dr[tmpName]), null);
                }
                else if (tmpType == typeof(Decimal?))
                {
                    dataPropertyInfo.SetValue(data, GConv.DbToDecNull(dr[tmpName]), null);
                }
                else if (tmpType == typeof(DateTime))
                {
                    dataPropertyInfo.SetValue(data, GConv.DbToDt(dr[tmpName]), null);
                }
                else if (tmpType == typeof(DateTime?))
                {
                    dataPropertyInfo.SetValue(data, GConv.DbToDtNull(dr[tmpName]), null);
                }
                else if (tmpType == typeof(Guid))
                {
                    dataPropertyInfo.SetValue(data, GConv.DbToGid(dr[tmpName]), null);
                }
                else
                {
                    throw new Exception("ObjectFromDataRow type not supported!");
                }
            }
            return(result);
        }