Exemplo n.º 1
0
        public static CouponCollection LoadForShipMethod(Int32 shipMethodId, int maximumRows, int startRowIndex, string sortExpression)
        {
            //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(" " + Coupon.GetColumnNames("ac_Coupons"));
            selectQuery.Append(" FROM ac_Coupons, ac_CouponShipMethods");
            selectQuery.Append(" WHERE ac_Coupons.CouponId = ac_CouponShipMethods.CouponId");
            selectQuery.Append(" AND ac_CouponShipMethods.ShipMethodId = @shipMethodId");
            selectQuery.Append(" AND 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, "@shipMethodId", System.Data.DbType.Int32, shipMethodId);
            database.AddInParameter(selectCommand, "@storeId", System.Data.DbType.Int32, Token.Instance.StoreId);
            //EXECUTE THE COMMAND
            CouponCollection results = new CouponCollection();
            int thisIndex            = 0;
            int rowCount             = 0;

            using (IDataReader dr = database.ExecuteReader(selectCommand))
            {
                while (dr.Read() && ((maximumRows < 1) || (rowCount < maximumRows)))
                {
                    if (thisIndex >= startRowIndex)
                    {
                        Coupon coupon = new Coupon();
                        Coupon.LoadDataReader(coupon, dr);
                        results.Add(coupon);
                        rowCount++;
                    }
                    thisIndex++;
                }
                dr.Close();
            }
            return(results);
        }
Exemplo n.º 2
0
        public static CouponCollection  LoadForCriteria(string sqlCriteria, int maximumRows, int startRowIndex, string sortExpression)
        {
            //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(" " + Coupon.GetColumnNames(string.Empty));
            selectQuery.Append(" FROM ac_Coupons");
            string whereClause = string.IsNullOrEmpty(sqlCriteria) ? string.Empty : " WHERE " + sqlCriteria;

            selectQuery.Append(whereClause);
            if (!string.IsNullOrEmpty(sortExpression))
            {
                selectQuery.Append(" ORDER BY " + sortExpression);
            }
            Database  database      = Token.Instance.Database;
            DbCommand selectCommand = database.GetSqlStringCommand(selectQuery.ToString());
            //EXECUTE THE COMMAND
            CouponCollection results = new CouponCollection();
            int thisIndex            = 0;
            int rowCount             = 0;

            using (IDataReader dr = database.ExecuteReader(selectCommand))
            {
                while (dr.Read() && ((maximumRows < 1) || (rowCount < maximumRows)))
                {
                    if (thisIndex >= startRowIndex)
                    {
                        Coupon coupon = new Coupon();
                        Coupon.LoadDataReader(coupon, dr);
                        results.Add(coupon);
                        rowCount++;
                    }
                    thisIndex++;
                }
                dr.Close();
            }
            return(results);
        }