public static EmailListCollection 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(" " + EmailList.GetColumnNames(string.Empty));
            selectQuery.Append(" FROM ac_EmailLists");
            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
            EmailListCollection results = new EmailListCollection();
            int thisIndex = 0;
            int rowCount  = 0;

            using (IDataReader dr = database.ExecuteReader(selectCommand))
            {
                while (dr.Read() && ((maximumRows < 1) || (rowCount < maximumRows)))
                {
                    if (thisIndex >= startRowIndex)
                    {
                        EmailList emailList = new EmailList();
                        EmailList.LoadDataReader(emailList, dr);
                        results.Add(emailList);
                        rowCount++;
                    }
                    thisIndex++;
                }
                dr.Close();
            }
            return(results);
        }
예제 #2
0
        public static EmailListCollection LoadForEmail(string email, int maximumRows, int startRowIndex, string sortExpression)
        {
            string        loweredEmail = email.ToLowerInvariant();
            StringBuilder selectQuery  = new StringBuilder();

            selectQuery.Append("SELECT DISTINCT");
            if (maximumRows > 0)
            {
                selectQuery.Append(" TOP " + (startRowIndex + maximumRows).ToString());
            }
            selectQuery.Append(" " + EmailList.GetColumnNames("EL"));
            selectQuery.Append(" FROM ac_EmailListUsers ELU, ac_EmailLists EL");
            selectQuery.Append(" WHERE ELU.EmailListId = EL.EmailListId");
            selectQuery.Append(" AND ELU.Email = @email");
            if (!string.IsNullOrEmpty(sortExpression))
            {
                selectQuery.Append(" ORDER BY " + sortExpression);
            }
            Database  database      = Token.Instance.Database;
            DbCommand selectCommand = database.GetSqlStringCommand(selectQuery.ToString());

            database.AddInParameter(selectCommand, "@email", System.Data.DbType.String, loweredEmail);
            //EXECUTE THE COMMAND
            EmailListCollection results = new EmailListCollection();
            int thisIndex = 0;
            int rowCount  = 0;

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