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 XTWorkplaceDefineController : Controller { XTWorkplaceDefineService service = new XTWorkplaceDefineService(); // // GET: /Menu/ public ActionResult Index() { return View(); } /// /// 客户产线集合 /// /// 数据集 public ActionResult GetTearmialName() { Hashtable resault = new Hashtable(); ArrayList list = service.GetTearmialName(); resault.Add("list", list); return Json(resault, JsonRequestBehavior.AllowGet); } /// /// 获取列表数据 /// /// 菜单名称 /// 分页 /// 排序方式 /// 排序列 /// public ActionResult getTerminalListByPage(String terminal_name, Pager pager, String direction, String sort) { if ((string.IsNullOrEmpty(terminal_name)) || terminal_name == "null") { terminal_name = "0"; } Hashtable result = new Hashtable(); result.Add("pager.pageNo", pager.pageNo); Hashtable dataHt = this.service.getTerminalListByPage(terminal_name, pager, direction, sort); result.Add("rows", dataHt["dataList"]); result.Add("pager.totalRows", dataHt["totalCount"]); result.Add("sort", sort); result.Add("direction", direction); return Json(result); } /// /// 保存菜单数据 /// /// public ActionResult saveModelType() { Hashtable result = new Hashtable(); String message = ""; String flag = ""; String editType = Request["editType"].ToString(); String ruid = Request["ruid"].ToString(); String edi_model_name = Request["edi_model_name"].ToString(); int model_id = this.service.GetModelID(Request["model_name"].ToString()); if (model_id == 0) { result.Add("message", "配置名称不存在!"); result.Add("flag", "Fail"); return Json(result); } //传递要更新的数据库字段 Hashtable htParams = new Hashtable(); htParams.Add("@edi_model_name", edi_model_name); htParams.Add("@model_id", model_id); if (editType != null && editType.Trim().Equals("edit")) { try { htParams.Add("@ruid", ruid); this.service.updateModelType(htParams); message = "修改成功"; flag = "OK"; } catch (Exception e) { message = "修改失败!"; flag = "Fail"; } } else { try { htParams.Add("@ruid", ruid); this.service.saveModelType(htParams); message = "添加成功"; flag = "OK"; } catch (Exception e) { message = "添加失败!"; flag = "Fail"; } } result.Add("message", message); result.Add("flag", flag); return Json(result); } /// /// 删除菜单 /// /// /// public ActionResult deleteModelType(String ids) { int delCount = 0; try { delCount = this.service.deleteModelType(ids); } catch (Exception e) { delCount = -1; } Hashtable result = new Hashtable(); result.Add("status", delCount); return Json(result); } public ActionResult getModelTypeDetail(String ruid) { Hashtable ht = this.service.getModelTypeDetail(ruid); ViewData.Add("ruid", ht["ruid"]); ViewData.Add("model_name", ht["model_name"]); ViewData.Add("edi_model_name", ht["edi_model_name"]); return View("~/Views/EDIRelationshipDefine/ViewEditEDIRelationship.aspx"); } public ActionResult editEDImodel(String ruid) { Hashtable ht = this.service.getModelTypeDetail(ruid); ViewData.Add("editType", "edit"); ViewData.Add("ruid", ht["ruid"]); ViewData.Add("model_name", ht["model_name"]); ViewData.Add("edi_model_name", ht["edi_model_name"]); return View("~/Views/EDIRelationshipDefine/EditEDIRelationshipDefine.aspx"); } /// /// 导出数据到Excel /// /// /// /// /// /// /// public ActionResult exportData(String model_name, String edi_model_name, 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.service.getShippingExport(model_name, edi_model_name, pager, direction, sort); 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("配置名称"); headRow.CreateCell(2).SetCellValue("EDI配置名称"); } 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]["ruid"].ToString()); dataRow.CreateCell(1).SetCellValue(dataHt.Rows[i]["model_name"].ToString()); dataRow.CreateCell(2).SetCellValue(dataHt.Rows[i]["edi_model_name"].ToString()); } Response.Clear(); workbook.Write(outputStream); Response.Buffer = true; Response.AppendHeader("Content-Disposition", "attachment;filename=EDI信息查询.xls"); Response.ContentEncoding = System.Text.Encoding.UTF8; Response.ContentType = "application/vnd.ms-excel"; Response.Flush(); } catch (Exception e) { } finally { workbook = null; } return null; } } }