public static ManufacturerCollection LoadForStore(int maximumRows, int startRowIndex, string sortExpression)
        {
            int storeId = Token.Instance.StoreId;
            //CREATE THE DYNAMIC SQL TO LOAD OBJECT
            StringBuilder selectQuery = new StringBuilder();

            selectQuery.Append("SELECT");
            if (maximumRows > 0)
            {
                selectQuery.Append(" TOP " + (startRowIndex + maximumRows).ToString());
            }
            selectQuery.Append(" " + Manufacturer.GetColumnNames(string.Empty));
            selectQuery.Append(" FROM ac_Manufacturers");
            selectQuery.Append(" WHERE StoreId = @storeId");
            if (!string.IsNullOrEmpty(sortExpression))
            {
                selectQuery.Append(" ORDER BY " + sortExpression);
            }
            Database  database      = Token.Instance.Database;
            DbCommand selectCommand = database.GetSqlStringCommand(selectQuery.ToString());

            database.AddInParameter(selectCommand, "@storeId", System.Data.DbType.Int32, storeId);
            //EXECUTE THE COMMAND
            ManufacturerCollection results = new ManufacturerCollection();
            int thisIndex = 0;
            int rowCount  = 0;

            using (IDataReader dr = database.ExecuteReader(selectCommand))
            {
                while (dr.Read() && ((maximumRows < 1) || (rowCount < maximumRows)))
                {
                    if (thisIndex >= startRowIndex)
                    {
                        Manufacturer manufacturer = new Manufacturer();
                        Manufacturer.LoadDataReader(manufacturer, dr);
                        results.Add(manufacturer);
                        rowCount++;
                    }
                    thisIndex++;
                }
                dr.Close();
            }
            return(results);
        }
        public static ManufacturerCollection FindManufacturersByName(string searchPattern, int maximumRows, int startRowIndex, string sortExpression)
        {
            ManufacturerCollection manufacturerCollection = new ManufacturerCollection();

            searchPattern = StringHelper.FixSearchPattern(searchPattern, false).ToLowerInvariant();
            //CREATE THE DYNAMIC SQL TO LOAD OBJECT
            string whereClause;

            if (!string.IsNullOrEmpty(searchPattern))
            {
                whereClause = " WHERE LOWER(M.Name) LIKE @searchPattern ";
            }
            else
            {
                whereClause = string.Empty;
            }
            StringBuilder selectQuery = new StringBuilder();

            selectQuery.Append("SELECT");
            if (maximumRows > 0)
            {
                selectQuery.Append(" TOP " + (startRowIndex + maximumRows).ToString());
            }
            selectQuery.Append(" M.ManufacturerId AS ManufacturerId");
            selectQuery.Append(" FROM ac_Manufacturers M ");

            if (!String.IsNullOrEmpty(sortExpression) && sortExpression.Contains("COUNT(P.ProductId)"))
            {
                selectQuery.Append(" LEFT OUTER JOIN ac_Products P ");
                selectQuery.Append(" ON M.ManufacturerId = P.ManufacturerId ");
                selectQuery.Append(whereClause);
                selectQuery.Append(" GROUP BY M.ManufacturerId ");
                selectQuery.Append(" ORDER BY " + sortExpression);
            }
            else
            if (!String.IsNullOrEmpty(sortExpression))
            {
                selectQuery.Append(whereClause);
                selectQuery.Append(" ORDER BY " + sortExpression);
            }
            else
            {
                selectQuery.Append(whereClause);
            }
            Database  database      = Token.Instance.Database;
            DbCommand selectCommand = database.GetSqlStringCommand(selectQuery.ToString());

            if (!string.IsNullOrEmpty(searchPattern))
            {
                database.AddInParameter(selectCommand, "searchPattern", DbType.String, searchPattern);
            }
            //EXECUTE THE COMMAND
            int thisIndex = 0;
            int rowCount  = 0;

            using (IDataReader dr = database.ExecuteReader(selectCommand))
            {
                while (dr.Read() && ((maximumRows < 1) || (rowCount < maximumRows)))
                {
                    if (thisIndex >= startRowIndex)
                    {
                        Manufacturer manufacturer = null;
                        manufacturer = ManufacturerDataSource.Load(AlwaysConvert.ToInt(dr["ManufacturerId"]));
                        if (manufacturer != null)
                        {
                            manufacturerCollection.Add(manufacturer);
                        }
                        rowCount++;
                    }
                    thisIndex++;
                }
                dr.Close();
            }
            return(manufacturerCollection);
        }