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 ModelProdInfoDefineController : Controller
{
private ModelProdInfoDefineService service = new ModelProdInfoDefineService();
//
// 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 getModelProdInfoListByPage(String model_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.getModelProdInfoListByPage(model_name_search, enabled_search, pager, direction, sort);
result.Add("rows", menuList);
int total = this.service.getMenuCount(model_name_search, enabled_search);
result.Add("pager.totalRows", total);
result.Add("sort", sort);
result.Add("direction", direction);
return Json(result);
}
///
/// 保存菜单数据
///
///
public ActionResult saveModelProdInfo()
{
Hashtable result = new Hashtable();
String message = "";
String editType = Request["editType"].ToString();
String model_id = Request["model_id"].ToString();
//String model_name = Request["model_name"].ToString();
String print_barcode = Request["print_barcode"].ToString();
String print_tray_page = Request["print_tray_page"].ToString();
String print_insp_page = Request["print_insp_page"].ToString();
String barcode_template = Request["barcode_template"].ToString();
String insp_page_template = Request["insp_page_template"].ToString();
String tray_page_template = Request["tray_page_template"].ToString();
String fillPatter = Request["fillPatter"].ToString();
String bgcolor = Request["bgcolor"].ToString();
String forecolor = Request["forecolor"].ToString();
String insp_special_char = Request["insp_special_char"].ToString();
String Barcode_count = Request["Barcode_count"].ToString();
//String qa_label_count = Request["qa_label_count"].ToString();
String tray_page_count = Request["tray_page_count"].ToString();
String insp_page_count = Request["insp_page_count"].ToString();
String need_ab_data = Request["need_ab_data"].ToString();
String need_zkc_data = Request["need_zkc_data"].ToString();
String enabled = Request["enabled"].ToString();
//页面中的model_id
if (String.IsNullOrEmpty(model_id))
{
model_id = Request["model_id_bak"].ToString();
}
//if (String.IsNullOrEmpty(model_id))
//{
// message = "无可新增的配置!";
// result.Add("message", message);
// return Json(result);
//}
//检测 填充样式 前景色 背景色中的enmu_value
//if (String.IsNullOrEmpty(fillPatter) || String.IsNullOrEmpty(bgcolor) || String.IsNullOrEmpty(forecolor))
//{
// message = "填充样式,前景色,背景色不能为空!";
// result.Add("message", message);
// return Json(result);
//}
int fillPatter_enum_value = -1000;
int bgcolor_enum_value = -1000;
int forecolor_enum_value = -1000;
try
{
fillPatter_enum_value = Convert.ToInt32((getEnumValue("insp_page_fillpattern", fillPatter)).Rows[0][0].ToString());
bgcolor_enum_value = Convert.ToInt32((getEnumValue("sys_bgcolor", bgcolor)).Rows[0][0].ToString());
forecolor_enum_value = Convert.ToInt32((getEnumValue("sys_forecolor", forecolor)).Rows[0][0].ToString());
}
catch
{
message = "填充样式,前景色,背景色Enum值不正确!";
result.Add("message", message);
return Json(result);
}
//传递要更新的数据库字段 2013 0510 14:05 by NOAH
Hashtable htParams = new Hashtable();
htParams.Add("@print_barcode", print_barcode);
htParams.Add("@print_tray_page", print_tray_page);
htParams.Add("@print_insp_page", print_insp_page);
htParams.Add("@barcode_template", barcode_template);
htParams.Add("@insp_page_template", insp_page_template);
htParams.Add("@tray_page_template", tray_page_template);
htParams.Add("@insp_page_fillpattern", fillPatter_enum_value);
htParams.Add("@insp_page_bgcolor", bgcolor_enum_value);
htParams.Add("@insp_page_forecolor", forecolor_enum_value);
htParams.Add("@insp_special_char", insp_special_char);
htParams.Add("@Barcode_count", Barcode_count);
htParams.Add("@tray_page_count", tray_page_count);
htParams.Add("@insp_page_count", insp_page_count);
htParams.Add("@need_ab_data", need_ab_data);
htParams.Add("@need_zkc_data", need_zkc_data);
htParams.Add("@enabled", enabled);
//htParams.Add("@qa_label_count", qa_label_count);
//用户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("@model_id",model_id);
this.service.updateModelProdInfo(htParams);
message = "修改成功";
}
catch (Exception e)
{
message = "修改失败!";
}
}
else
{
try
{
htParams.Add("@model_id", model_id);
this.service.saveModelProdInfo(htParams);
message = "添加成功";
}
catch (Exception e)
{
message = "添加失败!";
}
}
result.Add("message", message);
return Json(result) ;
}
///
/// 查看菜单详情
///
///
///
public ActionResult getModelProdInfoDetail(String model_id)
{
Hashtable ht = this.service.getModelProdInfoDetail(model_id);
ViewData.Add("model_id", ht["model_id"]);
ViewData.Add("model_name", ht["model_name"]);
ViewData.Add("print_barcode", ht["print_barcode"]);
ViewData.Add("print_tray_page", ht["print_tray_page"]);
ViewData.Add("print_insp_page", ht["print_insp_page"]);
ViewData.Add("barcode_template", ht["barcode_template"]);
ViewData.Add("insp_page_template", ht["insp_page_template"]);
ViewData.Add("tray_page_template", ht["tray_page_template"]);
ViewData.Add("fillPatter", ht["fillPatter"]);
ViewData.Add("bgcolor", ht["bgcolor"]);
ViewData.Add("forecolor", ht["forecolor"]);
ViewData.Add("fillPatter_id", ht["fillPatter_id"]);
ViewData.Add("bgcolor_id", ht["bgcolor_id"]);
ViewData.Add("forecolor_id", ht["forecolor_id"]);
ViewData.Add("insp_special_char", ht["insp_special_char"]);
ViewData.Add("Barcode_count", ht["Barcode_count"]);
//ViewData.Add("qa_label_count", ht["qa_label_count"]);
ViewData.Add("tray_page_count", ht["tray_page_count"]);
ViewData.Add("insp_page_count", ht["insp_page_count"]);
ViewData.Add("need_ab_data", ht["need_ab_data"]);
ViewData.Add("need_zkc_data", ht["need_zkc_data"]);
//ViewData.Add("need_bxd_data", ht["need_bxd_data"]);
//ViewData.Add("need_zp_data", ht["need_zp_data"]);
//ViewData.Add("need_dgn_data", ht["need_dgn_data"]);
//ViewData.Add("need_ab_test", ht["need_ab_test"]);
ViewData.Add("enabled", ht["enabled"]);
return View("~/Views/ModelProdInfoDefine/ViewModelProdInfoDefine.aspx");
}
///
/// 编辑菜单
///
///
///
public ActionResult editModelProdInfo(String model_id)
{
Hashtable ht = this.service.getModelProdInfoDetail(model_id);
ViewData.Add("editType", "edit");
ViewData.Add("model_id", ht["model_id"]);
ViewData.Add("model_name", ht["model_name"]);
ViewData.Add("print_barcode", ht["print_barcode"]);
ViewData.Add("print_tray_page", ht["print_tray_page"]);
ViewData.Add("print_insp_page", ht["print_insp_page"]);
ViewData.Add("barcode_template", ht["barcode_template"]);
ViewData.Add("insp_page_template", ht["insp_page_template"]);
ViewData.Add("tray_page_template", ht["tray_page_template"]);
ViewData.Add("fillPatter", ht["fillPatter"]);
ViewData.Add("bgcolor", ht["bgcolor"]);
ViewData.Add("forecolor", ht["forecolor"]);
ViewData.Add("fillPatter_id", ht["fillPatter_id"]);
ViewData.Add("bgcolor_id", ht["bgcolor_id"]);
ViewData.Add("forecolor_id", ht["forecolor_id"]);
ViewData.Add("insp_special_char", ht["insp_special_char"]);
ViewData.Add("Barcode_count", ht["Barcode_count"]);
//ViewData.Add("qa_label_count", ht["qa_label_count"]);
ViewData.Add("tray_page_count", ht["tray_page_count"]);
ViewData.Add("insp_page_count", ht["insp_page_count"]);
ViewData.Add("need_ab_data", ht["need_ab_data"]);
ViewData.Add("need_zkc_data", ht["need_zkc_data"]);
//ViewData.Add("need_bxd_data", ht["need_bxd_data"]);
//ViewData.Add("need_zp_data", ht["need_zp_data"]);
//ViewData.Add("need_dgn_data", ht["need_dgn_data"]);
//ViewData.Add("need_ab_test", ht["need_ab_test"]);
ViewData.Add("enabled", ht["enabled"]);
return View("~/Views/ModelProdInfoDefine/EditModelProdInfoDefine.aspx");
}
///
/// 删除菜单
///
///
///
public ActionResult deleteModelProdInfo(String ids)
{
int delCount = 0;
try
{
delCount = this.service.deleteModelProdInfo(ids);
}
catch(Exception e)
{
delCount = -1;
}
Hashtable result = new Hashtable();
result.Add("status", delCount);
return Json(result);
}
///
/// 获取 配置名称
/// BY NOAH
///
///
public ActionResult getModelName()
{
Hashtable result = new Hashtable();
ArrayList menuList = this.service.getModelName();
result.Add("list", menuList);
return Json(result, JsonRequestBehavior.AllowGet);
}
///
/// 获取 填充样式
/// BY NOAH
///
///
public ActionResult getFillPatterName(String style)
{
Hashtable result = new Hashtable();
ArrayList menuList = this.service.getFillPatterName(style);
result.Add("list", menuList);
return Json(result, JsonRequestBehavior.AllowGet);
}
///
/// 获取 enum_value
/// BY NOAH
///
///
public DataTable getEnumValue(String enum_type, String enum_id)
{
return this.service.getEnumValue(enum_type, enum_id);
}
///
/// 导出数据到Excel
/// BY NOAH
///
///
///
///
///
///
///
public ActionResult exportData(String model_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(model_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("目视单模板文件");
headRow.CreateCell(7).SetCellValue("料架模板文件");
headRow.CreateCell(8).SetCellValue("填充样式");
headRow.CreateCell(9).SetCellValue("背景颜色");
headRow.CreateCell(10).SetCellValue("前景颜色");
headRow.CreateCell(11).SetCellValue("特殊标示符");
headRow.CreateCell(12).SetCellValue("条码打印张数");
headRow.CreateCell(13).SetCellValue("料架单打印张数");
headRow.CreateCell(14).SetCellValue("目视单打印张数");
headRow.CreateCell(15).SetCellValue("是否采集安全气囊扭矩");
headRow.CreateCell(16).SetCellValue("是否采集坐靠结合扭矩");
headRow.CreateCell(17).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_id"].ToString());
dataRow.CreateCell(1).SetCellValue(dataHt.Rows[i]["model_name"].ToString());
dataRow.CreateCell(2).SetCellValue(dataHt.Rows[i]["print_barcode"].ToString());
dataRow.CreateCell(3).SetCellValue(dataHt.Rows[i]["print_tray_page"].ToString());
dataRow.CreateCell(4).SetCellValue(dataHt.Rows[i]["print_insp_page"].ToString());
dataRow.CreateCell(5).SetCellValue(dataHt.Rows[i]["barcode_template"].ToString());
dataRow.CreateCell(6).SetCellValue(dataHt.Rows[i]["insp_page_template"].ToString());
dataRow.CreateCell(7).SetCellValue(dataHt.Rows[i]["tray_page_template"].ToString());
dataRow.CreateCell(8).SetCellValue(dataHt.Rows[i]["fillPatter"].ToString());
dataRow.CreateCell(9).SetCellValue(dataHt.Rows[i]["bgcolor"].ToString());
dataRow.CreateCell(10).SetCellValue(dataHt.Rows[i]["forecolor"].ToString());
dataRow.CreateCell(11).SetCellValue(dataHt.Rows[i]["insp_special_char"].ToString());
dataRow.CreateCell(12).SetCellValue(dataHt.Rows[i]["Barcode_count"].ToString());
dataRow.CreateCell(13).SetCellValue(dataHt.Rows[i]["tray_page_count"].ToString());
dataRow.CreateCell(14).SetCellValue(dataHt.Rows[i]["insp_page_count"].ToString());
dataRow.CreateCell(15).SetCellValue(dataHt.Rows[i]["need_ab_data"].ToString());
dataRow.CreateCell(16).SetCellValue(dataHt.Rows[i]["need_zkc_data"].ToString());
dataRow.CreateCell(17).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;
}
}
}