public ActionResult Index(sorting info) { var Search = ""; Search = "%" + info.SearchText + "%"; string sql = "SELECT * FROM Products WHERE Name LIKE @p0"; List <Product> Product = db.Products.SqlQuery(sql, Search).ToList(); if (info.NewSearch == "Y") { info.SortField = ""; info.SortDirection = "ascending"; info.SizeOfThePage = 10; info.PageCount = Convert.ToInt32(Math.Ceiling((double)(Product.Count() / info.SizeOfThePage))); info.CurrentPageIndex = 0; info.NewSearch = "N"; } var query = Product.OrderBy(c => c.ProductId).Skip(info.CurrentPageIndex * info.SizeOfThePage).Take(info.SizeOfThePage); ViewBag.SortingPagingInfo = info; List <Product> model = query.ToList(); return(View(model)); }
/// <summary> /// Loads the catalog widgets. /// </summary> private void LoadWidgets() { if (Master.SiteSettings.DisplayNarrowCategory) { narrowcategory narrowCategoryWidget = (narrowcategory)Page.LoadControl("controls/catalog/narrowcategory.ascx"); narrowCategoryWidget.Category = category; phRightSideWidgets.Controls.Add(narrowCategoryWidget); } if (Master.SiteSettings.DisplaySortBy) { sorting sortingWidget = (sorting)Page.LoadControl("controls/catalog/sorting.ascx"); sortingWidget.Category = category; sortingWidget.ProductCollection = pagedDataSource.DataSource as ProductCollection; phRightSideWidgets.Controls.Add(sortingWidget); } if (Master.SiteSettings.DisplayNarrowByManufacturer) { narrowmanufacturer narrowManufacturerWidget = (narrowmanufacturer)Page.LoadControl("controls/catalog/narrowmanufacturer.ascx"); narrowManufacturerWidget.Category = category; phRightSideWidgets.Controls.Add(narrowManufacturerWidget); } if (Master.SiteSettings.DisplayNarrowByPrice) { narrowprice narrowPriceWidget = (narrowprice)Page.LoadControl("controls/catalog/narrowprice.ascx"); narrowPriceWidget.Category = category; phRightSideWidgets.Controls.Add(narrowPriceWidget); } }
public int TwoCitySchedCost(int[][] costs) { int cheapest; int count = costs.GetLength(0); sorting candidates = new sorting(costs, count); cheapest = candidates.balance(costs, count); return(cheapest); }
private void Report8_Load(object sender, EventArgs e) { Database.arr.Clear();//clear the arr hash table as we will fill it again so no duplicate error occurs Cow c = new Cow(); JersyCow jc = new JersyCow(); Goat g = new Goat(); Sheep s = new Sheep(); //fill the hash table named arr with id and profit of all animals c.SingleAnimalProfitability(); jc.SingleAnimalProfitability(); g.SingleAnimalProfitability(); s.SingleAnimalProfitability(); double tempVal; int tempid; int count = 0; sorting[] data = new sorting[Database.arr.Count]; //declare a struct array foreach (KeyValuePair <int, double> animal in Database.arr) //fill that array with hash table data { data[count].id = animal.Key; data[count].profit = animal.Value; count++; } for (int i = 0; i < Database.arr.Count; i++)//here is the array sorting algorithm { for (int j = i + 1; j < Database.arr.Count; j++) { if (data[i].profit > data[j].profit) { tempid = data[i].id; tempVal = data[i].profit; data[i].id = data[j].id; data[i].profit = data[j].profit; data[j].id = tempid; data[j].profit = tempVal; } } } textBox1.Text = textBox1.Text + "Animal ID" + " " + "Profitability" + "\r\n";//fill textbox with the array data textBox1.Text = textBox1.Text + "----------------------------------------------------" + "\r\n"; FileStream fs = new FileStream("sortedData.txt", FileMode.Create); StreamWriter sw = new StreamWriter(fs); for (int i = 0; i < Database.arr.Count; i++)//save that data into text file { textBox1.Text = textBox1.Text + data[i].id.ToString() + " " + data[i].profit.ToString() + "\r\n"; sw.WriteLine(data[i].id); } sw.Close(); }
// GET: Products public ActionResult Index(string Search) { //var products = db.Products.Include(p => p.Category); //return View(products.ToList()); string sql = "SELECT * FROM Products"; List <Product> Product = db.Products.SqlQuery(sql, "").ToList(); sorting info = new sorting(); info.SortField = ""; info.SortDirection = "ascending"; info.SizeOfThePage = 10; info.PageCount = Convert.ToInt32(Math.Ceiling((double)(Product.Count() / info.SizeOfThePage))); info.CurrentPageIndex = 0; info.NewSearch = "N"; var query = Product.OrderBy(c => c.ProductId).Take(info.SizeOfThePage); ViewBag.SortingPagingInfo = info; List <Product> model = query.ToList(); return(View(model)); }