public static void Sort(List<SongData> rows, SongOrder order) { List<SongData> irows = new List<SongData>(); foreach (SongData row in rows) irows.Add(row); irows.Sort(GetComparison(order)); rows.Clear(); foreach (SongData row in irows) rows.Add(row); }
public static Comparison<SongData> GetComparison(SongOrder order) { switch (order) { case SongOrder.TitleGroup: return CompareTitleGroup; case SongOrder.GroupTitle: return CompareTitleGroup; case SongOrder.Database: return CompareDatabase; } throw new Exception("Unsupported order:" + order.ToString()); }
public IEnumerable<SongData> GetSongs(SongOrder order) { List<SongData> rows = new List<SongData>(); foreach (SongData row in EnumSongs()) { rows.Add(row); } rows.Sort(Sorting.GetComparison(order)); return rows; }
protected void BtnOrder_Click(object sender, EventArgs e) { Page.Validate(); if (Page.IsValid) { validateNumbers(); if (lblValidation.Text != "") { return; } ArrayList arrProducts = new ArrayList(); // used to store the ProductNumber for each selected product int count = 0; // used to count the number of selected products // Iterate through the rows (records) of the GridView and store the ProductNumber // for each row that is checked int songID; string title; int quantity; decimal price; string format; int totalQuantity = 0; decimal grandTotal = 0m; lblSubscriptionNotification.Visible = true; for (int row = 0; row < gvProducts.Rows.Count; row++) { CheckBox CBox; TextBox TBox; DropDownList DropDownFormat; // Get the reference for the chkSelect control in the current row CBox = (CheckBox)gvProducts.Rows[row].FindControl("chkSelect"); if (CBox.Checked) { // Get the ProductNumber from the BoundField from the GridView for the current row // and store the value in the array of selected products. TBox = (TextBox)gvProducts.Rows[row].FindControl("txtQtyAdd"); songID = Convert.ToInt32(gvProducts.DataKeys[row].Values[0]); title = gvProducts.Rows[row].Cells[1].Text; quantity = Convert.ToInt32(TBox.Text); totalQuantity += quantity; price = Convert.ToDecimal(gvProducts.DataKeys[row].Values[1]); DropDownFormat = (DropDownList)gvProducts.Rows[row].FindControl("ddFormat"); format = DropDownFormat.Text; SongOrder song = new SongOrder(songID, title, quantity, price, format); grandTotal += song.TotalCost; arrProducts.Add(song); count = count + 1; } } string subscription = drpdwnPayment.SelectedValue; switch (subscription) { case "monthly": grandTotal += 2; lblSubscriptionNotification.Text += "2"; break; case "annual": grandTotal += 20; lblSubscriptionNotification.Text += "20"; break; case "one": grandTotal += 5; lblSubscriptionNotification.Text += "5"; break; } //Show customer info showUserOutput(); updateSubscriptionStatistics(); allElementsHide(); gvUserOutput.DataSource = arrProducts; gvUserOutput.Columns[0].FooterText = "Totals:"; gvUserOutput.Columns[2].FooterText = Convert.ToString(totalQuantity); gvUserOutput.Columns[4].FooterText = Convert.ToString(grandTotal); gvUserOutput.DataBind(); } }