using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using Estsh.Web.Service; using System.Data; using System.Collections; using NPOI.HSSF.UserModel; using System.IO; using Estsh.Web.Util; namespace Estsh.Core.Web.Controllers { public class StepUnlockController : Controller { StepUnlockService completeSetService = new StepUnlockService(); // // GET: /Menu/ public ActionResult Index() { return View(); } public ActionResult GetTerminalName() { Hashtable resault = new Hashtable(); ArrayList list = completeSetService.GetTerminalName(); resault.Add("list", list); return Json(resault, JsonRequestBehavior.AllowGet); } /// /// 获取列表数据 /// /// 菜单名称 /// 分页 /// 排序方式 /// 排序列 /// public ActionResult getShippingListByPage(String txtStartTime, String txtEndTime, String shipping_sn,string cbTerminalName,string ifProduct, Pager pager) { Hashtable result = new Hashtable(); Hashtable dataHt = this.completeSetService.getShippingListByPage(txtStartTime, txtEndTime, shipping_sn,cbTerminalName,ifProduct, pager); result.Add("rows", dataHt["dataList"]); result.Add("pager.totalRows", dataHt["totalCount"]); return Json(result); } /// /// 导出数据到Excel /// /// /// /// /// /// /// public ActionResult exportData(String txtStartTime, String txtEndTime, String shipping_sn, Pager pager, String sort, String direction, String isPage) { Boolean paging = false; if (isPage == null || "".Equals(isPage)) { paging = false; } else { if ("1".Equals(isPage.Trim())) { paging = true; } else { paging = false; } } DataTable dataHt = this.completeSetService.getShippingExport(txtStartTime, txtEndTime, shipping_sn, pager); HSSFWorkbook workbook = new HSSFWorkbook(); Stream outputStream = Response.OutputStream; HSSFSheet sheet = (HSSFSheet)workbook.CreateSheet("工步解锁查询"); try { if (workbook != null) { HSSFRow headRow = (HSSFRow)sheet.CreateRow(0); headRow.CreateCell(0).SetCellValue("条码"); headRow.CreateCell(1).SetCellValue("工位"); headRow.CreateCell(2).SetCellValue("车号"); headRow.CreateCell(3).SetCellValue("解锁名称"); headRow.CreateCell(6).SetCellValue("日期"); headRow.CreateCell(7).SetCellValue("时间"); } for (int i = 0; i < dataHt.Rows.Count; i++) { int row = i + 1; HSSFRow dataRow = (HSSFRow)sheet.CreateRow(row); dataRow.CreateCell(0).SetCellValue(dataHt.Rows[i]["serial_number"].ToString()); dataRow.CreateCell(1).SetCellValue(dataHt.Rows[i]["terminal_name"].ToString()); dataRow.CreateCell(2).SetCellValue(dataHt.Rows[i]["car_no"].ToString()); dataRow.CreateCell(3).SetCellValue(dataHt.Rows[i]["remark"].ToString()); dataRow.CreateCell(6).SetCellValue(dataHt.Rows[i]["create_ymd"].ToString()); dataRow.CreateCell(7).SetCellValue(dataHt.Rows[i]["create_hms"].ToString()); } Response.Clear(); workbook.Write(outputStream); Response.Buffer = true; Response.AppendHeader("Content-Disposition", "attachment;filename=工步解锁查询.xls"); Response.ContentEncoding = System.Text.Encoding.UTF8; Response.ContentType = "application/vnd.ms-excel"; Response.Flush(); } catch (Exception e) { } finally { workbook = null; } return null; } } }