using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using Estsh.Web.Util; using Estsh.Web.Service; using System.Collections; using System.Text.RegularExpressions; using System.Data; using NPOI.HSSF.UserModel; using System.IO; namespace Estsh.Core.Web.Controllers { /**************************************************************** * * 看板产线关系 * * NOAH * ****************************************************************/ public class ViewBoardPdlineDefineController : Controller { private ViewBoardPdlineDefineService service = new ViewBoardPdlineDefineService(); // // GET: /Menu/ public ActionResult Index() { return View(); } /// /// 加载功能树 /// /// public ActionResult getMenuTree() { string path = Request.ApplicationPath; if (path.EndsWith("/")) { path = path.Substring(0, path.Length - 1); } List treeNodes = new List(); treeNodes = service.getMenuList("isIndex = '是'", " RUID ASC ", path); Hashtable result = new Hashtable(); result.Add("treeNodes", treeNodes); String json = Estsh.Web.Util.JSON.Encode(result); return Json(result, JsonRequestBehavior.AllowGet); } /// /// 获取菜单管理列表数据 /// /// /// /// /// /// public ActionResult getViewBoardPdlineListByPage(String view_board_name_search, String pdline_name_search, String enabled_search, Pager pager, String direction, String sort) { Hashtable result = new Hashtable(); result.Add("pager.pageNo", pager.pageNo); ArrayList menuList = this.service.getViewBoardPdlineListByPage(view_board_name_search, pdline_name_search, enabled_search, pager, direction, sort); result.Add("rows", menuList); int total = this.service.getMenuCount(view_board_name_search, pdline_name_search, enabled_search); result.Add("pager.totalRows", total); result.Add("sort", sort); result.Add("direction", direction); return Json(result); } /// /// 保存菜单数据 /// /// public ActionResult saveViewBoardPdline() { Hashtable result = new Hashtable(); String message = ""; String flag = ""; String editType = Request["editType"].ToString(); String view_board_id = Request["view_board_id"].ToString(); //String view_board_name = Request["view_board_name"].ToString(); String pdline_id = Request["pdline_id"].ToString(); //String pdline_desc = Request["pdline_desc"].ToString(); String enabled = Request["enabled"].ToString(); String guid = Request["guid"].ToString(); //传递要更新的数据库字段 2013 0502 14:05 by NOAH Hashtable htParams = new Hashtable(); //htParams.Add("@view_board_name", view_board_name); htParams.Add("@pdline_id", pdline_id); //htParams.Add("@pdline_desc", pdline_desc); htParams.Add("@enabled", enabled); if (editType != null && editType.Trim().Equals("edit")) { try { htParams.Add("@guid",guid); htParams.Add("@view_board_id", view_board_id); this.service.updateViewBoardPdline(htParams); message = "修改成功"; flag = "OK"; } catch (Exception e) { message = "修改失败!"; flag = "NO"; } } else { try { htParams.Add("@view_board_id", view_board_id); this.service.saveViewBoardPdline(htParams); message = "添加成功"; flag = "OK"; } catch (Exception e) { message = "添加失败!"; flag = "NO"; } } result.Add("message", message); result.Add("flag", flag); return Json(result) ; } /// /// 查看菜单详情 /// /// /// public ActionResult getViewBoardPdlineDetail(String view_board_id) { Hashtable ht = this.service.getViewBoardPdlineDetail(view_board_id); ViewData.Add("view_board_id",ht["view_board_id"]); ViewData.Add("view_board_name", ht["view_board_name"]); ViewData.Add("pdline_name", ht["pdline_name"]); ViewData.Add("pdline_id", ht["pdline_id"]); ViewData.Add("pdline_desc", ht["pdline_desc"]); ViewData.Add("enabled", ht["enabled"]); ViewData.Add("guid", ht["guid"]); return View("~/Views/ViewBoardPdlineDefine/ViewViewBoardPdlineDefine.aspx"); } /// /// 编辑菜单 /// /// /// public ActionResult editViewBoardPdline(String guid) { Hashtable ht = this.service.getViewBoardPdlineDetail(guid); ViewData.Add("editType", "edit"); ViewData.Add("view_board_id", ht["view_board_id"]); ViewData.Add("view_board_name", ht["view_board_name"]); ViewData.Add("pdline_name", ht["pdline_name"]); ViewData.Add("pdline_id", ht["pdline_id"]); ViewData.Add("pdline_desc", ht["pdline_desc"]); ViewData.Add("enabled", ht["enabled"]); ViewData.Add("guid", ht["guid"]); return View("~/Views/ViewBoardPdlineDefine/EditViewBoardPdlineDefine.aspx"); } /// /// 删除菜单 /// /// /// public ActionResult deleteViewBoardPdline(String ids) { int delCount = 0; try { delCount = this.service.deleteViewBoardPdline(ids); } catch(Exception e) { delCount = -1; } Hashtable result = new Hashtable(); result.Add("status", delCount); return Json(result); } /// /// 获取 站点 信息 /// BY NOAH /// /// public ActionResult getBoardName() { Hashtable result = new Hashtable(); ArrayList menuList = this.service.getBoardName(); result.Add("list", menuList); return Json(result, JsonRequestBehavior.AllowGet); } /// /// 获取 产线 信息 /// BY NOAH /// /// public ActionResult getPdlineName() { Hashtable result = new Hashtable(); ArrayList menuList = this.service.getPdlineName(); result.Add("list", menuList); return Json(result, JsonRequestBehavior.AllowGet); } /// /// 判断是否为数字类型 /// BY NOAH /// /// /// public bool isNum(string s) { string pattern = "^[0-9]*$"; Regex rx = new Regex(pattern); return rx.IsMatch(s); } /// /// 导出数据到Excel /// BY NOAH /// /// /// /// /// /// /// public ActionResult exportData(String view_board_name_search, String pdline_name_search, String enabled_search, 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.getTableListByPage(view_board_name_search, pdline_name_search, enabled_search, pager, direction, sort, paging);//txtOrderNo, pager, direction, sort, paging 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(4).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]["view_board_id"].ToString()); dataRow.CreateCell(1).SetCellValue(dataHt.Rows[i]["view_board_name"].ToString()); dataRow.CreateCell(2).SetCellValue(dataHt.Rows[i]["pdline_name"].ToString()); dataRow.CreateCell(3).SetCellValue(dataHt.Rows[i]["pdline_desc"].ToString()); dataRow.CreateCell(4).SetCellValue(dataHt.Rows[i]["enabled"].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; } } }