public static TrackingNumberCollection LoadForShipGateway(Int32 shipGatewayId, 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(" " + TrackingNumber.GetColumnNames(string.Empty)); selectQuery.Append(" FROM ac_TrackingNumbers"); selectQuery.Append(" WHERE ShipGatewayId = @shipGatewayId"); if (!string.IsNullOrEmpty(sortExpression)) { selectQuery.Append(" ORDER BY " + sortExpression); } Database database = Token.Instance.Database; DbCommand selectCommand = database.GetSqlStringCommand(selectQuery.ToString()); database.AddInParameter(selectCommand, "@shipGatewayId", System.Data.DbType.Int32, NullableData.DbNullify(shipGatewayId)); //EXECUTE THE COMMAND TrackingNumberCollection results = new TrackingNumberCollection(); int thisIndex = 0; int rowCount = 0; using (IDataReader dr = database.ExecuteReader(selectCommand)) { while (dr.Read() && ((maximumRows < 1) || (rowCount < maximumRows))) { if (thisIndex >= startRowIndex) { TrackingNumber trackingNumber = new TrackingNumber(); TrackingNumber.LoadDataReader(trackingNumber, dr); results.Add(trackingNumber); rowCount++; } thisIndex++; } dr.Close(); } return(results); }
public static TrackingNumberCollection 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(" " + TrackingNumber.GetColumnNames(string.Empty)); selectQuery.Append(" FROM ac_TrackingNumbers"); 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 TrackingNumberCollection results = new TrackingNumberCollection(); int thisIndex = 0; int rowCount = 0; using (IDataReader dr = database.ExecuteReader(selectCommand)) { while (dr.Read() && ((maximumRows < 1) || (rowCount < maximumRows))) { if (thisIndex >= startRowIndex) { TrackingNumber trackingNumber = new TrackingNumber(); TrackingNumber.LoadDataReader(trackingNumber, dr); results.Add(trackingNumber); rowCount++; } thisIndex++; } dr.Close(); } return(results); }