|
|
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 PrintVendorDefineController : Controller
|
|
|
{
|
|
|
private PrintVendorDefineService service = new PrintVendorDefineService();
|
|
|
|
|
|
//
|
|
|
// GET: /Menu/
|
|
|
public ActionResult Index()
|
|
|
{
|
|
|
return View();
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 加载功能树
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
public ActionResult getMenuTree()
|
|
|
{
|
|
|
string path = Request.ApplicationPath; if (path.EndsWith("/")) { path = path.Substring(0, path.Length - 1); }
|
|
|
List<TreeNode> treeNodes = new List<TreeNode>();
|
|
|
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);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取菜单管理列表数据
|
|
|
/// </summary>
|
|
|
/// <param name="menuName"></param>
|
|
|
/// <param name="pager"></param>
|
|
|
/// <param name="direction"></param>
|
|
|
/// <param name="sort"></param>
|
|
|
/// <returns></returns>
|
|
|
public ActionResult getPrintVendorListByPage(String part_on, String vendorID, Pager pager, String direction, String sort)
|
|
|
{
|
|
|
Hashtable result = new Hashtable();
|
|
|
result.Add("pager.pageNo", pager.pageNo);
|
|
|
ArrayList menuList = this.service.getKeyDataListByPage(part_on, vendorID, pager, direction, sort);
|
|
|
result.Add("rows", menuList);
|
|
|
int total = this.service.getMenuCount(part_on, vendorID);
|
|
|
result.Add("pager.totalRows", total);
|
|
|
result.Add("sort", sort);
|
|
|
result.Add("direction", direction);
|
|
|
return Json(result);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 保存菜单数据
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
public ActionResult savePrintVendor()
|
|
|
{
|
|
|
Hashtable result = new Hashtable();
|
|
|
String message = "";
|
|
|
string flag = "";
|
|
|
String editType = Request["editType"].ToString();
|
|
|
|
|
|
String ruid = Request["ruid"].ToString();
|
|
|
String part_no = Request["part_no"].ToString();
|
|
|
if (!this.service.isExsitPart_no(part_no))
|
|
|
{
|
|
|
message = "零件号不存在!";
|
|
|
flag = "NO";
|
|
|
result.Add("message", message);
|
|
|
result.Add("flag", flag);
|
|
|
return Json(result);
|
|
|
}
|
|
|
|
|
|
String vendor_id = Request["vendor_id"].ToString();
|
|
|
String enabled = Request["enabled"].ToString();
|
|
|
String group_id = Request["group_id"].ToString();
|
|
|
|
|
|
|
|
|
Hashtable htParams = new Hashtable();
|
|
|
htParams.Add("@ruid", ruid);
|
|
|
htParams.Add("@part_no", part_no);
|
|
|
htParams.Add("@vendor_id", vendor_id);
|
|
|
htParams.Add("@enable", enabled);
|
|
|
htParams.Add("@group_id", group_id);
|
|
|
|
|
|
//用户id
|
|
|
UserInfo user = (UserInfo)Session["loginedUser"];
|
|
|
htParams.Add("@update_userid", user.empId);
|
|
|
htParams.Add("@create_userid", user.empId);
|
|
|
|
|
|
if (editType != null && editType.Trim().Equals("edit"))
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
|
|
|
this.service.updatePrintVendor(htParams);
|
|
|
message = "修改成功";
|
|
|
flag = "OK";
|
|
|
}
|
|
|
catch (Exception e)
|
|
|
{
|
|
|
message = "修改失败!";
|
|
|
flag = "NO";
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
|
|
|
this.service.savePrintVendor(htParams);
|
|
|
message = "添加成功";
|
|
|
flag = "OK";
|
|
|
}
|
|
|
catch (Exception e)
|
|
|
{
|
|
|
message = "添加失败!";
|
|
|
flag = "NO";
|
|
|
}
|
|
|
}
|
|
|
result.Add("message", message);
|
|
|
result.Add("flag",flag);
|
|
|
return Json(result) ;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// 编辑菜单
|
|
|
/// </summary>
|
|
|
/// <param name="keydata_id"></param>
|
|
|
/// <returns></returns>
|
|
|
public ActionResult editPrintVendor(String ruid)
|
|
|
{
|
|
|
Hashtable ht = this.service.getPrintVendorDetail(ruid);
|
|
|
ViewData.Add("editType", "edit");
|
|
|
|
|
|
ViewData.Add("ruid", ruid);
|
|
|
ViewData.Add("part_no", ht["part_no"]);
|
|
|
ViewData.Add("group_id", ht["group_id"]);
|
|
|
ViewData.Add("vendor_id", ht["vendor_id"]);
|
|
|
ViewData.Add("enabled", ht["enabled"]);
|
|
|
return View("~/Views/PrintVendorDefine/EditPrintVendorDefine.aspx");
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 删除菜单
|
|
|
/// </summary>
|
|
|
/// <param name="ids"></param>
|
|
|
/// <returns></returns>
|
|
|
public ActionResult deletePrintVendor(String ids)
|
|
|
{
|
|
|
int delCount = 0;
|
|
|
try
|
|
|
{
|
|
|
delCount = this.service.deletePrintVendor(ids);
|
|
|
}
|
|
|
catch(Exception e)
|
|
|
{
|
|
|
delCount = -1;
|
|
|
}
|
|
|
Hashtable result = new Hashtable();
|
|
|
result.Add("status", delCount);
|
|
|
return Json(result);
|
|
|
}
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// 判断是否为数字类型
|
|
|
/// BY NOAH
|
|
|
/// </summary>
|
|
|
/// <param name="s"></param>
|
|
|
/// <returns></returns>
|
|
|
public bool isNum(string s)
|
|
|
{
|
|
|
string pattern = "^[0-9]*$";
|
|
|
Regex rx = new Regex(pattern);
|
|
|
return rx.IsMatch(s);
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 导出数据到Excel
|
|
|
/// BY NOAH
|
|
|
/// </summary>
|
|
|
/// <param name="pager"></param>
|
|
|
/// <param name="txtOrderNo"></param>
|
|
|
/// <param name="sort"></param>
|
|
|
/// <param name="direction"></param>
|
|
|
/// <param name="isPage"></param>
|
|
|
/// <returns></returns>
|
|
|
public ActionResult exportData(String part_on, String vendorID, 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(part_on, vendorID, 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("供应商ID");
|
|
|
headRow.CreateCell(2).SetCellValue("分组");
|
|
|
headRow.CreateCell(3).SetCellValue("是否启用(Y or N)");
|
|
|
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]["part_no"].ToString());
|
|
|
dataRow.CreateCell(1).SetCellValue(dataHt.Rows[i]["vendor_id"].ToString());
|
|
|
dataRow.CreateCell(2).SetCellValue(dataHt.Rows[i]["group_id"].ToString());
|
|
|
dataRow.CreateCell(3).SetCellValue(dataHt.Rows[i]["enabled"].ToString());
|
|
|
dataRow.CreateCell(4).SetCellValue(dataHt.Rows[i]["vendor_name"].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;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 导入Excel文件
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
public ActionResult importPrintVendor()
|
|
|
{
|
|
|
Hashtable result = new Hashtable();
|
|
|
HttpPostedFileBase userDataFile = Request.Files[0];
|
|
|
UserInfo user = (UserInfo)Session["loginedUser"];
|
|
|
if (userDataFile == null)
|
|
|
{
|
|
|
return null;
|
|
|
}
|
|
|
result = service.ReadExcelFile(userDataFile.InputStream, user.empId);
|
|
|
return Json(result);
|
|
|
}
|
|
|
}
|
|
|
}
|