예제 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="value"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public static object ToAny(object value, Type type)
        {
            switch (type.Name)
            {
            case "Boolean":
                return(DbDataConvert.ToBoolean(value));

            case "Byte":
                return(DbDataConvert.ToByte(value));

            case "Byte[]":
                return(DbDataConvert.ToByteArray(value));

            case "Char":
                return(DbDataConvert.ToChar(value));

            case "DateTime":
                return(DbDataConvert.ToDateTime(value));

            case "Decimal":
                return(DbDataConvert.ToDecimal(value));

            case "Double":
                return(DbDataConvert.ToDouble(value));

            case "Single":
                return(DbDataConvert.ToFloat(value));

            case "Int32":
                return(DbDataConvert.ToInt(value));

            case "Int64":
                return(DbDataConvert.ToLong(value));

            case "Int16":
                return(DbDataConvert.ToShort(value));

            case "String":
                return(DbDataConvert.ToString(value));

            case "UInt32":
                return(DbDataConvert.ToUInt(value));

            case "UInt64":
                return(DbDataConvert.ToULong(value));

            case "UInt16":
                return(DbDataConvert.ToUShort(value));

            case "Guid":
                return(DbDataConvert.ToGuid(value));
            }
            return(value);
        }
예제 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="dataObject"></param>
        /// <param name="parameterName"></param>
        /// <param name="value"></param>
        public static void SetParameterValue(object dataObject, string parameterName, object value)
        {
            PropertyDescriptor property =
                ObjectHelper.FindPropertyByParameter(dataObject.GetType(), parameterName);

            if (property != null)
            {
                property.SetValue(dataObject, DbDataConvert.ToAny(value, property.PropertyType));
            }
            else
            {
                throw ParameterNotExists(parameterName, dataObject.GetType());
            }
        }
예제 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="dataObject"></param>
        /// <param name="value"></param>
        public static void SetPrimaryFieldValue(object dataObject, object value)
        {
            PropertyDescriptor property =
                ObjectHelper.FindPrimaryProperty(dataObject.GetType());

            if (property != null)
            {
                property.SetValue(dataObject, DbDataConvert.ToAny(value, property.PropertyType));
            }
            else
            {
                throw PrimaryNotExists(dataObject.GetType());
            }
        }
예제 #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="dataObject"></param>
        /// <param name="fieldName"></param>
        /// <param name="value"></param>
        public static void SetFieldValue(object dataObject, string fieldName, object value)
        {
            PropertyDescriptor property =
                ObjectHelper.FindPropertyByField(dataObject.GetType(), fieldName);

            if (property != null)
            {
                property.SetValue(dataObject, DbDataConvert.ToAny(value, property.PropertyType));
            }
            else
            {
                throw FieldNotExists(fieldName, dataObject.GetType());
            }
        }
예제 #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="tableName"></param>
        /// <returns></returns>
        public virtual bool IsTableEmpty(string tableName)
        {
            string __sql = string.Format("select count(*) from {0}", tableName);

            using (IDbConnection __connection = this.CreateConnection()) {
                __connection.ConnectionString = DataAccess.ConnectionStringSettings[this.ConnectionName].ConnectionString;
                __connection.Open();
                try {
                    using (IDbCommand __command = this.CreateCommand(__sql, CommandType.Text, __connection)) {
                        __command.CommandType = CommandType.Text;
                        return(DbDataConvert.ToInt(__command.ExecuteScalar()) == 0);
                    }
                }
                finally {
                    try {
                        __connection.Close();
                    }
                    catch { }
                }
            }
        }
 /// <summary>
 /// Executes the scalar.
 /// </summary>
 /// <returns></returns>
 public T ExecuteScalar <T>()
 {
     return(DbDataConvert.To <T>(ExecuteScalar()));
 }