Ejemplo n.º 1
0
        public IList <Eyousoft_yhq.Model.ProductType> GetList(int PageSize, int PageIndex, ref int RecordCount, Eyousoft_yhq.Model.serProductType serModel, string i)
        {
            IList <Eyousoft_yhq.Model.ProductType> list = new List <Eyousoft_yhq.Model.ProductType>();


            string tableName     = "tbl_ProductType";
            string fileds        = " TypeID, TypeName , ProductID , TypeImg,TpMark,AdminName ,OrderByInt ,WebImg,XianLu";
            string orderByString = "OrderByInt desc";

            StringBuilder query = new StringBuilder();

            query.Append(" 1=1  ");

            switch (i)
            {
            case "1":
                query.Append(" and TpMark ='1'  ");
                break;

            case "0":
                query.Append(" and TpMark ='0'  ");
                break;

            default:
                break;
            }

            if (serModel != null)
            {
                if (!string.IsNullOrEmpty(serModel.TypeName) && !serModel.IsAdmin)
                {
                    query.AppendFormat(" and TypeName like '%{0}%' ", serModel.TypeName);
                }
                if (!string.IsNullOrEmpty(serModel.AdminID) && !serModel.IsAdmin)
                {
                    query.AppendFormat("  and  charindex('{0}',[AdminName])>0  ", serModel.AdminID);
                }
                if (serModel.IsAdmin && !string.IsNullOrEmpty(serModel.TypeName))
                {
                    query.AppendFormat(" and TypeName like '%{0}%' ", serModel.TypeName);
                }
                if (serModel.xianlu.HasValue)
                {
                    query.AppendFormat(" and XianLu = '{0}' ", (int)serModel.xianlu.Value);
                }
            }



            using (IDataReader dr = DbHelper.ExecuteReader1(this._db, PageSize, PageIndex, ref RecordCount, tableName, fileds, query.ToString(), orderByString, null))
            {
                while (dr.Read())
                {
                    Eyousoft_yhq.Model.ProductType model = new Eyousoft_yhq.Model.ProductType();
                    model.TypeID    = dr.GetInt32(dr.GetOrdinal("TypeID"));
                    model.ProductID = dr.IsDBNull(dr.GetOrdinal("ProductID")) ? "" : dr.GetString(dr.GetOrdinal("ProductID"));
                    model.TypeName  = dr.IsDBNull(dr.GetOrdinal("TypeName")) ? "" : dr.GetString(dr.GetOrdinal("TypeName"));
                    model.TypeImg   = dr.IsDBNull(dr.GetOrdinal("TypeImg")) ? "" : dr.GetString(dr.GetOrdinal("TypeImg"));
                    model.TpMark    = dr.IsDBNull(dr.GetOrdinal("TpMark")) ? "" : dr.GetByte(dr.GetOrdinal("TpMark")).ToString();
                    model.AdminName = dr.IsDBNull(dr.GetOrdinal("AdminName")) ? null : getStrJson(dr.GetString(dr.GetOrdinal("AdminName")));
                    model.OrderBy   = dr.IsDBNull(dr.GetOrdinal("OrderByInt")) ? 0 : dr.GetInt32(dr.GetOrdinal("OrderByInt"));
                    model.WebImg    = dr.IsDBNull(dr.GetOrdinal("WebImg")) ? "" : dr.GetString(dr.GetOrdinal("WebImg"));
                    model.xianlu    = (Eyousoft_yhq.Model.XianLu)dr.GetByte(dr.GetOrdinal("XianLu"));

                    list.Add(model);
                }
            }
            return(list);
        }