Beispiel #1
0
        /// <summary>
        /// Load all valid order statuses.
        /// </summary>
        /// <returns>The collection of order statuses marked valid.</returns>
        public static OrderStatusCollection LoadValidOrderStatuses()
        {
            int storeId = Token.Instance.StoreId;
            OrderStatusCollection statuses    = new OrderStatusCollection();
            StringBuilder         selectQuery = new StringBuilder();

            selectQuery.Append("SELECT " + OrderStatus.GetColumnNames(string.Empty));
            selectQuery.Append(" FROM ac_OrderStatuses ");
            selectQuery.Append(" WHERE StoreId = @storeId AND IsValid = 1 ");
            Database  database      = Token.Instance.Database;
            DbCommand selectCommand = database.GetSqlStringCommand(selectQuery.ToString());

            database.AddInParameter(selectCommand, "@storeId", System.Data.DbType.Int32, storeId);
            //EXECUTE THE COMMAND
            using (IDataReader dr = database.ExecuteReader(selectCommand))
            {
                while (dr.Read())
                {
                    OrderStatus orderStatus = new OrderStatus();
                    OrderStatus.LoadDataReader(orderStatus, dr);
                    statuses.Add(orderStatus);
                }
                dr.Close();
            }
            return(statuses);
        }
        public static OrderStatusCollection LoadForEmailTemplate(Int32 emailTemplateId, int maximumRows, int startRowIndex, string sortExpression)
        {
            //DEFAULT SORT EXPRESSION
            if (string.IsNullOrEmpty(sortExpression))
            {
                sortExpression = "OrderBy";
            }
            //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(" " + OrderStatus.GetColumnNames("ac_OrderStatuses"));
            selectQuery.Append(" FROM ac_OrderStatuses, ac_OrderStatusEmails");
            selectQuery.Append(" WHERE ac_OrderStatuses.OrderStatusId = ac_OrderStatusEmails.OrderStatusId");
            selectQuery.Append(" AND ac_OrderStatusEmails.EmailTemplateId = @emailTemplateId");
            selectQuery.Append(" AND StoreId = @storeId");
            selectQuery.Append(" ORDER BY " + sortExpression);
            Database  database      = Token.Instance.Database;
            DbCommand selectCommand = database.GetSqlStringCommand(selectQuery.ToString());

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

            using (IDataReader dr = database.ExecuteReader(selectCommand))
            {
                while (dr.Read() && ((maximumRows < 1) || (rowCount < maximumRows)))
                {
                    if (thisIndex >= startRowIndex)
                    {
                        OrderStatus orderStatus = new OrderStatus();
                        OrderStatus.LoadDataReader(orderStatus, dr);
                        results.Add(orderStatus);
                        rowCount++;
                    }
                    thisIndex++;
                }
                dr.Close();
            }
            return(results);
        }
        public static OrderStatusCollection  LoadForCriteria(string sqlCriteria, int maximumRows, int startRowIndex, string sortExpression)
        {
            //DEFAULT SORT EXPRESSION
            if (string.IsNullOrEmpty(sortExpression))
            {
                sortExpression = "OrderBy";
            }
            //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(" " + OrderStatus.GetColumnNames(string.Empty));
            selectQuery.Append(" FROM ac_OrderStatuses");
            string whereClause = string.IsNullOrEmpty(sqlCriteria) ? string.Empty : " WHERE " + sqlCriteria;

            selectQuery.Append(whereClause);
            selectQuery.Append(" ORDER BY " + sortExpression);
            Database  database      = Token.Instance.Database;
            DbCommand selectCommand = database.GetSqlStringCommand(selectQuery.ToString());
            //EXECUTE THE COMMAND
            OrderStatusCollection results = new OrderStatusCollection();
            int thisIndex = 0;
            int rowCount  = 0;

            using (IDataReader dr = database.ExecuteReader(selectCommand))
            {
                while (dr.Read() && ((maximumRows < 1) || (rowCount < maximumRows)))
                {
                    if (thisIndex >= startRowIndex)
                    {
                        OrderStatus orderStatus = new OrderStatus();
                        OrderStatus.LoadDataReader(orderStatus, dr);
                        results.Add(orderStatus);
                        rowCount++;
                    }
                    thisIndex++;
                }
                dr.Close();
            }
            return(results);
        }
		private static OrderStatusCollection DBMapping(DBOrderStatusCollection dbCollection)
		{
			if (dbCollection == null)
				return null;

			OrderStatusCollection collection = new OrderStatusCollection();
			foreach (DBOrderStatus dbItem in dbCollection)
			{
				OrderStatus item = DBMapping(dbItem);
				collection.Add(item);
			}

			return collection;
		}