Example #1
0
        /// <summary>
        /// Counts the number of orders for given search criteria
        /// </summary>
        /// <param name="criteria">The search criteria for orders to search</param>
        /// <returns>The number of orders for given search criteria</returns>
        public static int SearchCount(OrderSearchCriteria criteria)
        {
            //COUNT ORDER IDS THAT FIT THE CRITERIA
            Database  database     = Token.Instance.Database;
            DbCommand countCommand = criteria.BuildSelectCommand(string.Empty, true);

            return(AlwaysConvert.ToInt(database.ExecuteScalar(countCommand)));
        }
Example #2
0
        public OrderCollection Search(OrderSearchCriteria criteria, int maximumRows, int startRowIndex, string sortExpression)
        {
            //CREATE RETURN SET
            OrderCollection orders = new OrderCollection();

            //GET LIST OF ORDER IDS THAT FIT THE CRITERIA
            Database   database      = Token.Instance.Database;
            DbCommand  selectCommand = criteria.BuildSelectCommand(sortExpression);
            List <int> orderIdList   = new List <int>();

            //EXECUTE THE COMMAND TO OBTAIN ORDER ID List
            using (IDataReader dr = database.ExecuteReader(selectCommand))
            {
                while (dr.Read())
                {
                    orderIdList.Add(dr.GetInt32(0));
                }
                dr.Close();
            }

            //NOW GET ORDER DETAIL FOR CORRECT INDEXES
            int rowIndex = startRowIndex;
            int rowCount = 0;

            if (maximumRows < 1)
            {
                maximumRows = 1000;
            }
            while ((rowCount < maximumRows) && (rowIndex < orderIdList.Count))
            {
                Order order = OrderDataSource.Load(orderIdList[rowIndex]);
                orders.Add(order);
                rowIndex++;
                rowCount++;
            }

            //RETURN ORDER DETAIL MATCHING CRITERIA
            return(orders);
        }