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 XTRankQueryController : Controller { // XTRankQueryService Service = new XTRankQueryService(); 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["txtPdlineNo"])) { condition++; _where += " and pdline_no= '" + Request["txtPdlineNo"].ToString().Trim() + "'"; } if (!string.IsNullOrEmpty(Request["txtProcessNo"])) { condition++; _where += " and process_no = '" + Request["txtProcessNo"].Trim() + "'"; } if (!string.IsNullOrEmpty(Request["txtTerminalNo"])) { condition++; _where += " and terminal_no = '" + Request["txtTerminalNo"].Trim() + "'"; } if (!string.IsNullOrEmpty(Request["txtPartType"])) { condition++; _where += " and part_type = '" + Request["txtPartType"].Trim() + "'"; } if (!string.IsNullOrEmpty(Request["txtAssemblyCode"])) { condition++; _where += " and assembly_code = '" + Request["txtAssemblyCode"].ToString() + "'"; } if (!string.IsNullOrEmpty(Request["txtLot"])) { condition++; _where += " and lot = '" + Request["txtLot"].Trim() + "'"; } if (!string.IsNullOrEmpty(Request["txtStartTime"])&& !string.IsNullOrEmpty(Request["txtEndTime"])) { condition++; _where += " and gtb2create_ymd+' '+gtb2create_hms >= '" + Request["txtStartTime"].Trim() + "'"; _where += " and gtb2create_ymd+' '+gtb2create_hms <= '" + Request["txtEndTime"].Trim() + "'"; } if (condition == 0) { _where += " and gtb2create_ymd+' '+gtb2create_hms >= '" + starttime + "'"; _where += " and gtb2create_ymd+' '+gtb2create_hms <= '" + endtime + "'"; } return _where; } /// /// 汇总 /// /// /// public ActionResult GetRankData(Pager pager) { _where = SetWhere(); int totalCount = 0; DataTable dtQuery = Service.GetRankData(_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(Pager pager, int a, String sort, String direction, String isPage) { int totalCount = 0; DataTable dataHt = Service.GetRankData(_where, pager, ref totalCount); HSSFWorkbook workbook = new HSSFWorkbook(); Stream outputStream = Response.OutputStream; HSSFSheet sheet = (HSSFSheet)workbook.CreateSheet("GTB2总成检测信息"); try { if (workbook != null) { HSSFRow headRow = (HSSFRow)sheet.CreateRow(0); headRow.CreateCell(0).SetCellValue("GTB2ID"); headRow.CreateCell(1).SetCellValue("产线号"); headRow.CreateCell(2).SetCellValue("工序号"); 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("产品SN"); headRow.CreateCell(11).SetCellValue("上料托盘号"); headRow.CreateCell(12).SetCellValue("下料托盘号"); headRow.CreateCell(13).SetCellValue("当日流水号"); headRow.CreateCell(14).SetCellValue("操作扭矩"); headRow.CreateCell(15).SetCellValue("顺最大扭矩波动"); headRow.CreateCell(16).SetCellValue("逆最大扭矩波动"); headRow.CreateCell(17).SetCellValue("换向操作空行程"); headRow.CreateCell(18).SetCellValue("检测结果"); headRow.CreateCell(19).SetCellValue("同步日期"); headRow.CreateCell(20).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]["gtb2_id"].ToString()); dataRow.CreateCell(1).SetCellValue(dataHt.Rows[i]["pdline_no"].ToString()); dataRow.CreateCell(2).SetCellValue(dataHt.Rows[i]["process_no"].ToString()); dataRow.CreateCell(3).SetCellValue(dataHt.Rows[i]["terminal_no"].ToString()); dataRow.CreateCell(4).SetCellValue(dataHt.Rows[i]["facility_no"].ToString()); dataRow.CreateCell(5).SetCellValue(dataHt.Rows[i]["facility_name"].ToString()); dataRow.CreateCell(6).SetCellValue(dataHt.Rows[i]["jig_no"].ToString()); dataRow.CreateCell(7).SetCellValue(dataHt.Rows[i]["part_type"].ToString()); dataRow.CreateCell(8).SetCellValue(dataHt.Rows[i]["lot"].ToString()); dataRow.CreateCell(9).SetCellValue(dataHt.Rows[i]["finish_time"].ToString()); dataRow.CreateCell(10).SetCellValue(dataHt.Rows[i]["assembly_code"].ToString()); dataRow.CreateCell(11).SetCellValue(dataHt.Rows[i]["inpdline_try_no"].ToString()); dataRow.CreateCell(12).SetCellValue(dataHt.Rows[i]["outpdline_try_no"].ToString()); dataRow.CreateCell(13).SetCellValue(dataHt.Rows[i]["day_seq"].ToString()); dataRow.CreateCell(14).SetCellValue(dataHt.Rows[i]["work_torque"].ToString()); dataRow.CreateCell(15).SetCellValue(dataHt.Rows[i]["obey_max_keyundulate"].ToString()); dataRow.CreateCell(16).SetCellValue(dataHt.Rows[i]["reverse_max_keyundulate"].ToString()); dataRow.CreateCell(17).SetCellValue(dataHt.Rows[i]["reverse_work_route"].ToString()); dataRow.CreateCell(18).SetCellValue(dataHt.Rows[i]["detection_result"].ToString()); dataRow.CreateCell(19).SetCellValue(dataHt.Rows[i]["gtb2create_ymd"].ToString()); dataRow.CreateCell(20).SetCellValue(dataHt.Rows[i]["gtb2create_hms"].ToString()); } Response.Clear(); workbook.Write(outputStream); Response.Buffer = true; Response.AppendHeader("Content-Disposition", "attachment;filename=GTB2总成检测信息_" + DateTime.Now.ToString("yyyy-MM-dd") + ".xls"); Response.ContentEncoding = System.Text.Encoding.UTF8; Response.ContentType = "application/vnd.ms-excel"; Response.Flush(); } catch (Exception e) { } finally { workbook = null; } return null; } } }