// GET: Product public ActionResult ProductList(ProductListAction CommandAction, bool isPopup = false) { this.ViewBag.isPopup = isPopup; this.ViewBag.Result = CommandAction.Execute(); return(View()); }
public ActionResult ProductList(ProductListAction CommandAction) { var products = CommandAction.Execute(); List <string[]> aa = new List <string[]>(); aa.Add(new string[] { "MaSP", "Nhóm SP", "Tên SP", "Giá", "Barcode", "Số lượng" }); products.ForEach(delegate(dynamic a) { List <string> bb = new List <string>(); bb.Add(a.ProductId.ToString()); bb.Add(a.CategoryName.ToString()); bb.Add(a.ProductName.ToString()); bb.Add(a.Price.ToString()); bb.Add(a.Barcode.ToString()); bb.Add(a.Qty.ToString()); aa.Add(bb.ToArray()); }); var rs = aa.ToArray(); return(JsonExpando(rs)); }
// public void ExportExcel(ProductListAction CommandAction) { this.ViewBag.Result = CommandAction.Execute(); ExcelPackage pck = new ExcelPackage(); ExcelWorksheet ws = pck.Workbook.Worksheets.Add("Report"); ws.Cells["A1"].Value = "Title"; ws.Cells["B1"].Value = "Title"; ws.Cells["A2"].Value = "Table"; ws.Cells["B2"].Value = "Product"; ws.Cells["A3"].Value = "Date"; ws.Cells["B3"].Value = string.Format("{0:dd MMM yyyy} at {0:H: mm tt};", DateTimeOffset.Now); ws.Cells["A6"].Value = "Mã"; ws.Cells["B6"].Value = "Tên nhà cung cấp"; ws.Cells["C6"].Value = "Giá"; ws.Cells["D6"].Value = "Barcode"; int rowStart = 7; foreach (var item in this.ViewBag.Result) { ws.Cells[string.Format("A{0}", rowStart)].Value = item.ProductId; ws.Cells[string.Format("B{0}", rowStart)].Value = item.ProductName; ws.Cells[string.Format("C{0}", rowStart)].Value = item.Price; ws.Cells[string.Format("D{0}", rowStart)].Value = item.Barcode; rowStart++; } ws.Cells["A:AZ"].AutoFitColumns(); Response.Clear(); Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; Response.AddHeader("content-disposition", "attachment: filename=" + "ExcelReport.xlsx"); Response.BinaryWrite(pck.GetAsByteArray()); Response.End(); }
public ActionResult PrintBarCode(ProductListAction CommandAction) { this.ViewBag.Result = CommandAction.Execute(); return(View()); }