public static void SetLowGradeFloors(GlobalValues globals)
        {
            //kludge :
            if (globals.LOWGRADE < 12)
            {
                globals.LOWGRADE = 12;
            }

            int floor = (GradeCodeFloorMap.ContainsKey(Int16.Parse(globals.Grade.Value)))
                    ? GradeCodeFloorMap[Int16.Parse(globals.Grade.Value)]
                    : globals.LOWGRADE;

            if (globals.HIGHGRADE > floor && globals.LOWGRADE < floor)
            {
                globals.LOWGRADE = floor;
            }
        }
        public String BuildAutoGradeCodeClause(SQLHelper.WhereClauseJoiner join, String field, String dbObject)
        {
            String strOrAggGradeCode = String.Empty;
            Int16  gradeCode         = Int16.Parse(GlobalValues.Grade.Value);

            Int16 floor = (GradeCodeFloorMap.ContainsKey(gradeCode))
                ? GradeCodeFloorMap[gradeCode]
                : GradeCodeFloorMap[99];

            //Include Combined Grades only for pages that have individual grade selections
            if (GlobalValues.Group.Key != GroupKeys.Grade) // i.e. this clause was triggered some other way
            {
                strOrAggGradeCode = "OR {0} = '" +
                                    //WSAS Exception for "All Tested" Flag
                                    ((GradeCodeFloorMap.ContainsKey(gradeCode) && GlobalValues.Grade.Value != "0")
                           ? GlobalValues.Grade.Value : "99")
                                    + "' ";
            }

            return("  " + SQLHelper.GetJoinerString(join) + " " +
                   String.Format(@"(
(--lowgrade:
    {0} >= (select top 1  CASE WHEN lowgrade < {2} THEN {2} ELSE lowgrade END from tblAgencyFull where  {1}.year = tblAgencyFull.year and {1}.fullkey = tblAgencyFull.fullkey)
    OR fullkey = 'XXXXXXXXXXXX'  AND {0} >= {2}
)--/lowgrade
    AND 
(--highgrade
{0} <= (select top 1 highgrade from tblAgencyFull where {1}.year = tblAgencyFull.year and {1}.fullkey = tblAgencyFull.fullkey)
    OR fullkey = 'XXXXXXXXXXXX'  AND {0}< 70
)--/highgrade
    " + strOrAggGradeCode + @"
) "
                                 , field
                                 , dbObject
                                 , floor
                                 ));
        }