using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using Estsh.BLL; using System.Collections; using System.Data; using Estsh.Web.Util; using System.IO; using Estsh.Web.Service; using NPOI.HSSF.UserModel; namespace Estsh.Core.Web.Controllers { public class YYEdiShipController : Controller { // YYEdiShipService Service = new YYEdiShipService(); public ActionResult Index() { return View(); } string _where = ""; public string SetWhere() { int condition = 0; _where = ""; DateTime startDate = Request.RequestContext.HttpContext.Timestamp.AddDays(-1); DateTime endDate = Request.RequestContext.HttpContext.Timestamp; string starttime = startDate.ToString("yyyy-MM-dd HH:mm:ss"); string endtime = endDate.ToString("yyyy-MM-dd HH:mm:ss"); if (!string.IsNullOrEmpty(Request["txtOrderNo"])) { condition++; _where += " and a.order_no= '" + Request["txtOrderNo"].ToString().Trim() + "'"; } if (!string.IsNullOrEmpty(Request["txtPartNo"])) { condition++; _where += " and c.part_no = '" + Request["txtPartNo"].Trim() + "'"; } if (!string.IsNullOrEmpty(Request["txtCSN"])) { condition++; _where += " and a.csn = '" + Request["txtCSN"].Trim() + "'"; } if (!string.IsNullOrEmpty(Request["txtVIN"])) { condition++; _where += " and m.vin = '" + Request["txtVIN"].Trim() + "'"; } if (!string.IsNullOrEmpty(Request["txtSN"])) { condition++; //lvf 2021-02-02 调整like语法拼接字符串的问题 //lvf 20210616 处理#字符,避免字符串被截断 _where += " and a.serial_number like '%" + Request["txtSN"].Trim().Replace("|", "#") + "%' "; } if (!string.IsNullOrEmpty(Request["txtStartTime"])&& !string.IsNullOrEmpty(Request["txtEndTime"])) { condition++; _where += " and a.create_ymd+' '+a.create_hms >= '" + Request["txtStartTime"].Trim() + "'"; _where += " and a.create_ymd+' '+a.create_hms <= '" + Request["txtEndTime"].Trim() + "'"; } if (condition == 0) { _where += " and a.create_ymd+' '+a.create_hms >= '" + starttime + "'"; _where += " and a.create_ymd+' '+a.create_hms <= '" + endtime + "'"; } return _where; } /// /// 汇总 /// /// /// public ActionResult GetYYEDIShipData(Pager pager) { _where = SetWhere(); int totalCount = 0; DataTable dtQuery = Service.GetYYEDIShipData(_where, pager, ref totalCount); Hashtable result = new Hashtable(); result.Add("rows", DataTypeConvert.NewObject.DataTableToArrayList(dtQuery)); result.Add("pager.totalRows", totalCount); return Json(result); } /// /// 车型 /// /// public ActionResult GetTypeName() { Hashtable ht = new Hashtable(); ArrayList alType = Service.GetTypeName(); ht.Add("list", alType); return Json(ht, JsonRequestBehavior.AllowGet); } /// /// 配置 /// /// /// public ActionResult GetModelName(string typeName) { Hashtable ht = new Hashtable(); ArrayList alModel = Service.GetModelName(typeName); ht.Add("list", alModel); return Json(ht, JsonRequestBehavior.AllowGet); } /// /// 导出数据 /// /// /// /// /// /// /// public ActionResult exportData(String txtStartTime, String txtEndTime, String txtOrderNo, String txtPartNo, String txtCSN, String txtSN, Pager pager, int a, String sort, String direction, String isPage, string vin) { int totalCount = 0; _where = SetWhere(); DataTable dataHt = Service.GetYYEDIShipData(_where, pager, ref totalCount); HSSFWorkbook workbook = new HSSFWorkbook(); Stream outputStream = Response.OutputStream; HSSFSheet sheet = (HSSFSheet)workbook.CreateSheet("EDI发运信息"); try { if (workbook != null) { HSSFRow headRow = (HSSFRow)sheet.CreateRow(0); headRow.CreateCell(0).SetCellValue("发运单号"); headRow.CreateCell(1).SetCellValue("CSN号"); headRow.CreateCell(2).SetCellValue("VIN码"); headRow.CreateCell(3).SetCellValue("车型"); headRow.CreateCell(4).SetCellValue("配置"); headRow.CreateCell(5).SetCellValue("零件号"); headRow.CreateCell(6).SetCellValue("客户零件号"); headRow.CreateCell(7).SetCellValue("零件描述"); headRow.CreateCell(8).SetCellValue("座椅条码"); headRow.CreateCell(9).SetCellValue("状态"); headRow.CreateCell(10).SetCellValue("发运日期"); headRow.CreateCell(11).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]["order_no"].ToString()); dataRow.CreateCell(1).SetCellValue(dataHt.Rows[i]["csn"].ToString()); dataRow.CreateCell(2).SetCellValue(dataHt.Rows[i]["vin"].ToString()); dataRow.CreateCell(3).SetCellValue(dataHt.Rows[i]["type_name"].ToString()); dataRow.CreateCell(4).SetCellValue(dataHt.Rows[i]["model_name"].ToString()); dataRow.CreateCell(5).SetCellValue(dataHt.Rows[i]["part_no"].ToString()); dataRow.CreateCell(6).SetCellValue(dataHt.Rows[i]["part_no_3c"].ToString()); dataRow.CreateCell(7).SetCellValue(dataHt.Rows[i]["part_spec"].ToString()); dataRow.CreateCell(8).SetCellValue(dataHt.Rows[i]["serial_number"].ToString()); dataRow.CreateCell(9).SetCellValue(dataHt.Rows[i]["status"].ToString()); dataRow.CreateCell(10).SetCellValue(dataHt.Rows[i]["create_ymd"].ToString()); dataRow.CreateCell(11).SetCellValue(dataHt.Rows[i]["create_hms"].ToString()); } Response.Clear(); workbook.Write(outputStream); Response.Buffer = true; Response.AppendHeader("Content-Disposition", "attachment;filename=物料排序扫描信息_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + ".xls"); Response.ContentEncoding = System.Text.Encoding.UTF8; Response.ContentType = "application/vnd.ms-excel"; Response.Flush(); } catch (Exception e) { } finally { workbook = null; } return null; } } }