Exemplo n.º 1
0
        /// <summary>
        /// 自动形成条件和赋值
        /// </summary>
        /// <typeparam name="TEnty"></typeparam>
        /// <param name="tablename">物理表</param>
        /// <param name="keyfield">字段值</param>
        /// <param name="pageindex">分页索引</param>
        /// <param name="pagesize">分页大小</param>
        /// <param name="wList">参数和条件列表</param>
        /// <param name="strorder"></param>
        /// <param name="sqlCol">SQL列</param>
        /// <param name="fieldlist"></param>
        /// <param name="total">总数</param>
        /// <returns></returns>
        protected IList <TEnty> GetListByPage <TEnty>(string procedure, string tablename, string PrimaryKey, string Sort, int CurrentPage, int pagesize, string Fields, string Filter, string Group, string fieldlist, out int total) where TEnty : new()
        {
            string[] Params = new string[8] {
                tablename, PrimaryKey, Sort, CurrentPage.ToString(), pagesize.ToString(), Fields, Filter, Group
            };
            LogInfo(procedure);
            DbCommand dbCommand = db.GetSqlStringCommand(procedure);

            dbCommand.CommandType = CommandType.StoredProcedure;
            dbCommand.Parameters.AddRange(SQLProcedures.GetParameter(procedure, Params));
            IList <TEnty> infoList = new List <TEnty>();

            using (IDataReader dataReader = db.ExecuteReader(dbCommand))
            {
                Dictionary <string, string> cachUserNameMaping = new Dictionary <string, string>();
                while (dataReader.Read())
                {
                    TEnty info = new TEnty();
                    GetEnty <TEnty>(dataReader, fieldlist.Replace("[", "").Replace("]", "").Replace("\r\n", ""), ref info, cachUserNameMaping);
                    infoList.Add(info);
                }
            }
            total = infoList.Count;
            return(infoList);
        }