/// <summary> /// Adds an item to the sorting list. If it exists already, it will be superceded (deprioritized), unless the existing /// item is marked as "Required" or "RequiredOrder." In the first case, only the order (asc or desc) will be changed to /// the current value. In the 2nd case, no changes will be made. /// </summary> /// <param name="field"></param> /// <param name="order"></param> /// <param name="priority"></param> /// <returns></returns> public ISqlQuery AddSort(string field, SortOrder order, SortPriority priority) { if (String.IsNullOrEmpty(field)) { throw new Exception("The field name cannot be missing to add a sort"); } string sortOrder = order == SortOrder.Ascending ? "" : " DESC"; int index = sortCriterionList.Count - 1; string fieldNameClean = unAliased(field.Trim().ToLower()); bool found = false; while (index >= 0) { var item = sortCriterionList[index]; if (item.Field == fieldNameClean) { switch (item.Priority) { case SortPriority.RequiredOrder: found = true; index = -1; break; case SortPriority.Required: sortCriterionList[index] = new SortCriterion(fieldNameClean, order, item.Priority); sortCriterionList[index].Owner = this; index = -1; found = true; break; default: sortCriterionList.RemoveAt(index); break; } } index--; } if (!found) { var crit = new SortCriterion(fieldNameClean, order, priority); crit.Owner = this; sortCriterionList.Add(crit); Touch(); } return(this); }
public SortCriterion Clone() { SortCriterion clone = new SortCriterion(Field, Order, Priority); return(clone); }
/// <summary> /// Adds an item to the sorting list. If it exists already, it will be superceded (deprioritized), unless the existing /// item is marked as "Required" or "RequiredOrder." In the first case, only the order (asc or desc) will be changed to /// the current value. In the 2nd case, no changes will be made. /// </summary> /// <param name="field"></param> /// <param name="order"></param> /// <param name="priority"></param> /// <returns></returns> public ISqlQuery AddSort(string field, SortOrder order, SortPriority priority) { if (String.IsNullOrEmpty(field)) { throw new Exception("The field name cannot be missing to add a sort"); } string sortOrder = order == SortOrder.Ascending ? "" : " DESC"; int index = sortCriterionList.Count - 1; string fieldNameClean = unAliased(field.Trim().ToLower()); bool found = false; while (index >= 0) { var item = sortCriterionList[index]; if (item.Field == fieldNameClean) { switch (item.Priority) { case SortPriority.RequiredOrder: found = true; index = -1; break; case SortPriority.Required: sortCriterionList[index] = new SortCriterion(fieldNameClean, order, item.Priority); sortCriterionList[index].Owner = this; index = -1; found = true; break; default: sortCriterionList.RemoveAt(index); break; } } index--; } if (!found) { var crit = new SortCriterion(fieldNameClean, order, priority); crit.Owner = this; sortCriterionList.Add(crit); Touch(); } return this; }
public SortCriterion Clone() { SortCriterion clone = new SortCriterion(Field,Order,Priority); return clone; }