Exemple #1
0
        /// <summary>
        /// 根据某个表名查询实体集合(分页)
        /// </summary>
        /// <typeparam name="T">泛型类型</typeparam>
        /// <param name="strTableName">属性名称</param>
        /// <param name="fieldShow">属性名称</param>
        /// <param name="pageSize">属性名称</param>
        /// <param name="currentPageIndex">属性名称</param>
        /// <param name="intCountPage">属性值</param>
        /// <param name="component">属性值</param>
        /// <returns></returns>
        public IList <T> GetList <T>(string strTableName, string fieldShow, int pageSize,
                                     int currentPageIndex, int intCountPage, ConditionComponent component) where T : class
        {
            IDataParameter[] param = null;

            StringBuilder sbSQL = new StringBuilder();

            sbSQL.Append(" select  ");
            sbSQL.Append(fieldShow);     //此功能暂未实现


            sbSQL.Append(" from ");
            sbSQL.Append(strTableName);

            if (component != null && component.sbComponent.Length > 0)
            {
                sbSQL.Append(" where ");

                sbSQL.Append(component.sbComponent.ToString());
            }

            intRowCount_ = int.Parse(BaseHelper.ExecuteScalar(sbSQL.ToString().Replace(fieldShow, "count(*)")).ToString());
            intPageNum_  = pageSize;
            //string strSql = Factory.CreatePageSql(typeof(T),pageSize, currentPageIndex, intCountPage, sbSQL.ToString());
            string strSql = Factory.CreatePageSql(typeof(T), pageSize, currentPageIndex, intCountPage, sbSQL.ToString());

            // return BaseHelper.Query(strSql);

            return(BaseHelper.ConvertToList <T>(BaseHelper.ExecuteDataReader(strSql, param as OracleParameter[])));
        }
Exemple #2
0
        ///// <summary>
        ///// 根据某个实体属性删除数据



        ///// 该实体必须包含指定的属性名称



        ///// 而且实体属性值不能为空



        ///// </summary>
        ///// <param name="entity">实体属性公共接口</param>
        ///// <param name="propertyName">实体属性名称</param>
        ///// <returns></returns>
        //public int Delete(IEntity entity, string propertyName)
        //{
        //    IDataParameter[] param = null;
        //    string sql = Factory.CreateDeleteSql(entity,out param,propertyName);
        //    using (IDbProvider provider = new SqlProvider())
        //    {
        //        return BaseHelper.ExecuteNonQuery( sql, param);
        //    }
        //}

        ///// <summary>
        ///// 根据实体多个属性删除数据



        ///// 实体中必须包含该属性



        ///// 传递参数数组不能为空



        ///// </summary>
        ///// <param name="entity">实体属性公共接口</param>
        ///// <param name="propertyNames">实体属性名称数组</param>
        ///// <returns></returns>
        //public int Delete(IEntity entity, string[] propertyNames)
        //{
        //    IDataParameter[] param = null;
        //    string sql = Factory.CreateDeleteSql(entity, out param, propertyNames);
        //    using (IDbProvider provider = new SqlProvider())
        //    {
        //        return BaseHelper.ExecuteNonQuery( sql, param);
        //    }
        //}

        ///// <summary>
        ///// 根据泛型类删除数据



        ///// 该方法是根据实体的主键删除的
        ///// </summary>
        ///// <typeparam name="T">泛型类</typeparam>
        ///// <param name="t">泛型实例</param>
        ///// <returns></returns>
        //public int Delete<T>(T t) where T : class
        //{
        //    IDataParameter[] param = null;
        //    string sql = Factory.CreateDeleteSql(typeof(T), t, out param);
        //    using (IDbProvider provider = new SqlProvider())
        //    {
        //        return BaseHelper.ExecuteNonQuery( sql, param);
        //    }
        //}

        ///// <summary>
        ///// 根据泛型类的某个属性删除数据



        ///// 泛型类中必须存在该属性,而且
        ///// 属性值不能为空



        ///// </summary>
        ///// <typeparam name="T">泛型类型</typeparam>
        ///// <param name="t">泛型类实例</param>
        ///// <param name="propertyName">属性名称</param>
        ///// <returns></returns>
        //public int Delete<T>(T t, string propertyName) where T : class
        //{
        //    IDataParameter[] param = null;
        //    string sql = Factory.CreateDeleteSql(typeof(T), t, out param,propertyName);
        //    using (IDbProvider provider = new SqlProvider())
        //    {
        //        return BaseHelper.ExecuteNonQuery( sql, param);
        //    }
        //}

        ///// <summary>
        ///// 根据泛型类型的多个属性删除数据



        ///// 泛型类型中必须存在这些属性,传



        ///// 递参数的时候不能为null
        ///// </summary>
        ///// <typeparam name="T">泛型类</typeparam>
        ///// <param name="t">泛型实例</param>
        ///// <param name="propertyNames">属性名称数组</param>
        ///// <returns></returns>
        //public int Delete<T>(T t, string[] propertyNames) where T : class
        //{
        //    IDataParameter[] param = null;
        //    string sql = Factory.CreateDeleteSql(typeof(T), t, out param, propertyNames);
        //    using (IDbProvider provider = new SqlProvider())
        //    {
        //        return BaseHelper.ExecuteNonQuery( sql, param);
        //    }
        //}

        ///// <summary>
        ///// 根据实体的类型删除数据。



        ///// value 中的类型由type确定
        ///// </summary>
        ///// <param name="type">实体类型</param>
        ///// <param name="value">实体对象实例</param>
        ///// <returns></returns>
        //public int Delete(Type type, object value)
        //{
        //    IDataParameter[] param = null;
        //    string sql = Factory.CreateDeleteSql(type,value,out param);
        //    using (IDbProvider provider = new SqlProvider())
        //    {
        //        return BaseHelper.ExecuteNonQuery( sql, param);
        //    }
        //}

        ///// <summary>
        ///// 根据实体的类型的某个属性删除数据。



        ///// value 中的类型由type确定
        ///// propertyName 属性名称必须在value
        ///// 对象中存在



        ///// </summary>
        ///// <param name="type">实体类型</param>
        ///// <param name="value">实体对象实例</param>
        ///// <param name="propertyName">属性名称</param>
        ///// <returns></returns>
        //public int Delete(Type type, object value, string propertyName)
        //{
        //    IDataParameter[] param = null;
        //    string sql = Factory.CreateDeleteSql(type, value, out param,propertyName);
        //    using (IDbProvider provider = new SqlProvider())
        //    {
        //        return BaseHelper.ExecuteNonQuery( sql, param);
        //    }
        //}

        ///// <summary>
        ///// 根据实体的类型的某个属性删除数据。



        ///// value 中的类型由type确定
        ///// propertyName 属性名称必须在value
        ///// 对象中存在



        ///// </summary>
        ///// <param name="type">实体类型</param>
        ///// <param name="value">实体对象实例</param>
        ///// <param name="propertyNames">属性名称数组</param>
        ///// <returns></returns>
        //public int Delete(Type type, object value, string[] propertyNames)
        //{
        //    IDataParameter[] param = null;
        //    string sql = Factory.CreateDeleteSql(type, value, out param, propertyNames);
        //    using (IDbProvider provider = new SqlProvider())
        //    {
        //        return BaseHelper.ExecuteNonQuery( sql, param);
        //    }
        //}

        /// <summary>
        /// 根据主键查询实体对象
        /// </summary>
        /// <typeparam name="T">泛型类型</typeparam>
        /// <param name="pkPropertyValue">主键值</param>
        /// <returns></returns>
        public T GetEntity <T>(object pkPropertyValue) where T : class, new()
        {
            IDataParameter[] param = null;
            string           sql   = Factory.CreateSingleSql(typeof(T), pkPropertyValue, out param);

            return(BaseHelper.ConvertToEntity <T>(BaseHelper.ExecuteDataReader(sql, param)));
        }
Exemple #3
0
        /// <summary>
        /// 根据多个属性查询实体集合


        /// 该查询方式附加查询组建


        /// </summary>
        /// <typeparam name="T">类型类</typeparam>
        /// <param name="dic">属性键值对</param>
        /// <param name="component">查询组件</param>
        /// <returns></returns>
        public IList <T> GetListTop <T>(IDictionary <string, object> dic, ConditionComponent component) where T : class
        {
            IDataParameter[] param = null;
            string           sql   = Factory.CreateQueryByPropertySql(typeof(T), dic, out param, component);

            return(BaseHelper.ConvertToList <T>(BaseHelper.ExecuteDataReader(sql, param as OracleParameter[])));
        }
Exemple #4
0
        /// <summary>
        /// 根据多个属性查询实体集合



        /// </summary>
        /// <typeparam name="T">泛型类型</typeparam>
        /// <param name="dic">实体公共接口</param>
        /// <returns></returns>
        public IList <T> GetListTop <T>(IDictionary <string, object> dic) where T : class
        {
            IDataParameter[] param = null;
            string           sql   = Factory.CreateQueryByPropertySql(typeof(T), dic, out param);

            strOrderString = "";
            return(BaseHelper.ConvertToList <T>(BaseHelper.ExecuteDataReader(sql, param)));
        }
Exemple #5
0
        /// <summary>
        /// 根据某个实体属性查询实体集合



        /// </summary>
        /// <typeparam name="T">泛型类型</typeparam>
        /// <param name="iTop">属性名称</param>
        /// <param name="strTableName">属性名称</param>
        /// <param name="component">属性值</param>
        /// <returns></returns>
        public IList <T> GetListTop <T>(int iTop, ConditionComponent component) where T : class
        {
            IDataParameter[] param    = null;
            string           strWhere = ((component == null || component.sbComponent == null) ? "" : component.sbComponent.ToString());
            string           sql      = Factory.CreateQuerySql(typeof(T), "*", strWhere, iTop);

            strOrderString = "";
            return(BaseHelper.ConvertToList <T>(BaseHelper.ExecuteDataReader(sql, param)));
        }
Exemple #6
0
        /// <summary>
        /// 根据某个表名查询实体集合(分页)
        /// </summary>
        /// <typeparam name="T">泛型类型</typeparam>
        /// <param name="strTableName">属性名称</param>
        /// <param name="fieldShow">属性名称</param>
        /// <param name="pageSize">属性名称</param>
        /// <param name="currentPageIndex">属性名称</param>
        /// <param name="intCountPage">属性值</param>
        /// <param name="component">属性值</param>
        /// <param name="isDel">是否删除0 未删除 1 已删除 2 所有</param>
        /// <returns></returns>
        public IList <T> GetList <T>(string strTableName, string fieldShow, string strKey, int pageSize,
                                     int currentPageIndex, int intCountPage, ConditionComponent component) where T : class
        {
            IDataParameter[] param = null;

            //StringBuilder sbSQL = new StringBuilder();
            //sbSQL.Append(" select  ");
            //sbSQL.Append(fieldShow);     //此功能暂未实现



            //sbSQL.Append(" from ");
            //sbSQL.Append(strTableName);

            //if (component != null && component.sbComponent.Length > 0)
            //{
            //    sbSQL.Append(" where ");

            //    sbSQL.Append(component.sbComponent.ToString());
            //}

            //intRowCount_ = int.Parse(BaseHelper.ExecuteScalar(sbSQL.ToString().Replace(fieldShow, "count(*)")).ToString());
            intPageNum_ = pageSize;
            //string strSql = Factory.CreatePageSql(typeof(T),pageSize, currentPageIndex, intCountPage, sbSQL.ToString());

            //if (isDel == 0)
            //{
            //    component.AddComponent("isnull(isdel,0)", "0", SearchComponent.Equals, SearchPad.And);
            //}
            //else if (isDel == 1)
            //{
            //    component.AddComponent("isdel", "1", SearchComponent.Equals, SearchPad.And);
            //}

            string strSql = Factory.CreatePageSql(strTableName, fieldShow, strKey,
                                                  strOrderString_, pageSize, currentPageIndex,
                                                  intCountPage, component.sbComponent.ToString(), out param);

            strOrderString_ = "";
            // return BaseHelper.Query(strSql);
            IList <T> lstRet = BaseHelper.ConvertToList <T>(BaseHelper.ExecuteDataReader(strSql, true, param));

            if (intCountPage <= 1 && (param[param.Length - 1] as SqlParameter) != null && (param[param.Length - 1] as SqlParameter).Value.ToString() != "")
            {
                intRowCount_ = Int32.Parse((param[param.Length - 1] as SqlParameter).Value.ToString());
            }
            else
            {
                intPageCount_ = intCountPage;
            }

            return(lstRet);
        }
Exemple #7
0
        ///// <summary>
        ///// 根据实体类的类型和主键值查询实体对象


        ///// 使用 type 确定实体,主键确定数据的唯


        ///// 一性


        ///// </summary>
        ///// <param name="type">实体类型</param>
        ///// <param name="pkPropertyValue">主键值</param>
        ///// <returns></returns>
        //public object GetEntity(Type type, object pkPropertyValue)
        //{
        //    IDataParameter[] param = null;
        //    string sql = Factory.CreateSingleSql(type,pkPropertyValue,out param);

        //        return SqlHelperComm.ConvertToEntity(type, BaseHelper.ExecuteDataReader(sql, param as OracleParameter[]));

        //}

        /// <summary>
        /// 根据表名和条件获取实体对象


        /// </summary>
        /// <typeparam name="T">泛型类型</typeparam>
        /// <param name="strTableName">表名</param>
        /// <param name="component">条件</param>
        /// <returns>实体</returns>
        public T GetEntity <T>(string strTableName, ConditionComponent component) where T : class, new()
        {
            IDataParameter[] param = null;
            string           sql   = string.Format("select * from {0} where rownum<2", strTableName);

            if (component != null && component.sbComponent.Length > 0)
            {
                sql += " and " + component.sbComponent.ToString();
            }

            return(BaseHelper.ConvertToEntity <T>(BaseHelper.ExecuteDataReader(sql, param as OracleParameter[])));
        }
Exemple #8
0
        /// <summary>
        /// 查询所有实体集合


        /// </summary>
        /// <typeparam name="T">泛型类型</typeparam>
        /// <param name="iTop">属性值</param>
        /// <param name="fieldShow">查询的列</param>
        /// <param name="component">属性值</param>
        /// <returns></returns>
        public IList <T> GetListTop <T>(int iTop, string fieldShow, ConditionComponent component) where T : class
        {
            string strWhere = " 1=1 ";

            if (iTop > 0)
            {
                strWhere += " and rownum<=" + iTop.ToString();
            }
            if (component != null && component.sbComponent.Length > 0)
            {
                strWhere += " and " + component.sbComponent.ToString();
            }
            string sql = Factory.CreateQuerySql(typeof(T), fieldShow, strWhere, iTop);

            return(BaseHelper.ConvertToList <T>(BaseHelper.ExecuteDataReader(sql)));
        }
Exemple #9
0
        /// <summary>
        /// 根据表名和条件获取实体对象



        /// </summary>
        /// <typeparam name="T">泛型类型</typeparam>
        /// <param name="strTableName">表名</param>
        /// <param name="component">条件</param>
        /// <returns>实体</returns>
        public T GetEntity <T>(string pkPropertyValue, ConditionComponent component) where T : class, new()
        {
            IDataParameter[] param = null;
            //string sql = string.Format("select top 1 * from {0} ", strTableName);

            string strWhere = Factory.CreateSingleSql(typeof(T), pkPropertyValue, out param);

            if (component != null && component.sbComponent.Length > 0)
            {
                strWhere += (pkPropertyValue == null && strWhere.IndexOf(" where ") < 0 ? " where " : " and ") + component.sbComponent.ToString();
            }

            if (strOrderString != null && strOrderString.Trim() != "")
            {
                strWhere       = strWhere + " order by " + strOrderString;
                strOrderString = "";
            }
            return(BaseHelper.ConvertToEntity <T>(BaseHelper.ExecuteDataReader(strWhere, param)));
        }