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; using Estsh.Web.Models; namespace Estsh.Core.Web.Controllers { /** * 客户产线对应关系 * * NOAH * */ public class CustPdlineDefineController : Controller { private CustPdlineDefineService service = new CustPdlineDefineService(); // // 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 getCustPdlineListByPage(String customer_name_search, String cust_pdline_name_search, String type_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.getCustPdlineListByPage(customer_name_search,cust_pdline_name_search, type_name_search, enabled_search, pager, direction, sort); result.Add("rows", menuList); int total = this.service.getMenuCount(customer_name_search,cust_pdline_name_search, type_name_search, enabled_search); result.Add("pager.totalRows", total); result.Add("sort", sort); result.Add("direction", direction); return Json(result); } /// /// 保存菜单数据 /// /// public ActionResult saveCustPdline() { Hashtable result = new Hashtable(); String message = ""; String editType = Request["editType"].ToString(); String cust_pdline_id = Request["cust_pdline_id"].ToString(); String customer_id = Request["customer_id"].ToString(); String cust_pdline_desc = Request["cust_pdline_desc"].ToString(); String cust_pdline_name = Request["cust_pdline_name"].ToString(); String type_id = Request["type_id"].ToString(); String enabled = Request["enabled"].ToString(); //传递要更新的数据库字段 2013 0507 14:05 by NOAH Hashtable htParams = new Hashtable(); htParams.Add("@customer_id", customer_id); htParams.Add("@cust_pdline_desc", cust_pdline_desc); htParams.Add("@cust_pdline_name", cust_pdline_name); htParams.Add("@tray_type_id", type_id); htParams.Add("@enabled", enabled); //用户id UserInfo user = (UserInfo)Session["loginedUser"]; htParams.Add("@update_userid", user.updateUserId); htParams.Add("@create_userid", user.updateUserId); if (editType != null && editType.Trim().Equals("edit")) { try { htParams.Add("@cust_pdline_id",cust_pdline_id); this.service.updateCustPdline(htParams); message = "修改成功"; } catch (Exception e) { message = "修改失败!"; } } else { try { htParams.Add("@cust_pdline_id", cust_pdline_id); this.service.saveCustPdline(htParams); message = "添加成功"; } catch (Exception e) { message = "添加失败!"; } } result.Add("message", message); return Json(result) ; } /// /// 查看菜单详情 /// /// /// public ActionResult getCustPdlineDetail(String cust_pdline_id) { Hashtable ht = this.service.getCustPdlineDetail(cust_pdline_id); ViewData.Add("cust_pdline_id", ht["cust_pdline_id"]); ViewData.Add("cust_pdline_name", ht["cust_pdline_name"]); ViewData.Add("cust_pdline_desc", ht["cust_pdline_desc"]); ViewData.Add("customer_id", ht["customer_id"]); ViewData.Add("customer_name", ht["customer_name"]); ViewData.Add("type_name", ht["type_name"]); ViewData.Add("type_id", ht["type_id"]); ViewData.Add("tray_type_id", ht["tray_type_id"]); ViewData.Add("enabled", ht["enabled"]); return View("~/Views/CustPdlineDefine/ViewCustPdlineDefine.aspx"); } /// /// 编辑菜单 /// /// /// public ActionResult editCustPdline(String cust_pdline_id) { Hashtable ht = this.service.getCustPdlineDetail(cust_pdline_id); ViewData.Add("editType", "edit"); ViewData.Add("cust_pdline_id", ht["cust_pdline_id"]); ViewData.Add("cust_pdline_name", ht["cust_pdline_name"]); ViewData.Add("cust_pdline_desc", ht["cust_pdline_desc"]); ViewData.Add("customer_id", ht["customer_id"]); ViewData.Add("customer_name", ht["customer_name"]); ViewData.Add("type_name", ht["type_name"]); ViewData.Add("type_id", ht["type_id"]); ViewData.Add("tray_type_id", ht["tray_type_id"]); ViewData.Add("enabled", ht["enabled"]); return View("~/Views/CustPdlineDefine/EditCustPdlineDefine.aspx"); } /// /// 删除菜单 /// /// /// public ActionResult deleteCustPdline(String ids) { int delCount = 0; try { delCount = this.service.deleteCustPdline(ids); } catch(Exception e) { delCount = -1; } Hashtable result = new Hashtable(); result.Add("status", delCount); return Json(result); } /// /// 获取 产线 信息 /// BY NOAH /// /// public ActionResult getTypeName() { Hashtable result = new Hashtable(); ArrayList menuList = this.service.getTypeName(); result.Add("list", menuList); return Json(result, JsonRequestBehavior.AllowGet); } /// /// 获取 客户产线 信息 /// BY NOAH /// /// public ActionResult getCustName() { Hashtable result = new Hashtable(); ArrayList menuList = this.service.getCustName(); 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 customer_name_search,String cust_pdline_name_search, String type_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(customer_name_search,cust_pdline_name_search, type_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("客户产线描述"); headRow.CreateCell(5).SetCellValue("料架类型名称"); headRow.CreateCell(6).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]["customer_id"].ToString()); dataRow.CreateCell(1).SetCellValue(dataHt.Rows[i]["customer_name"].ToString()); dataRow.CreateCell(2).SetCellValue(dataHt.Rows[i]["cust_pdline_id"].ToString()); dataRow.CreateCell(3).SetCellValue(dataHt.Rows[i]["cust_pdline_name"].ToString()); dataRow.CreateCell(4).SetCellValue(dataHt.Rows[i]["cust_pdline_desc"].ToString()); dataRow.CreateCell(4).SetCellValue(dataHt.Rows[i]["type_name"].ToString()); dataRow.CreateCell(5).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; } } }