public ActionResult Index(int?page) { int pageIndex = PagingHelper.GetPageIndex(page); BomItemSearchModel q = new BomItemSearchModel(); IBomItemService bis = new BomItemService(Settings.Default.db); IPagedList <BomItem> bomItems = bis.Search(q).ToPagedList(pageIndex, Settings.Default.pageSize); ViewBag.Query = q; return(View(bomItems)); }
public ActionResult Search([Bind(Include = "ID, ComponentId, VFFrom, VFTo, VTFrom, VTTo, BomId")] BomItemSearchModel q) { int pageIndex = 0; int.TryParse(Request.QueryString.Get("page"), out pageIndex); pageIndex = PagingHelper.GetPageIndex(pageIndex); IBomItemService bis = new BomItemService(Settings.Default.db); IPagedList <BomItem> bomItems = bis.Search(q).ToPagedList(pageIndex, Settings.Default.pageSize); ViewBag.Query = q; return(View("Index", bomItems)); }
public void Export([Bind(Include = "ID, ComponentId, VFFrom, VFTo, VTFrom, VTTo, BomId")] BomItemSearchModel q) { IBomItemService ps = new BomItemService(Settings.Default.db); List <BomItem> bomItems = ps.Search(q).ToList(); ViewBag.Query = q; MemoryStream ms = new MemoryStream(); using (StreamWriter sw = new StreamWriter(ms, Encoding.UTF8)) { List <string> head = new List <string> { " No.", "ID", "ComponentId", "ValidFrom", "ValidTo", "HasChild", "UOM", "Quantity", "BomId", "Action" }; sw.WriteLine(string.Join(Settings.Default.csvDelimiter, head)); for (var i = 0; i < bomItems.Count; i++) { List <string> ii = new List <string>(); ii.Add((i + 1).ToString()); ii.Add(bomItems[i].id.ToString()); ii.Add(bomItems[i].componentId); ii.Add(bomItems[i].validFrom.ToString()); ii.Add(bomItems[i].validTo.ToString()); ii.Add(bomItems[i].hasChind.ToString()); ii.Add(bomItems[i].uom.ToString()); ii.Add(bomItems[i].quantity.ToString()); ii.Add(bomItems[i].bomId); ii.Add(""); sw.WriteLine(string.Join(Settings.Default.csvDelimiter, ii.ToArray())); } //sw.WriteLine(max); } var filename = "BomItem" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".csv"; var contenttype = "text/csv"; Response.Clear(); Response.ContentEncoding = Encoding.UTF8; Response.ContentType = contenttype; Response.AddHeader("content-disposition", "attachment;filename=" + filename); Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.BinaryWrite(ms.ToArray()); Response.End(); }