You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

314 lines
11 KiB
C#

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
{
/*****************************************************************
*
* 客户零件号关系管理
*
* Fred
*
******************************************************************/
public class GPartRelationDefineController : Controller
{
private GPartRelationDefineService service = new GPartRelationDefineService();
//
// 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 getDataListByPage(String part_no_search, Pager pager, String direction, String sort)
{
Hashtable result = new Hashtable();
result.Add("pager.pageNo", pager.pageNo);
ArrayList menuList = this.service.getDataListByPage(part_no_search, pager, direction, sort);
result.Add("rows", menuList);
int total = this.service.getMenuCount(part_no_search);
result.Add("pager.totalRows", total);
result.Add("sort", sort);
result.Add("direction", direction);
return Json(result);
}
/// <summary>
/// 保存菜单数据
/// </summary>
/// <returns></returns>
public ActionResult saveData()
{
Hashtable result = new Hashtable();
String message = "";
string flag = "";
String editType = Request["editType"].ToString();
String ruid = Request["ruid"].ToString();
int model_id = this.service.getModelID(Request["model_name"].ToString());
if (model_id == 0)
{
result.Add("message", "配置名称不存在!");
result.Add("flag", "NO");
return Json(result);
}
int part_id = this.service.getpartID(Request["part_no"].ToString());
if (part_id == 0)
{
result.Add("message", "总成名称不存在!");
result.Add("flag", "NO");
return Json(result);
}
String cust_part_no = Request["cust_part_no"].ToString();
//传递要更新的数据库字段 2013 0506 14:05 by NOAH
Hashtable htParams = new Hashtable();
htParams.Add("@model_id", model_id);
htParams.Add("@part_id", part_id);
htParams.Add("@cust_part_no", cust_part_no);
//用户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("@ruid", ruid);
this.service.updateData(htParams);
message = "修改成功";
flag = "OK";
}
catch (Exception e)
{
message = "修改失败!";
flag = "NO";
}
}
else
{
try
{
DataTable dt = this.service.checkExist(model_id, part_id, cust_part_no);
if (dt.Rows.Count >= 1)
{
result.Add("message", "信息已存在,请勿重复添加!");
result.Add("flag", "NO");
return Json(result);
}
htParams.Add("@ruid", ruid);
this.service.saveData(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 getDataDetail(String ruid)
{
Hashtable ht = this.service.getDataDetail(ruid);
ViewData.Add("model_name", ht["model_name"]);
ViewData.Add("part_no", ht["part_no"]);
ViewData.Add("part_spec", ht["part_spec"]);
ViewData.Add("cust_part_no", ht["cust_part_no"]);
return View("~/Views/GPartRelationDefine/ViewGPartRelationDefine.aspx");
}
/// <summary>
/// 编辑菜单
/// </summary>
/// <param name="keydata_id"></param>
/// <returns></returns>
public ActionResult editData(String ruid)
{
Hashtable ht = this.service.getDataDetail(ruid);
ViewData.Add("editType", "edit");
ViewData.Add("ruid", ht["ruid"]);
ViewData.Add("model_name", ht["model_name"]);
ViewData.Add("part_no", ht["part_no"]);
ViewData.Add("part_spec", ht["part_spec"]);
ViewData.Add("cust_part_no", ht["cust_part_no"]);
return View("~/Views/GPartRelationDefine/EditGPartRelationDefine.aspx");
}
/// <summary>
/// 删除菜单
/// </summary>
/// <param name="ids"></param>
/// <returns></returns>
public ActionResult deleteData(String ids)
{
int delCount = 0;
try
{
delCount = this.service.deleteData(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
/// </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_no_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(part_no_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("客户零件号");
}
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]["model_name"].ToString());
dataRow.CreateCell(1).SetCellValue(dataHt.Rows[i]["part_no"].ToString());
dataRow.CreateCell(2).SetCellValue(dataHt.Rows[i]["part_spec"].ToString());
dataRow.CreateCell(3).SetCellValue(dataHt.Rows[i]["cust_part_no"].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 importData()
{
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);
}
}
}