コード例 #1
0
 public static Manufacturer Load(Int32 manufacturerId)
 {
     return(ManufacturerDataSource.Load(manufacturerId, true));
 }
コード例 #2
0
        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);
        }