public void Sort <T>(T[] array, SortDirection typeSorting = SortDirection.Ascending) { Comparer <T> comparer = Comparer <T> .Default; int length = array.Count(); for (int i = 0; i < length - 1; i++) { int minIndex = i; for (int index = i + 1; index < length; index++) { if (typeSorting.Equals(SortDirection.Ascending)) { if (comparer.Compare(array[index], array[minIndex]) < 0) { minIndex = index; } } if (typeSorting.Equals(SortDirection.Descending)) { if (comparer.Compare(array[index], array[minIndex]) < 0) { minIndex = index; } } } Swap(array, minIndex, i); } }
public void Sort <T>(IList <T> list, SortDirection typeSorting = SortDirection.Ascending) { Comparer <T> comparer = Comparer <T> .Default; int length = list.Count(); for (int i = 0; i < length - 1; i++) { int minIndex = i; for (int index = i + 1; index < length; index++) { if (typeSorting.Equals(SortDirection.Ascending)) { if (comparer.Compare(list[index], list[minIndex]) < 0) { minIndex = index; } } if (typeSorting.Equals(SortDirection.Descending)) { if (comparer.Compare(list[index], list[minIndex]) > 0) { minIndex = index; } } } Swap(list, minIndex, i); } }
public void Sort <T>(T[] array, SortDirection typeSorting) { Comparer <T> comparer = Comparer <T> .Default; int length = array.Length - 1; for (int i = 0; i < length; i++) { for (int index = 0; index < length - i; index++) { if (typeSorting.Equals(SortDirection.Ascending)) { if (comparer.Compare(array[index], array[index + 1]) > 0) { Swap(array, index, index + 1); } } if (typeSorting.Equals(SortDirection.Descending)) { if (comparer.Compare(array[index], array[index + 1]) < 0) { Swap(array, index, index + 1); } } } } }
protected void RepairCardsGridView_Sorting(object sender, GridViewSortEventArgs e) { SortDirection newSortDirection = SortDirection.Descending; object currentSortDirectionObject = ViewState[CarServiceConstants.SORT_DIRECTION_VIEW_STATE_ATTR]; if (currentSortDirectionObject != null) { SortDirection currentSortDirection = (SortDirection)currentSortDirectionObject; newSortDirection = (currentSortDirection.Equals(SortDirection.Ascending)) ? SortDirection.Descending : SortDirection.Ascending; } ViewState[CarServiceConstants.SORT_DIRECTION_VIEW_STATE_ATTR] = newSortDirection; ViewState[CarServiceConstants.SORT_EXPRESSION_VIEW_STATE_ATTR] = e.SortExpression; object repairCardsFilterObj = Session[CarServiceConstants.REPAIR_CARDS_FILTER_SESSION_ATTR_NAME]; IQueryable <RepairCard> repairCards; if (repairCardsFilterObj != null) { RepairCardFilter filter = (RepairCardFilter)repairCardsFilterObj; repairCards = FilterRepairCards(filter); } else { repairCards = this.persister.GetRepairCards(); } IQueryable <RepairCard> sortedCards = SortingUtility.SortRepairCards(repairCards, e.SortExpression, newSortDirection); BindRepairCardsGrid(sortedCards); }
private static TagBuilder GetAnchor(string expressionField, string displayName, ref string sortField, ref SortDirection sortDirection) { var anchor = new TagBuilder("a"); anchor.AddCssClass("sortLink"); if (string.IsNullOrWhiteSpace(sortField)) { sortField = expressionField; } else if (!sortField.Equals(expressionField)) { sortDirection = SortDirection.Ascending; sortField = expressionField; } else { var icon = new TagBuilder("i"); icon.AddCssClass("sortIcon"); if (sortDirection.Equals(SortDirection.Ascending)) { sortDirection = SortDirection.Descending; icon.AddCssClass("sortAscending"); } else { sortDirection = SortDirection.Ascending; icon.AddCssClass("sortDescending"); } anchor.InnerHtml = $"{icon} {displayName}"; } return(anchor); }
/// <summary> /// Paginación y ordenación de la fuente de datos /// </summary> /// <param name="gv"></param> /// <param name="sortField"></param> /// <param name="dt"></param> /// <param name="iPage"></param> public static void pageAndSort(GridView gv, ref SortDirection GridViewSortDirection, string sortField, DataTable dt, int iPage) { if (dt != null) { if (!string.IsNullOrEmpty(sortField)) { int actualPage = gv.PageIndex; // Si es paginacion, permanecer con la misma direccion de ordenación if (actualPage != iPage) { // Esta asc ordenarlo desc if (GridViewSortDirection.Equals(SortDirection.Ascending)) { gv.DataSource = dt.AsEnumerable().OrderBy(x => x.Field <object>(sortField)).CopyToDataTable(); } else { gv.DataSource = dt.AsEnumerable().OrderByDescending(x => x.Field <object>(sortField)).CopyToDataTable(); } } else { // Esta asc ordenarlo desc if (GridViewSortDirection.Equals(SortDirection.Ascending)) { gv.DataSource = dt.AsEnumerable().OrderByDescending(x => x.Field <object>(sortField)).CopyToDataTable(); GridViewSortDirection = SortDirection.Descending; } else { gv.DataSource = dt.AsEnumerable().OrderBy(x => x.Field <object>(sortField)).CopyToDataTable(); GridViewSortDirection = SortDirection.Ascending; } } } else { gv.DataSource = dt; } gv.PageIndex = iPage; gv.DataBind(); } }
///<summary> ///Determines whether the specified <see cref="T:System.Object"></see> is equal to the current <see cref="T:System.Object"></see>. ///</summary> /// ///<returns> ///true if the specified <see cref="T:System.Object"></see> is equal to the current <see cref="T:System.Object"></see>; otherwise, false. ///</returns> /// ///<param name="obj">The <see cref="T:System.Object"></see> to compare with the current <see cref="T:System.Object"></see>. </param><filterpriority>2</filterpriority> public override bool Equals(object obj) { if (!(obj is OrderCriteriaField)) { return(false); } OrderCriteriaField objOrderCriteriaField = obj as OrderCriteriaField; return(this.PropertyName.Equals(objOrderCriteriaField.PropertyName) && _sortDirection.Equals(objOrderCriteriaField.SortDirection)); }
public static SortDirection GetSortDirection(StateBag viewState) { SortDirection newSortDirection = SortDirection.Descending; object currentSortDirectionObject = viewState[CarServiceConstants.SORT_DIRECTION_VIEW_STATE_ATTR]; if (currentSortDirectionObject != null) { SortDirection currentSortDirection = (SortDirection)currentSortDirectionObject; newSortDirection = (currentSortDirection.Equals(SortDirection.Ascending)) ? SortDirection.Descending : SortDirection.Ascending; } return(newSortDirection); }
public static IQueryable <SparePart> SortSpareParts(IQueryable <SparePart> spareParts, string sortExpression, SortDirection sortDirection) { bool ascending = sortDirection.Equals(SortDirection.Ascending); IQueryable <SparePart> sortedSpareParts = spareParts; if (sortExpression.Equals(CarServiceConstants.SPARE_PART_ID_SORT_EXPRESSION)) { if (ascending) { sortedSpareParts = spareParts.OrderBy(part => part.PartId); } else { sortedSpareParts = spareParts.OrderByDescending(part => part.PartId); } } else if (sortExpression.Equals(CarServiceConstants.SPARE_PART_NAME_SORT_EXPRESSION)) { if (ascending) { sortedSpareParts = spareParts.OrderBy(part => part.Name); } else { sortedSpareParts = spareParts.OrderByDescending(part => part.Name); } } else if (sortExpression.Equals(CarServiceConstants.SPARE_PART_PRICE_SORT_EXPRESSION)) { if (ascending) { sortedSpareParts = spareParts.OrderBy(part => part.Price); } else { sortedSpareParts = spareParts.OrderByDescending(part => part.Price); } } else if (sortExpression.Equals(CarServiceConstants.SPARE_PART_ACTIVE_SORT_EXPRESSION)) { if (ascending) { sortedSpareParts = spareParts.OrderBy(part => part.IsActive); } else { sortedSpareParts = spareParts.OrderByDescending(part => part.IsActive); } } return(sortedSpareParts); }
public void Sort <T>(IList <T> list, SortDirection typeSorting) { Comparer <T> comparer = Comparer <T> .Default; int length = list.Count - 1; bool isSwap = false; for (int i = 0; i < length; i++) { isSwap = false; for (int index = 0; index < length - i; index++) { if (typeSorting.Equals(SortDirection.Ascending)) { if (comparer.Compare(list[index], list[index + 1]) > 0) { Swap(list, index, index + 1); isSwap = true; } } if (typeSorting.Equals(SortDirection.Descending)) { if (comparer.Compare(list[index], list[index + 1]) < 0) { Swap(list, index, index + 1); isSwap = true; } } } if (!isSwap) { break; } } }
/// <summary> /// Equalses the specified other. /// </summary> /// <param name="other">The other.</param> /// <returns></returns> public bool Equals(PfeColumnAttribute other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return(base.Equals(other) && Equals(Name, other.Name) && Type.Equals(other.Type) && Editable == other.Editable && Mandatory == other.Mandatory && Hidden == other.Hidden && Hideable == other.Hideable && Width == other.Width && Equals(Text, other.Text) && Xtype.Equals(other.Xtype) && Align.Equals(other.Align) && Equals(Tooltip, other.Tooltip) && Sortable == other.Sortable && SortDirection.Equals(other.SortDirection) && Equals(Format, other.Format) && DecimalPlaces == other.DecimalPlaces && Equals(DataUrl, other.DataUrl) && Equals(DefaultValue, other.DefaultValue) && Equals(Description, other.Description) && Rank == other.Rank && ReadOnly == other.ReadOnly && MaxLength == other.MaxLength && Validator == other.Validator && SearchFieldDefinition == other.SearchFieldDefinition && Nullable == other.Nullable && SingleComboFilter == other.SingleComboFilter && AllowComboCustomValue == other.AllowComboCustomValue && SearchComboFromLeft == other.SearchComboFromLeft && LoadWhenVisible == other.LoadWhenVisible && Tpl == other.Tpl && MinCharSearch == other.MinCharSearch && AdditionalWhereSqlTemp == other.AdditionalWhereSqlTemp); }
public static IQueryable <Automobile> SortAutomobiles(IQueryable <Automobile> automobiles, string sortExpression, SortDirection sortDirection) { bool ascending = sortDirection.Equals(SortDirection.Ascending); IQueryable <Automobile> sortedAutomobiles = automobiles; if (sortExpression.Equals(CarServiceConstants.AUTOMOBILE_ID_SORT_EXPRESSION)) { if (ascending) { sortedAutomobiles = automobiles.OrderBy(auto => auto.AutomobileId); } else { sortedAutomobiles = automobiles.OrderByDescending(auto => auto.AutomobileId); } } else if (sortExpression.Equals(CarServiceConstants.AUTOMOBILE_VIN_SORT_EXPRESSION)) { if (ascending) { sortedAutomobiles = automobiles.OrderBy(auto => auto.Vin); } else { sortedAutomobiles = automobiles.OrderByDescending(auto => auto.Vin); } } else if (sortExpression.Equals(CarServiceConstants.AUTOMOBILE_CHASSIS_SORT_EXPRESSION)) { if (ascending) { sortedAutomobiles = automobiles.OrderBy(auto => auto.ChassisNumber); } else { sortedAutomobiles = automobiles.OrderByDescending(auto => auto.ChassisNumber); } } else if (sortExpression.Equals(CarServiceConstants.AUTOMOBILE_MAKE_SORT_EXPRESSION)) { if (ascending) { sortedAutomobiles = automobiles.OrderBy(auto => auto.Make); } else { sortedAutomobiles = automobiles.OrderByDescending(auto => auto.Make); } } else if (sortExpression.Equals(CarServiceConstants.AUTOMOBILE_MODEL_SORT_EXPRESSION)) { if (ascending) { sortedAutomobiles = automobiles.OrderBy(auto => auto.Model); } else { sortedAutomobiles = automobiles.OrderByDescending(auto => auto.Model); } } else if (sortExpression.Equals(CarServiceConstants.AUTOMOBILE_OWNER_SORT_EXPRESSION)) { if (ascending) { sortedAutomobiles = automobiles.OrderBy(auto => auto.Owner); } else { sortedAutomobiles = automobiles.OrderByDescending(auto => auto.Owner); } } return(sortedAutomobiles); }
public static IQueryable<RepairCard> SortRepairCards(IQueryable<RepairCard> repairCards, string sortExpression, SortDirection sortDirection) { bool ascending = sortDirection.Equals(SortDirection.Ascending); IQueryable<RepairCard> sortedCards; if (sortExpression.Equals(CarServiceConstants.REPAIR_CARD_ID_SORT_EXPRESSION)) { if (ascending) { sortedCards = repairCards.OrderBy(card => card.CardId); } else { sortedCards = repairCards.OrderByDescending(card => card.CardId); } } else if (sortExpression.Equals(CarServiceConstants.REPAIR_CARD_CHASSIS_SORT_EXPRESSION)) { if (ascending) { sortedCards = repairCards.OrderBy(card => card.Automobile.ChassisNumber); } else { sortedCards = repairCards.OrderByDescending(card => card.Automobile.ChassisNumber); } } else if (sortExpression.Equals(CarServiceConstants.REPAIR_CARD_Vin_SORT_EXPRESSION)) { if (ascending) { sortedCards = repairCards.OrderBy(card => card.Automobile.Vin); } else { sortedCards = repairCards.OrderByDescending(card => card.Automobile.Vin); } } else if (sortExpression.Equals(CarServiceConstants.REPAIR_CARD_START_DATE_SORT_EXPRESSION)) { if (ascending) { sortedCards = repairCards.OrderBy(card => card.StartRepair); } else { sortedCards = repairCards.OrderByDescending(card => card.StartRepair); } } else if (sortExpression.Equals(CarServiceConstants.REPAIR_CARD_FINISH_DATE_SORT_EXPRESSION)) { if (ascending) { sortedCards = repairCards.OrderBy(card => card.FinishRepair); } else { sortedCards = repairCards.OrderByDescending(card => card.FinishRepair); } } else if (sortExpression.Equals(CarServiceConstants.REPAIR_CARD_PRICE_SORT_EXPRESSION)) { if (ascending) { sortedCards = repairCards.OrderBy(card => card.CardPrice); } else { sortedCards = repairCards.OrderByDescending(card => card.CardPrice); } } else { sortedCards = repairCards; } return sortedCards; }
public static IQueryable <RepairCard> SortRepairCards(IQueryable <RepairCard> repairCards, string sortExpression, SortDirection sortDirection) { bool ascending = sortDirection.Equals(SortDirection.Ascending); IQueryable <RepairCard> sortedCards; if (sortExpression.Equals(CarServiceConstants.REPAIR_CARD_ID_SORT_EXPRESSION)) { if (ascending) { sortedCards = repairCards.OrderBy(card => card.CardId); } else { sortedCards = repairCards.OrderByDescending(card => card.CardId); } } else if (sortExpression.Equals(CarServiceConstants.REPAIR_CARD_CHASSIS_SORT_EXPRESSION)) { if (ascending) { sortedCards = repairCards.OrderBy(card => card.Automobile.ChassisNumber); } else { sortedCards = repairCards.OrderByDescending(card => card.Automobile.ChassisNumber); } } else if (sortExpression.Equals(CarServiceConstants.REPAIR_CARD_Vin_SORT_EXPRESSION)) { if (ascending) { sortedCards = repairCards.OrderBy(card => card.Automobile.Vin); } else { sortedCards = repairCards.OrderByDescending(card => card.Automobile.Vin); } } else if (sortExpression.Equals(CarServiceConstants.REPAIR_CARD_START_DATE_SORT_EXPRESSION)) { if (ascending) { sortedCards = repairCards.OrderBy(card => card.StartRepair); } else { sortedCards = repairCards.OrderByDescending(card => card.StartRepair); } } else if (sortExpression.Equals(CarServiceConstants.REPAIR_CARD_FINISH_DATE_SORT_EXPRESSION)) { if (ascending) { sortedCards = repairCards.OrderBy(card => card.FinishRepair); } else { sortedCards = repairCards.OrderByDescending(card => card.FinishRepair); } } else if (sortExpression.Equals(CarServiceConstants.REPAIR_CARD_PRICE_SORT_EXPRESSION)) { if (ascending) { sortedCards = repairCards.OrderBy(card => card.CardPrice); } else { sortedCards = repairCards.OrderByDescending(card => card.CardPrice); } } else { sortedCards = repairCards; } return(sortedCards); }
public static IEnumerable <CarServiceUser> SortUsers(List <CarServiceUser> users, string sortExpression, SortDirection sortDirection) { bool ascending = sortDirection.Equals(SortDirection.Ascending); IEnumerable <CarServiceUser> sortedUsers = null; if (sortExpression.Equals(CarServiceConstants.USER_NAME_SORT_EXPRESSION)) { if (ascending) { sortedUsers = users.OrderBy(user => user.UserName); } else { sortedUsers = users.OrderByDescending(user => user.UserName); } } else if (sortExpression.Equals(CarServiceConstants.USER_EMAIL_SORT_EXPRESSION)) { if (ascending) { sortedUsers = users.OrderBy(user => user.Email); } else { sortedUsers = users.OrderByDescending(user => user.Email); } } else if (sortExpression.Equals(CarServiceConstants.USER_FIRST_NAME_SORT_EXPRESSION)) { if (ascending) { sortedUsers = users.OrderBy(user => user.FirstName); } else { sortedUsers = users.OrderByDescending(user => user.FirstName); } } else if (sortExpression.Equals(CarServiceConstants.USER_LAST_NAME_SORT_EXPRESSION)) { if (ascending) { sortedUsers = users.OrderBy(user => user.LastName); } else { sortedUsers = users.OrderByDescending(user => user.LastName); } } else if (sortExpression.Equals(CarServiceConstants.USER_ACTIVE_SORT_EXPRESSION)) { if (ascending) { sortedUsers = users.OrderBy(user => user.IsActive); } else { sortedUsers = users.OrderByDescending(user => user.IsActive); } } return(sortedUsers); }
public static IQueryable<SparePart> SortSpareParts(IQueryable<SparePart> spareParts, string sortExpression, SortDirection sortDirection) { bool ascending = sortDirection.Equals(SortDirection.Ascending); IQueryable<SparePart> sortedSpareParts = spareParts; if (sortExpression.Equals(CarServiceConstants.SPARE_PART_ID_SORT_EXPRESSION)) { if (ascending) { sortedSpareParts = spareParts.OrderBy(part => part.PartId); } else { sortedSpareParts = spareParts.OrderByDescending(part => part.PartId); } } else if (sortExpression.Equals(CarServiceConstants.SPARE_PART_NAME_SORT_EXPRESSION)) { if (ascending) { sortedSpareParts = spareParts.OrderBy(part => part.Name); } else { sortedSpareParts = spareParts.OrderByDescending(part => part.Name); } } else if (sortExpression.Equals(CarServiceConstants.SPARE_PART_PRICE_SORT_EXPRESSION)) { if (ascending) { sortedSpareParts = spareParts.OrderBy(part => part.Price); } else { sortedSpareParts = spareParts.OrderByDescending(part => part.Price); } } else if (sortExpression.Equals(CarServiceConstants.SPARE_PART_ACTIVE_SORT_EXPRESSION)) { if (ascending) { sortedSpareParts = spareParts.OrderBy(part => part.IsActive); } else { sortedSpareParts = spareParts.OrderByDescending(part => part.IsActive); } } return sortedSpareParts; }
public static IEnumerable<CarServiceUser> SortUsers(List<CarServiceUser> users, string sortExpression, SortDirection sortDirection) { bool ascending = sortDirection.Equals(SortDirection.Ascending); IEnumerable<CarServiceUser> sortedUsers = null; if (sortExpression.Equals(CarServiceConstants.USER_NAME_SORT_EXPRESSION)) { if (ascending) { sortedUsers = users.OrderBy(user => user.UserName); } else { sortedUsers = users.OrderByDescending(user => user.UserName); } } else if (sortExpression.Equals(CarServiceConstants.USER_EMAIL_SORT_EXPRESSION)) { if (ascending) { sortedUsers = users.OrderBy(user => user.Email); } else { sortedUsers = users.OrderByDescending(user => user.Email); } } else if (sortExpression.Equals(CarServiceConstants.USER_FIRST_NAME_SORT_EXPRESSION)) { if (ascending) { sortedUsers = users.OrderBy(user => user.FirstName); } else { sortedUsers = users.OrderByDescending(user => user.FirstName); } } else if (sortExpression.Equals(CarServiceConstants.USER_LAST_NAME_SORT_EXPRESSION)) { if (ascending) { sortedUsers = users.OrderBy(user => user.LastName); } else { sortedUsers = users.OrderByDescending(user => user.LastName); } } else if (sortExpression.Equals(CarServiceConstants.USER_ACTIVE_SORT_EXPRESSION)) { if (ascending) { sortedUsers = users.OrderBy(user => user.IsActive); } else { sortedUsers = users.OrderByDescending(user => user.IsActive); } } return sortedUsers; }
public static IQueryable<Automobile> SortAutomobiles(IQueryable<Automobile> automobiles, string sortExpression, SortDirection sortDirection) { bool ascending = sortDirection.Equals(SortDirection.Ascending); IQueryable<Automobile> sortedAutomobiles = automobiles; if (sortExpression.Equals(CarServiceConstants.AUTOMOBILE_ID_SORT_EXPRESSION)) { if (ascending) { sortedAutomobiles = automobiles.OrderBy(auto => auto.AutomobileId); } else { sortedAutomobiles = automobiles.OrderByDescending(auto => auto.AutomobileId); } } else if (sortExpression.Equals(CarServiceConstants.AUTOMOBILE_VIN_SORT_EXPRESSION)) { if (ascending) { sortedAutomobiles = automobiles.OrderBy(auto => auto.Vin); } else { sortedAutomobiles = automobiles.OrderByDescending(auto => auto.Vin); } } else if (sortExpression.Equals(CarServiceConstants.AUTOMOBILE_CHASSIS_SORT_EXPRESSION)) { if (ascending) { sortedAutomobiles = automobiles.OrderBy(auto => auto.ChassisNumber); } else { sortedAutomobiles = automobiles.OrderByDescending(auto => auto.ChassisNumber); } } else if (sortExpression.Equals(CarServiceConstants.AUTOMOBILE_MAKE_SORT_EXPRESSION)) { if (ascending) { sortedAutomobiles = automobiles.OrderBy(auto => auto.Make); } else { sortedAutomobiles = automobiles.OrderByDescending(auto => auto.Make); } } else if (sortExpression.Equals(CarServiceConstants.AUTOMOBILE_MODEL_SORT_EXPRESSION)) { if (ascending) { sortedAutomobiles = automobiles.OrderBy(auto => auto.Model); } else { sortedAutomobiles = automobiles.OrderByDescending(auto => auto.Model); } } else if (sortExpression.Equals(CarServiceConstants.AUTOMOBILE_OWNER_SORT_EXPRESSION)) { if (ascending) { sortedAutomobiles = automobiles.OrderBy(auto => auto.Owner); } else { sortedAutomobiles = automobiles.OrderByDescending(auto => auto.Owner); } } return sortedAutomobiles; }
public override int Compare(GetAFTAuditDetailsResult x, GetAFTAuditDetailsResult y) { String valueX = String.Empty, valueY = String.Empty; try { switch (SortBy) { default: valueX = x.AFT_Audit_ID.ToString(); valueY = y.AFT_Audit_ID.ToString(); break; case "Audit_ID": valueX = x.AFT_Audit_ID.ToString(); valueY = y.AFT_Audit_ID.ToString(); break; case "Data": case "Date": valueX = x.AFT_TransactionDate.ToString(); valueY = y.AFT_TransactionDate.ToString(); break; case "Transaction Type": case "Tipo di transazione": valueX = x.AFT_TransactionType; valueY = y.AFT_TransactionType; break; case "CashableAmount": // case "Importo": valueX = x.CashableAmount.ToString(); valueY = y.CashableAmount.ToString(); break; case "NonCashableAmount": // case "Importo": valueX = x.NonCashableAmount.ToString(); valueY = y.NonCashableAmount.ToString(); break; case "WATAmount": // case "Importo": valueX = x.WATAmount.ToString(); valueY = y.WATAmount.ToString(); break; case "Player_ID": valueX = x.AFT_PlayerID.ToString(); valueY = y.AFT_PlayerID.ToString(); break; case "Nome del giocatore": case "Player Name": valueX = x.AFT_PlayerName; valueY = y.AFT_PlayerName; break; case "Errore Messaggio": case "Error Message": valueX = x.AFT_Error_Message; valueY = y.AFT_Error_Message; break; } if (SortDirection.Equals(ListSortDirection.Ascending)) { return(String.Compare(valueX, valueY)); } else { return((-1) * String.Compare(valueX, valueY)); } } catch (Exception) { return(0); } }
/// Compares the specified x to y. public override int Compare(GetAuditDetailsResult x, GetAuditDetailsResult y) { String valueX = String.Empty, valueY = String.Empty; try { switch (SortBy) { default: valueX = x.Audit_ID.ToString(); valueY = y.Audit_ID.ToString(); break; case "Audit_ID": valueX = x.Audit_ID.ToString(); valueY = y.Audit_ID.ToString(); break; case "Verificare_l'operatore_l'identità": case "Audit_User_ID": valueX = x.Audit_User_ID.ToString(); valueY = y.Audit_User_ID.ToString(); break; case "Nome di operatore": case "User Name": valueX = x.Audit_User_Name; valueY = y.Audit_User_Name; break; case "Data": case "Date": valueX = x.Audit_Date.ToString(); valueY = y.Audit_Date.ToString(); break; case "Module Name": case "Nome di modulo": valueX = x.Audit_Module_Name; valueY = y.Audit_Module_Name; break; case "Screen Name": case "Schermare il Nome": valueX = x.Audit_Screen_Name; valueY = y.Audit_Screen_Name; break; case "Descrizione": case "Description": valueX = x.Audit_Desc; valueY = y.Audit_Desc; break; case "Slot": valueX = x.Audit_Slot; valueY = y.Audit_Slot; break; case "Campo": case "Field": valueX = x.Audit_Field; valueY = y.Audit_Field; break; case "Vecchio Valore": case "Old Value": valueX = x.Audit_Old_Vl; valueY = y.Audit_Old_Vl; break; case "Nuovo Valore": case "New Value": valueX = x.Audit_New_Vl; valueY = y.Audit_New_Vl; break; case "Tipo di operazione": case "Operation Type": valueX = x.Audit_Operation_Type; valueY = y.Audit_Operation_Type; break; //case "Old Value": // if (SortDirection.Equals(ListSortDirection.Ascending)) return x.Audit_Operation_Type.CompareTo(y.Audit_Operation_Type); // else return (-1) * x.Audit_Operation_Type.CompareTo(y.Audit_Operation_Type); } if (SortDirection.Equals(ListSortDirection.Ascending)) { return(String.Compare(valueX, valueY)); } else { return((-1) * String.Compare(valueX, valueY)); } } catch (Exception) { return(0); } }
private void SortGridView(string sortExpression, SortDirection direction) { if (direction.Equals(SortDirection.Ascending)) { switch (sortExpression) { case "name": { AppHelper.ProductsSession = AppHelper.ProductsSession.OrderBy(b => b.name).ToList(); break; } case "count": { AppHelper.ProductsSession = AppHelper.ProductsSession.OrderBy(b => b.count).ToList(); break; } case "measure": { AppHelper.ProductsSession = AppHelper.ProductsSession.OrderBy(b => b.measure).ToList(); break; } case "bprice": { AppHelper.ProductsSession = AppHelper.ProductsSession.OrderBy(b => b.bprice).ToList(); break; } case "reserveCount": { AppHelper.ProductsSession = AppHelper.ProductsSession.OrderBy(b => b.reserveCount).ToList(); break; } } } else { switch (sortExpression) { case "name": { AppHelper.ProductsSession = AppHelper.ProductsSession.OrderByDescending(b => b.name).ToList(); break; } case "count": { AppHelper.ProductsSession = AppHelper.ProductsSession.OrderByDescending(b => b.count).ToList(); break; } case "measure": { AppHelper.ProductsSession = AppHelper.ProductsSession.OrderByDescending(b => b.measure).ToList(); break; } case "bprice": { AppHelper.ProductsSession = AppHelper.ProductsSession.OrderByDescending(b => b.bprice).ToList(); break; } case "reserveCount": { AppHelper.ProductsSession = AppHelper.ProductsSession.OrderByDescending(b => b.reserveCount).ToList(); break; } } } gvwProducts.DataSource = AppHelper.ProductsSession; gvwProducts.DataBind(); }
public Task <HttpResponseMessage> ExecuteActionFilterAsync(HttpActionContext actionContext, CancellationToken cancellationToken, Func <Task <HttpResponseMessage> > continuation) { #region Inital Validation Logic // Check if there are the pagination headers in the request, bool doPagination = paginationHeaders.ToList().All(x => actionContext.Request.Headers.Contains(x)); continuation().Wait(); // If there isn't just return the response to the web api flow if (!doPagination) { return(continuation()); } #endregion #region Get HttpContent Data Logic // Get the values of the pagination headers request, and the HttpResponseMessage SortParam = actionContext.Request.Headers.GetValues(paginationHeaders[0]).First(); SortDirection = actionContext.Request.Headers.GetValues(paginationHeaders[1]).First(); PageStart = Convert.ToInt32(actionContext.Request.Headers.GetValues(paginationHeaders[2]).First()); PageSize = Convert.ToInt32(actionContext.Request.Headers.GetValues(paginationHeaders[3]).First()); if (!(SortDirection == "asc" || SortDirection == "dsc")) { return(continuation()); } HttpResponseMessage response = continuation().Result; HttpContent content = response.Content; // Get and deserialize the data response of the annotated action string jsonString = @content.GetValue(); dynamic deserialized = JsonConvert.DeserializeObject(jsonString, ObjectType); // Hold the all data that has the SortParam property name in a dynamic list var objsFound = new List <dynamic>(deserialized) .Where(x => x.GetType().GetProperty(SortParam) != null).ToList(); // If there isn't any data return the response to the flow if (objsFound.Count == 0) { return(continuation()); } #endregion #region Filter Data Logic // The pagination logic objsFound = SortDirection.Equals("asc") ? objsFound.OrderBy(x => x.GetType().GetProperty(SortParam).GetValue(x, null)) .Skip(PageSize <= 1 ? PageStart * PageSize - 1 : (PageStart * PageSize) - PageSize) .Take(PageSize).ToList() : objsFound.OrderByDescending(x => x.GetType().GetProperty(SortParam).GetValue(x, null)) .Skip(PageSize <= 1 ? PageStart * PageSize - 1 : (PageStart * PageSize) - PageSize) .Take(PageSize).ToList(); #endregion #region Return Data Logic // Serialize the filtered data var json = JsonConvert.SerializeObject(objsFound); // Clean the response content response.Content.Dispose(); // Generate a StringContent with the json var stringContent = new StringContent(json, Encoding.UTF8, "application/json"); // Set the response content with the generated string content response.Content = stringContent; // Return with the filtered data return(Task.Run(() => response)); #endregion }
private string directionToString(SortDirection direction) { return direction.Equals(SortDirection.ASC) ? "ASC" : "DESC"; }