public ActionResult Index(int?page) { int pageIndex = PagingHelper.GetPageIndex(page); BomSearchModel q = new BomSearchModel(); IBomService bs = new BomService(Settings.Default.db); IPagedList <BOM> boms = bs.Search(q).ToPagedList(pageIndex, Settings.Default.pageSize); ViewBag.Query = q; return(View(boms)); }
public ActionResult Search([Bind(Include = "ID, PartNr, VFFrom, VFTo, VTFrom, VTTo")] BomSearchModel q) { int pageIndex = 0; int.TryParse(Request.QueryString.Get("page"), out pageIndex); pageIndex = PagingHelper.GetPageIndex(pageIndex); IBomService bs = new BomService(Settings.Default.db); IPagedList <BOM> boms = bs.Search(q).ToPagedList(pageIndex, Settings.Default.pageSize); ViewBag.Query = q; return(View("Index", boms)); }
public void Export([Bind(Include = "ID, PartNr, VFFrom, VFTo, VTFrom, VTTo")] BomSearchModel q) { IBomService bs = new BomService(Settings.Default.db); List <BOM> boms = bs.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", "PartNr", "ValidFrom", "ValidTo", "VersionId", "BomDesc", "Action" }; sw.WriteLine(string.Join(Settings.Default.csvDelimiter, head)); for (var i = 0; i < boms.Count; i++) { List <string> ii = new List <string>(); ii.Add((i + 1).ToString()); ii.Add(boms[i].id.ToString()); ii.Add(boms[i].partNr); ii.Add(boms[i].validFrom.ToString()); ii.Add(boms[i].validTo.ToString()); ii.Add(boms[i].versionId); ii.Add(boms[i].bomDesc); ii.Add(""); sw.WriteLine(string.Join(Settings.Default.csvDelimiter, ii.ToArray())); } //sw.WriteLine(max); } var filename = "Bom" + 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(); }